akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<ll> T(N, 0LL), A(N, 0LL);
	rep (i, N){
		cin >> T[i] >> A[i];
	} // end rep

	ll a = 1LL, b = 1LL; 
	rep (i, N){
		ll x = T[i], y = A[i];
		ll n = max(a/x, b/y);
		while(n * x < a || n * y < b){
			++n;
		} // end while
		a = n * x; b = n * y;
	} // end rep

	ll res = a + b;
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

import javax.xml.crypto.Data;

import java.math.*;
import java.awt.geom.*;
import java.io.*;
     
     
public class Main {
	static int W;
	static int H;
	static int N;
	static boolean[][] fld;
	static int[] vx = new int[] {0,1,0,-1};
	static int[] vy = new int[] {1,0,-1,0};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int a1 = sc.nextInt();
		int a2 = sc.nextInt();
		int b1 = sc.nextInt();
		int b2 = sc.nextInt();
		int[][] dp = new int[r][c];
		int[][] cost = new int[r][c];
		boolean[][] use = new boolean[r][c];
		dp[a1][a2] = 1;
		for(int i = 0; i < r; i++) {
			Arrays.fill(cost[i], 2 << 27);
		}
		ArrayDeque<Data> queue = new ArrayDeque<Data>();
		queue.add(new Data(a1,a2,0));
		while(!queue.isEmpty()) {
			Data tmp = queue.poll();
			if(use[tmp.a][tmp.b]) continue;
			use[tmp.a][tmp.b] = true;
			for(int i = 0; i < 4; i++) {
				int ty = tmp.a + vy[i];
				int tx = tmp.b + vx[i];
				if(tx == -1) {
					tx = c-1;
				}
				else if(tx == c) {
					tx = 0;
				}
				if(ty == -1) {
					ty = r-1;
				}
				else if(ty == r) {
					ty = 0;
				}
				if(cost[ty][tx] < tmp.c+1 || use[ty][tx]) continue;
				cost[ty][tx] = tmp.c+1;
				dp[ty][tx] += dp[tmp.a][tmp.b];
				dp[ty][tx] %= 100000007;
				queue.add(new Data(ty,tx,tmp.c+1));
			}
		}
		System.out.println(dp[b1][b2]);
	}
	static class Data{
		int a;
		int b;
		int c;
		Data(int c, int d, int e) {
			a = c;
			b = d;
			this.c = e;
		}
	}
}

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> P;

int main(){
	int n ; cin >>n;
	if(n<1000){
		cout<<"ABC"<<endl;
	  }
	  else{
		cout<<"ABD"<<endl;}
	  }



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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
	int  n;cin >> n;
	vector<int> a(n), b(n-1);
	for(int i = 0; i < n-1; ++i){cin >> b[i];}
	a[0] = a[1] = b[0]; 
    a[n-1]=b[n-2];
     for(int i = 1; i < n-1; ++i){
    	a[i]=min(b[i-1], b[i]);
    }
    int ans = 0;
    for(int i = 0; i < n; ++i){ans+=a[i];}
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
#define clr(n)	memset(n,0,sizeof(n));
const int INF = 1e9;

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

struct edge { int to, cap, rev; };
vector<edge> G[1001];
bool used[1001];

void clear() {
	rep(i, 1001) {
		G[i].clear();
		used[i] = false;
	}
}

void add_edge(int from, int to, int cap) {
	G[from].push_back(edge{ to, cap, int(G[to].size()) });
	G[to].push_back(edge{ from, 0, int(G[from].size()) - 1 });
}

int dfs(int v, int t, int f) {
	if (v == t)return f;
	used[v] = true;
	rep(i, G[v].size()) {
		edge &e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		clr(used);
		int f = dfs(s, t, INF);
		if (f == 0)return flow;
		flow += f;
	}
}

