akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; ++i)
#define rep(i,n) for(int i = 1; i <= n; ++i)
#define boost ios::sync_with_stdio(0)
#define ms0(s) memset((s), 0, sizeof(s))
#define INF 0x3f3f3f3f
#define ABS(x) ((x)<0 ? (-(x)) : (x))
#define forvec(it,v) for(vector<int>::iterator it = v.begin(); it != v.end(); ++it)

#ifdef LOCAL
#define DEBUG 1
#else
#define DEBUG 0
#endif
#define $ if(DEBUG)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

//quick I/O
ostream& operator << (ostream& out, const pii& p){
	out << "(" << p.first << ", " << p.second << ")";
	return out;
}
template <typename T>
inline void read(T& x){
	int w = 1; T data = 0;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-') ch = getchar();
	if(ch == '-') w = -1, ch = getchar();
	while(isdigit(ch))
		data = 10 * data + ch - '0', ch = getchar();
	x = data * w;
}
template <typename T>
void write(T x){
	 if (x < 0) putchar('-'),x = ~x + 1;
	 if (x > 9) write(x / 10);
	 putchar( x % 10 + '0');
}

//debug
template<typename T>
void printvec(vector<T> vec){
	for(T v : vec) cout << ' ' << v;
	cout << '\n';
}
template<typename T>
void printset(set<T> s){
	for(auto it = s.begin(); it != s.end(); ++it)
		cout << ' ' << *it;
	cout << '\n';
}
template<typename T>
void printarray(T* p,int n){
	cout << '{';
	REP (i,n) cout << ' ' << p[i];
	cout << "}\n";
}
char s[100];
int main()
{
 	#ifdef FREOPEN
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
 		clock_t starttime = clock();
	#endif
	scanf("%s",s);
	int len =strlen(s);
	int ok = 1, coccur = 0;
	if(s[0] != 'A') return puts("WA"), 0;
	if(s[1]<'a' || s[1]>'z')return puts("WA"), 0;
	for(int i = 2; i < len - 1; ++i){
		if(s[i]<'a' || s[i] >'z'){
			if(s[i]=='C' && !coccur) coccur = 1;
			else return puts("WA"), 0;
		}
	}
	if(s[len - 1]<'a' || s[len-1] > 'z') return puts("WA"), 0;
	if(!coccur) return puts("WA"), 0;
	return puts("AC"), 0;

	#ifdef FREOPEN
		freopen("CON", "w", stdout);
		printf( "\n\n-----------------\n%ld ms are used.\n", clock() - starttime );
	#endif
	return 0;
}



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

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	char c;
	cin >> c;
	++c;
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
n = int(input())
s = list(input())
s1=[]
if( n %2 != 0):
    print("No")
    sys.exit()
else:
    for i in range(0,int(n/2)):
        a = s.pop(0)
        s1.append(a)
if(s ==s1):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        String a = new String();
        
        String b = new String();
        String c = new String();
        int d =0;
        
        while(true){
        
        a = sc.next();
        b = sc.next();
        c = sc.next();
        
        int e = Integer.parseInt(a);
        int f = Integer.parseInt(c);
        
        if("+".equals(b)){
            d = e+f;
        }
        if("-".equals(b)){
            d = e-f;
        }
        if("*".equals(b)){
            d = e*f;
        }
        if("/".equals(b)){
            d = e/f;
        }
        if("?".equals(b))break;
        
        
        
        System.out.println(d);
        }
        
    }
}



Measured memory_bytes: 26104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//const ll MOD=(ll)1e9+7;
const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

ll dp[3010][3010];
void solve(int ca){
    int N,S; cin>>N>>S;
    vector<int> a(N);
    memset(dp,0, sizeof(dp));
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
    }
    dp[0][0]=1;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= S; ++j) {
            (dp[i+1][j]+=2ll*dp[i][j])%=MOD;
            if(j+a[i]<=S){
                (dp[i+1][j+a[i]]+=dp[i][j])%=MOD;
            }
        }
    }

    cout<<dp[N][S]<<endl;



}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 74428
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
char ch[6];
cin >> s;
for(int i=0;i<6;i++)
{
ch[i]=s.at(i);
}
if(ch[2]==ch[3] && ch[4]==ch[5])
{
cout << "Yes";
}
else
{
cout << "No";
}
return 0;
}


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

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    vector<string>vs(n);
    for(int i=0;i<n;i++)
        cin>>vs[i];
    vector<vector<long long> >mtx(n+1,vector<long long>(m+1));
    long long rm=1e9+7;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(i==1&&j==1)
                mtx[1][1]=1ll;
            else{
                if(vs[i-1][j-1]=='.'){
                    mtx[i][j]=mtx[i][j-1]+mtx[i-1][j];
                    mtx[i][j]%=rm;
                }
            }

        }
    }
    cout << mtx[n][m] << endl;
    return 0;
}


