akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;

ll comb(ll n, ll r) {
    ll num = 1, den = 1;
    for (ll i = 0; i < r; i++) {
        num *= (n - i);
        num %= mod;
        den *= (r - i);
        den %= mod;
    }

    ll power = mod - 2, x = den;
    ll ans = 1;
    while (power) {
        if (power % 2) {
            ans *= x;
            ans %= mod;
        }

        power /= 2;
        x = (x * x) % mod;
    }

    return (num * ans) % mod;

}


int main() {
//    cout << setprecision(30);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= m; j++) {
            ans += ((i * (i - 1) / 2) * m) % mod;
            ans += ((j * (j - 1) / 2) * n) % mod;
            ans %= mod;
        }
    }

    cout << (ans * comb(n * m - 2, k - 2)) % mod;


}



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

class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		int[] num = new int[3];
		for(int i=0;i<n;i++){
			if(a[i]%4==0){
				num[0]++;
			}
			else if(a[i]%2==0){
				num[1]++;
			}
			else{
				num[2]++;
			}
		}
		if(num[2]>num[0]+1){
			System.out.println("No");
		}
		else if(num[2]>num[0] && num[1]!=0){
			System.out.println("No");
		}
		else if(num[2]!=0 && num[0]==0){
			System.out.println("No");
		}
		else{
			System.out.println("Yes");
		}
	} 
}


Measured memory_bytes: 48712
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define prique priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const int_fast64_t MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t
using Graph = vector<vector<int> >;
typedef pair<int, int> P;

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

int dp[42][1<<17];

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

  int N, X, Y, Z; cin >> N >> X >> Y >> Z;

  // pre
  int all = 1;
  REP(i, N){
    all *= 10; all %= MOD;
  }

  int ng = 0;
  ng |= 1<<(Z-1);
  ng |= 1<<(Z+Y-1);
  ng |= 1<<(Z+Y+X-1);

  dp[0][0] = 1;
  REP(i, N) REP(j, 1<<(X+Y+Z)){
    for(int num = 1; num <= 10; num++){
      int nx = (j<<num) | (1<<(num-1));
      if((ng & nx) == ng) continue;
      nx &= ((1<<(X+Y+Z)) - 1);

      dp[i+1][nx] += dp[i][j];
      dp[i+1][nx] %= MOD;
    }
  }
  int ans = 0;
  REP(i, 1<<(X+Y+Z)){
    ans += dp[N][i]; ans %= MOD;
  }
  
  cout << (all+MOD-ans) % MOD << endl;
}


Measured memory_bytes: 42240
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int N,M;
    cin>>N>>M;
    int p[M];
    string s[M];
    for(int i=0;i<M;i++){
        cin>>p[i]>>s[i];
    }
    
    vector<bool> ACed(N,false);
    vector<int> WAed(N,0);
    int ACcnt = 0;
    int WAcnt = 0;
    for(int i=0;i<M;i++){
        if(s[i] == "AC" && ACed[p[i]-1] == false){
            ACcnt++;
            ACed[p[i]-1] = true;
            WAcnt += WAed[p[i]-1];
        }
        else if(s[i] == "WA" && ACed[p[i]-1] == false){
            WAed[p[i]-1]++;
        }
    }
    cout << ACcnt << " " << WAcnt << endl;
    return 0;
}

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

int a[200010];
int f1[200010][18], f2[200010][18];
long long s1[200010][18], s2[200010][18];

int main () {
	int n, k; scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	int pos = 1;
	for (int i = 1; i <= n; i++) {
		while (pos <= n && a[pos] - a[i] < k) pos++;
		f1[i][0] = s1[i][0] = pos;
	}
	f1[n + 1][0] = s1[n + 1][0] = n + 1;
	pos = n;
	for (int i = n; i >= 1; i--) {
		while (pos >= 1 && a[i] - a[pos] < k) pos--;
		f2[i][0] = s2[i][0] = pos;
	}
	f2[0][0] = s2[0][0] = 0;
	for (int j = 1; j < 18; j++) {
		for (int i = 0; i <= n + 1; i++) {
			f1[i][j] = f1[f1[i][j - 1]][j - 1];
			s1[i][j] = s1[i][j - 1] + s1[f1[i][j - 1]][j - 1];
			f2[i][j] = f2[f2[i][j - 1]][j - 1];
			s2[i][j] = s2[i][j - 1] + s2[f2[i][j - 1]][j - 1];
		}
	}
	int q; scanf("%d", &q);
	while (q--) {
		int l, r; scanf("%d%d", &l, &r);
		int now = l; long long ss1 = l; int c1 = 1;
		for (int i = 17; i >= 0; i--) {
			if (f1[now][i] <= r) ss1 += s1[now][i], now = f1[now][i], c1 += 1 << i;
		}
		now = r; long long ss2 = r; int c2 = 1;
		for (int i = 17; i >= 0; i--) {
			if (f2[now][i] >= l) ss2 += s2[now][i], now = f2[now][i], c2 += 1 << i;
		}
		assert(c1 == c2);
		printf("%lld\n", ss2 - ss1 + c1);
	}
	return 0;
}


