akhauriyash/Code-Regression huggingface dataset:
import math

n = input()

for i in range(n):
    flag = 0
    a = map(int, raw_input().split())
    if(pow(a[0],2)+pow(a[1],2) == pow(a[2],2)):
        flag = 1
    if(pow(a[1],2)+pow(a[2],2) == pow(a[0],2)):
        flag = 1
    if(pow(a[2],2)+pow(a[0],2) == pow(a[1],2)):
        flag = 1
    if flag == 1:
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 4384
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)


N, K = inp_list()
h = inp_list()
h = np.array(h)

dp = np.array([10 ** 9] * N)
dp[0] = 0

for i in range(N - 1):
    dp[i + 1 : i + K + 1] = np.minimum(dp[i + 1 : i + K + 1], dp[i] + abs(h[i + 1 : i + K + 1] - h[i]))

# print(dp)
print(dp[-1])


Measured memory_bytes: 24176
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
i = 0
state = 0
ans = 1
while i < n-1:
  if a[i] == a[i+1]:
    ans*=a[i]
    state += 1
    if state == 2:
      break
    i += 2
  else:
    i += 1
if state < 2:
  print(0)
else:
  print(ans)
  
    
  
  

        

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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n, m;

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

	int ans = 1900 * m + 100 * (n - m);

	for (int i = 0; i < m; i++) ans *= 2;

	printf("%d\n", ans);

	return 0;
}

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

const int64_t MAX = 510000;
const int64_t MOD = 1000000007;

int64_t 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;
    }
}
int64_t 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();
  
  int64_t H,W,A,B;
  cin>>H>>W>>A>>B;
  int64_t ans=0;
  int64_t i=H-1-A,j=B;
  
  while(true){
    ans += COM(H-1-A+B,i)*COM(W-1-B+A,W-1-j);
    ans %= MOD; 
    --i;
    ++j;
    if(i<0 || j>=W) break;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 12160
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    int ans;
    if (n % 1000 == 0) {
        ans = 0;
    }
    else {
        ans = 1000 - (n % 1000);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const long long INF = 1e18;
int main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<long long> S(A + 2), T(B + 2), X(Q + 2);
    for (int i = 1; i <= A; i++)
        cin >> S[i];
    for (int i = 1; i <= B; i++)
        cin >> T[i];
    for (int i = 0; i < Q; i++)
        cin >> X[i];
    S[0] = -INF; S[A + 1] = INF;
    T[0] = -INF; T[B + 1] = INF;
    sort(S.begin(), S.end());
    sort(T.begin(), T.end());

    vector<long long> ANS(Q);
    for (int i = 0; i < Q; i++) {
        long long sl, sr, tl, tr;
        auto s = upper_bound(S.begin(), S.end(), X[i]);
        sl = *(s - 1); sr = *s;
        auto t = upper_bound(T.begin(), T.end(), X[i]);
        tl = *(t - 1), tr = *t;

        long long ans = INF;
        ans = min(ans, abs(X[i] - sl) + abs(sl - tl));
        ans = min(ans, abs(X[i] - sr) + abs(sr - tl));
        ans = min(ans, abs(X[i] - sl) + abs(sl - tr));
        ans = min(ans, abs(X[i] - sr) + abs(sr - tr));
        ans = min(ans, abs(X[i] - tl) + abs(tl - sl));
        ans = min(ans, abs(X[i] - tr) + abs(tr - sl));
        ans = min(ans, abs(X[i] - tl) + abs(tl - sr));
        ans = min(ans, abs(X[i] - tr) + abs(tr - sr));

        ANS[i] = ans;
    }
    for (int i = 0; i < Q;i ++)
        cout << ANS[i] << endl;
    return 0;
}

Measured memory_bytes: 4480
a= input()
b= input()
c= input()
qa=[]
qb=[]
qc=[]
for i in a:
	qa.append(i)
for i in b:
	qb.append(i)
for i in c:
	qc.append(i)
qa.append('d')
qb.append('d')
qc.append('d')
t=qa.pop(0)
while len(qa)>0 and len(qb)>0 and len(qc)>0:
	if t=='a':
		t=qa.pop(0)
	elif t=='b':
		t=qb.pop(0)
	else :
		t=qc.pop(0)

if len(qa)==0:
	print('A')
elif len(qb)==0:
	print('B')
else:
	print('C')

Measured memory_bytes: 61924
n,m=map(int,input().split())
x=1
p=10**9+7
if abs(n-m)>1:print(0)
elif n==m:
  for i in range(1,n+1):
    x=(x*i)%p
  print((2*(x**2))%p)
else:
  for i in range(1,min(n,m)+1):
    x=(x*i)%p
  y=(x*max(n,m))%p
  print((x*y)%p)

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

using namespace std;

int main()
{
	int n,m;
	cin>>n>>m;
	int a[n+1][m+1];
	
	for (int i=1;i<=n;++i)
	    for (int j=1;j<=m;++j)     cin>>a[i][j];
	    
	int sum=0;
	for (int i=1;i<=n;++i){
		for (int j=i+1;j<=n;++j){
			int t=0;
			for (int k=1;k<=m;++k)
				t=t+pow(fabs(a[i][k]-a[j][k]),2);
			if (floor(sqrt(t))==sqrt(t))
			    sum++;
		}
	}
	
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
string str;int n;
int main()
{
    cin>>str;
    int n=str.length();
    for (int i=1;i<n;i++)
        if (str[i]!=str[n-i-1]){cout<<"No"<<endl;return 0;}
    cout<<"Yes"<<endl;


return 0;
}


Measured memory_bytes: 256
#include <iostream>

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" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1, 1e9);
    a[0] = 0;
    for(int i = 0; i < n; i++){
        a[i+1] = min(a[i+1], a[i] + 1);

        for(int j = 6; i + j <= n; j *= 6) a[i+j] = min(a[i+j], a[i] + 1);
        for(int j = 9; i + j <= n; j *= 9) a[i+j] = min(a[i+j], a[i] + 1);
    }
    cout << a[n] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
    int N;
    scanf("%d",&N);
    int A[N];
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    int d=0;
    while(1){
        int c=0;
        for(int j=0;j<N;j++){
            if(A[j]%2==0){
                c++;
                A[j]=A[j]/2;
            }
        }
        //printf("%d\n",c);
        if(c==N)
            d++;
        else
            break;
    }
    printf("%d\n",d);
    return 0;
}


Measured memory_bytes: 128
def resolve():
    n, t = map(int, input().split())
    a = list(map(int, input().split()))
    ans = t * n
    for i in range(1, n):
        if a[i - 1] + t > a[i]:
            ans -= abs(a[i - 1] + t - a[i])
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 85456
#include <bits/stdc++.h>
using namespace std;
#define int long long int
bool even(string& s){
	int n=s.length();
	int mid = n/2;
	for(int i=0;i<mid;i++){
		if(s[i]!=s[mid+i]){
			return 0;
		}
	}
	return 1;
}
int32_t main(){
	string s;
	cin>>s;
	do{
		s.pop_back();
		s.pop_back();
	}while(!even(s));
	cout<<s.length();
}


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

ll dfs(ll k, ll N) {
    if (k > N) return 0;
    ll tmp = k;
    vector<bool> ok(8, false);
    while (tmp != 0) {
        ok[tmp % 10] = true;
        tmp /= 10;
    }
    ll ret = 0;
    if (ok[3] && ok[5] && ok[7]) ++ret;
    ret += dfs(k * 10 + 3, N);
    ret += dfs(k * 10 + 5, N);
    ret += dfs(k * 10 + 7, N);
    return ret;
}

int main() {
    ll N; cin >> N;
    cout << dfs(0, N) << endl;
    return 0;
}


Measured memory_bytes: 3612
N,M = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(M)]