Measured memory_bytes: 12940
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; ++i)

const int MAX = 3019;
const ll INF = 1e15;
int N, K;
ll dp[MAX][MAX];
int A[MAX];

ll solve(int l, int r) {
  if (l+r == N) return 0;
  if (dp[l][r] > -INF) return dp[l][r];
  if ((l+r)%2 == 0)
    dp[l][r] = max(solve(l+1, r) + A[l], solve(l, r+1) + A[N-1-r]);
  else
    dp[l][r] = min(solve(l+1, r) - A[l], solve(l, r+1) - A[N-1-r]);
  return dp[l][r];
}

int main () {
  cin >> N;
  REP (i, N) cin >> A[i];
  REP (i, MAX) REP (j, MAX) dp[i][j] = -INF;
  ll ans = solve(0, 0);
  cout << ans << endl;
}

Measured memory_bytes: 71552
// ALDS1_13_A.cpp
// Heuristic Search - 8 Queens Problem
#include <iostream>
#include <vector>
#include <stack>
#include <cstdio>
using namespace std;
const int N = 8;
vector<int> row(N);
vector<int> col(N);
vector<int> md(2*N - 1); // main diagonal
vector<int> ad(2*N - 1); // anti-diagnoal
vector<int> res(N);
//vector<int> flag(N);
int main()
{
    int k;
    cin >> k;
    int r, c;
    for (int i = 0; i < k; i++) {
        cin >> r >> c;
        row[r] = 1;
        col[c] = 1;
        md[r+c] = 1;
        ad[c-r+N-1] = 1;
        res[r] = c;
    }
    stack<pair<int, int> > ms;
    bool found = true;
    r = 0;
    c = 0;
    while (r < N) {
        if (row[r]) {
            r++;
            continue;
        }
        if (c < N) {
            if (col[c] || md[r+c] || ad[c-r+N-1]) {
                c++;
            }
            else {
                ms.push({r, c});
                res[r] = c;
                col[c] = 1;
                md[r+c] = 1;
                ad[c-r+N-1] = 1;
                r++;
                c = 0;
            }
        }
        else {
            if (ms.empty()) {
                found = false;
                break;
            }
            r = ms.top().first;
            c = ms.top().second;
            ms.pop();
            col[c] = 0;
            md[r+c] = 0;
            ad[c-r+N-1] = 0;
            c++;
        }

    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (res[i] == j) printf("Q");
            else printf(".");
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 3108
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	n := len(s)

	if n == 1 {
		fmt.Println(1)
		return
	}
	if n == 2 {
		if s[0] != s[1] {
			fmt.Println(2)
		} else {
			fmt.Println(1)
		}
		return
	}

	ans := 0
	prev := byte('A')
	for i := 0; i < n; i++ {
		if now := s[i]; now != prev {
			prev = now
		} else {
			if i == n-1 {
				break
			}
			i++
			prev = 'A'
		}
		ans++
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1920
import java.util.Scanner;
import java.util.HashMap;
public class Main {
    static HashMap<String, Integer> romanMap;
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	romanMap = new HashMap<String, Integer>();
	String[] romanArray = {"I", "V", "X", "L", "C", "D", "M"};
	int[] arabianArray = {1, 5, 10, 50, 100, 500, 1000};
	for (int i = 0; i < 7; i++) {
	    romanMap.put(romanArray[i], arabianArray[i]);
	}

	String roman;
	while (scan.hasNext()) {
	    roman = scan.nextLine();
	    System.out.println(solv(roman));
	}
    }

    static int solv (String roman) {
	int prev, now, sum = 0;
	prev = romanMap.get(roman.substring(0, 1));
	sum += prev;
	for (int i = 1; i < roman.length(); i++) {
	    now = romanMap.get(roman.substring(i, i + 1));
	    if (now > prev) {
		now -= prev;
		sum -= prev;
	    }
	    sum += now;
	    prev = now;
	}
	return sum;
    }
}

Measured memory_bytes: 25944
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

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;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int a, b, c;cin >> a >> b >> c;
  int tmp;
  bool f = true;
  while(true){
    f = true;
    if(a > b){
        tmp = b;
        b = a;
        a = tmp;
        f = false;
    }
    if(b > c){
        tmp = c;
        c = b;
        b = tmp;
        f = false;
    }
    if(f){
        break;
    }
  }
  cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long h, n, sum;
  cin>>h>>n;
  sum = 0;
  vector<long long> vec(n, 0);
  for(int i = 0; i < n; ++i)cin>>vec[i];
  for(int i = 0; i < n; ++i)sum += vec[i];
  if(sum >= h){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 1024
n,h = map(int,input().split())
a = []
b = []
for i in range(n):
    ai,bi = map(int,input().split())
    a.append(ai)
    b.append(bi)
a.sort(reverse=True)
b.sort(reverse=True)
ans = 0
damage = 0
for i in b:
    if i > a[0]:
        damage += i
        ans += 1
        if damage >= h:
            print(ans)
            exit()
h -= damage
print(ans + (h+a[0]-1)//a[0])

Measured memory_bytes: 11348
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int x, y;
	cin >> x>> y;
	y /= 2;
	cout << x + y << endl;
}   

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A <= 5) cout << 0 << endl;
  else if (A <= 12) cout << B / 2 << endl;
  else cout << B << endl;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve(long long H, long long W, long long N, std::vector<long long> a){
    VI li;
    REP(i, N){
        REP(j,a[i]){
            li.PB(i+1);
        }
    }
    VI out;
    bool flag=true;
    REP(i,li.size()){
        out.PB(li[i]);
        if(out.size()==W){
            if(flag){
                flag= false;
                REP(j, out.size()){
                    cout<<out[j]<<" ";
                }cout<<endl;
            }
            else{
                flag=true;
                REP(j, out.size()){
                    cout<<out[W-j-1]<<" ";
                }cout<<endl;
            }
            out.clear();
        }
    }
    return;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(H, W, N, std::move(a));
    return 0;
}


Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)
var countFive, countSeven int

func main() {
  var x, y, z int 

  fmt.Scan(&x, &y, &z)
  
  count(x)
  count(y)
  count(z)
  
  if countFive == 2 && countSeven == 1 {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

func count(num int) {
  if num == 5 {
    countFive++
  } else if num == 7 {
    countSeven++
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int>v;
	for (int i = 0; i<n; i++) {
		int vi; cin >> vi;
		v.push_back(vi);
	}
	cin >> n;
	for (int i = 0; i<n; i++) {
		int p; cin >> p;
		auto t1 = lower_bound(v.begin(), v.end(), p), t2=upper_bound(v.begin(), v.end(), p);
		cout << t1 - v.begin() << ' ' <<t2-v.begin()<< endl;
	}
	return 0;
}


Measured memory_bytes: 3552
#include <iostream>
#include <sstream>
#include <fstream>

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>

#include <algorithm>
#include <numeric>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
// #include <unordered_map>
#include <set>
#include <utility>
#include <bitset>
#include <limits>
#include <climits>
using namespace std;

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 11
char _buf[INTSPACE*100000 + 3];  // ここ要確認

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}
int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

ll solve(int N, vector<int>& a, vector<int>& b, vector<int>& c) {
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));
    // vector<ll> aa(N+1); aa[0] = 0;

    ll ac = 0LL;
    vector<pair<int,ll>> bx(N+1);
    bx[0] = make_pair(-1, 0LL);

    rep(i, N) {
        int bj = lower_bound(ALL(a), b[i]) - a.begin();
        ac += bj;
        bx[1+i] = make_pair(b[i], ac);
    }
    // cout << bx << endl;

    ll ans = 0LL;
    rep(i, N) {
        int cj = lower_bound(ALL(bx), make_pair(c[i], -1LL)) - bx.begin();
        // printf("%d %d %lld\n", i, cj, bx[cj-1].second);
        ans += bx[cj-1].second;
    }
    return ans;
}
int main() {
    int N = loadint();
    vector<int> a(N), b(N), c(N);
    loadvec(a, N);
    loadvec(b, N);
    loadvec(c, N);
    ll ans = solve(N, a, b, c);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4600
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    double r = in.nextDouble();
     
    double square = Math.PI * r * r ;
    double perimeter = Math.PI * 2 * r;
    
    System.out.printf("%5.6f", square);
    System.out.printf(" %5.6f\n", perimeter);
  }
}

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

