akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;

#define INF 0x7fffffffffffff

typedef long long int LLI;

int N;
LLI as[314514];
LLI lsum[314514];
LLI rsum[314514];

int main() {
  scanf("%d", &N);
  for (int i=0; i<3*N; i++) {
    scanf("%lld", &as[i]);
  }

  multiset<LLI> st;
  for (int i=0; i<N; i++) {
    st.insert(as[i]);
    lsum[0] += as[i];
  }

  for (int i=N; i<N*2; i++) {
    st.insert(as[i]);
    lsum[i-N+1] = lsum[i-N] + as[i] - *st.begin();
    st.erase(st.begin());
  }

  st.clear();
  for (int i=2*N; i<3*N; i++) {
    st.insert(as[i]);
    rsum[N] += as[i];
  }

  for (int i=N*2-1; i>=N; i--) {
    st.insert(as[i]);
    rsum[i-N] = rsum[i-N+1] + as[i] - *st.rbegin();
    st.erase(next(st.rbegin()).base());
  }

  LLI ans = -INF;
  for (int i=0; i<=N; i++) {
    ans = max(ans, lsum[i] - rsum[i]);
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 10880
<?php

fscanf(STDIN,"%d %d",$a,$b);

if(($a+$b)%3 == 0) {
   echo 'Possible';
}else if ($a%3 == 0 ){
   echo 'Possible';   
}else if ($b%3 == 0 ){
   echo 'Possible';   
}else{
   echo 'Impossible';
}

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,p;
    set<int>s;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        s.insert(a);
    }
    p=s.size();
    cout<<p<<endl;
    return 0;
}


Measured memory_bytes: 256
main:: IO ()
main = do
    [a,b] <- (map read . words) <$> getLine
    putStrLn $ solve (a,b)

-- |
--
-- >>> solve (4,5)
-- "Possible"
--
-- >>> solve (1,1)
-- "Impossible"
solve :: (Int, Int) -> String
solve (a,b)
  | any (\x -> x `mod` 3 == 0) [a, b, a+b] = "Possible"
  | otherwise = "Impossible"


Measured memory_bytes: 508
n=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

sat = 0
prev_ryouri = -10

for i in range(n):
  ryouri = A[i] - 1
  sat += B[ryouri]
  if prev_ryouri+1 == ryouri:
    sat += C[prev_ryouri]
    
  prev_ryouri = ryouri


print(sat)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);



int main(){
	ll a,b;
	cin>>a>>b;
	ll miin=100000;
	ll t1,t;
	FOR(i,1,1256){
		t=i*0.08;
		t1=i*0.1;
		if(t==a&&t1==b) miin=min(miin,i);
	}
	if(miin<100000)cout<<miin<<endl;
    else cout<<-1<<endl;

    
}

Measured memory_bytes: 256
#include <cstdio>

int main() {
	int n;
	scanf("%d", &n);
	int ans = 0;
	for(int i = n; i <= 999; i++) {
		if(i % 111 == 0) {
			ans = i;	
			break;
		}
	}

	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
import java.io.*;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader =
            new BufferedReader(new InputStreamReader(System.in));

        String[] line = reader.readLine().split(" ");
        int inputA = Integer.parseInt(line[0]);
        int inputB = Integer.parseInt(line[1]);

        if (inputA < inputB) {
            System.out.println("a < b");
        } else if (inputA > inputB) {
            System.out.println("a > b");
        } else {
            System.out.println("a == b");
        }
    }
}

Measured memory_bytes: 24120
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=200010;
const int inf=2147483647;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
LL n,a[Maxn],f[Maxn],g[Maxn];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	f[0]=g[n+1]=0;
	LL o=0;
	for(int i=1;i<=n;i++)
	{
		o+=a[i];
		f[i]=min(f[i-1]+(a[i]&1)+(a[i]==0?2:0),o);
	}
	for(int i=1;i<=n;i++)f[i]=min(f[i-1]+(!(a[i]&1)),f[i]);
	o=0;
	for(int i=n;i;i--)
	{
		o+=a[i];
		g[i]=min(g[i+1]+(a[i]&1)+(a[i]==0?2:0),o);
	}
	LL ans=inf;
	for(int i=0;i<=n;i++)ans=min(ans,f[i]+g[i+1])/*,printf("%d %lld %lld\n",i,f[i],g[i+1])*/;
	printf("%lld",ans);
}

Measured memory_bytes: 4992
import math

def A():
    x, a, b = [int(x) for x in input().split()]
    if abs(x-a) < abs(x-b):
        print('A')
    else:
        print('B')
def B():
    S = input()
    alphabet = [False for x in range(26)]
    for char in S:
        i = ord(char) - ord('a')
        alphabet[i] = True
    printed = False
    for i in range(len(alphabet)):
        if alphabet[i] == False:
            print(chr(ord('a')+i))
            printed = True
            break
    if printed == False:
        print("None")
def C():
    n = int(input())
    three = 0

B()


Measured memory_bytes: 3316
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const int hand_r = 0; // stone
const int hand_s = 1; // ceaser
const int hand_p = 2; // paper

