akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U; typedef pair<int,int > P; typedef long long ll;
void inp();
int main(){
#ifdef XS
	freopen("at80d.in","r",stdin);
#endif
	//int n;scanf("%d",&n);for(int i=1;i<=n;i++)
	inp();
	return 0;
}
int h,w;
const int H = 2000,W=2000;
int g[H][W];
int A[20000];
int B[20000];
const int D[4][2]={
	{0,1},
	{1,0},
	{0,-1},
	{-1,0}
};
const int X =0,Y=1;
void inp(){
	scanf("%d%d",&h,&w);
	int n;scanf("%d",&n);
	int i;for(i=1;i<=n;i++)scanf("%d",&A[i]);
	MS(g,-1);
	int j;for(i=1;i<=h;i++)for(j=1;j<=w;j++)g[i][j]=0;
	int x;
	int cnt=0;
	int k;
	for(k=1;k<=n;k++){
		for(i=0;i<A[k];i++){
			B[cnt]=k;
			cnt++;
		}
	}
	x=1;int y=1;int d=0;
	for(i=0;i<cnt;i++){
		g[x][y]=B[i];
		while(g[x+D[d][X]][y+D[d][Y]]){
			if(i==cnt-1)break;
			d++;d%=4;
		}
		x+=D[d][X],y+=D[d][Y];
	}
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			if(j!=1)printf(" ");
			printf("%d",g[i][j]);
		}
		printf("\n");
	}
}
//at80d.cc by xsthunder at Sun Aug  6 21:03:37 2017


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll K, S;
        ll ans = 0;
        cin >> K >> S;
        rep(i, 0, K+1) {
                rep(j, 0, K+1) {
                        ll x = S - i - j;
                        if (0 <= x and x <= K)
                                ans++;
                } 
        }
        cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
    rep(i,0,tx - sx) cout << "R";
    rep(i,0,ty - sy) cout << "U";
    rep(i,0,tx - sx) cout << "L";
    rep(i,0,ty - sy + 1) cout << "D";

    rep(i,0,tx - sx + 1) cout << "R";
    rep(i,0,ty - sy + 1) cout << "U";
    cout << "LU";
    rep(i,0,tx - sx + 1) cout << "L";
    rep(i,0,ty - sy + 1) cout << "D";
    cout << "R";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

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

  int n, z, w;
  cin >> n >> z >> w;
  
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }

  if (n == 1) { cout << abs(a[0]-w) << endl; }
  else { cout << max(abs(a[n-1]-w), abs(a[n-1]-a[n-2])) << endl; }

  return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int k, int[] v) {
    int n = cast(int)v.length;
    int ans = 0;

    // 左から a 個とる
    for (int a = 0; a <= min(n, k); a++) {
        // 右から b 個とる
        for (int b = 0; b <= min(n, k) - a; b++) {
            int[] w;
            foreach (i; 0..a) w ~= v[i];
            foreach (i; 0..b) w ~= v[n-1-i];

            int val = w.sum;
            int restK = max(0, k - (a + b));
            if (restK > 0) {
                w.sort();
                // writeln("restK ", restK, " ", w);
                val += -w.until!("a >= 0").take(restK).sum;
            }
            ans = max(ans, val);
        }
    }
    return ans;
}

void main() {
    int n, k; scan(n, k);
    auto v = readints;
    writeln(calc(k, v));
}


Measured memory_bytes: 764
def main():
    from itertools import permutations

    n, m, r, *x = map(int, open(0).read().split())
    to = x[:r]

    dis = [[float("Inf")] * (n + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        dis[i][i] = 0

    for a, b, c in zip(*[iter(x[r:])] * 3):
        dis[a][b] = c
        dis[b][a] = c

    for k in range(1, n + 1):
        for i in range(1, n + 1):
            for j in range(1, n + 1):
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])

    ans = float("Inf")
    for p in permutations(to):
        tmp = 0
        nw = p[0]
        for nx in p[1:]:
            tmp += dis[nw][nx]
            nw = nx

        ans = min(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 83588
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j+1, n):
            if l[i] != l[j] and l[j] !=l[k] and l[k] != l[i]:
                if l[i] <l[j] + l[k]:
                    cnt += 1
print(cnt)


Measured memory_bytes: 9196
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(x) (int)x.size()
typedef long double f80;
#define all(x) x.begin(), x.end()

const int mod = 1e9 + 7;

string l, r;

ll dp[65][2][2][2][2][2];

string to_bin(ll val) {
    string s = "";
    while(val) {
        s += '0' + (val & 1);
        val >>= 1;
    }
    reverse(all(s));
    return s;
}

void upd(ll &x, ll y) {
    x = (x + y) % mod;
}