se1 = set()
se2 = set()

for a,b in AB:
  if a == 1:
    se1.add(b)
  if b == N:
    se2.add(a)
    
se = se1 & se2
answer = 'POSSIBLE' if se else 'IMPOSSIBLE'
print(answer)


Measured memory_bytes: 46480
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>
#include <bitset>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

using R = double;
const R PI = 4.0*atan(1.0);
using Pc = complex<R>;

void fft(int s, bool type, Pc c[]) {
    const int N = 1<<s;
    Pc *a = new Pc[N];
    Pc *b = new Pc[N];
    copy_n(c, N, a);
    for (int i = 1; i <= s; i++) {
        int H = 1<<(i-1), W = 1<<(s-i); //??????2H, ???W
        Pc base = polar<R>(1, (type ? -PI : PI) / H);
        Pc now = Pc(1, 0);
        for (int y = 0; y < (N>>1); y += W) {
            for (int x = 0; x < W; x++) {
                auto l =       a[y<<1 | x];
                auto r = now * a[y<<1 | x | W];
                b[y | x]          = l+r;
                b[y | x | (N>>1)] = l-r;
            }
            now *= base;
        }
        swap(a, b);
    }
    copy_n(a, N, c);
    delete[] a;
    delete[] b;
}

const int B = 11;
const int N = 1<<B;

int main() {
    Pc *a = new Pc[1<<(2*B)];
    Pc *b = new Pc[1<<(2*B)];
    int n;
    scanf("%d", &n);
    int csm = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int x;
            scanf("%d", &x);
            csm += x;
            a[i<<B | j] = x;
            b[(N/2-1-i)<<B | (N/2-1-j)] = x;
        }
    }
    fft(2*B, false, a);
    fft(2*B, false, b);
    for (int i = 0; i < (1<<(2*B)); i++) {
        a[i] *= b[i];
    }
    fft(2*B, true, a);
    for (int i = 0; i < (1<<(2*B)); i++) {
        a[i] /= (1<<2*B);
    }
    double dsm = 0;
    double distsm = 0;
    map<int, ll> mp;
    for (int y = 0; y < N; y++) {
        for (int x = 0; x < N; x++) {
            ll d = (ll)(a[y<<B | x].real()+0.5);
            if (y == N/2-1 && x == N/2-1) {
                d -= csm;
            }
            dsm += d;
            int dy = abs(N/2-1 - y), dx = abs(N/2-1 - x);
            int dist = dy*dy + dx*dx;
            if (d) {
                mp[dist] += d;
                distsm += sqrt(dist) * d;
//                cout << y << " " << x << " " << d << endl;
            }
        }
    }

    distsm /= dsm;
    printf("%.20lf\n", distsm);
    int c = 0;
    for (auto p: mp) {
        printf("%d %lld\n", p.first, p.second / 2);
        c++;
        if (c == 10000) break;
    }
    return 0;
}

Measured memory_bytes: 265392
#include <stdio.h>