int N, K, R, S, P;
vector<vector<int>> dp;
vector<int> T;

int calc_cur_turn_point(const int me, const int opposite) {
    if (me == hand_r && opposite == hand_s) {
        return R;
    } else if (me == hand_s && opposite == hand_p) {
        return S;
    } else if (me == hand_p && opposite == hand_r) {
        return P;
    } else {
        return 0;
    }
}

int main(void) {
    cin >> N >> K;
    cin >> R >> S >> P;

    T.resize(N + 1);
    for (int i = 1; i <= N; i++) {
        char c;
        cin >> c;
        if (c == 'r') {
            T[i] = hand_r;
        } else if (c == 's') {
            T[i] = hand_s;
        } else if (c == 'p') {
            T[i] = hand_p;
        }
    }

    dp.resize(N + 1, vector<int>(3, -1));
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;

    for (int i = 1; i <= N; i++) {
        const int opposite_hand = T[i];

        for (int j = 0; j < 3; j++) {
            const int my_hand = j;
            const int cur_turn_point = calc_cur_turn_point(my_hand, opposite_hand);
            if (i <= K) {
                chmax(dp[i][j], cur_turn_point);
            } else {
                for (int k = 0; k < 3; k++) {
                    if (j == k) continue;
                    chmax(dp[i][j], dp[i - K][k] + cur_turn_point);
                }
            }
        }
    }

    // for (int i = 0; i <= N; i++) {
    //     for (int j = 0; j < 3; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    int ans = 0;
    for (int i = N - K + 1; i <= N; i++) {
        int v = 0;
        for (int j = 0; j < 3; j++) {
            chmax(v, dp[i][j]);
        }
        ans += v;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6144
import java.util.Scanner;

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

        int ret = 0;
        int count = 0;
        int prev = Integer.parseInt(sc.next());
        for (int i = 0; i < n - 1; i++) {
            int now = Integer.parseInt(sc.next());
            if (prev >= now) {
                count++;
            } else {
                ret = Math.max(ret, count);
                count = 0;
            }
            prev = now;
        }
        ret = Math.max(ret, count);
        System.out.println(ret);
    }
}


Measured memory_bytes: 46536
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int H = in.nextInt();
		int W = in.nextInt();
		int h = in.nextInt();
		int w = in.nextInt();
		System.out.println((H-h)*(W-w));
	}
}


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

#define int unsigned long long

signed main() {
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	//freopen("out", "w", stdout);
#endif
	int n, a, b; cin >> n >> a >> b;
	int t = (a + b);
	cout << n / t * a + min(n % t, a) << '\n';
}

Measured memory_bytes: 256
a, b, c, x =[int(input()) for i in range(4)]
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)

Measured memory_bytes: 2940
#include<stdio.h>

#define N 100001

int main(){
	int n,i,fl[N]={0};
	int a[N],b[N],c=0,t;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(fl[a[i]]==1)b[c++]=a[i];
		else fl[a[i]]=1;
	}t=c;
	while(c>=3)c=c/3+c%3;
	printf("%d\n",n-t-c%2);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for(int i = 0; i != ty - sy; i++) cout << 'U';
  for(int i = 0; i != tx - sx; i++) cout << 'R';
  for(int i = 0; i != ty - sy; i++) cout << 'D';
  for(int i = 0; i != tx - sx + 1; i++) cout << 'L';
  for(int i = 0; i != ty - sy + 1; i++) cout << 'U';
  for(int i = 0; i != tx - sx + 1; i++) cout << 'R';
  cout << "DR";
  for(int i = 0; i != ty - sy + 1; i++) cout << 'D';
  for(int i = 0; i != tx - sx + 1; i++) cout << 'L';
  cout << 'U' << endl;
  return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
ll MOD;

//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[200010];//適宜変える
	int id[100010];//適宜変える
}G;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}

