akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    string S;
    ll a[4];

    cin >> S;
    rep(i, 4) a[i] = ll(S[i]) - ll('0');

    rep(i, 8){
        ll tmp = i;
        ll answer = a[0];
        rep(j, 3){
            if (tmp % 2 == 0) answer += a[j + 1];
            else answer -= a[j + 1];
            tmp /= 2;
        }

        if (answer == 7){
            tmp = i;
            cout << a[0];
            rep(j, 3){
                if (tmp % 2 == 0) cout << "+" << a[j + 1];
                else cout << "-" << a[j + 1];
                tmp /= 2;
            }
            cout << "=" << 7 << endl;
            return 0;
        }
    }

    return 0;
}


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

typedef long long ll;
#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

int main(){
	ll X, t;
	cin >> X >> t;

	ll ans = X - t;
	if(ans < 0) ans = 0;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define int long long
#define PB push_back

int gcd(int a, int b)
{
    int tmp;
    while (b) {
        tmp = a;
        a = b;
        b = tmp % b;
    }
    return a;
}

int lcm(int a, int b)
{
    return a / gcd(a, b) * b;
}

signed main()
{
    int L;
    
    while (cin >> L, L) {
        vector<int> divisors;

        for (int i = 1; i * i <= L; ++i) {
            if (L % i == 0) {
                divisors.PB(i);
                if (i * i != L) divisors.PB(L / i);
            }
        }

        sort(begin(divisors), end(divisors));

        int ans = 0;

        for (int i = 0; i < (int)divisors.size(); ++i) {
            for (int j = 0; j <= i; ++j) {
                int ii = divisors[i], jj = divisors[j];

                if (lcm(ii, jj) == L) {
                    ans++;
                }
            }
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 3016
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int a,b,c;
	int ans = 0;
	while(~scanf("%d%d%d",&a,&b,&c)){
		ans = a * 100 + b * 10 + c;
		if(ans % 4 == 0) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
n,m = list(map(int,input().split()))
harr = list(map(int,input().split()))
ans = [True] * n
for i in range(m):
    a,b = list(map(int,input().split()))
    s = harr[a-1]; t = harr[b-1]
    if s > t:
        ans[b-1] = False
    elif s < t:
        ans[a-1] = False
    else:
        ans[a-1] = ans[b-1] = False

print(sum(ans))

Measured memory_bytes: 20092
#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()
using ll = long long;
using P = pair<int,int>;



int main() {
	
	
	int n; cin >> n;
	
	n -= 400;

	n /= 200;
	
	
	int ans = 8 - n ;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3620
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

x,y=map(int,input().split())

if (2*y-x)%3==0:
    a=(2*y-x)//3
    b=(2*x-y)//3
    mod = 10**9+7 #出力の制限
    N = a+b
    r=min(a,b)
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    print(cmb(N,r,mod))
else:
    print(0)

Measured memory_bytes: 82296
#include <cstdio>
int c[200][3],p[200];
int main() {
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		for(int j=0;j<3;j++)scanf("%d",&c[i][j]);
	}
	for(int i=0;i<3;i++) {
		for(int j=0;j<N;j++) {
			bool b=false;
			for(int k=0;k<N;k++)
				if(j!=k&&c[j][i]==c[k][i])b=true;
			if(!b)p[j]+=c[j][i];
		}
	}
	for(int i=0;i<N;i++) {
		printf("%d\n",p[i]);
	}
}

Measured memory_bytes: 1024
#include<stdio.h>
main(){int i,j,n;char p[1000000];while(scanf("%d",&n)!=-1){for(i=2;i<=n;i++)p[i]=1;for(i=2;i<n;i++)for(j=2;i*j<=n;j++)p[i*j]=0;j=0;for(i=2;i<=n;i++)j+=p[i];printf("%d\n",j);}}

Measured memory_bytes: 1380
from itertools import permutations
N, M, R = map(int, input().split())
r = [int(i) - 1 for i in input().split()]
d = [[10000000 for i in range(N)] for j in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    d[A-1][B-1] = min(d[A-1][B-1], C)
    d[B-1][A-1] = min(d[A-1][B-1], C)
for k in range(N):
    for s in range(N):
        for e in range(N):
            d[s][e] = min(d[s][e], d[s][k] + d[k][e])
l = True
for o in permutations(r):
    tmp_l = 0
    for s, e in zip(o[:-1], o[1:]):
        tmp_l = tmp_l + d[s][e]
    if l is True:
        l = tmp_l
    else:
        l = min(l, tmp_l)
print(l)

Measured memory_bytes: 51032
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}


signed main(){
	
	ll n,cnt = 0,ans = 0,memo = LINF;
	cin >> n;
	
	ll a[n] = {0};
	
	rep(i,0,n){
		cin >> a[i];
		if(a[i] < 0) cnt++;
		ans += abs(a[i]);
		memo = min(memo,abs(a[i]));
	}
	
	if(cnt % 2){
		cout << ans - memo*2 << endl;
	}
	else{
		cout << ans << endl;
	}
	
	return 0;

}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
using namespace std;
typedef long long ll;
int main()
{
    ll r, g;
    while (~scanf("%lld%lld", &r, &g))
    {
    	printf("%lld\n", 2 * g - r);
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void){
int x;
int i, j, k;
int t;
int r;
double s;
int max=1;
scanf("%d", &x);
s = sqrt((double)x);
t = (s * 10) / 10;
for(i=2;i<=t;i++){
    r = 1;
    while(max<=x){
        r *= i;
        if(r > x){
            break;
        }
        if(r > max){
            max = r;
        }
    }
    if(max>x){
        max /= i;
    }
}
printf("%d", max);
return 0;
}


Measured memory_bytes: 128
n, l = map(int, input().split())

# L ~ L + N - 1

y = 1000000000000
xx = None
for x in range(l, l + n):
    if y > abs(x):
        y = abs(x)
        xx = x

ans = 0
for x in range(l, l + n):
    if x == xx:
        continue
    ans += x
print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
    int H, W;
    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        for (int i = 0; i < W; i++) {
            cout << "#";
        }
        cout << "\n";
        for (int i = 0; i < H - 2; i++) {
            cout << "#";
            for (int j = 0; j < W - 2; j++) {
                cout << ".";
            }
            cout << "#\n";
        }
        for (int i = 0; i < W; i++) {
            cout << "#";
        }
        cout << "\n" << endl;

    }

    return 0;
}

Measured memory_bytes: 3104
#include <stdio.h>

int main(void)
{
	int n, m, src;
	int tag[101], sco[101] = {0};
	int i, j;
	
	scanf("%d %d", &n, &m);
	
	for (i = 1; i <= m; i++){
		scanf("%d", &tag[i]);
	}
	
	for (i = 1; i <= m; i++){
		for (j = 1; j <= n; j++){
			scanf("%d", &src);
			if (tag[i] == src){
				sco[j]++;
			}
			else {
				sco[tag[i]]++;
			}
		}
	}
	
	for (i = 1; i <= n; i++){
		printf("%d\n", sco[i]);
	}
	
	return (0);
}

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

const int N = 30;
const int INF = 1 << 29;
const double EPS = 1e-8;

struct edge{
  int to, lim;
  double dis;
  edge(int t=0, double d=0, int l=0):to(t),lim(l),dis(d){}
};

struct state{
  int n, speed, ps, pn;
  double t;
  state(int n=0, int pn=0, int s=0, int ps=0, double t=0):n(n),speed(s),ps(ps),pn(pn),t(t){}
  bool operator < (const state &s) const {
    return t > s.t;
  }
};


int n,m,st,go;
vector<edge> g[N];

double solve(){
  priority_queue<state> pq;
  state u, u2;
  double d[N][N][31][31];

  for(int i=0;i<n*n;i++) for(int j=0;j<31*31;j++)  d[i/n][i%n][j/31][j%31] = INF;
  d[st][st][1][1] = 0;

  for(pq.push(state(st, st, 1, 1, 0)); !pq.empty();){
    u = pq.top();
    pq.pop();

    if(u.n == go && u.ps == 1) return u.t;
    
    for(int i=0;i<g[u.n].size();i++){
      edge next = g[u.n][i];
      for(int j=-1;j<=1;j++){
        u2 = state(next.to, u.n, u.speed + j, u.speed, u.t + next.dis / (double)u.speed);
        if(u2.speed <= 0 || u2.speed > 30 || u.speed > next.lim || u2.n == u.pn || d[u2.n][u2.pn][u2.speed][u2.ps] <= u2.t + EPS) continue;
        d[u2.n][u2.pn][u2.speed][u2.ps] = u2.t;
        pq.push(u2);
      }
    }
  }

  return -1;
}

int main(){
  while(cin >> n >> m && (n|m)){
    cin >> st >> go;
    st--; go--;
    for(int i=0;i<n;i++) g[i].clear();
    for(int i=0;i<m;i++){
      int x,y,d,c;
      cin >> x >> y >> d >> c;
      x--; y--;
      g[x].push_back(edge(y, d, c));
      g[y].push_back(edge(x, d, c));
    }
    double res = solve();
    if(res < -0.5) cout << "unreachable" << endl;
    else printf("%.5f\n", res);
  }
}

Measured memory_bytes: 9208
#include <stdio.h>
int main()
{
    int a, b, c, temp;
    scanf("%d %d %d", &a, &b, &c);

    if (b < a) {
        temp = b;
        b = a;
        a = temp;
    }
    if (c < b) {
        temp = c;
        c = b;
        b = temp;
        if (temp < a) {
            b = a;
            a = temp;
        }
    }

    printf("%d %d %d\n", a, b, c);
    return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int n,m,cnt=0,aa[220000],ans=0,ab[220000],a=0,b=0,xx[220000];
pair<int,int> pp[220000];
string s,sa[220000];
char c;
queue<int> que;
signed main(){
    rep(i,200000){
        int l=i+1;
        cnt=0;
        rep(j,20){
            if(l%2==1){
                cnt++;
            }
            l/=2;
        }
        xx[i+1]=xx[(i+1)%cnt]+1;
    }
    cnt=0;
    cin>>n>>s;
    rep(i,n){
        if(s[i]=='1'){
            cnt++;
        }
    }
    rep(i,n){
        if(i==0){
            if(cnt==0){
                aa[i]=0;
                ab[i]=0;
            }elif(cnt==1){
                aa[i]=1;
                ab[i]=0;
            }else{
                aa[i]=1;
                ab[i]=1;
            }
        }else{
            aa[i]=aa[i-1]*2%(cnt+1);
            if(cnt-1>0){
                ab[i]=ab[i-1]*2%(cnt-1);
            }else{
                ab[i]=0;
            }
        }
        a+=aa[i]*(s[n-1-i]-'0');
        b+=ab[i]*(s[n-1-i]-'0');
    }
    rep(i,n){
        if(s[i]=='0'){
            cout<<xx[(a+aa[n-1-i])%(cnt+1)]+1<<endl;
        }else{
            if(cnt-1>0){
                cout<<xx[(b-ab[n-1-i])%(cnt-1)]+1<<endl;
            }else{
                if(cnt==1){
                    cout<<0<<endl;
                }else{
                    cout<<1<<endl;
                }
            }
        }
    }
}

Measured memory_bytes: 15300
n = int(input())
F = [list(map(int, input().split())) for i in range(n)]
P = [list(map(int, input().split())) for i in range(n)]

ans = -10 ** 11
for i in range(1, 2**10) :
    ans1 = 0
    t = format(i, "010b")
    for j in range(n) :
        kaburi = 0
        for k in range(10) :
            #print(t)
            if int(t[k]) * F[j][k] == 1 :
                kaburi += 1
        ans1 += P[j][kaburi]
    #print("{} {}".format(t,ans1))
    #if ans1>ans :
    #    print(t)
    ans = max(ans, ans1)

print(ans)


Measured memory_bytes: 3064
#pragma GCC optimize(2)
//Happy TLE and WA every day!
#include<bits/stdc++.h>
#define mp			make_pair
#define rep(i,n)	for(int i = 0; i < n; i++)
#define BINF		0x7fffffff
#define INF			0x3f3f3f3f
#define LINF		3223372036854775807
#define END(s)		{cout<<s; return 0;}
#define CON(s)		{cout<<s; continue;}
#define BRE(s)		{cout<<s; break;}
#define pb			push_back
//#define int			long long
#define All(a)		a.begin(), a.end()  //with A in CAPITAL!!!
#define sz(a)		(int)a.size()
#define F			first
#define S			second
//#define usingFiles
using namespace std;

const int rp = 666666;
const bool debug = 1;

int a[100100];

signed main(){
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	rep(i, n) cin >> a[i];
	int mn = INF;
	rep(i, (n - k + 1)){
		int Beg = i, End = i + k - 1;
		int Min = min(abs(a[End]), abs(a[Beg]));
		mn = min(mn, Min + (a[End] - a[Beg]));
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
inline void read (int &x) {
	char ch = getchar(); x = 0;
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
const int N = 1e5 + 10;
int n, m, a, b, vis[N], s[N];
char ch[3];
signed main() {
	read (n), read (m);
	for (int i = 1; i <= m; ++i) {
		int x;
		read (x); scanf ("%s", ch);
		if (ch[0] == 'A') a += vis[x] ^ 1, vis[x] = 1;
		else if (!vis[x]) ++s[x];
	}
	for (int i = 1; i <= n; ++i) b += s[i] * vis[i];
	printf ("%d %d\n", a, b);
	return 0;
}

Measured memory_bytes: 1024
s = int(input())
moto = s
count = 0
while s!=1:
  if s%2==0:
    s /= 2
  else:
    s = s*3+1
  count += 1
if moto == 1:
  print(4)
elif moto == 2:
  print(4)
else:
  print(count+2)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

signed main(){
    ll N; cin >> N;
    vector<ll> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    ll ans = 0;
    for(ll digit = 0; digit <= 60; digit++){
        ll c0 = 0, c1 = 0;
        for(int i = 0; i < N; i++){
            if(1LL & (a[i] >> digit)) c1++;
            else c0++;
        }
        ans += ((c0 * c1)%MOD) * ((1ll << digit)%MOD);
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5572
import java.io.*;

public class Main{

	public static int[] a;
	public static int n;
	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(br.readLine());
		a = new int[n];
		String[] ins = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			a[i] = Integer.parseInt(ins[i]);
		}
		int q = Integer.parseInt(br.readLine());
		int[] m = new int[q];
		String[] in = br.readLine().split(" ");
		for(int i = 0; i < q; i++){
			m[i] = Integer.parseInt(in[i]);
		}

		for(int i = 0; i < q; i++){
			System.out.printf("%s\n", solve(0, m[i])? "yes" : "no");
			
		}
	}

	static boolean solve(int i, int m){
		if(m == 0)
			return true;
		if(i >= n)
			return false;
		return solve(i+1, m) || solve(i+1, m-a[i]);
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int n, a, b, c[12525];
int ans[12525];
vi g[12525];

void bfs(int s){
	queue<int> q;
	q.push(s);
	int cnt=n-1;
	ans[s]=c[cnt];
	while(q.size()){
		int p=q.front();
		q.pop();
		for(auto& x : g[p]){
			if(ans[x]!=-1){
				continue;
			}
			ans[x]=c[--cnt];
			// DEBUG(cnt);
			q.push(x);
		}
	}
	return;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	cin>>n;
	REP(i, n-1){
		cin>>a>>b;
		--a;
		--b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int sum=0;
	REP(i, n){
		cin>>c[i];
		sum+=c[i];
	}
	sort(c, c+n);
	int ma=c[n-1];
	REP(i, n){
		ans[i]=-1;
	}
	bfs(0);
	cout<<sum-ma<<'\n';
	REP(i, n){
		cout<<ans[i]<<" \n"[i==n-1];
	}
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define pb                  push_back
#define mp                  make_pair

#define dd                  double
#define ll                  long long int

using namespace std;
#define pi                  pair<int,int>
#define pii                 pair< pair<int,int> ,int>


int solve()
{
    ll n,k;cin>>n>>k;
    if(n>=k)cout<<min(n%k,abs(n%k-k))<<endl;
    else{
        cout<<min(abs(n-k),n%k)<<endl;
    }


    return 0;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

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

    vector<pair<int,ll>> G[N];
    for (int i=0; i<N-1; ++i)  {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    vector<int> dist(N,-1);
    queue<int> que;

    dist[0]=0;
    que.push(0);

    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(auto nv : G[v]) {
            if(dist[nv.first]!=-1) continue;
            if(nv.second%2==0) dist[nv.first]=dist[v];
            else if(nv.second%2==1 && dist[v]==0) dist[nv.first]=1;
            else dist[nv.first]=0;
            que.push(nv.first);
        }
    }
    for(int v=0; v<N; ++v) cout << dist[v] << "\n";
    return 0;
}

Measured memory_bytes: 11152
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Ord

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- sortOn Down <$> getIntList
    print . sum . take (n-1) . sortOn Down $ as ++ (tail as)

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

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		int p[2][10001], d1, d2;
		vector<int> pp;
		for(int i=0;i<n;i++){
			cin>>p[0][i]>>d1>>d2;
			p[1][i] = d1 + d2;
			pp.push_back(d1+d2);
		}

		sort(pp.begin(), pp.end());

		for(int i=0;i<n;i++){
			if(pp[pp.size()-1] == p[1][i]){
				cout<<p[0][i]<<" "<<p[1][i]<<endl;
				break;
			}
		}

	}
	return 0;
}

Measured memory_bytes: 1400
#include <stdlib.h>
#include <string.h>
#include <math.h> 
#include <stdio.h>

int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return 1;
    return -1;
}
int main()
{   int A,B,M;
    scanf("%d%d%d",&A,&B,&M);
    int a[A],b[B];
    for(int i=0;i<A;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<B;i++){
        scanf("%d",&b[i]);
    }
    int x[M],y[M],c[M];
    int vl[M+1];
    for(int i=0;i<M;i++){
        scanf("%d%d%d",&x[i],&y[i],&c[i]);
        vl[i]=a[x[i]-1]+b[y[i]-1]-c[i];
    }
    qsort(a,A,sizeof(int),compare);
    qsort(b,B,sizeof(int),compare);
    vl[M]=a[0]+b[0];
    qsort(vl,M+1,sizeof(int),compare);
    printf("%d",vl[0]);

    return 0;
}


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int n, k, p[1005];
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> p[i];
  sort(p, p + n);

  int sum = 0;
  for (int i = 0; i < k; ++i) sum += p[i];

  cout << sum << endl;
}


Measured memory_bytes: 3576
#include <iostream>
using namespace std;

int main(void) {
	int sheet[101][101] = {0}, r, c, i, j, sum;
	cin >> r >> c;
	for (i = 0; i < r; i++) {
		for (j = 0; j < c; j++) {
			cin >> sheet[i][j];
			sheet[i][c] += sheet[i][j];
			sheet[r][j] += sheet[i][j];
			sheet[r][c] += sheet[i][j];
		}
	}
	for (i = 0; i <= r; i++) {
		for (j = 0; j < c; j++) {
			cout << sheet[i][j] << ' ';
		}
		cout << sheet[i][c] << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
N,K=map(int, input().split())
A = list(map(int, input().split()))

A0=list(range(N))

def calc_zero(n):
    return n * 0

A0 = list(map(calc_zero, A0))

temp=0
tempv=[]

for i in range(K):
  if A0[temp]>=1:
    loop=i-A0[temp]
    t=(K-A0[temp])%loop
    temp=tempv[A0[temp]+t-1]
    break
  else:
    A0[temp]=i
    temp=A[temp]-1
    tempv.append(temp)

print(temp+1)

Measured memory_bytes: 105464
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	if((b-a)%2==0)
		printf("%lld\n",(b-a)/2);
	else
	{
		long long h1=a,h2=b;
		long long g=n-b;
		h1+=g;
		g++;
		h1++;
		g+=((n-h1)/2);
		long long ans=a-1;
		h2-=ans;
		ans++;
		h2--;
		ans+=((h2-1)/2);
		printf("%lld\n",min(g,ans));
	}
} 


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication16
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);

            c = a;
            for (int i = 1; i <= b - 1; i++)
            {
                c = c * 10 + a;
            }

            d = b;
            for (int v = 1; v <= a - 1; v++)
            {
                 d = d * 10 + b;
            }
            if (c > d)
                Console.WriteLine(c);
            if (c < d)
                Console.WriteLine(d);
            if (c == d)
                Console.WriteLine(c);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
// Code By H~$~C

uses math;

type
  int32 = longint;
  double = extended;
  bool = boolean;

const inf = 1061109567;

var
  i, j, swap_tmp, x, y, z: int32;
  n, ans: int32;
  h, p: array [0 .. 5005] of int32;
  dp: array [0 .. 5005] of int64;

function qsort_less(i, j: int32): bool;
begin
  qsort_less := (h[i] + p[i]) < (h[j] + p[j]);
end;
procedure qsort_swap(i, j: int32);
  var _swap_tmp: int32;
begin
  _swap_tmp := h[i]; h[i] := h[j]; h[j] := _swap_tmp;
  _swap_tmp := p[i]; p[i] := p[j]; p[j] := _swap_tmp;
end;
procedure qsort(_l, _r: int32);
  var i, j, _p: int32;
begin
  if (_r = _l) then exit;
  i := _l; j := _r;
  _p := _l;
  repeat
    while qsort_less(i, _p) do inc(i);
    while qsort_less(_p, j) do dec(j);
    if (i <= j) then begin
      qsort_swap(i, j);
      inc(i); dec(j);
    end;
  until (i > j);
  if (i < _r) then qsort(i, _r);
  if (j > _l) then qsort(_l, j);
end;

begin
//  assign(input,'in'); reset(input);
//  assign(output,'1.out'); rewrite(output);
  randseed := 6714;
  
  readln(n);
  for i := 1 to n do begin
    readln(h[i], p[i]);
  end;
  qsort(1, n);
  
  fillchar(dp, sizeof(dp), 63);
  dp[0] := 0;
  for i := 1 to n do begin
    for j := i - 1 downto 0 do begin
      if (dp[j] <= h[i]) and (dp[j + 1] > dp[j] + p[i]) then begin
        dp[j + 1] := dp[j] + p[i];
      end;
    end;
  end;
  
  ans := 0;
  for i := 0 to n do begin
    if (dp[i] < 1000000000000000000) then begin
      ans := i;
    end;
  end;
  writeln(ans);
  
  close(input);
  close(output);
end.


Measured memory_bytes: 256
//
//  ALDS_1_4_A.cpp
//  AizuOnlineJudge
//
//  Created by jiji on 2018/12/02.
//  Copyright © 2018年 jiji4000. All rights reserved.
//

#include <stdio.h>

bool linearSearch(int row[],int n,int key){
    int i = 0;
    // 末端に番兵を仕込む
    row[n] = key;
    for(i = 0;i <= n;++i){
        if(row[i] == key) break;
    }
    return i != n;
}

int main(){
    int n,row[10000 + 1],q,key,sum = 0;
    // 一つ目
    scanf("%d",&n);
    for(int i = 0;i < n;++i){
        scanf("%d",&row[i]);
    }

    // 探索する数
    scanf("%d",&q);
    for(int i = 0;i < q;++i){
        scanf("%d",&key);
        if(linearSearch(row, n, key)){
            ++sum;
        }
    }
    printf("%d\n",sum);
    return 0;
}



Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int dp[105][4][2];

int main() {
    string s;
    cin >> s;
    int K;
    cin >> K;

    dp[0][0][0] = 1;
    int L = s.size();
    rep(i, L) {
        rep(j, 4) {
            rep(k, 2) {
                int nd = s[i] - '0';
                rep(d, 10) {
                    int ni = i + 1, nj = j, nk = k;
                    if(d != 0) nj++;
                    if(nj > K) continue;
                    if(k == 0) {
                        if(d > nd) continue;
                        if(d < nd) nk = 1;
                    }
                    dp[ni][nj][nk] += dp[i][j][k];
                }
            }
        }
    }

    cout << dp[L][K][0] + dp[L][K][1] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Aka-beko and 40 Thieves
 */
public class Main {

	static int[][] map = {
			//
			{ 2, 3 },// 0:A
			{ 3, 2 },// 1:B
			{ 6, 4 },// 2:X
			{ 2, 6 },// 3:Y
			{ 5, 1 },// 4:Z
			{ 1, 3 },// 5:W
			{ 6, 6 },// 6:Sand
	};

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("#")) {

			int at = 0;
			for (char c : line.toCharArray()) {
				at = map[at][c - '0'];
				if (at == 6) {
					break;
				}
			}
			if (at == 1) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}

	}
}

Measured memory_bytes: 16880
#include <stdio.h>

int main(void) {

	int x = 0;
	int y = 0;
	scanf("%d", &x);
	scanf("%d", &y);



	while (x!=0||y!=0) { 

		if (x >= y) {
			printf("%d %d\n", y, x);
		}

		if (x < y) {
			printf("%d %d\n", x, y);
		}

		scanf("%d", &x);
		scanf("%d", &y);
	}


	return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);

  double l; cin >> l;
  l /= 3;
  cout << l * l * l << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;

void solve()
{
    int n;
    cin >> n;
    int maxi = 0, ans = 0;
    while (n--)
    {
        int a, b;
        cin >> a >> b;
        if (maxi < a)
        {
            ans = a + b;
            maxi = a;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  int q = 0;
  int cnt = 0;
  int left = 0, right = n;
  vector<pair<int, int>> past(n);
  vector<int> es(n);
  while(true) {
    cout << q << endl;
    string tmp;
    cin >> tmp;
    if(tmp == "Vacant"){
      return 0;
    }else if(tmp =="Male"){
      past[cnt] = {q, 0};
      if(cnt == 0) {
        for(int i = 0; i < n; i++){
          if(i % 2 == 0){
            es[i] = 0;
          }else{
            es[i] = 1;
          }
        }
      } else {
        if(es[q] == 0){
          left = q;
        } else {
          right = q;
        }
      }
    }else{
      past[cnt] = {q, 1};
      if(cnt == 0) {
        for(int i = 0; i < n; i++){
          if(i % 2 == 0){
            es[i] = 1;
          }else{
            es[i] = 0;
          }
        }
      } else {
        if(es[q] == 1){
          left = q;
        } else {
          right = q;
        }
      }
    }
    q = (left + right) / 2;
    cnt++;
  }
  return 0;
}

Measured memory_bytes: 2004
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
    string s, t;
    cin >> s;
    cin >> t;

    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());

    if (s.size() < t.size()) {
        bool flag = true;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] != t[i]) {
                flag = false;
            }
        }
        if (flag) {
            cout << "Yes";
            return 0;
        }
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9+7;


int N;
ll A[200010];
ll ans;
int main(){
    cin>>N;
    REP(i,0,N){
        cin>>A[i];
    }
    ll l=0,r=0;
    ll sum=0,tmp=0;
    while(r<N){
        if((sum^A[r])==sum+A[r]){
            sum+=A[r];
            r++;
        }else{
            ans+=(r-l);
            sum-=A[l];
            l++;
        }
    }
    ans+=(r-l+1)*(r-l)/2;
    p(ans);

    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env pypy3

def main():
    X, K, D = map(int, input().split())

    if X - K * D >= 0:
        print(X - K * D)
    elif X + K * D <= 0:
        print(-D * K - X)
    else:
        y = (D * K - X) // (2 * D)
        yy = (D * K - X + 2 * D) // (2 * D)
        print(min(abs(2 * D * y + X - D * K), abs(2 * D * yy + X - D * K)))
main()


Measured memory_bytes: 61732
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

ll conv(string num) { stringstream ss; ss << num << flush; ll n; ss>>n; return n; }

string conv(ll n) { stringstream ss; ss << n << flush; return ss.str(); }

vector<string> split(string s, string delim) {
    vector<string> res;
    int pos = 0;
    while(true) {
        int found = s.find(delim, pos);
        if(found >= 0) {
            res.push_back(s.substr(pos, found - pos));
        }
        else {
            res.push_back(s.substr(pos));
            break;
        }
        pos = found + delim.size();
    }
    return res;
}
int ALPH_SIZE = 26;
char ALPH_L[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char ALPH_U[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

int main() {
    int N, M, C;
    int A[20][20];
    int B[20];

    cin >> N >> M >> C;
    for (int i=0; i<M; i++) {
        cin >> B[i];
    }

    for (int j=0; j<N; j++) {
        for (int k=0; k<M; k++) {
            cin >> A[j][k];
        }
    }

    int sum=0, ans=0;
    for (int j=0; j<N; j++) {
        sum = 0;
        for(int k=0; k<M; k++) {
            sum += A[j][k] * B[k];
        }

        sum += C;
        if (sum >0) {
            ++ans;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
typedef unsigned long long uint64;


int main() {
	int n;
	cin >> n;
	vector<uint64>a(n);

	for (int i = 0; i < n; i++) {
		scanf("%lld",&a[i]);
		if (a[i] == 0) {
			cout << "0" << endl;
			return 0;
		}
	}
	
	uint64 prod = 1;
	for (int i = 0; i < n; i++) {
		if(a[i] <= (1000000000000000000 / prod)){
			prod *= a[i]; 
		}
		else { 
			cout << "-1" << endl;
			return 0;
		}
	}

	cout << prod << endl;

	return 0; 
}

Measured memory_bytes: 4032
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int cnt[300];
int input[300];

int main() {
  int n;
  while (scanf("%d", &n), n) {
    REP(i, n) { scanf("%d", &input[i]); }
    double ansmin = 1e+10;
    int anss, ansa, ansc;
    REP(s, 16) REP(a, 16) REP(c, 16) {
      MEMSET(cnt, 0);
      int r = s;
      REP(i, n) {
        r = (a * r + c) % 256;
        int o = (r + input[i]) % 256;
        cnt[o]++;
      }
      double h = 0.0;
      REP(i, 256) {
        if (cnt[i] == 0) { continue; }
        h -= cnt[i] / (double)n * log(cnt[i] / (double)n);
      }
      if (h - ansmin < -EPS) {
        ansmin = h;
        anss = s;
        ansa = a;
        ansc = c;
      }
    }
    printf("%d %d %d\n", anss, ansa, ansc);
  }
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	cout << 15 - a - b - c - d - e << '\n';
}

Measured memory_bytes: 3632
N = int(input())

if N == 3:
    print('2\n3\n25')
    exit()

M = (N - 1) // 8
m2s = []
m3s = []
m6s = []
for i in range(1, (M + 1) * 12 + 1):
    if i % 6 == 0:
        m6s += [i]
    elif i % 3 == 0:
        m3s += [i]
    elif i % 2 == 0:
        m2s += [i]

im2 = 4 * M + [0, 2, 2, 2, 2, 4, 4, 4][(N - 1) % 8]
im3 = 2 * M + [0, 0, 0, 2, 2, 2, 2, 2][(N - 1) % 8]
im6 = 2 * M + [1, 0, 1, 0, 1, 0, 1, 2][(N - 1) % 8]

for i in m2s[:im2] + m3s[:im3] + m6s[:im6]:
    print(i)


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

int main(){
    int a,b;
    cin>>a>>b;
    if(a>b){
        for(int i=0; i<a; i++){
            cout<<b;
        }
        cout<<endl;
    }
    else{
        for(int  i=0; i<b; i++){
            cout<<a;
        }
        cout<<endl;
    }

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define _CRT_SECURE_NO_DEPRECATE
#define ii pair<int, int>
#define vii vector<ii>
#define vi vector<int>
const int N = 100500;
const int Q = 1 << 21;
const ll mod =  10e9+7;
using namespace std;
#define INF 1000000000
int n,m,k;
vector<int> g[N];
struct UnionFind{
    int parent[N],rank[N];

    UnionFind(int n){
        int i;
        for(int i=1;i<=n;i++) {parent[i] = i; rank[i] = 1;}
    }

    int root(int x){
        if(parent[x] != x) parent[x] = root(parent[x]);
        return parent[x];
    }

    void connect(int x, int y){
        int rx=root(x),ry=root(y);
        if(rx == ry) return;
        if(rank[rx] > rank[ry]) {parent[ry] = rx; rank[rx] += rank[ry];}
        if(rank[rx] <= rank[ry]) {parent[rx] = ry; rank[ry] += rank[rx];}
    }
};


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


    cin >> n>>m>>k;
    UnionFind uf(n);

    for(int i=1;i<=m;i++){
    	int a,b;
        cin >> a >> b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
        uf.connect(a,b);
     
    }
    for(int i=0;i<k;i++)
    {
    	int a,b;
    	cin>>a>>b;
    	g[a].push_back(b);
    	g[b].push_back(a);
	}
	for(int i=1;i<=n;i++)
	{
		int ans=uf.rank[uf.root(i)]-1;
		for(int j=0;j<g[i].size();j++)
		if(uf.root(i)==uf.root(g[i][j]))
		ans--;
		cout<<ans<<" ";
	}
  return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    if(N/100 == 7 || (N/10)%10 == 7 || N%10 == 7){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
def main():
    N=int(input())
    S=[input() for i in range(N)]
    
    dictionary={}
    for word in S:
        if word in dictionary:
            dictionary[word]+=1
            
        else:
            dictionary[word]=1
            
    maximum=max(dictionary.values())
    for key,value in sorted(dictionary.items()):
        if value==maximum:
            print(key)

if __name__ == "__main__":
    main()

Measured memory_bytes: 45712
#include "bits/stdc++.h"
using namespace std;


int main() {
	int Q;
	cin >> Q;
	vector<long long>P(30);
	for (int i = 0; i < 30; ++i) {
		if (0 == i) {
			P[i] = 1;
			continue;
		}
		P[i] = P[i - 1] * 3;
	}
	for (int i = 0; i < Q; ++i) {
		long long x, y, z, w;
		cin >> x >> y >> z >> w;
		x--;
		y--;
		z--;
		w--;
		long long ret = abs(z - x) + abs(w - y);
		for (int j = 29; j >= 0; --j) {
			long long x1 = x / P[j];
			long long y1 = y / P[j];
			long long z1 = z / P[j];
			long long w1 = w / P[j];
			if ((x1 == z1) && (1 == x1 % 3) && (abs(y1 - w1) >= 2)) {
				ret = abs(y - w) + min(x%P[j] + z % P[j] + 2, 2 * P[j] - x % P[j] - z % P[j]);
				break;
			}
			if ((y1 == w1) && (1 == y1 % 3) && (abs(x1 - z1) >= 2)) {
				ret = abs(x - z) + min(y%P[j] + w % P[j] + 2, 2 * P[j] - y % P[j] - w % P[j]);
				break;
			}
		}
		cout << ret << endl;
	}
	return 0;
}



Measured memory_bytes: 3628
from sys import stdin, stdout
from collections import deque, defaultdict
from functools import lru_cache

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	MOD = 10**9 + 7
	x = []
	for c in rll()[0]:
		x.append(int(c))
	d = int(rl())
	ans = 0

	dp = [[0 for __ in range(2)] for _ in range(d)]
	dp[0][1] = 1
	for i in range(len(x)):
		ndp = [[0 for __ in range(2)] for _ in range(d)]
		for digsum in range(d):
			for tight in range(2):
				for nd in range(x[i]+1 if tight else 10):
					ns = (digsum + nd) % d 
					ntight = 1 if tight and nd == x[i] else 0
					ndp[ns][ntight] += dp[digsum][tight]
					ndp[ns][ntight] %= MOD
		dp = ndp

	ans = (dp[0][0] + dp[0][1] - 1) % MOD
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

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

int main(){
  int N;
  cin >> N;
  vector<int> D(N);
  for(int i=0; i<N; i++){
    cin >> D.at(i);
  }
  sort(D.begin(), D.end());
  cout << D.at(N/2)-D.at(N/2-1) << endl;
}

Measured memory_bytes: 640
n =int(input())
a = list(map(int,input().split()))	

c = 0

s = [a[0]]
for i in range(1,n):
    s.append(s[-1]+a[i])

#print(s)
s.sort()
#print(s)

k=1
for i in range(1,n):
    if s[i]==s[i-1]:
        k += 1
    else:
        if k != 1:
            c += k*(k-1)//2
        k = 1
    if i == n-1 and k != 1:
         c += k*(k-1)//2
        
c += s.count(0)
print(c)

Measured memory_bytes: 26136
#include<iostream>
using namespace std;

void showif(int a,int b){
    if(a>b){
        cout<<"a > b"<<endl;
    }
    else if(a<b){
        cout<<"a < b"<<endl;
    }
    else{
        cout<<"a == b"<<endl;
    }
}

int main(){
    int a,b;
    cin>>a>>b;
    showif(a,b);
}



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

int n;
long result=0;

int Ju(int n)
{
  int res=1;
  for(int i=0;i<n-1;i++)
    res=res*10;
  return res;
}

int Check(long now)
{
  int a=0,b=0,c=0;
  
  int n=0;
  int now_check=now;
  
  while(now_check>=1)
  {
    now_check=now_check/10;
    n++;
  }
  
  for(int i=0;i<n;i++)
  {
    if(now/Ju(n-i)==3)
      a++;
    else if(now/Ju(n-i)==5)
      b++;
    else
      c++;
    now-=(now/Ju(n-i))*Ju(n-i);
  }
  
  //cout<<a<<" "<<b<<" "<<c<<endl;//
  
  if(a!=0&&b!=0&&c!=0)
    return 1;
  else
    return 0;
}
  
void dfs(long now)
{
  if(now>n)
    return;
  if(Check(now))
  {
    //cout<<now<<endl;
    result+=1;
  }
  
  dfs(now*10+3);
  dfs(now*10+5);
  dfs(now*10+7);
  
}

int main()
{
  cin>>n;
  dfs(3);
  dfs(7);
  dfs(5);
  cout<<result<<endl;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    ll ans = 0;
    ll n, k;
    cin >> n >> k;
    if(k == 0) {
        cout << n * n << endl;
        return 0;
    }
    REPN(waru, k+1, n+1) {
        ans += (n / waru) * (waru - k);
        ll tmp = n % waru;
        tmp -= k - 1;
        tmp = max((ll)0, tmp);
        ans += tmp;
        //cout << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
T = []
A = []
for i in 0..N-1
    T[i],A[i] = gets.split.map(&:to_i)
end

answer = T[0] + A[0]
t = []
a = []
t[0] = T[0]
a[0] = A[0]


for i in 1..N-1
    answer = (1..10 ** 20).bsearch{|n| (T[i]+A[i]) * n >= answer && A[i] * n >= a[i-1] && T[i] * n >= t[i-1]} * (T[i]+A[i])
    a[i] = (1..10 ** 20).bsearch{|n| (T[i]+A[i]) * n >= answer && A[i] * n >= a[i-1] && T[i] * n >= t[i-1]} * A[i]
    t[i] = (1..10 ** 20).bsearch{|n| (T[i]+A[i]) * n >= answer && A[i] * n >= a[i-1] && T[i] * n >= t[i-1]} * T[i]
end

puts answer


Measured memory_bytes: 1916
#include <iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(){
    long long int i;
    long long int o=0;
    int r = 0;
    cin >> i;
    o += (i/500) * 1000;
    i%=500;
    r = i%5;
    o+= i-r;
    cout << o;
    return 0;
}


Measured memory_bytes: 256
use std::io::{self, BufWriter, Write};
use std::collections::HashMap;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty), +) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn main() {
    from_line!(n: u64);
    let mut h = HashMap::new();
    for _i in 0..n {
        // b棟f階のr番目の部屋にv人
        from_line!(b: u64, f: u64, r: u64, v: i64);
        let key = gen_key(b, f, r);
        let new_v = match h.get(&key) {
            Some(val) => val + v,
            None => v,
        };
        h.insert(key, new_v);
    }

    let out = io::stdout();
    let mut out = BufWriter::new(out.lock());
    for bld in 1..4+1 {
        for flr in 1..3+1 {
            for rm in 1..10+1 {
                let key = gen_key(bld, flr, rm);
                let val = match h.get(&key) {
                    Some(&v) => v,
                    None => 0i64,
                };
                out.write_all(format!(" {}", val).as_bytes()).unwrap();
            }
            out.write_all(b"\n").unwrap()
        }
        if bld < 4 {
            out.write_all(b"####################\n").unwrap();
        }
    }
}

fn gen_key(b: u64, f: u64, r: u64) -> String {
    format!("{}-{}-{}", b, f, r)
}



Measured memory_bytes: 5044
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		// solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
		solver.readN(in.readLine());
		for (; solver.hasNextN();) {
			solver.readBodyN(in.readLine());
		}
		solver.readM(in.readLine());
		for (; solver.hasNextM();) {
			solver.readBodyM(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int M;
	int cnt;

	public void init() {
		N = 0;
		M = 0;
		cnt = 0;
		Blue = new HashMap<String, Integer>();
		Red = new HashMap<String, Integer>();
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public void readN(String str) {
		N = Integer.parseInt(str);
		cnt = 0;
	}

	public void readM(String str) {
		M = Integer.parseInt(str);
		cnt = 0;
	}

	public boolean hasNextN() {
		return cnt < N;
	}

	public boolean hasNextM() {
		return cnt < M;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	HashMap<String, Integer> Blue;

	public void readBodyN(String str) {
		// System.out.println(str);
		if (Blue.containsKey(str))
			Blue.put(str, Blue.get(str) + 1);
		else
			Blue.put(str, 1);
		cnt++;
	}

	HashMap<String, Integer> Red;

	public void readBodyM(String str) {
		// System.out.println(str);
		if (Red.containsKey(str))
			Red.put(str, Red.get(str) + 1);
		else
			Red.put(str, 1);
		cnt++;
	}

	public void solve() {
		int ans = 0;
		for (String key : Blue.keySet()) {
			int n = Blue.get(key);
			if (Red.containsKey(key))
				n -= Red.get(key);
			if (n > ans)
				ans = n;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 21332