signed main()
{
    #ifdef LOCAL
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll lk, rk;
    cin >> lk >> rk;
    l = to_bin(lk);
    r = to_bin(rk);
    while(sz(l) != 62) l = '0' + l;
    while(sz(r) != 62) r = '0' + r;
    int nn = 61;
    dp[0][1][1][1][1][0] = 1;
    ll ans = 0;
    fr(i, 0, nn - 1) {
        fr(a, 0, 1) {
            fr(b, 0, 1) {
                fr(c, 0, 1) {
                    fr(d, 0, 1) {
                        fr(e, 0, 1) {
                            if(!dp[i][a][b][c][d][e]) continue;
                            ll cur = dp[i][a][b][c][d][e];
                            fr(j, 0, 1) {
                                fr(j1, 0, 1) {
                                    if(a && j < l[i + 1] - '0') continue;
                                    if(b && j > r[i + 1] - '0') continue;
                                    if(c && j1 < l[i + 1] - '0') continue;
                                    if(d && j1 > r[i + 1] - '0') continue;
                                    if(!e && (j != j1)) continue;
                                    if(j1 > j) continue;
                                    bool aa = a && (j == l[i + 1] - '0');
                                    bool bb = b & (j == r[i + 1] - '0');
                                    bool cc = c & (j1 == l[i + 1] - '0');
                                    bool dd = d & (j1 == r[i + 1] - '0');
                                    bool ee = e | j;
                                    upd(dp[i + 1][aa][bb][cc][dd][ee], cur);
                                    if(i == nn - 1) {
                                        upd(ans, cur);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    string s; cin >> s;
    const int n = s.size();

    auto solve = [](int rc, int lc) {
        vector<int> ret(rc + lc);
        int o = max(rc, lc) - min(rc, lc), t = max(rc, lc) - 1,  m = (rc + lc) / 2;

        REP(i, rc + lc) {
            if(i == rc-1) {
                if(o % 2) {
                    if(rc > lc) {
                        ret[i] = t % 2 ? m : m + 1;
                    } else {
                        ret[i] = t % 2 ? m + 1 : m;
                    }
                } else {
                    ret[i] = m;
                }
            } else if(i == rc) {
                if(o % 2) {
                    if(rc > lc) {
                        ret[i] = t % 2 ? m + 1 : m;
                    } else {
                        ret[i] = t % 2 ? m : m + 1;
                    }
                }else {
                    ret[i] = m;
                }
            }else {
                ret[i] = 0;
            }
        }

        return ret;
    };

    vector<int> ans;
    int i = 0;
    while(i < n) {
        int rc = 0, lc = 0;
        while(s[i] == 'R') {
            i++;
            rc++;
        }

        while(s[i] == 'L') {
            i++;
            lc++;
        }

        vector<int> ret = solve(rc, lc);
        REP(j, rc + lc) ans.push_back(ret[j]);
    }

    REP(i, n) cout << ans[i] << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 1404
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int count=0;
    string w;
    cin >> w;
    while(1){
        string t;
        cin >> t;
        if (t=="END_OF_TEXT") break;
        transform(t.begin(), t.end(), t.begin(), ::tolower);
        if (t==w) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3144
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

		final int r = sc.nextInt();
		final int c = sc.nextInt();
		
		int[][] matrix = new int[r + 1][c + 1];
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				matrix[i][j] = sc.nextInt();
			}
		}
		
		for(int i = 0; i < r; i++){
			
			int r_sum = 0;
			for(int j = 0; j < c; j++){
				r_sum += matrix[i][j];
			}
			
			matrix[i][c] = r_sum;
		}
		
		for(int j = 0; j <= c; j++){
			
			int c_sum = 0;
			for(int i = 0; i < r; i++){
				c_sum += matrix[i][j];
			}
			
			matrix[r][j] = c_sum;
		}
		
		for(int i = 0; i <= r; i++){
			for(int j = 0; j <= c; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(matrix[i][j]);
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 39532
import java.util.*;


import java.io.*;

class Main {

  public static void main(String[] args) throws Exception{
    try (Scanner sc = new Scanner(System.in)){
      String S = sc.next();
      if (S.length() == 2) {
        System.out.println(S);
      } else {
        for (int i = 0; i < S.length(); i++) {
          System.out.print(S.charAt(S.length()-i-1));
        }
      }
    }
  }
}


Measured memory_bytes: 22484
#include<bits/stdc++.h>
#define ll long long
using namespace std;

bool winner(vector<ll>&moves, ll k, ll n)
{
	vector<bool>dp(k + 1, false);
	//true matlab pehla jitega
	//false matlab dusra jitega
	for (int i = 1; i <= k; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (moves[j] > i)
				continue;

			if (dp[i - moves[j]] == false)
			{
				dp[i] = true;
			}

		}
	}
	return dp[k];

}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n, k;
	cin >> n >> k;
	vector<ll>moves(n + 1);
	for (ll i = 1; i <= n; i++)
	{
		ll d;
		cin >> d;
		moves[i] = d;
	}
	if (winner(moves, k, n) == true)
	{
		cout << "First";
	}
	else
	{
		cout << "Second";
	}
	return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    vector<int> v(N), c(N), res(N);
    REP(i, N) {
        cin >> v[i];
    }
    REP(i, N) {
        cin >> c[i];
    }
    REP(i, N) {
        res[i] = max(0, v[i] - c[i]);
    }
    cout << accumulate(ALL(res), 0);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9

#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)

string s, t;
string s1, s2;
int n;
int dp1[1024][1024];
int dp2[1024][1024];

int main(){
  cin >> s >> t;
  for (int i = 0; i < s.length(); i++) {
    if (i % 2) {
      s1 += s[i];
    }
    else {
      s2 += s[i];
    }
  }
  

  for (int i = 0; i < s1.length(); i++) {
    for (int j = 0; j < t.length(); j++) {
      dp1[i + 1][j + 1] = max(dp1[i][j + 1], dp1[i + 1][j]);
      if (s1[i] == t[j]) {
	dp1[i + 1][j + 1] = max(dp1[i + 1][j + 1], dp1[i][j] + 1);
      }

      //cout << dp1[i + 1][j + 1] << ' ';
    }
    //cout << endl;
  }

  for (int i = 0; i < s2.length(); i++) {
    for (int j = 0; j < t.length(); j++) {
      dp2[i + 1][j + 1] = max(dp2[i][j + 1], dp2[i + 1][j]);
      if (s2[i] == t[j]) {
	dp2[i + 1][j + 1] = max(dp2[i + 1][j + 1], dp2[i][j] + 1);
      }

      //cout << dp2[i + 1][j + 1] << ' ';
    }
    //cout << endl;
  }

  if (dp1[s1.length()][t.length()] == s1.length() || dp2[s2.length()][t.length()] == s2.length()) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}




Measured memory_bytes: 7196
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
vector<int> g[4];
bool b[4];

void solve(){
	int s = -1;
	rep(i, 4){
		if(g[i].size() == 1){
			s = i;
		}
	}
	if(s == -1){
		cout << "NO" <<endl;
		return;
	}
	queue<int> q;
	q.push(s);
	b[s] = true;
	while(!q.empty()){
		int n = q.front(); q.pop();
		int c = 0;
		rep(i, g[n].size()){
			int to = g[n][i];
			if(!b[to]){
				b[to] = true;
				q.push(to);
				c += 1;
			}
		}
		if(c == 0){
			rep(i, 4){
				if(!b[i]){
					cout << "NO" <<endl;
					return;
				}
			}
			cout << "YES" <<endl;
		}
		if(c > 1){
			cout << "NO" <<endl;
			return;
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	rep(i, 3){
		int a,b;
		cin >> a>>b;
		a--;b--;
		g[a].pub(b);
		g[b].pub(a);
	}
	solve();
	return 0;
}


Measured memory_bytes: 256
while True:
    h, w = map(int, input().split(" "))
    if h == 0 and w == 0:
        break
    print("#"*w)
    print(("#"+ "."*(w-2) +"#" + "\n")*(h-2) + "#" * w) if h >2 and w>=2 else 0
    print("#"*w) if h == 2 else 0
    print("")

Measured memory_bytes: 7540
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    
    
	 long long n,i,j,k,sum=0,count=0,ans=0,x,y,l,r,m;
     cin>>n>>k;
     long long b[n+1]={0};
     while(k--)
     {
         cin>>x;
         while(x--)
         {
             cin>>l;
             b[l]++;
         }
     }
     for(i=1;i<=n;i++)
     {
         if(b[i]==0)
         count++;
     }
     cout<<count;
    
}

Measured memory_bytes: 3664
import java.util.Scanner;


public class Main {


	//final int MOD = 1000000007;


	public static void main(String[] args) {

//		long ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

		int n = sc.nextInt();
//		int m = sc.nextInt();

		int[] a = new int[n];
		int[] ans = new int[n];
		for (int i = 0; i < n-1; i++) {
			a[i]= sc.nextInt();
			ans[i] = 0;
		}
		ans[n-1] = 0;

		//-------------------------------------------------------------------------------------

		for(int i = 0; i < n; i++) {
			if(a[i] != 0)
				ans[a[i]-1]++;
		}

		//-------------------------------------------------------------------------------------

		for(int i = 0; i < n; i++) {
			System.out.println(ans[i]);
		}

//		if(f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

		//System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 61452
#include <bits/stdc++.h>
using namespace std;
int a[10];
bool cmp(int a, int b) {
  int t = (a%10 == 0) ? 10 : a%10;
  int t1 = (b%10 == 0) ? 10 : b%10;
  return t < t1;
}
int main() {
  int n = 5;
  for(int i=0;i<n;i++) {
    cin >> a[i];
  }
  sort(a, a+n,cmp);
  long long res = 0;
  for(int i=1;i<5;i++) {
  	res += (a[i] / 10 * 10 + ((a[i] %10 ==0) ? 0 : 10)); 
  }
  res += a[0];
  cout <<res;
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int a,b,c; cin >> a >> b >> c;
    if(a+b+c >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

ll combination(ll n, ll a){  // nCa
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}

bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vi prime;
  rep(i,n) {
    if(isprime(i+1)) prime.push_back(i+1);
  }
  vi cnt(n+1);
  REP(i,n+1) {
    int copy = i;
    int tmp = 0;
    while(tmp < sz(prime)) {
      if(copy % prime[tmp] == 0) {
        cnt[prime[tmp]]++;
        copy /= prime[tmp];
      }
      else tmp++;
    }
  }

  int ans = 0;
  int count = 0;
  REP(i,n+1) {
    if(cnt[i] >= 74) count++;
  }
  ans += count;
  int cnt_a, cnt_b, cnt_c, cnt_d;
  cnt_a = cnt_b = cnt_c = cnt_d = 0;
  REP(i,n+1) {
    if(cnt[i] >= 4) cnt_a++;
    if(cnt[i] >= 14) cnt_b++;
    if(cnt[i] >= 2) cnt_c++;
    if(cnt[i] >= 24) cnt_d++;
  }
  if(cnt_a >= 2) ans += (cnt_a-1) * cnt_b;
  if(cnt_c >= 2) ans += (cnt_c-1) * cnt_d;
  if(cnt_c >= 3) ans += (cnt_c-2) * combination((cnt_a), 2);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=300005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli arr[MaxN];
	void solve(){
		lli N,i,j,res=0,p;
		lli A,B,C,X,Y;
		cin>>A>>B>>C>>X>>Y;
		p=min(X,Y);
		if(C*2<A+B){
			res+=C*p*2;
			X-=p;
			Y-=p;
		}
		if(C*2<A){
			res+=X*C*2;
			X=0;
		}
		if(C*2<B){
			res+=Y*C*2;
			Y=0;
		}
		res+=X*A;
		res+=Y*B;
		cout<<res;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}


Measured memory_bytes: 256
#include <stdio.h>

int itti(const char* a, const char* b, int l) {
	int i;
	for (i = 0; i < l; i++) {
		if (a[i] != b[i]) return 0;
	}
	return 1;
}

int nagasa(const char* a) {
	int i = 0;
	while (a[i] != '\0') i++;
	return i;
}

int main(void) {
	char S[256];
	int l;
	int i;
	if (scanf("%255s", S) != 1) return 1;
	l = nagasa(S);
	for (i = (l - 1) / 2; i >= 0; i--) {
		if (itti(S, S + i, i)) {
			printf("%d\n", i * 2);
			return 0;
		}
	}
	puts("ERROR!");
	return 0;
}


Measured memory_bytes: 128
N, A, B = map(int, input().split())
S = input()
n_passed = 0
n_passed_abroad = 1
for i, s in enumerate(S):
  res = "No"
  if s == 'a':
    if n_passed < A+B:
      res = "Yes"
      n_passed += 1
  elif s == 'b':
    if (n_passed < A+B) and (n_passed_abroad <= B):
      res = "Yes"
      n_passed += 1
      n_passed_abroad += 1

  print(res)

Measured memory_bytes: 9080
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = CInt(NextString())
        Dim s As String = NextString()
        Dim t As String = NextString()

        Dim overlap As Integer = 0
        For i As Integer = 1 To N
            If Right(s, i) = Left(t, i) Then
                overlap = i
            End If
        Next

        WriteLine(2 * N - overlap)
    End Sub

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll X, Y;
    cin >> X >> Y;
    int ans = 0;
    while (X <= Y) {
        X *= 2;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i >= 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main(){
	int a,b,c,x; cin >> a >> b >> c >> x;
	int ans = 0;
	for(int i=0;i<=a;i++) {
		for(int j=0;j<=b;j++) {
			for(int k=0;k<=c;k++) {
				if(500*i+100*j+50*k==x) ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	final Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new E();
	}
	
	class E{
		E(){
			while(sc.hasNext()){
				int N=sc.nextInt();
				if(N==0)	break;
				solve(N);
			}
		}
		void solve(int N){
			int[] d=new int[N],v=new int[N];
			for(int i=0; i<N; i++){
				d[i]=sc.nextInt();
				v[i]=sc.nextInt();
			}
			long vvv=v[0],ddd=d[0];
			for(int i=1; i<N; i++){
				long vv=v[i]*vvv;
				long d1=d[i]*vvv,d2=ddd*v[i];
				long d3=lcm(min(d1,d2),max(d1,d2));
				long gcd=gcd(d3,vv);
				vvv=vv/gcd;
				ddd=d3/gcd;
			}
			for(int i=0; i<N; i++){
				System.out.println(((long)v[i]*ddd/vvv)/(long)d[i]);
			}
		}
		long gcd(long x,long y){
			if(y==0)	return x;
			return gcd(y,x%y);
		}
		long lcm(long x,long y){
			return x/gcd(x,y)*y;
		}
	}

}

Measured memory_bytes: 13000
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long int lont;
int main() {
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	cout << N - (A + B - C) << endl;
}


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

int main(){
  int n;
  cin >> n;
  cout << (n*(n-1)/2) - (n/2)<< endl;
  if(n %2 == 0){
    for(int x = 1; x <= n; x++){
      for(int y = x+1; y<= n; y++){
        if(x != n - y + 1){
          cout << x << " " << y << endl;
        }
      }
    }
  }else{
    for(int x = 1; x <= n; x++){
      for(int y = x+1; y<= n; y++){
        if(x != n - y){
          cout << x << " " << y << endl;
        }
      }
    }

  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int dp[111][1111];

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int l,n,m,x;
  while(cin>>l>>n>>m>>x,l){
    string st;
    vector<Int> se(n),ss(n);
    vector<Int> e(m),s(m);
    for(Int i=0;i<n;i++) cin>>st>>se[i]>>ss[i];
    for(Int i=0;i<m;i++) cin>>st>>e[i]>>s[i];
    
    const Int INF = 1e9;
    for(Int i=0;i<111;i++)
      for(Int j=0;j<1111;j++)
	dp[i][j]=-INF;

    dp[0][0]=0;
    for(Int k=0;k<m;k++)
      for(Int i=m;i>=0;i--)
	for(Int j=l;j>=0;j--)
	  chmax(dp[i+1][j+e[k]],dp[i][j]+s[k]);
    
    vector<Int> dp2(l+1,-INF);
    for(Int i=x;i<=m;i++)
      for(Int j=0;j<=l;j++)
	chmax(dp2[j],dp[i][j]);

    for(Int j=1;j<=l;j++) chmax(dp2[j],dp2[j-1]);

    Int ans=-INF;
    for(Int i=0;i<n;i++){
      if(se[i]>l) continue;
      chmax(ans,dp2[l-se[i]]+ss[i]);
      for(Int j=0;j<i;j++){
	if(se[i]+se[j]>l) continue;
	chmax(ans,dp2[l-(se[i]+se[j])]+ss[i]+ss[j]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 4156
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    vector<int> V(N), C(N);
    for(int i=0; i<N; i++) cin >> V[i];
    for(int i=0; i<N; i++) cin >> C[i];

    int ans = 0;
    for(int i=0; i<N; i++) {
        int cost = max(0LL, V[i] - C[i]);
        ans += cost;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=[]
b=[]
c=0
for i in range(n):
  a.append(list(map(int,input().split())))

for i in range(m):
  b.append(int(input()))

for i in range(n):
  for j in range(m):
    c+=a[i][j]*b[j]
  print(c)
  c=0



Measured memory_bytes: 6012
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define N 123456
int main() {
	int i, j, cnt = 0, p[N*2] = {},n;
	for (i = 2; i <= (int)sqrt(N*2); ++i) if (!p[i]) for (j = 2; j*i < N*2; j++) p[i*j] = 1;
	while (~fscanf(stdin, "%d", &n), n) {
		cnt = 0;
		for (i = n + 1; i <= 2 * n; i++) if (!p[i]) cnt++;
		P(d, cnt);
	}
	return 0;
}

Measured memory_bytes: 1576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
 
 
public class Main {
 
    private static final int BIG_NUM  = 2000000000;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        long sum = 0;
        int minimum = BIG_NUM,maximum = -BIG_NUM;
 
        try {
 
            int N = Integer.parseInt(br.readLine());
 
            String first[] = br.readLine().split("[\\s]+");
            int array[] = new int[first.length];
 
            for(int i = 0; i < first.length; i++){
 
                array[i] = Integer.parseInt(first[i]);
                minimum = Math.min(minimum, array[i]);
                maximum = Math.max(maximum, array[i]);
                sum += array[i];
            }
 
            System.out.printf("%d %d %d\n",minimum,maximum,sum);
 
        } catch (IOException e) {
            e.printStackTrace();
        }
 
    }
}


Measured memory_bytes: 31488
N,A,B,C,D = map(int, input().split())
A -= 1
B -= 1
C -= 1
D -= 1

S = list(input())

iwa2 = []
cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] == "#":
#         iwa2.append(1)
        cnt += 1
#     else:
#         iwa2.append(0)
    iwa2.append(cnt)
    
#長さ揃える
iwa2.append(cnt)        
        
def iwa2_check(s,g):
    if iwa2[s] < iwa2[g]:
        return True
    return False

# aki3は複数あったら、そのどれかに二人でたどり着ければ良い
aki3 = [0]
cnt = 0
for i in range(1,len(S)-1):
    if S[i-1] == S[i] == S[i+1] == ".":
        cnt += 1
    aki3.append(cnt)
aki3.append(cnt)

def aki3_check(B,CORD):
    # AさんがBさんと出会える（iwa2ない）
#     if not iwa2(A,B):
#         return False
    # Bさんがaki3にたどり着ける（最寄りの2つを見るだけで良い）
    # oBoのような状態でもOKなので-1
    if aki3[B-1] < aki3[CORD]:
        return True
    return False

# 順序が入れ替わらないとき
def solve():
    if iwa2_check(A,C) or iwa2_check(B,D):
#         print("1")
        return False
    if C<D:
#         print("2")
        return True
    else:
        if aki3_check(B, D):
#             print("3")
            return True
        else:
#             print("4")
            return False

if solve():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63524
S = list(input())

while len(S) != 0:
    if S[-1] == "m":
        if "".join(S[-5:]) == "dream":
            del S[-5:]
        else:
            print("NO")
            exit()
    elif "".join(S[-3:]) == "mer":
        if "".join(S[-7:]) == "dreamer":
            del S[-7:]
        else:
            print("NO")
            exit()
    elif S[-1] == "e":
        if "".join(S[-5:]) == "erase":
            del S[-5:]
        else:
            print("NO")
            exit()
    elif "".join(S[-3:]) == "ser":
        if "".join(S[-6:]) == "eraser":
            del S[-6:]
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()

print("YES")


Measured memory_bytes: 3956
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		Arrays.setAll(A, i -> sc.nextInt());
		int lb = 0, ub = Integer.MAX_VALUE/2, mid;
		while(lb + 1 < ub) {
			mid = (ub + lb) / 2;
			boolean ok = true;
			int c = 0;
			for(int i = 0; i < N; i++) {
				c += (A[i] + mid - 1) / mid - 1;
				if(c > K) {
					ok = false;
					break;
				}
			}
			if(ok)
				ub = mid;
			else
				lb = mid;
		}
		System.out.println(lb + 1);
	}

}

Measured memory_bytes: 59976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    int sl = s.length();
    if (sl == 1) {
        cout << "YES" << endl;
        return 0;
    }
    if (sl == 2) {
        if (s[0] != s[1]) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
        return 0;
    }
    vector<int> cnt(3, 0);
    rep(i, sl) cnt[s[i] - 'a']++;
    int minv = INT_MAX, maxv = INT_MIN;
    rep(i, sz(cnt)) {
        minv = min(minv, cnt[i]);
        maxv = max(maxv, cnt[i]);
    }
    if ((minv + 1) < maxv) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
#define enld endl
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s,t; cin >> s >> t;
    int ans  =0;
    for(int i=0;i<(int)s.size();i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3812
#!/usr/bin/env python
# -*- coding: utf-8 -*-

a, b, c = map(int, input().split())

# cが仲間外れ
if a == b and b != c:
    print("Yes")
# bが仲間外れ
elif a == c and a != b:
    print("Yes")
# aが仲間外れ
elif b == c and b != a:
    print("Yes")
else:
    print("No")


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

signed main(){
  int K, T; cin >> K >> T;
  vector<int> a(T);
  for(int i = 0; i < T; i++) cin >> a[i];
  int x = *max_element(a.begin(), a.end());
  int ans = max(0, 2*x - 1 - K);
  cout << ans << endl;
}

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

#define ll long long
#define pb push_back
unordered_map<long long int,long long int> mp;
vector<long long int > a;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll int sum=0;
    ll int n;cin>>n;
    a.resize(n);
    for (int i=0;i<n;i++){
        cin>>a[i];
        mp[a[i]]++;
    }
    for (auto it = mp.begin(); it != mp.end(); it++){
        long long int temp = it->second; // {first, second} {2, 3}
        sum+=(temp*(temp-1))/2;
    }
    for (int j=0;j<n;j++){
        long long int x =(((mp[a[j]]-1)*(mp[a[j]]-2))/2);
        long long y =((mp[a[j]]*(mp[a[j]]-1))/2);
        cout<<(sum-y)+x<<endl;
    }
    return 0;
}

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

int main(){
  int A,B;
  cin >> A >> B;
  
  if(1<=A && A<=9 && 1<=B && B<=9 ){
      cout << A*B << endl;
  }
  
  else{
  cout << -1 << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}


void solve() {
    int n, m; cin >> n >> m;
    priority_queue<int> items;
    fo(i, n) {
        int ai;
        cin >> ai;
        items.push(ai);
    }
    fo(i, m) {
        int me = items.top();
        items.pop();
        items.push(me >> 1);
    }
    ll ans = 0;
    fo(i, n) {
        ans += (ll) items.top();
        items.pop();
    }
    cout << ans;
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 892
#coding: utf-8
from functools import reduce
def gcd(a, b):
    if b == 0:
        return max(a, b)
    else:
        return gcd(b, a%b)

N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
print(reduce(gcd, x))

Measured memory_bytes: 14748
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, m, Q; cin >> n >> m >> Q;
	vector<vector<int>> sum(n + 1, vector<int>(n + 1, 0));
	while (m--)
	{
		int l, r; cin >> l >> r;
		++sum[l][r];
	}
	rep(i, n + 1)rep(j, n)sum[i][j + 1] += sum[i][j];
	rep(i, n)rep(j, n + 1)sum[i + 1][j] += sum[i][j];
	while (Q--)
	{
		int p, q; cin >> p >> q;
		cout << sum[q][q] - sum[q][p - 1] - sum[p - 1][q] + sum[p - 1][p - 1] << endl;
	}
}

Measured memory_bytes: 1920
#include <stdio.h>
#include <unordered_set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

#define F(x, y, d) while (f[x+dx[d]][y+dy[d]] != '#') x+=dx[d], y+=dy[d]
inline int h(int x, int y, int d) { return (x<<8) | (y<<2) | d; }
inline int h(int x1, int y1, int d1, int x2, int y2, int d2) {
    return (h(x1, y1, d1) << 16) | h(x2, y2, d2);
}

int H, W;
char f[16][64];
int sx, sy, sd, tx, ty, td;
std::unordered_set<int> h1, h2;

bool reach(int x, int y, int d) {
    F(x, y, d);
    if (x == tx && y == ty) return true;
    if (!h1.insert(h(x, y, d)).second) return false;
    if (reach(x, y, (d+1)%4)) return true;
    if (reach(x, y, (d+3)%4)) return true;
    return false;
}

bool acc(int cx, int cy, int cd, int x, int y, int d) {
    if (f[x+dx[d]][y+dy[d]] != '#') return false;
    F(cx, cy, cd);
    const bool p = cx == tx && cy == ty && d == td;
    while (f[x][y] != '#') {
        if (!h2.insert(h(cx, cy, cd, x, y, d)).second) break;
        if (p && x == tx && y == ty) return true;
        if (acc(cx, cy, (cd+1)%4, x, y, (d+1)%4)) return true;
        if (acc(cx, cy, (cd+3)%4, x, y, (d+3)%4)) return true;
        x -= dx[d], y -= dy[d];
    }
    return false;
}

void solve() {
    h1.clear();
    rep (i, H) rep (j, W) if (f[i][j] == 'K') {
        f[i][j] = '.';
        rep (d, 4) if (f[i+dx[d]][j+dy[d]] != '#') sx = i, sy = j, sd = d;
    }
    rep (i, H) rep (j, W) if (f[i][j] == 'M') {
        f[i][j] = '.';
        rep (d, 4) if (f[i+dx[d]][j+dy[d]] != '#') tx = i, ty = j, td = d;
    }
    if (!reach(sx, sy, sd)) puts("He cannot bring tea to his master.");
    else {
        h2.clear();
        rep (d, 4) if (acc(sx, sy, sd, sx, sy, d)) {
            puts("He can accomplish his mission.");
            return ;
        }
        puts("He cannot return to the kitchen.");
    }
}

int main() {
    for (;;) {
        scanf("%d%d", &W, &H);
        if (H == 0) return 0;
        rep (i, H) rep (j, W) scanf(" %c", f[i]+j);
        solve();
    }
}

Measured memory_bytes: 6036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	//freopen("input.txt", "r", stdin);
	int n, w;
	cin>>n>>w;
	ll price[n+1], weight[n+1];
	price[0] = 0, weight[0] = 0;
	for(int i=1; i<=n; i++){
		cin>>weight[i]>>price[i];
	}

	ll dp[n+1][w+1];

	for(int i=0; i<=w; i++) dp[0][i] = 0;
	for(int i=0; i<=n; i++) dp[i][0] = 0;

	for(int i=1; i<=n; i++){
		for(int j = 1; j<=w; j++){
			if(j-weight[i]<0) dp[i][j] = dp[i-1][j];
			else{
				dp[i][j] = max(dp[i-1][j], price[i]+(dp[i-1][j-weight[i]]));
			}
		}
	}
	
	/*
	for(int i=0; i<=n; i++){
		for(int j = 0; j<=w; j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	*/
	
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 79104
#include<stdio.h>
int main(void){
	int i,j,k,v,N,A[100];

	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}

	for(i=1;i<=N-1;i++){

		for(k=0;k<N;k++){
			printf("%d",A[k]);
			if(k<N-1){
				printf(" ");
			}else{
				printf("\n");
			}
		}

		v=A[i];
		j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=v;
	}

	for(k=0;k<N;k++){
		printf("%d",A[k]);
		if(k<N-1){
			printf(" ");
		}else{
			printf("\n");
		}
	}

	return 0;
}


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

int main() {
  int N;
  int A;
  int M = 0;

  cin >> N;
  cin >> A;

  if (N < 0 && N > 100 ) {
    exit (1);
  }

  if (N < -1 && N > N * N) {
    exit (1);
  }

  M = N * N - A;

  cout << M << endl;
}



Measured memory_bytes: 3592
n = int(input())

a_list = []
person_list = []
syogen_list = []
ans = 0

for i in range(0, n):
    w = []
    v = []
    a = int(input())
    for j in range(0, a):
        x,y = map(int,input().split())
        w.append(x)
        v.append(y)
    person_list.append(w)
    syogen_list.append(v)
#print(person_list)
#print(syogen_list)

for bit in range(1 << n):
    break_flag = 0
    bit_1_cnt = 0
    for i in range(n):
        if break_flag:
            break
        if (bit >> i) & 1: #人iが正直
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] != ((bit>>(person_list[i][j]-1))&1): #矛盾　：　正直としているのに証言が食い違えばbreak
                    break_flag = 1
                    break
            bit_1_cnt += 1
#                if j == len(syogen_list[i])-1:
#                    bit_1_cnt += 1
        if break_flag==0 and i==n-1:
            ans = max(ans, bit_1_cnt)
            #ans = max(ans, bin(bit).count("1"))
print(ans)


Measured memory_bytes: 9160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp9
{   
    class Program
    {
        public static void Main(string[] args) {
            while (true)
            {
                string[] sss = Console.ReadLine().Split(' ');
                int a = int.Parse(sss[0]); int b = int.Parse(sss[1]);
                if (a==0&&b==0) { break; }
                for (int d =1;d<= a;d++)
                {
                    for (int c =1;c<=b;c++)
                    {
                        Console.Write("#");

                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 8892
#include<iostream>
#include<algorithm>
const int INF=(1<<22);
int dp[1000000],d[20],n,m,i;
int main(){
    std::cin>>n>>m;
    std::fill(dp,dp+n+1,INF);dp[0]=0;
    for(i=0;i<m;++i)std::cin>>d[i];
    for(i=0;i<m;++i)for(int j=d[i];j<=n;++j){
        dp[j]=std::min(dp[j],dp[j-d[i]]+1);
    }std::cout<<dp[n]<<std::endl;
}

Measured memory_bytes: 1356
#include <stdio.h>
#define MAX 100000
void partition(int *,int,int);

int t;
int main(){
int i,n;
int A[MAX];

scanf("%d",&n);

for(i=0;i<n;i++){
    scanf("%d",&A[i]);
}

partition(A,0,n-1);

for(i=0;i<n-1;i++){
    if(i==t){
        printf("[%d] ",A[i]);
        continue;
    }
    printf("%d ",A[i]);
}
printf("%d\n",A[n-1]);

return 0;
}
//パーティション生成
void partition(int *A,int p,int r){

    int x,i,j,temp1,temp2;

    x=A[r];
    i=p-1;
    for(j=p;j<=r-1;j++){
        if(A[j]<=x){       
            i=i+1;
            temp1=A[i];
            A[i]=A[j];
            A[j]=temp1;
        }
    }
    t=i+1;
    temp2=A[i+1];
    A[i+1]=A[r];
    A[r]=temp2;


}




Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define SORT(i) sort((i).begin(),(i).end())
constexpr ll INF = 2000000000;
constexpr ll mod = 1000000007;

ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

int main() {
	int N, K;
	cin >> N >> K;
	unordered_map<int, int>ump;
	rep(i, N) {
		int a; cin >> a;
		ump[a]++;
	}
	vector<int>vec;
	for (auto p : ump) {
		auto a = p.second;
		vec.push_back(a);
	}
	SORT(vec);
	int ans = 0, k = vec.size() - K;
	if (k > 0) {
		rep(i, k)ans += vec[i];
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 10312