G g;
void readgraph(){
	//適宜変える
	ll n;
	scanf("%lld%lld",&n,&MOD);
	rep(i,0,n-1){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		x--,y--;
		g.e[2*i].s=x;
		g.e[2*i].g=y;
		g.e[2*i+1].s=y;
		g.e[2*i+1].g=x;
	}
	g.vcnt=n;
	g.ecnt=2*n-2;
	qsort(g.e,g.ecnt,sizeof(E),esort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}

ll dp1[100010];//頂点に対する答え
ll dp2[200010];//辺に対する答え
ll cum[2][200010];//累積和

ll dfs2(int);
ll dfs1(int v){
	if(dp1[v]!=-1)return dp1[v];
	rep(i,g.id[v],g.id[v+1]){
		if(i==g.id[v])cum[0][i]=1;
		else cum[0][i]=cum[0][i-1]*(dfs2(i-1)+1)%MOD;
	}
	for(int i=g.id[v+1]-1;i>=g.id[v];i--){
		if(i==g.id[v+1]-1)cum[1][i]=1;
		else cum[1][i]=cum[1][i+1]*(dfs2(i+1)+1)%MOD;
	}

	ll temp=1;
	rep(i,g.id[v],g.id[v+1])temp=temp*(dfs2(i)+1)%MOD;
	return dp1[v]=temp;
}
ll dfs2(int e){
	if(dp2[e]!=-1)return dp2[e];
	if(dp1[g.e[e].g]!=-1){
		//逆辺のindexが必要
		int v=g.e[e].g;
		int l=g.id[v],r=g.id[v+1];
		while(r-l>1){
			int m=(l+r)/2;
			if(g.e[m].g<=g.e[e].s)l=m;
			else r=m;
		}
		return cum[0][l]*cum[1][l]%MOD;
	}
	ll temp=1;
	int v=g.e[e].g;
	rep(i,g.id[v],g.id[v+1]){
		if(g.e[i].g!=g.e[e].s)temp=temp*(dfs2(i)+1)%MOD;
	}
	return dp2[e]=temp;
}

//dfs
void dfs(int v,int pre){
	dfs1(v);
	rep(i,g.id[v],g.id[v+1]){
		if(g.e[i].g!=pre){
			dfs(g.e[i].g,v);
		}
	}
}

int main(){
	readgraph();
	rep(i,0,g.vcnt)dp1[i]=-1;
	rep(i,0,g.ecnt)dp2[i]=cum[0][i]=cum[1][i]=-1;
	dfs(0,-1);
	rep(i,0,g.vcnt)printf("%lld\n",dp1[i]);
}

Measured memory_bytes: 14584
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    string s;
    cin>>s;
    int len=s.size()-1;
    if(s[len]=='s')
    	cout<<s<<"es"<<endl;
    else
    	cout<<s<<"s"<<endl;
	return 0;
}


Measured memory_bytes: 3608
import sys
from collections import *
I=sys.stdin.readlines()
N,M=map(int,I[0].split())
E=[]
for i in range(M):
  E.append(list(map(lambda x:x-1,(list(map(int,I[i+1].split()))))))
S,T=map(int,I[M+1].split())
G=[[] for i in range(3*N)]
for i in range(M):
  G[E[i][0]].append(E[i][1]+N)
  G[E[i][0]+N].append(E[i][1]+N+N)
  G[E[i][0]+N+N].append(E[i][1])
D=deque()
Z=set()
def qao(x):
  global D,Z
  if x in Z:
    return False
  D.append(x)
  Z.add(x)
  return True

def bfs():
  global D,G,N
  v=0
  for i in range(len(D)):
    v=D.popleft()
    for j in range(len(G[v])):
      qao(G[v][j])
  return len(D)==0

qao(S-1)
for i in range(3*N):
  bfs()
  if T-1 in Z:
    print((i+1)//3)
    exit()
print(-1)

Measured memory_bytes: 169136
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const int INF = 0x3f3f3f3f;

int a[100001];

int mpow(int b, int e)
{
    int ret=1;
    for(int i=0; i<e; i++)
    {
        ret=ret*b%mod;
    }
    return ret;
}

ll x[100001];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, a, b, ans=0;
    cin >> n >> a >> b;
    cin >> x[1];
    for(int i=2; i<=n; i++)
    {
        cin >> x[i];
        ans += min(a*(x[i]-x[i-1]), b);
    }
    cout << ans;
}

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

using namespace std;
using ll = long long;

const int N = 2e5 + 5;

struct point {
    int x, y, id;
} a[N];

bool cmp1(const point& a, const point& b) {
    if (a.x != b.x) {
        return a.x < b.x;
    }
    return a.y < b.y;
}

bool cmp2(const point& a, const point& b) {
    if (a.y != b.y) {
        return a.y < b.y;
    }
    return a.x < b.x;
}

int n;
bool visited[N];
vector<pair<ll, int> > g[N];

ll prim(int x) {
    priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > pq;
    ll ans = 0;
    pq.push({0, x});
    while(!pq.empty()) {
        pair<ll, int> p = pq.top();
        pq.pop();
        x = p.second;
        if (visited[x]) {
        	continue;
		}
        ans += p.first;
        visited[x] = true;
        for(int i = 0; i < g[x].size(); i++) {
            int y = g[x][i].second;
            if (!visited[y]) {
            	pq.push(g[x][i]);
            }
        }
    }
    return ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].x >> a[i].y;
		a[i].id = i + 1;
	}
	sort(a, a + n, cmp1);
	for (int i = 1; i < n; i++) {
		g[a[i].id].push_back({abs(a[i].x - a[i - 1].x), a[i - 1].id});
		g[a[i - 1].id].push_back({abs(a[i].x - a[i - 1].x), a[i].id});
	}
	sort(a, a + n, cmp2);
	for (int i = 1; i < n; i++) {
		g[a[i].id].push_back({abs(a[i].y - a[i - 1].y), a[i - 1].id});
		g[a[i - 1].id].push_back({abs(a[i].y - a[i - 1].y), a[i].id});
	}
	cout << prim(1) << '\n';
	return 0;
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] intArray = convertInt(br.readLine().split(" "));
		int result = 0;
		for (int i = intArray[0]; i <= intArray[1]; i++) {
			if (intArray[2] % i == 0) { result++; }
		}
		System.out.println(result);
	}

	private static int[] convertInt(String[] strArray) {
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}
}

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

