akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace MyProgram
{
    public class Program
    {	
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long[] Luca = new long[N+1];
            
            Luca[0] = 2;
            Luca[1] = 1;
            
            for(int i = 2; i <= N ; i++)
            {
                Luca[i] = Luca[i-1] + Luca[i-2];
            }
            Console.WriteLine(Luca[N]);
        }
    }
}

Measured memory_bytes: 13140
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long amount, deadline;
		List<Job> jobList = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			amount = Long.parseLong(sc.next());
			deadline = Long.parseLong(sc.next());
			jobList.add(new Job("Job" + (i + 1), amount, deadline));
		}

		Collections.sort(jobList, Comparator.comparing(Job::getDeadline));
		String ans = solve(jobList) ? "Yes" : "No";
		System.out.println(ans);
	}

	static boolean solve(List<Job> jobList) {
		long current = 0;
		for (int i = 0; i < jobList.size(); i++) {
			current += jobList.get(i).amount;
			if (current > jobList.get(i).deadline) {
				return false;
			}
		}
		return true;
	}

}

class Job {
	String jobName;
	long amount;
	long deadline;

	Job(String jobName, long amount, long deadline) {
		this.jobName = jobName;
		this.amount = amount;
		this.deadline = deadline;
	}

	public String getJobName() {
		return jobName;
	}

	public long getAmount() {
		return amount;
	}

	public long getDeadline() {
		return deadline;
	}

	public String toString() {
		return jobName + " , " + amount + " , " + deadline;
	}
}

Measured memory_bytes: 148500
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X,Y;
  cin>>N>>X>>Y;
  X=X-1;
  Y=Y-1;
  int k=0;
  vector<int> V(N-1);
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      k=min(j-i,abs(X-i)+1+abs(Y-j));
      V.at(k-1)++;
    }
  }
  for(int i=0;i<N-1;i++){
    cout<<V.at(i)<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int k,a,b;
  cin >>k >> a >> b;
  for(int i =a; i<=b; i++){
    if(i%k==0){
      cout <<"OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}


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

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

    long long a, b;
    cin >> a >> b;
    long long g = __gcd(a, b);
    map<int, int> mp;
    for (int i = 2; (long long) i * i <= g; i++) {
        while (g % i == 0) {
            mp[i]++;
            g /= i;
        }
    }
    if (g > 1) mp[g]++;
    cout << mp.size() + 1 << endl;
}


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

string s;
cin >> s;
if (s[2]==s[3] && s[4]==s[5]) cout << "Yes" << endl;
else cout << "No" << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<cstdio>

using namespace std;

#define rep(i, n) for(long int i = 0; i < n; i++)
#define P pair<long int, long int>

int main(){
    int a, b;
    cin >> a >> b;
    if (a < b){
        rep(i, b){
            cout << a;
        }
        cout << endl;
    }else{
        rep(i, a){
            cout << b;
        }
        cout << endl;
    }
    
}


Measured memory_bytes: 256
n,m,x=map(int,input().split())

s=[0]*(n+1)
l=list(map(int,input().split()))
       
for i in range(m):
    s[l[i]]=1
       
       
if sum(s[0:x])>sum(s[x+1:]):
       print(sum(s[x+1:]))
else:
       print(sum(s[0:x]))
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int min = vec.at(0);
  int max = vec.at(vec.size()-1);
  vector<int> result(0);
  for(int i=min; i<max+1; i++){
    int g = 0;
    for(int j=0; j<N; j++){
      g += std::pow((i-vec.at(j)), 2);
    }
    result.push_back(g);
  }
  sort(result.begin(), result.end());
  cout << result.at(0) << endl;
}

Measured memory_bytes: 256
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    Q, *BC = map(int, read().split())

    total = sum(A)
    d = [0] * (10 ** 5 + 1)
    for a in A:
        d[a] += 1

    for b, c in zip(BC[::2], BC[1::2]):
        total += (c - b) * d[b]
        d[c] += d[b]
        d[b] = 0
        print(total)

    return


if __name__ == '__main__':
    main()


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

using namespace std;

const int N = 1e5 + 7 , mod = 1e9 + 7 ;

long long n ; 
long long x[N] ; 
long long a[N] ;

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
//        freopen("in.in" , "r" , stdin) ; 
        cin>>n ; 
        long long a[n+1] ; 
        long long ans = 0 , mx = 1 ;      
        long long rem = 0 ;   
        for(int i = 0 ;i <=n;i++){
                long long t ; 
                cin>>a[i] ; 
                rem+=a[i] ; 
        }
        x[n] = a[n] ; 
        for(int i = n ; i ; i--)
                x[i-1] = a[i-1] +  x[i] ; 
        for(int i = 0 ; i <=n;i++){
                long long t = a[i] ; 
                if(t > mx){
                        return cout<<-1,0 ; 
                }
                long long all = min(mx  , rem); 
                mx-=a[i] ; 
                ans+=all ;
                mx*=2 ;   
                if(mx > 1e15)
                        mx = 1e15 ; 
                rem-=a[i] ; 
        }
        cout<< ans ; 
        return 0;
}


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