int main() {
	int m, n;

	while (cin >> m >> n && m) {
		vector<int> r(m), b(n);
		clear();
		rep(i, m) {
			cin >> r[i];
			add_edge(m + n, i, 1);
		}
		rep(i, n) {
			cin >> b[i];
			add_edge( m + i, m + n + 1, 1);
		}
		rep(i, m)rep(j, n) {
			if (gcd(r[i], b[j]) != 1) {
				add_edge(i, m + j, 1);
			}
		}

		cout << max_flow(m + n, m + n + 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 9752
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

//using namespace std;
using std::cin, std::cout, std::endl, std::string;
using ll = long long;

#define rep(countName, left, right, up) for (auto countName = left; countName < right; countName += up)
#define REP(countName, end) for (auto countName = 0; countName < end; countName++)
#define rev(countName, right, left, down) for (auto countName = right; countName >= left; countName -= down)
#define REV(countName, end) for (auto countName = end; countName >= 0; countName--)

auto solve1(int k, int a, int b)
{
    rep(i, a, b + 1, 1)
    {
        if (i % k == 0)
        {
            return "OK";
        }
    }
    return "NG";
}

int main(void)
{
    int k, a, b;
    cin >> k >> a >> b;
    cout << solve1(k, a, b) << endl;

    return 0;
}


Measured memory_bytes: 3624
MOD = int(1e9) + 7


def calc(N, T, A):
    highest = max(T)
    if highest != max(A):
        return 0
    l = T.index(highest)
    r = A.index(highest)
    if N - (l + r) <= 0:
        return 0
    elif N - (l + r) == 1:
        ans = 1
    else:
        free = N - (l + r) - 2
        ans = pow(highest, free, MOD)
    prev = 0
    for i in range(l):
        if T[i] == prev:
            ans = (ans * T[i]) % MOD
        prev = T[i]
    prev = 0
    for i in range(r):
        if A[i] == prev:
            ans = (ans * A[i]) % MOD
        prev = A[i]
    return ans


def main():
    N = int(input())
    T = list(map(int, input().split()))
    A = list(map(int, input().split()))[::-1]
    ans = calc(N, T, A)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 81764
#include <cstdio>
#include <map>
#define mod 1000000007
#define LL long long
using namespace std;
map< pair<LL,LL>,pair<int,int> > mp;
LL gcd(LL a,LL b){
	return b?gcd(b,a%b):a;
}
LL quick_pow(LL a,LL b){
	LL ret=1;
	while(b){
		if(b&1)ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret%mod;
}
int main(){
	int n,i;
	LL a,b,d,zero=0,sum=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%lld%lld",&a,&b);
		if(!a&&!b){zero++;continue;}
		d=gcd(a,b);
		a/=d,b/=d;
		if(b<0)a=-a,b=-b;
		if(a<=0)mp[make_pair(b,-a)].second++;
		else mp[make_pair(a,b)].first++;
	}
	for(map< pair<LL,LL>,pair<int,int> >::iterator it=mp.begin();it!=mp.end();it++)
		sum=(quick_pow((LL)2,(LL)it->second.first)-1+quick_pow((LL)2,(LL)it->second.second)-1+1)%mod*sum%mod;
	sum=(sum+zero-1)%mod;
	sum=(sum%mod+mod)%mod;
	printf("%lld\n",sum);
	return 0;
}

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

/*
このクイズ大会ではQ回の正解が出るので，1回も正解しなかった人の最終ポイントはK-Qポイントとなる
最初に，全員にこのポイントを設定し，正解した人に1ポイント足していけば最終ポイントを計算できる
最後に，その値が0より大きいかを確認して答えを出力する
*/

int main(){
  int n,k,q;
  cin >> n >> k >> q;

  // set everyone's each point to K-Q
  int *point = new int[n];
  const int normalFinalPoint = k-q;
  for(int i=0;i<n;i++){
    point[i]=normalFinalPoint;
  }

  // add points to the person who answered correctly
  int who;
  for(int i=0;i<q;i++){
    cin >> who;
    point[who-1]++;
  }

  // answer
  for(int i=0;i<n;i++){
    if(point[i]>0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  delete [] point;
  return 0;
}

Measured memory_bytes: 1024
l = [0 for i in range(31)]
pos = goal = 0
def solve(cur,sum):
    global pos, goal
    if cur == goal:
        print " ".join(map(str,l[:pos]))
        return
    for i in range(sum,0,-1):
        if cur + i <= goal:
            l[pos] = i
            pos += 1
            solve(cur+i,i)
            pos -= 1
while True:
    goal = int(raw_input())
    if goal==0: break
    solve(0,goal)

Measured memory_bytes: 6468
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long int ll;

int main() {
  ll d, n;
  cin >> d >> n;
  ll ans;

  if(n==100)
    ans = static_cast<ll>(pow(100, d))*(n+1);
  else
    ans  = static_cast<ll>(pow(100, d))*n;


  cout << ans  << endl;

  return 0;
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{
    gearup;
    ll n,C; cin >> n >> C;
    vvl d(C,vl(C));
    rep(i,C)rep(j,C)cin>>d[i][j];
    vvl c(n,vl(n));
    rep(i,n)rep(j,n)cin>>c[i][j];
    ll res = L_INF;

    vvl cost(3,vl(C)); //cost[i][j]: あまりの集合iをjに塗り替えるコスト
    rep(i,C){
        rep(j,n){
            rep(k,n){
                cost[(j+k+2)%3][i] += d[c[j][k] - 1][i];
            }
        }
    }
    rep(i,C){ //あまり0でぬる色
        rep(j,C){ //1
            rep(k,C){ //2
                if(i == j || j == k || k == i)continue;
                ll ans = 0;
                rep(ii,3){
                    if(ii==0)ans += cost[ii][i];
                    else if(ii == 1) ans += cost[ii][j];
                    else ans += cost[ii][k];
                }
                res = min(ans,res);
            }
        }
    }
    out(res);
}

Measured memory_bytes: 5296
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, cnt = 0;
    cin >> n;
    repf(i, n){
        lli p;
        cin >> p;
        if(p != i) cnt++;
    }
    (cnt == 2 || cnt == 0) ? YES() : NO();
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;
import std.numeric;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

class Fraction {
public:
	long n, d;
	this(long n, long d) {
		auto g = gcd(abs(n), d);
		this.n = n/g;
		this.d = d/g;
	}
	Fraction opUnary(string s) () if(s == "-") {
		return new Fraction(-n, d);
	}
	Fraction opBinary(string op) (Fraction r) {
		static if (op == "+"){
			return new Fraction(n*r.d + r.n*d, d*r.d);
		} else static if(op == "-") {
			return this + (-r); 
		} else static assert(0);
	}
}
unittest {
	auto f1 = Fraction(2,3);
	auto f2 = Fraction(12, 5);
	auto f3 = f1+f2;
	assert(f3.n == 46 && f3.d == 15);
}

void main(){
	while(true) {
		auto l = readln().chomp.dup.reverse;
		if(l == "#") return;

		auto f = (){
			if(l[0] == 'h') {
				l = l[5..$];
				return new Fraction(0, 1);
			} else {
				l = l[4..$];
				return new Fraction(90, 1);
			}
		}();
		auto n = 1;
		while(!l.empty) {
			if(l[0] == 'h') {
				f = f - new Fraction(90, 2L^^n);
				l = l[5..$];
			} else {
				f = f + new Fraction(90, 2L^^n);
				l = l[4..$];
			}
			++n;
		}
		if(f.d > 1) {
			writeln(f.n, "/", f.d);
		} else {
			writeln(f.n);
		}
	}
}

Measured memory_bytes: 2336
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[])throws Exception{
    // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    // n = Integer.parseInt(br.readLine());
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int A[] = new int[n];
    int B[] = new int[n];
    int max = 0;
    StringBuilder builder = new StringBuilder();
    // String s[] = br.readLine().split("\\s+");
    for(int i = 0; i<n; i++){
      // A[i] = Integer.parseInt(s[i]);
      A[i] = sc.nextInt();
      max=Math.max(max,A[i]);
    }
    sort(A,B,max);
    // for(int i = 0; i<n; i++){
    //   if(i>0)System.out.print(" ");
    //   System.out.print(B[i]);
    // }
    // System.out.println();
    builder.append(B[0]);
    for (int i = 1; i < n; i++) {
        builder.append(' ').append(B[i]);
    }
    System.out.println(builder);

  }
  static void sort(int A[] , int B[] , int max){
    int C[] = new int[max+1];
    for(int i = 0; i<A.length; i++){
      C[A[i]]++;
    }
    for(int i = 1; i<=max; i++){
      C[i] += C[i-1];
    }
    for(int i = A.length-1; i>-1; i--){
      B[C[A[i]]-1] =A[i];
      C[A[i]]--;
    }
  }
}


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

using namespace std;

const int NMax = 100003;

int n;
int a[NMax],b[NMax],c[NMax];

int main(){
    cin >> n;
    for(int i = 1; i < n; ++i){
        cin >> b[i];
    }
    a[1] = b[1];
    for(int i = 2; i < n; ++i){
        a[i] = min(b[i - 1], b[i]);
    }
    a[n] = b[n - 1];
    long long s = 0;
    for(int i = 1; i <= n; ++i){
        s += a[i];
    }
    cout << s << '\n';
    return 0;
}


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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

string K, X;

int main(){
  cin >> K >> X;
  cout << X << K <<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	s="2018"+s.substr(4,(ll)s.size()-4);
	cout<<s<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

inline int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int k;
  cin >> k;
  ll ans = 0;
  for (int a = 1; a <= k; ++a) {
    for (int b = 1; b <= k; ++b) {
      for (int c = 1; c <= k; ++c) {
        ans += gcd(a, gcd(b, c));
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 3644
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		if(a<b&&b<c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26348
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

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

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．
//cout << fixed << setprecision(15);

int main() {
    string s;
    vector<vector<int> > a(3, vector<int> (3));
    vector<vector<bool> > b(3, vector<bool> (3));
    //初期値0
    //vector<int> data(i, 0);
    rep(i, 0, 3) {
        rep(j, 0, 3) {
            b[i][j] = false;
        }
    }

    rep(i, 0, 3) {
        rep(j, 0, 3) {
            int c;
            cin >> c;
            a[i][j] = c;
        }
    }
    int N;
    cin >> N;
    rep(i, 0, N) {
        int k;
        cin >> k;
        rep(i, 0, 3) {
            rep(j, 0, 3) {
                if (a[i][j] == k) {
                    b[i][j] = true;
                }
            }
        }
    }

    if (b[0][0] && b[0][1] && b[0][2]) {
        cout << "Yes" << endl;
        return 0;
    }

    if (b[1][0] && b[1][1] && b[1][2]) {
        cout << "Yes" << endl;
        return 0;
    }

    if (b[2][0] && b[2][1] && b[2][2]) {
        cout << "Yes" << endl;
        return 0;
    }

    if (b[0][0] && b[1][0] && b[2][0]) {
        cout << "Yes" << endl;
        return 0;
    }

    if (b[0][1] && b[1][1] && b[2][1]) {
        cout << "Yes" << endl;
        return 0;
    }

    if (b[0][2] && b[1][2] && b[2][2]) {
        cout << "Yes" << endl;
        return 0;
    }

    if (b[0][0] && b[1][1] && b[2][2]) {
        cout << "Yes" << endl;
        return 0;
    }

    if (b[0][2] && b[1][1] && b[2][0]) {
        cout << "Yes" << endl;
        return 0;
    }

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

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

int main(){
    ll n; cin>>n;
    ll sum =0;

    if(ll(n) % 2 != 0){
        cout<<sum<<endl;
        return 0;
    }
    n /= 2;
    while(n > 0){
        sum += n/5;
        n /= 5;
    }

    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <unordered_map>
#include <utility>

int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int32_t N;
  std::cin >> N;
  using elem_cnt_map_type = std::unordered_map<int32_t, int32_t>; 
  elem_cnt_map_type elem_cnt_map;
  while (N--) {
    int32_t a_tmp = 0;
    std::cin >> a_tmp;
    elem_cnt_map[a_tmp]++;
  }

  int64_t res = 0;
  std::for_each (elem_cnt_map.begin(), elem_cnt_map.end(), [&res](elem_cnt_map_type::value_type p) {
    if (p.second < p.first) {
      res += p.second;
    } else {
      res += p.second - p.first;
    }
  });

  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int x;
	cin >> x;
	if( x == 3 || x == 5 || x == 7 ) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int main(void){
  int N;
  int odd_even[2] = {0};
  long int A[100010];
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(A[i] % 2 == 0){odd_even[1]++;}
    else{odd_even[0]++;}
  }
  if(odd_even[0] % 2 == 0){cout << "YES" << endl;}
  else{cout << "NO" << endl;}
  return 0;
}


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

class dice {
    public:
    int top;
    int bottom;
    int north;
    int east;
    int south;
    int west;
    
    dice(int tin, int sin, int ein, int win, int nin, int bin) {
        top = tin;
        bottom = bin;
        north = nin;
        east = ein;
        south = sin;
        west = win;
    }
    
    void N() {
        int np = north;
        int tp = top;
        int sp = south;
        int bp = bottom;
        north = tp;
        top = sp;
        south = bp;
        bottom = np;
    }
    
    void S() {
        int np = north;
        int tp = top;
        int sp = south;
        int bp = bottom;
        north = bp;
        top = np;
        south = tp;
        bottom = sp;
    }
    
    void E() {
        int ep = east;
        int bp = bottom;
        int wp = west;
        int tp = top;
        east = tp;
        bottom = ep;
        west = bp;
        top = wp;
    }
    
    void W() {
        int ep = east;
        int bp = bottom;
        int wp = west;
        int tp = top;
        east = bp;
        bottom = wp;
        west = tp;
        top = ep;
    }
    
    void clock() {
        int ep = east;
        int sp = south;
        int wp = west;
        int np = north;
        east = np;
        south = ep;
        west = sp;
        north = wp;
    }
    
};


int main() {
  dice dice2(0, 0, 0, 0, 0, 0);
  cin >> dice2.top >> dice2.south >> dice2.east;
  cin >> dice2.west >> dice2.north >> dice2.bottom;
  
  int q;
  cin >> q;
  for (int i=0; i<q; i++) {
      int t;
      int s;
      cin >> t >> s;
      int check = 0;
      int count = 0;
      while (check == 0 && count < 4) {
          if ( t == dice2.top ) {
              check = 1;
              break;
          } else {
              dice2.E();
          }
          count++;
      }
      while (check == 0) {
          if ( t == dice2.top) {
              check = 1;
              break;
          } else {
              dice2.N();
          }
      }
      while (check == 1) {
          if ( s == dice2.south) {
              check = 2;
              break;
          } else {
              dice2.clock();
          }
      }
      
       if(check == 2) {
         cout << dice2.east << endl;
       }
  }
  
  return 0;
}




Measured memory_bytes: 3088
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    int n ; 
    cin >> n ; 
    vector<int> v(n);
    int even = 0 ;
    for(int i = 0; i < n; i++){
        cin >> v[i] ;
        if ( v[i] % 2 == 0 ) even++ ;
    }
    puts(even == n ? "second" : "first") ;
    return 0 ;
}

Measured memory_bytes: 3660
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()

	matrix := make([]int, N+2)
	for i := 0; i < M; i++ {
		L, R := sc.NextInt(), sc.NextInt()
		matrix[L] += 1
		matrix[R+1] -= 1
	}

	cnt := 0
	A := 0
	for i := 0; i <= N; i++ {
		A += matrix[i]
		if A == M {
			cnt++
		}
	}
	fmt.Println(cnt)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 4224
//A.cpp
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main(){
  string S,T;
  cin >> S >> T;
  int Tln = T.size(), Sln = S.size();
  int Ans;
  bool flag;
  for(int i = Sln-Tln; i >= 0; i--){
    flag = true;
    for(int j = 0; j < Tln; j++){
      if(S[i+j]!=T[j]&&S[i+j]!='?'){
        flag = false;
        break;
      }
    }
    if(flag){
      Ans = i;
      break;
    }
  }

  if(flag){
    for(int i = 0; i < Sln; i++){
      if(i == Ans) cout << T, i += Tln - 1;
      else{
        if(S[i]=='?') printf("a");
        else printf("%c",S[i]);
      }
    }
  }else{
    cout << "UNRESTORABLE" << endl;
  }

  return 0;
}


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

int main(){

  int sum=0;

  int in,in2;
  int min=100;

  for(int i=0; i<4; i++){
    cin >> in;
    sum+=in;
    if(min>in)
      min=in;
  }

  sum -= min;

  cin>>in>>in2;

  if(in<in2)
    sum += in2;

  else
    sum += in;

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output3.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)
        cout<<k;
    else if(k>a && k<=(a+b))
        cout<<a;
    else
        cout<<a-(k-a-b);
    return 0;
}


Measured memory_bytes: 3652
import Data.List as L
import Data.IntMap as M

keyCounts :: [Int] -> (((IntMap Int),Int), ((IntMap Int),Int))
keyCounts = L.foldl' (\((a,ac), b) k -> (b, ((M.insertWith (+) k 1 a), ac+1))) ((M.empty, 0), ((M.empty), 0))

sortIntMap :: ((IntMap Int), Int) -> ([(Int, Int)], Int)
sortIntMap (a,ac) = (sortBy (\a b -> compare (snd a) (snd b)) $ foldlWithKey (\ks k x -> (k,ac-x):ks) [] a, ac)

costs :: ([(Int, Int)], Int) -> ([(Int, Int)], Int) -> Int
costs ([], a) ([], b) = a + b
costs ([], a) ((x,y):k, b) = a + y
costs ((x,y):k, a) ([], b) = b + y
costs ((t,u):k, a) ((v,w):l, b) = if t==v then 
    if costs ((t,u):k, a) (l, b) < costs (k, a) ((v,w):l, b) then costs ((t,u):k, a) (l, b) else costs (k, a) ((v,w):l, b) 
    else u + w

main=do
    n<-L.map read . words<$>getLine::IO[Int]
    (m)<-L.map read . words<$>getLine::IO[Int]
    print $ (\(a,b) -> costs a b)$ (\(a,b) -> (sortIntMap a, sortIntMap b)) $ keyCounts m

Measured memory_bytes: 50556
#include<stdio.h>
#include<math.h>
int main(){
  int h=0,i,N,t=0,j;
  scanf("%d",&N);
  int hairetu[N];
  for(i=0;i<N;i++){
    scanf("%d",&hairetu[i]);
  }  
  for(i=0;i<N;i++){
      h=0;
      for(j=2;j<=sqrt(hairetu[i]);j++){
      if(hairetu[i]%j==0)h++;
    }
    if(h==0)t++;
  }
  printf("%d\n",t);  
  return 0;
}

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

#define println(msg) cout << msg << endl

int main() {
  // 入力
  int N, D;
  cin >> N >> D;

  vector<vector<int>> vvi(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      int x;
      cin >> x;
      vvi.at(i).push_back(x);
    }
  }
  
  // 計算
  
  // 最大サイズまでの整数の二乗tableを作る
  set<int> table;
  {
    int max = D * (40 * 40);
    int c = 1;
    while (true) {
      if ((c * c) > max) break;
    
      table.insert(c * c);
      c++;
    }
  }
  
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      if (i >= j) continue;
      
      auto p1 = vvi.at(i);
      auto p2 = vvi.at(j);
      
      int sum = 0;
      for (int k = 0; k < D; k++) {
        sum += ((p1.at(k) - p2.at(k)) * (p1.at(k) - p2.at(k)));
      }
      
      if (table.find(sum) != table.end()) {
        count++;
      }
    }
  }
  
  // 出力
  println(count);
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x;
    cin>>x;
    if(x>= 400 && x<=599)
    {
        cout<<"8"<<endl;
    }
    else if(x>= 600 && x<=799)
    {
        cout<<"7"<<endl;
    }
    else if(x>= 800 && x<=999)
    {
        cout<<"6"<<endl;
    }
    else if(x>= 1000 && x<=1199)
    {
        cout<<"5"<<endl;
    }
    else if(x>= 1200 && x<=1399)
    {
        cout<<"4"<<endl;
    }
    else if(x>= 1400 && x<=1599)
    {
        cout<<"3"<<endl;
    }
    else if(x>= 1600 && x<=1799)
    {
        cout<<"2"<<endl;
    }
    else
    {
        cout<<"1"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,j,k;
  while(cin>>k,k){
    string s,e;
    cin >> s>>e;
    typedef pair<string,int> P;
    set<string> m;
    P p;
    queue<P> q;
    q.push(P(s,0));
    int ans=k;
    while(!q.empty()){
      p=q.front();q.pop();
      s=p.first;
      if(s==e){
	ans=min(ans,p.second);
	break;
      }
      i=0;
      while(s[i]==e[i]) i++;
      int x=e[i]-s[i];
      bool f=false;
      for(j=i;j<k;j++){
	s[j]='0'+((s[j]-'0'+x+10)%10);
	if(m.find(s)==m.end()){
	  m.insert(s);
	  q.push(P(s,p.second+1));
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2524
#include <iostream>
#include <stack>
#include <vector>
using namespace std;

int main(){
    //freopen("Areas.txt", "r", stdin);
    stack<int> s1;
    stack<pair<int, int>> s2;
    stack<int> res;
    char c;
    int cnt = 0;
    int floodcnt = 0;
    int area = 0;
    int leftIndex;
    int tempArea;
    int mergeArea;
    pair<int, int> tempPair;
    while(scanf("%c", &c) != EOF){
        cnt++;
        if(c == '\\'){
            s1.push(cnt);
        }
        if(c == '/'){
            if(!s1.empty()){
                leftIndex = s1.top();
                s1.pop();
                tempArea = cnt-leftIndex;
                area += tempArea;
                while(!s2.empty()){
                    tempPair = s2.top();
                    if(tempPair.first > leftIndex){
                        s2.pop();
                        mergeArea = tempPair.second;
                        tempArea += mergeArea;
                    }
                    else{
                        break;
                    }
                }
                s2.push(make_pair(leftIndex, tempArea));
            }
        }
    }
    printf("%d\n", area);
    if(s2.size() == 0){
        printf("%d\n", s2.size());
    }
    else{
        printf("%d ", s2.size());
        while(!s2.empty()){
            res.push(s2.top().second);
            s2.pop();
        }
        while(res.size() > 1){
            printf("%d ", res.top());
            res.pop();
        }
        if(res.size() == 1){
            printf("%d\n", res.top());
            res.pop();
        }
    }
    return 0;
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

string s;
int main(){
	cin >> s;
	int x = count(s.begin(), s.end(), 'g') - count(s.begin(), s.end(), 'p');
	x = abs(x);
	cout << x/2;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
    long long k,a,b;
    long long now = 1;
    cin >> k >> a >> b;
    if(b - a <= 1){
        cout << 1 + k << endl;
        return 0;
    }
    now = a;
    k = k - a + 1;
    if(k % 2 == 0){
        now = a + k / 2 *(b - a);
    }
    else{
        now = a + (k-1) / 2 * (b - a) + 1;
    }
    cout << now << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/local/gnu/bin/bash
read n
read k
read -a a
for x in ${a[@]}
do
    ((x>0)) && da=$x || da=-$x
    ((x>k)) && db=$((x-k)) || db=$((k-x))
    ((da<db)) && d=$((d+da)) || d=$((d+db))
done
echo $((d*2))

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep (i, n) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int mid = (a[n - 1] + 1) / 2;
    int ans = Inf;
    rep (i, n - 1) {
        int tmp = abs(a[i] - mid);
        if (tmp < abs(ans - mid)) ans = a[i];
    }    
    
    cout << a[n - 1] << " " << ans << endl;

    return 0;
}



Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<20)
typedef pair<ll, ll> pll;
vector<ll> even_p, odd_p;
vector<pll> even, odd;
ll even_n, odd_n;

/* RMQ begin */
//dat{ val , index }
int init(int n_,vector<pll>& dat) {
	int n = 1;
	while (n < n_) n *= 2;
	dat.resize(2 * n - 1);
	for (int i = 0; i < 2 * n - 1;i++) dat[i] = { INF,INF };
	return n;
}

// k = p_index
void update(int k, int a,int n,vector<pll>& dat) {
	int temp = k;
	k /= 2;
	k += n - 1;
	dat[k] = { a, temp};

	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}
// [a,b)の最小値
pll query(int a, int b, int k, int l, int r,vector<pll>& dat) {
	// [a,b)と[l,r)が交差しなければ,INT_MAX
	if (r <= a || b <= l) return{ INF,INF };
	// [a,b)が[l,r)を完全に含んでいれば,この節点の値
	if (a <= l && r <= b) return dat[k];
	else {
		pll vl = query(a, b, k * 2 + 1, l, (l + r) / 2, dat);
		pll vr = query(a, b, k * 2 + 2, (l + r) / 2, r, dat);
		return min(vl, vr);
	}
}
/* RMQ end */

struct Node {
	// [l,r)
	int l, r;
	// even(odd) index 
	int a, b;
	
	int Min_val, Min_index;
	Node(int l, int r) :l(l), r(r) {
		if (l % 2 == 0) {
			a = l / 2;
			b = (r + 1) / 2;
			auto x = query(a, b, 0, 0, even_n, even);
			Min_val = x.first; Min_index = x.second;
		}
		else {
			a = l/ 2;
			b = r/ 2;
			auto x = query(a, b, 0, 0, odd_n, odd);
			Min_val = x.first; Min_index = x.second;
		}
	}

	bool operator <(const Node&o) const {
		// 昇順
		return o.Min_val < Min_val;
	}
};

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N; cin >> N;
	for (int i = 0; i < N;i++) {
		int p; cin >> p;
		if (i % 2 == 0) even_p.push_back(p);
		else odd_p.push_back(p);
	}

	// even/odd initialize
	even_n = init(even_p.size(), even);
	odd_n = init(odd_p.size(), odd);

	for (int i = 0; i < N;i++) {
		if (i % 2 == 0) update(i, even_p[i / 2], even_n, even);
		else update(i, odd_p[i / 2], odd_n, odd);
	}

	// solve
	priority_queue<Node> pq;
	pq.push(Node(0, N));

	for (int i = 0; i < N / 2;i++) {
		auto x = pq.top(); pq.pop();
		auto y = Node(x.Min_index + 1, x.r);

		cout << x.Min_val << " " << y.Min_val << " ";

		if(x.l != x.Min_index)pq.push(Node(x.l, x.Min_index));
		if(x.Min_index+1 != y.Min_index)pq.push(Node(x.Min_index + 1, y.Min_index));
		if(y.Min_index+1 != y.r)pq.push(Node(y.Min_index + 1, y.r));
	}
	cout << endl;
}

Measured memory_bytes: 13032
/**
 * author: dhakad_123
**/

#include<bits/stdc++.h>
using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int x;
    cin >> x;
    
    int count = 0;
    
    if(x == 0){
        cout <<count <<"\n";
        exit(0);
    }
 
   while(x >= 5){
       if(x >= 500){
           count += 1000;
           x = x-500;
       }
       else if(x >= 5){
           count += 5;
           x = x-5;
       }
   }
   cout << count <<"\n";
    
    return 0;
}

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

int z(double x1, double y1, double x2, double y2) {
    return (0 < x1 * y2 - y1 * x2 ? 1 : -1);
}

int main() {
    double x[3], y[3], xp, yp;
    while (cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> xp >> yp) {
        int sum = 0;
        for (int i=0; i<3; ++i) {
            sum += z(x[(i+1)%3] - x[i], y[(i+1)%3] - y[i], xp - x[i], yp - y[i]);
        }
        cout << (abs(sum) == 3 ? "YES" : "NO") << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
  int a;
  string ans="AGC";
    cin >> a;
    if(a<1200)
      ans = "ABC";
    else if(a<2800)
      ans = "ARC";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll n;
  cin>>n;
  vector<ll> a(n*3);
  for(ll i=0;i<3*n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  ll ans=0;
  for(ll i=0;i<n*2;i+=2){
    ans+=a[i+1];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5636
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	int a, b, x;
	cin >> a >> b >> x;
	if(a <= x and a + b >= x){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


int main() {
  int N,X,T;
  cin >> N >> X >> T;
  int turn = (N + X - 1) / X;
  cout << turn*T << endl;

  
  return 0;
}



Measured memory_bytes: 3060
n = int(input())
t, a = map(int, input().split())
l = list(map(int, input().split()))
min_tmp = 9999999999999999
area = -1
for i in range(len(l)):
    tmp = t - l[i] * 0.006
    if min_tmp > abs(a - tmp):
        min_tmp = abs(a - tmp)
        area = i + 1
print(area)

Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll x,y;
    cin>>x>>y;
    int cou=1;
    while(1){
        x=x*2;
        if(x>y)break;
        cou++;
    }
    cout<<cou<<endl;
    return 0;
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    REP(i, n) {
        REP(j, d) {
            cin >> x[i][j];
        }
    }
    int t = 0;
    REP(i, n - 1) {
        FOR(j, i + 1, n) {
            int y = 0;
            REP(k, d) {
                y += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            int a = 1;
            while (a * a <= y) {
                if (a * a == y) {
                    t++;
                }
                a++;
            }
        }
    }
    cout << t << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int A,B,C,D;
  scanf("%d%d%d%d",&A,&B,&C,&D);
  
  while(1){
    C -= B;
    if(C<=0){
      printf("Yes\n");
      break;
    }
    A -= D;
    if(A<=0){
      printf("No\n");
      break;
    }
  }
  return 0;
}

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

int main() {
	int n,m,input,input2;
	cin>>n>>m;
	int count[n]={0};
	for (int i=0;i<m;i++){
		cin>>input>>input2;
		count[input-1]++;
		count[input2-1]++;
	}
	for (int i=0;i<n;i++){
		cout<<count[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#define MAXN 1000010
const int INF = ~(0U) >> 2;

int n, m, k, a[MAXN], b[MAXN];
char buf[MAXN];
std::set<int> A, B;

int main(int argc, char const *argv[]) {
	scanf("%d%d%d", &n, &m, &k);
	scanf("%s", buf + 1);
	std::reverse(buf + 1, buf + n + 1);
	for (int i = 1; i <= n; i++) a[i] = buf[i] == '1';
	scanf("%s", buf + 1);
	std::reverse(buf + 1, buf + m + 1);
	for (int i = 1; i <= m; i++) b[i] = buf[i] == '1';
	n = std::max(n, m);
	A.insert(INF);
	B.insert(INF);
	for (int i = n; i; i--) {
		if (a[i] || b[i]) {
			if (!a[i]) {
				B.insert(i);
			} else if (!b[i]) {
				A.insert(i);
			} else {
				int rest = k;
				int pos = i;
				while (rest >= 0) {
					// printf("GO pos = %d, rest = %d\n", pos, rest);

					int AA, BB;
					int nearst = std::min(AA = *A.lower_bound(pos), BB = *B.lower_bound(pos));

					if (rest - nearst + pos < 0) {
						A.insert(pos + rest);
						B.insert(pos + rest);
						break;
					}

					if (AA == nearst) {
						int cur = nearst;
						B.insert(nearst);
						while (A.find(cur) != A.end()) A.erase(cur++);
						if (B.find(cur) != B.end()) {
							rest -= nearst - pos;
							pos = cur;
							B.erase(cur);
							continue;
						}
						A.insert(cur);
						break;
					} else {
						int cur = nearst;
						A.insert(nearst);
						while (B.find(cur) != B.end()) B.erase(cur++);
						if (A.find(cur) != A.end()) {
							rest -= nearst - pos;
							pos = cur;
							A.erase(cur);
							continue;
						}
						B.insert(cur);
						break;
					}
				}
			}
		}
	}
	A.insert(0);
	B.insert(0);

	auto it = --A.end();
	for (int j = *--it; j; j--) {
		if (j == *it) {
			it--;
			printf("1");
		} else {
			printf("0");
		}
	}
	printf("\n");
	it = --B.end();
	for (int j = *--it; j; j--) {
		if (j == *it) {
			it--;
			printf("1");
		} else {
			printf("0");
		}
	}
	printf("\n");

	return 0;
}


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

int main()
{
  int n,k;
  cin>>n>>k;
  int ans=0;
  for (int i = 0; i < n; ++i)
  {
    int x;
    cin>>x;
    ans+=2*min(abs(k-x),x);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632