using namespace std;

int n, m, a, sum;

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

	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		cin >> a;
		sum += a;
	}

	if (sum > n)
		cout << -1 << endl;
	else
		cout << n - sum << endl;
}


Measured memory_bytes: 3636
#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 a, b, c, d;
    cin >> a >> b >> c >> d;
    int taka = ceil(a/float(d)), ao = ceil(c/float(b));
    if (taka == ao || taka > ao)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=3;i++){
		if(a*b*i%2==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  rep(i, N) cin >> v[i];

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

  double ans = v[0];
  rep(i, N) {
    ans = (double)(ans + v[i]) / 2;
  }
  printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define P(x) cout << x << endl
#define D(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(int)(n); i++)
#define DEC(i,n) for (int i=(int)(n); --i>=0;)
#define S(s) (int)((s).size())
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,(v))
#define MA(a,v) a = max(a,(v))
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;

signed main() {
    int n,m; cin>>n>>m;
    int cnt[n];
    F(i,n) cnt[i] = 0;
    F(i,m) {
        int a,b; cin>>a>>b;
        a--, b--;
        cnt[a]++;
        cnt[b]++;
    }
    bool ok=true;
    F(i,n) if (cnt[i]%2)
        ok = false;
    if (ok) P("YES");
    else P("NO");
}

Measured memory_bytes: 1024
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD = 1000000007
#define INF (1e9)
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;


int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a-c) <= d) {
        yes;
    } else if (abs(a-b) <= d & abs(b-c) <= d) {
        yes;
    } else {
        no;
    }
    return 0;
}


Measured memory_bytes: 256
def puts(s);end
N, *AS = $stdin.read.split.map(&:to_i)
puts AS.inspect

ans = 0
l = r = 0
newr = 1
b = AS[0]
for l in 0...N
  q = false
  puts "l=#{l} (#{l}, #{l})があるので+1"
  ans += 1
  for r in newr...N
    if b & AS[r] > 0
      puts "  r=#{r} #{AS[r]}はだめ"
      if r > l+2
        dans = (r-1)-(l+1)
        puts "  次はl=#{l+1}だが、(#{l+1}, #{r-1})まではokだとわかるのでans += #{dans}"
        ans += dans
        newr = r
        b &= ~AS[l]
      else
        b = AS[l+1]
        newr = l+2
      end
      q = 1
      break
    else
      b ^= AS[r]
      ans += 1
      puts "  (#{l}, #{r})はいけるので+1 (b^#{AS[r]}=#{b})"
    end
  end
  if r == N-1 && l < N-1 && !q
    dans = (N-1)-(l+1)
    puts "  右端まで完走した。次はl=#{l+1}だが、r=#{N-1}まではokだとわかるのでans += #{dans}"
    ans += dans
    newr = N
  end
end
p ans

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

typedef long long LL;

#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)

const int MAX = 500000;
const int LIM = 100000000;
const LL MOD = 1000000007;
const int INF = 2147483647/2;
const LL LINF = 9223372036854775807/3;

int ucmpii(const void *a, const void *b){return(*(int*)a==*(int*)b?0:(*(int*)a>*(int*)b?1:-1));}
int dcmpii(const void *a, const void *b){return(*(int*)a==*(int*)b?0:(*(int*)a<*(int*)b?1:-1));}

int ucmpll(const void *a, const void *b){return(*(LL*)a==*(LL*)b?0:(*(LL*)a>*(LL*)b?1:-1));}
int dcmpll(const void *a, const void *b){return(*(LL*)a==*(LL*)b?0:(*(LL*)a<*(LL*)b?1:-1));}

void SORT(int*a, int n){qsort(a,n,sizeof(int),ucmpii);}
void SORTR(int*a, int n){qsort(a,n,sizeof(int),dcmpii);}
void LSORT(LL*a, int n){qsort(a,n,sizeof(LL),ucmpll);}
void LSORTR(LL*a, int n){qsort(a,n,sizeof(LL),dcmpll);}

