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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n),b(n);
	rep(i,n) scanf("%d%d",&a[i],&b[i]);

	// experiment
	/*
	rep(S,1<<n){
		bool b[30][2]={};
		rep(i,n){
			if((S>>i&1)==0) b[i][0]=true;
			else            b[(i+1)%n][1]=true;
		}
		rep(i,n){
			rep(j,2) putchar(b[i][j]?'A'+j:' ');
			putchar(i<n-1?' ':'\n');
		}
	}
	*/

	vector<int> p(2*n);
	iota(p.begin(),p.end(),0);
	sort(p.begin(),p.end(),[&](int i,int j){
		return (i<n?a[i]:b[i-n])<(j<n?a[j]:b[j-n]);
	});

	vector<lint> val(2*n);
	rep(i,2*n) val[i]=(p[i]<n?a[p[i]]:b[p[i]-n]);
	lint sum=accumulate(val.begin(),val.begin()+n,0LL);

	vector<int> apos(n),bpos(n);
	rep(i,2*n){
		if(p[i]<n) apos[p[i]]=i;
		else       bpos[p[i]-n]=i;
	}
	rep(i,n) if(apos[i]<n && bpos[i]<n) return printf("%lld\n",sum),0;

	lint ans=min(accumulate(a.begin(),a.end(),0LL),
				 accumulate(b.begin(),b.end(),0LL));
	rep(i,n){
		if(apos[i]>=n && bpos[i]>=n){
			ans=min(ans,sum-val[n-2]-val[n-1]+val[apos[i]]+val[bpos[i]]);
		}
		else if(apos[i]>=n){
			ans=min(ans,sum-(bpos[i]<n-1?val[n-1]:val[n-2])+val[apos[i]]);
		}
		else{ // bpos[i]>=n
			ans=min(ans,sum-(apos[i]<n-1?val[n-1]:val[n-2])+val[bpos[i]]);
		}
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 7200
const MOD: i64 = 1_000_000_007;

fn main() {
    let (n, k): (usize, usize) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let pow = |mut a: i64, mut n: usize| -> i64 {
        let mut res = 1;
        while n > 0 {
            if n & 1 > 0 {
                res = res * a % MOD;
            }
            a = a * a % MOD;
            n >>= 1;
        }
        res
    };

    let mut count: Vec<i64> = vec![0; k + 1];
    for i in (1..=k).rev() {
        count[i] = pow((k / i) as i64, n);
        let mut j = i + i;
        while j <= k {
            count[i] = (count[i] + MOD - count[j]) % MOD;
            j += i;
        }
    }

    let ans = (1..=k).fold(0, |acc, i| (acc + i as i64 * count[i]) % MOD);
    println!("{}", ans);
}

Measured memory_bytes: 2820
/*input
24
*/
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include <tgmath.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
#define MAXN   100001  
 

std::vector<int> ans;

void factorize(long long n){
   
   int count = 0;
   while (!(n % 2)) {
      n/= 2;
      count++;
   }
   if (count)
      ans.push_back(count);
   for (long long i = 3; i <= sqrt(n); i += 2) {
      count = 0;
      while (n % i == 0) {
         count++;
         n = n / i;
      }
      if (count)
      	ans.push_back(count);
   }
   if (n > 2)
   	ans.push_back(1);
}






int main() {
 	int64 n;
 	cin>>n;
 	factorize(n);
 	int64 count = 0;
 	int p = (int)ans.size();

 	for(int i = 0;i<p;i++){
 		int g = ans[i];
 		g = g*2;
 		int a = 1;
 		while(a*(a+1)<=g){
 			a++;
 		}
 		a--;
 		count+=a;
 	}
 	cout<<count<<endl;
}



 


Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int par[100010];//親
int rnk[100010];//ランク

void init(int n){//初期化
  for(int i=0;i<n;i++){
     par[i]=i;
     rnk[i]=0;
  }
}

int find(int x){//親を求める
  if(par[x]==x) return x;
  return par[x]=find(par[x]);
}

void unite(int x,int y){//union
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(rnk[x]<rnk[y]){//rankが小さい方にくっつける
    par[x]=y;
  }
  else{
   par[y]=x;
    if(rnk[x]==rnk[y])rnk[x]++;//rankが同じ時は1増やす
  }
}

bool same(int x,int y){
 return find(x)==find(y); 
}

int main(){cout<<fixed<<setprecision(10);
		   int n,m;
           cin>>n>>m;
           map<int,int> mp;//iの場所を持つ
           init(n+1);
           vin p(n);rep(i,0,n){cin>>p[i];mp[p[i]]=i+1;}
           
           rep(i,0,m){
            int x,y;
             cin>>x>>y;
             unite(x,y);
           }
           int ans=0;
           rep(i,0,n){
            if(same(mp[p[i]],p[i]))ans++;
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 9064
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,x,y;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	x=0;
	y=0;
	if(a<=b && a<=c){
		x=a;
	}
	else if(b<=a && b<=c){
		x=b;
	}
	else{
		x=c;
	}
	if(d<=e){
		y=d;
	}
	else{
		y=e;
	}
	printf("%d\n",x+y-50);
	return 0;
}


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

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

	static class TaskD {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			final int MOD = (int) (1e9 + 7);
			int n = in.nextInt();
			char[][] s = new char[2][];
			s[0] = in.next().toCharArray();
			s[1] = in.next().toCharArray();
			int[][] d = new int[4][4];
			d[3][3] = 1;
			for (int i = 0; i < n; ) {
				boolean horizontal = false;
				if (s[0][i] != s[1][i]) {
					horizontal = true;
				}

				int[][] nd = new int[4][4];
				for (int c1 = 0; c1 < 4; c1++) {
					for (int c2 = 0; c2 < 4; c2++) {
						if (d[c1][c2] == 0) {
							continue;
						}
						for (int nc1 = 0; nc1 < 3; nc1++) {
							for (int nc2 = 0; nc2 < 3; nc2++) {
								if (horizontal && nc1 == nc2) {
									continue;
								}
								if (!horizontal && nc1 != nc2) {
									continue;
								}
								if (nc1 == c1) {
									continue;
								}
								if (nc2 == c2) {
									continue;
								}
								nd[nc1][nc2] += d[c1][c2];
								if (nd[nc1][nc2] >= MOD) {
									nd[nc1][nc2] -= MOD;
								}
							}
						}
					}
				}
				d = nd;

				if (horizontal) {
					i += 2;
				} else {
					i += 1;
				}
			}
			int ans = 0;
			for (int c1 = 0; c1 < 3; c1++) {
				for (int c2 = 0; c2 < 3; c2++) {
					ans = (ans + d[c1][c2]) % MOD;
				}
			}
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

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

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

	}
}



Measured memory_bytes: 22868
//package atcoder.beginnner_176;

import java.io.*;
import java.util.HashSet;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

    static Stack<Integer> Ih = new Stack<>();
    static Stack<Integer> Iw = new Stack<>();

    public static void main (String[] args) throws Exception {

        String s = "4 4\n" +
                "1 1\n" +
                "4 4\n" +
                "..#.\n" +
                "..#.\n" +
                ".#..\n" +
                ".#..";

//        br = new BufferedReader(new StringReader(s));
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));

        rl(); int H = nin(), W=nin();
        rl(); int ch = nin()-1, cw=nin()-1;
        rl(); int dh = nin()-1, dw=nin()-1;

        char S[][] = new char[H][]; int G[][] = new int[H][];
        for (int h=0; h<H; ++h) {
            rl();S[h]=nca(); G[h]=new int[W];
        }


        if (ch==dh && cw==dw) {
            bw.write(0 + "\n");
        } else if (S[dh][dw]=='#') {
            bw.write(-1 + "\n");
        } else {
            int c=1;
            Ih.push(ch); Iw.push(cw);
            while (G[dh][dw]==0 && !Ih.isEmpty()) {
                fill(S,G,H,W,c);
                ++c;
            }
            bw.write((G[dh][dw]==0?-1:(G[dh][dw]-1))+"\n");
        }

        bw.flush();
    }

    static int m[][] = new int[][]{new int[]{1,0}, new int[]{-1,0}, new int[]{0,1}, new int[]{0,-1}};

    static void fill(char S[][], int G[][], int H, int W, int c) {
        Set<Integer> B = new HashSet<>();
        while (!Ih.isEmpty()) {
            int _h = Ih.pop(); int _w=Iw.pop();
            if (G[_h][_w]!=0 || S[_h][_w]=='#') continue;
            G[_h][_w]=c;
            for (int[] _m:m) {
                int h2=_h+_m[0]; int w2=_w+_m[1];
                if (h2>H-1 || h2<0 || w2>W-1 || w2<0) continue;
                Ih.push(h2); Iw.push(w2);
            }
            for (int h3=_h-2; h3<=_h+2; ++h3) {
                for (int w3=_w-2; w3<=_w+2; ++w3) {
                    if (h3<0 || h3>H-1 || w3<0 || w3>W-1 || S[h3][w3]=='#' || G[h3][w3]!=0) continue;
                    B.add(h3*10_000+w3);
                }
            }
        }

        for (int b:B) {
            int _h=b/10_000, _w=b%10_000;
            Ih.push(_h); Iw.push(_w);
        }
    }

    static BufferedReader br; static BufferedWriter bw; static StringTokenizer st;
    static void rl() throws Exception{ st = new StringTokenizer(br.readLine()); }
    static long nlo(){ return Long.parseLong(st.nextToken()); }
    static int nin(){ return Integer.parseInt(st.nextToken()); }
    /*private static void te(){}*/
    static double ndo(){ return Double.parseDouble(st.nextToken()); }
    static char[] nca(){ return st.nextToken().toCharArray(); }
}