int calc_rectangle(int a, int b, int *s, int *l)
{

    *s = a * b;
    *l = 2 * a + 2 * b;
}
int main(void)
{
    int a, b, s, l;

    scanf("%d %d", &a, &b);
    calc_rectangle(a, b, &s, &l);
    printf("%d %d\n", s, l);

    return 0;
}


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



/*以下便利なマクロを定義する。*/

#define refor(i, min, max) for(i=min; i<=max; i=i+1)



#define if_forall(i, min, max, prop)\
	bool if_forall_condition=1;\
\
	for(i=min; i<=max; i=i+1)\
	{\
		if(!(prop))\
		{\
			if_forall_condition=0;\
			break;\
		}\
	}\
\
	if(if_forall_condition==1)\



#define if_exists(i, min, max, prop)\
	bool if_exists_condition=0;\
\
	for(i=min; i<=max; i=i+1)\
	{\
		if(prop)\
		{\
			if_exists_condition=1;\
			break;\
		}\
	}\
\
	if(if_exists_condition==1)\











/*以下便利な関数を定義する。*/



void ini_int(int a[], int num)
{
	int i=0;

	for(i=0; i<=num; i=i+1)
	{
		a[i]=0;
	}

}



void ini_char(char array[], int num)
{
	int i=0;

	for(i=0; i<=num; i=i+1)
	{
		array[i]='\0';
	}

}



int powi(int base, unsigned int exponent)
{
	int answer=1;

	answer=(int)pow((double)base, (double)exponent);

	return answer;
}



void sort_asc_int(int a[], int min, int max)
{
	int i, j;
	int dumy;

	for(i=min; i<=max; i=i+1)
	{
		for(j=i+1; j<=max; j=j+1)
		{
			if(a[i]>a[j])
			{
				dumy=a[i];
				a[i]=a[j];
				a[j]=dumy;
			}
		}
	}
}



void sort_des_int(int a[], int min, int max)
{
	int i, j;
	int dumy;

	for(i=min; i<=max; i=i+1)
	{
		for(j=i+1; j<=max; j=j+1)
		{
			if(a[i]<a[j])
			{
				dumy=a[i];
				a[i]=a[j];
				a[j]=dumy;
			}
		}
	}
}



int max(int a, int b)
{
	int answer=a;
	if(a<b)
	{
		answer=b;
	}

	return answer;
}



int min(int a, int b)
{
	int answer=a;
	if(a>b)
	{
		answer=b;
	}

	return answer;
}



int max_int(int a[], int min, int max)
{
	int i;
	int answer;

	answer=a[min];

	for(i=min+1; i<=max; i=i+1)
	{
		if(answer<a[i])
		{
			answer=a[i];
		}
	}

	return answer;
}



int min_int(int a[], int min, int max)
{
	int i;
	int answer;

	answer=a[min];

	for(i=min+1; i<=max; i=i+1)
	{
		if(answer>a[i])
		{
			answer=a[i];
		}
	}

	return answer;
}



bool containelement_int(int array[], int min, int max, int element)
{
	int i;
	bool answer=0;

	if_exists(i, min, max, array[i]==element)
	{
		answer=1;
	}

	return answer;
}



int count_differentelement_int(int array[], int min, int max)
{
	int i=min;
	int pickup[max];
	ini_int(pickup, max);
	int answer=0;

	for(i=min; i<=max; i=i+1)
	{
		if(containelement_int(pickup, 0, answer-1, array[i])==0)
		{
			pickup[answer]=array[i];
			answer=answer+1;
		}
	}

	return answer;
}



int count_equalelement_int(int array[], int min, int max, int element)
{
	int i;
	int answer=0;

	for(i=min; i<=max; i=i+1)
	{
		if(array[i]==element)
		{
			answer=answer+1;
		}
	}

	return answer;
}