int main () {
  int N, c = 1;
  bool b = false;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int p = vec.at(0);
  if (p == 2) {
    cout << 1;
  }
  else {
    for (int i = 0; i < N - 1; i++) {
        p = vec.at(p - 1);
        c++;
        if (p == 2) {
          cout << c;
          b = true;
          break;
        }
      }
    if (!b){
      cout << -1;
    }
  }
}

Measured memory_bytes: 640
unittest
{
	assert( [ "3", "4", "2" ].parse.expand.solve == 7 );
	assert( [ "4", "4", "4" ].parse.expand.solve == 16 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto a = input.front.to!( long );
	input.popFront;
	auto b = input.front.to!( long );
	input.popFront;
	auto h = input.front.to!( long );
	return tuple( a, b, h );
}

auto solve( long a, long b, long h )
{
	return ( a + b ) * h / 2;
}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    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 <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int s, w;
	cin >> s >> w;
	
	if( w >= s ) cout << "unsafe" << endl;
	else cout << "safe" << endl;
	
	return 0;
}


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

int main() {
    int K, S; cin >> K >> S;
    int ans = 0;
    for (int i = 0; i <= K; i++) {
        for (int j = 0; j <= K; j++) {
            if (0 <= S - i - j && S - i - j <= K) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7,mod=1e9+7;
int n,a,b,c,ans,fac[N],inv[N],pa[N],pb[N],s[N];
int qpow(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)ret=1ll*ret*a%mod;
		a=1ll*a*a%mod,b>>=1;
	}
	return ret;
}
int C(int a,int b){return 1ll*fac[a]%mod*inv[a-b]%mod*inv[b]%mod;}
int main()
{
	cin>>n>>a>>b>>c;
	a=1ll*a*qpow(100-c,mod-2)%mod;
	b=1ll*b*qpow(100-c,mod-2)%mod;
	c=1ll*c*qpow(100,mod-2)%mod;
	fac[0]=1;for(int i=1;i<=2*n;i++)fac[i]=1ll*fac[i-1]*i%mod;
	inv[2*n]=qpow(fac[2*n],mod-2);
	for(int i=2*n;i;i--)inv[i-1]=1ll*inv[i]*i%mod;
	pa[0]=pb[0]=1;for(int i=1;i<=2*n;i++)pa[i]=1ll*pa[i-1]*a%mod,pb[i]=1ll*pb[i-1]*b%mod;
	for(int i=1;i<=2*n;i++)s[i]=1ll*i*qpow(mod+1-c,mod-2)%mod;
	for(int i=0;i<n;i++)ans=(ans+(1ll*pa[i]*pb[n]+1ll*pa[n]*pb[i])%mod*s[i+n]%mod*C(i+n-1,i))%mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 4096
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int k = sc.nextInt();
		int x = sc.nextInt();

		// 計算
		int from = x - k + 1;
		int to = x + k - 1;
		
		// 出力
		for(int i = from; i <= to; i++){
		    System.out.print(i + " ");
		}
	}
}


Measured memory_bytes: 21844
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    ll sum = 0;
    rp(i,n){
      ll x;
      cin >>x;
      sum -=x;
      cin >> x;
      sum +=x;
      sum +=1;
    }
    cout << sum <<endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
 
#define pi pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define mx 1000000
#define mn 0
#define hello 123

signed main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    int sum[n];
    sum[n-1]=arr[n-1];
    for(int i=n-2;i>=0;i--)sum[i]=(arr[i]+sum[i+1])%mod;
    int ans=0;
    for(int i=0;i<n-1;i++)
    {
        ans=ans+(arr[i]*sum[i+1])%mod;
        ans%=mod;
    }
    cout<<ans;
}

Measured memory_bytes: 6744
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

constexpr ll mod = 1e9 + 7;

long long inv(long long n) {
    long long res = 1;
    while (n > 1) {
        res *= (mod - mod/n);
        res %= mod;
        n = mod % n;
    }
    return res;
}