Measured memory_bytes: 67204
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    string s;
    cin>>k>>s;
    if(s.length()<=k)
    {
        cout<<s<<"\n";
    }
    else{
        string t= s.substr(0,k);
        cout<<t<<"...\n";
    }
	return 0;
}

Measured memory_bytes: 3568
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int n; cin>>n;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin>>h[i];

    vector<ll> dp(n+1, INF);
    dp[1] = 0;
    for(int i=1; i<n; i++){
        chmin(dp[i+1], dp[i] + abs(h[i] - h[i-1]));
        if(i - 2 >= 0) chmin(dp[i+1], dp[i-1] + abs(h[i] - h[i-2]));
    }

    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] z = new int[n];
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextInt() - 1;
			y[i] = sc.nextInt() - 1;
			z[i] = sc.nextInt() - 1;
		}
		int[][] imos = new int[40][100010];
		for(int i = 0; i < n; i++) {
			imos[z[i]][x[i]]++;
			imos[z[i]][y[i] + 1]--;
		}
		for(int i = 0; i < c; i++) {
			for(int j = 0; j < 100009; j++) {
				imos[i][j + 1] += imos[i][j];
				if(imos[i][j] >= 2) imos[i][j] = 1;
			}
		}
		int ans = 0;
		for(int i = 0; i < 100010; i++) {
			int cnt = 0;
			for(int j = 0; j < c; j++) {
				cnt += imos[j][i];
			}
			ans = Math.max(ans, cnt);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 102044
#include<stdio.h>

int main(){
  int stp[10];
  int car;
  int i;

  for(i=0;i<10;i++){
    stp[i]=0;
  }

  i=0;
  while(scanf("%d",&car)!=EOF){
    if(car==0){
      printf("%d\n",stp[i-1]);
      stp[i-1]=0;
      i--;
    }
    else{
      stp[i]=car;
      i++;
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1001002003004005006ll;
const int MX = 200005;
long long dp[MX];
int main()
{
	int n,w;
	cin >> n >> w;
	for(int i = 0; i < MX; ++i) dp[i] = LINF;
	dp[0] = 0;
	for(int i = 0; i < n; ++i)  
	{
		int a,b;
		cin >> a >> b;
		for (int j=MX-b-1; j>=0; --j) 
			dp[j+b] = min(dp[j+b], dp[j]+a);
	}
	int ans = 0;
	for(int i = 0; i < MX; ++i)
		if (dp[i] <= w) ans = i;
	cout<<ans<<endl;
	return 0;
}

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

int main() {

  int n;
  cin >> n;
  string str;
  int l_white=0;
  int r_red = 0;

  cin >> str;
  int w_num=0;
  int r_num = 0;
  for(int i=0 ; i<n ; i++){
    if(str[i]=='R') r_num++;
    else w_num++;
  }

  for(int i=0; i<n; i++){
    if( i<r_num && str[i]=='W') l_white++;
    else if(i >=r_num && str[i]=='R') r_red++;
  }

  if((w_num==0) || (r_num==0)) cout << "0" << endl;
  else {
    int max_num = min(l_white, r_red);
    cout << max_num << endl;
  }
  return 0;
  
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    string n;
    cin >> n;
    rep(i,n.size()){
        if(n[i]=='1') n[i]='9';
        else if(n[i]=='9') n[i]='1';
    }
    cout << n << endl;
    return 0;
}


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

constexpr int64_t INF = 1e18;
constexpr int D = 365;
constexpr int N = 26;
int c[N];
int s[D][N];
int last[N];
int t[D];

constexpr int64_t CYCLES_PER_SEC = 2800000000;
constexpr double TIMELIMIT = 1.95;
struct Timer {
	int64_t start;
	Timer() { reset(); }
	void reset() { start = getCycle(); }
	void plus(double a) { start -= (a * CYCLES_PER_SEC); }
	inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
	inline int64_t getCycle() {
		uint32_t low, high;
		__asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
		return ((int64_t)low) | ((int64_t)high << 32);
	}
};
mt19937 mt{random_device{}()};
uniform_int_distribution<int> rnd_contest(0, N - 1);
uniform_int_distribution<int> rnd_day(0, D - 1);

void input() {
	int _d; cin >> _d;
	for(int i = 0; i < N; ++i) {
		cin >> c[i];
		last[i] = -1;
	}
	for(int i = 0; i < D; ++i) {
		for(int j = 0; j < N; ++j) {
			cin >> s[i][j];
		}
	}
}

void greedy() {
	for(int i = 0; i < D; ++i) {
		int64_t loss = 0;
		for(int j = 0; j < N; ++j) {
			loss += c[j] * (i - last[j]);
		}
		int64_t maxi = -INF;
		int midx = 0;
		for(int j = 0; j < N; ++j) {
			int64_t los = loss - c[j] * (i - last[j]);
			if(s[i][j] - los > maxi) {
				maxi = s[i][j] - los;
				midx = j;
			}
		}
		last[midx] = i;
		t[i] = midx;
	}
}

int64_t calc() {
	for(int i = 0; i < N; ++i) {
		last[i] = -1;
	}
	int64_t ans = 0;
	for(int i = 0; i < D; ++i) {
		last[t[i]] = i;
		ans += s[i][t[i]];
		for(int j = 0; j < N; ++j) {
			int64_t loss = c[j] * (i - last[j]);
			ans -= loss;
		}
	}
	return ans;
}

void output() {
	for(int i = 0; i < D; ++i) {
		cout << t[i] + 1 << '\n';
	}
}

int main() {
	Timer timer;
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	input();
	greedy();
	int64_t score = calc();
	while(timer.get() < TIMELIMIT) {
		int q = rnd_contest(mt);
		int d = rnd_day(mt);
		int pre = t[d];
		t[d] = q;
		int64_t nxt = calc();
		if(nxt > score) {
			score = nxt;
		} else {
			t[d] = pre;
		}
	}
	output();
	// for(int i = 0; i < D; ++i) {
	// 	cin >> t[i];
	// }
	// cout << calc() << '\n';
	// int m; cin >> m;
	// while(m--) {
	// 	int d, q; cin >> d >> q;
	// 	--d, --q;
	// 	t[d] = q;
	// 	cout << calc() << '\n';
	// }
	return 0;
}


Measured memory_bytes: 3708
#include <cstdio>

int main() {
	int n, a, b, r = 0;
	scanf("%d", &n);
	while (n--) {
		scanf("%d%d", &a, &b);
		while (1) {
			if (a < b) break;
			if (a % b == 0) {
				r ^= a / b;
				break;
			}
			int t = a / b + 1;
			int z = a / b * b;
			a -= (a - z + t - 1) / t * t;
		}
	}
	puts(r ? "Takahashi" : "Aoki");
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main() {
  string s;
  cin>>s;
  int tot =0;
 
  int N =s.size();
  vector<int> vec(N);
  for(int i =0;i<N;i++){
    vec[i]=s.at(i)-'0';
    tot+=vec[i];
  }
 
  if(tot%9!=0)
    { cout<<"No"<<endl;}
  else
    {cout<<"Yes"<<endl;}
}  


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

alphabet = [chr(i) for i in range(97, 97+26)]
s = ''

while n > 0:
  tmp = n % 26
  s += alphabet[tmp - 1]
  if tmp == 0:
    n = (n - 1) // 26
  else:
    n = n // 26
print(s[::-1])

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

int main(){
	int N, K; cin>>N>>K;
	vector<int> A(N); rep(i, N) cin>>A[i];
	int ng = 0, ok = 1e9; // (ng,ok] = (l,r]
	while(ok - ng > 1){
		auto f = [&](int m){
			int c = 0;
			rep(i, N) c += (A[i] - 1) / m;
			return c <= K;
		};
		if(int m=(ok+ng)/2; f(m)) ok = m; else ng = m;
	}
	cout<< ok <<endl;
}


Measured memory_bytes: 3948
#解説参照
#ap+bp=aq+bq作って微調整

n = int(input())
p = list(map(int, input().split( )))
for i in range(n):
    p[i]-=1
#n = 20
a = [5*10**8+i*20001 for i in range(n)]
b = [5*10**8-i*20001 for i in range(n)]
#import numpy as np
#p = np.random.permutation(n)
#print(*a)
for i in range(n):##2万差までひっくり返る
    a[p[i]] += i ##p[i],iに注意
   
print(*a)
print(*b)
"""
for i in range(n-1):
    assert a[i]<a[i+1],(a[i],a[i+1])
    assert b[i]>b[i+1],(b[i],b[i+1])
    assert a[p[i]]+b[p[i]]<a[p[i+1]]+b[p[i+1]],(i,p[i],a[p[i]],b[p[i]],a[p[i+1]],b[p[i+1]])
"""
    



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int a,b;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='Z'){a=i;}
    }
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
            b=i;
            break;
        }
    }
    cout << a-b+1 << endl;


    return 0;
}