int main(){
  int n,x,t;
  scanf("%d%d%d",&n,&x,&t);
  printf("%d\n",(n+x-1)/x *t);
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
using namespace std;
int n, q, c, x, y, size_, dat[266666];
inline void update(int pos, int x) {
	pos += size_; dat[pos] = x;
	while(pos != 1) {
		pos >>= 1;
		dat[pos] = min(dat[pos * 2], dat[pos * 2 + 1]);
	}
}
inline int query(int a, int b, int k, int l, int r) {
	if(r <= a || b <= l) return 2147483647;
	if(a <= l && r <= b) return dat[k]; k <<= 1;
	int lc = query(a, b, k, l, (l + r) / 2);
	int rc = query(a, b, k + 1, (l + r) / 2, r);
	return min(lc, rc);
}
int main() {
	scanf("%d%d", &n, &q);
	for(size_ = 1; size_ < n;) size_ *= 2;
	for(int i = 0; i < size_ * 2; i++) dat[i] = 2147483647;
	for(int i = 0; i < q; i++) {
		scanf("%d%d%d", &c, &x, &y);
		if(c == 0) update(x, y);
		else printf("%d\n", query(x, y + 1, 1, 0, size_));
	}
}

Measured memory_bytes: 4228
from fractions import gcd
N=int(input())
A=list(map(int, input().split()))
if len(set(A))==1:
  print(A[0])
  exit()
  
#A=sorted(A, reverse=True)
alleven=True


for i in range(1,N):
  if i==1:
    now=gcd(A[i-1],A[i])
  else:
    now=gcd(now,A[i])

print(now)



Measured memory_bytes: 16540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 300000 + 10;
char s[maxn];
ll f[4][maxn];
const int trans[4][4] = {
	{0, 1, 0, 1},
	{0, 1, 2, 3},
	{2, 2, 2, 3},
	{3, 3, 3, 3}
};
int get(char c, int d) { return c == '?' ? d : c - '0';}
void add(ll & x, ll y) { x += y; while(x >= mod) x -= mod;}
int main()
{
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	f[1][0] = 1;
	for(int i = 2; i <= n; i += 2)
		for(int k1 = get(s[i - 1], 0); k1 <= get(s[i - 1], 1); ++k1)
			for(int k2 = get(s[i], 0); k2 <= get(s[i], 1); ++k2)
			{
				int k = k1 * 2 + k2;
				for(int j = 0; j < 4; ++j)
					add(f[trans[j][k]][i], f[j][i - 2]);
			}
	ll ans = 0;
	if(s[n] == '1' || s[n] == '?') 
	{
		for(int j = 1; j < 4; ++j) 
			add(ans, f[j][n - 1]);
	}
	if(s[n] == '0' || s[n] == '?')
		add(ans, f[3][n - 1]);
	cout << ans << endl;
	 
	return 0;
}
	 

Measured memory_bytes: 13448
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;


public class Main{
	static List<Integer> primes = findPrimes(104729);

	private static List<Integer> findPrimes(int n){
		boolean[] isPrime = new boolean[n];
		Arrays.fill(isPrime, true);

		isPrime[0] = false;
		for(int i = 0; i < isPrime.length; i++){
			if(isPrime[i]){
				for(int j = 2; (i + 1) * j < isPrime.length; j++){
					isPrime[(i + 1) * j - 1] = false;
				}
			}
		}
		List<Integer> result = new ArrayList<Integer>();
		for(int i = 1 - 1; i < isPrime.length; i++)
			if(isPrime[i]){
				result.add(i + 1);
			}
		return result;
	}

	private static long sumOfPrimes(int n) {
		long result = 0L;
		for(int i = 0; i < n; i++) result += primes.get(i);
		return result;
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()) {
			int n = sc.nextInt();
			if(n == 0) break;
			System.out.println(sumOfPrimes(n));
		}
		sc.close();
	}
	
}

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

//#define fin cin
//#define fout cout

#define leftSon (node << 1)
#define rightSon ((node << 1) | 1)

#define pii pair < int , int >
#define F first
#define S second

using namespace std;

typedef long long ll;

const int inf = 0x3f3f3f3f;
const long long infL = LLONG_MAX;

const int nmax = 1e5 + 10;

int n, cost[nmax];
vector < int > g[nmax];

void sortt(int node, int dad) {
    vector < pair < int, int > > v;
    for (auto &it : g[node])
        if (it != dad) v.push_back({cost[it], it});
    sort(v.begin(), v.end());

    int cnt = v.size(), act = 0;
    for (auto &it : v) {
        cost[it.second] += cnt--;
        act = max(act, cost[it.second]);
    }

    cost[node] += act;
}

int dfs2(int node, int dad) {
    for (auto &it : g[node]) {
        if (it == dad) continue;
        dfs2(it, node);
    }

    sortt(node, dad);
}

int main()
{
    

    /*
    ifstream fin("input.in");
    ofstream fout("output.out");
    */

    scanf("%d", &n);
    for (int i = 2; i <= n; ++i) {
        int x; scanf("%d", &x);
        g[x].push_back(i);
        g[i].push_back(x);
    }

    dfs2(1, 0);
    printf("%d\n", cost[1]);

    return 0;
}


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

using namespace std;

#define pb push_back
#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 REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=m.begin();i!=m.end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;

void printv(vector<auto> const& s) {
  rep(i, s.size()) {
    cout << s[i] << endl;
  }
}

