akhauriyash/Code-Regression huggingface dataset:
/*

Author: @karngyan
Team: BlundersPride

*/

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

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 1e5+10;
ll n , k;
ll a[310];
ll dp[N];
ll go(ll i)
{

	if( i == 0 )
		return 0;
	ll &ans = dp[i];
	if(ans != -1)
		return ans;
	ans = 0;
	//from current position to any losing position
	//then curret position is winning
	for(ll j = 0 ; j<n ; ++j)
	{
		if(i - a[j] >= 0)
			if(go(i - a[j]) == 0)
				ans = 1;
	}
	return ans;
}
signed main()
{
	fast;
	memset( dp , -1 , sizeof dp);
////////////////////////////////////////////////////////////////////////////////////////////
	
	cin >> n >> k;
	rep(i,0,n)
		cin >> a[i];


	char ans[][20] = {"Second","First"};
	cout<<ans[go(k)]<<endl;



////////////////////////////////////////////////////////////////////////////////////////////
	
	return 0;
}


Measured memory_bytes: 4224
import java.io.*;
import java.util.Scanner;
public class Main{
    public static void main(String argsp[]){
        int x, y, s, p1, p2, max;
        Scanner sc=new Scanner(System.in);
        while (true){
            x=sc.nextInt();
            y=sc.nextInt();
            s=sc.nextInt();
            if (x==0&&y==0&&s==0) break;
            max=0;
            for (int i=1;i<s;i++){
            for (int j=1;j<s;j++){
                p1=i*(100+x)/100;
                p2=j*(100+x)/100;
                if (p1+p2==s){
                    p1=i*(100+y)/100;
                    p2=j*(100+y)/100;
                    if (p1+p2>max) max=p1+p2;
                    break;
                }
            }
        }
        System.out.println(max);
        }
    }
}

Measured memory_bytes: 29188
#include<iostream>

using namespace std;

void sort(int data[]) {
    for(int i = 0; i < 9; i++) {
        for(int j = i; j < 10; j++) {
            if(data[i] < data[j]) {
                int tmp = data[i];
                data[i] = data[j];
                data[j] = tmp;
            }
        }
    }
}