Measured memory_bytes: 720
# abc167_a.py
# https://atcoder.jp/contests/abc167/tasks/abc167_a

# A - Registration /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 高橋君はとあるWebサービスに会員登録しようとしています。
# まずIDを Sとして登録しようとしました。しかし、このIDは既に他のユーザーによって使用されていました。
# そこで、高橋君は Sの末尾に 1文字追加した文字列をIDとして登録することを考えました。
# 高橋君は新しくIDを Tとして登録しようとしています。これが前述の条件を満たすか判定してください。

# 制約
#     S, Tは英小文字列
#     1≤|S|≤10
#     |T|=|S|+1

# 入力
# 入力は以下の形式で標準入力から与えられる。
# S
# T

# 出力
# Tが問の条件を満たすならば Yes と、そうでないならば No と出力せよ。

# 入力例 1
# chokudai
# chokudaiz

# 出力例 1
# Yes

# chokudaiz は chokudai の末尾に z を追加して得られる文字列です。

# 入力例 2
# snuke
# snekee

# 出力例 2
# No

# snekee は snuke の末尾に英小文字を 1文字追加して得られる文字列ではありません。

# 入力例 3
# a
# aa

# 出力例 3
# Yes


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    S = lines[0]
    T = lines[1]
    # N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = 'Yes'
    if S != T[:-1]:
        result = 'No'

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['chokudai', 'chokudaiz']
        lines_export = ['Yes']
    if pattern == 2:
        lines_input = ['snuke', 'snekee']
        lines_export = ['No']
    if pattern == 3:
        lines_input = ['a', 'aa']
        lines_export = ['Yes']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 8956
fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(& mut input).unwrap();
    let v: Vec<u32> = input.trim().split_whitespace()
            .map(|x| x.parse().unwrap()).collect();
//    println!("{}{}{}", v[0], v[1], v[2]);
    let rgb = v[0] * 100 + v[1] * 10 + v[2];
//    println!("{}", rgb);
    let ans = if rgb % 4 == 0 { "YES" } else { "NO" };
    println!("{}", ans);
}

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

int main(int argc, char **argv)
{
	string str; ll k; cin >> str >> k; --k;
	char res;

	if (k == 0)
	{
		res = str[0];
	}
	else
	{
		if (str[0] == '1')
		{
			ll i{1};
			while (str[i] == '1') {++i;}
			res = str[min(k, i)];
		}
		else
			res = str[0];
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
A = [ input() for _ in range(h) ]
H, W = [], []
for i in range(h):
    if A[i].count('.')==w:
        H.append(i)
for j in range(w):
    if [ A[i][j] for i in range(h) ].count('.')==h:
        W.append(j)
for i in range(h):
    if i in H:
        continue
    for j in range(w):
        if j in W:
            continue
        print(A[i][j], end='')
    print()

Measured memory_bytes: 4468
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>

constexpr auto mod = 1000000007ll;

template <class T>
void add(std::vector<T>& v, int a, T w) {
    for (int x = a; x <= v.size(); x += x & -x) v[x] = (v[x] + w) % mod;
}

template <class T>
T sum(std::vector<T>& v, int a) {
    T ret = 0;
    for (int x = a; x > 0; x -= x & -x) ret = (ret + v[x]) % mod;
    return ret;
}

int main() {
    long long n, m;
    std::cin >> n >> m;
    std::vector<long long> p(n), e(m), x(n), y(n), l(n), r(n);
    for (auto i = 0; i < n; i++) std::cin >> p[i];
    for (auto i = 0; i < m; i++) std::cin >> e[i];
    for (auto i = 0, j = 0; i < n; i++) {
        if (p[i] < e[0] || p[i] > e[m - 1]) continue;
        while (p[i] > e[j + 1] && j < m) j++;
        if (j >= m) break;
        l[i] = p[i] - e[j];
        r[i] = e[j + 1] - p[i];
        x[i] = l[i];
        y[i] = r[i];
        // std::cout << "(" << l[i] << "," << r[i] << ")" << "\n";
    }
    std::cout << std::flush;

    std::sort(x.begin(), x.end());
    std::sort(y.begin(), y.end());
    x.erase(std::unique(x.begin(), x.end()), x.end());
    y.erase(std::unique(y.begin(), y.end()), y.end());

    std::vector<std::deque<long long>> v(n);
    for (auto i = 0; i < n; i++) {
        if (l[i] && r[i]) {
            l[i] = std::lower_bound(x.begin(), x.end(), l[i]) - x.begin();
            r[i] = std::lower_bound(y.begin(), y.end(), r[i]) - y.begin();
            v[l[i]].push_back(r[i]);
        }
    }

    std::vector<long long> bit(n + 10);
    add(bit, 1, 1ll);
    for (auto i = 0; i < n; i++) {
        std::sort(v[i].begin(), v[i].end());
        v[i].erase(std::unique(v[i].begin(), v[i].end()), v[i].end());
        std::reverse(v[i].begin(), v[i].end());
        for (auto j : v[i]) {
            auto s = sum(bit, j + 1);
            add(bit, j + 2, s);
        }
    }

    std::cout << sum(bit, n + 5) % mod << std::endl;

    return 0;
}


Measured memory_bytes: 73728
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace IPT1_7B
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans;
            Boolean ansNoDuplicate;
            // loop true
            while ( true )
            {
                ans = 0;
                // input n x
                String[] in_num = Console.ReadLine().Split(' ');
                int n = int.Parse(in_num[0]);
                int x = int.Parse(in_num[1]);
                // check n = x = 0 then break
                if ((n == 0) && (x == 0)) break;
                // create array n * n 
                //int[,] array_ans = new int[n, n];
                int[,] array_ans = new int[n * n * n, 3];
                int[] array_abc = new int[3];
                // loop a 0 -> n - 1
                for (int a = 1; a <= n; a++)
                {
                    // loop b a + 1 -> n - 1
                    for (int b = a + 1; b <= n; b++)
                    {
                        // calc c = x - (a + b)
                        int c = x - (a + b);
                        // check c <= n
                        // check a != b and a !=c and b != c 
                        if ((0 < c) && (c <= n) && (a != b) && (a != c) && (b != c))
                        {
                            ansNoDuplicate = true;
                            array_abc[0] = a;
                            array_abc[1] = b;
                            array_abc[2] = c;
                            Array.Sort(array_abc);
                            for (int i = 0; i < ans; i++ )
                            {
                                if ((array_ans[i, 0] == array_abc[0]) &&
                                    (array_ans[i, 1] == array_abc[1]) &&
                                    (array_ans[i, 2] == array_abc[2]))
                                    ansNoDuplicate = false;
                            }
                            if (ansNoDuplicate == true)
                            {
                                //Console.WriteLine(array_abc[0] + "+" + array_abc[1] + "+" + array_abc[2]);
                                array_ans[ans, 0] = array_abc[0];
                                array_ans[ans, 1] = array_abc[1];
                                array_ans[ans, 2] = array_abc[2];
                                //Console.WriteLine(a + "+" + b + "+" + c);
                                // count up yes ans
                                ans++;
                            }
                        }
                    }
                }
                // print ans count
                Console.WriteLine(ans);
            }
        }
    }
}