void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> in(n);
    for (int i=0; i<n; i++) {
        cin >> in.at(i);
    }
    vector<pair<ll, int>> a(n);
    for (int i=0; i<n; i++) {
        a.at(i).first = in.at(i);
        a.at(i).second = i;
    }
    sort(a.begin(), a.end());
    vector<pair<int, int>> maxmin(n);
    for (int i=0; i<n; i++) {
        maxmin.at(a.at(i).second).first = i+1;
        maxmin.at(a.at(i).second).second = n-i;
    }
    vector<ll> comb(n+1);
    ll nume = 1, deno = 1;
    for (ll i=1; i<=k-1; i++) {
        deno *= i;
        deno %= mod;
    }
    for (ll i=0; i<n+1; i++) {
        if (i < k-1) {
            comb.at(i) = 0;
            continue;
        } else if (i == k-1) {
            nume = deno;
            deno = inv(deno);
        } else {
            ll tmp = i - (k - 1);
            tmp = inv(tmp);
            nume *= i;
            nume %= mod;
            nume *= tmp;
            nume %= mod;
            if (nume < 0) nume += mod;
        }
        comb.at(i) = (nume * deno) % mod;
    }
    ll ans = 0;
    for (int i=0; i<n; i++) {
        ans += in.at(i) * comb.at(n - maxmin.at(i).second) % mod;
        ans %= mod;
        ans -= in.at(i) * comb.at(n - maxmin.at(i).first) % mod;
        ans %= mod;
    }
    if (ans < 0) ans += mod;
    cout << ans << "\n";
}

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

    solve();

    return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
    int L, R;
    cin >> L >> R;

    int ans = INT_MAX;
    for (int i = L; i < L + 2030; i++) {
        if (i >= R) break;
        for (int j = i + 1; j < i + 2030; j++) {
            if (j > R) break;
            int cm = (i % 2019) * (j % 2019) % 2019; 
            ans = min(ans, cm);
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  ll ans = 0;
  for (int k = 60; k >= 0; --k) {
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] & (1ll << k)) {
        cnt++;
      }
    }
    ll res = (1ll << k) % MOD * cnt % MOD * (n - cnt) % MOD;
    ans = (ans + res) % MOD;
  }
  cout << ans << endl;
  return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n;
    cin >> n;

    vector l(n, 0L);
    for (auto&& ll : l) {
        cin >> ll;
    }

    int64_t ans = 0;
    for (auto i : irange(0L, n)) {
        for (auto j : irange(i + 1, n)) {
            for (auto k : irange(j + 1, n)) {
                auto mx = max({l[i], l[j], l[k]});
                auto mi = min({l[i], l[j], l[k]});
                auto me = l[i] + l[j] + l[k] - mx - mi;

                if (mx == me || me == mi) {
                    continue;
                }

                if (mx < me + mi) {
                    ++ans;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>

using namespace std;
using LL = long long;

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;

        unordered_map<LL, int> B;
        vector<LL> T;

        int m;
        LL a, b;
        for (int i = 0; i < n; i++) {
            cin >> m >> a >> b;
            if (B.find(a) == B.end()) {
                B[a] = 0;
                T.push_back(a);
            }
            B[a] += m;
            if (B.find(b) == B.end()) {
                B[b] = 0;
                T.push_back(b);
            }
            B[b] -= m;
        }

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

        bool ans = B[T[0]] <= 150;

        for (int i = 1; i < T.size(); i++) {
            B[T[i]] += B[T[i - 1]];
            ans &= B[T[i]] <= 150;
            if (!ans) break;
        }

        cout << (ans ? "OK" : "NG") << endl;
    }
}


Measured memory_bytes: 3088
#include <cstdio>

int N,W;
int INF=1000000007;
int dpA[40008];
int dpB[608][108];
int ws[108];
int vs[108];
int main() {
	scanf("%d%d",&N,&W);
	for(int i=0;i<N;i++) scanf("%d%d",&ws[i],&vs[i]);
	int sol=0;
	if(ws[0]<397) {
		//init
		for(int j=0;j<40008;j++) dpA[j]=-INF;
		dpA[0]=0;
		if(W>40007) W=40007;
		for(int i=0;i<N;i++) {
			for(int j=W-ws[i];j>=0;j--) if(dpA[j]>=0) if(dpA[j+ws[i]]<dpA[j]+vs[i]) dpA[j+ws[i]]=dpA[j]+vs[i];
		}
		for(int j=0;j<=W;j++) if(dpA[j]>sol) sol=dpA[j];
	} else {
		int allowed=W/ws[0];
		if(allowed>N) {
			allowed=N;
		}
		int rem=W-allowed*ws[0];
		if(rem>607) rem=607;
		for(int loop=0;loop<2;loop++) {
			if(allowed<=0) break;
			for(int i=0;i<108;i++) {
				for(int j=0;j<608;j++) dpB[j][i]=-INF;
			}
			dpB[0][0]=0;
			for(int i=0;i<N;i++) {
				for(int k=allowed-1;k>=0;k--) {
					for(int j=0;j<=rem-ws[i]+ws[0];j++) {
						if(dpB[j][k]>=0) if(dpB[j+ws[i]-ws[0]][k+1]<dpB[j][k]+vs[i]) dpB[j+ws[i]-ws[0]][k+1]=dpB[j][k]+vs[i];
					}
				}
			}
			for(int k=0;k<=allowed;k++) {
				for(int j=0;j<=rem;j++) {
					if(sol<dpB[j][k]) sol=dpB[j][k];
				}
			}
			allowed--;
			rem=W-allowed*ws[0];
			if(rem>607) rem=607;
		}
		
	}
	printf("%d\n",sol);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cmath>
#define value( x ) cout<< "value of "<< #x << " is "<< x<<endl;
long long max( long long x, long long y) {if(x>y) return x;else return y;}
using namespace std;
int main()
{
	
  int x, n, count1=0, count2=0;
  for(int i=0;i<3;i++){
  	cin>>x;
  	if(x==5) count1++;
  	else if(x==7) count2++;
  }
  if(count1==2&&count2==1)cout<<"YES";
  else cout<<"NO";
return 0;
}


Measured memory_bytes: 256
N=int(input())

l = []
for i in range(N):
    s,p=input().split()
    p=int(p)
    l.append([s,p,i])
    
l=sorted(sorted(l,key=lambda x:x[1],reverse=True),key=lambda x:x[0])

for a in l:
    print(a[2]+1)
    


Measured memory_bytes: 3060
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


from collections import defaultdict

N = I()
D = LI()
d1 = defaultdict(int)  # 問題案
for d in D:
    d1[d] += 1

M = I()
T = LI()
d2 = defaultdict(int)  # 必要な問題
for t in T:
    d2[t] += 1

for key in d2.keys():
    if d2[key] > d1[key]:
        print('NO')
        break
else:
    print('YES')


Measured memory_bytes: 153408
#include "iostream"
using namespace std;
int main()
{
long long int a,b;
cin>>a>>b;
//if((a%2==0 && b%2==0) || (a%2!=0 && b%2!=0))
if(a+b==(a+b)/2*2)
cout<<(a+b)/2;
else 
cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int main(){
	int dataset;
	cin >> dataset;
	bool f = true;
	while(dataset--){
		if(!f) cout << endl;

		vector<vi> v(9, vi(9, 0));
		vector<vi> ng = v;
		rep(i, 9) rep(j, 9) cin >> v[i][j];

		rep(i, 9){
			vi cnt1(10, 0), cnt2(10, 0), cnt3(10, 0);
			int x = i%3*3;
			int y = i/3*3;
			rep(j, 9){
				cnt1[v[i][j]]++;
				cnt2[v[j][i]]++;
				cnt3[v[y+j/3][x+j%3]]++;
			}
			rep(j, 9){
				if((cnt1[v[i][j]] >= 2)) ng[i][j] = 1;
				if(cnt2[v[j][i]] >= 2) ng[j][i] = 1;
				if((cnt3[v[y+j/3][x+j%3]] >= 2)) ng[y+j/3][x+j%3] = 1;
			}
		}

		rep(i, 9){
			rep(j, 9){
				cout << (ng[i][j]?'*':' ') << v[i][j];
			}
			cout << endl;
		}

		f = false;
	}


	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;
bool sr(int a, int b)
{
	return a > b;
}
bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(ll n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}

int main()
{
	int n;
	cin >> n;
	vector<int> a(n), b(n), dis(n);

	rep(i, n)
	{
		cin >> a[i] >> b[i];
		dis[i] = b[i]-a[i] % b[i];
		if(dis[i]==b[i]){
			dis[i]=0;
		}
		
	}
	reverse(all(a));
	reverse(all(b));
	reverse(all(dis));
	ll now = 0;
	rep(i, n)
	{
		if (now > dis[i])
		{
			int rem=(now+a[i])%b[i];
			if(rem==0){

			}else{
				now+=b[i]-rem;
			}
		}
		else
		{
			now = dis[i];
		}
	}
	cout<<now<<endl;
}

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

;; BEGIN_INSERTED_CONTENTS
(defconstant +binom-size+ 200000)
(defconstant +binom-mod+ #.(+ (expt 10 9) 7))

(declaim ((simple-array (unsigned-byte 32) (*)) *fact* *fact-inv* *inv*))
(defparameter *fact* (make-array +binom-size+ :element-type '(unsigned-byte 32)))
(defparameter *fact-inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))
(defparameter *inv* (make-array +binom-size+ :element-type '(unsigned-byte 32)))

(defun initialize-binom ()
  (setf (aref *fact* 0) 1
        (aref *fact* 1) 1
        (aref *fact-inv* 0) 1
        (aref *fact-inv* 1) 1
        (aref *inv* 1) 1)
  (loop for i from 2 below +binom-size+
        do (setf (aref *fact* i) (mod (* i (aref *fact* (- i 1))) +binom-mod+)
                 (aref *inv* i) (mod (- (* (aref *inv* (rem +binom-mod+ i))
                                           (floor +binom-mod+ i)))
                                     +binom-mod+)
                 (aref *fact-inv* i) (mod (* (aref *inv* i)
                                             (aref *fact-inv* (- i 1)))
                                          +binom-mod+))))

(initialize-binom)

(declaim (inline binom))
(defun binom (n k)
  (if (or (< n k) (< n 0) (< k 0))
      0
      (mod (* (aref *fact* n)
              (mod (* (aref *fact-inv* k) (aref *fact-inv* (- n k))) +binom-mod+))
           +binom-mod+)))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

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

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((h (read))
         (w (read))
         (a (read))
         (b (read))
         (res 0))
    (declare (uint31 h w a b res))
    (loop for j from (+ b 1) to w
          do (setf res (mod (+ res
                               (mod (* (binom (+ (- h a 1) (- j 1)) (- j 1))
                                       (binom (+ (- a 1) (- w j)) (- w j)))
                                    +mod+))
                            +mod+)))
    (println res)))

#-swank(main)


Measured memory_bytes: 25824
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

ll rem[3][200010], re[3], F[200010], T[200010];

int PC(int x){
	int ans = 0;
	for (int i = 0;i < 26;i++) {
		if (x & (1 << i))ans++;
	}
	return ans;
}

int main() {
	int N;
	cin >> N;
	string X;
	cin >> X;
	int pc = 0;
	for (int i = 0;i < N;i++) {
		if (X[i] == '1')pc++;
	}
	if (pc == 0) {
		//全て1回
		for (int i = 0;i < N;i++) {
			cout << 1 << "\n";
		}
		return 0;
	}
	else if (pc == 1) {
		//立っているのを選んだら0回
		//立っていないのを選んだら
		//それが末端の時は2回
		//それが末端でない時は1回
		for (int i = 0;i < N;i++) {
			if (X[i] == '1')cout << 0 << "\n";
			else if (i == N - 1) {
				cout << 2 << "\n";
			}
			else {
				cout << 1 << "\n";
			}
		}
		return 0;
	}

	int d = 1 % (pc - 1), d2 = 1, d3 = 1;
	for (int i = 0;i < N;i++) {
		rem[0][N - i - 1] = d;
		rem[1][N - i - 1] = d2;
		rem[2][N - i - 1] = d3;
		d *= 2, d2 *= 2, d3 *= 2;
		d %= pc - 1, d2 %= pc, d3 %= pc + 1;
	}
	for (int i = 0;i < N;i++) {
		if (X[i] == '0')continue;
		for (int j = 0;j < 3;j++) {
			re[j] += rem[j][i];
		}
	}
	for (int i = 0;i < N;i++) {
		if (X[i] == '0') {
			F[i] = (re[2] + rem[2][i]) % (pc + 1);
		}
		else {
			F[i] = (re[0] - rem[0][i]) % (pc - 1);
			if (F[i] < 0)F[i] += pc - 1;
		}
		T[i] = 1;
	}
	queue<pair<int, int>> Q;
	for (int i = 0;i < N;i++) {
		if (F[i])
			Q.push({ F[i],i });
	}
	pair<int, int> m;
	int npc;
	while (!Q.empty()) {
		m = Q.front();
		Q.pop();
		T[m.second]++;
		npc = PC(m.first);
		m.first %= npc;
		if (m.first) {
			Q.push(m);
		}
	}
	for (int i = 0;i < N;i++) {
		cout << T[i] << "\n";
	}
}

Measured memory_bytes: 13060
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		a.push_back(x);
	}
	int res = *std::max_element(a.begin(), a.end())-*std::min_element(a.begin(), a.end());
	cout << res;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define dbug(x) cout<<#x<<"="<<x<<endl
#define m0(x) memset(x,0,sizeof(x))
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pl;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main(){

  string S;
  cin >> S;
  int len=S.length();
  int itrn=pow(2,len-1);
  ll sum=0;
  ll sum_temp=0;
  int num[len];

  rep(i,len){
    num[i]=ctoi(S[i]);
  }

  rep(i,itrn){
    int citrn=i;

    rep(j,len-1){
      sum_temp+=num[j];
      if(citrn%2){
        sum_temp=sum_temp*10;
      }
      else{sum+=sum_temp;

        sum_temp=0;}
      citrn=citrn/2;
      }
    sum_temp+=num[len-1];
    sum+=sum_temp;
    sum_temp=0;
  }

  cout << sum <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MOD = 1e9+7
#define rep(i,n) for(int i=0;i<(n);++i)
const double PI=3.14159265358979323846; 
const int INF = 1001001001;
using namespace std;

int main(){
  int a;
  cin >> a;
  cout << a + a*a + a*a*a << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ios_base::sync_with_stdio( false );
    int a, b, c, x, y;
    cin >> a >> b >> c >>  x >> y;
    int result = INT_MAX;
    for(int i = 0; i <= max(x, y); i++){
        int tmp = 2 * c * i + max(0, x - i) * a + max(0, y - i) * b;
        if(tmp < result){
            result = tmp;
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<queue>
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int c[4][2]={1,0,0,1,-1,0,0,-1};
int puzzle[10];

map<string,int> book;
struct yun
{
    int s;
    int state[9];
};

int bfs()
{
    int i,j,k,l;
    yun st,en;
    queue<yun> Q;
    st.s=0;
    for(i=0;i<9;i++)
        st.state[i]=puzzle[i];
    Q.push(st);
    while(Q.size())
    {
        st=Q.front();
        Q.pop();
        for(k=0;k<9;k++)
            if(!st.state[k])break;
        int x=k/3,y=k%3;
        for(j=0;j<4;j++)
        {
            int dx=x+c[j][0];
            int dy=y+c[j][1];
            int dz=dx*3+dy;
            if(dx<0||dy<0||dx>=3||dy>=3)continue;
            string ss="";
            for(l=0;l<9;l++)
                en.state[l]=st.state[l];
            en.state[k]=en.state[dz];
            en.state[dz]=0;
            int f=0;
            for(l=0;l<8;l++)
            {
                ss+=en.state[l]+'0';
                if(en.state[l]!=l+1)
                    f=1;
            }
          //  cout<<ss<<endl;
            if(!f)return st.s+1;
            if(book[ss])continue;
            book[ss]=1;
            en.s=st.s+1;
            Q.push(en);
        }
    }
}

int main()
{
    int i;
    for(i=0;i<9;i++)
        scanf("%d",&puzzle[i]);
    int g=0;
    for(i=0;i<8;i++)
    {
        if(puzzle[i]!=i+1)
            g=1;
    }
    int max1;
    if(!g)
        max1=0;
    else max1=bfs();
    printf("%d\n",max1);
}



Measured memory_bytes: 23112
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]
    Amax = max(A)

    INF = float('inf')
    dp = [[INF] * (H+Amax+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+Amax+1):
            tmp = j - A[i]
            if tmp >= 0:
                dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]])
            elif j == H and tmp < 0:
                dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i])
            else:
                dp[i+1][j] = dp[i][j]
    ret = min(dp[N][H:])
    print(ret)



if __name__ == "__main__":
    run()

Measured memory_bytes: 307848
S = input()
T = input()
T_high = len(T) - 1

ans = "~~UNRESTORABLE~~"

for i in range(T_high, len(S)):
    flg = False
    for j in range(T_high + 1):
        c = S[i + j - T_high]
        if c != '?' and c != T[j]:
            flg = True
            break
    if not flg:
        buf = S.replace("?", "a")
        ans = min(ans, buf[:(i - T_high)] + T + buf[(i + 1):])

print(ans.replace("~", ""))

Measured memory_bytes: 3064
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	ins := strings.Split(readLine(), " ")
	wi, _ := strconv.Atoi(ins[0])
	hi, _ := strconv.Atoi(ins[1])
	xi, _ := strconv.Atoi(ins[2])
	yi, _ := strconv.Atoi(ins[3])

	w := float64(wi)
	h := float64(hi)
	x := float64(xi)
	y := float64(yi)

	var j int

	if w/2 == x && h/2 == y {
		j = 1
	}

	fmt.Println(w*h/2, j)
}


Measured memory_bytes: 640
import java.util.*;

import static java.lang.System.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = ni();
        String s = ns();
        String t = ns();

        for (int i = 0; i < N; i++) {
            boolean ok = true;
            for (int j = 0; j < N - i; j++) {
                if (s.charAt(i + j) != t.charAt(j)) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                out.println(N + i);
                return;
            }
        }

        out.println(2 * N);
    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static int[] niarr(int N) {
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        return a;
    }

    static long[] nlarr(int N) {
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextLong();
        }
        return a;
    }
}

Measured memory_bytes: 23764
#include <iostream>

using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	int K;
	cin >> K;

	for (int i = 0; i < K; i++) {
		if (A >= B) {
			B *= 2;
			continue;
		}
		if (B >= C) {
			C *= 2;
			continue;
		}
	}

	if (A < B && B < C)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

int main()
{
	char a[10];
	
	scanf("%s", a);
	if (a[0] == a[1] && a[1] == a[2] || a[1] == a[2] && a[2] == a[3]) puts("Yes");
	else puts("No");
}



Measured memory_bytes: 256
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

n = int(input())

x = []
for i in range(n):
    x.append(int(input()))

for i in range(3):
    if a[i] in x:
        a[i] = True
    else:
        a[i] = False
    if b[i] in x:
        b[i] = True
    else:
        b[i] = False
    if c[i] in x:
        c[i] = True
    else:
        c[i] = False

flag = False

if a[0] and a[1] and a[2]:
    flag = True
if b[0] and b[1] and b[2]:
    flag = True
if c[0] and c[1] and c[2]:
    flag = True

for i in range(3):
    if a[i] and b[i] and c[i]:
        flag = True

if a[0] and b[1] and c[2]:
    flag = True
if a[2] and b[1] and c[0]:
    flag = True

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import qualified Data.Graph            as G
import           Data.List             (delete)
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [n, m] <- getInts
  abs <- getIntss
  print $ solve n m abs

solve :: Int -> Int -> [[Int]] -> Int
solve n m abs = length $ filter isBridge abs where
  isBridge [a, b] = not $ G.path g a b where
    g = G.buildG (1, n) es
    es = twin $ delete [a, b] abs

twin :: [[Int]] -> [(Int, Int)]
twin = concatMap $ \[a, b] -> [(a, b), (b, a)]

readInts :: BC.ByteString -> [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words

getInts :: IO [Int]
getInts = readInts <$> BC.getLine

getIntss :: IO [[Int]]
getIntss = map readInts . BC.lines <$> BC.getContents


Measured memory_bytes: 892
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		
		if(a < b && b < c){
			System.out.println("Yes");
		}

		else {
			System.out.println("No");

		}

		
	}
}


Measured memory_bytes: 26332
#include<iostream>
using namespace std;
int main(){
int a,b;
  cin >> a >> b;
  if(a==b){
  cout << a*2 << endl;
  }else if(a<b){
  cout << b+b-1 << endl;
  }else{
  cout << a+a-1 << endl;
  }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll cnt[11111][26];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;

  for(int i=0;i<n;i++){
    string s;cin>>s;
    for(auto a:s)cnt[i][a-'a']++;
  }
  vector<char>ans;
  for(int i=0;i<26;i++){
    ll mi=llINF;
    for(int j=0;j<n;j++){
      mi=min(mi,cnt[j][i]);
    }
    for(int j=0;j<mi;j++)
      ans.pb((char)(i+'a'));
  }
  for(auto a:ans)cout<<a;
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int h,w;
  cin >> h >> w;
  rep(i,h){
    string s; cin>>s;
    cout<<s<<endl;
    cout<<s<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()
	tmpN := N

	total := 0

	for {
		d := tmpN % 10
		total += d
		if int64(tmpN / 10) == 0 {
			break
		}
		tmpN /= 10
	}

	// fmt.Printf("N, %v\n", N)


	//fmt.Printf("divide, %v\n",float64(N) / float64(total))
	//fmt.Printf("divide, %v\n",(float64(N) / float64(total)) - float64(N / total))
	//c := float64(N / total) - float64(int64(N / total))
	//fmt.Printf("float64(N / total), %v\n", float64(N / total))
	if (float64(N) / float64(total)) - float64(N / total) == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

	//for {
	//	N = N / total
	//	fmt.Printf("N, %v\n", N)
	//	if N == 0 {
	//		fmt.Println("Yes")
	//		break
	//	}
	//
	//	if N < total {
	//		fmt.Println("No")
	//		break
	//	}
	//}
}


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

int main() {
	int d;
	cin >> d;
	string s;

	if (d == 25) s = "Christmas";
	else if (d == 24) s = "Christmas Eve";
	else if (d == 23) s = "Christmas Eve Eve";
	else if (d == 22) s = "Christmas Eve Eve Eve";

	cout << s << endl;
	return 0; 
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			int N = Integer.parseInt(sc.nextLine());
			// https://atcoder.jp/contests/abc125/submissions/5147323の9行目
			int[] A = IntStream.range(0, N).map(i -> sc.nextInt()).toArray();
			
			int[] preGCD = new int[N+1]; // 前からGCDを計算した結果
			for (int i = 0; i < N; i++) {
				preGCD[i + 1] = gcd(preGCD[i], A[i]); 
//				System.out.println("preGCD [" + i + "] = " + preGCD[i] + ", A[" + i + "] = " + A[i]);
//				System.out.println("preGCD [" + (i+1) + "] = " + preGCD[i+1] );
//				System.out.println("");
			}
			
			int[] postGCD = new int[N+1]; // 後ろからGCDを計算した結果
			for (int i = N -1;  0 <= i; i--) {
				postGCD[i] = gcd(postGCD[i + 1], A[i]); 
//				System.out.println("postGCD [" + (i+1) + "] = " + postGCD[i+1] + ", A[" + i + "] = " + A[i]);
//				System.out.println("postGCD [" + (i) + "] = " + postGCD[i] );
//				System.out.println("");
			}
			
			int maxGcd = 1;
			for (int i = 0; i < N; i++) {
				// 無視する場所の”1 ~ i-1まで”の公約数と"i+1 ~ N"までの公約数の公約数を求めれば、OK
				maxGcd = Math.max(gcd(preGCD[i], postGCD[i+1]), maxGcd);
			}
			
			System.out.println(maxGcd);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private static int gcd(int m, int n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
		
}


Measured memory_bytes: 60124
implicit none
integer n,i,j
integer :: counts=0,max_height=0
integer,allocatable,dimension(:)::h

read(5,*) n

allocate(h(n))

read(5,*) (h(i),i=1,n)

do j=1,n
if(h(j).ge.max_height) then
counts=counts+1
endif
max_height=max(max_height,h(j))
enddo

write(6,*) counts

deallocate(h)
end

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

template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}

const std::uint_fast64_t MOD = 1e9 + 7;
/**
 * usage: modint<mod> x(1);
 * x.aで値を取り出し. modint同士で計算をやる.
 * http://noshi91.hatenablog.com/entry/2019/03/31/174006
 */
template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint &rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint &rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint &rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint &rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint &rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint &rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint &rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

vector<pair<int, int>> prime_factorization(int n) {
    vector<pair<int, int>> ret;
    int i = 2;
    for (; i * i <= n; i++) {
        int cnt = 0;
        while (n % i == 0) ++cnt, n /= i;
        if (cnt) ret.push_back({i, cnt});
    }
    ret.push_back({n, 1});
    return ret;
}

int pow_mod(int n, int k, int m) {
    int r = 1;
    for(; k > 0; k >>= 1) {
        if(k & 1)
            r = (r * n) % m;
        n = (n * n) % m;
    }
    return r;
}


signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    map<int, int> m;
    for (int a : A) {
        for (auto& p: prime_factorization(a)) {
            m[p.first] = max(p.second, m[p.first]);
        }
    }
    modint<MOD> lcm(1);
    for (auto& p: m) {
        lcm *= modint<MOD>(pow_mod(p.first, p.second, MOD));
    }
    modint<MOD> ans(0);
    for(int i = 0; i < N; i++) {
        ans += lcm / modint<MOD>(A[i]);
    }
    cout << ans.a << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#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;

bool is_prime (int n )
{
	if (n < 2 ) return false;
	if (n == 2 ) return true;
	if (n % 2 == 0 ) return false;

	for (int i = 3; i*i <= n; i += 2 ){
		if (n % i == 0 ) return false;
	} // end rep
	
	return true;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.prime_number", "r", stdin );
	int n;
	scanf ("%d", &n );
	int res = 0;
	rep (i, n ){
		int m;
		scanf ("%d", &m );
		if (is_prime (m ) ) res++;
	} // end rep
	printf ("%d\n", res );
		
	return 0;
}

Measured memory_bytes: 0
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};
const main=()=>{
  let [a,b]=tnn(2),ans=0
  if(a==1)ans+=300000
  else if(a==2)ans+=200000
  else if(a==3)ans+=100000
  if(b==1)ans+=300000
  else if(b==2)ans+=200000
  else if(b==3)ans+=100000
  if(a==1&&b==1)ans+=400000
  to(ans)
}
main()


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

int main(){
    int h, w, s, t;
    cin >> h >> w >> s >> t;
    if(h > w)   swap(h,w), swap(s,t);
    if(h == 1){
        cout << (t==0||t==w-1 ? "Yes" : "No") << endl;
    }else{
        bool ok = w%2 == 0 || h%2 == 0;
        // wもhも奇数のとき、縦s、横tの線で長方形の区画を4等分したときに
        // 4区画すべての縦横の偶奇がそれぞれ等しければ達成できる
  
        // sやtが端っこの場合は4区画にはならないが、端っこならそもそも
        // 確実に達成できるので、ここでは考える必要は無い
  
        // 4区画の縦横の偶奇が一致している&大元の縦横は奇数->隣り合う区画
        // は縦横 偶偶と奇奇 奇奇なら始点と終点は区画の辺を共有する角、
        // 偶偶なら始点と終点は対角

        // 4区画を一筆書きでうまく埋めることができる

        ok |= (s%2 == t%2);

        cout << (ok ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 3124