int main()
{
	int a[3];
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	printf("%d\n", count_differentelement_int(a, 0, 2));
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

struct UF {
  vector<int> p;
  UF(int N):p(N,-1) {}
  int rt(int x){return p[x]<0?x:p[x]=rt(p[x]);}
  int s(int x){return -p[rt(x)];}
  void cat(int x,int y) {
    if((x=rt(x))==(y=rt(y))) return;
    if(p[x]<p[y])swap(x,y);
    p[y]+=p[x];
    p[x]=y;
  }
};

int main() {
  for(int tci = 0; ; tci++) {
    int W, H; scanf("%d%d", &W, &H);
    if(W==0) break;
    static char tbl[30][30];
    for(int y = 0; y < H; y++) scanf(" %s", tbl[y]);
    UF uf(W*H);
    int k = 0;
    for(int y = 0; y < H; y++) {
      for(int x = 0; x < W; x++) {
        if(tbl[y][x]=='#') continue;
        if(y>0 && tbl[y-1][x]!='#') uf.cat(y*W+x,(y-1)*W+x);
        if(x>0 && tbl[y][x-1]!='#') uf.cat(y*W+x,y*W+(x-1));
        if(tbl[y][x]=='@')k=y*W+x;
      }
    }
    printf("%d\n", uf.s(k));
  }
  return 0;
}

Measured memory_bytes: 1036
l = [int(x) for x in input().split()]
n = l[0]
k = l[1]
pos = 1

go = [int(x) for x in input().split()]
ref = {}

#[first find, second find]

i = 0

while i < k:
    pos = go[pos-1]
    i = i+1

    if pos in ref:
        if ref[pos][1] == -1:
            ref[pos][1] = i
        else:
            temp = ref[pos][1] - ref[pos][0]
            tempy = ((k-i)//temp)*temp
            i = i + tempy

    else:
        ref[pos] = [i, -1]

print(pos)


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

using namespace std;

int main()
{
  int w, q, a[101], s, t, v;
  char u;
  bool f;

  while(cin>>w>>q && (w+q)){
    fill(a, a+101, -1);

    while(q--){
      cin >> u;
      if(u == 'w'){
	cin >> s;
	for(int i = 0; i < w; i++){
	  if(a[i] == s){
	    a[i] = -1;
	  }
	}
      } else {
	cin >> s >> t;
	f = false;
	for(int i = 0; i < w; i++){
	  if(a[i] == -1){
	    f = true;
	    for(int j = 0; j < t; j++){
	      if(a[i+j] != -1 || i+j >= w){
		f = false;
		break;
	      }
	    }
	    if(f){
	      for(int j = 0; j < t; j++){
		a[i+j] = s;
	      }
	      cout << i << endl;
	      break;
	    }
	  }
	}
	if(!f){
	  cout << "impossible" << endl;
	}
      }
    }

    cout << "END" << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(){
  int n,k;
  int a[n],b[n];
  cin >> n;
  cout << 180*(n-2) << endl;
}

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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define fWrite          freopen ("out.txt","w",stdout);
#define TC              int t;cin >> t;FOR(tc,1,t)
#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define MEM(a,x)        memset(a,x,sizeof(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

int main()
{
    int arr[5];
    REP(i,5) cin >> arr[i];
    REP(i,5) {
        if(arr[i]==0){
            cout << i+1;
            return 0;
        }
    }
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c; cin >> a >> b >> c;
    for (int i=0;i<120;++i){
        int t=60*i+c;
        if (t%(a+b)<=a){
            cout << t << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';
}


Measured memory_bytes: 3212
#include <iostream>

int main()
{
	int N;
	std::cin >> N;
	int p[11];
	int max = 0;
	int result = 0;
	for (int i = 0; i < N; i++) {
		std::cin >> p[i];
		if (p[i] > max)max = p[i];
		result += p[i];
	}
	result = result - (max / 2);

	std::cout << result;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using static System.Math;
using System.Text;

namespace Program
{
    public static class ABC108D
    {
        static public void Main(string[] args)
        {
            var L = int.Parse(Console.ReadLine());
            var path = new List<string>();
            var stack = new Stack<int>();
            var sum = 1;
            var i = 1;
            for (; i <= 20; i++)
            {
                if ((L & 1) == 1) stack.Push(i);
                L >>= 1;
                if (L == 0) break;
                path.Add(i + " " + (i + 1) + " " + 0);
                path.Add(i + " " + (i + 1) + " " + sum);
                sum <<= 1;
            }
            stack.Pop();
            while (stack.Count > 0)
            {
                var idx = stack.Pop();
                path.Add(idx + " " + i + " " + sum);
                sum += Enumerable.Repeat(2, idx - 1).Aggregate(1, (x, y) => x * y);
            }
            Console.WriteLine(i + " " + path.Count);
            path.ForEach(Console.WriteLine);
        }
    }
}


Measured memory_bytes: 13268
# coding: utf-8
def main():
    n, a, b = map(int, input().split())
    ans = 0
    ans += n // (a+b) * a
    if n % (a+b) >= a:
        ans += a
    else:
        ans += n % (a+b)
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;
void solve(){
    string s;cin>>s;
    if (s.find("YAKI")==0) cout << "Yes" <<endl;
    else cout << "No" <<endl;
}

int main(){
/*/Debug by file input
    ifstream fin("input");
    cin.rdbuf(fin.rdbuf());// */
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
vector<int> temp;
void func(vector<int>::iterator beginIt, vector<int>::iterator endIt) {
    if (beginIt == endIt || ++beginIt == endIt) {
        return;
    }
    --beginIt;
    vector<int>::iterator minIt = min_element(beginIt, endIt);
    if (minIt == --endIt) {//もし最後尾が最小値だったら、最後尾を省く
        func(beginIt, minIt);
    }
    else {
        ++endIt;
        vector<int>::iterator maxIt = max_element(minIt, endIt);
        temp.push_back(*maxIt - *minIt);
        func(beginIt, minIt);
    }
}
int main(void) {
    int n;
    cin >> n;
    vector<int> vec;
    for (int i=0; i<n; i++) {
        int t;
        cin >> t;
        vec.push_back(t);
    }
    vector<int>::iterator minIt = min_element(vec.begin(),vec.end());
    if (minIt == --vec.end()) {
        func(vec.begin(), minIt);
    }
    else {
        vector<int>::iterator maxIt = max_element(minIt, vec.end());
        temp.push_back(*maxIt - *minIt);
        func(vec.begin(), minIt);   
    }
    if (temp.size() == 0) {
        vector<int> temp2;
        for(int i=0; i<n-1;i++) {
            temp2.push_back(vec[i+1]-vec[i]);
        }
        cout << *max_element(temp2.begin(), temp2.end()) << endl;
    }
    else {
        cout << *max_element(temp.begin(), temp.end()) << endl;
    }
    return 0;
}



Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> ap(A);
    vector<int> bp(B);
    int minA = 999999;
    int minB = 999999;
    for (int i = 0; i < A; i++) {
        cin >> ap.at(i);
        if (ap.at(i) < minA) minA = ap.at(i);
    }

    for (int i = 0; i < B; i++) {
        cin >> bp.at(i);
        if (bp.at(i) < minB) minB = bp.at(i);
    }

    struct wari {
        int x;
        int y;
        int c;
    };

    int minWarip = 999999;
    vector<wari> wa(M);
    for (int i = 0; i < M; i++) {
        struct wari w;
        cin >> w.x >> w.y >> w.c;
        wa.at(i) = w;
        int warip = ap.at(w.x - 1) + bp.at(w.y - 1) - w.c;
        if (warip < minWarip) minWarip = warip;
    }
    if (minWarip < (minA + minB)) {
        cout << minWarip;
    } else {
        cout << (minA + minB); 
    }
    cout << endl;
}

Measured memory_bytes: 2176
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}


signed main(){
    double pi     = 2.0 * asin(1.0); 
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    int hun = 60 * h + m;
    double theta = 5.5 * hun;
    while(theta > 360.0-eps){
        theta -= 360;
    }
    double now = 1.0 * a * a + 1.0 * b * b - 2.0 * a * b * cos(theta * pi /180.0);
    double ans = sqrt(now);
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define FR(i,a,b) for(int i = (a);i<(b);i++)
#define RF(i,a,b) for(int i = (a);i>(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 100005
#define M 51
#define INF 100000000000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-14
using namespace std;
inline int Max(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^b;
}
inline int Min(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^a;
}

ll a[N];
ll rmp[N];
pair<ll,ll>b[N];
vector<ll>v;
void update(int p,pair<ll,ll> x)
{
    while(p<N)
    {
        b[p].FT+=x.FT;
        b[p].SD+=x.SD;
        p+=(p&-p);
    }
}
pair<ll,ll> query(int p)
{
    pair<ll,ll> ret = MP(0,0);
    while(p>0)
    {
        ret.FT+=b[p].FT;
        ret.SD+=b[p].SD;
        p-=(p&-p);
    }
    return ret;
}
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        v.clear();
        FOR(i,1,n)
        {
            scanf("%lld",&a[i]);
            v.PB(a[i]);
        }
        sort(v.begin(),v.end());
        int sz = unique(v.begin(),v.end())-v.begin();
        v.resize(sz);
        rmp[0] = 0;
        FOR(i,1,n)
        {
            int p = lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
            rmp[p] = a[i];
            update(p,MP(a[i],1));
        }
        int p1 = 0,p2 = 0;
        FOR(i,1,n)
        {
            int p = lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
            if(p<p2)
            {
                update(p,MP(-a[i],-1));
                printf("0\n");
                continue;
            }
            p1 = p2;
            p2 = p;
            pair<ll,ll> x = query(p1);
            pair<ll,ll> y = query(p2);
            printf("%lld\n",y.FT-(ll)(y.SD-x.SD)*rmp[p1]-x.FT+(ll)(n-i+1-y.SD)*(rmp[p2]-rmp[p1]));
            update(p,MP(-a[i],-1));
        }

    }
    return 0;
}


Measured memory_bytes: 5108
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

def eratosthenes(n):
  prime = []
  limit = math.sqrt(n)
  data = [i + 1 for i in range(1, n)]
  while True:
    p = data[0]
    if limit <= p:
      return prime + data
    prime.append(p)
    data = [e for e in data if e % p != 0]
  return prime

x = int(input())
while True:
  ary = eratosthenes(x)
  if ary[-1] == x:
    break
  else:
    x += 1
print(x)


Measured memory_bytes: 17828
import sys
sys.setrecursionlimit(1000000)

N = int(input())
X = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    X[u-1].append((v-1, w%2))
    X[v-1].append((u-1, w%2))

D = [-1] * N
def calc(i, c):
    D[i] = c
    for j, w in X[i]:
        if D[j] < 0:
            calc(j, D[i]^w)

calc(0, 0)
for d in D:
    print(d)

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

int main() {
	string s ;
	cin >> s;
	long long int ans=0 , n=s.length();
	int c[26]={0};
	for(int i=0; i<s.length() ;i++){
		c[s[i]-'a']++;
	}
	ans=(n-1)*(n);
	ans/=2;
	ans++;
	
	for(int i=0; i<26; i++){
		long long int t;
		t=c[i];
		if(t>1){
			t=t*(t-1);
			t/=2;
			ans-=t;
		}
	}
	
	cout << ans ;
	
	return 0;
}

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

int judge_prime(int *);

int main(){
  int n,i,prime_count;
  int *p;

  prime_count = 0;
   
  scanf("%d",&n);
  if(n < 1 || 10000 < n)exit(0);
  
  p = malloc(n*sizeof(int));
   
  for(i = 0; i < n; i++){//inputxn
    scanf("%d",p+i);
    if(*(p+i) < 2 || 100000000 < *(p+i))exit(1);
    prime_count += judge_prime(p+i);
  }
  
  printf("%d\n",prime_count);

  return 0;
}

int judge_prime(int *num){
  int i;
  double sq;

  if(*num == 2) return 1;
  if(*num < 2 || (*num)%2 == 0)return 0;

  sq = sqrt((double)(*num));
  i = 3;
  
  while(i <= sq){
    if((*num) % i == 0)return 0;
    i = i + 2;
  }
  
  return 1;
}



Measured memory_bytes: 2064
n,m = gets.chomp.split(" ").map(&:to_i)

a_arr = []
m.times do |i|
  a_arr << gets.chomp.to_i
end
a_arr << n+1

fib = [1, 1]
100000.times do |i|
  fib[2+i] = fib[2+(i-1)] + fib[2+(i-2)]
end

arr = []
step = 0
prev = -1
a_arr.each do |a|
  if a - prev == 1 then
    puts 0
    exit
  end
  count = a - step - 1
  #puts count
  if count > 0 then
    arr << fib[count]
  end
  step = a + 1
  prev = a
end

result = 1
arr.each do |a|
  result *= a
  result = result % 1000000007
end

puts result


Measured memory_bytes: 435068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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 long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const ll mod = 1000000007;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];
ll beki(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    const int MAX = 10000002;
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}
ll N;
vector<int> paths[200100];
vector<int> children[200100];
ll dp[200100];

ll p[200100];
ll SIZE[200100];
ll ans[200100];
void dfs0(int now) {
    SIZE[now] = 1;
    vector<ll> v;
    dp[now] = 1;
    for(auto to : paths[now]) {
        if(to == p[now]) continue;
        p[to] = now;
        children[now].push_back(to);
        dfs0(to);
        SIZE[now] += SIZE[to];
        dp[now] *= dp[to];
        dp[now] %= mod;
        v.push_back(SIZE[to]);
    }
    dp[now] *= Factorial[SIZE[now] - 1];
    dp[now] %= mod;
    for(auto tmp : v) {
        dp[now] *= FactorialInv[tmp];
        dp[now] %= mod;
    }
}

void dfs1(int now) {
    ll P = 1;
    if(p[now] != -1) {
        P = ans[p[now]];
        P *= FactorialInv[N - 1];
        P %= mod;
        P *= Factorial[N-1-SIZE[now]];
        P %= mod;
        P *= Factorial[SIZE[now]];
        P %= mod;
        P *= beki(dp[now], mod - 2);
        P %= mod;
    }
    cerr << now << " " << P << endl;
    ans[now] = dp[now] * P % mod;
    ans[now] *= combination(N - 1, SIZE[now] - 1);
    ans[now] %= mod;
    for(auto to : children[now]) dfs1(to);
}

int main() {
    init_combination();
    cin >> N;
    for(int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        paths[a].push_back(b);
        paths[b].push_back(a);
    }
    p[0] = -1;
    dfs0(0);
    dfs1(0);
    for(int i = 0; i < N; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 262656
import math

def ok_check(half, data, num, a, b):
    kari = 0
    for i in range(num):
        nokori = data[i] - half * b
        if nokori > 0:
            kari += math.ceil(nokori / (a - b))
    if kari > half:
        return 0
    else:
        return 1

def check(left, right, data, num, a, b):
    if left == right - 1:
        print(right)
        return
    half = (left + right) // 2
    if ok_check(half, data, num, a, b):
        check(left, half, data, num, a, b)
    else:
        check(half, right, data, num, a, b)

def main():
    num, a, b = map(int, input().split())
    data = [int(input()) for i in range(num)]

    left = 0
    right = max(data) // b + 1
    check(left, right, data, num, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 51416
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}
#define NUM_MAX 100000

int main(void) {
    int num, t;
    // t is dummy
    get_int2(&num, &t);

    static int arr[NUM_MAX];
    fget_array(arr, num);

    int i;
    int mmax = arr[num-1];
    int diff = 0;
    int cnt = 1;
    for(i = num-2; i >= 0; i--) {
        int cur = arr[i];
        int profit = max(0, mmax - cur);
        if(diff < profit) {
            cnt = 1; // reset
            diff = profit;
        } else if (diff == profit) {
            cnt++;
        }
        mmax = max(cur, mmax);
    }

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

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int e,y;
    cin>>e>>y;
    if(e==0&&1868<=y&&y<=1911){
        cout<<"M"<<y%1867<<endl;
    }
    else if(e==0&&1912<=y&&y<=1925){
        cout<<"T"<<y%1911<<endl;
    }
    else if(e==0&&1926<=y&&y<=1988){
        cout<<"S"<<y%1925<<endl;
    }
    else if(e==0&&1989<=y&&y<=2016){
        cout<<"H"<<y%1988<<endl;
    }
    else if(e==1){
        cout<<1867+y<<endl;
    }
    else if(e==2){
        cout<<1911+y<<endl;
    }
    else if(e==3){
        cout<<1925+y<<endl;
    }
    else if(e==4){
        cout<<1988+y<<endl;
    }
    }


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    ll ans;
    if(k == 0){
        ans = a - b;
    }else if(k % 2 == 1){
        ans = b - a;
    }else{
        ans = a - b;
    }

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


Measured memory_bytes: 256
N, K = map(int, input().split())
S = list(map(int, input()))

xs = []
cur, length = S[0], 1
for i in range(1, N):
    if S[i] != cur:
        xs.append((cur, length))
        cur = S[i]
        length = 1
    else:
        length += 1
xs.append((cur, length))

if sum(1 for v, l in xs if v == 0) <= K:
    print(N)
else:
    length = 0
    changed_count = 0
    for i, (v, l) in enumerate(xs):
        if v == 0:
            changed_count += 1
        length += l
        if changed_count == K:
            left = 0 if xs[0][0] == 0 else 1
            if i + 1 < len(xs):
                length += xs[i + 1][1]
            break
    max_length = length
    for right in range(i + 2, len(xs), 2):
        length -= xs[left][1]
        if 0 <= left - 1:
            length -= xs[left - 1][1]
        length += xs[right][1]
        if right + 1 < len(xs):
            length += xs[right + 1][1]
        max_length = max(max_length, length)
        left += 2
    print(max_length)

Measured memory_bytes: 50780
//NAME-DEEPESH BHATT
//Institute-IIT Dhanbad
//MOTTO-THINK FIRST,CODE LATER

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007  ;
#define pb push_back
#define mp make_pair

//Check for signed int overflow

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
ll power(ll a,ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p);
    if (n % 2)
        return (p * a);
    else
        return p;
}
/*vector<bool>is_prime(1000001,true);
void sieve(){
    is_prime[0]=is_prime[1]=false;
    is_prime[2]=true;
    for(int i=2;i*i<=1000000;i++){
        if(is_prime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                is_prime[j]=false;
            }
        }
    }
}*/

/*bool is_sorted(int *arr,int n){
    for(int i=0;i<n-1;i++){
        if(arr[i+1]<arr[i]){
            return false;
        }
    }
    return true;
}*/

void solve(){
    int x[5];
    int ans=0;
    for(int i=0;i<5;i++){
        cin>>x[i];
        if(x[i]==0){
            ans=i+1;
        }
    }
    cout<<ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(NULL);
    ll test=1;
    /*cin>>test;*/
    while(test--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3604
//

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <iomanip>
#include <fstream>

using namespace std;

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

#define endl "\n"
#define mp make_pair

const int mod = 1000000007;
const int INF = 1000000000;

int n, a, b;
string result = "Draw";

int main() {
	bool alice = 1;

	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> a >> b;

	for (int i = 0; i <= 1000000; i++) {
		if (alice) {
			if (a < (b - 1))
				a++;
			else if (a == 1) {
				result = "Borys";
				break;
			}
			else
				a--;
		}
		else {
			if (b > (a + 1))
				b--;
			else if (b == n) {
				result = "Alice";
				break;
			}
			else
				b++;
		}

		alice ^= 1;
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
val, size = map(int, input().split())
disabledList = [int(x) for x in input().split()] # number
enableList = list(set(range(10)) - set(disabledList)) # number
resultList = [] # str, must reverse
isTenOver = False
for char in reversed(list(str(val))):
  targetInt = int(char)
  if isTenOver:
    targetInt += 1
  if targetInt in enableList:
    isTenOver = False
    resultList.append(str(targetInt))
    continue
  resultList = [str(min(enableList))] * len(resultList)
  if targetInt > max(enableList):
    isTenOver = True
    resultList.append(str(min(enableList)))
  else:
    isTenOver = False
    minNum = min(filter(lambda x:x > targetInt, enableList))
    resultList.append(str(minNum))

if isTenOver:
  minNum = min(filter(lambda x:x > 0, enableList))
  resultList.append(str(minNum))
print(''.join(reversed(resultList)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(b>a)return 0;
	if(a==b)return 1;
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n;
P p[100010];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int a;
		cin>>a;
		p[i-1]={a,i};
	}
	sort(p,p+n);
	rep(i,n)cout<<p[i].se<<(i==n-1?"\n":" ");
	return 0;
}


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

	    public static void main(String[] args) throws java.io.IOException{
	        Scanner scan = new Scanner(System.in);
	        boolean [] prime =new boolean[50022];
	        for(int i=2;i<prime.length;i++)prime[i]=true;
	        for(int i=2;i<=Math.sqrt(prime.length-1);i++){
	        	if(prime[i])
	        		for(int j=i*2;j<=prime.length-1;j+=i)prime[j]=false;
	        }
	        while(scan.hasNext()){
	        	
	        	int n=scan.nextInt();
	        	int prev =0;
	        	for(int i=0;i<50022;i++){
	        		if(prime[i]){
	        			if(i>n){
	        				System.out.println(prev+" "+i);
	        				break;
	        			}
	        			if(i!=n)
	        				prev = i;
	        		}
	        	}
	        	
	        }
	    }
}
	    

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

using namespace std;

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

    vector<int> a(3);
    for (int i = 0; i < 3; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    int sum = (a[1] - a[0]) + (a[2] - a[1]);
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':

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

    tmp1 = (n // (a + b)) * a
    if tmp1 == 0:
        tmp2 = min(n,a)
    else:
        tmp2 = n % (a + b)
        tmp2 = min(a,tmp2)
    print(tmp1+tmp2)

Measured memory_bytes: 9172
module Main where

import           Control.Monad
import           Data.List
import Prelude


main = do
  n  <- read <$> getLine
  rs <- replicateM n getPair
  print $ solve rs

getPair = (\(x : y : _) -> (x, y)) . fmap read . words <$> getLine

solve :: [(Int, Int)] -> Int
solve xs = uncurry (+) $ foldl' getNextVotes (1, 1) xs


-- 現在の投票数と次の投票数の比から、次の投票数を返却する
getNextVotes ::  (Int, Int) -> (Int, Int) -> (Int, Int)
getNextVotes (a, b) (x, y) =  (n * x,  n * y) where
  n = max (a `ceilDiv` x) (b `ceilDiv` y)

ceilDiv :: Int -> Int -> Int
ceilDiv x y = x `div` y + (if x `mod` y == 0 then 0 else 1)


Measured memory_bytes: 1916
#include<stdio.h>
 
int main(void){
  int i;
  int n;
  int m;
  int a;
  scanf("%d%d",&n, &m);
  for(i = 0; i < m; i++){
    scanf("%d", &a);
    n -= a;
  }
  if (n < -1)
    n=-1;
  printf("%d",n);
}

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

typedef long long ll;
//#define int ll
#define db(x) cout<<#x<<" = "<<x<<"\n";
#define FIN ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ALL(a) a.begin(),a.end()
#define mset(a,b) memset(a,b,sizeof(a));


main() 
{
	FIN;
	int n;
	char c;
	cin>>c;
	if(isupper(c))
	{
	    cout<<"A"<<endl;
	}
	else
	cout<<"a"<<endl;
  
}

Measured memory_bytes: 3648
#include<cstdio>
#define N 65536
#define p 1000000007
#define ll long long
int a[N],b[N],c[N],d[N],f[N],i,j,k,m,n,q;
inline int A(int x,int y){return x<y?0:(ll)a[x]*b[x-y]%p;}
int main()
{
	scanf("%d%d",&n,&m),*f=q=1<<n,*a=*b=a[1]=b[1]=1;
	for(i=2;i<q;i++)a[i]=(ll)a[i-1]*i%p,b[i]=(ll)(p-p/i)*b[p%i]%p;
	for(i=2;i<q;i++)b[i]=(ll)b[i-1]*b[i]%p;
	for(i=1;i<=m;i++)scanf("%d",c+i);
	for(i=m,c[m+1]=(1<<n)+1;i;i--)d[i]=d[i+1]+c[i+1]-c[i];
	for(k=m;k;k--)for(i=q;i--;)if(f[i])for(j=0;j<n;j++)if(~i>>j&1)f[i|1<<j]=(f[i|1<<j]+(ll)(p-f[i])*A(d[k]-i-1,(1<<j)-1)%p*(1<<j))%p;
	for(i=k=0;i<q;i++)k=(k+(ll)f[i]*a[q-1-i])%p;
	return 0*printf("%d\n",k);
}

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

#define FOR( i, m, n )   for( int i = m; i < n; i++ )
#define REP( i, n )      FOR( i, 0, n )
#define ALL( a )         (a).begin(), (a).end()

int main(){
  int n; cin >> n;
  switch( n % 7 ){
  case 0: cout << "thu" << endl; break;
  case 1: cout << "fri" << endl; break;
  case 2: cout << "sat" << endl; break;
  case 3: cout << "sun" << endl; break;
  case 4: cout << "mon" << endl; break;
  case 5: cout << "tue" << endl; break;
  case 6: cout << "wed" << endl; break;
  }
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int h, w;
    cin >> h >> w;
    vvi a(h, vi(w));
    rep(i, h) rep(j, w) cin >> a[i][j];
    vi ab, b, c, d;
    int cnt = 0;
    rep(i, h) rep(j, w) {
        if (i == h-1 && j == w-1) continue;
        if (a[i][j] % 2 == 1) {
            a[i][j]--;
            cnt++;
            if (j == w-1) {
                a[i+1][j]++;
                ab.pb(i+1), b.pb(j+1), c.pb(i+2), d.pb(j+1);
            } else {
                a[i][j+1]++;
                ab.pb(i+1), b.pb(j+1), c.pb(i+1), d.pb(j+2);
            }
        }
    }
    cout << cnt << endl;
    rep(i, cnt) cout << ab[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl;
}

Measured memory_bytes: 5224
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, ans;
    string S;
    cin >> S;
    int i = S.size() - 1;
    if ( S.at(i) - '0' == 3 ){
        cout << "bon" << endl;
    }
    else if ( S.at(i) - '0' == 0 
        ||    S.at(i) - '0' == 1 
        ||    S.at(i) - '0' == 6  
        ||    S.at(i) - '0' == 8 ){
        cout << "pon" << endl;
    }
    else cout << "hon" << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INF = 2147483647;
#define rep(i, n) rep3(i, 0, n)
#define rep2(i, n) rep3(i, 1, n+1)
#define rep3(i, x, n) for(ll i = x; i < (ll)(n); i++)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}
template<class T>
void printp(vector<pair<T,T>> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}
template<class T>
void printp(map<T,T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
 
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
 
        // その結果を push
        res.push_back({a, ex});
    }
 
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(void){
    char a;
    cin>>a;
    cout << ((65<=a && a<=90)? "A" : "a") << endl;
    
    return 0;
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    deque<char>d;
    int dir = 0;
    for(int i=0;i<s.length();i++){
        d.push_back(s[i]);
    }
    int t;
    cin>>t;
    while(t--){
        int ch;
        cin>>ch;
        if(ch == 1){
            dir = dir ^ 1;
        }else{
            int x;
            char c;
            cin>>x>>c;
            if(dir == 0){
                if(x == 1){
                    d.push_front(c);
                }else{
                    d.push_back(c);
                }
            }else{
                if(x == 1){
                    d.push_back(c);
                }else{
                    d.push_front(c);
                }
            }
        }
    }
    string res = "";
    if(dir == 0){
        for(auto c:d){
            res += c;
        }
    }else{
        while(!d.empty()){
            res += d.back();
            d.pop_back();
        }
    }
    cout<<res<<endl;
    return 0;
    
}



Measured memory_bytes: 1368