Measured memory_bytes: 46496
/*
  GOOD is not Enough
  You've got to be GREAT.
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n' 
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

void solve()
{
    int n;
    cin >> n;
  int a[n];
  int ans=1;
  f(i,n)
  {
      cin >> a[i];
      if(a[i]==0)
        ans=0;
      // dbg(ans);
      int prev=ans;
      if(ans!=-1)
        ans*=a[i];
      if(ans>(int)1000000000000000000 || (a[i]!=0 && ans<prev))
      {
          ans=-1;
      }
  } 
    cout << ans << '\n';
  return;
} 

signed main()
{
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

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

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

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

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    vector<vector<pair<int, int>>> v(n+1);
    REP(i, n+1) {
      int m; cin >> m;
      int px, py; cin >> px >> py;
      int diff = 0;
      REP(j, m-1) {
        int nx, ny; cin >> nx >> ny;
        int dir = 0;
        int x = nx - px, y = ny - py;
        // cout << x << ":" << y << endl;
        px = nx;
        py = ny;
        if(x > 0) {
          dir = 0;
        } else if(y > 0) {
          dir = 1;
        } else if(x < 0) {
          dir = 2;
        } else {
          dir = 3;
        }
        if(i != 0 && j == 0) {
          diff = (dir - v[0][0].fi + 4) % 4;
        }
        v[i].push_back(make_pair((dir - diff + 4) % 4 , abs(x + y)));
      }
    }

/*     REP(i, n+1) {
      // cout << i << endl;
      REP(j, SZ(v[i])) {
        cout << v[i][j].fi << ":" << v[i][j].se << " ";
      }
      cout << endl;
    } */

    FOR(i, 1, n+1) {
      if(v[0] == v[i]) cout << i << endl;
      else {
        REP(j, SZ(v[0])) {
          v[i][j].fi += ((v[0][0].fi - v[i][SZ(v[0]) - 1].fi) + 4) % 4;
          v[i][j].fi %= 4;
        }
        reverse(ALL(v[i]));
        if(v[0] == v[i]) cout << i << endl;
        // cout << i << endl;
/*         REP(j, SZ(v[i])) {
          cout << v[i][j].fi << ":" << v[i][j].se << " ";
        }
        cout << endl; */
      }
    }

    cout << "+++++" << endl;
  }
}



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

