akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;
// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }



#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  vector<ll> a(N);
  ll sum = 0;
  for(int i = 0; i < N; i++) {
    int n;
    cin >> n;
    sum += n;
    a[i] = n;
  }

  ll zero_to_N = (N * (N + 1)) / 2;

  if( sum % zero_to_N != 0 ) {
    cout << "NO\n";
    return 0;
  }

  // k回操作を行う
  ll k = sum / zero_to_N;
  vector<ll> diff(N);
  for(int i = 0; i < N-1; i++) {
    diff[i] = a[i+1] - a[i];
  }
  diff[N-1] = a[0] - a[N-1];

  bool flag = true;

  for(int i = 0; i < N; i++) {
    if( not( (diff[i] - k) <= 0 && (diff[i] - k) % N == 0  )) {
      flag = false;
      break;
    }
  }

  cout << ( flag ? "YES" : "NO"  ) << "\n";

  return 0;
}


Measured memory_bytes: 1792
n = int(input())
s = str(input())

alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ans =""

for i in s:
    #print(alp.index(i)+1+n)
    if alp.index(i)+1+n > 26:
        ans += alp[alp.index(i)+n-26]
    else:
        ans += alp[alp.index(i)+n]

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long

using namespace std;

inline ll read()
{
    ll ret=0,flag=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();}
    while(c>='0'&&c<='9')ret=ret*10+(c^'0'),c=getchar();
    return flag*ret;
}

const ll N=2e5+5;
ll n,k;
ll s[N];

int main()
{
    n=read(),k=read();
    for(ll i=1;i<=n;i++)s[i]=read();
    if(k>=n)
    {
        printf("%lld",0);
        return 0;
    }
    sort(s+1,s+n+1);
    ll ans=0;
    for(ll i=n-k;i>=1;i--)ans+=s[i];
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    char S[200000];
    bool can = true;
    bool space3 = false;
    string ans;
    rep(i,N) cin >> S[i];
    if (C<D)
    {
        for(int i = A - 1; i < C - 1; i++){
            if (S[i] == '#' && S[i+1] == '#'){
                can = false;
                break;
            }
        }

        for (int i= C;i<D-1;i++){
            if (S[i] == '#' && S[i+1] == '#'){
                can = false;
                break;
            }
        }

    }else
    {
        for (int i=B-2;i<D-1;i++){
            if (S[i] == '.' && S[i+1] == '.' && S[i+2] == '.'){
                space3 = true;
                B = S[i+1];
                break;
            }
        }
        if (space3){
            for (int i=B;i<D-1;i++){
                if (S[i] == '#' && S[i+1] == '#'){
                    can = false;
                }
            }
            for (int i=A;i<C-1;i++){
                if (S[i] == '#' && S[i+1] == '#'){
                    can = false;
                }
            }
        }else can = false;
    }
    if (can){
         cout << "Yes" << endl;
    }else cout << "No" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int N, M; cin >> N >> M;
  vec v(N);
  rep(i,M){
    int a, b; cin >> a >>b;
    v[a-1]++; v[b-1]++;
  }
  rep(i,N) cout <<v[i] << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.print(a*b+" ");
		System.out.println(a+a+b+b);
		
	}

}


Measured memory_bytes: 26096
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 1e5;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string s; cin >> s;
	for(int i = 0; i < s.length(); i++)
		if(s[i]=='?')
			s[i] = 'D';
	cout<<s<<endl;

	cout<<flush;
	return 0;
}

Measured memory_bytes: 3380
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits.h>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ret=INT_MAX;
    for(int i=0;i<26;i++){
        int mn=INT_MAX;
        int mx=0;
        for(int j=n-1;j>=0;j--){
            if(s[j]==(char)('a'+i)){
                mn=j;
            }else if(mn==INT_MAX){
                mx=max(mx,n-j);
            }else{
                mx=max(mx,mn-j);
            }
        }
        ret=min(ret,mx);
    }
    cout<<ret<<endl;
}


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

public class PaizaPj
{
    const string PrintScoreN = "1";
    const string SolveNM = "2";

    public static void Main()
    {
        // 読込
        var K = int.Parse(Console.ReadLine().Trim());
        var strs = Console.ReadLine().Trim().Split(' ');
        var A = int.Parse(strs[0]);
        var B = int.Parse(strs[1]);

        var res = "NG";
        for (int i = A; i <= B; i++)
        {
            if (i % K == 0)
            {
                res = "OK";
                break;
            }
        }
        Console.WriteLine(res);

        //Console.ReadLine();
    }

}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout << x << '\n';

#define INF (1 << 29)

