akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long n,m,a,b,l,r,inv[200005],mod,num,power[35],u,cnt=1,fac[200005],fac_inv[200005],kmp,pp;
vector<long long> v;
int main()
{
	scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
	l=n-a+b-1;
	r=n+b-2;
	mod=1000000007;
	pp=mod*10000;
	u=mod-2;
	while(1)
	{
		if(u<=1)
		{
			v.push_back(u);
			break;
		}else
		{
			v.push_back(u%2);
			u/=2;
		}
	}
	/*for(int i=0;i<v.size();i++)
	{
		printf("%lld ",v[i]);
	}
	printf("\n%lld\n",v.size());*/
	for(int i=0;i<=200000;i++)
	{
		inv[i]=1;
		power[0]=i;
		for(int j=1;j<=30;j++)
		{
			power[j]=power[j-1]*power[j-1];
			power[j]%=mod;
		}
		for(int j=0;j<v.size();j++)
		{
			if(v[j]==1)
			{
				inv[i]*=power[j];
				inv[i]%=mod;
			}
		}
	}
	for(int i=m;i<=n+m-2;i++)
	{
		cnt*=i;
		cnt%=mod;
	}
	for(int i=1;i<n;i++)
	{
		cnt*=inv[i];
		cnt%=mod;
	}
	fac[0]=1;
	for(int i=1;i<=200000;i++)
	{
		fac[i]=fac[i-1]*i;
		fac[i]%=mod;
	}
	fac_inv[0]=1;
	for(int i=1;i<=200000;i++)
	{
		fac_inv[i]=fac_inv[i-1]*inv[i];
		fac_inv[i]%=mod;
	}
	for(int i=n-a;i<=n-1;i++)
	{
		kmp=1;
		kmp*=fac_inv[i];
		kmp%=mod;
		kmp*=fac_inv[b-1];
		kmp%=mod;
		kmp*=fac[i+b-1];
		kmp%=mod;
		num=(n-i)-1;
		kmp*=fac[num+m-b-1];
		kmp%=mod;
		kmp*=fac_inv[num];
		kmp%=mod;
		kmp*=fac_inv[m-b-1];
		kmp%=mod;
		cnt-=kmp;
		cnt+=pp;
		cnt%=mod;
	}
	printf("%lld",cnt);
}

Measured memory_bytes: 8520
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

vector<int> adj[MAX];