Measured memory_bytes: 88988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 1e5 + 5;

int n, m, a, b, ans;
int par[N];
bool vis[N];

void init() {
    for(int i = 1; i <= n; i++) par[i] = i;
}

int root(int x) {
    return par[x] == x ? x : par[x] = root(par[x]);
}

void join(int x, int y) {
    par[root(x)] = root(y);
}

void solve() {
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++) {
        cin >> n >> m;
        init();
        while(m--) {
            cin >> a >> b;
            join(a, b);
        }
        for(int i = 1; i <= n; i++) {
            if(!vis[root(i)]) {
                vis[root(i)] = true;
                ans++;
            }
        }
        cout << ans - 1 << "\n";
    }
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

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

/**
 * Made by egor https://github.com/chermehdi/egor.
 * 
 * @author Azuz
 */
public class Main {

    void solve(Scanner in, PrintWriter out) {
        int n = in.nextInt();
        int[] ans = new int[n + 1];
        for (int i = 2; i <= n; ++i) {
            ++ans[in.nextInt()];
        }
        for (int i = 1; i <= n; ++i) {
            out.println(ans[i]);
        }
    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


Measured memory_bytes: 61600
#include <bits/stdc++.h>
using namespace std;
#define rep(shoki,i,n) for(int i=shoki; i<n; i++)
#define _GLIBCXX_DEBUG
using ll = long long;
using vi = vector<int>;
int main(){
    int n,t,a,x; cin>>n>>t>>a;
    int mindeff = 1<<30;
    int index = 0;
    rep(1,i,n+1){
        cin>>x;
        int deff = max(a*1000,t*1000-x*6)-min(a*1000,t*1000-x*6);
        if(deff<mindeff){
            mindeff = deff;
            index = i;
        }
    }
    cout << index << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
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;}
int main()
{
int n;
string s;
cin >> n >> s;

rep(i,s.size()){
    if(s[i]+n <= 'Z'){
        s[i] = char(s[i]+n);
    }else{
        s[i] = char(s[i]+n-26);
    }
}

cout << s << endl;

return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int p[110000];
int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	for(int i=0;i<n;i++)scanf("%d",p+i);
	int left=0;
	int right=mod;
	while(left+1<right){
		int M=(left+right)/2;
		long long req=0;
		for(int i=0;i<n;i++){
			long long rem=p[i]-(long long)b*M;
			if(rem>0){
				req+=(rem+a-b-1)/(a-b);
			}
		}
		if(req<=M){
			right=M;
		}else left=M;
	}
	printf("%d\n",right);
}

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

string S;

int main() {
	cin >> S;
	int n = S.size();
	int ans = n;
	for (int i = 0; i < n - 1; i++) {
		if (S[i] != S[i + 1]) {
			ans = min(ans, max(i + 1, n - (i + 1)));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
const long long MOD = 1E+9 + 7;

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

int main() {
	int x, y;
	cin >> x >> y;
	int sum = x + y;
	if (sum % 3) {
		cout << 0 << endl;
		return 0;
	}
	int xcount = x - sum / 3;
	int ycount = y - sum / 3;
	if (xcount < 0 || ycount < 0) {
		cout << 0 << endl;
		return 0;
	}
	int countsum = xcount + ycount;
	long long ans = 1, xdiv = 1, ydiv = 1;
	for (int i = 2; i <= countsum; i++) {
		ans *= i;
		ans %= MOD;
	}
	for (int i = 2; i <= xcount; i++) {
		xdiv *= i;
		xdiv %= MOD;
	}
	for (int i = 2; i <= ycount; i++) {
		ydiv *= i;
		ydiv %= MOD;
	}
	ans *= modinv(xdiv, MOD);
	ans %= MOD;
	ans *= modinv(ydiv, MOD);
	ans %= MOD;
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>

// positive only
int get_int() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return -1;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
int linear_search(int key, int *arr, int N) {
    arr[N] = key;
    int i = 0;
    // search 0 -> N
    while(arr[i++] != key) {};
    return i > N ? 0 : 1;
}
int main(int argc, char **argv) {
    int n = get_int();
    int s[10001];
    for(int i = 0; i < n; ++i) {
        s[i] = get_int();
    }
    int q = get_int();
    int cnt = 0;
    int t;
    while(q--) {
        t = get_int();
        linear_search(t, s, n) && cnt++;
    }
    printf("%d\n", cnt);
}



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

typedef long long LL;
typedef LL i128;

i128 A[3][3], B[3][3];

LL a, b, c, k;


void mult(i128 a[][3], i128 b[][3], i128 c[][3]) {
	i128 t[3][3];
	memset(t, 0, sizeof t);
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 3; ++j)
			for (int k = 0; k < 3; ++k)
				t[i][k] += a[i][j] * b[j][k];
	memcpy(c, t, sizeof t);
}


int main() {
	/*
	A[0][1] = A[0][2] = A[1][0] = A[1][2] = A[2][0] = A[2][1] = 1;
	B[0][0] = B[1][1] = B[2][2] = 1;

	for (int i = 0; i < 10; ++i) {
		mult(A, B, B);
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 3; ++k)
				cout << B[j][k] << ' ';
			puts("");
		}
			puts("");
	}
	*/

	cin >> a >> b >> c >> k;
	if (k & 1) a = b - a;
	else a = a - b;
	cout << a << endl;;
		/*
	if (k == 0) {
		cout << a - b << endl;
	} else {
		for (; k != 0; k >>= 1) {
			if (k & 1) {
				mult(A, B, B);
			}
			mult(A, A, A);
		}
		i128 ans = b * B[1][0] + c * B[2][0] - a * B[0][1] - c * B[2][1];
		cout << ans << endl;
	}
		*/

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  cin.ignore();
  vector<int> a(n);
  for (int i = 0; i < n; i++) a.at(i) = getchar() - '1';
  bool exist1 = false;
  for (int i = 0; i < n; i++) {
    if (a.at(i) == 1) {
      exist1 = true;
      break;
    }
  }
  if (exist1) {
    for (int i = 0; i < n; i++) a.at(i) %= 2;
  } else {
    for (int i = 0; i < n; i++) a.at(i) /= 2;
  }
  vector<int> count2(n);
  for (int i = 1; i < n; i++) {
    int k = i;
    count2.at(i) = count2.at(i - 1);
    while (k > 0 && k % 2 == 0) {
      count2.at(i)++;
      k /= 2;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (count2.at(i) + count2.at(n - 1 - i) == count2.at(n - 1)) {
      ans = (ans + a.at(i)) % 2;
    }
  }
  if (!exist1) ans *= 2;
  cout << ans << endl;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using namespace std;

long long a[100010][3];
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    long long res = 0;
    for (int j = 0; j < 3; ++j) {
        chmax(res, dp[N][j]);
    } 
    cout << res << endl;
}

Measured memory_bytes: 4992
str = gets.chomp
gets.to_i.times do
  command, a, b, p = gets.split
  a = a.to_i
  b = b.to_i
  case command
  when "replace"
    str[a..b] = p
  when "reverse"
    str[a..b] = str[a..b].reverse
  when "print"
    puts str[a..b]
  end
end

Measured memory_bytes: 8676
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

ll n;
V<ll> ans,cnt,last,und,col,ue;
VV<int> e;

ll dfs1(int now,int pre){
  ll num=1;
  for(auto&& nex:e[now]){
    if(nex==pre)continue;
    num+=dfs1(nex,now);
  }
  und[now]=num;
  return num;
}


void dfs2(int now,int pre){
  int tmp=last[col[now]];

  for(auto&& nex:e[now]){
    if(nex==pre)continue;

    last[col[now]]=nex;
    dfs2(nex,now);

    if(now==0){
      rep(i,1,n+1){
        ans[i]-=ue[i]*(ue[i]+1)/2;
      }
    }else{
      ans[col[now]]-=cnt[nex]*(cnt[nex]+1)/2;
    }
  }

  last[col[now]]=tmp;

  if(last[col[now]]>0)cnt[last[col[now]]]-=und[now];
  else ue[col[now]]-=und[now];

  return;
}

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

  e.assign(n+1,V<int>(0));
  ans.assign(n+1,n*(n+1)/2);
  und.assign(n+1,0);
  col.assign(n+1,0);
  last.assign(n+1,0);
  ue.assign(n+1,n);


  rep(i,0,n)cin>>col[i+1];
  rep(i,0,n-1){
    int a,b;cin>>a>>b;
    e[a].pb(b);
    e[b].pb(a);
  }
  e[0].pb(1);

  dfs1(0,-1);
  cnt=und;
  dfs2(0,-1);

  rep(i,1,n+1){
    cout<<ans[i]<<ENDL;
  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 35948
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var a2 = new bool[2 * n+1];
            generatePrime(a2);
            var res = 0;
            for (int i = n + 1; i < a2.Length; i++)
                if (!a2[i]) res++;
            Console.WriteLine(res);
        }
    }
    public static void generatePrime(bool[] f)
    {
        var pL = f.Length;                                           // prime :  false
        f[0] = true; f[1] = true;
        for (int i = 2; i < pL; i++)
            if (!f[i])
                for (int j = i + i; j < pL; j += i) f[j] = true;
    }
}




Measured memory_bytes: 9732
#include<bits/stdc++.h>
#define fr(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int k,s;
  cin >> k >> s;
  int res=0;
  fr(x,k+1){
    fr(y,k+1){
      int z=s-x-y;
      if(0<=z&&z<=k)res++;
    }
  }
  cout << res << endl;
}


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

public class Main {
	// ??????d???left??????right?????§???????????????????????????????????????????????????
	static void quick_sort(int[] d, int left, int right) {
		if (left >= right) {
			return;
		}
		int p = d[(left + right) / 2];
		int l = left, r = right, tmp;
		while (l <= r) {
			while (d[l] < p) {
				l++;
			}
			while (d[r] > p) {
				r--;
			}
			if (l <= r) {
				tmp = d[l];
				d[l] = d[r];
				d[r] = tmp;
				l++;
				r--;
			}
		}
		quick_sort(d, left, r); // ???????????????????????´????????????????????????
		quick_sort(d, l, right); // ???????????????????????´????????????????????????
	}

	// ?????????????????????????????¨?????????
	static void print_data(int[] d) {
		for (int i = 0; i < d.length; i++){
			if(i==d.length-1){
				System.out.println(d[i]);
			}else{
				System.out.print(d[i] + " ");
			}
		}
//		System.out.println();
	}

	public static void main(String[] args) throws IOException {
		//        int[] data = {5, 10, 3, 7, 8, 1, 9, 2};
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		String str = br.readLine();

		String[] inputData = str.split(" ");

		int data[] = new int[inputData.length];

		for(int i=0;i<inputData.length;i++){
			data[i] = Integer.parseInt(inputData[i]);
		}


//		print_data(data);
		quick_sort(data, 0, data.length - 1);
		print_data(data);
	}
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll n;cin>>n;
  ll a[n];rep(i,0,n)cin>>a[i];
  sort(a,a+n);

  ll q;cin>>q;
  ll ans=0;
  rep(i,0,q){
    ll b;cin>>b;
    ll l=-1,r=n;
    while(r-l>1){
      ll mid=(l+r)/2;

      if(a[mid]==b){ans++;break;}
      else if(a[mid]<b)l=mid;
      else r=mid;
    }
  }

  out(ans);

  return 0;
}



Measured memory_bytes: 3908
def main():
    k = int(input())
    n = 7
    if k % 2 == 0:
        print(-1)
    else:
        for i in range(10 ** 7):
            if n % k == 0:
                print(i + 1)
                break
            n = (10 * n + 7) % k
        else:
            print(-1)


if __name__ == '__main__':
    main()



Measured memory_bytes: 9164
#include <stdio.h>

int main() {
    int n, a[105];
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    for (int i = n; i > 0; i--) {
        printf("%d", a[i]);
        if (i > 1) printf(" ");
    }
    printf("\n");
}


Measured memory_bytes: 2056
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>

int main() {

    int N, K, X, A, B, D, tmp1, tmp2, i = 0, ans = 0, cst = 1;

    std::cin >> N >>D;

    double x[N][D];

    int n=0, d=0;

    while(std::cin >> tmp1){
        x[n][d] = tmp1;
        d++;
        if(d==D){
            d=0;
            n++;
        }
        i++;
        if(i >= N*D){
            break;
        }
    }

    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            double tmp = 0;
            for(int k=0;k<D;k++){
                tmp += std::pow((x[i][k] - x[j][k]),2);
            }
            int tmp2 = sqrt(tmp);
            if(sqrt(tmp) - (double)tmp2 == 0.0){
                ans++;
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
t = input()
nagasa = len(t)
ans = ""
okflag = 0
for i in range(n - nagasa + 1):
    temp = True
    for j in range(nagasa):
        if s[i + j] == "?":
            continue
        else:
            if s[i + j] == t[j]:
                temp = True
            else:
                temp = False
        if temp is False:
            break
    if temp is True:
        okflag = 1
        start = i
if okflag:
    for i in range(n):
        if i >= start and i < start + nagasa:
            ans += t[i - start]
        else:
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
else:
    ans = "UNRESTORABLE"
print(ans)


Measured memory_bytes: 3064
n = int(input())
p = [int(_) for _ in input().split()]
ans = 0
for i in range(1,n-1):
    a = p[i-1]
    b = p[i]
    c = p[i+1]
    if a > b > c:
        ans += 1
    elif c > b > a:
        ans += 1
        
print(ans)

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

ll solve(ll n,ll k)
{
    ll ans=(n/k)*(n/k)*(n/k);
    if(k%2==0)
    {
        n+=k/2;
        ans+=(n/k)*(n/k)*(n/k);
    }
    return ans;
}

int main()
{
    ll n,k;cin>>n>>k;
    cout<<solve(n,k)<<endl;
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string s, t;
  cin >> s >> t;
  bool ok = false;
  rep(i, 100) {
    s = s.back() + s.substr(0, s.size() - 1);
    if (s == t) {
      ok = true;
      break;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3620
from collections import deque
n, m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]

graph = [[] for _ in range(n)]
out_deg = [0] * n
dp = [0]*n

for x, y in xy:
    graph[y-1].append(x-1)
    out_deg[x-1] += 1

stack = deque([i for i in range(n) if out_deg[i] == 0])

while stack:
    node = stack.popleft()
    for i in graph[node]:
        dp[i] = max(dp[i], dp[node]+1)
        out_deg[i] -= 1
        if out_deg[i] == 0:
            stack.append(i)

print(max(dp))

Measured memory_bytes: 77656
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    int r, g, b, ans;
    cin >> r >> g >> b;
    ans = r * 100 + g * 10 + b;
    if (ans % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main(){
    string s;
    cin>>s;
    int dp[(int)s.size()+1][13];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=1;i<=s.size();i++){
        for(int j=0;j<13;j++){
            if(s[i-1]=='?'){
                for(int k=0;k<=9;k++){
                    (dp[i][(10*j+k)%13]+=dp[i-1][j])%=MOD;
                }
            }
            else{
                (dp[i][(10*j+s[i-1]-'0')%13]+=dp[i-1][j])%=MOD;
            }
        }
    }
    cout<<dp[s.size()][5]<<endl;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
const int N=2e5+100;
ll a[N];
int32_t main(){
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    if (a[1]!=0){
        cout << -1 << endl;
        return 0;
    }
    ll ans=0;
    for (int i=2;i<=n;i++){
        if (a[i]-a[i-1]>1){
            cout << -1 << endl;
            return 0;
        }
        if (a[i]-a[i-1]==1){
            ans++;
        }
        else{
            ans+=a[i];
        }
    }
    cout << ans;
}


Measured memory_bytes: 1792
n, m, x, y =  gets.chomp.split.map(&:to_i)
x1 = gets.chomp.split.map(&:to_i)
y1 = gets.chomp.split.map(&:to_i)
_x = [x1.max, x].max
_y = [y1.min, y].min
puts _x < _y ? "No War" : "War"

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

static const llint MAX = 200005LL;
// static const int NIL = -1;
// static const ll INF = 1<<21;
static const llint MOD = 998244353LL ;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (llint 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;
    }
}

llint COM(llint n, llint k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

llint modpow(llint a, llint b) {
    if(b==0) return 1LL;
    if(b%2==0) {
        llint t = modpow(a, b/2);
        return t * t %MOD;
    }   
    return a*modpow(a, b-1)%MOD;
}

int main(void) {
    llint n, m, k;
    cin >> n >> m >> k;

    COMinit();

    llint ans = 0, anstmp;
    for(llint ik=0;ik<=k;ik++) {
        anstmp = COM(n-1, ik);
        anstmp *= m;
        anstmp %= MOD;
        anstmp *= modpow(m-1, n-1-ik);
        anstmp %= MOD;
        ans += anstmp;
        ans %= MOD;
    }

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


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

ll n;

int main() {
	cin>>n;
	ll a[n+1], kanan=0;
	for (int i=1; i<=n; i++) {
		cin>>a[i];
		if (i>2) kanan=(kanan^a[i]);
	}
	ll x=a[1]+a[2]-kanan, awal=a[1];
	if (x%2==1||x<0) {
		cout<<-1<<endl;
		return 0;
	}
	x/=2;
	if ((x&kanan)>0||x>awal) {
		cout<<-1<<endl;
		return 0;
	}
	a[1]=x, a[2]=x;
	for (int i=42; i>=0; i--) {
		ll p=(1LL<<i);
		if ((p&kanan)>0) {
			if (a[1]+p>awal) a[2]+=p;
			else a[1]+=p;
		}
	}
	ll ans;
	if (a[1]==0) ans=-1;
	else ans=awal-a[1];
	cout<<ans<<endl;
}



Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string a,b;
  cin >> a >> b;
  if(a<b) cout << '<' << endl;
  else if(a>b) cout << '>' << endl;
  else cout << '=' << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

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

int id[16];
int dis[16];
int w[16];
ll tw[1 << 16];
ll g[16][16];
ll memo[16][1 << 16];
int pv[16][1 << 16];

int main(){
	int n;
	cin >> n;
	rep(i, n){
		cin >> id[i] >> dis[i] >> w[i];
		w[i] *= 20;
	}
	
	fill(&memo[0][0], &memo[15][(1 << 16) - 1] + 1, 1LL << 50);
	memset(pv, -1, sizeof(pv));
	memset(tw, 0, sizeof(tw));

	rep(i, n)rep(j, n) g[i][j] = abs(dis[i] - dis[j]);
	rep(i, 1 << n){
		rep(j, n) if(i & (1 << j)) tw[i] += w[j];
	}

	rep(i, n) memo[i][1 << i] = tw[1 << i];

	rep2(s, 0, 1 << n){
		rep(i, n){
			if(s & (1 << i)){
				rep(j, n) {
					if(!(s & (1 << j))){
						ll cost = memo[i][s] + (70 + tw[s]) * g[i][j];
						if(cost < memo[j][s | (1 << j)]){
							memo[j][s | (1 << j)] = cost;
							pv[j][s | (1 << j)] = i;
						}
					}
				}
			}
		}
	}
	int p = 0;
	int s = (1 << n) - 1;
	ll best = 1LL << 50;
	rep(i, n) if(memo[i][(1 << n) - 1] < best){
		best = memo[i][(1 << n) - 1];
		p = i;
	}
	vector<int> res;
	res.push_back(id[p]);
	while(pv[p][s] != -1){
		int t = p;
		p = pv[p][s];
		s -= (1 << t);
		res.push_back(id[p]);
	}
	rep(i, (int)res.size()){
		if(i != 0) cout << " ";
		cout << res[(int)res.size() - i - 1];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
long long N,X;
int main(){
    cin>>N>>X;
    vector<long long>L(51,0);
    vector<long long>P(51,0);
    L[0]=1;P[0]=1;
    for(int i=0;i<N;i++){
        L[i+1]=L[i]*2+3;
        P[i+1]=P[i]*2+1;
    }
    long long ans=0;
    for(int i=N;i>=1;i--){
        //cout <<i<<" " <<ans<<" ";
        if(X==0)break;
        X--;
        if(X<=L[i-1])continue;
        ans+=P[i-1]+1;
        X-=L[i-1]+1;
    }
    if(X>0)ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define Rep(i,a,n) for(int i = a;i<n;i++)
#define ll long long  
const long long MOD = 1000000007LL;
int main(){
    ll n;
    ll a[5];
    cin >> n;
    rep(i,5){
        cin >> a[i];
    }
    sort(a,a+5);
    ll f = a[0];
    if(n%f == 0){
        cout << n/f + 4 << endl;
    }
    else{
        cout << n/f + 5 << endl;
    }
}


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

using namespace std;

int main(){
	int N;
	while (scanf("%d",&N)!=EOF){
		bool f=false;
		for (int i=1;i<=512;i<<=1){
			if (N&i){
				if (f) putchar(' ');
				printf("%d",i);
				f=true;
			}
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

ll solve(ll,bool);
ll h,w;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>h>>w;
    if(h%3==0 || w%3==0){
        cout << 0<<endl;
        return 0;
    }
    ll ans=min(h,w);
    ans=min(solve(h/3,true),ans);
    ans=min(solve(h/3+1,true),ans);
    ans=min(solve(w/3,false),ans);
    ans=min(solve(w/3+1,false),ans);
    cout << ans <<endl;

    return 0;
}

ll solve(ll n,bool maki){
    ll m,a,b,c;
    if(maki==true){
        m=w/2;
        a=n*w;
        b=(h-n)*m;
        c=(h-n)*(w-m);
        m=min(a,b);
        a=max(a,b);
        m=min(m,c);
        a=max(a,c);
        return a-m;
    }
    else{
        m=h/2;
        a=n*h;
        b=(w-n)*m;
        c=(w-n)*(h-m);
        m=min(a,b);
        a=max(a,b);
        m=min(m,c);
        a=max(a,c);
        return a-m;
    }
}



Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	LL H;
	cin >> N >> H;
	vector<LL> A(N),B(N);
	for(int i=0;i<N;++i){
		cin >> A[i] >> B[i];//A<=B
	}
	//////
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	LL sum = 0;
	int count = 0;
	
	LL MAX = A[N-1];

	for(int i=N-1;i>=0;--i){
		//最大の振りより大きかったら最後になげる
		if( B[i] < MAX ){
			break;
		}
		sum += B[i];
		++count;
		if( sum >= H ){
			cout << count << endl;
			return;
		}
	}
	
	//max(A)をふりまくる
	
	LL nokori = H-sum;
	cout << ((nokori+MAX-1)/MAX) + count << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;
int n, k;
int a[5000];
int b[5000];

bool ok(int x)
{
    vector<int> d;
    while (x > 0)
    {
        d.push_back(x % 10);
        x /= 10;
    }
    for (int i = 0; i < d.size(); i++)
    {
        if (b[d[i]])
            return 0;
    }
    return 1;
}

int main()
{
    cin >> n >> k;
    for (int i = 0; i < k; i++)
    {
        cin >> a[i];
        b[a[i]] = 1;
    }
    for (; n <= 1000000; n++)
    {
        if (ok(n))
        {
            cout << n;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,i;
    cin>>n;
    if(n%10){
        string s=to_string(n);
        for(i=n=0;i<s.size();i++)n+=s[i];
        cout<<n-'0'*s.size()<<endl;
    }
 	else cout<<10<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;
}

Measured memory_bytes: 256
n = int(input())
T = [int(t) for t in input().split()]
m = int(input()) # num of drinks
drinks = []
diffs = [0 for _ in range(n)] # diff buffs

for i in range(m):
    p, x = map(int, input().split())
    drinks.append([p,x])

for drink in drinks:
    diff = T[drink[0]-1] - drink[1] # 通常の時間 - 加速された時間
    print(sum(T)-diff)

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please



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


	int N, K;
	cin >> N >> K;


	if ((N + 1) / 2 >= K) {
		int A[100000], B[100000], C[100000];
		rep(i, N) A[i] = K + i;
		rep(i, N) B[i] = K + N + i;
		rep(i, N) C[i] = K + N + N + i;
		int b = N / 2;

		rep(i, (N + 1) / 2) {
			cosp(A[i]);
			cosp(B[(b + i) % N]);
			co(C[i * 2 % N]);
		}
		for (int i = (N + 1) / 2; i < N; i++) {
			cosp(A[i]);
			cosp(B[(b + i) % N]);
			co(C[(i * 2 + !(N & 1)) % N]);
		}

	}
	else {
		co(-1);
	}


	Would you please return 0;
}

Measured memory_bytes: 3456
fn main() {
    let input = read_vec::<u128>();

    let s = input[0];
    let w = input[1];
    
    println!("{}", if s > w {"safe"} else {"unsafe"});
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var k = Console.ReadLine().ToInt();
		var q = Input().ToInt();
		var a = q[0];
		var b = q[1];
		for(int i = 1; i < 999999; i++)
		{
			if(i * k > b)
			{
				Console.WriteLine("NG");
				
				return;
			}
			if(i * k >= a && i * k <= b)
			{
				Console.WriteLine("OK");
				return;
			}
			
		}
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

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

int main(){
    int n;
    double t,a;
    cin>>n>>t>>a;
    
    double mindif= 200000, diff;
    int h, mini;
    rep(i,n){
        cin>>h;
        diff = abs(a-(t-0.006*h));
        
        if(diff<mindif){
            mini = i+1;
            mindif = diff;
        }
    }
    
    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 256
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (a (read))
         (b (read))
         (c (read))
         (ls (make-array n :element-type 'uint15))
         (min-cost most-positive-fixnum))
    (declare ((integer 3 8) n)
             (uint15 a b c))
    (dotimes (i n) (setf (aref ls i) (read)))
    (dotimes (is (expt 4 n))
      (loop with set1 of-type uint32 = 0
            with set2 of-type uint32 = 0
            with set3 of-type uint32 = 0
            with set1-size of-type uint4 = 0
            with set2-size of-type uint4 = 0
            with set3-size of-type uint4 = 0
            for i from 0 below n
            for mask of-type uint32 = 3 then (ash mask 2)
            do (let ((value (ash (logand mask is) (* -2 i))))
                 (cond ((= value 1)
                        (incf set1-size)
                        (incf set1 (aref ls i)))
                       ((= value 2)
                        (incf set2-size)
                        (incf set2 (aref ls i)))
                       ((= value 3)
                        (incf set3-size)
                        (incf set3 (aref ls i)))))
            finally (unless (or (zerop set1-size)
                                (zerop set2-size)
                                (zerop set3-size))
                      (let* ((merge-cost (* 10 (+ (- set1-size 1)
                                                  (- set2-size 1)
                                                  (- set3-size 1))))
                             (cost (+ merge-cost
                                      (abs (- a set1))
                                      (abs (- b set2))
                                      (abs (- c set3)))))
                        (when (< cost min-cost)
                          (setf min-cost cost))))))
    (println min-cost)))

#-swank(main)


Measured memory_bytes: 11240
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

string YorN(bool P) { if (P)return "Yes"; else return "No"; }

int main() {

    vector<int>g = {-1,0,2,0,1,0,1,0,0,1,0,1,0 };
    int x,y;
    cin >> x >> y ;

    cout << YorN(g[x]==g[y]) << endl;

    return 0;

}

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

using namespace std;

typedef pair<int, int> ii;

int n, k, a[200002], sorted_len[200002];
bitset<200002> sorted_start;

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  int sort_start = 0; int sort_len = 0; int cval = -1;
  a[n] = -1;
  deque<ii> mind;
  deque<ii> maxd;
  for (int i = 0; i <= n; i++) {
    if (i < n) cin >> a[i];
    if (a[i] > cval) {
      sort_len++;
      cval = a[i];
    } else {
      sorted_start[sort_start] = 1;
      for (int k = sort_start; k < i; k++)
        sorted_len[k] = sort_len--;
      sort_len = 1;
      sort_start = i;
      cval = a[i];
    }
    if (i < k - 1) {
      while (mind.size() > 0 && a[i] <= mind.back().first) mind.pop_back();
      mind.push_back(ii(a[i], i));
      while (maxd.size() > 0 && a[i] >= maxd.back().first) maxd.pop_back();
      maxd.push_back(ii(a[i], i));
    }
  }
  int result = 0; bool cnted_all_sorted = false;
  for (int i = 0; i < n - k + 1; i++) {
    if (maxd.front().second < i) maxd.pop_front();
    if (mind.front().second < i) mind.pop_front();
    if (i == 0) {
      result++;
      if (sorted_len[i] >= k) cnted_all_sorted = true;
    } else {
      if (a[i + k - 1] < maxd.front().first) {
        if (sorted_len[i] < k || !cnted_all_sorted) {
          // cerr << "pos " << i << ", sorted_len is " << sorted_len[i] << endl;
          result++;
          if (sorted_len[i] >= k) cnted_all_sorted = true;
          // if (cnted_all_sorted) cerr << "cnted_all_sorted now" << endl;
        }
      } else if (a[i - 1] > mind.front().first) {
        if (sorted_len[i] < k || !cnted_all_sorted) {
          // cerr << "pos " << i << ", sorted_len is " << sorted_len[i] << endl;
          result++;
          if (sorted_len[i] >= k) cnted_all_sorted = true;
          // if (cnted_all_sorted) cerr << "cnted_all_sorted now" << endl;
        }
      }
    }
    while (mind.size() > 0 && a[i + k - 1] <= mind.back().first) mind.pop_back();
    mind.push_back(ii(a[i + k - 1], i + k - 1));
    while (maxd.size() > 0 && a[i + k - 1] >= maxd.back().first) maxd.pop_back();
    maxd.push_back(ii(a[i + k - 1], i + k - 1));
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3456
#include <string>
#include <iostream>
#include <vector>
#include <algorithm> 
#include <cmath>
using namespace std;
int main()
{
	unsigned long long int n,sum=0;
	cin>>n;
	for(unsigned long long int i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			sum=i+(n/i);		
		}
	}
	sum-=2;
	cout<<sum;
	
	return 0;
}
	

Measured memory_bytes: 384
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int, input().split())
ab = [ list(map(int, input().split())) for _ in range(m) ][::-1]
c = n*(n-1)//2
L = [c]
uf = UnionFind(n)
cur = 0
for a, b in ab[:-1]:
  if not uf.same(a-1, b-1):
    cur += uf.size(a-1)*uf.size(b-1)
    uf.union(a-1, b-1)
  L.append(c-cur)
print(*L[::-1], sep="\n")

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

int main() {
  int N; cin >> N;
  int s[N], total =0, a =100, ans; 
  rep(i,0,N) {
    cin >> s[i]; total += s[i];
    if (s[i] % 10 != 0) a = min(a,s[i]);
  }
  
  if (total % 10 == 0) {
    if (a % 10 == 0) ans = 0;
    else ans = total - a;
  } else {
    ans = total;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3656
<?php
fscanf(STDIN, "%d %d", $h, $w);
if ($h % 3 == 0 || $w % 3 == 0) {
	$x = 0;
} else {
	$x = min($h, $w);
	for ($i = 0; $i < 2; $i++) {
		$w1 = floor($w / 3);
		$w2 = $w1 + 1;
		$h1 = floor($h / 2);
		$h2 = ceil($h / 2);
		$s1 = ($w - $w1) * max($h1, $h2)  - $w1 * $h;
		$s2 = $w2 * $h - ($w - $w2) * min($h1, $h2);
		$x = min($x, $s1, $s2);
		if ($h == $w) break;
		list($h, $w) = [$w, $h];
	}
}
echo $x;

Measured memory_bytes: 4728
def main():
    n = int(input())
    words = {}
    for _ in range(n):
        a = input()
        if a in words:
            words[a] += 1
        else:
            words[a] = 1

    max_val = max(words.values())
    # words_sorted = sorted(words.items(), key=lambda x: x[0])
    for key, value in sorted(words.items()):
        if value != max_val:
            continue
        else:
            print(key)
            # key valueを両方printするとき
            # print('{}:{}'.format(key, value))


if __name__ == "__main__":
    main()


Measured memory_bytes: 44124