#define FAST cin.tie(0), ios::sync_with_stdio(false)
inline int chmax(int &a, int b){return b>a ? a=b,1 : 0;}
inline int chmin(int &a, int b){return b<a ? a=b,1 : 0;}
//________

main(){
  char s[100010];
  scanf("%s", s);
  reps(i,'a','z'){
    if(strchr(s,i) == NULL){
      printf("%c\n", i);
      return 0;
    }
  }
  puts("None");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <string>
#define rep(i,n) for(int i=0; i<n; ++i)
#define dev std::cout << "OK" << std::endl

int main(){
    int N;
    std::cin >> N;
    int A[N];
    rep(i,N) std::cin >> A[i];

    std::string str = "DENIED";

    for(int i=0; i<N; ++i){
        if(A[i] % 2 == 0){
            if(A[i]%3 != 0){
              //dev;
            
              if(A[i]%5 != 0){
                break;
              }
            }
        }
      //std::cout << i << " " << N << std::endl;
      
        if(i == N-1){
            str = "APPROVED";
			
        }
    }
    std::cout << str << std::endl;
}
    

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long target = sc.nextLong();
		for (int i = 1; i < n; i++) {
			target = get(target, sc.nextLong());
		}
		System.out.println(target);
	}
	
	static long get(long a, long b){
		return a / gcd(a, b) * b;
	}
	
	static long gcd(long a, long b) {
		long x = a % b;
		if (x == 0) {
			return b;
		} else {
			return gcd(b, x);
		}
	}
}


Measured memory_bytes: 22868
N,T = map(int,input().strip().split())

cs = []
ts = []
minc = None

for i in range(N):
    tempc,tempt = map(int,input().strip().split())
    cs.append(tempc)
    ts.append(tempt)
    if tempt <= T:
        if minc is None or tempc < minc:
            minc = tempc

if minc is not None:
    print(minc)
else:
    print('TLE')

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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long)(1e15)
//#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');
    cerr.write(names, name-names) << " = " << arg1 << endl;
    _F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){
    in >> q.F >> q.S; return in;
}template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}