int main(void) {
    int i, hills[10];

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

    sort(hills);

    for(int i = 0; i < 3; i++) {
        cout << hills[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define loop(i,a,b) for(i=a;i<b;i++)
#define ms(a,b) memset(a,b,sizeof(a))
#define X first
#define Y second
#define pb(a) push_back(a)
#define pf(a) push_front(a)


using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long large;

int arr[100010];

int main(){
  int i,suma,N,E,W,S;
  large cont,tmp;
  scanf("%d",&N);
  cont =0; tmp=0;
  loop(i,1,N+1){
    scanf("%d",&arr[i]);
  }
  loop(i,1,N){
    cont+=arr[i]/2;
    tmp = arr[i]%2;
    if(arr[i+1]!=0)arr[i+1]+=tmp;
    //printf("%d %lld\n",arr[i],cont);
  }
  cont+=arr[N]/2;
  printf("%lld\n",cont);
  return 0;
}


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


#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int N = 2e5 + 10;


using namespace std;

int main()
{



	IOS;

	string s,ans;

	cin >> s;

    loop(i,s.length())

    {
    	if(s.at(i) != 'B')
    	{
    		ans.push_back(s.at(i));
    	}

    	else if (ans.size() > 0)
    	{
    		ans.pop_back();
    	}
    }


    cout<<ans<<endl;
	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int D=10;
int Min=1000000;
vector<int> p(D+1,0);
vector<int> c(D+1,0);
vector<int> B(D+1,0);

void dfs(int i,int count,long int score,vector<int> B){
    if(i == D+1){
        int j;
        for(j=D;j>=1;j--){
            if(B[j] != 1) break;
        }
        if((p[j]-1)*100*j >= score){
            if(score <= 0);
            else if(score%(100*j) != 0)count += score/(100*j) + 1;
            else count += score/(100*j);
            if(count < Min) Min = count;
        }
    }else{
        B[i] = 1;
        dfs(i+1,count + p[i],score - p[i]*100*i - c[i],B);
        B[i] = 0;
        dfs(i+1,count,score,B);
    }
    return;
}

int main(){
    long int G;
    int count = 0;
    cin >> D;
    cin >> G;
    for(int i=1;i<=D;i++){
        cin >> p[i] >> c[i];
    }
    dfs(1,count,G,B);
    cout << Min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
    long long int L,R;
    cin >> L >> R;
    if( L-R >= 2018){
        cout << 0 << endl;
        return 0;
    }
    int out = 10000;
    for(long long int i=L; i< R+1;i++){
        for(long long int j=i+1; j <R+1; j++){
            int tmpout = (i*j)%2019;
            if (out > tmpout){
                out=tmpout;
                if(out == 0){
                    cout << 0 <<endl;
                    return 0;
                }
            }
        }
    }
    cout<<out<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
ll INF = 1000000007;


/***************/
 #define amin main
/***************/

ll exp(ll x, ll n)
{if(n==0) return 1;if(n==1) return x%INF;if(n%2==0) return exp((x*x)%INF,n/2); else return(x*exp((x*x)%INF,n/2))%INF;}


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j;

	ll n;
	cin>>n;
	ll arr[n];
	ll sum = 0;
	for(i=0;i<n;i++)
		{
			cin>>arr[i];
			sum = sum^arr[i];
		}
		vector<ll>ans;
	for(i=0;i<n;i++)
		{
			ans.pb(sum^arr[i]);
		}
		for(i=0;i<ans.size();i++)
		{
			cout<<ans[i]<<" ";
		}
		cout<<endl;
	
	


	
	

	
	


	
	return 0;
}

Measured memory_bytes: 6852
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int n;
int main(){
    string s;
    cin>>s;
    int wrongs0=0;
    int wrongs1=0;
    for(int i=0;i<s.size();i++){
        if(i%2){
            wrongs0+=(s.at(i)=='1');
        }
        else{
            wrongs0+=(s.at(i)=='0');
        }
    }
    for(int i=0;i<s.size();i++){
        if(i%2){
            wrongs1+=(s.at(i)=='0');
        }
        else{
            wrongs1+=(s.at(i)=='1');
        }
    }
    cout<<min(wrongs0,wrongs1)<<endl;
    return 0;
}




Measured memory_bytes: 512
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
  int n = sc.nextInt();
  int[] ints = new int[1001];
  for (int i=2;i < n+1;i++){
    int y = 2;
    int z = i;
    while(z > 1){
      if(z%y==0){
        z/=y; 
        ints[y]++;
      }
      else if(z%y!=0)y++;
    }
  }
  long ans = 1;
  for(int i=1;i<1001;i++){
    if (ints[i]!=0) {ans = ans*(ints[i]+1)%1000000007;}
  }
  System.out.println(ans);
}}

Measured memory_bytes: 21844
# 0028
array = []
while True:
    try:
        a = input()
        array.append(int(a))
    except EOFError:
        break
s = set(array)
mx = max(list(map(lambda a: array.count(a), s)))
for a in sorted(s):
    if array.count(a) == mx:
        print(a)

Measured memory_bytes: 7788
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
minv = min(A) + min(B)
for i in range(m):
	x, y, c = map(int, input().split())
	x -= 1
	y -= 1
	minv = min(minv, A[x] + B[y] - c)
print(minv)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;
typedef pair<string, ll> psl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll A, B, N, ans, x, tmp, f1, f2;
    ans = 0;
    cin >> A >> B >> N;

    // 最大値
    x = N;
    f1 = A * x / B;
    f2 = x / B;
    tmp = f1 - A * f2;
    ans = max(ans, tmp);

    // bの上境界
    x = N / B;
    if(x > 0) {
        x = (B * x) - 1;
        f1 = A * x / B;
        f2 = x / B;
        tmp = f1 - A * f2;
        ans = max(ans, tmp);
    }

    // bの下境界
    x = N / B;
    if(x > 1) {
        x = (B * (x - 1)) - 1;
        f1 = A * x / B;
        f2 = x / B;
        tmp = f1 - A * f2;
        ans = max(ans, tmp);
    }

    // aの上境界
    x = N / A;
    if(x > 0) {
        x = (A * x) - 1;
        f1 = A * x / B;
        f2 = x / B;
        tmp = f1 - A * f2;
        ans = max(ans, tmp);
    }

    // aの下境界
    x = N / A;
    if(x > 1) {
        x = (A * (x - 1)) - 1;
        f1 = A * x / B;
        f2 = x / B;
        tmp = f1 - A * f2;
        ans = max(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
using namespace std;

int main(void){
     char r;
     cin>>r;
    if(r=='T'){
        cout<<"A"<<endl;
    }else if(r=='A'){
        cout<<"T"<<endl;
    }else if(r=='G'){
        cout<<"C"<<endl;
    }else{
        cout<<"G"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())
As = list(mi())
avg = sum(As) / N

minno = -1
min = 1000
for i, a in enumerate(As):
  if abs(a-avg) < min:
    min = abs(a-avg)
    minno = i

print(minno)



Measured memory_bytes: 38384
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) a[i] = sc.nextInt();
		sort(a);
		for(long i=1;i<=(long)a[0];i++)if(a[0]%i == 0){
			boolean f = true;
			for(int j=1;j<n;j++) if(a[j]%i != 0) f = false;
			if(f) System.out.println(i);
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main() {
    int x, y, W, H, r;
    cin >> W >> H >> x >> y >> r;
    if ((r <= x && x <= W-r) && (r <= y && y <= H-r)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



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

using namespace std;

typedef long long ll;

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

    vector <int> a(n);

    for(int& x : a) scanf("%d", &x);

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

    k = n - k;

    ll Ans = 0;

    for(int i = 0; i < k; i++)  Ans += (ll) a[i];

    cout << Ans << endl;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            String t = in.next();
            StringBuilder sb = new StringBuilder();
            for (int i = s.length() - 1; i >= t.length() - 1; i--) {
                char c = s.charAt(i);
                if (c == '?' || c == t.charAt(t.length() - 1)) {
                    for (int j = t.length() - 1; j >= 0; j--) {
                        char cs = s.charAt(i + j - t.length() + 1);
                        char ct = t.charAt(j);
                        if (cs != '?' && cs != ct) break;
                        if (j == 0) {
                            sb.append(s.substring(0, i - t.length() + 1));
                            sb.append(t);
                            sb.append(s.substring(i + 1, s.length()));
                            for (int k = 0; k < sb.length(); k++) if (sb.charAt(k) == '?') sb.replace(k, k + 1, "a");
                            out.println(sb);
                            return;
                        }
                    }
                }
            }
            out.println("UNRESTORABLE");
        }

    }
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define el "\n"
#define sp " "
typedef long long ll;
bool myfun(pair<string,pair<ll,ll> > p1,pair<string,pair<ll,ll> > p2)
{
	if(p1.first!=p2.first)
	return (p1.first<p2.first);
	else
	return (p1.second.first>p2.second.first);
}
main()
{
	ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,i;
cin>>n;
pair<string,pair<ll,ll> > p[n];
for(i=0;i<n;i++)
{
	cin>>p[i].first>>p[i].second.first;
	p[i].second.second=i+1;
}
sort(p,p+n,myfun);
for(i=0;i<n;i++)
cout<<p[i].second.second<<" ";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"Yes":"No")<<endl;

int main() {
    int n, k; cin >> n >> k;
    vector<int> nums(200000, 0);
    rep(i, n) {
        int num; cin >> num;
        num--;
        nums[num]++;
    }
    sort(nums.begin(), nums.end(), greater<int>());
    int ans = 0;
    rep(i, nums.size()) {
        if (i < k) continue;
        ans += nums[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace 日経PC2019_D___Restore_the_Tree
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NM[0]; var M = NM[1];
            var to = new List<int>[N + 1];
            for (int i = 0; i < N + 1;i++)to[i] = new List<int>();
            var indegree = new int[N + 1];
            indegree[0] = -1;
            for (int i = 0; i < N + M - 1; i++)
            {
                var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                to[ab[0]].Add(ab[1]);
                indegree[ab[1]]++;
            }

            var queue = new Queue<int>();
            int root = 1;
            for (; root < N + 1; root++) if (indegree[root] == 0) break;
            var parents = new int[N + 1];
            parents[root] = 0;
            queue.Enqueue(root);
            while (queue.Count > 0)
            {
                var parent = queue.Dequeue();
                foreach (int e in to[parent])
                {
                    indegree[e]--;
                    if (indegree[e] == 0)
                    {
                        parents[e] = parent;
                        queue.Enqueue(e);
                    }
                }
            }

            for (int i = 1; i < N + 1; i++) Console.WriteLine(parents[i]);
        }
    }
}


Measured memory_bytes: 26244
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXX 1e12
#define MAXN 3005
#define MOD 1000000007
double dp[MAXN][MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N; cin>>N;
    double arr[N];
    
    for(ll i=0;i<N;++i)
        cin>>arr[i];
    
    dp[0][0] = 1.0;
    for(ll i=1;i<=N;++i)
    {
        for(ll j=0;j<=i;++j)
        {
            if(j > 0)
                dp[i][j] = dp[i - 1][j - 1]*arr[i - 1];
            
            dp[i][j] += dp[i - 1][j] * (1.00 - arr[i - 1]);
            
            //dp[i][j] = (dp[i - 1][j - 1] * arr[i - 1]) + (dp[i - 1][j] * (1.00 - arr[i]));
        }
    }
    
    //cout<<dp[1][0]<<endl;
    
    double ans = 0.0;
    
    for(ll j=(N + 1)/2;j<=N;++j)
        ans += dp[N][j];
    cout<<setprecision(10)<<ans<<endl;
    
}

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

int main() {
    
  string w;
  cin >> w;
  
  int count = 0;

  string s;
  cin >> s;
  while (  s != "END_OF_TEXT") {
      for (int i=0; i<s.size(); i++) {
          if (isupper(s.at(i))) {
              s.at(i) = tolower(s.at(i));
          }
      }
      if (s == w) {
          count++;
      }
      cin >> s;
  }
  
  cout << count << endl;

return 0;
}




Measured memory_bytes: 3164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] top3 = new int[3];
        String line;
        try {
            while((line = br.readLine()) != null){
                String[] numbers = line.trim().split(" ");
                int a = Integer.parseInt(numbers[0]);
                int b = Integer.parseInt(numbers[1]);
                System.out.println(Integer.toString(a+b).length());
            }
        } catch (IOException e) {
        }
    }
}

Measured memory_bytes: 15152
#include <bits/stdc++.h> 
using namespace std; 
int main()
{
	int n,a;
	string b;
	cin>>n;
	a=n%10;
	if(a==0||a==8||a==6||a==1)
	{
		b="pon";
	}
	else if(a==3)
	{
		b="bon";
	}
	else
	{
		b="hon";
	}
	cout<<b;
	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int& a : A) cin >> a;
  N -= K; K--;
  cout << 1 + N/K + (0 < N % K) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

#define MAX 200000
#define SENTINEL 2000000000

int n;
int a[MAX+10];
int L[MAX/2+2], R[MAX/2+2];

ll merge(int l, int m, int r){
  int n1 = m-l;
  int n2 = r-m;
  rep(i, n1) L[i] = a[l+i];
  rep(i, n2) R[i] = a[m+i];
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  int i = 0;
  int j = 0;
  ll cnt = 0;
  REP(k, l, r-1){
    if(L[i] <= R[j]) a[k] = L[i++];
    else{
      a[k] = R[j++];
      cnt += n1 - i;
    }
  }
  return cnt;
}

ll mergeSort(int l, int r){
  if(l+1 < r){
    ll v1, v2, v3;
    int m = (l+r)/2;
    v1 = mergeSort(l, m);
    v2 = mergeSort(m, r);
    v3 = merge(l, m, r);
    return v1+v2+v3;
  }
  else return 0;
}

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

  printf("%lld\n", mergeSort(0, n));

  return 0;
}





Measured memory_bytes: 4760
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

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

void solve_A(){
    string s;
    string t;
    cin >> s;
    cin >> t;

    int n = s.size();
    bool flag = true;
    REP(i,n){
        if(s[i] != t[i]) flag = false;
    }

    int m = t.size();
    if((m == n + 1) && flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

void solve_B(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    if(a >= k) cout << k << endl;
    else if(a + b >= k) cout << a << endl;
    else cout << 2*a + b - k << endl;
}

int n, m, x;
vector<int> c;
vector< vector<int> > a;

int cost(vector<int> &D){
    int ans = 0;
    vector<int> skill(m, 0);
    REP(i,n){
        if(D[i] == 1){
            REP(j,m){
                skill[j] += a[i][j];
            }
        }
    }
    
    bool flag = true;
    REP(j,m){
        if(skill[j] < x) flag = false;
    }

    if(!flag) return 20000000;
    else{
        REP(i,n){
            if(D[i] == 1){
                ans += c[i];
            }
        }
        return ans;
    }
}

int dfs(vector<int> &D){
    if(D.size() == n){
        //REP(i,n) cout << D[i];
        //cout << endl;
        return cost(D);
    }

    int tmp = 100000000;
    for(int i = 0; i < 2; i++){
        D.push_back(i);
        tmp = min(tmp, dfs(D));
        D.pop_back();
    }
    return tmp;
}

void solve_C(){
    cin >> n >> m >> x;

    c.resize(n);
    a.resize(n);
    REP(i,n){
        a[i].resize(m);
    }
    REP(i,n){
        cin >> c[i];
        REP(j,m) cin >> a[i][j];
    }

    vector<int> Ans;

    if(dfs(Ans) == 20000000){
        cout << -1 << endl;
    } else{
        cout << dfs(Ans) << endl;
    }
}

int main(void){
    solve_C();
    
    return 0;
}

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

string str;
int subsolve(string s) {
  int ct = 0;
  while(s[ct] == 'A' || s[ct] == 'C' || s[ct] == 'G' || s[ct] == 'T'){
    ct++;
  }
  return ct;
}

int solve(){
  int ret = 0;
  for (int i = 0; i < int(str.length()); i++) {
    ret = max(ret, subsolve(str.substr(i)));
  }
  return ret;
}

int main() {
  cin >> str;
  cout << solve() << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	Scanner scan = new Scanner(System.in);
	
	
	void compute() {
		int N = scan.nextInt();
		int D = scan.nextInt();
		double x = (double)N / (double)(2 * D + 1);
		int y = N / (2 * D + 1);
		if(0 < x - y) {
			y++;
		}
		System.out.println(y);
	}

	public static void main(String[] args) {
		new Main().compute();
	}

}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	bool k = false;
	for(int i=0; i<50; i++){
		for(int j=0; j<50; j++){
			int total = i*4+j*7;
			if(total==n){
				k=true;
			}
		}
	}
	if(k) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
    
using namespace std;
    
string str[2];
int s, n, t, m, lt, rt, t_w, t_t;
double p;
    
int conv(string s){
  string data[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};  
  for(int i=0;i<7;i++) if(s == data[i]) return i;
  if(s == "All") return -1;
}
    
int calc(int s_w, int s_t){
  int cnt = 0;
  for(int k=0;k<m;k++){
    int f_w = s_w;
    int f_t = s_t + s;
    if(f_t >= 24 * 60){
      f_t -= 24 * 60;
      f_w = (f_w + 1) % 7;
    }
    bool f = false;
    if(t_w == -1 || (t_w == s_w && t_w == f_w)){
      if(t_t == 0){
        if(0 <= s_t && s_t < 24 * 60 && 0 <= f_t && f_t < 24 * 60) f = true;
      }
      if(t_t == 1){
        if(6 * 60 <= s_t && s_t < 18 * 60 && 6 * 60 <= f_t && f_t < 18 * 60) f = true;
      }
      if(t_t == 2){
        if(((18 * 60 <= s_t && s_t < 24 * 60) || (0 <= s_t && s_t < 6 * 60))
           && ((18 * 60 <= f_t && f_t < 24 * 60) || (0 <= f_t && f_t < 6 * 60))) f = true;
      }
    }
    if(f) cnt++;
    s_t += t;
    if(s_t >= 24 * 60){
      s_t -= 24 * 60;
      s_w = (s_w + 1) % 7;
    }
  }
  return cnt;
}
    
main(){
  while(cin >> s >> n >> t >> str[0] >> str[1] >> p >> m && (s|n|t|m) && str[0] != "None" && str[1] != "None"){
    t_w = conv(str[0]);
    if(str[1] == "All") t_t = 0;
    if(str[1] == "Day") t_t = 1;
    if(str[1] == "Night") t_t = 2;
    int ans = 0;
    for(int i=0;i<7;i++) for(int j=0;j<24*60;j++) ans = max(ans, calc(i, j));
    printf("%.10f\n", 1.0 - pow(1.0 - 1.0 / p, n * ans));
  }
}

Measured memory_bytes: 1296
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <random>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int n; cin >> n;
    map<int, int> m;
    for (int i = 0; i < n; ++i) {
        int k;
        scanf("%d", &k);
        m[k]++;
    }
    int x; cin >> x;
    for (int i = 0; i < x; ++i) {
        int k;
        scanf("%d", &k);
        m[k]--;
    }
    for (auto &&a : m) if(a.second<0) {cout << "NO\n"; return 0;}
    cout << "YES\n";
    return 0;
}


Measured memory_bytes: 9600
from collections import Counter
import bisect
N, M = map(int, input().split())
P = list(map(int, input().split()))
V = [[] for _ in range(N)]

for _ in range(M):
	x, y = map(int, input().split())
	V[x - 1].append(y - 1)
	V[y - 1].append(x - 1)
	
#labelはり
label = [-1] * N
label_num = 0

for i in range(N):
	if label[i] != -1: continue
	Q = [i]
	while Q:
		cur = Q.pop()
		if label[cur] != -1: continue
		label[cur] = label_num
		for adj in V[cur]:
			if label[adj] != -1: continue
			Q.append(adj)
	label_num += 1
	
# labelの番号(i)->labelの番号がiの頂点の集合
label_set = [[] for _ in range(label_num)]
for i in range(N):
	label_set[label[i]].append(i)
	
# 2分探索
def binary_search(val, lst):
	insert_place = bisect.bisect_left(lst, val)
	if len(lst) == insert_place: return False 
	return lst[insert_place] == val
	
ans = 0
for i in range(N):
	# 同じlabelを振ってある集合にP[i] - 1があるかを高速判定
	# print(P[i] - 1, label_set[label[i]])
	# print(binary_search(P[i] - 1, label_set[label[i]]))
	if binary_search(P[i] - 1, label_set[label[i]]):
		ans += 1
		
print(ans)

Measured memory_bytes: 88172
N=list(map(int,input().split()))
#A=list(map(int,input().split()))
list1=[[0]*N[1]] *N[0]

for i in range(N[0]):
 list1[i]=list(map(int,input().split()))
 
count=0
for i in range(N[0]):
 for j in range(N[0]-i-1):
   d=0
   for k in range(N[1]):
     d=d+(list1[i][k]-list1[j+i+1][k])**2
   if d**(1/2)==int(d**(1/2)):     
      count=count+1      
print(count)

Measured memory_bytes: 3188
###
### atcorder test program
###

### math class
class math:
    ### pi
    pi = 3.14159265358979323846264338

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

math = math()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#A, B, C = [x for x in input().split()]
#templist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

S = []
H = []
C = []
D = []

ALL = list(range(1,14))

N = int(input())
for i in range(N):
    p, n = [x for x in input().split()]
    if p == "S":
        S.append(int(n))
    elif p == "H":
        H.append(int(n))
    elif p == "C":
        C.append(int(n))
    elif p == "D":
        D.append(int(n))

S = list(set(ALL)-set(S))
H = list(set(ALL)-set(H))
C = list(set(ALL)-set(C))
D = list(set(ALL)-set(D))

S.sort()
H.sort()
C.sort()
D.sort()

for i in S:
    print("S {}".format(i))
for i in H:
    print("H {}".format(i))
for i in C:
    print("C {}".format(i))
for i in D:
    print("D {}".format(i))





Measured memory_bytes: 5624
using System.Collections.Generic;
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        var d = new Dictionary<long, int>();
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        for (int i = 0; i < n; i++)
        {
            var w = int.Parse(line[i]);
            if (d.ContainsKey(w)) d[w]++;
            else d[w] = 1;
        }
        if (d.Count(x => x.Value >= 4) == 0 && d.Count(x => x.Value >= 2 && x.Value <= 3) <= 1)
        { Console.WriteLine(0); goto end; }
        var ret = 0L;
        foreach (var x in d.Where(y => y.Value >= 2).OrderByDescending(y => y.Key))
        {
            if (ret == 0 && x.Value >= 4) { ret = x.Key * x.Key; break; }
            else if (ret == 0) ret = x.Key;
            else { ret *= x.Key; break; }
        }
        Console.WriteLine(ret);
        end:;
    }
}