int main(){
  int X;
  cin>>X;

  int sa=X-9;
  if(sa>=0){
    switch(sa%7){
      case 0:cout<<"sat";break;
      case 1:cout<<"sun";break;
      case 2:cout<<"mon";break;
      case 3:cout<<"tue";break;
      case 4:cout<<"wed";break;
      case 5:cout<<"thu";break;
      case 6:cout<<"fri";break;
    }
  }
  else{
    sa*=-1;
    switch(sa%7){
      case 0:cout<<"sat";break;
      case 1:cout<<"fri";break;
      case 2:cout<<"thu";break;
      case 3:cout<<"wed";break;
      case 4:cout<<"tue";break;
      case 5:cout<<"mon";break;
      case 6:cout<<"sun";break;
    }
  }
  cout<<endl;
}


Measured memory_bytes: 3116
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 


const ll sz = 1000009;
ll prime[sz + 1], gain[sz + 1];


int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	ll t, i, x, j, y, 	z, k, n;
	cin >> n;
	ll a[n];
	scan(a, n);
	// memset(prime, 0, sizeof(prime));
	// memset(gain, 0, sizeof(gain));

	// for (ll i = 1; i <= sz; i++) {
	// 	prime[i] = i;
	// }


	for (ll p = 2; p <= sz; p++) {
		if (prime[p] == 0) {
			for (ll i = p * p; i <= sz; i += p) {
				// if (!prime[i])
				prime[i] = p;
			}
		}
	}
	for (int p = 2; p <= sz; p++)
		if (prime[p] == 0)	prime[p] = p;
	// 		cout << p << " ";

	for (int i = 0; i < n; i++) {
		x = a[i];
		// while (x > 1) {
		// if (prime[x] == 0) {
		// 	gain[x]++;
		// 	break;
		// }
		// 	x /= prime[x];
		// 	gain[prime[x]]++;
		// }

		set<ll> st;
		while (x > 1) {
			// cerr << prime[x] << " ";
			st.insert(prime[x]);
			// while (x % prime[x] == 0)
			x /= prime[x];
		}

		// debug(st);

		for (auto zx : st)	gain[zx]++;

		// cerr << x << "\n";
	}


	for (i = 0; i <= sz; i++) {
		if (gain[i] > 1)	break;
	}

	if (i == sz + 1)	return cout << "pairwise coprime", 0;

	for (i = 0; i <= sz; i++) {
		if (gain[i] >= n)	break;
	}

	if (i == sz + 1)	return cout << "setwise coprime", 0;
	cout << "not coprime";

}