void solve(){
    int n;
    int ans = 0;
    cin >> n;
    string s;
    cin >> s;
    int r[n+1], g[n+1], b[n+1];
    r[n] = b[n] = g[n] = 0;
    for(int i = n-1; i >= 0; i--){
        r[i] = r[i+1];
        g[i] = g[i+1];
        b[i] = b[i+1];
        if(s[i] == 'R')r[i]++;
        if(s[i] == 'G')g[i]++;
        if(s[i] == 'B')b[i]++;
    }
    string tmp = "RGB";
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(s[i] == s[j])continue;
            char c;
            for(auto u : tmp){
                if(u != s[i] && u != s[j])
                    c = u;
            }
            if(c == 'R')ans += r[j+1]-(j+(j-i) < n && s[2*j-i] == 'R');
            if(c == 'G')ans += g[j+1]-(j+(j-i) < n && s[2*j-i] == 'G');
            if(c == 'B')ans += b[j+1]-(j+(j-i) < n && s[2*j-i] == 'B');  
        }
    }
    cout << ans << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(12);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif

    //cin >> t;

    for(int i = 1; i <= t; ++i){
        //cout << "Case #" << i << ": ";
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(ll &x){
    x=0;static char ch;static bool flag;flag = false;
    while(ch=getchar(),ch<'!');if(ch=='-') ch=getchar(),flag = true;
    while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
const int lim = 100000000;
int main(){
    ll a,b,c;read(a);read(b);read(c);
    int ans = 0;
    ll tmpa,tmpb,tmpc;
    while(ans <= lim){
	tmpa = tmpb = tmpc = 0;
	bool flag = false;
	if(!(a&1)) tmpb += a >> 1,tmpc += a >> 1;
	else break;
	if(!(b&1)) tmpa += b >> 1,tmpc += b >> 1;
	else break;
	if(!(c&1)) tmpa += c >> 1,tmpb += c >> 1;
	else break;
	if(a == tmpa && b == tmpb && c == tmpc){
	    puts("-1");
	    return 0;
	}
	a = tmpa;
	b = tmpb;
	c = tmpc;
	++ ans;
//	printf("%lld %lld %lld\n",a,b,c);
    }
    if(ans <= lim) printf("%d\n",ans);
    else puts("-1");
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    if(n%2) cout << n*2 << endl;
    else cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using p = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int n;
    cin >> n;
    vector<int> vec(4);
    rep(i,n){
        string s;
        cin >> s;
        if(s=="AC"){
            vec.at(0)++;
        }
        if(s=="WA"){
            vec.at(1)++;
        }
        if(s=="TLE"){
            vec.at(2)++;
        }
        if(s=="RE"){
            vec.at(3)++;
        }
    }
    cout << "AC" << " x " << vec.at(0) << endl;
    cout << "WA" << " x " << vec.at(1) << endl;
    cout << "TLE" << " x " << vec.at(2) << endl;
    cout << "RE" << " x " << vec.at(3) << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll dp[100005];
ll qpow(ll a,ll b)
{
	if(b==0) return 1;
	ll c=qpow(a,b/2);
	if(b%2==0) return c*c%mod;
	else return c*c%mod*a%mod;
}
int main()
{
	ll n,k;
	scanf("%lld%lld",&n,&k);
	ll sum=0;
	for(ll i=k;i>0;i--)
	{
		dp[i]=(qpow(k/i,n))%mod;
		for(ll j=i*2;j<=k;j+=i) dp[i]=(dp[i]-dp[j]+mod)%mod;
		sum=(sum+dp[i]*i)%mod;
	}
	printf("%lld",sum);
}

Measured memory_bytes: 4584
#include<iostream>
#include<cstdlib>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
//--------------------
#define MOD 1000000007 
using namespace std;
//--------------------
int main(){

	string res = "ABC";
	int R; cin >> R;

	if (R >= 1200) res = "ARC";
	if (R >= 2800) res = "AGC";

	cout << res << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int k;
int main(){
	scanf("%lld %lld %d",&a,&b,&k);
	int opt=1;
	while(k--){
		if(opt==1){
			if(a%2==0){
				b+=a/2;
				a/=2;
			}
			else{
				a--;
				b+=a/2;
				a/=2;
			}
		}
		if(opt==2){
			if(b%2==0){
				a+=b/2;
				b/=2;
			}
			else{
				b--;
				a+=b/2;
				b/=2;
			}
		}
		opt=opt==1?2:1;
	}
	printf("%lld %lld",a,b);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

string s, t;

int main(){
  ios_base::sync_with_stdio(false);

  cin >> s >> t;

  vector<string> ans;

  for(int i=0;i<s.size()-t.size()+1;i++){
    int f = 0;
    for(int j=0;j<t.size();j++){
      if(s[i+j] == '?' || s[i+j] == t[j])continue;
      else {
        f = 1;
        break; 
      }
    }

    if(f)continue;

    string a;
    a = s;

    for(int j=0;j<a.size();j++)if(a[j] == '?')a[j] = 'a';
    for(int j=0;j<t.size();j++)a[i+j] = t[j];

    ans.push_back(a);

  }

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

  if(ans.size() == 0){
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << ans[0] << endl;
  }

  return 0;
}



Measured memory_bytes: 256
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

vi adj[101];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,k; cin >> n >> k;
	for(int i=0; i<k; i++){
		int m,kk; cin >> m;
		for(int j=0; j<m; j++){
			cin >> kk;
			adj[kk].pb(j);
		}
	}
	int cnt =0;
	for(int i=1; i<=n; i++){
		if(adj[i].empty())cnt++;
	}
	cout << cnt << endl;
}	


Measured memory_bytes: 3656
use proconio::input;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        AB: [(u64, u64); N]
    }
    let mut A: Vec<u64> = vec![0; N];
    let mut B: Vec<u64> = vec![0; N];

    for i in 0..N {
        let (a, b) = AB[i];
        A[i] = a;
        B[i] = b;
    }
    A.sort();
    B.sort();

    let (x, y) = if N % 2 == 0 {
        (A[N / 2 - 1] + A[N / 2], B[N / 2 - 1] + B[N / 2])
    } else {
        (A[(N + 1) / 2 - 1], B[(N + 1) / 2 - 1])
    };
    let ans = y - x + 1;
    println!("{}", ans);
}


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

public class Main {
    static StringBuilder sb;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sb = new StringBuilder();

        long a = sc.nextLong();
        long b = sc.nextLong();

        sb.append(to32BitBinaryString(a & b)).append("\n");
        sb.append(to32BitBinaryString(a | b)).append("\n");
        sb.append(to32BitBinaryString(a ^ b)).append("\n");

        PrintWriter out = new PrintWriter(System.out);
        out.print(sb);
        out.flush();
        
        sc.close();
    }

    public static String to32BitBinaryString(long l) {
        String s = String.format("%32s", Long.toBinaryString(l)).replace(" ", "0");
        return s.substring(s.length() - 32, s.length());
    }
}



Measured memory_bytes: 26444
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a   = scan.nextInt();
        int b[] = new int[a];
        int stop = 0;
        int count = 0;

        for (int i = 0; i < a; i++) {
            b[i] = scan.nextInt();
        }

        do{

            for (int x = 0; x < a; x++) {
                
                if(b[x] % 2 == 0 ){
                    b[x] = b[x]/2 ;
                }

                else{
                    stop = 1;
                }
            }

            if(stop == 0){
                count++;
            }
            
        }while( stop == 0 );

        System.out.println(count);
    }
}