int main(){

    int N;
    cin >> N;

    vector<int> ans;
    for(int n = 11; n <= 55555; n += 10){
        bool prime = true;
        for(int i = 2; i < n; i++){
            if(n % i == 0){
                prime = false;
                break;
            }
        }
        if(prime) ans.push_back(n);
        if(ans.size() == N) break;
    }

    for(int i = 0; i < N; i++) cout << ans[i] << " "; cout << endl;

    return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    while (n--) {
        double x1, x2, x3, x4, y1, y2, y3, y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        if (abs((x4 - x3) * (y2 - y1) - (x2 - x1) * (y4 - y3)) < 1e-10) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1224
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V vec(n);
    set<ll> st;
    rep(i,n){
        cin>>vec[i];
        st.insert(vec[i]);
    }
    sort(all(vec));
    ll prev=vec[0];
    ll temp=1;
    ll even=0;
    rep3(i,1,n){
        if(prev==vec[i]){
            temp++;
        }else{
            if(temp%2==0){
                even++;
            }
            temp = 1;
            prev = vec[i];
        }
    }
    if(temp>0&&temp%2==0){
        even++;
    }
    if(even%2==1){
        cout << st.size() - 1 << endl;
    }else{
        cout << st.size() << endl;
    }
}


Measured memory_bytes: 5760
#include <cstdio>
#include <cstring>
#include <set>

using namespace std;

int edge[300000],nxt[300000],first[300000];
int d[300000],e[300000],g[300000];
int i,m,n,x,y,head,tail,sum_edge;

inline void addedge(int x,int y)
{
	sum_edge++,edge[sum_edge]=y,nxt[sum_edge]=first[x],first[x]=sum_edge;
	return;
}

int main()
{
	scanf("%d%d",&n,&m);
	for (i=1;i<n+m;i++)
		scanf("%d%d",&x,&y),addedge(x,y),d[y]++;
	for (i=1;i<=n;i++)
		if (! d[i])
			tail++,g[tail]=i;
	for (head=1;head<=tail;head++)
	{
		for (i=first[g[head]];i!=0;i=nxt[i])
		{
			d[edge[i]]--;
			if (! d[edge[i]])
				tail++,g[tail]=edge[i],e[g[tail]]=g[head];
		}
	}
	for (i=1;i<=n;i++)
		printf("%d\n",e[i]);
	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
 
int n;
char a[1000];
int b[1000];
bool flg[1000];
 
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  int ans=0;
  while(1){
    int id=-1;
    for(int i=0;i<n;i++){
      if(flg[i]||a[i]=='n')continue;
      if(id==-1||b[i]<b[id])id=i;
    }
    if(id==-1)break;
    ans++;
    int l=id,r=id;
    while(0<=l-1&&(a[l-1]=='y'||b[l-1]<b[id]))l--;
    while(r+1<n&&(a[r+1]=='y'||b[r+1]<b[id]))r++;
    for(int i=l;i<=r;i++)flg[i]=true;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3120
R,C,K=map(int,input().split())
G=[[0]*(C+1) for i in range(R+1)]
for i in range(K):
    r,c,v=map(int,input().split())
    G[r][c]=v
dp=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
    d1,d2,d3=0,0,0
    for j in range(1,C+1):
        v=G[i][j]
        if v!=0:
            if d2!=0:
                d3=max(d3,d2+v)
            if d1!=0:
                d2=max(d2,d1+v)
            d1=max(dp[i-1][j]+v,d1)
        else:
            d1=max(dp[i-1][j],d1)
        dp[i][j]=max(d1,d2,d3)
print(dp[R][C])


Measured memory_bytes: 217128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n,l;cin>>n>>l;
  vector<string> c(n);
  rep(i,n)cin>>c[i];
  sort(c.begin(),c.end());
  string s;
  rep(i,n){
    s+=c[i];
  }
  cout<<s<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(min(b,d)-max(a,c),0)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include <iomanip>
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007

double dp[3001][3001] = {};




double rec(double p[] , int idx , int heads, int tails){
	//if(heads<=tails)return INT_MIN;
	if(idx<0 && heads>tails){
		return (double)1;
	}
	else if(idx<0) return (double)0;

	return p[idx] * rec(p,idx-1,heads+1,tails) + (1-p[idx]) * rec(p,idx-1, heads,tails+1);
}	



int main(){
	memset(dp,0,sizeof(dp));
	int n;
	cin >> n;
	double p[n];
	for(int i=0; i <  n ; ++i){
		cin >> p[i];
	}
	
	//cout << rec(p, n-1, 0,0) << endl;
	dp[0][0] = 1-p[0];
	dp[0][1] = p[0];

	for(int i=1; i <n ; ++i ){
		dp[i][0] = dp[i-1][0] * (1-p[i]);
	}

	for(int i=1;i<n ; ++i){
		for(int j=1;j<=i+1 ; ++j){
			dp[i][j] = p[i]*dp[i-1][j-1] + (1-p[i])* (dp[i-1][j]);
		}
	}
	double ans = 0.0;
	for(int i=n/2 +1 ;i<=n ; ++i){
		ans+= dp[n-1][i];
	}
	cout << setprecision(10);
	cout << ans << endl;

}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



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

    s.pop_back();

    for(;;){
        int size = s.size();
        if(size%2==0){
            string a = s.substr(0,size/2);
            string b = s.substr(size/2,size/2);

            if(a==b){
                cout << size << endl;
                break;
            }
        }

        
        s.pop_back();
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

ll n, m;
string s;
ll a[200005];
vector<ll> ve[200005];
ll A[200005], B[200005];
bool v[200005];
bool vv[200005];
queue<ll> qu;

int main()
{
    scanf("%lld%lld", &n, &m);
    cin>>s;
    for(ll i = 0; i < n; i++)
    {
        a[i + 1] = (s[i] == 'A');
    }
    for(ll i = 0; i < m; i++)
    {
        ll t1, t2;
        scanf("%lld%lld", &t1, &t2);
        ve[t1].push_back(t2);
        ve[t2].push_back(t1);
    }
    for(ll i = 1; i <= n; i++)
    {
        for(ll j = 0; j < ve[i].size(); j++)
        {
            if(a[ve[i][j]] == 1) A[i]++;
            else B[i]++;
        }
        if(A[i] == 0 || B[i] == 0) v[i] = true, qu.push(i);
    }
    while(!qu.empty())
    {
        ll t = qu.front();
        qu.pop();
        for(ll j = 0; j < ve[t].size(); j++)
        {
            if(v[ve[t][j]]) continue;
            if(a[t] == 1) A[ve[t][j]]--;
            else B[ve[t][j]]--;
            if(A[ve[t][j]] == 0 || B[ve[t][j]] == 0)
            {
                if(!v[ve[t][j]]) v[ve[t][j]] = true, qu.push(ve[t][j]);
            }
        }
    }
    for(ll i = 1; i <= n; i++)
    {
        if(!v[i])
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


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

int main() {
	int n, i;
	double a = 100000;
	cin >> n;
	for (i = 0; i<n; i++) {
		a *= 1.05;
		ceil(a);
		while ((int)a % 1000 != 0) {
			a += 1;
		}
	}
	cout << (int)a << endl;
}

Measured memory_bytes: 1160
s,t=input(),input()
ans=len(t)
"""
s[x]から、t文字分探索。tと一致しない箇所があればtmpをプラス。
tmpの合計は直さなくてはいけない文字の数だから、tmpの各合計の中で最も小さい数が答え。
"""
for x in range(len(s)-len(t)+1):
    tmp=0
    for y in range(len(t)):
        if s[x+y]!=t[y]:
            tmp+=1
    ans=min(ans,tmp)        
print(ans)

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

int main(){
	long long k,a,b;
	cin >> k >> a >> b;
	long long ans = k+1;
	if (k>=a+1)
	ans=max(ans,b+(b-a)*((k-a-1)/2)+(k-a-1)%2);
	cout << ans;
}

Measured memory_bytes: 256
/*
                                                  
  _|_|                              _|  _|    _|  
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|    
_|    _|  _|_|          _|          _|  _|_|      
_|    _|  _|          _|      _|    _|  _|  _|    
  _|_|    _|        _|_|_|_|    _|_|    _|    _|  
                                                                                                    
*/ 
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn=2150;
int n;
struct Flow{
	int s,t,relay[5],cnt,head[maxn],cur[maxn];
	queue<int>q;
	bool vis[maxn];
	ll ans,inf,dis[maxn];
	struct gg{
		int u,v,w,cost,next;
	}side[(maxn*5+1000)*2];
	Flow(){s=maxn-2,t=maxn-1;for(int i=3;i<=6;i++)relay[i-2]=maxn-i;cnt=1;ans=0;inf=1e18;}
	void ins(int u,int v,int w,int cost){
	//	cout<<u<<' '<<v<<' '<<w<<' '<<cost<<endl;
		side[++cnt]=(gg){u,v,w,cost,head[u]};head[u]=cnt;
		side[++cnt]=(gg){v,u,0,-cost,head[v]};head[v]=cnt;
	}
	bool spfa(){
		while(!q.empty())q.pop();memset(vis,0,sizeof(vis));memset(dis,0x3f,sizeof(dis));
		dis[s]=0;vis[s]=1;q.push(s);
	
		while(!q.empty()){
			int u=q.front();q.pop();vis[u]=0;//cout<<u<<endl;
			for(int i=head[u];i;i=side[i].next){
				int v=side[i].v;if(!side[i].w)continue;
				if(dis[u]+side[i].cost<dis[v]){
				
					dis[v]=dis[u]+side[i].cost;
					if(!vis[v])vis[v]=1,q.push(v);
				}
			}
		}
	//	rep(i,1,2*n)cout<<i<<' '<<dis[i]<<endl;
	//	rep(i,1,4)cout<<"relay"<<i<<' '<<dis[relay[i]]<<endl;
		return (dis[t]<inf);
	}
	int dfs(int u,ll flow){
		if(u==t)return flow;
		vis[u]=1;int tot=0;
		for(int &i=cur[u];i;i=side[i].next){
			int v=side[i].v;if(vis[v]||dis[v]!=dis[u]+side[i].cost||!side[i].w)continue;
			int sent=dfs(v,min(flow,(ll)side[i].w));
			side[i].w-=sent;side[i^1].w+=sent;tot+=sent;flow-=sent;
			ans+=1ll*sent*side[i].cost;
		}
		return tot;
	}
	int dinic(){
		int maxflow=0;	
		while(spfa()){
			memcpy(cur,head,sizeof(cur));memset(vis,0,sizeof(vis));
			maxflow+=dfs(s,inf);
		}
		return maxflow;
	}
}f;

int main(){
	scanf("%d",&n);
	rep(i,1,n){
		int rx,ry,rc;scanf("%d%d%d",&rx,&ry,&rc);f.ins(f.s,i,rc,0);
		f.ins(i,f.relay[1],rc,rx+ry);
		f.ins(i,f.relay[2],rc,rx-ry);
		f.ins(i,f.relay[3],rc,-rx+ry);
		f.ins(i,f.relay[4],rc,-rx-ry);
	}
	rep(i,1,n){
		int rx,ry,rc;scanf("%d%d%d",&rx,&ry,&rc);f.ins(i+n,f.t,rc,0);
		f.ins(f.relay[1],i+n,rc,-rx-ry);
		f.ins(f.relay[2],i+n,rc,-rx+ry);
		f.ins(f.relay[3],i+n,rc,rx-ry);
		f.ins(f.relay[4],i+n,rc,+rx+ry);
	}
	f.dinic();
	printf("%lld",-f.ans);
	return 0;
}


Measured memory_bytes: 4204
#子ども　N人
# 1人目に1個、2人目に2個・・・　N人めにはN個
#必要なキャンディーの合計を求める

#N=2の時　1+2=3
#N=3の時　1+2+3=6
#N=4の時　1+2+3+4=10

#N=10の時　55

N=int(input())
#個数に対してのキャンディーの合計を示す
sum_candy=(N * (N+1) / 2)
print(int(sum_candy))




Measured memory_bytes: 9028
import sys
import os

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.buffer.readline().rstrip())
    print('Hello World') if N == 1 else print(sum(int(sys.stdin.buffer.readline().rstrip()) for _ in range(2)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int n, m; cin >> n >> m;
    vector<int> c(m);
    rep(i, m) cin >> c[i];
    sort(c.begin(), c.end());

    vector<int> dp(n+1, 2*n);
    dp[0] = 0;
    FOR(i, 1, n+1) {
        rep(j, m){
            int idx = i - c[j];
            if (idx > -1) chmin(dp[i], dp[idx] + 1);
        };
    };

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



Measured memory_bytes: 3176
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

int solve(int n, V& as){
    sort(as.begin(), as.end());
    as.erase(unique(as.begin(), as.end()), as.end());
    return as.size() - (n - as.size()) % 2;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

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

    cout << solve(n, as) << endl;

    return 0;
}


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

int main() {
	ll h,w,H[2005][2005],W[2005][2005];
	char a[2005][2005];
	cin>>h>>w;
	for(int i=0;i<2005;i++){
		for(int j=0;j<2005;j++){
			a[i][j]='@';
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a[i][j];
		}
	}
	for(int I=0;I<h;I++){
		for(int i=0;i<w;i++){
			ll sum=0,j=i;
			while(a[I][j]=='.'){
				sum++;
				j++;
			}
			for(int k=i;k<j;k++){
				H[I][k]=sum;
			}
			i=j;
		}
	}
	for(int I=0;I<w;I++){
		for(int i=0;i<h;i++){
			ll sum=0,j=i;
			while(a[j][I]=='.'){
				sum++;
				j++;
			}
			for(int k=i;k<j;k++){
				W[k][I]=sum;
			}
			i=j;
		}
	}
	ll ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			ans=max(ans,W[i][j]+H[i][j]);
		}
	}
	cout << ans-1;
}

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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    int N=in();
    int M=in();
    int a,b;
    unordered_map<int,vector<int>> mp;
    REP(i,M){
        cin>>a>>b;
        mp[a].push_back(b);
    }
    //debug(mp[1][1]);
    for(int i=0;i<mp[1].size();i++){
        //debug(mp[1][i]);
        for(int j=0;j<mp[mp[1][i]].size();j++){
        if(mp[(mp[1][i])][j]==N){
            print("POSSIBLE");
            return 0;
        }
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;

}

Measured memory_bytes: 15168
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#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 p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll howManyDevide(ll n){
    ll count = 0;
    while(n%2 == 0){
        n /= 2;
        count++;
    }
    return count;
}

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

    // input
    ll N;
    cin >> N;

    ll sum = 0;
    FOR(i, 0, N){
        ll a;
        cin >> a;
        sum += howManyDevide(a);
    }

    p(sum);
    
    return 0;
}

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

using namespace std;

int main(){
    int n,w[100],ws[100],sum = 0;
    cin >> n;
    for (int i =0;i<n;i++){
        cin >> w[i];
        sum += w[i];
    }
    ws[0] = w[0];
    for (int i = 1;i<n;i++){
        ws[i] = ws[i-1] + w[i];
    }
    for (int i = 0;i<n;i++){
        if(sum > 2*ws[i]){
            ws[i] = sum - 2*ws[i];
        }
        else{
            ws[i] = 2*ws[i] -sum;
        }
    }
    sort(ws,ws+n-1);
    cout << ws[0] <<endl;
}

Measured memory_bytes: 256
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

N,K = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]

ans = 0
for h in H:
    if h >= K:
        ans += 1

print(ans)

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

using namespace std;
using ll = long long;

template <typename T>
T gcd(T a, T b) { return (a % b == 0 ? b : gcd(b, a % b)); }

int main() {
	int N;
	cin >> N;
	vector<ll> a(N + 1);
	for (int i = 1; i <= N; ++i) { cin >> a[i]; }

	vector<ll> dl(N + 1, 0);
	dl[1] = a[1];
	for (int i = 2; i <= N; ++i) {
		dl[i] = gcd(dl[i - 1], a[i]);
	}
	vector<ll> dr(N + 1, 0);
	dr[N] = a[N];
	for (int i = N - 1; i >= 1; --i) {
		dr[i] = gcd(dr[i + 1], a[i]);
	}

	ll res = max(dl[N - 1], dr[2]);
	for (int i = 2; i <= N - 1; ++i) {
		res = max(res, gcd(dl[i - 1], dr[i + 1]));
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
int Search(int *,int, int);

int main(){
 int S[100000],T[50000];
    int n,q,i,count=0;

    scanf("%d",&n);

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

    scanf("%d",&q);

    for(i=0;i<q;i++) {
        scanf("%d",&T[i]);
        if(Search(S,n,T[i])==1) count++;
    }

    printf("%d\n",count);

    return 0;
}

int Search(int *A,int n,int key){
    int left=0,middle=0,right=0;
    right=n;

    while(left<right){
        middle=(left+right)/2;
        if(A[middle]==key) return 1;
        if(A[middle]<key) left=middle+1;
        else if(A[middle]>key) right=middle;
    }
    return 0;
}


Measured memory_bytes: 2308
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    rep(i, k) {
        if ( i & 1 ) {
            if ( b & 1 ) {
                --b;
            }
            a += b / 2;
            b /= 2;
        } 
        else {
            if ( a & 1 ) {
                --a;
            }
            b += a / 2;
            a /= 2;
        }
    }

    cout << a << " " << b << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		int H, W, i, j;
		
		Scanner scan = new Scanner(System.in);
		
		while(true) {
			
			H = scan.nextInt();
			W = scan.nextInt();
			
			for(i = 0; i < H; i++) {
				for(j = 0; j < W; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			
			if(H == 0 && W == 0) break;
			
			System.out.println();
			
		}
		
	}

}


Measured memory_bytes: 33204
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
const int MAXN = 200100;

int N;
ll K;
int arr[MAXN];
int nocc[MAXN];
ll njump[MAXN][60];

set <int> sv;
vector <int> ans;

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

    cin >> N >> K;
    for (int i = 0; i < N; i++)
        cin >> arr[i];
    for (int i = 0; i < MAXN; i++)
        nocc[i] = 1e9;

    for (int i = 2 * N - 1; i >= 0; i--)
    {
        if (i < N)
            njump[i][0] = (nocc[arr[i]] + 1 - i);
        nocc[arr[i%N]] = i;
    }

    for (int i = 1; i < 60; i++)
    {
        for (int j = 0; j < N; j++)
        {
            ll x = njump[j][i-1];
            njump[j][i] = min ((ll) 1e18, x + njump[(j+x)%N][i-1]);
        }
    }

    ll ctot = 0;
    int cloc = 0;
    for (int i = 59; i >= 0; i--)
    {
        if (njump[cloc][i] + ctot <= N * K)
        {
            ctot += njump[cloc][i];
            cloc = (cloc + njump[cloc][i]) % N;
        }
    }

    sv.clear();
    //cout << ctot << " " << N * K << endl;
    while (ctot < N * K)
    {
        int nv = arr[ctot % N];
        //cout << nv << endl;
        if (sv.find(nv) == sv.end())
        {
            ans.push_back(nv);
            sv.insert(nv);
        }
        else
        {
            while (sv.find(nv) != sv.end())
            {
                sv.erase(ans.back());
                ans.pop_back();
            }
        }
        ctot++;
    }

    for (int i = 0; i < ans.size(); i++)
    {
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << "\n";
}

Measured memory_bytes: 106996
a,b,c,x,y = map(int,input().split())

piza_min = min(x,y)

plan1 = c*piza_min*2 + a*(x-piza_min) + b*(y-piza_min)
plan2 = a*x + b*y
plan3 = c*max(x,y)*2

print(min(plan1,plan2,plan3))

Measured memory_bytes: 9188
#include <stdio.h>
int parent(int);
int left(int);
int right(int);

int main(){
  int i,H,A[251];

  scanf("%d",&H);

  for(i=1; i<=H; i++)
    scanf("%d",&A[i]);

  for(i=1; i<=H; i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) >= 1)
      printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= H)
      printf("left key = %d, ",A[left(i)]);
    if(right(i) <= H)
      printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }

  return 0;
}

int parent(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}

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

int main(){
  int N; cin >> N;
  vector<long long> a(N),b(N);
  for(int i=0; i<N; i++) cin >> a[i];
  for(int i=0; i<N; i++) cin >> b[i];
  
  // sum(b)-sum(a) 回の試行
  long long total=0;
  for(int i=0; i<N; i++){
    total-=a[i];
    total+=b[i];
  }
  
  //最低限の試行回数
  vector<long long> u(N,0),v(N,0);
  for(int i=0; i<N; i++){
    if(a[i]<b[i]){
      long long k=b[i]-a[i];
      if(k%2==0){
        a[i]+=k;
        u[i]+=k/2;
      }else{
        a[i]+=k+1;
        u[i]+=(k+1)/2;
        b[i]+=1;
        v[i]+=1;
      }
    }else if(a[i]>b[i]){
      long long k=a[i]-b[i];
      b[i]+=k;
      v[i]+=k;
    }
  }
  
  //今のところa=b
  //uが多い-->bに差分u-vをばらまく-->同じだけ試行をしてa=bに戻せる
  //         最終試行回数はv+2(u-v)
  //vが多い-->aに差分v-uをばらまいても無理
  //同じ-->それが最終試行回数
  long long usum=0,vsum=0;
  for(int i=0; i<N; i++) usum+=u[i];
  for(int i=0; i<N; i++) vsum+=v[i];
  if(vsum>usum){
    cout << "No" << endl;
  }else{
    if(total==(2*usum-vsum)){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(void)
{
	long long n, k;

	scanf("%lld %lld", &n, &k);

	printf("%lld", min(n % k, (-n + (n % k ? n / k + 1 : n / k) * k) % k));
	return 0;
}

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

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

  string s;
  cin >> s;
  int ans = 0;

  int rock = 0, paper = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'g') rock++;
    if (s[i] == 'p') paper++;
    while (paper > rock) {
      paper--;
      rock++;
      ans--;
    }
    if (s[i] == 'g') {
      if (paper + 1 <= rock - 1) {
        ans++;
        paper++;
        rock--;
      }
    }
  }

  cout << ans << "\n";
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main(){
	int t,n,s,f;
	int st;
	while(1){
		cin>>t;
		if(t==0) break;
		cin>>n;
		st=0;
		for(int i=0;i<n;i++){
			cin>>s>>f;
			st+=f-s;
		}
		if(st>=t) cout<<"OK"<<endl;
		else cout<<t-st<<endl;
	}
}

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(int i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

const int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 60;
const ll mod = 998244353;



struct Segment_tree {
	using T = ll;

	int n;
	vector<T> data;
	const T out = 0;

	inline T vmerge(T l, T r) { return max(l, r); }

	Segment_tree(int n) :n(n) { data.assign(2 * n, out); }

	void update(int p, T x) {  // set value at position p
		for (data[p += n] = x; p > 1; p >>= 1) {
			data[p >> 1] = vmerge(data[p], data[p ^ 1]);
		}
	}

	T query(int l, int r) {  // sum on interval [l, r)
		T resl = out, resr = out;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) resl = vmerge(data[l++], resl);
			if (r & 1) resr = vmerge(resr, data[--r]);
		}
		return vmerge(resl, resr);
	}
};


int main(){

	int n, k;
	cin >> n >> k;

	VI a(n);
	REP(i, n)cin >> a[i];

	Segment_tree s(300005);
	int MAX = 300001;

	int ans = 0;

	REP(i, n) {
		int j = s.query(max(0, a[i] - k), min(MAX, a[i] + k) + 1);
		s.update(a[i], j + 1);
		ans = max(ans, j + 1);
	}
	cout << ans << endl;


}

Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h, w;
    cin >> h >> w;
    map<int, int> m;
    multiset<int> v;
    for(int i = 0; i < w; i++)
        m[i] = i;
    for(int i = 0; i < w; i++)
        v.insert(0);
    for(int i = 0; i < h; i++){
        int a, b;
        cin >> a >> b;
        a--;
        auto it = m.lower_bound(a);
        int mm = -1;
        while(it != m.end() && it->first <= b){
            mm = max(mm, it->second);
            int x = it->first - it->second;
            v.erase(v.find(x));
            m.erase(it++);
        }
        if(mm != -1 && b < w){
            v.insert(b - mm);
            m[b] = mm;
        }
        int ans = -1;
        if(v.size() > 0)
            ans = *v.begin() + (i + 1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 22352