/*

	return cout<<"setwise coprime";
*/



Measured memory_bytes: 26900
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    vector<ll> cnt(100001);
    int N;cin>>N;
    ll ans = 0;
    REP(i,N){
        int a;cin>>a;
        cnt[a]++;
        ans += a;
    }
    int Q;
    cin>>Q;
    REP(_,Q){
        int b,c;
        cin>>b>>c;
        ans -= b*cnt[b];
        ans += c*cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout<<ans<<"\n";
    }
}


Measured memory_bytes: 3824
/*
Character Drawing Adapted from FAKEUPDATE.NET
		   _    _____         _
		   \`,""   ,'7"r-..__/ \
		  ,'\ `, ,',','    _/   \
		 /   \, 7 / /     (   \ |
		J     \/ j  L______\  / |
		L   __JF"""/""\"\_,    /
		L,-"| O|  f O |  L_  _/
		F   \_ /  \__/   `-  j|
			.-'    `"""    ,' |          _..====.._
			\__/         r"_  A        ,' _..---.._`,
			 `-.______,,-L// / \  ___,' ,'_..:::.. `,`,
					  j   / / / 7"    `-<""=:'  '':. \ \
					 /   <,' /  F  . i , \   `,    :T W I
					 |    \,'  /    >X<  |     \   :| | L
					 |     `._/    ' ! ` |      I  :| |  G
					  \           \     /       |  :H T  |
					 __>-.__   __,-\   |        |  S P   |
					/     /|   | \  \  \_       | 'A R   |
				   /   __/ |   |  L  L   \      K./ /    L
				  /   |    |   4  I  I    |    E./ /   ,'
				 J    \    I    L F  I    |    // / _,'
		_________|     |   F    |J   F    |   //_/-'
		\   __   |    /   J     |/  J     |  /="
		\\  \_\  \__,' \  F     |   F     |
		\\\_____________\/      F__/      F
		 \\| 计算机编程 |_____/  (______/
		  \/从入门到入土/
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
#include <functional>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	long long n, a, b;
	cin >> n >> a >> b;
	if (n>1 && b >= a || n == 1 && a == b)
		cout << (n - 2)*(b - a) + 1 << endl;
	else
		cout << 0 << endl;
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int k[m],a[m][20],p[m];
  for(int i=0;i<m;i++){
      cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin>>a[i][j];
    }
  }
  
  for(int i=0;i<m;i++) cin>>p[i];
  int ans=0;
  for(int bit=0;bit<(1<<n);bit++){
     int light=0;
     for(int i=0;i<m;i++){
       int cnt=0;
       for(int j=0;j<k[i];j++){
       if(bit&(1<<a[i][j]-1)) cnt++;
     }
       if(p[i]==0&&(cnt%2==0)) light++;
       if(p[i]==1&&(cnt%2!=0)) light++;
     }
       if(light==m) ans++;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
	int N;
	int num;
	cin >> N;
	
	if      (N<10    ) num = N;
	else if (N<100   ) num = 9;
	else if (N<1000  ) num = N - 90;
	else if (N<10000 ) num = 909;
	else if (N<100000) num = N - 9090;
	else if (N==100000) num = 90909;
	cout << num << endl;
	return 0;
}


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

int main()
{
  int k, A, B;
  bool bResult = false;
  cin >> k >> A >> B;
  
  for(int i = A; i <= B; i++)
  {
    if ( i % k == 0 )
    {
      bResult = true;
      break;
    }
  }
  if ( bResult == true )
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}

Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        Scanner cin = new Scanner();
        int N = cin.Int();
        int M = cin.Int();

        var a = new int[N + 1];
        var b = new int[N + 1];
        var c = new int[M + 1];
        var d = new int[M + 1];
        for(int i = 1; i <= N; i++)
        {
            a[i] = cin.Int();
            b[i] = cin.Int();
        }
        for(int i = 1; i <= M; i++)
        {
            c[i] = cin.Int();
            d[i] = cin.Int();
        }

        for(int i = 1; i <= N; i++)
        {
            int min_index = M;
            int min = int.MaxValue;
            for (int j = M; j >= 1; j--)
            {
                int tmp = Math.Abs(a[i] - c[j]) + Math.Abs(b[i] - d[j]);
                if(tmp <= min)
                {
                    min = tmp;
                    min_index = j;
                }
            }
            Console.WriteLine(min_index);
        }
        Console.ReadLine();
    }

}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


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

int main() {
  int N,M;
  cin>>N>>M;
  int ans=N*(N-1)+M*(M-1);
  ans/=2;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;
//bool comp(
//
//	st pll &a, const pll &b) {
//	return a.first < b.first;
//}
//std::vector<int> enum_div(int n)//nの約数を列挙
//{
//	std::vector<int> ret;
//	for (int i = 1; i*i <= n; ++i)
//	{
//		if (n%i == 0)
//		{
//			ret.push_back(i);
//			if (i != 1 && i*i != n)
//			{
//				ret.push_back(n / i);
//			}
//		}
//	}
//	return ret;
//}

template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}

int main()
{
	priority_queue<int> q;
	ll h = 0, w = 0, k = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, ans = 0;
	string s = {};
	ll x[100005] = {};
	ll y[302][302] = {};
	cin >> a;
	ans = 1;
	for (ll i = 0; i < a; i++)
	{

		cin >> w;
		h = 0;
		if (d==w)
		{
			h++;
			d++;
			if (b==w)
			{
				h++;
				//if (c==h)
				//{
				//	h++;
				//}
			}
			if (c==w)
			{
				h++;
			}
		}
		else if (b==w)
		{
			h++;
			b++;
			if (c==w)
			{
				h++;
			}
		}
		else if (c==w)
		{
			h++;
			c++;
		}
		if (h>0)
		{
			ans *= h;
			ans %= 1000000007;
		}
		if (h==0)
		{
			cout << 0 << endl;
			return 0;
		}


	}


	cout << ans << endl;


	//cout<<factorial<10><<endl;

	//cin >> a >> b;
	//for (int i = 0; i < a; i++)
	//{
	//	cin >> s[i];
	//	if (s[i] >= b)
	//	{
	//		ans++;
	//	}
	//}

	//cout << ans << endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>

using i64 = std::int64_t;

int main() {
	i64 n;
	std::cin >> n;

	i64 a, b;
	for (i64 i = 1; i * i <= n; ++i)
		if (n % i == 0)
			a = i, b = n / i;

	std::cout << a - 1 + b - 1 << std::endl;
}

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

using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i, x) for(int i=0;i<(int)(x);i++)
#define REPS(i, x) for(int i=1;i<=(int)(x);i++)
#define RREP(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i, x) for(int i=((int)(x));i>0;i--)
#define FOR(i, c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i, c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

const int INF = 1 << 28;
const double EPS = 1e-8;
const int MOD = 1000000007;
int grundy(int a, int k) {
    if (a < k) return 0;
    if (a % k == 0) return a / k;
    int d = a/k + 1;
    int nxt = a - (a % k / d) * d;
    return grundy(min(a - d, nxt), k);
}

int n, m;
int main(int argc, char *argv[]) {
    ios::sync_with_stdio(false);
    cin >> n;
    int ans = 0;
    REP(i, n) {
        int a, k;
        cin >> a >> k;
        int ret = grundy(a, k);
        ans ^= ret;
    }
    puts(ans ? "Takahashi" : "Aoki");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
int main()
{
	int n;
	while (~scanf("%d", &n), n) {
		int total[3] = { 0 }, oks[3] = { 0 };
		const char* str[] = { "lunch", "dinner", "midnight" };
		for (int i=0; i<n; ++i) {
			int hh, mm, MM, m, M;
			scanf("%d:%d %d", &hh, &mm, &MM);
			if (2<=hh && hh<11 || 15<=hh && hh<18) continue;
			if (hh < 2) hh += 24;
			m = 60*hh + mm;
			M = 60*hh + MM;
			if (m > M) M += 60;
			int k = 0;
			k += (m >= 18*60) + (m >= 21*60);
			total[k]++;
			if (M - m <= 8) oks[k]++;
		}
		for (int i=0; i<3; ++i) {
			printf("%s ", str[i]);
			if (total[i] == 0) puts("no guest");
			else printf("%d\n", oks[i]*100/total[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		double d1 = sc.nextInt();
		double x = sc.nextInt();
		
		double ans = 0;
		
		for(; N>0; N--) {
			ans += d1 + (N-0.5)*x;
			d1 = ((2*N+2)*d1 + 5*x)/(2*N);
			x = ((double)N+2)/N*x;
		}
		
		System.out.println(ans);
		sc.close();
	}
}


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

int main(){

  int a,b,k;

  cin>>a>>b>>k;

  int cnt=0;
  
  
  for(int i=max(a,b);i>=1;i--){

    
    if(a%i==0&&b%i==0){

      cnt++;
      if(cnt==k){
	cout<<i<<endl;
	return 0;
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 256