void print(auto const s) {
  cout << s << endl;
}

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

  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  REP(i, ty - sy) {
    cout << "U";
  }
  REP(i, tx - sx) {
    cout << "R";
  }
  REP(i, ty - sy) {
    cout << "D";
  }
  REP(i, tx - sx) {
    cout << "L";
  }

  cout << "L";
  REP(i, ty - sy + 1) {
    cout << "U";
  }
  REP(i, tx - sx + 1) {
    cout << "R";
  }
  cout << "D";
  cout << "R";
  REP(i, ty - sy + 1) {
    cout << "D";
  }
  REP(i, tx - sx + 1) {
    cout << "L";
  }
  cout << "U" << endl;
  
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EWhoSaysAPun solver = new EWhoSaysAPun();
        solver.solve(1, in, out);
        out.close();
    }

    static class EWhoSaysAPun {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String x = in.next();
            int dp[] = new int[n];
            long ans = 0;
            for (int i = 1; i < n; i++) {
                Arrays.fill(dp, 0);
                for (int j = n - i - 1; j >= 0; j--) {
                    if (x.charAt(j) == x.charAt(j + i)) {
                        dp[j] = dp[j + 1] + 1;
                    } else {
                        dp[j] = 0;
                    }
                    ans = Math.max(ans, Math.min(dp[j], i));
                }
            }
            out.println(ans);


        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 25044
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
#include<fstream>
#include <chrono>
using namespace std;
typedef long long LL;


int main(void)
{
	/*
	chrono::system_clock::time_point start, end;
	start = chrono::system_clock::now();
	end = chrono::system_clock::now();
	double time = static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
	//printf("time %lf[ms]\n", time);
	*/

	LL D,dim=1;
	cin >> D;
	random_device rnd;
	mt19937 mt(rnd());
	uniform_int_distribution<> randabc(1, 26);
	vector<vector<LL>> t(dim, vector<LL>(D + 1));

	for (int i = 0; i < dim; i++) {
		for (int j = 1; j <= D; j++) {
			t[i][j]=randabc(mt);
		}
	}


	vector<int> c(27);
	
	for (int i = 1; i <= 26; i++) {
		cin >> c[i];
	}
	vector<vector<LL>> s(D + 1, vector<LL>(27, 0));
	
	for (int i = 1; i <= D; i++) {
		for (int j = 1; j <= 26; j++) {
			cin >> s[i][j];
		}
	}

	for (int i = 0; i < dim; i++) {
		for(int j = 1; j <= D; j++){
			cout <<t[i][j]<<endl;;
		}
	}
	

	for (int k = 0; k < dim; k++) {
		vector<LL> last(27, 0);
		LL man = 0;
		for (int i = 1; i <= D; i++) {
			LL dis = 0;
			man += s[i][t[k][i]];
			last[t[k][i]] = i;
			for (int j = 1; j <= 26; j++) {
				dis += (c[j] * (i - last[j]));
			}
			man -= dis;
			//cout <<man<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ




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


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w, n ;
  cin >> h >> w >> n ;
  int m = max(h,w) ;
  if(n%m==0){
    cout << n/m <<endl ;
  }
  else{
    cout << n/m+1 <<endl ;
  }
  
  
  
  return 0 ;
}




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

int main(void) {
    int H,W;cin>>H>>W;
    pair<int, int> pv[H];
    for (int i = 0; i < H; i++) {
        string a;cin>>a;
        int start = -1;
        int end = -1;
        pair<int, int> p;
        for (int j = 0; j < W; j++) {
            char c = a[j];
            if (start == -1 && c == '#') {
                start = j;
            }
            if (c == '#') end = j;
        }
        p = make_pair(start, end);
        pv[i] = p;
    }
    for (int i = 0; i < H - 1; i++) {
        pair<int, int> before = pv[i];
        pair<int, int> next = pv[i+1];
        if (before.second > next.first) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <stdlib.h>
#include <functional>
#define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
using namespace std;
const int N = 1e5 + 10;
int n;
ll a[10010], b[10010];

int main() {
	int i;
	scanf("%d", &n);
	ll keep;

	keep = 0;
	for (i = 0; i < n; ++i) {
		scanf("%lld", &a[i]);
	}
	for (i = 0; i < n; ++i) {
		scanf("%lld", &b[i]);
	}
	for (i = 0; i < n; ++i) {
		if (a[i] == b[i]) continue;
		if (a[i] > b[i]) {
			keep += (a[i] - b[i]);
		}
		else if(a[i]<b[i])
		{
			keep -= ((b[i] - a[i]) / 2);
		}
	}
	
	if (keep > 0) printf("No\n");
	else printf("Yes\n");
	
}

Measured memory_bytes: 384
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  ll a,b,c,k;
  std::cin >> a >> b >> c >> k;
  if(k%2) std::cout << b-a << '\n';
  else std::cout << a-b << '\n';
  return 0;
}


Measured memory_bytes: 256
import numpy as np
n,m=map(int,input().split())
hlist = list(map(int,input().split()))
ablist = []
for i in range(m):
    ablist.append(input().split())
x=np.zeros(n,int)
for ab in ablist:
  a=int(ab[0])
  b=int(ab[1])
  if hlist[a-1]<hlist[b-1]:
    x[a-1]=1#ダメ
  elif hlist[a-1]>hlist[b-1]:
    x[b-1]=1#ダメ
  elif hlist[a-1]==hlist[b-1]:
    x[a-1]=1
    x[b-1]=1
count=0
for l in range(n):
  if x[l]==0:
    count+=1
print(count)

Measured memory_bytes: 61380
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    MAX = max(A)
    dp = [True] * (MAX+1)
    A.sort()
    cnt = Counter(A)
    ans = 0
    for a in A:
        if dp[a]:
            if cnt[a] == 1:
                ans += 1
            x = a
            while x <= MAX:
                dp[x] = False
                x += a
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 133412
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 23 21:51:02 2019

@author: Yamazaki Kenichi
"""

N,W = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]

ans = [[-1 for i in range(N+1)]]
ans[0][N] = 0
for i in range(1,W+1):
    tmp = -1
    maxv = ans[-1][N]
#    print('aa',maxv)
    for j in range(N):
#        print(i,j,A[j][0],maxv,ans[i -A[j][0]][j])
#        print(i,j,A[j],i -A[j][0],ans[-1])
        if i-A[j][0] >= 0 and ans[i-A[j][0]][j] == -1 and ans[i-A[j][0]][N] + A[j][1] > maxv:
            maxv = ans[i-A[j][0]][N] + A[j][1]
            tmp = j
#            print('maxv',maxv,'tmp',tmp)
    if tmp != -1:
        ans.append(ans[-A[tmp][0]][:])
        ans[i][tmp] = 1
    else:
        ans.append(ans[-1][:])
    ans[i][N] = maxv
#    print(ans[i][N])
#    print(ans[i])
print(ans[W][N])

Measured memory_bytes: 128480
#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 n;
	cin >> n;
	cout << n/3 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;
const int MOD = 1000000007;
const ll INF = 1LL << 60;

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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0 ; i < n; ++i){
        cin >> s[i];
    }

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

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 2e12
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e5 + 2;
ll n,m,h,w;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m>>h>>w;
    cout<<n * m - h * m - w * n + h * w;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		if(N == 1){
			System.out.println(1);
			sc.close();
			return;
		}

		Integer[] d = new Integer[N];

		for(int i = 0; i < d.length; i++){
			d[i] = sc.nextInt();
		}

		sc.close();

		Arrays.sort(d, Collections.reverseOrder());

		int c = d[0];
		int ans = 1;
		
		for(int i = 1; i < d.length; i++){
			if(d[i] < c){
				c = d[i];
				ans++;
			}
		}

		System.out.println(ans++);
	}
}


Measured memory_bytes: 21844
while True:
    n = int(input())
    if n == 0: break
  
    data = {}
    staff = []
    for i in range(n):
        tmp = list(map(int, input().split(' ')))
        if tmp[0] in data:
            data[tmp[0]] += tmp[1] * tmp[2]
        else:
            data[tmp[0]] = tmp[1] * tmp[2]
            staff.append(tmp[0])
  
    if max(data.values()) < 1e6:
        print('NA')
    else:
        for k in staff:
            if data[k] >= 1e6:
                print(k)

Measured memory_bytes: 7808
#include <iostream>

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  bool ab = A == B;
  bool bc = B == C;
  bool ac = A == C;
  if ((ab && bc && ac) || (!ab && !bc && !ac)) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y;
  int min,max;
  vector<int> li;
  int i = 1;
  
  while(1){
    cin >> x >> y;
    if(x == 0 && y == 0)break;
    if(x < y){
    cout << x << " " << y << endl;
    } else {
    cout << y << " " << x << endl;
    }
  }
  
}


Measured memory_bytes: 3068
#include <iostream>
 using namespace std;
 int main(){
 string s;
 cin >> s;
 int ans;
 if(s == "SUN")ans = 7;
 else if(s == "MON")ans = 6;
 else if(s == "TUE")ans = 5;
 else if(s == "WED")ans = 4;
 else if(s == "THU")ans = 3;
 else if(s == "FRI")ans = 2;
 else if(s == "SAT")ans = 1;
 cout << ans << endl;
 }

Measured memory_bytes: 3544
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
	fastio;
	int n;
	cin >> n;
	vector<int> v(n);
	int sum = 0;
	for(int& x : v){
		cin >> x;	
		sum += x;
	}
	sort(all(v));
	int mid = n/2;
	cout << v[mid] - v[mid-1] << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;
#define MAX 100000
#define INFTY (1 << 30)

class Edge {
public:
    int t, w;
    Edge() {}
    Edge(int t, int w)
        : t(t) // t:行き先
        , w(w) // w:重み
    {
    }
};

vector<Edge> G[MAX]; // Gはグラフで行き先と重みを持っている
int n, d[MAX]; // d:距離

bool vis[MAX];
int cnt;

void bfs(int s)
{
    // sから行ける距離をすべて探索してdに入れている
    for (int i = 0; i < n; i++) {
        d[i] = INFTY; // 各点の距離を初期化
    }
    queue<int> Q; // キューQを作る
    Q.push(s); // Qに引数sを入れる
    d[s] = 0; // sの距離を0とする
    int u;
    while (!Q.empty()) { // Qの中身がゼロでないとき
        // uをQに最初に入れたデータを入れた順番に取り出す
        u = Q.front();
        Q.pop();
        for (int i = 0; i < G[u].size(); i++) {
            // eをエッジ構造のものとする
            Edge e = G[u][i]; // eを頂点uから行けるグラフでまだ通ったことがないものとする
            if (d[e.t] == INFTY) { // もしsの距離が初期化のときのままだったら
                d[e.t] = d[u] + e.w; // e->tまでの距離:uまでの距離とeの時点での距離を足したもの
                Q.push(e.t); // Qにeの行き先を入れる
            }
        }
    }
}

void solve()
{
    // 適当な始点sから最も遠い節点tgtを求める
    bfs(0);
    int maxv = 0;
    int tgt = 0;
    for (int i = 0; i < n; i++) {
        if (d[i] == INFTY) {
            continue;
        }
        if (maxv < d[i]) {
            maxv = d[i]; // maxvの最大値を更新する
            tgt = i; // tgt最も遠い節点はi
        }
    }
    // tgt から最も遠い節点の距離maxvを求める
    bfs(tgt);
    maxv = 0;
    for (int i = 0; i < n; i++) {
        // d[i]が初期化のときのままならスキップ
        if (d[i] == INFTY) {
            continue;
        }
        // d[i]の距離が初期化以外なら更新
        maxv = max(maxv, d[i]);
    }

    cout << maxv << endl;
}

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

    int s, t, w;
    cin >> n;

    for (int i = 0; i < n - 1; i++) {
        cin >> s >> t >> w;

        // 無向グラフだからGに両方への行き先を入れて，重みを入力している
        G[s].push_back(Edge(t, w));
        G[t].push_back(Edge(s, w));
    }
    solve();
}


Measured memory_bytes: 9956
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static System.Console;

namespace E_ABC126
{
    class MainClass
    {

        static int[] s;


        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            UnionFind u = new UnionFind(s[0]);
            for(int i=0;i<s[1];i++){
                int[] ab = new int[3];
                ab = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
                u.Connect(ab[0]-1,ab[1]-1);
            }
            int ans = 0;
            for(int i=0;i<s[0];i++){
               // WriteLine(u.Root(i));
                if(u.Root(i)==i){
                    ans++;
                }
            }
            WriteLine(ans);
        }
    }


     class UnionFind
    {
        public List<int> Parent;
        public UnionFind(int n)
        {
            //親の番号をそれぞれ格納する。自分が親なら、-(サイズ)
            this.Parent = Enumerable.Repeat(-1, n).ToList();
        }

        public int Size(int a)
        {
            if (Parent[a] < 0)return -Parent[a];
            else return -Parent[Root(a)];
        }

        public int Root(int a)
        {
            if (Parent[a] < 0) return a;
            else
            {
                int root = Root(Parent[a]);
                Parent[a] = root;
                return root;
            }
        }

        public bool Connect(int a, int b)
        {
            a = Root(a);
            b = Root(b);
            if (a == b) return false;
            else
            {
                //a > bにする
                if (a < b)
                {
                    int tmp = a;
                    a = b;
                    b = tmp;
                }
                //bの親をaにして、aのsizeにbのぶんを足す
                Parent[a] += Parent[b];
                Parent[b] = a;
                return true;
            }
        }
    }
}


Measured memory_bytes: 18264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll po(ll x,ll n)
{
    x%=mod;
    ll res=1;
    while(n>0)
    {
        if(n&1)
        {
            res=res*x%mod;
        }
        n>>=1;
        x=x*x%mod;
    }
    return res;
}
int main()
{
    ll n;
    cin>>n;
    if(n<2)
        cout<<0<<endl;
    else
        cout<<((((po(10,n)%mod-po(9,n)%mod+mod)%mod-po(9,n)%mod+mod)%mod+po(8,n)%mod))%mod<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>

int ha(long a){
	int r=0;
	while(a%2==0){
		a=a/2;
		r++;
	}
	return r;
}

int main(){
	int n,i,ans=0;
	long a;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%ld",&a);
		ans+=ha(a);
	}
	printf("%d\n",ans);
	return 0;
}

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
      COMinit();
  string N;
  long long x,y,ans,z,p,f,l;
  int K;
  int u;
  cin >>N>>K;
  l=N.length();
  ans=0;
  f=0;
  p=1;
  int a[101][3];
  a[0][0]=0;
  a[0][1]=0;
  a[0][2]=0;

  for(int i=0;i<l;i++){
    if(N[i]!='0'){
      f++;
      u=N[i]-'0';
      if(K-f==2){
      ans+=COM(l-i-1,3)*729+(u-1)*COM(l-i-1,2)*81;
      }
      else if(K-f==1){
      ans+=COM(l-i-1,2)*81+(u-1)*COM(l-i-1,1)*9;
      }
       else if(K-f==0){
      ans+=COM(l-i-1,1)*9+(u-1)*COM(l-i-1,0)+1;
      }
    }

  }
    cout<<ans<<endl;
}

Measured memory_bytes: 12160
#include <stdio.h>
int main(void){
  int h,w,i,j;
  while(scanf("%d %d",&h,&w)) {
    for(i=0;i<h;i++){
      if (i==0 || i==h-1) for (j=0;j<w;j++) printf("#");
      else for (j=0;j<w;j++) if (j==0 || j==w-1) printf("#"); else printf(".");
      printf("\n");
    }
    if (h==0&&w==0) break;
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    ll n, k, a, b;
    cin >> n >> k;
    map<ll, ll> mp;
    
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        mp[a] += b;
    }
    
    for(auto x: mp) {
        k -= x.second;
        if (k <=0) {
            cout << x.first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4224