akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;  cin >> n;
  int cnt = 0;
  while(n--){
    int a;  cin >> a;
    for(int i=2; i*i<=a; i++)
      if(a % i == 0){
	cnt--;
	break;
      }
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3040
//package AtCoder.Nekkei;

import java.io.*;
import java.util.*;

class Main {
    
    public static void main(String[] args) {
    	Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int a = s.nextInt();
        int b = s.nextInt();
        System.out.println(Math.min(a,b) + " " + Math.max(0,(a+b-n)));
    }

}


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

int main(){
    int k;
    string s;
    cin >> k >> s;
    int len = s.size();
    if (len <= k) {
        cout << s <<endl;
    } 
    else {
        cout << s.substr(0,k) + "..." <<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int z = sc.nextInt();
                for (int zz = 0; zz < z; zz++) {
                        int xmin = sc.nextInt(), ymin = sc.nextInt();
                        int xmax = sc.nextInt() + xmin, ymax = sc.nextInt() + ymin;
                        int N = sc.nextInt();
                        int ans = 0;
                        for (int i = 0; i < N; i++) {
                                int x = sc.nextInt(), y = sc.nextInt();
                                if (xmin <= x && x <= xmax && ymin <= y && y <= ymax) {
                                        ans++;
                                }
                        }
                        System.out.println(ans);
                }
        }
}

Measured memory_bytes: 34556
import Control.Monad
main = do
  n <- readLn 
  ms <- replicateM n (words <$> getLine) :: IO [[String]]
  let f = foldl (\acc (d:u:_) -> if u == "JPY" then (r d)+acc else (r d)*380000.0+acc) 0.0 ms 
  print f 

r :: String -> Float
r s = read s :: Float

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>com;
    vector<int>jud;
    int comn,judn;
    cin >> comn;
    cin >> judn;
    vector<int>point(comn,0);
    for(int i = 0;i < comn;i++){
        int n;
        cin >> n;
        com.push_back(n);
    }
    for(int i = 0;i < judn;i++){
        int n;
        cin >> n;
        jud.push_back(n);
    }
    for(int i = 0;i < judn;i++){
        for(int j = 0;j < comn;j++){
            if(jud[i] >= com[j]){
                point[j]++;
                break;
            }
        }
    }
    int m = -9999;
    int yc;
    /*for(int i = 0;i < comn;i++){
        cout << point[i] << 'P' << endl;
    }*/
    for(int i = 0;i < comn;i++){
        if(point[i] > m){
            m = point[i];
            yc = i+1;
        }
    }
    cout << yc << endl;
    return 0;
}