int solve(int N, const vector<int>& hs)
{
    int ans = 0;

    for (int i = 1; i <= N; ++i)
    {
        bool good = true;

        for (auto v : adj[i])
        {
            if (hs[v] >= hs[i])
            {
                good = false;
                break;
            }
        }

        ans += (good ? 1 : 0);
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<int> hs(N + 1);

    for (int i = 1; i <= N; ++i)
        cin >> hs[i];

    while (M--)
    {
        int u, v;
        cin >> u >> v;

        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    auto ans = solve(N, hs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 11100
#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int N = 200005;

int n;
int dat[N];

int main() {
	scanf("%d", &n);
	int ans = 0;
	int mins = INT_MAX;
	for (int i = 0; i < n; i++) {
		scanf("%d", &dat[i]);
		mins = min(mins, dat[i]);
		if (dat[i] <= mins) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e8 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  cin >> S;
  ;
}
int dp[MX + 2][2];  // dp[i][j] : iけたまで，j?負:せい
void solve() {
  int N = S.size();
  int lw = S[N - 1] - '0';
  dp[N - 1][0] = lw;
  dp[N - 1][1] = (1+10-lw);

  int ans = 0;
  rrep(i, N - 2, 0) {
    int n = S[i] - '0';
    dp[i][0] = min(dp[i + 1][0] + n, dp[i + 1][1] + n);
    dp[i][1] = min((1 + dp[i+1][0] + 10-n), (dp[i+1][1] + 10-n-1));
  }
  cout << min(dp[0][0], dp[0][1]) << endl;

  ;
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 17796
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;

int main(){
	double sd[3];
	int N;
	cin>>N;
	while(N>0){
		cin>>sd[0]>>sd[1]>>sd[2];
		sort(sd,sd+3);
		if(sd[2] == sqrt(pow(sd[1],2.0)+pow(sd[0],2.0))){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
		N--;
	}
	
	
	return 0;
}

Measured memory_bytes: 3100
import bisect
N = int(input())
count = {}
for x in map(int, input().split()):
    count[x] = count.get(x, 0) + 1

a = sorted(count.values())
sums = a[:]
n = len(a)
for i in range(1, n):
    sums[i] += sums[i-1]
    
def check(k, x):
    pos = bisect.bisect_right(a, x)
    if pos == 0:
        return x * n >= k * x
    return sums[pos-1]+ x * (n - pos) >= k * x

x = N
for k in range(1, N + 1):
    while not check(k, x):
        x -= 1
    print(x)

Measured memory_bytes: 122424
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef pair<ll,ll> P;
 
int main(){
    int ahp,aat,chp,cat;
    cin>>ahp>>aat>>chp>>cat;
    while(ahp*chp>0){
        chp-=aat;
        if(chp<=0)break;
        ahp-=cat;
        if(ahp<=0)break;
    }
    if(ahp<=0){cout<<"No";}
    else{cout<<"Yes";}
 
 
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

int main () {
    int h, m, s;
    cin >> s;
    h = s / 3600;
    s %= 3600;
    m = s / 60;
    s %= 60;
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

signed main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vi t(n);
    rep(i,n)cin>>t[i];
    sort(all(t));
    rep(i,n-2)t[i+1]+=t[i];
    int ans=0;
    rep(i,n-1)ans+=t[i];
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int H, W;
  cin >> H >> W;

  int a = (W+1)/2;
  int b = W/2;
  int c = (H+1)/2;
  int d = H/2;
  if(H == 1 || W == 1) cout << 1 << endl;
  else cout << a*c+b*d << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b;
	string s;
	cin>>a>>b;
	cin>>s;
	int zong=a+b;
	for(int i=0;i<a+b;i++){
		char d=s[i];
		if(d=='1'||d=='2'||d=='3'||d=='4'||d=='5'||d=='6'||d=='7'||d=='8'||d=='9'||d=='0'){
			zong--;
		}
	}
	if(zong!=1){
		cout<<"No"<<endl;
		return 0;
	}
	if(s[a]=='-')cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
H, W = map(int, input().split())
cntA = Counter()

for _ in range(H):
    cntA += Counter(list(input()))

four = (H // 2) * (W // 2)
for a, c in cntA.items():
    if four <= 0:
        break
    while c >= 4 and four > 0:
        c -= 4
        four -= 1
    cntA[a] = c

if four > 0:
    print('No')
    exit()

if H % 2 == W % 2 == 1:
    for a, c in cntA.items():
        if c % 2 == 1:
            cntA[a] -= 1
            break
    else:
        print('No')
        exit()

print('Yes' if all(c % 2 == 0 for c in cntA.values()) else 'No')


Measured memory_bytes: 3316
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 1e5 + 5;

string s;
bool flag[300];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> s;
  for (int i = 0 ; i < s.size() ; i++)
    flag[s[i]] = 1;
  if (flag['E'] != flag['W'] || flag['N'] != flag['S'])
    cout << "No";
  else
    cout << "Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	string a, b, c; cin >> a >> b >> c;
    cout << "A" << b[0] << "C" << endl;
	return 0;
}


Measured memory_bytes: 3600
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> inline void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> inline void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }
TPL<TNM T> inline void UNIQUE(vector<T>& vec) { sort(ALL(vec)); vec.erase(unique(ALL(vec)), vec.end()); }

int main(void) {
	string S;
	cin >> S;
	cout << count(ALL(S), '2') << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {

        string s, t;
        cin >> s >> t;

        if (s.size() + 1 != t.size()) cout << "No" << endl;
        for (int i = 0; i < s.size(); i++) {
                if (s[i] != t[i]) {
                        cout << "No" << endl;
                        return 0;
                }
        }
        cout << "Yes" << endl;
        return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	long long n,k,num=0,last=0;
	cin>>n>>k;
/*	if(n%k==0)
	{
		cout<<"0";
		return 0;
	}
	long long t=max(n,k)%min(n,k);*/
	n=n%k;
	last=abs(n-k);
	num=abs(last-k);
	while(num<last)
	{
		last=num;
		num=abs(last-k);
	}
	cout<<last;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    int n,H[105],max=-1,ans=0;
    cin>>n;
    REP(i,n) cin>>H[i];
    REP(i,n){
        if(H[i]>=max){
            ans++;
            max=H[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma region

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define MOD 1000000007
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  REP(i, vec.size())
  i == 0
      ? os << vec[i]
      : os << ", " << vec[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &deq) {
  os << "deq[ ";
  REP(i, deq.size())
  i == 0
      ? os << deq[i]
      : os << ", " << deq[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}

#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  ll N;
  cin >> N;
  vector<ll> A(N);
  cin >> A;

  ll r = 0;
  REP(i, 60) {
    int one = 0;
    REP(j, N) {
      one += (A[j] >> i) & 1;
    }
    r = (r + (one * (N - one) % MOD) * ((1ll << i) % MOD)) % MOD;
  }

  cout << r << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  ll l, r;
  cin >> l >> r;
  int ans = 2018;
  r = min(r, l + 2019 * 2);
  for (ll i = l; i <= r; i++) {
    for (ll j = i + 1; j <= r; j++) {
      int m = (i * j) % 2019;
      ans = min(ans, m);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def binom(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)

    res = factinv[r] % p
    for i in range(r):
        res = res * (n - i) % p

    return fact[n] * factinv[r] * factinv[n-r] % p

N, K = list(map(int, input().split()))

p = 10 ** 9 + 7

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

for i in range(1, K + 1):
    print(binom(K - 1, i - 1) * binom(N - K + 1, i) % p)

Measured memory_bytes: 68848
#include <iostream>
#include <cmath>

using namespace std;

int a[200010];
int ans[200010];

int main(){
    int n;
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=2;i<=n;i++)
        ans[a[i]]++;
    for(int i=1;i<=n;i++)
        printf("%d\n",ans[i]);
}


Measured memory_bytes: 5268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int a, b;
  cin >> a >> b;
  
  int ans = 0;
  for(int i = a; i <= b; i++) {
    string s = to_string(i);
    if(s.at(0) == s.at(4) && s.at(1) == s.at(3)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <tuple>
#include <functional>
using namespace std;

string A, B;

int main() {
	cin >> A >> B;
	for (int i = 0; i < A.size() + B.size(); i++) {
		if (i % 2 == 0) cout << A[i / 2];
		else cout << B[i / 2];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <bitset>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct Edge {
	int from, to, w;
};
  
class SegmentTree {//基本的に半開区間 [a,b)
public:
	vector<int> data;
	int n = 1;
	SegmentTree(int a) {
		while (n < a) n *= 2;
		data = vector<int>(n * 2 - 1, 0);
	}
	void update(int p, int a) {
		int cur = p + n - 1;
		while (cur) {
			data[cur] += a;
			cur = (cur - 1) / 2;
		}
		data[0] = a;
	}
	int sum(int a, int b, int num = 0, int base = 1) {
		int l = (num + 1 - base) * (n / base), r = l + n / base;

		if (a == l && b == r)
			return data[num];
		int nr = (l + r) / 2;
		int ret = 0;
		if (nr > a) ret += sum(a, min(b, nr), num * 2 + 1, base * 2);
		if (nr < b) ret += sum(max(a, nr), b, num * 2 + 2, base * 2);
		return ret;
	}
};

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) { //ｘの入ってる集合と yの入ってる集合を併合
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) { //xとyが同じ集合に入っているかどうかを判定
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	bool isroot(int x) {
		return data[x] < 0;
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main() {
	int n;
	cin >> n;

	ll rest = INT_MAX;
	ll sum = 0;
	bool dif = false;
	REP(i, n) {
		ll a, b;
		scanf("%lld %lld", &a, &b);
		if (a > b) {
			rest = min(rest, b);
		}
		if (a != b) dif = true;
		sum += a;
	}
	if (!dif) cout << 0 << endl;
	else	cout << max(0LL, sum - rest) << endl;

	return 0;
}

Measured memory_bytes: 256
int main(void)
{
	int n,i,j;
	scanf("%d",&n);
	
	for(i = 3;i <= n;i++){
		j = i;
		if(i % 3 == 0)printf(" %d",i);
		else		
		while(j > 0){
			if(j % 10 == 3){
				printf(" %d",i);
				break;
			}
			j /= 10;
		}	
	}
			
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
int main(){
	int i=0,j=0;
	char str1[21],str2[21];
    scanf("%s",str1);
	while (str1[i]!='\0') {
		i++;
	}
	str2[i]='\0';
	i--;
	while (i>=0) {
		str2[j]=str1[i];
		i--;
		j++;
	}
	printf("%s\n",str2);
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
 
using namespace std;
 
#define li long long int
#define FOR(i, a, b) for (li (i) = (a) ; (i) < (b) ; ++(i))
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    li X, Y, Z;
    cin >> X >> Y >> Z;

    li left = X - Z;
    cout << left / (Y + Z);

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int x, a;
    cin >> x >> a;

    int ret = (x < a) ? 0 : 10; 

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
n,d = map(int,input().split())
arr = np.zeros((n,d))
for i in range(n):
    arr[i,:] = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        l = np.sum((arr[i,:] - arr[j,:])**2)**0.5
        if l.is_integer():
            ans+=1
print(ans)


Measured memory_bytes: 12508
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int, int>;

int main() {

    string s;
    cin >> s;

    for (int i = 0; i < s.length(); ++i) {
        if (i%2 == 0) cout << s[i];
    }

    cout << endl;


    return 0;
}

Measured memory_bytes: 3700
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int  a = scanner.nextInt();
	  	int  b = scanner.nextInt();
	  	int[][] array;//配列確保
        array = new int[a][b];
        int Vec[] = new int[b];  // 配列確保
        int sum[] = new int[a];
        int x = 0;
        
        
        // データ入力
        for (int i = 0; i < a; i++) {
        	for (int j = 0; j < b; j++) {
	            array[i][j]=scanner.nextInt();
	        }
        }
        for (int i = 0; i < b; i++) {
	            Vec[i]=scanner.nextInt();
	     }
        
        for (int i = 0; i < a; i++) {
        	for (int j = 0; j < b; j++) {
	            sum[i] = array[i][j] * Vec[j] + x;
	            x = sum[i];
	        }
	        x = 0;
        }
        for (int i = 0; i < a; i++) {
	            System.out.println(sum[i]);
	     }
        
        
        
        scanner.close();
  }
}


Measured memory_bytes: 40716
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const ll INF = 1ll << 60;

ll dp[110][100010];
ll a[100010][2];

int main()
{
    ll n, w;

    cin >> n;
    cin >> w;

    for (int i = 0; i < n; ++i)
    {
        cin >> a[i][0];
        cin >> a[i][1];
    }

    dp[0][0] = 0;

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j <= w; ++j)
        {
            if (j - a[i][0] >= 0)
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - a[i][0]] + a[i][1]);

            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }

    cout << dp[n][w] << endl;

    return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
int main(){
string n;
cin>>n;
for(int i=0; i<3; i++){
    if(n.at(i)=='1'){
        cout<<9;
    }
    else if(n.at(i)=='9')
    {
        cout<<1;
    }  
}
cout<<""<<endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define un(x)           x.erase(unique(all(x)), x.end())
#define xx              first
#define yy              second
#define pb              emplace_back
#define all(v)          v.begin(),v.end()

#define D(x)            cerr << #x " = " << x << '\n'
#define DBG             cerr << "Hi!" << '\n'

#define CLR(a)          memset(a,0,sizeof(a))
#define SET(a)          memset(a,-1,sizeof(a))

//inline int setBit(int n,int pos) { return n = n | (1 << pos); }
//inline int resetBit(int n,int pos) { return n = n & ~(1 << pos); }
//inline bool checkBit(int n,int pos) { return (bool)(n & (1 << pos)); }
//inline int countBit(ll n) { return __builtin_popcountll(n); }


//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//unsigned int num = rng();
//shuffle(V.begin(),V.end(),rng);

/******************************************************************************************/

const int MAX = 1000010;
//const int INF = 0x3f3f3f3f;
//const double inf = 1.0/0.0;
const int MOD = 998244353;
//inline int add(int a,int b) { return (a + 0LL + b) % MOD; }
//inline int mul(int a,int b) { return (a * 1LL * b) % MOD; }


vector <int> divs[MAX];
ll sum[MAX], sqsum[MAX], dp[MAX];
ll ara[MAX];

ll bm(ll a, ll b, ll m) {
    if(b == 0) return 1LL;
    ll ret = bm(a, b/2, m);
    ret = (ret * ret) % MOD;
    if(b & 1LL) ret = (ret * a) % MOD;
    return ret;
}


int main() {
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

//    ios_base::sync_with_stdio(false);
//    cin.tie(0);


    for(int i=1;i<=1e6;i++) for(int j=i;j<=1e6;j+=i) divs[j].pb(i);

//    int T;
//    cin >> T;
//    for(int t=1;t<=T;t++) {
//        CLR(sum); CLR(sqsum); CLR(dp);
        int n;
        cin >> n;
        for(int i=1;i<=n;i++) {
            cin >> ara[i];
            for(int d : divs[ara[i]]) sum[d] = (sum[d] + ara[i]) % MOD, sqsum[d] = (sqsum[d] + (ara[i] * ara[i] % MOD)) % MOD;
        }
        ll ans = 0;
        for(int i=1e6;i>=1;i--) {
            dp[i] = (sum[i] * sum[i] - sqsum[i]) % MOD;
            dp[i] = (dp[i] + MOD) % MOD;
            for(int j=i+i;j<=1e6;j+=i) dp[i] = (dp[i] - dp[j] + MOD) % MOD;
        }
        for(int i=1;i<=1e6;i++) {
            ans = (ans + (dp[i] * bm(i, MOD-2, MOD) % MOD)) % MOD;
        }
        ans = (ans * bm(2, MOD-2, MOD)) % MOD;
//        cout << "Case " << t << ": " << ans << endl;
        cout << ans << endl;
//    }

    return 0;
}




Measured memory_bytes: 141440
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int h, w;
void load(vector<vector<int>> mp, int x, int y, int m = 0)
{
	if (x < 0 || w <= x || y < 0 || h <= y)	return;
	if (mp[y][x] == -1)	return;
	mp[y][x] = min(mp[y][x], m);
	load(mp, x + 1, y, m + 1);
	load(mp, x - 1, y, m + 1);
	load(mp, x, y + 1, m + 1);
	load(mp, x, y - 1, m + 1);
	return;
}
int getMax(vector<vector<int>> mp)
{
	int ret = 0;
	rep(i, h) rep(j, w) ret = max(ret, mp[i][j]);
	return ret;
}
int main()
{
	cin >> h >> w;
	vector<vector<int>> maze(h, vector<int>(w, 0));
	string s;
	vector<P> starts;
	rep(i, h) {
		cin >> s;
		rep(j, w) {
			if (s[j] == '.') {
				maze[i][j] = -2;
				starts.push_back(make_pair(j, i));
			}
			else maze[i][j] = -1;
		}
	}

	int sz = starts.size();
	int ans, tmpans;
	ans = 0;
	rep(i, sz) {
		tmpans = 0;
		vector<vector<int>> mp = maze;
		queue<P> que;
		que.push(starts[i]);
		mp[starts[i].second][starts[i].first] = 0;
		while (!que.empty()) {
			P v = que.front();
			que.pop();

			P next = v;
			next.first--;
			if (0 <= next.first) {
				if (mp[next.second][next.first] == -2) {
					mp[next.second][next.first] = mp[v.second][v.first] + 1;
					que.push(next);
				}
			}
			next.first += 2;
			if (next.first < w) {
				if (mp[next.second][next.first] == -2) {
					mp[next.second][next.first] = mp[v.second][v.first] + 1;
					que.push(next);
				}
			}
			next.first--; next.second--;
			if (0 <= next.second) {
				if (mp[next.second][next.first] == -2) {
					mp[next.second][next.first] = mp[v.second][v.first] + 1;
					que.push(next);
				}
			}
			next.second += 2;
			if (next.second < h) {
				if (mp[next.second][next.first] == -2) {
					mp[next.second][next.first] = mp[v.second][v.first] + 1;
					que.push(next);
				}
			}
		}
		tmpans = getMax(mp);
		ans = max(ans, tmpans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)

int getmd(int a,int b,int c,int d){
    return abs(a-c)+abs(b-d);
}

int main(){
    int n,k,ans(0);
    cin >> n >> k;
    int h[n];
    rep(i,n){
        cin >> h[i];
        if(h[i]>=k)
            ans++;
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <set>

using namespace std;

int main() {
    int n, y;
    cin >> n >> y;

    int A = -1, B = -1, C = -1;
    for (int a = 0; a <= n; ++a) {
        for (int b = 0; b <= n - a; ++b) {
            int c = n - a - b;
            if (10000*a + 5000*b + 1000*c == y) {
                A = a;
                B = b;
                C = c;
            }
        }
    }

    cout << A << " " << B << " " << C << endl;
}

Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(void)
{
  int k; cin>>k;
  int count=0;
  
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      if((i%2==0)&&(j%2!=0)){count++;}
    }
  }
  
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int pasta[3];
int drink[2];
const int INF=1<<20;
int main(){
	int p=INF;
	int d=INF;
	for(int i=0;i<3;i++){
		cin>>pasta[i];
		p=min(p,pasta[i]);
	}
	for(int i=0;i<2;i++){
		cin>>drink[i];
		d=min(d,drink[i]);
	}
	cout<<d+p-50<<endl;
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		while (scanner.hasNext()) {

			boolean ans = false;
			int ansh = 0;
			int answ = 0;

			int h = scanner.nextInt();
			int w = scanner.nextInt();

			if (h == 0 && w == 0) {
				return;
			}

			int givenDia = h * h + w * w;

			//同じ対角線の長さのものを探す
			//				長方形の高さを一つづつ長くする
			for (int i = h + 1; i < w; i++) {
				int j = givenDia - i * i;

				//				同じ対角線の長さの長方形を探す
				for (int k = w - 1; k * k >= j; k--) {
					if (k * k == j && i < k) {

						ans = true;
						ansh = i;
						answ = k;
						break;
					}
				}

				if (ans == true) {
					break;
				}
			}
			if (ans != true) {

				//				対角線を1づつ長くして、整数の二乗で作れるものを探す
				for (int j = givenDia+1;; j++) {

					for (int l = 1; l * l < j / 2; l++) {
						double d = Math.sqrt(j - l * l);
						if (d == (int) d && !(l == h && d == w)) {
							ans = true;
							ansh = l;
							answ = (int) d;
							break;
						}

						if (ans == true) {
							break;
						}
					}
					if (ans == true) {
						break;
					}
				}
			}

			System.out.println(ansh + " " + answ);
		}
		scanner.close();
		return;
	}

}


Measured memory_bytes: 26364
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int n, k;

int counter(int point){
    int count = 0;
    while(point < k){
        point = point * 2;
        count++;
    }
    
    return count;
}

int main(){
    cin >> n >> k;

    double pro = 0.0;
    double half = 0.5;
    double first_p = 1.0 / (double) n; 

    for(int i = 1; i <= n; i++){
        
        pro = pro + first_p * pow(half, counter(i));
    }

    printf("%.20f\n", pro);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 2e9;
const int MOD = 1e9 + 7;

int dp[100005][2][105];
int main() {
   string K;
   int D;
   cin >> K >> D;

   dp[0][0][0] = 1;
   rep(i, 0, K.size()) {
      int k = K[i] - '0';
      rep(j, 0, D) {
         rep(digit, 0, 10)(dp[i + 1][1][(j + digit) % D] += dp[i][1][j]) %= MOD;
         rep(digit, 0, k)(dp[i + 1][1][(j + digit) % D] += dp[i][0][j]) %= MOD;
         (dp[i + 1][0][(k + j) % D] += dp[i][0][j]) %= MOD;
      }
   }
   int ans = (dp[K.size()][0][0] + dp[K.size()][1][0] - 1 + MOD) % MOD;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 
int main(){
    vl v(4,0);
    ll n;cin >> n;
    rep(i,n){
        string s;cin >> s;
        if(s=="AC")v[0]++;
        if(s=="WA")v[1]++;
        if(s=="TLE")v[2]++;
        if(s=="RE")v[3]++;
    }
    cout << "AC x "<<v[0]<<endl;
    cout << "WA x "<<v[1]<<endl;
    cout << "TLE x "<<v[2]<<endl;
      cout << "RE x "<<v[3]<<endl;
}

Measured memory_bytes: 3624
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll target;
bool my_compare(pair<string, ll> a, pair<string , ll> b) {
    // 基本はfirstで比較
    if(a.first != b.first){
         return a.first < b.first; // 昇順
        //return a.first > b.first; // 降順
    }

    // それ以外はsecondで比較
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        // どちらも同じ
        return true;
    }
}

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    //double mini=INF;
    ll maxi=0,f=0,sum=0,mini=INF;
    string str,str1,str2;
    ll i;
    double h;
    ll n,x,m;
    ll a,b,d,c;
    cin>>n;
    ll dp[50];
    dp[0]=1;
    dp[1]=1;
    for(i=2;i<46;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    cout<<dp[n]<<endl;

    return 0;
}



Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  ll k, a, b;
  cin >> k >> a >> b;
  if (a >= b - 2) {
    cout << k + 1 << endl;
  } else {
    if (k <= a) {
      cout << k + 1 << endl;
    } else {
      ll t = k - (a - 1);
      ll ans = a;
      if (t % 2 == 1) {
        ans += 1;
        t -= 1;
      }
      ans += ((t / 2) * (b - a));
      cout << ans << endl;
    }
  }
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define push_back pb
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
ll dp[100005][2];
int main() {
	int N;
	cin>>N;
	vector<ll> A(N);
	rep(i,N)cin>>A[i];
	dp[0][0] = 0;
	dp[0][1] = -INF;

	rep(i,N){
		dp[i+1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i]);
		dp[i+1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i]);
	}
	ll ans = dp[N][0]; 
	cout<<ans<<endl;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
void norm(string &s,vector<char> &c,int n){
  if(s.size()==n){
    cout<<s<<endl;
    return;
  }
  for(char x:c){
    s+=x;
    norm(s,c,n);
    s.pop_back();
  }
  c.push_back((char)c.size()+'a');
  s+=c.back();
  norm(s,c,n);
  c.pop_back();
  s.pop_back();
  return;
}
int main(){
  int n;
  cin>>n;
  string s;
  vector<char> c;
  norm(s,c,n);
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    double n,m,d;
    cin>>n>>m>>d;
    double ans=(d*2+(n-(d*2))*2)/(n*n);
    ans*=(m-1);
    if(d==0) ans/=2;
    cout<<fixed<<setprecision(10)<<ans<<endl;

}

Measured memory_bytes: 3792
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll d[300][300];
int r[10];
int main()
{
	int N, M, R;
	cin >> N >> M >> R;
	for (int i = 0; i < R; i++) {
		cin >> r[i];
		r[i]--;
	}
	for (int i = 0; i < 300; i++) {
		for (int j = 0; j < 300; j++) {
			if (i != j)d[i][j] = INF;
		}
	}
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = c;
		d[b][a] = c;
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	ll ans = INF;
	sort(r, r + R);
	do {
		ll sum = 0;
		for (int i = 0; i < R - 1; i++) {
			sum += d[r[i]][r[i + 1]];
		}
		ans = min(ans, sum);
	} while (next_permutation(r, r + R));
	cout << ans << endl;
}

Measured memory_bytes: 896
import java.util.*;
public class Main {
    public static void main(String[] args) {
        int X, A,B;
        Scanner sc = new Scanner(System.in);
        X = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        X = X -A;
        System.out.println(X%B);
    }

}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl 	"\n"

typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;
#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define tr(c,i) 	for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) 	((c).find(x) != (c).end())

#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

int main()
{	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);

	string s;
	cin>>s;
	string t;
	cin>>t;
	ll count=0;
	for(ll i=0; i<3; i++)
	{
		if(s.at(i)==t.at(i))
			count++;
	}
	cout<<count;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C, K;
  int sum = 0;
  
  cin >> A >> B >> C >> K;
  if(A >= K) sum = K;
  else {
    sum = A;
    if(A+B < K)sum -= (K - (A+B));
  }
  cout << sum << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

struct dice{
    int l[6];
    void roll(int a, int b, int c, int d){
        int t = l[a];
        l[a] = l[b];
        l[b] = l[c];
        l[c] = l[d];
        l[d] = t;}
    void roll_x() {roll(0, 2, 5, 3);}
    void roll_y() {roll(0, 1, 5, 4);}
    void roll_z() {roll(1, 2, 4, 3);}
    bool find_l3(dice a){
        REP(i, 4) {
            roll_x();
            REP(j, 4) {
                roll_y();
                REP(k, 4) {
                    roll_z();
                    int n = 0;
                    REP(m, 6) {
                        if (l[m] != a.l[m]) break;
                        else n++;}
                    if (n == 6) return 1;}}}
        return 0;
    }
};

int main(){
    dice d1, d2;
    REP(i, 6) cin >> d1.l[i];
    REP(i, 6) cin >> d2.l[i];
    d1.find_l3(d2) ? cout << "Yes" << endl : cout << "No" << endl;
}

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N;
int A[200010],B[200010];
pi P[200010];
bool comp(pi& a,pi& b){
  return a.second<b.second;
}
int main(){
  cin>>N;
  rep(i,N) cin>>A[i]>>B[i];
  rep(i,N) P[i]=mp(A[i],B[i]);
  sort(P,P+N,comp);
  int t=0;
  bool f=true;
  rep(i,N){
    t+=P[i].first;
    if(t>P[i].second){
      f=false;
      break;
    }
  }
  if(f) prin("Yes");
  else prin("No");

  
  return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <stdbool.h>

#define MAX 100

int main(void)
{
    int i, j;

    char ring[MAX + 1];
    char must_make[MAX + 1];
    scanf("%s %s", ring, must_make);

    char ringring[MAX * 2 + 1];
    for (i = 0; (ringring[i] = ring[i]) != '\0'; i++) {
        ;
    }
    int len_ring = i;
    for (i = 0; (ringring[len_ring + i] = ring[i]) != '\0'; i++) {
        ;
    }

    for (i = 0; must_make[i] != '\0'; i++) {
        ;
    }
    int len_must_make = i;

    bool canMake = false;
    for (i = 0; i < len_ring; i++) {
        if (ringring[i] == must_make[0]) {
            for (j = 0; j < len_must_make; j++) {
                if (ringring[i + j] == must_make[j]) {
                    canMake = true;
                    continue;
                } else {
                    canMake = false;
                    break;
                }
            }
            if (canMake == true) {
                break;
            } else {
                continue;
            }
        }
    }

    if (canMake == true) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    if (N % 2 == 0) {
        std::cout << N << std::endl;
    } else {
        std::cout << 2*N << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> tri;
int main(){
  int n,m,a;
  vector<tri> line;
  while(cin>>n>>m>>a){
    if(n==0)break;
    int h,p,q;
    for(int i=0;i<m;i++){
      cin>>h>>p>>q;
      line.push_back(tri(h, pii(p,q)));
    }
    sort(line.begin(), line.end(),greater<tri>());
    int cnt=0;
    for(int i=line[0].first;i>0 && cnt<line.size();){
      if(line[cnt].first<=i){
	if( line[cnt].second.first==a){
	  //cout << a << endl;
	  a=line[cnt].second.second;
	  i=line[cnt].first-1;
	}else if(line[cnt].second.second==a){
	  a=line[cnt].second.first;	
	  i=line[cnt].first-1;
	}
      }
      cnt++;
    }
    cout << a << endl;
    line.clear();
  }
  return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>

int main(){
  int flag=1,i,j,n,a[100],tmp,cnt=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    for(j=n-1;j>0;j--){
      if(a[j]<a[j-1]){
	tmp=a[j];
	a[j]=a[j-1];
	a[j-1]=tmp;
	cnt++;
      }
    }
}
  for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[i]);
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2104
A, B, M = map(int,input().split())
A = [a for a in map(int,input().split())]
B = [b for b in map(int,input().split())]
C = []
for m in range(M):
    C.append([c for c in map(int,input().split())])

ans = min(A) + min(B)

for c in C:
    if (A[c[0]-1]+B[c[1]-1]-c[2])<ans:
        ans = A[c[0]-1]+B[c[1]-1]-c[2]
print(ans)

Measured memory_bytes: 32224
#include<cstdio>
#include<algorithm>
using namespace std;
int n, Mod, A[510], B[510], R[510];
long long D[510][510];
struct point {
	int a, c;
	bool operator <(const point &p)const {
		return c != p.c ? c<p.c : a>p.a;
	}
}w[510];
long long Do(int K) {
	int i, j;
	for (i = 0; i <= n + n; i++)for (j = 0; j <= K; j++)D[i][j] = 0;
	D[0][0] = 1;
	int c = 0;
	for (i = 1; i <= n + n; i++) {
		int x = w[i].a;
		if (x <= n) {
			for (j = 0; j <= K; j++) {
				D[i][j + 1] = (D[i][j + 1] + D[i - 1][j] * (w[i].c - j - c))%Mod;
				D[i][j] = (D[i][j] + D[i - 1][j] * max(B[x] - n - (i-1-c) - (K - j), 0)) % Mod;
			}
		}
		else {
			for (j = 0; j <= K; j++) {
				D[i][j] = (D[i][j] + D[i - 1][j] * (w[i].c - j - c)) % Mod;
			}
			c++;
		}
	}
	return D[2*n][K];
}
int main() {
	scanf("%d%d", &n, &Mod);
	int i, j;
	for (i = 0; i < 2*n; i++) {
		for (j = 0; j < 2 * n; j++) {
			if (i*i + j * j < n*n)A[i+1] = j + 1;
			if (i*i + j * j <= 4*n*n)B[i+1] = j + 1;
		}
	}
	for (i = 1; i <= 2 * n; i++) {
		w[i].a = i;
		w[i].c = A[i];
		if (i > n)w[i].c = B[i];
	}
	sort(w + 1, w + n + n + 1);
	long long res = 0;
	for (i = 0; i <= n; i++) {
		R[i] = Do(i);
		if (i % 2==0)res += R[i];
		else res += Mod - R[i];
	}
	printf("%lld\n", res%Mod);
}

Measured memory_bytes: 2176
#!/usr/bin/env fsharpi

open System;

let ParseIntN ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int32.Parse

let ParseInt1 ( str : string ) =
    ParseIntN str |> fun arr -> arr.[0]

let ParseInt2 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1])

let ParseInt3 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let ReadLinesN ( n : int ) =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.take n

let ReadLines =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.takeWhile ((<>) null)

let set = new System.Collections.Generic.HashSet< int >()
Console.ReadLine()
|> ParseIntN
|> Array.iter (fun i -> (set.Add >> ignore) i )
printf "%d" set.Count


Measured memory_bytes: 14168
#include <iostream>
#include <string>

using namespace std;

int main(){

	string str;
	int ans = 0;
	while(cin>>str){
		if(str[0] == '0'){
			break;
		}
		int size = str.size();
		int state = 0;
		if(size%2==0){
			for(int i=0;i<str.size()/2;i++){
				if(str[i] != str[size-i-1]){
					state = 1;
					break;
				}
			}
		}
		else{
			for(int i=0;i<str.size()/2+1;i++){
				if(str[i] != str[size-i-1]){
					state = 1;
					break;
				}
			}
		}
		if(state == 0){
			ans++;
		}
	}
	cout<<ans<<endl;
}

/*
Sample Input
abcba
sx
abcddcba
rttrd
Output for the Sample Input
2
*/

Measured memory_bytes: 1184