Measured memory_bytes: 21460
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    t = deque()
    for i in s:
        t.append(i)
    q = I()
    k = 0
    for _ in range(q):
        qu = input().split()
        if qu[0] == "1":
            k ^= 1
        else:
            f,c = qu[1:]
            key = (int(f)-1)^k
            if not key:
                t.appendleft(c)
            else:
                t.append(c)
    ans = ""
    if not k:
        while t:
            ans += t.popleft()
    else:
        while t:
            ans += t.pop()
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 6644
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,n) for(int i= 0; i<(int)(n);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
const int N = 1e6+7 ;
string s ;
#define inp(a) for(auto& i : a) cin >> i;
int32_t main(){fast ;
	int n,k ;
	cin >> n ;
	vi a(n) ,b(n) , c(n) ;
	inp(a) inp(b) inp(c)
	sort(all(a)) ;
	sort(all(c)) ;
	int cnt = 0 ;
	F(i,n){
		int x = lower_bound(all(a),b[i]) - a.begin() ;
		int y = upper_bound(all(c),b[i]) - c.begin() ;
		cnt += (x*(n-y)) ;
	}
	cout << cnt << endl ;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define PI 2.0*acos(0.0)
#define ll              long long int
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define MOD             1000000007
#define mx              123456789
using namespace std;
int main()
{
    ll n, m, i;
    cin>>n>>m;
    ll a[n+2];
    ll sum=0;
    for(i=0; i<m; i++)
    {
        ll x;
        cin>>x;
        sum+=x;
    }
    if(sum>n)
        cout<<-1<<endl;
    else
        cout<<n-sum<<endl;
    return 0;
}


Measured memory_bytes: 3636
from collections import defaultdict

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def prime_factorization(n):
    '''
    Trial division.
    Input: 
        n : a positive integer
    Output:
        a dictionary of #(each prime factors) of n,
    '''
    result = defaultdict(int)
    if n < 2:
        return result
    while n % 2 == 0:
        result[2] += 1
        n //= 2
    p = 3
    while p*p <= n:
        while n % p == 0:
            n //= p
            result[p] += 1
        p += 2
    if n > 1:
        result[n] += 1
    return result

A, B = map(int, input().split())
g = gcd(A, B)
primes = prime_factorization(g)
print(1 + len(primes))

Measured memory_bytes: 3444
import sys

line_num = int(sys.stdin.readline().rstrip())
maxv = -2000000000
minv = int(sys.stdin.readline().rstrip())

for i in range(1, line_num):
    rt = int(sys.stdin.readline())
    if rt - minv > maxv:
        maxv = rt - minv
    if rt < minv:
        minv = rt

print(maxv)


Measured memory_bytes: 5612
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
int n,M[N][N];
int color[N],d[N],f[N],tt;
 
void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==WHITE){
      dfs_visit(v); 
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}
 
void dfs(){
  int u;
  for(u=0;u<n;u++)color[u]=WHITE;
  tt=0;
 
  for(u=0;u<n;u++){
    if(color[u]==WHITE)dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
 
int main(){
  int u,v,k,i,j;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j]=0;
  }
 
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
 
  dfs();
 
  return 0;
}



Measured memory_bytes: 2112
#include<iostream>
#include<algorithm>
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

int N,K,x[110000],r,ans,t;
int main(){
	cin >> N >> K;
	ans=0x7fffffff;
	fi(i,1,N)
        cin >> x[i];
	fi(l,1,N-K+1){
		r=l+K-1;
		if((x[l]>=0)^(x[r]>=0))
            t=-x[l]+x[r]+min(-x[l],x[r]);
        else
            t=max(abs(x[l]),abs(x[r]));
		if(ans>t)
            ans=t;
	}
    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;

vector<int> c;
vector<vector<int> > ns;
vector<int> ans;
vector<bool> visited;
int cindex;

void solve(int cur_pos){
    visited.at(cur_pos) = true;
    for(int ni : ns.at(cur_pos)){
        if(!visited.at(ni)){
            solve(ni);
        }
    }
    ans.at(cur_pos) = c.at(cindex);
    cindex++;
    return;
}

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

    vector<pair<int, int> > edges;
    ns.resize(n);
    for(int i = 0; i < n - 1; ++i){
        int a, b;
        cin >> a >> b;
        edges.push_back(make_pair(a - 1, b - 1));
        ns.at(a - 1).push_back(b - 1);
        ns.at(b - 1).push_back(a - 1);
    }

    for(int i = 0; i < n; ++i){
        int ci;
        cin >> ci;
        c.push_back(ci);
    }
    sort(c.begin(), c.end());

    ans.resize(n);
    visited.resize(n, false);
    cindex = 0;
    solve(0);

    int m = 0;
    for(auto &p : edges){
        m += min(ans.at(p.first), ans.at(p.second));
    }
    printf("%d\n", m);

    for(int i = 0; i < n; ++i){
        printf("%d", ans.at(i));
        if(i < n - 1){
            printf(" ");
        }else{
            printf("\n");
        }
    }
    return 0;
}


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

vector<vector<int>> E;
vector<int> V;

void dfs(int v, int p) {
  V.at(v) += V.at(p);
  for (int e : E.at(v)) if (p != e) dfs(e, v);
}

int main() {
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;

  E.resize(N + 1);
  for (int i = 1; i < N; i++) {
    int a, b;
    cin >> a >> b;
    E.at(a).push_back(b), E.at(b).push_back(a);
  }

  V.resize(N + 1);
  for (int i = 0; i < Q; i++) {
    int p, x;
    cin >> p >> x;
    V.at(p) += x;
  }

  dfs(1, 0);

  for (int i = 1; i <= N; i++) cout << V.at(i) << "\n";
}

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

// in-short-use macros

#define all(c) (c).begin(),(c).end()
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define PI 3.14159265
#define sizes 1000010



//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("C:/Users/Saurav Kumar Singh/Desktop/cp/input.txt", "r", stdin);
    freopen("C:/Users/Saurav Kumar Singh/Desktop/cp/output.txt", "w", stdout);
    #endif
    int k;
    cin>>k;
    string s,ans="";
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(i<k)
            ans+=s[i];
        else
        {
            ans+="...";
            break;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

string s;
int q;
int dir=0;
string f,b;
int main(){
    cin>>s;
    cin>>q;
    REP(i,q){
        int t;
        cin>>t;
        if(t==1){
            dir++;
        }else{
            int fi;
            string ci;
            cin>>fi>>ci;
            if((dir+fi)%2==1){
                f=f+ci;
            }else{
                b=b+ci;
            }
        }
    }
    string ans;
    REP(i,f.size()){
        ans=ans+f[f.size()-i-1];
    }
    ans=ans+s+b;
    if(dir%2==0){
        cout<<ans<<endl;
    }else{
        REP(i,ans.size()){
            cout<<ans[ans.size()-i-1];
        }
        cout<<endl;
    
    }
    return 0;
}

Measured memory_bytes: 1736
#include<cstdio>
#include<iostream>

using namespace std;

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

int h,w;
int cell[128][128];
int ans;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int check(int x, int y){
    if(x < 0 || y < 0 || y >= h || x >= w)return 0;
    return 1;
}

void func(int x, int y, int count){

    rep(i,4){
        if(check(x+dx[i],y+dy[i]) && cell[y+dy[i]][x+dx[i]] == 1){
            cell[y+dy[i]][x+dx[i]] = 0;
            func(x+dx[i], y+dy[i], count+1);
            cell[y+dy[i]][x+dx[i]] = 1;
        }else{
            ans = max(ans, count);
        }
    }
}

int main(void){

    while(scanf("%d%d", &w, &h), w){

        rep(i,h)rep(j,w)scanf("%d", &cell[i][j]);

        rep(i,h)rep(j,w)if(cell[i][j])func(j, i, 0);
        rep(i,128)rep(j,128)cell[i][j] = 0;
        printf("%d\n", ans);
        ans = 0;
    }

    return 0;
}

Measured memory_bytes: 1252
#include<stdio.h>

int main(){
  int an[5], i, k;

  for(i = 0; i < 5; i++){
    scanf("%d", &an[i]);
  }
  scanf("%d", &k);

  if(an[4] - an[0] > k){
    printf(":(\n");
  } else {
    printf("Yay!\n");
  }

  return 0;
}



Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    string S;
    cin >> S;
    int res = 0;
    if (S == "SUN") res = 7;
    else if (S == "MON") res = 6;
    else if (S == "TUE") res = 5;
    else if (S == "WED") res = 4;
    else if (S == "THU") res = 3;
    else if (S == "FRI") res = 2;
    else if (S == "SAT") res = 1;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
input()
a = list(map(int, input().split()))
nNegative = 0
total = 0
minVal = float('inf')
for num in a:
    if num < 0:
        num *= -1
        nNegative += 1
    minVal = min(minVal, num)
    total += num
print(total if nNegative & 1 == 0 else total - 2 * minVal)

Measured memory_bytes: 14412
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
const ll mod=1e9+7;

int main() {
		int N, M;
		cin >> N >> M;
  
		vector<int> oks(N+1, true);
		for (int i = 0; i < M; i++) {
				int a; 
				cin >> a;
				oks[a] = false;
		}

		vector<ll> dp(N+1, 0);
		dp[0] = 1;
		for (int now = 0; now < N; ++now) {
				for (int next = now + 1; next <= min(N, now+2); ++next) {
						if (oks[next]) {
								dp[next] += dp[now];
								dp[next] %= mod;
						}
				}
		}

		cout << dp[N] << endl;
		return 0;
}


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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
using ll  = long long;
using vi  = vector<int>;

signed main(){
  int x, y, z, k; cin >> x >> y >> z >> k;
  vi a(x); rep(i,x) cin >> a[i];
  vi b(y); rep(i,y) cin >> b[i];
  vi c(z); rep(i,z) cin >> c[i];

  vi ab;
  rep(i,x) rep(j,y) ab.push_back(a[i]+b[j]);
  sort(rall(ab));
  if(k < ab.size()) ab.erase(ab.begin()+k,ab.end());

  vi abc;
  rep(i,ab.size()) rep(j,z) abc.push_back(ab[i]+c[j]);
  sort(rall(abc));

  rep(i,k) cout << abc[i] << endl;
}


Measured memory_bytes: 43368
#include <bits/stdc++.h>
#define repeat(i, n) for(int (i) = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const double EPS = numeric_limits<double>::epsilon();
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int N;
	cin >> N;
	int result = N / 2;

	if ((N % 2) == 1) result++;

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    string s;
    cin>>s;
    ll ans=0;
    for(auto ch:s)
    {
        if(ch=='+')
            ans++;
        else
            ans--;
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 15516
import std.stdio,
       std.string,
       std.conv;

void main() {
    int N = readln.chomp.to!int;
    while(N--) {
        auto i = readln.split;
        auto c = i[0].to!int, a = i[1].to!int, n = i[2].to!int;
        int ans;
        while(c && a && n) {
            ans++;
            c--;
            a--;
            n--;
        }
        while(c >= 2 && a) {
            ans++;
            c -= 2;
            a--;
        }
        while(c >= 3) {
            ans++;
            c -= 3;
        }
        ans.writeln;
    }
}

Measured memory_bytes: 1048
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    while (1) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
INF = 10**18

if __name__ == "__main__":
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    preA = [0]
    for i in range(n):
        preA.append(preA[i] + a[i])
    preB = [0]
    for i in range(m):
        preB.append(preB[i]+b[i])
    ans = 0
    preB.pop(0)
    for i in range(n+1):
        if preA[i] <= k:
            find = bisect.bisect_right(preB,k-preA[i])
            ans = max(ans,find+i)
    print(ans)

Measured memory_bytes: 47808
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pii;
const int inf = (1<<28) +11555;


template <class T>
struct SegmentTree {
private:
    int n;
    using F = function<T(T,T)>;
    F func;
    vector<T> node;
    T initial;
public:
// vector, function,iniの順番に突っ込む。
    SegmentTree(vector<T> v,F f,T ini) {
        func = f;
        initial = ini;
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, initial);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = func(node[2*i+1], node[2*i+2]);
    }

    void update(int x, T val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = func(node[2*x+1], node[2*x+2]);
        }
    }

    int find(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return initial;
        if(a <= l && r <= b) return node[k];

        int vl = find(a, b, 2*k+1, l, (l+r)/2);
        int vr = find(a, b, 2*k+2, (l+r)/2, r);
        return func(vl, vr);
    }
};

int main(){
    // sort(vc.begin(),vc.end())
    int n;
    cin >> n;
    vector<pii>  dubl(n);
    vector<lli> xvec(n);
    lli x,d;
    rep(i,n){
        cin >> x >> d;
        dubl.at(i).first = x;
        dubl.at(i).second = d;
        xvec.at(i) = x;
    } 
    sort(dubl.begin(),dubl.end());
    sort(xvec.begin(),xvec.end());
    lli mod = 998244353;
    vector<int> issou(n);
    int ima;
    rep(i,n){
        ima = lower_bound(xvec.begin(),xvec.end(),dubl.at(i).first + dubl.at(i).second) - xvec.begin();
        issou[i] = ima -1;
      //  cout << issou[i]<<endl;
    }
    SegmentTree<int> seg(issou,[](int a, int b){return max(a,b);}, 0);
    vector<int> acum(n);
    for(int i = n-1; i >=0;i--){
        ima = issou[i];
        if(ima == n-1) {
            acum.at(i) = n-1;
            seg.update(i,ima);
        }
        else{
            ima = max(ima,seg.find(i,ima+1));
            acum.at(i) = ima;
            seg.update(i,ima);
        }
    }
    vector<lli> ans(n);
    ans[n-1] = 2;
    for(int i = n-2; i>-1;i--){
        if(acum[i] == n-1) ans[i] = (ans[i+1]+1) % mod ;
        else ans[i] = (ans[i+1] + ans[acum[i]+1]) % mod ;
    }
    cout << ans[0] << endl;
    
    return 0;
}

Measured memory_bytes: 10096
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

// もっとも左にある1のpos
ll mlpos(ll bit){
    int i=63;
    for (; (bit & (1ull<<i)) == 0; i--)
        ;
    return i;
}

signed main() {
    // cout<<mlpos(0b1101)<<endl;; //=3
    // cout<<mlpos(0b0110)<<endl;; //=2
    ll n, ans=0;
    vector<ll> v;
    multiset<ull> s;
    cin>>n;
    rep(i,0,n){
        ll a;
        cin>>a;
        s.insert(a);
        v.push_back(a);
    }

    sort(begin(v),end(v),greater<ll>());
    for(auto x: v){
        auto it = s.find(x);
        if (it==end(s)){
            continue;
        }
        s.erase(it);
        ull y = (ull)(x -1) ^ ((1ull<< (mlpos(x)+1)) -1);
        // printf("%016lx %016lx\n", x, y);

        // check
        auto iy = s.find(y);
        if (iy != s.end()){
            ans++;
            // cout<<"("<<x<<","<<y<<")"<<endl;
            s.erase(iy);
            continue;
        }

        for (ll pos = mlpos(x)+1; pos<64; pos++){
            y |= 1ull<<pos;
            // printf("%016lx %016lx\n", x, y);
            auto iy = s.find(y);
            if (iy != s.end()){
                ans++;
                // cout<<"("<<x<<","<<y<<")"<<endl;
                s.erase(iy);
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int n,x,d;

  cin >> n >> d >> x;

  int a[n];
  
  for(int i=0;i < n;i++){
    cin >> a[i];
  }
  
  for(int i=0;i < n;i++){

    int day = 1;
    int sum = 0;
    
    while(day <= d)
      {
	day += a[i];
	sum++;
      }
    x += sum;
  }

  cout << x << endl;
  return 0;
}
      
  

Measured memory_bytes: 256
from collections import Counter


N, K = map(int, input().split())
A = list(map(int, input().split()))

S = [0] * (N + 1)
for i in range(N):
    S[i + 1] = (S[i] + A[i]) % K
    # S[i + 1] = S[i] + A[i]

cnt = 0
C = Counter()
for r in range(N + 1):
    R = (S[r] - r) % K
    cnt += C[R]
    C[R] += 1
    l = r - (K - 1)
    if l >= 0:
        L = (S[l] - l) % K
        C[L] -= 1

print(cnt)


Measured memory_bytes: 46856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> ldp(n), rdp(n);
    rep(i, n) {
        if (i == 0) {
            ldp[i] = a[i];
            rdp[n - 1 - i] = a[n - 1 - i];
        }
        else {
            ldp[i] = gcd(ldp[i - 1], a[i]);
            rdp[n - 1 - i] = gcd(rdp[n - 1 - (i - 1)], a[n - 1 - i]);
        }
    }
    ll ans = 1;
    rep(i, n) {
        if (i == 0) {
            ans = max(ans, rdp[i + 1]);
        }
        else if (i == (n - 1)) {
            ans = max(ans, ldp[i - 1]);
        }
        else {
            ans = max(ans, gcd(ldp[i - 1], rdp[i + 1]));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <cstdio>
using std::max;
using std::min;
using std::sort;
using std::swap;
struct rec
{
    int a, b;
    rec()
    {
        a = b = 0;
    }
    rec(int x, int y)
    {
        a = x;
        b = y;
    }
    friend bool operator<(const rec a, const rec b)
    {
        if (a.a == b.a)
        {
            return a.b < b.b;
        }
        return a.a < b.a;
    }
} a[200010];
int main()
{
    int n;
    rec mx(0, 0), mn(1e9, 1e9);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d%d", &a[i].a, &a[i].b);
        if (a[i].a > a[i].b)
        {
            swap(a[i].a, a[i].b);
        }
        mx.a = max(mx.a, a[i].a);
        mx.b = max(mx.b, a[i].b);
        mn.a = min(mn.a, a[i].a);
        mn.b = min(mn.b, a[i].b);
    }
    long long ans = 1LL * (mx.a - mn.a) * (mx.b - mn.b);
    sort(a + 1, a + n + 1);
    mx = {a[n].a, mx.b};
    mn = {1000000000, a[1].a};
    for (int i = 1; i < n; i++)
    {
        mx.a = max(mx.a, a[i].b);
        mn.a = min(mn.a, a[i].b);
        ans = min(ans, 1LL * (mx.a - min(mn.a, a[i + 1].a)) * (mx.b - mn.b));
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main() {

	int x; cin >> x;
	const int b_max = 100;
	const int p_max = 10;
	vector<int> c;
	for (int b = 1; b <= b_max; b++) {
		for (int p = 2; p <= p_max; p++) {
			c.push_back(pow(b, p));
		}
	}
	sort(c.begin(), c.end());
	int index = 0;
	int tmp;
	while (true) {
		tmp = c[index];
		if (x < tmp) break;
		index++;
	}
	cout << c[index - 1] << endl;
	return 0;
}

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var ans = "No";

            for (int i = 1;i <= 9; i++)
            {
                for(int j = 1; j <= 9; j++)
                {
                    if (n == i * j) ans = "Yes";
                }
            }

            Console.WriteLine(ans);
        
            
        }
    }
}


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

int main(){
int n,i,a[10000];

cin>>n;
for(i=1;i<=n;i++){
cin>>a[i];
}
i=n;
for(;;i--){
if(i==1){cout<<a[i];
break;}
else{cout<<a[i]<<" ";}
}

cout<<endl;
return 0;
}


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

using namespace std;

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

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

    int q;
    cin >> q;
    while (q--) {
        int op, b, e;
        cin >> op >> b >> e;
        if (op == 0) {
            cout << *min_element(vt.begin() + b, vt.begin() + e) << endl;
        } else {
            cout << *max_element(vt.begin() + b, vt.begin() + e) << endl;
        }
    }
    return 0;
}


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

TXY = []
for i in range(N):
    txy = [int(x) for x in input().split()]
    TXY.append(txy)


def solve(TXY):
    px, py, pt = 0, 0, 0
    for t, x, y in TXY:
        dt = abs(x - px) + abs(y - py) - (t - pt)
        if dt > 0 or dt % 2 == 1:
            return "No"
        px, py, pt = x - px, y - py, t - pt
    return "Yes"

print(solve(TXY))


Measured memory_bytes: 21052
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;
    static int N;
    static int[] A;
    static int[] B;

    static void input()
    {
        cin = new Scanner();
        N = cin.nextInt();
        A = new int[N];
        B = new int[N];
        A = cin.ArrayInt(N + 1);
        B = cin.ArrayInt(N);
    }
    static void solve()
    {
        input();
        long sum = 0;
        int remain = 0;
        for(int i = 0; i < N; i++)
        {
            sum += Min(A[i], B[i] + remain);
            remain = Min(Max(B[i] + remain - A[i], 0), B[i]);
        }
        sum += Min(A[N], remain);
        WriteLine(sum);
    }

    
    class Scanner
    {
        string[] s;
        int i;

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

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

        public int nextInt()
        {
            return int.Parse(next());
        }

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

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

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

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

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

Measured memory_bytes: 32188
#include<stdio.h>
#define LIM 500000
#define SENTINEL 1000000000
int cnt = 0;

void merge(int A[], int left, int middle, int right) {
  int l = middle - left;
  int r = right - middle;
  int L[l], R[r];
  for ( int i = 0; i < l; i++ ) L[i] = A[left + i];
  for ( int i = 0; i < r; i++ ) R[i] = A[middle + i];
  L[l] = R[r] = SENTINEL;
  l = r = 0;

  for ( int i = left; i < right; i++ ) {
    if ( L[l] <= R[r] ) A[i] = L[l++];
    else A[i] = R[r++];
    cnt++;
  }
}

void mergeSort(int A[], int left, int right) {
  if ( left + 1 < right ) {
    int middle = (left + right) / 2;
    mergeSort(A, left, middle);
    mergeSort(A, middle, right);
    merge(A, left, middle, right);
  }
}

int main() {
  int n, A[LIM];

  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);

  mergeSort(A, 0, n);

  for ( int i = 0; i < n; i++ ) {
    if (i) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n%d\n", cnt);

  return 0;
}


Measured memory_bytes: 6484