Measured memory_bytes: 3160
#include<cstdio>
#define ll long long
using namespace std;
const int M = 1e9+7;
const int maxn = 3e5+4;
ll a[maxn];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    ll ans = 0;
    for(int i=0;i<60;i++)
    {
        ll k = 0;
        for(int j=1;j<=n;j++)
        {
            if((a[j]>>i)&1) k++;
        }
        ll t = 1LL<<i;
        t %= M;
        t = t*k%M;
        t = t*(n-k)%M;
        ans = (ans+t)%M;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
ll cnt_digit(ll a){
	ll x=0;
	while(a>0){
		a/=10;
		x++;
	}
	return x;
}

int main(){
	ll x;
	cin>>x;
	ll ans=x;
	for(ll i=1;i*i<=x;i++){
		if(x%i!=0)continue;
		ll b=x/i;
		ll y=max(cnt_digit(i),cnt_digit(b));
		ans=min(ans,y);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

main :: IO ()
main = do
    [_, m] <- readInts
    as <- readInts
    print $ solve m as

readInts :: IO [Int]
readInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

solve :: Int -> [Int] -> Int
solve m = sum
    . map (\x -> x * (x - 1) `div` 2)
    . map length
    . group
    . sort
    . map (`mod` m)
    . scanl' (+) 0

Measured memory_bytes: 13692
#include <iostream>
#include <map>

using namespace std;

int main()
{
    map<int, pair<int, int>> pos;

    for(int i=0, val; i<3; i++) {
        for(int j=0; j<3; j++) {
            cin >> val;

            pos[val] = {i, j};
        }
    }

    bool card[3][3] = {{0, 0, 0},{0, 0, 0},{0, 0, 0}};

    int q;
    cin >> q;

    for(int i=0, val; i<q; i++)
    {
        cin >> val;

        if(pos.count(val))
        {
            int x = pos[val].first;
            int y = pos[val].second;

            card[x][y] = true;
        }
    }

    bool bingo = false;

    bingo |= (card[0][0] && card[0][1] && card[0][2]);
    bingo |= (card[1][0] && card[1][1] && card[1][2]);
    bingo |= (card[2][0] && card[2][1] && card[2][2]);

    bingo |= (card[0][0] && card[1][0] && card[2][0]);
    bingo |= (card[0][1] && card[1][1] && card[2][1]);
    bingo |= (card[0][2] && card[1][2] && card[2][2]);

    bingo |= (card[0][0] && card[1][1] && card[2][2]);
    bingo |= (card[0][2] && card[1][1] && card[2][0]);

    cout << (bingo ? "Yes" : "No") << '\n';

    return 0;
}


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

bool solve(vector<int> &Z, int z, int M){
  M += 10;
  vector<vector<int> > dp(Z.size()+1, vector<int>(M*2 + 30, 0));
  int sum = 0;
  
  dp[0][M] = true;
  
  for(int i = 1; i <= Z.size(); i++){
    for(int j = -sum; j <= sum; j++){
      if(j + Z[i-1] <= M && dp[i-1][M + j]) dp[i][M + j + Z[i-1]] = true;
      if(j - Z[i-1] >= -M && dp[i-1][M + j]) dp[i][M + j - Z[i-1]] = true;
    }
    sum += Z[i-1];
  }

  return dp[Z.size()][M+z];
}

signed main(){

  string s;
  vector<int> X, Y;

  int x, y, now = 0, a = 0, b = 0;

  cin>>s;

  s += 'T';
  
  cin>>x>>y;

  for(now = 0; now < s.size(); now++){
    if(s[now] == 'F') x--;
    else break;
  }

  for(int i = now, count = 0, sum = 0; i <= s.size(); i++){
    if(s[i] == 'T'){
      if(count%2 == 0){
	X.push_back(sum);
	a += sum;
      } else {
	Y.push_back(sum);
	b += sum;
      }
      count++, sum = 0;
    } else sum++;
  }

  if(solve(X,x,a) && solve(Y,y,b)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 63304
#%%
s = list(input())
i = 0
ss = ''

while True:
    if i <= len(s) - 2:
        if s[i] == 'B' and s[i+1] == 'C':
            ss += 'D'
            i += 2
        else:
            ss += s[i]
            i += 1          
    else:
        ss += s[i]
        i += 1
    if i >= len(s):
        break
#print(ss)

a = 0
ans = 0
for i in range(len(ss)):
    if ss[i] == 'A':
        a += 1
    elif ss[i] == 'D':
        ans += a
    else:
        a = 0
print(ans)

#%%


Measured memory_bytes: 4840
#include <stdio.h>

int main(){
  long long int X, A, B, C;
  int i, j, k, cnt = 0;
  scanf("%ld%ld%ld%ld", &A, &B, &C, &X);
  for (i = 0; i <= A; i++) {
    for (j = 0; j <= B; j++) {
      for (k = 0; k <= C; k++) {
        if (500*i + 100*j + 50*k == X) {cnt++;}
      }
    }
  }
  printf("%d\n", cnt);

}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

typedef long long li;
typedef unsigned long long uli;
typedef pair<int, int> pii;
typedef long double ld;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fr first
#define sc second
#define pb push_back
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forb(i, n) for(int i = int(n) - 1; i >= 0; --i)
//#define x first
//#define y second

const int INF = 1e9;
const li INF64 = 4e18;
const int M = 100 + 10;
const int N = 100 * 1000 + 100;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = 3.14159265359;

li gcd(li a, li b) {
    return a == 0 ? b : gcd(b % a, a);
}

li dp[M][N];

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector<int> w(n), v(n);
    forn(i, n) {
        cin >> w[i] >> v[i];
    }

    fore(i, 1, n + 1) {
        fore(j, 1, m + 1) {
            dp[i][j] = dp[i - 1][j];
            if (j - w[i - 1] >= 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
            }
        }
    }

    cout << dp[n][m] << '\n';

}

Measured memory_bytes: 79360
import java.util.*;
import java.io.*;

public class Main {	

	private static void solve(){
		//Implement solution here.
		System.out.println(ni() * ni());
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 25364
#include <iostream>
#include <stdio.h>

int main() {
	int array[3];
	for (int i = 0; i < 3; i++) {
		scanf("%d", &array[i]);
	}
	int min = 300;

	for (int i = 0; i < 3; i++) {
		int sum = 0;
		for (int j = 0; j < 3; j++) {
			if (i != j) {
				sum += array[j];
			}
		}
		if (min > sum) {
			min = sum;
		}
	}
	printf("%d", min);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char s[15];
	scanf("%s",s);
	int n=strlen(s);
	int f=0;
	int sum=0;
	for(int i=0;i<n;i++){
		if(s[0]!='A'){
			f=1;
			break;
		}
		if(s[1]=='C'||s[n-1]=='C'){
			f=1;
			break;
		}
		else if(s[i]=='C'){
			sum++;
		}
		if(s[i]>'A'&&s[i]<'C'||s[i]>'C'&&s[i]<'Z'){
			f=1;
			break;
		}
	}
	if(sum==1&&f==0){
		printf("AC\n");
	}
	else printf("WA\n");
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

class G
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var n = h[0];
		var es = new int[h[1]].Select(_ => Read()).ToArray();

		var map = Array.ConvertAll(new int[n], _ => new List<int>());
		var map_r = Array.ConvertAll(new int[n], _ => new List<int>());
		foreach (var e in es)
		{
			map[e[0]].Add(e[1]);
			map_r[e[1]].Add(e[0]);
		}

		var u = new bool[n];
		var order = new int[n];
		var c = n;
		var gs = new int[n];
		var gi = 0;

		void Dfs(int v)
		{
			u[v] = true;
			foreach (var nv in map[v]) if (!u[nv]) Dfs(nv);
			order[--c] = v;
		}
		for (int v = 0; v < n; v++) if (!u[v]) Dfs(v);

		void Dfs_r(int v)
		{
			u[v] = true;
			foreach (var nv in map_r[v]) if (!u[nv]) Dfs_r(nv);
			gs[v] = gi;
		}
		Array.Clear(u, 0, n);
		foreach (var v in order) if (!u[v]) { gi++; Dfs_r(v); }

		Console.WriteLine(gi);
		Console.WriteLine(string.Join("\n", gs.Select((g, v) => (g, v)).GroupBy(_ => _.g, _ => _.v).OrderBy(g => g.Key).Select(g => g.ToArray()).Select(g => string.Join(" ", g.Prepend(g.Length)))));
	}
}


Measured memory_bytes: 188812
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
#include <iostream>
using namespace std;

/* 入力 */

int main() {
  int n;cin>>n;
  string s; cin>>s;
  int count=1;
  for(int i=0;i<n-1;i++)
  if(s[i]!=s[i+1])count++;

  cout<<count<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define N_MAX 100000
#define M_MAX 100000
#define INF 10000000
#define SMAP(a, b) ((a)!=(b))&&((a)^=((b)^=((a)^= (b))))

typedef unsigned long long ull;
typedef   signed long long dll;

int balls[N_MAX];
bool b[N_MAX];
int n, m;

int i, j, k;

typedef struct {
	int in;
	int out;
} twoway;

twoway x[M_MAX];

void deb(){
	return;
}

void solve(){
	int result = 0;

	for (i = 0; i < n; i++) {
		balls[i] = 1;
		b[i] = !i;
	}

	for (i = 0; i < m; i++) {
		balls[x[i].in]--;
		balls[x[i].out]++;

		if (b[x[i].in]) b[x[i].out] = 1;
		if (!balls[x[i].in]) b[x[i].in] = 0;
	}

	for (i = 0; i < n; i++) {
		if (b[i]) result++;
	}
	printf("%d\n", result);
	return;
}

int main (void) {
	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d%d", &x[i].in, &x[i].out);
		x[i].in--;
		x[i].out--;
	}

		// puts("deb line A");

	solve();
	return 0;
}




Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

int n;
int done[100005];
int xp;
int yp;
pair<int,int> x[100005];
pair<int,int> y[100005];
int ep;
pair<int, pair<int,int> > edge[200010];


int union_data[100005];
int union_weight[100005];

void union_init(int n){
  for(int i=0;i<n;i++){
    union_data[i] = i;
    union_weight[i] = 1;
  }
}

int union_root(int x){
  int tmp = x;
  while(x!=union_data[x]){
    x = union_data[x];
  }
  while(tmp != union_data[tmp]){
    tmp = union_data[tmp];
    union_data[tmp] = x;
  }
  return x;
}

bool union_eq(int x,int y){
  return union_root(x) == union_root(y);
}

int union_join(int x, int y){
  if(union_eq(x,y)) return 0;
  if(union_weight[y] > union_weight[x]){
    union_weight[union_root(x)] += union_weight[union_root(y)];
    union_data[union_root(y)] = union_root(x);
  } else {
    union_weight[union_root(y)] += union_weight[union_root(x)];
    union_data[union_root(x)] = union_root(y);
  }
  return 0;
}

int union_size(int x){
  return union_weight[union_root(x)];
}

int main(){
  cin>>n;
  union_init(n);
  for(int i=0;i<n;i++){
    int xx,yy;cin>>xx>>yy;
    x[xp++] = make_pair(xx,i);
    y[yp++] = make_pair(yy,i);
  }
  sort(x,x+xp);
  sort(y,y+yp);
  for(int i=1;i<n;i++){
    edge[ep++] = make_pair(x[i].first-x[i-1].first, make_pair(x[i].second,x[i-1].second));
    edge[ep++] = make_pair(y[i].first-y[i-1].first, make_pair(y[i].second,y[i-1].second));
  }
  sort(edge,edge+ep);
  long long ans = 0;
  for(int i=0;i<ep;i++){
    //cout<<edge[i].second.first<<" "<<edge[i].second.first<<" "<<edge[i].first<<endl;
    if(!union_eq(edge[i].second.first,edge[i].second.second)){
      union_join(edge[i].second.first,edge[i].second.second);
      ans += (long long)edge[i].first;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  vector<int> a(n+1); rep(i,n+1) cin >> a[i];
  vector<int> b(n); rep(i,n) cin >> b[i];

  ll ans = 0;
  if(b[0]>=a[0]){
    ans+=a[0];
    b[0]-=a[0];
    a[0]=0;
  }
  else{
    ans+=b[0];
    b[0]=0;
  }
  
  for(int i = 1;i<n;i++){
    if(a[i]<=b[i-1]){
      ans += a[i];
      b[i-1] -= a[i];
      a[i]=0;
    }
    else{
      ans+=b[i-1];
      a[i] -= b[i-1];
      b[i-1] = 0;
    }
    if(a[i]<=b[i]){
      ans+=a[i];
      b[i] -= a[i];
      a[i]=0;
    }
    else{
      ans+=b[i];
      a[i] -= b[i];
      b[i] = 0;
    }
  }
  if(a[n]<=b[n-1]){
    ans+=a[n];
    b[n-1] -= a[n];
    a[n] = 0;
  }
  else{
    ans+=b[n-1];
    a[n]-=b[n-1];
    b[n-1]=0;
  }
  
  /*cout << "a" << endl;
  rep(i,n+1){
    cout << a[i] << " ";
  }
  cout << endl << "b" << endl;
  rep(i,n){
    cout << b[i] << " ";
  }
  cout << endl;
  */
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int N;
char s[40],a[40],b[40],c[40],d[40];
int cnt,dnt;
ll ans;
ll f[40][40];
/**
    f[i][j]表示 c前i个，d前j个的构成方法
    f[i][j]=f[i-1][j]*(c[i]==b[i+j])+f[i][j-1]*(d[j]==b[i+j])
*/
void dp() {
    memset(f,0,sizeof f);
    f[0][0]=1;
    for(int i=0;i<=cnt;++i)
        for(int j=0;j<=dnt;++j) if(i+j)
            f[i][j]=f[i-1][j]*(c[i]==b[i+j])+f[i][j-1]*(d[j]==b[i+j]);//,printf("f[%d][%d]=%lld\n",i,j,f[i][j]);
    ans+=f[cnt][dnt];
}
int main() {
    scanf("%d",&N);
    scanf("%s",s+1);
    for(int i=1;i<=N;++i) a[i]=s[i],b[i]=s[N+N+1-i];
    //puts(a+1);puts(b+1);
    for(int i=0;i<(1<<N);++i) {
        dnt=cnt=0;
        for(int j=0;j<N;++j) {
            if((1<<j)&i) c[++cnt]=a[j+1];
            else    d[++dnt]=a[j+1];
        }
        //printf("color=%d\n",i);
        //for(int i=1;i<=cnt;++i) printf("%c",c[i]);puts("");
        //for(int i=1;i<=dnt;++i) printf("%c",d[i]);puts("");
        dp();
        //cout<<f[cnt][dnt]<<endl;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n, x;
  cin >> n >> x;
  
  ll sum = 0;
  ll m = INF;
  for (int i = 0; i < n; i++){
    ll a;
    cin >> a;
    
    m = min(m, a);
    sum += a;
  }

  cout << n + (x - sum) / m << endl;

  return 0;
}


Measured memory_bytes: 3632
program main
implicit none
integer :: n
integer , allocatable :: a(:), b(:)
integer :: i, j, s

read(*,*) n
allocate( a(n) )
allocate( b(n) )
do i = 1, n
   read(*,*) a(i), b(i)
end do
call quicksort(n, b, a, 1, n)
s = 0.
do i = 1, n
   s = s + a(i)
   if(s .gt. b(i) ) then
      write(*,*) 'No'
      stop
   end if
end do
write(*,*) 'Yes'

stop
contains
recursive subroutine quicksort(n, a, b, first, last)
  implicit none
  integer :: a(n), b(n)
  integer :: first, last
  integer ::  i, j, n
  integer ::  x, y, t, s
  
  x = a( (first+last) / 2 )
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i)
    a(i) = a(j)
    a(j) = t
    s = b(i)
    b(i) = b(j)
    b(j) = s
    i=i+1
    j=j-1
  end do
  if (first < i - 1) call quicksort(n, a, b, first, i - 1)
  if (j + 1 < last)  call quicksort(n, a, b, j + 1, last)
end subroutine quicksort
end program main


Measured memory_bytes: 1792
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<string,int> a, const pair<string,int> b) {
  if (a.first != b.first)
    return a.first < b.first; // 高い順に並べたいので演算子を逆に
  else{
      return a.second > b.second;
  }
}

int Dx[6] = { 0, 0, 1, 1,-1,-1};
int Dy[6] = { 1,-1, 1, 0, 0,-1};

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;
int main(){

    int t,n;
    vector<int> ansList;

    cin >>t>>n;

    while(!(t == 0 && n == 0)){
        int map[200][200] = {0};
        int boolmap[200][200] = {0};
        queue<pair<int,int> > BFSQ;
        queue<int> Turn;
        int ans = 0;

        for(int i = 0;i<n;i++){
            int x,y;
            cin >>x>>y;
            boolmap[x + 100][y + 100] = 1;
        }

        int sx,sy;
        cin >>sx>>sy;
        BFSQ.push(make_pair(sx+100,sy+100));
        Turn.push(0);

        while(!BFSQ.empty()){
            pair<int,int> pos;
            long int turnNum = Turn.front();
            Turn.pop();
            pos = BFSQ.front();
            BFSQ.pop();

            if(turnNum > t || map[pos.first][pos.second] == -1 || boolmap[pos.first][pos.second] == 1 )continue;
            ans++;

            for(int i = 0;i<6;i++){
                /*if(pos.first + Dx[i] > 60 || pos.second + Dy[i] > 60 || pos.second + Dy[i] < 0 || pos.first + Dx[i] < 0 )continue;*/
                /*if(boolmap[pos.first + Dx[i]][pos.second + Dy[i]] == 0){*/
                    BFSQ.push(make_pair(pos.first + Dx[i],pos.second + Dy[i]));
                    Turn.push(turnNum+1);
                /*}*/
            }
            map[pos.first][pos.second] = -1;
        }
        ansList.push_back(ans);
        cin >>t>>n;
    }

    for(int i = 0;i<(int)ansList.size();i++){
        cout <<ansList[i]<<endl;
    }
    return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

*/


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

int main() {
  string S;
  cin >> S;

  for (int bit = 0; bit<8; bit++) {
    int ans = S[0] - '0';
    for (int i = 0; i < 3; i++) {
      if(bit & (1<<i)){		//bit ni ibanme no flag aru?
        ans += S[i+1] - '0';
      } else{
        ans -= S[i+1] - '0';
      }
    }
    if(ans==7){
      string Sans ="0-0-0-0=7";      			
      for(int i=0;i<4;i++)Sans[i*2]=S[i];	
      for(int i=0;i<3;i++){
        if(bit & (1<<i)){
          Sans[1+(i*2)]='+';
        }
      }
      cout << Sans << endl; 
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <functional>
#include <iomanip>
using namespace std;
	
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>

using ll = long long;
ll INF = LLONG_MAX / 4 - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
	
class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
	
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

bool solve() {
    string s; cin >> s;
    vi R,L;
    REP (i,s.size()) {
        if (s[i] == 'L') {
            L.pb(i);
        } else {
            R.pb(i);
        }
    }
    int n = s.size();
    int cnt[n]; REP (i,n) cnt[i] = 0;
    REP (i,n) {
        if (s[i] == 'R') {
            int pos = *upper_bound(ALL(L),i);
            if ((pos-i)%2==0) {
                cnt[pos]++;
            } else {
                cnt[pos-1]++;
            }
        } else {
            auto it = upper_bound(ALL(R),i);
            --it;
            int pos = *it;
            if ((i-pos)%2==0) {
                cnt[pos]++;
            } else {
                cnt[pos+1]++;
            }
        }
    }
    REP (i,n) cout << cnt[i] << " "; cout << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}


Measured memory_bytes: 2372
n = gets.to_i
a = []
x = []
y = []

n.times do |i|
  a << gets.to_i
  xa = []
  ya = []

  a[i].times do |j|
    xtmp, ytmp = gets.split.map(&:to_i)
    xa << xtmp
    ya << ytmp
  end
  x << xa
  y << ya
end

def solve(n, a, x, y, i)
  # puts "case #{i}"
  n.times do |ni|
    next if i[ni] == '0'

    a[ni].times do |ai|
      xij = x[ni][ai]

      # puts "#{i[xij-1]} != #{y[ni][ai]}"
      if i[xij-1] != y[ni][ai].to_s
        return -1
      end
    end
  end

  i.count('1')
end

max = 0
(2**n).times do |i|
  max = [max, solve(n, a, x, y, sprintf("%0#{n}b", i))].max
end

puts max


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

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N,A,B;
  cin >>N >>A >>B;
  int total=0;
  for (int i=1; i <=N; ++i) {
    int sum = findSumOfDigits(i);
    if (sum >= A && sum <=B) {
      total += i;
    }
  }
  cout << total << endl;
}
      

Measured memory_bytes: 256
function GCD() {
  loop='n?(tmp=n,n=m%n,m=tmp,loop):m'
  echo $((m=$1>$2?$1:$2,n=$1^$2^m,loop))
}

function LCM() {
  echo $((($1*$2)/$(GCD $1 $2)))
}

read A B C D
echo $((
  A--,
  lcm=$(LCM $C $D),
  (B-A)-((B/C-A/C)+(B/D-A/D)-(B/lcm-A/lcm))
))

Measured memory_bytes: 632
def main():
    K = int(input())
    from math import gcd
    total = 0
    for a in range(1, K+1):
        for b in range(1, K+1):
            ab = gcd(a, b)
            if ab == 1:
                total += K
            else:
                for c in range(1, K+1):
                    total += gcd(ab, c)
    print(total)

main()


Measured memory_bytes: 9188
def actual(n, t, a, H):
    avg_temperture = lambda height: t - (height * 0.006)
    diff_a = lambda avg_temperture: abs(avg_temperture - a)

    temperature_diffs = [diff_a(avg_temperture(h)) for h in H]

    return temperature_diffs.index(min(temperature_diffs)) + 1

n = int(input())
t, a = map(int, input().split())
H = map(int, input().split())

print(actual(n, t, a, H))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int N, K;
int x[110];

int main(void) {
	cin >> N >> K;
	rep(i, N) cin >> x[i];
	ll ans = 0;
	rep(i, N) {
		int d1 = x[i] * 2;
		int d2 = abs(x[i] - K) * 2;
		ans += min(d1, d2);
	}
	cout << ans << endl;
	return 0;
}

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

string s;
deque<char> dq;

int main(void)
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios::sync_with_stdio(false);

	int q, i, sts = 0;

	cin >> s >> q;

	for (i = 0; i < s.size(); i++)
		dq.push_back(s[i]);

	while (q--)
	{
		char add;
		int cmd, opt;

		cin >> cmd;

		if (cmd == 1)
			sts ^= 1;
		else
		{
			cin >> opt >> add;
			--opt;

			if (sts ^ opt)
				dq.push_back(add);
			else
				dq.push_front(add);
		}
	}

	if (sts)
		for (i = dq.size() - 1; i >= 0; i--)
			cout << dq[i];
	else
		for (i = 0; i < dq.size(); i++)
			cout << dq[i];
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int H, W; cin >> H >> W;
  int A[H][W]; rep(i,H) rep(j,W) cin >> A[i][j];
  int B[H][W]; rep(i,H) rep(j,W) cin >> B[i][j];
  int diff[H][W]; rep(i,H) rep(j,W) diff[i][j] = abs(A[i][j]-B[i][j]);
  bool dp[H][W][10000] = {};
  rep(h,H) rep(w,W) {
    if (h==0&&w==0) dp[h][w][diff[h][w]] = true;
    if (h!=0) {
      rep(i,10000) {
        if (i+diff[h][w]<10000) dp[h][w][i+diff[h][w]] |= dp[h-1][w][i];
        dp[h][w][abs(i-diff[h][w])] |= dp[h-1][w][i];
      }
    }
    if (w!=0) {
      rep(i,10000) {
        if (i+diff[h][w]<10000) dp[h][w][i+diff[h][w]] |= dp[h][w-1][i];
        dp[h][w][abs(i-diff[h][w])] |= dp[h][w-1][i];
      }
    }
  }
  // rep(i,10) cout << dp[H-1][W-1][i] << endl;
  int result = 0;
  while (!dp[H-1][W-1][result]) result++;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 62848
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int K, X;
  cin >> K >> X;
  for (int i = X - K + 1; i < X + K; i++) {
    cout << i << " ";
  }
  cout << "\n";
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

int n;
int h[100010];
int memo[100010];

int dp(int i) {

  if( i < 1 ) return INF;
  if( i == 1 ) return 0;
  if( memo[i] != -1 ) return memo[i];

  int a1 = dp(i - 1) + abs(h[i-1] - h[i]);
  int a2 = dp(i - 2) + abs(h[i-2] - h[i]);

  memo[i] = min(a1, a2);

  return memo[i];
}

signed main()
{
  cin.tie(0); ios::sync_with_stdio(false);

  memset(memo, -1, sizeof(memo));

  cin >> n;

  reps(i, 1, n) cin >> h[i];

  cout << dp(n) << endl;

  return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for (int i = 0; i < n; i++)
#define Rep(i,n) for (int i = n; i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define cend cout<<endl;
#define P pair<int, int>
#define prique priority_queue<P, vector<P>, greater<P>>
struct edge { int to, cost; };
using namespace std;
double n, k;
double ans = 0.0;
int how(double n) {
	int ans = 0.0;
	while (n < k) {
		n *= 2.0;
		ans += 1.0;
	}
	return ans;
}
signed main() {
	cin >> n >> k;
	for (int i = 1; i <= (int)n; i++) {
		ans += 1.0 / n / pow(2.0L, how(i));
	}
	printf("%.20Lf\n", ans);
}


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

int main(){
  int A,B;
  cin>>A>>B;
  if (A%3==0||B%3==0||(A+B)%3==0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}


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

int main() {
  int x,y;
  cin>>x>>y;
  if((y-2*x) % 2 == 0 && (y-2*x)>=0 && (4*x-y) %2 ==0 && (4*x-y)>=0)
    cout << "Yes" << endl;
  else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(){
  char x,h;
  cin >> x;
  switch(x){
    case 'A':h='T';break;
    case 'T':h='A';break;
    case 'C':h='G';break;
    case 'G':h='C';break;
  }
  cout << h << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;    
  
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define rev reverse
#define mp make_pair
#define all(x) x.begin(), x.end()
#define ll long long
#define ull unsigned long long
#define sz(x) (int)x.size()
/*
string lower(string a) {
    for(int i=0;i<a.size();i++) {
        a[i]=tolower(a[i]);
    }
    return a;
}
ll nod(ll a,ll b) {
    if(a==0)
        return b;
    else if(b==0)
        return a;
    if(a>=b)
        return nod(a%b,b);
    else if(a<=b)
        return nod(a,b%a);
}
ll nok(ll x, ll y) {
    return x/nod(x,y)*y;
} 
*/
const ll INF = 1e9+7;
int main() {
//  freopen("measurement.in", "r", stdin);
//  freopen("measurement.out", "w", stdout);
    IOS	
    set<ll> st;
    ll a, b, c;
    cin >> a >> b >> c;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    if(st.size() == 2) {
    	cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
} 	 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<double> x(n);
    for(int i=0; i<n; i++){
        cin >> x[i];
    }
    for(int i=0; i<n; i++){
        double y;
        cin >> y;
        x[i] = abs(x[i] -y);
    }

    double s1=0, s2=0, s3=0, sinf=0;
    for(int i=0; i<n; i++){
        s1 += x[i];
        s2 += x[i]*x[i];
        s3 += x[i]*x[i]*x[i];
        sinf = max(sinf, x[i]);
    }
    s2 = sqrt(s2);
    s3 = cbrt(s3);
    cout << fixed << setprecision(10);
    cout << s1 << endl << s2 << endl << s3 << endl << sinf << endl;
    return 0;
}


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

a.sort(reverse=True)
ideal = a[0]//2
dif_mn = 10**9

for i in range(1,n):
    tmp = a[0]-a[i] if a[i] > ideal else a[i]
    dif = ideal-tmp
    if dif < dif_mn:
        r = a[i]
        dif_mn = dif

print(a[0], r)


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);

    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    int count = 0;
    bool br = true;

    while (true) {

        for (int i = 0; i < N; i++) {
            if (A.at(i) % 2 != 0) {
                br = false;
                break;
            }
            else {
                A.at(i) /= 2;
            }
        }

        if (br) {
            count++;
        }
        else {
            break;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

const string mcxi = "mcxi";
bool isNum(char c){return '0' <= c && c <= '9';}
int c2i(char c){return c - '0';}

void solve() {
	string lhs, rhs;
	cin>>lhs>>rhs;
	int sum[4];
	memset(sum, 0, sizeof sum);

	// lhs
	int bef = 1;
	for (int i = 0; i < lhs.size(); i++) {
		if (isNum(lhs[i])) {
			bef = c2i(lhs[i]);
		} else {
			sum[mcxi.find(lhs[i])] += bef;
			bef = 1;
		}
	}
	bef = 1;
	// rhs
	for (int i = 0; i < rhs.size(); i++) {
		if (isNum(rhs[i])) {
			bef = c2i(rhs[i]);
		} else {
			sum[mcxi.find(rhs[i])] += bef;
			bef = 1;
		}
	}
	// advance
	for (int i = 3; i > 0; i--) {
		if (sum[i] > 9) {
			sum[i-1] += sum[i] / 10;
			sum[i] %= 10;
		}
	}
	// print
	for (int i = 0; i < 4; i++) {
		if (sum[i] == 0) continue;
		if (sum[i] != 1) cout<<sum[i];
		cout<<mcxi[i];
	}
	cout<<endl;
}

int main(int argc, const char *argv[]) {
	int n; cin>>n;
	rep(i,n) solve();
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 

int main()
{
	int n,s=0,t;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t;
		if(i%2!=0&&t%2!=0)s++;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>

int main()
{
    int n, m;
    while (scanf("%d%d", &n, &m), n)
    {
        int ans = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = i + 1; j <= n; j++)
            {
                int k = m - i - j;
                if (j < k && k <= n)
                    ans++;
            }
        }
        printf("%d\n", ans);
    }
}



Measured memory_bytes: 2104
import java.util.*;

public class Main {
	public String check( int pm , int pe , int pj ) {
		if ( pm == 100 || pe == 100 || pj == 100 ) return "A";
		int ave = ( pm + pe ) / 2;
		if ( ave >= 90 ) return "A";
		ave = ( pm + pe + pj ) / 3;
		if ( ave >= 80 ) return "A";
		if ( ave >= 70 ) return "B";
		if ( ave >= 50 && ( pm >= 80 || pe >= 80 ) ) return "B";
		else return "C";
	}
	
	public static void main ( String[] args ) {
		int pm , pe , pj;
		Main m = new Main();
		Scanner sc = new Scanner(System.in);
		while ( !sc.hasNext("0") ) {
			int n = sc.nextInt();
			for ( int i = 0; i < n; i++ ) {
				pm = sc.nextInt();
				pe = sc.nextInt();
				pj = sc.nextInt();
				System.out.println(m.check(pm, pe, pj));
			}
		}
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <array>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <numeric>
using namespace std;

#define REP(i, a, b) for(int i = (a); i < int(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

enum FACE { TOP, BOTTOM, NORTH, SOUTH, WEST, EAST };

struct dice {
	array<int, 6> num;

	inline void roll(FACE a, FACE b, FACE c, FACE d) {
		const int tmp = num[a];
		num[a] = num[b];
		num[b] = num[c];
		num[c] = num[d];
		num[d] = tmp;
	}

	dice(const array<int, 6> &t):num(t) {}
	dice(const dice &die):num(die.num) {}

	inline int sum() const {
		return accumulate(ALL(num), 0);
	}

	inline bool check(int a, int s) const {
		return a <= s - a;
	}

	inline bool can_reach() const {
		const int s = sum();
		return check(num[TOP] + num[BOTTOM], s)
			&& check(num[NORTH] + num[SOUTH], s + 1)
			&& check(num[EAST] + num[WEST], s + 1);
	}
};

inline void north(dice &die) { die.roll(TOP, SOUTH, BOTTOM, NORTH); }
inline void south(dice &die) { die.roll(TOP, NORTH, BOTTOM, SOUTH); }
inline void east (dice &die) { die.roll(TOP,  WEST, BOTTOM,  EAST); }
inline void west (dice &die) { die.roll(TOP,  EAST, BOTTOM,  WEST); }

const string IMPOSSIBLE = "impossible";

void solve(dice die, string &ans) {
	if(!die.can_reach()) return;

	const array<function<void(dice&)>, 4> f{{&east, &north, &south, &west}};
	const string s = "ENSW";

	string res = "";
	bool better = (ans == IMPOSSIBLE);

	for(int i = 0; die.sum(); ++i) {
		rep(d, 4) {
			dice next(die);
			f[d](next);
			if(--next.num[BOTTOM] < 0) continue;
			if(next.can_reach()) {
				die = move(next);
				res += s[d];
				break;
			}
		}

		if(!better) {
			if(ans[i] < res[i]) {
				return;
			}
			else if(ans[i] > res[i]) {
				better  = true;
			}
		}
	}
	ans = move(res);
}

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

	while(true) {
		array<int, 6> t;
		for(auto &e : t) cin >> e;

		if(none_of(ALL(t), [](int x) { return x; })) break;

		sort(ALL(t));
		string ans = IMPOSSIBLE;
		do {
			solve(dice(t), ans);
		} while(next_permutation(ALL(t)));

		int p, q;
		cin >> p >> q;

		cout << (ans == IMPOSSIBLE ? IMPOSSIBLE : ans.substr(p - 1, q - p + 1)) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1304
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  int c[3][3];
  for (int i = 0; i < 9; i++) {
    cin >> c[i / 3][i % 3];
  }

  int b2 = c[0][1] - c[0][0];
  int b3 = c[0][2] - c[0][0];
  for (int i = 1; i < 3; i++) {
    if (b2 != (c[i][1] - c[i][0]) || b3 != (c[i][2] - c[i][0])) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


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

int main(){
	int x1, y1, x2, y2, x3, y3, x4, y4, dx, dy;
	cin >> x1 >> y1 >> x2 >> y2;
	dx = x2 - x1;
	dy = y2 - y1;
	x3 = x2 - dy;
	y3 = y2 + dx;
	x4 = x3 - dx;
	y4 = y3 - dy;
	cout << x3 << " " <<  y3 << " " <<  x4 << " " << y4 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1
#define N 100005
 struct Node{
   int p,l,r;
 };

   struct Node T[N];

int depth(int);
void child(int);
int main(){
  int id,k,c,m;
  int i,j;
  int n;

  scanf("%d",&n);
  for(i=0; i < n; i++){
    T[i].p=NIL;
    T[i].l=NIL;
    T[i].r=NIL;
  }

  for(i=0; i < n; i++){
    scanf("%d%d",&id,&k);
    for(j=0; j < k; j++){
      scanf("%d",&c);
      T[c].p=id;
      if(j==0){
	T[id].l=c;
      }

      else{
	T[m].r=c;
      }
      m=c;
    }
  }

  for(i=0; i < n; i++){
    printf("node %d: parent = %d, depth = %d, ", i,T[i].p,depth(i));
    if(T[i].p==NIL){
      printf("root, [");
    }

    else if(T[i].l==NIL){
      printf("leaf, [");
    }

    else{
      printf("internal node, [");
    }

    child(i);
  }

  return 0;
}

int depth(int u){
  int d=0;
  while(T[u].p!=NIL){
    u=T[u].p;
    d++;
  }
  return d;
}

void child(int u){
  int c=T[u].l;
  while(c!=NIL){
    printf("%d",c);
    c=T[c].r;
    if(c!=NIL){
      printf(", ");
    }
  }
  printf("]\n");
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
#define ll long long int 
#define fori(i,n) for(int i=0; i<n; ++i)
#define ford(i,n) for(int i=n-1; i>=0; --i)
#define vi vector<int> 
#define vs vector<string>
#define vll vector<ll>
#define di deque<int>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
#define mod1 1000000007
#define mod2 998244353
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gcd __gcd

//Printing template
#define pf2(a,b) cout<<a<<" "<<b<<"\n"
#define pf3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define pf4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"

#define fast_cin() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> i_set;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ll_set; 
/* new_data_set p; */
/* *p.find_by_order(3); The value at third place */
/* p.order_of_key(7); The expected index in the set in sorted order */

bool sortbysec(pair<ll,ll> &p1, pair<ll, ll> &p2){
    return (p1.se<p2.se);
}

int main(int argc, char const *argv[]){
    fast_cin();
    ll h,n;
    cin>>h;
    n=log2(h);
    cout<<(ll)pow(2,n+1)-1<<"\n";
    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }

const int maxn = 3000 + 7;

string s;
string t;
int ns;
int nt;

int dp[maxn][maxn]; // max length using up to i-chars in s and j-chars in t
pair<int,int> prv[maxn][maxn];

int main() {

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

    cin >> s >> t;
    ns = s.size();
    nt = t.size();

    for (int i = 1; i <= ns; i++) {
        for (int j = 1; j <= nt; j++) {
            if (s[i-1] == t[j-1]) {
                if (dp[i][j] < 1 + dp[i-1][j-1]) {
                    dp[i][j] = 1 + dp[i-1][j-1];
                    prv[i][j] = make_pair(i-1,j-1);
                }
            }
            if (dp[i][j] < dp[i-1][j-1]) {
                dp[i][j] = dp[i-1][j-1];
                prv[i][j] = make_pair(i-1,j-1);
            }
            if (dp[i][j] < dp[i-1][j]) {
                dp[i][j] = dp[i-1][j];
                prv[i][j] = make_pair(i-1,j);
            }
            if (dp[i][j] < dp[i][j-1]) {
                dp[i][j] = dp[i][j-1];
                prv[i][j] = make_pair(i,j-1);
            }
        }
    }

    string ans = "";
    int i = ns;
    int j = nt;
    while (i > 0 && j > 0) {
        if (s[i-1] == t[j-1]) {
            ans += s[i-1];
        }
        auto p = prv[i][j];
        i = p.first;
        j = p.second;
    }

    reverse(ans.begin(), ans.end());
    out(ans);
    
    
    
    return 0;
}


Measured memory_bytes: 106112
use std::collections::HashMap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let n: i32 = read_line().parse()?;
    
    let mut counts = HashMap::new();
    counts.insert("AC", 0);
    counts.insert("WA", 0);
    counts.insert("TLE", 0);
    counts.insert("RE", 0);

    for _ in 0..n {
        let s = read_line();
        let v = counts.get_mut(s.as_str()).unwrap();
        *v += 1;
    }

    for s in ["AC", "WA", "TLE", "RE"].iter() {
        println!("{} x {}", s, counts[s]);
    }
    Ok(())
}

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


Measured memory_bytes: 2196