Measured memory_bytes: 27488
import sys
import collections

def resolve(in_, out):
    n = int(next(in_))
    c = collections.Counter(s.strip() for s in in_)
    print('AC x {}'.format(c.get(b'AC', 0)), file=out)
    print('WA x {}'.format(c.get(b'WA', 0)), file=out)
    print('TLE x {}'.format(c.get(b'TLE', 0)), file=out)
    print('RE x {}'.format(c.get(b'RE', 0)), file=out)


def main():
    resolve(sys.stdin.buffer, sys.stdout)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9520
#include <iostream>
#include <string>
#include<vector>
using namespace std;
int main() {
	int h, m;
	cin >> h >> m;
	vector<string> vec(h);
	for (int i(0); i < h; i++) {
		cin >> vec[i];
	}
	for (int k(0); k < h; k++) {
		for (int l(0); l < m; l++) {
			if (vec.at(k).at(l) != '#') {
				int count(0);
				for (int i=k-1; i <= k+1; i++) {
					for (int j=l-1; j <= l+1; j++) {
						if (i>=0 && i<h && j>=0 && j<m && vec.at(i).at(j) == '#') {
							count++;
						}
					}
				}
				vec.at(k).at(l) = char(count + '0');
			}
			
		}
	}
	for (int k(0); k < h; k++) {
		cout << vec[k] << endl;
	}
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc146/tasks/abc146_b

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(void){
    string S;
    int N;
    cin >> N >> S;

    for( auto& c : S ){
        c -= 'A';
        c += N;
        c = c % 26;
        c += 'A';
    }

    cout << S << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <random>
#include <stdio.h>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef string ST;


#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) for(auto (a): v )   cerr << a << endl
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl



vector<vector<LL>> A;
LL N, M;
LL cnt=0;
void recusive( LL now_index, vector<LL> visit)
{
  //visit.insert(now_index);
  visit.push_back(now_index);
  if (visit.size() == N) {
    cnt++;
    //PRINTSP(visit);
    return;
  }

  auto a = A[now_index];
  for (LL i = 0; i < a.size(); i++) {
    //if (visit.fin(a[i]) == visit.end()) {
    if(find(ALL(visit),a[i]) == visit.end()){
     recusive(a[i], visit);
    }
  }

}

void func() {
  cin >> N >> M;
  A.resize(N);
  REP(i, M) {
    LL a, b;
    cin >> a >> b;
    a--;
    b--;
    A[a].push_back(b);
    A[b].push_back(a);
  }

  //set<LL> visit;
  vector<LL> visit;
  recusive(0, visit);
  cout << cnt;
#if 0
  REP(i, N) {
    cerr << i << " : ";
    PRINTSP(A[i]);
  }
#endif

}

#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "\n%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif





Measured memory_bytes: 256
#include<iostream>
    using namespace std;
    int main(){
        int n,a[100000]={},count=0;
        unsigned long long num;
        cin >> n;
        while(n--){
            cin >> num;
            if(num<=100000){
                a[num-1]++;
            }
            else count++;
        }
        
        for(int i=0;i<100000;i++){
            if(a[i]>i+1)    count+=(a[i]-(i+1));
            else if(a[i]<i+1)   count+=a[i];
        }
        cout << count << "\n";
        return 0;
    }

Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int N,L[105],point=0,max=1,tag=0,n=1;
	scanf("%d",&N);
	for(int i=0;i<N;++i)
		scanf("%d",L+i);
	while(point<N){
		if(tag==0&&L[point])tag=1;
		if(tag&&!L[point]){
			tag=0;
			if(n>max) max=n;
			n=1;}
		if(tag&&point==N-1){
			++n;
			if(n>max) max=n;}
		if(tag) ++n;
		++point;}
			
	printf("%d\n",max);
	return 0;
}


Measured memory_bytes: 2100
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
const int mod = 998244353;
const int inf = 1e9+7;

struct node {
    int l, r;
    inline void read() {
        scanf("%d%d", &l, &r);
    }
    inline bool operator < (const node &p) const {
        return l == p.l ? r < p.r : l < p.l;
    }
}a[maxn];
int n;

int l1[maxn], l2[maxn], r1[maxn], r2[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        a[i].read();
    sort(a + 1, a + 1 + n);
    l1[1] = a[1].l, r1[1] = a[1].r;
    l2[n] = a[n].l, r2[n] = a[n].r;
    for (int i = 2; i <= n; ++i) l1[i] = max(a[i].l, l1[i-1]), r1[i] = min(a[i].r, r1[i-1]);
    for (int i = n-1; i >= 1; --i) l2[i] = max(a[i].l, l2[i+1]), r2[i] = min(a[i].r, r2[i+1]);

    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = max(ans,
               max(max(0, r1[i] - l1[i] +1) + max(0, r2[i+1] - l2[i+1] + 1),
                       a[i].r - a[i].l + 1 + max(0, min(r1[i-1], r2[i+1]) - max(l1[i-1], l2[i+1]) + 1)
                       )
                );
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2560
//AtCoder ABC087 C - Candies
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
#if LOCAL&0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N;
    cin>>N;
    vector<vector<ll>> an(2,vector<ll>(N+1,0));
    for(auto&& at:an){
        for(ll i=1;i<=N;++i){
            cin>>at[i];
        }
    }
    vector<vector<ll>> sumt(2,vector<ll>(N+1,0));
    ll n=0;
    for(auto && sum:sumt){
        ll ttl=0;
        for(int i=1;i<=N;++i){
            ttl+=an[n][i];
            sum[i]=ttl;
        }
        ++n;
    }
    ll ans=0;
    for(ll i=1;i<=N;++i){
        ll num=sumt[0][i]-sumt[0][0] + sumt[1][N]-sumt[1][i-1];
        ans=max(ans,num);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.List

lenJOIandIOI :: (Int, Int) -> String -> [Int]
lenJOIandIOI (a, b) []     = [a, b]
lenJOIandIOI (a, b) str
  | "JOI" `isPrefixOf` str = lenJOIandIOI (a + 1, b) (tail str)
  | "IOI" `isPrefixOf` str = lenJOIandIOI (a, b + 1) (tail str)
  | otherwise              = lenJOIandIOI (a, b) (tail str)

solver :: [String] -> [Int]
solver = concatMap $ lenJOIandIOI (0, 0)

main :: IO()
main = do
  contents <- lines <$> getContents
  mapM_ print $ solver contents

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

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> as(n);
	for (auto &&a : as)
	{
		cin >> a;
	}

	int ans = 0;
	for (auto &&a : as)
	{
		ans += 2 * min(a, k - a);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3560
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    mi = 0
    le = len(a)
    cost = 0
    for i in range(le-1):
        if mi > a[i+1] or a[i] > a[i+1]:
            mi = max(a[i], mi)
            cost += mi - a[i+1]
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 33068
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main(){
	int n,k,ans=0;
	cin>>n>>k;
	int t;
	for(int i=0;i<n;i++){
		cin>>t;
		if(t>=k){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout<<'\n';
#define MOD 1000000007
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN

void solve(){
  int x,y; cin>>x>>y;
  int s=2*x;
  if(y<s){cout<<"No";LOL return;}
  for(int i=s ; i<=4*x ; i+=2){
    if(y==i){
      cout<<"Yes";LOL return;
    }
  }
  cout<<"No";LOL
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 3576
#include <stdio.h>
#define N 100
int main()
{
    int data[N];
    int i,num,flag,key,cnt=0;
    

    scanf("%d",&num);

    for(i=0;i<num;i++){
        scanf("%d",&data[i]);
    }
    flag = 1;
    while(flag == 1){
        flag = 0;
        for(i=num-1;i>=1;i--){
            if(data[i] < data[i-1]){
                key = data[i];
                data[i] = data[i-1];
                data[i-1] = key;
                flag = 1;
                cnt++;
            }
        }
    }
    for(i=0;i<num;i++){
        printf("%d",data[i]);
        if(i != num-1) printf(" ");
        if(i == num -1) printf("\n");
    }
    printf("%d\n",cnt);
    return 0;
}



Measured memory_bytes: 2104
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,m = readline() |> split |> parseMap
	e = [Int[] for i in 1:n]
	for i in 1:m
		a,b = readline() |> split |> parseMap
		push!(e[a],b)
		push!(e[b],a)
	end
	q = readline() |> parseInt
	v = Tuple{Int,Int,Int}[(0,0,0) for i in 1:q]
	for i in q:-1:1
		a,b,c = readline() |> split |> parseMap
		v[i] = (a,b,c)
	end
	clr = zeros(Int,n)
	vst = zeros(Int,n)
	ct = 0
	for i in 1:q
		if ct >= n
			break
		else
			stack = Tuple{Int,Int}[]
			push!(stack,(v[i][1],v[i][2]))
			while !isempty(stack)
				(j,d) = shift!(stack)
				if clr[j]==0
					clr[j] = v[i][3]
					ct += 1
				end
				if vst[j]<d&&d>0
					vst[j] = d
					for k in e[j]
						push!(stack,(k,d-1))
					end
				end
			end
		end	
	end
	for i in 1:n
		println(clr[i])
	end
end

main()

Measured memory_bytes: 177440
#include <stdio.h>

int main(){
  int n, i, a, sum;

  while(1){
    scanf("%d", &n);

    if(n==0){
      break;
    }

    sum=0;
    for(i=0;i<n/4;i++){
      scanf("%d", &a);
      sum += a;
    }
    
    printf("%d\n", sum);
  }
    
  return 0;
}

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


int main(){
    int N, M;
    cin >> N >> M;
    int card_min=-10, card_max=1000000;
    rep(i, M){
        int L, R;
        cin >> L >> R;
        card_min = max(card_min, L);
        card_max = min(card_max, R);
    }

    cout << max(card_max - card_min + 1, 0) << endl;
    return 0;
}

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

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> matrix;
    matrix = vector<vector<int>>(N+1, vector<int>(N+1, 0));
    for(int i=0; i<M; i++){
        int L, R;  cin >> L >> R;
        matrix[L][R]++;
    }

    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            matrix[i][j]+=matrix[i-1][j];
        }
    }
    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            matrix[i][j]+=matrix[i][j-1]; 
        }
    }

    for(int i=0; i<Q; i++){
        int p, q;  cin >> p >> q;
        cout << matrix[q][q] - matrix[q][p-1] - matrix[p-1][q] + matrix[p-1][p-1] << endl;
    }

}


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

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

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


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

  vector<int> left(N+1,0),right(N+1,0);
  for (int i=0;i<N;++i) left[i+1]=GCD(left[i],a[i]);
  for (int i=N-1;i>=0;--i) right[i]=GCD(right[i+1],a[i]);

  int res=0;
  for (int i=0;i<N;++i){
    int l=left[i];
    int r=right[i+1];
    chmax(res,GCD(l,r));
  }
  cout << res << endl;
}


Measured memory_bytes: 1408
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    if N == 0:
        print(0)
        exit()
    if N < 0:
        N = -N
        D = defaultdict(int)
        index = 0
        while N >= 1:
            #bitフラグがたっていたら
            if N & 1 == 1:
                #2の倍数の場合D[index]とD[index+1]に1を足す
                if index % 2 == 0:
                    D[index] += 1
                    D[index+1] += 1
                else:
                    D[index] += 1
            else:
                D[index] = D[index]
            N = N>>1
            index += 1
    else:
        D = defaultdict(int)
        if N & 1 == 1:
            D[0] = 1
        else:
            D[0] = 0
        index = 1
        N = N >> 1

        while N >= 1:
            #bitフラグがたっていたら
            if N & 1 == 1:
                #2の倍数の場合D[index]とD[index+1]に1を足す
                if index % 2 == 1:
                    D[index] += 1
                    D[index+1] += 1
                else:
                    D[index] += 1
            else:
                D[index] = D[index]
            N = N>>1
            index += 1
            
            
    index = 0
    while True:
        if not index in D.keys():
            break
        if D[index] <= 1:
            pass
        else:
            temp = D[index]
            D[index] = temp % 2
            D[index+1] += (temp // 2)
            D[index+2] += (temp // 2)
            if D[index+1] >= D[index+2] * 2:
                temp = D[index+2]
                D[index+2] -= temp
                D[index+1] -= temp * 2
        index += 1
    res = True

    for i in reversed(D.values()):
        if res and i == 1:
            res = False
        if not res:
            print(i, end="")
    print()

if __name__ == "__main__":
    main()

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

int w;

void dfs(int d, int acc, string s){
    if(acc == w){
        reverse(s.begin(), s.end());
        cout << s << endl;
        exit(0);
    }
    
    if(d >= 12) return;

    int t = 1;
    for(int i = 0; i < d; i++)  t *= 3;

    dfs(d+1, acc+t, s+"+");
    dfs(d+1, acc, s+"0");
    dfs(d+1, acc-t, s+"-");
}

int main(){
    cin >> w;
    dfs(0, 0, "");
}


Measured memory_bytes: 3204
#include <stdio.h>

int main(void)
{
	int n = 0;
	
	int a[4];
	
	scanf("%d",&n);
	
	a[0] = (n % 10);
	n = n/10;// 1桁目を取り出す
	
	a[1] = (n % 10);
	n = n/10;// 2桁目を取り出す
	
	a[2] = (n % 10);
	n = n/10;// 3桁目を取り出す

	
	switch(a[0]){
		case 0:
			printf("pon");
			break;
		case 1:
			printf("pon");
			break;
		case 2:
			printf("hon");
			break;
		case 3:
			printf("bon");
			break;
		case 4:
			printf("hon");
			break;
		case 5:
			printf("hon");
			break;
		case 6:
			printf("pon");
			break;
		case 7:
			printf("hon");
			break;
		case 8:
			printf("pon");
			break;
		case 9:
			printf("hon");
			break;
	}

	return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF = 1000000100;

int main(){
    int x,N;
    cin >> x >> N;
    int p[N];
    int all[110];
    fill(all, all+110, true);
    for(int i=0;i<N;i++){
        cin >> p[i];
        all[p[i]]=false;
    }
    int cnt=0;
    while(true){
        if(all[x-cnt]){
            cout << x-cnt << endl;
            return 0;
        }
        if(all[x+cnt]){
            cout << x+cnt << endl;
            return 0;
        }
        cnt++;
    }
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N, A[101010], C[20];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N - 1) {
        int a, b, c; cin >> a >> b >> c;
        A[a] ^= c;
        A[b] ^= c;
    }
    rep(i, 0, N) C[A[i]]++;

    //rep(i, 0, 16) printf("%d ", C[i]); printf("\n");

    int ans = 0;
    rep(i, 1, 16) {
        ans += C[i] / 2;
        C[i] %= 2;
    }

    int x = 0;
    rep(i, 1, 16) if (C[i]) x ^= i;
    if (x != 0) {
        printf("-1\n");
        return;
    }

    vector<int> xo;
    rep(i, 1, 16) if (C[i]) xo.push_back(i);
    int n = xo.size();
    vector<int> dp(1 << n);

    rep(msk, 1, 1<<n) {
        int x = 0;
        rep(i, 0, n) if (msk & (1 << i)) x ^= xo[i];
        if (x == 0) dp[msk] = 1;

        for (int msk2 = msk; msk2>0; msk2 = (msk2 - 1)&msk) {
            if (0 < dp[msk2] and 0 < dp[msk - msk2]) chmax(dp[msk], dp[msk2] + dp[msk - msk2]);
        }
    }

    ans += n - dp[(1 << n) - 1];
    cout << ans << endl;
}

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

int main() {
    int x, a, b; cin >> x >> a >> b;

    if (abs(x-a) < abs(x-b)) cout << "A" << endl;
    else cout << "B" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{

    int i, j, m, n, cnt = 0;
    long long a[10005], b[505];

    scanf("%d", &m);
    for (i = 0; i < m; i++)
    {
        scanf("%lld", &a[i]);
        //  printf("%d ",a[i]);
    }
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%lld", &b[i]);
        //  printf("%d ",b[i]);
    }

    for (j = 0; j < n; j++)
    {
        i = 0;
        a[m] = b[j];

        while (1)
        {
            if (i == m - 1)
            {
                break;
            }
            if (a[i] == a[m])
            {
                cnt++;
                break;
            }
            i++;
        }
    }

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

    return 0;
}



Measured memory_bytes: 2112