akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

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

int main(){
	int n;
	while(cin>>n,n){
		int x[n],y[n];
		bool check[n];
		rep(i,n){
			cin>>x[i]>>y[i];
			check[i]=((x[i]==10 && y[i]==10)?true:false);
		}
		int m,dir,l,nowx=10,nowy=10;
		char d;
		cin>>m;
		rep(i,m){
			cin>>d>>l;
			if(d=='N')dir=1;
			if(d=='W')dir=2;
			if(d=='S')dir=3;
			if(d=='E')dir=0;
			rep(k,l){
				nowx+=dx[dir];
				nowy+=dy[dir];
				rep(j,n)if(nowx==x[j] && nowy==y[j])check[j]=true;
			}
		}
		bool ans=true;
		rep(i,n)if(!check[i])ans=false;
		cout<<((ans)?"Yes":"No")<<endl;
	}
	return 0;
}

Measured memory_bytes: 3064
// agrawal117
//chahatagrawal117
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long int ll;
const  ll mod=1000000007;
const int MAX=1000000+9;
int main()
{
   ll n,k,s;
   cin>>n>>k>>s;
   if(s==1000000000){
       for(int i=1;i<=n;i++){
       if(i<=k) cout<<s<<" ";
       else cout<<1<<" ";
    }
    return 0;
   }
   for(int i=1;i<=n;i++){
       if(i<=k) cout<<s<<" ";
       else cout<<s+1<<" ";
   }
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

struct Point{
	double x,y;
};


int main(){

	int n;
	scanf("%d",&n);
	double gaiseki,sum = 0;

	Point points[n];

	for(int i=0; i < n; i++){
		scanf("%lf %lf",&points[i].x,&points[i].y);
	}
	sum = points[n-1].x*points[0].y - points[n-1].y*points[0].x;
	for(int i=0; i < n-1; i++){
		gaiseki = points[i].x*points[i+1].y - points[i].y*points[i+1].x;
		sum += gaiseki;
	}

	printf("%.1lf\n",fabs(sum)/2);

    return 0;
}



Measured memory_bytes: 2748
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    for(int i=0; i<100; i++){
        if(A % 2 == 1 || B % 2 == 1 || C % 2 == 1){
            cout << i << endl;
            return 0;
        }
        int AA = B/2 + C/2;
        int BB = C/2 + A/2;
        int CC = A/2 + B/2;
        A = AA; B = BB; C = CC;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', function (line) {
  var a = line.split(' ');
  var b = Number(a[0]);
  var c = Number(a[1]);
  var d = Number(a[2]);
  var e = Number(a[3]);
  b = Math.sqrt((b-d)*(b-d)+(c-e)*(c-e));
  console.log(b.toFixed(8));
  process.exit();
});
process.stdin.on('end', function () {
});

Measured memory_bytes: 16380
n,x=map(int,input().split())
l=list(map(int,input().split()))
c=0
d=0
for i in range(n):
    d+=l[i] 
    if(d>x):
        print('{0}'.format(i+1))
        break
if(d<=x):
    print('{0}'.format(n+1))

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstring>
int main(){
	char s[100001];
	int i,a=0,b=0;
	scanf("%s",s);
	for(i=0;i<strlen(s);i++){
		if(i%2){if(s[i]-49)a++; else b++;}
		else{if(s[i]-48)a++; else b++;}
	}
	printf("%d",a>b?b:a);
}

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

int main(){

  int n;
  
  cin >> n;
  
  int ans = 1;
  rep(i,3)ans *= n;
    
  cout << ans;
    return 0;
}


Measured memory_bytes: 256
n,l=map(int,input().split())
s1=(l-1)*n+(n*(n+1))//2
m=9999999999
ans=0
for k in range(1,n+1):
    s2=s1-(l+k-1)
    if m>abs(s1-s2):
        m=abs(s1-s2)
        ans=s2
print(ans)


Measured memory_bytes: 2940
import math
N, H = map(int, input().split())
As = []
Bs = []
for i in range(N):
    a, b = map(int, input().split())
    As.append(a)
    Bs.append(b)
As.sort()
Bs.sort()
amax = As[-1]
ans = 0
dam = 0
while Bs:
    b = Bs.pop()
    if b < amax or dam >= H:
        break
    else:
        ans += 1
        dam += b
if dam < H:
    ans += math.ceil((H-dam)/amax)
print(ans)

Measured memory_bytes: 11312
#include<bits/stdc++.h>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#define mil 200001

using namespace std;


int main()
{
    string  s;
    cin>>s;
    int count = 0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i] == s[i+1])
        {
            if(s[i] == '0')
                s[i+1] = '1';
            else
                s[i+1] = '0';

            count++;
        }

    }
    cout<<count;

}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=210;
int f[N][N][N][2],s[N][N],H,W;
char S[N];
int calc(int lx,int ly,int rx,int ry){return s[rx][ry]+s[lx-1][ly-1]-s[lx-1][ry]-s[rx][ly-1];}
bool check(int lx,int ly,int rx,int ry){int v=calc(lx,ly,rx,ry);return !v||(v==(rx-lx+1)*(ry-ly+1));}
int lowb(int b,int i,int j,int k)
{
	int l=i,r=j-1,res=0;
	while(l<=r)
	{
		int mid=(l+r)>>1,lmid=f[i][mid][k][b],rmid=f[mid+1][j][k][b];
		res=max(res,min(lmid,rmid));
		if(lmid<rmid)r=mid-1;
		else l=mid+1;
	}
	return res;
}
int main()
{
	H=gi();W=gi();
	for(int i=1;i<=H;i++)
	{
		scanf("%s",S+1);
		for(int j=1;j<=W;j++)s[i][j]=(S[j]=='.');
	}
	for(int i=1;i<=H;i++)
		for(int j=1;j<=W;j++)s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
	int pre=0,nxt=1;
	for(int i=1;i<=H;i++)
		for(int j=i;j<=H;j++)
		{
			int lst;
			for(int k=1;k<=W;k=lst+1)
			{
				lst=k-1;while(lst<W&&check(i,k,j,lst+1))lst++;
				for(int p=k;p<=lst;p++)f[i][j][p][pre]=lst;
				if(lst==k-1)f[i][j][k][pre]=k-1,lst++;
			}
		}
	int ans;
	for(ans=1;f[1][H][1][pre]<W;ans++,nxt^=1,pre^=1)
	{
		for(int i=1;i<=H;i++)
			for(int j=i;j<=H;j++)
				for(int k=1;k<=W;k++)
				{
					int lst=f[i][j][k][pre];
					if(lst==W){f[i][j][k][nxt]=W;continue;}
					f[i][j][k][nxt]=max(f[i][j][lst+1][pre],lowb(pre,i,j,k));
				}
	}
	printf("%d\n",--ans);
	return 0;
}


Measured memory_bytes: 65280
#include <stdio.h>
#define N 1000
    
 int main(void)
 
    {
      int s[N],n,sum,f,k;
      char ch;
      n = 0; 
   f = 0;
      while( (ch = getchar()) != '\n' ) { 
        if( ch >='0' && ch<= '9' ) { 
          if( f ) { 
            s[n] = s[n] * 10 + (ch - '0'); 
          } else {
            s[n] = (ch - '0');
            f++;
          }
        }
        if( ch ==' ' ) {
          if( f ) { 
            n++;
            f = 0;
          }
        }
        switch(ch){
            case '+':
                if( n > 1 ) {
                n--;
              }
              s[n-1] += s[n];
              s[n] = 0;
            break;
            
            case '-':
                if( n > 1 ) {
                n--;
              }
              s[n-1] -= s[n];
              s[n] = 0;
            break;
            
            case '*':
                 if( n > 1 ) {
                n--;
              }
              s[n-1] *= s[n];
              s[n] = 0;
            break;
            
        
        }
       
      }
      printf("%d\n",s[0]);
      return 0;
    }


Measured memory_bytes: 2104
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;cin>>n;
	vector<int> a(n);REP(i,n)cin>>a[i];
	int q;cin>>q;
	int dp[40002];
	fill_n(dp,n,0);
	dp[0] = 1;
	REP(i,n){
		for(int j = 2000*n;j>=a[i];j--){
			dp[j] += dp[j - a[i]];
		}
	}
	REP(i,q){
		int m;cin>>m;
		if(dp[m])cout << "yes" << endl;
		else cout << "no" << endl;
	}
  return 0;
}

Measured memory_bytes: 3284
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
int n,a[251000],x[510];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
int main(){
	read(n);
	for(int i=1;i<=n;i++){
		read(x[i]);
		if(a[x[i]]){puts("No");return 0;}
		a[x[i]]=i;
		for(int j=1;j<i;j++)
			q.push(make_pair(x[i],i));
	}
	for(int i=1;i<=n*n;i++){
		if(!q.empty()&&q.top().first<i){puts("No");return 0;}
		if(a[i]){
			for(int j=a[i]+1;j<=n;j++) q.push(make_pair(n*n+1,a[i]));
		}
		else{
			if(q.empty()){puts("No");return 0;}
			a[i]=q.top().second;q.pop();
		}
	}
	puts("Yes");
	for(int i=1;i<=n*n;i++)
		cout<<a[i]<<' ';cout<<'\n';
	return 0;
}


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

string s;

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

    int cnt = 0, front = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='(') cnt++;
        else cnt--;

        if(cnt==-1){
            front++;
            cnt = 0;
        }
    }

    for(int i=0;i<front;i++) cout << '(';
    cout << s;
    for(int i=0;i<cnt;i++) cout << ')';
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		int c = 0;
		while (true) {
			if (A == B && B == C && A == C) {
				break;
			}
			if (A < B && A < C) {
				A += 2;
			} else if (B < A && B < C) {
				B += 2;
			} else if (C < A && C < B) {
				C += 2;
			} else if (A == B) {
				A++;
				B++;
			} else if (B == C) {
				B++;
				C++;
			} else if (A == C) {
				A++;
				C++;
			}
			c++;
		}
		
		System.out.println(c);
	}
}

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

int main(){
	/*input*/
	int n;	cin >> n;
	vector<int>a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	/*calculaiton*/
	sort(a.rbegin(), a.rend());
	int A = 0, B = 0;
	for(int i = 0; i < n; i++){
		if(i%2){
			B += a[i];
		}else{
			A += a[i];
		}
	}
	/*output*/
	cout << A - B << endl;
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())

c = []
for _ in range(H):
    letters = input()
    my_row = [1 if letter == '#' else 0 for letter in letters]
    c.append(my_row)
    
import itertools
count = 0
for h in range(H + 1):
    for delete_rows in itertools.combinations(range(H), h):
        new_c = c
        new_c = [[0] * W if idx in delete_rows else row for idx, row in enumerate(c)]
        # print(new_c)
        for w in range(W + 1):
            for delete_cols in itertools.combinations(range(W), w):
                new_new_c = [[0 if idx in delete_cols else score for idx, score in enumerate(row)] for row in new_c]
                # print(new_new_c)
                # print(sum(sum(new_new_c[i]) for i in range(H)))
                if sum(sum(new_new_c[i]) for i in range(H)) == K:
                    count += 1
print(count)

Measured memory_bytes: 9244
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int t = 0;
    for (int i = 0; i <= 3600; ++i) {
        int p = t, q = (t+a);
        for (int j = 0; j <= 3600; ++j) {
            if(p <= 60*j+c && 60*j+c <= q){
                cout << 60*j+c << "\n";
                return 0;
            }
        }
        t += a+b;
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 3120
using System;

namespace A___Eating_Symbols_Easy
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var ans = 0;
            for (var i = 0; i < 4; i++)
            {
                if (s.Substring(i, 1) == "+")
                {
                    ans++;
                }
                else
                {
                    ans--;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
let N = Int(readLine()!)!
let a = readLine()!.split(separator: " ").map({Int($0)!})
let T = a[0]
let A = a[1]

let H_line = readLine()!.split(separator: " ").map{abs(a[0]*1000 - 1000*a[1] - Int($0)! * 6)}
print(H_line.firstIndex(of: H_line.min()!)! + 1)

Measured memory_bytes: 8364
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		
		List<List<Object>> sp = new ArrayList<>();
		for(int i=1;i<=N;i++) {
			sp.add(Arrays.asList(sc.next(), sc.nextInt(),i));
		}
		
		sp.sort(new Comparator<List<Object>>() {

			@Override
			public int compare(List<Object> o1, List<Object> o2) {
				int x = ((String)o1.get(0)).compareTo((String)o2.get(0));
				if(x != 0) {
					return x;
				}
				
				return Integer.compare((Integer)o2.get(1), (Integer)o1.get(1));
			}
			
		});
		
		sc.close();

		for(List<Object> l : sp) {
			out.println(l.get(2));
		}
		
		
	}

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

}


Measured memory_bytes: 21844
n = int(input())
a = [int(input()) for _ in range(n)]
# a = list(map(lambda x: int(x) - 1, a))	#すべての要素から-1

p = a[0]

if p == 2:
    print(1)
    exit()
    
cnt = 1

for _ in range(n):
    p = a[p-1]
    cnt += 1
    if p == 2:
        print(cnt)
        exit()

print(-1)

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

int main(void) {
    int i, N, A, B, C;
    string X, Y, Z;
    cin >> N;
    A = 0; C = N-1;
    B = (A+C)/2; // N/2
    cout << A << endl;
    cin >> X;
    if (X == "Vacant") return 0;
    while (1) {
        cout << B << endl;
        cin >> Y;
        if (Y == "Vacant") return 0;
        if (((A%2 != B%2) && X != Y) || ((A%2 == B%2) && X == Y)) {
            A = B; X = Y;
            B = (A+C)/2;
            if (A == B) B++;
        } else {
            C = B; Z = Y;
            B = (A+C)/2;
        }
    }

    return 0;
}

Measured memory_bytes: 852
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll A, B;
	cin >> A >> B;
	vector<ll> a, b;
	for (ll i = 1; i * i <= A; i++) {
		if (A % i == 0) {
			if (i * i != A) a.push_back(A / i);
			a.push_back(i);
		}
	}
	for (ll i = 1; i * i <= B; i++) {
		if (B % i == 0) {
			if (i * i != B) b.push_back(B / i);
			b.push_back(i);
		}
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	vector<ll> V;
	int j = 0;
	for (int i = 0; i < a.size(); i++) {
		while (a[i] > b[j] && j < b.size()) {
			j++;
		}
		if (j == b.size()) break;
		if (a[i] == b[j]) V.push_back(a[i]);
	}
	int ans = 1;
	for (int i = 1; i < V.size(); i++) {
		bool ok = true;
		for (int j = 1; j < i; j++) {
			if (V[i] % V[j] == 0) {
				ok = false;
				break;
			}
		}
		if (ok) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3740
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(void){
    int R;
    cin>>R;
    if(R<1200){
        cout<<"ABC"<<endl;
    }else if(R<2800){
        cout<<"ARC"<<endl;
    }else{
        cout<<"AGC"<<endl;
    }

    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void output(int array[],int array2[],int number){
    int num = 0;
    for(int j = 0;j<number;j++){
        num = num + array[j]*array2[j];               
    }
    cout<<num<<endl;
}

int main(){
    int n,m,l;
    long int number;
    long long int array_A[101][101] = {0};
    long long int array_B[101][101]= {0};
    long long int array_C[101][101]= {0};
    cin>>n>>m>>l;
    for(int i = 0;i < n;i++){
        for(int j = 0;j<m;j++){
            cin>>number;
            array_A[i][j] = number;            
        }        
    }
    int sum = 0;
    for(int i = 0;i < m;i++){
        for(int j = 0;j<l;j++){ 
            cin>>number;          
            array_B[i][j] = number;
            // sum = sum + number*array_A[i][j];              
        }       
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < l;j++){
            for(int k = 0;k< m;k++){
                array_C[i][j] = array_C[i][j] + array_A[i][k]*array_B[k][j];
            }
            if(j < l -1)
                cout<<array_C[i][j]<<" ";
            else
            {
                cout<<array_C[i][j]<<endl;
            }
            
        }
    }
    return 0;
}


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

const int MOD = 1000000007;

int main() {
    int N;
    string s1, s2;
    cin >> N >> s1 >> s2;

    long long res = 0;
    int i = 0;
    if (s1[0] == s2[0]) {
        res = 3;
        i++;
    } else {
        res = 6;
        i += 2;
    }

    while (i < N) {
        if (s1[i] == s2[i]) {
            if (s1[i - 1] == s2[i - 1]) {
                res *= 2;
            } else {
                res *= 1;
            }
            i++;
        } else {
            if (s1[i - 1] == s2[i - 1]) {
                res *= 2;
            } else {
                res *= 3;
            }
            i += 2;
        }
        res %= MOD;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e6+5;
char c[N];
int main()
{
	scanf("%s",c+1);
	if(c[1]>='A'&&c[1]<='Z'){
		printf("A");
	}
	else{
		printf("a");
	}
}


Measured memory_bytes: 3760
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define BIT_CHK(f, i)       ((f >> (i) & 1) > 0)

typedef long long ll;

const int N_MAX = 1000;

int N, M;
ll x[N_MAX];
ll y[N_MAX];
ll z[N_MAX];
ll w[N_MAX];

void solve() {
  ll ans = 0;
  REP(k, 8) {
    int xs = BIT_CHK(k, 0) ? -1 : 1;
    int ys = BIT_CHK(k, 1) ? -1 : 1;
    int zs = BIT_CHK(k, 2) ? -1 : 1;
    // printf("xs: %d, ys:%d, zs: %d\n", xs, ys, zs);
    REP(i, N) w[i] = x[i] * xs + y[i] * ys + z[i] * zs;
    sort(w, w + N, greater<ll>());
    ll sum = 0;
    REP(i, M) sum += w[i];
    ans = max(ans, sum);
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, N) scanf("%lld%lld%lld", x + i, y + i, z + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 128
import math
n = int(input())
a = list(map(int, input().split()))
if n == 1:
    print(10 ** 9)
    exit()
l = [0] * n
r = [0] * n
l[0] = a[0]
r[-1] = a[-1]
for i in range(n-1):
    l[i+1] = math.gcd(a[i+1], l[i])
    r[-i-2] = math.gcd(a[-i-2], r[-i-1])
ans = max(l[-2], r[1])
for i in range(n-2):
    ans = max(ans, math.gcd(l[i], r[i+2]))
print(ans)

Measured memory_bytes: 21056
def insertionSort(a, n):
    for i in range(1, n):
        v = a[i]
        j = i - 1
        while (j >= 0 and a[j] > v):
            a[j + 1] = a[j]
            j -= 1
        a[j + 1] = v
        print(" ".join(map(str, a)))

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    print(" ".join(map(str, a)))
    insertionSort(a, n)


Measured memory_bytes: 5604
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>

#define MAX 1000

using namespace std;

typedef unsigned long long ull;

int H,W,R,C;
char field[MAX][MAX]; //????´¢????±?
char pattern[MAX][MAX]; //????????????

ull hashh[MAX][MAX],temp[MAX][MAX];
ull target;

//a???R*C?????¨??????hash????¨????
void compute_hash(char a[MAX][MAX], int n, int m){
	const ull B1=9973;
	const ull B2=100000007;
	
	ull t1=1;//B1???C???
	for(int i=0;i<C;i++) t1*=B1;
	//????????????hash????¨????
	for(int i=0;i<n;i++){
		ull e=0;
		for(int j=0;j<C;j++) e=e*B1+a[i][j];
		for(int j=0;C+j<=m;j++){
			temp[i][j]=e;
			e=e*B1-t1*a[i][j]+a[i][j+C];
		}
	}
	ull t2=1;//B2???R???
	for(int i=0;i<R;i++) t2*=B2;
	for(int j=0;j+C<=m;j++){
		ull e=0;
		for(int i=0;i<R;i++) e=e*B2+temp[i][j];
		for(int i=0;i+R<=n;i++){
			hashh[i][j]=e;
			e=e*B2-t2*temp[i][j]+temp[i+R][j];
		}
	}
}

void solve(){
	compute_hash(pattern,R,C);//pattern???hash???????±???????
	target=hashh[0][0];
	compute_hash(field,H,W);//field???hash???????±???????
	//target??¨?????´??????hash??????search
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(target==hashh[i][j])
			printf("%d %d\n",i,j);
		}
	}
}

int main(){
	scanf("%d %d",&H,&W);
	cin.ignore();
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			scanf("%c",&field[i][j]);
		}
		cin.ignore();
	}
	scanf("%d %d",&R,&C);
	cin.ignore();
	for(int i=0;i<R;i++){
		for(int j=0;j<C;j++){
			scanf("%c",&pattern[i][j]);
		}
		cin.ignore();
	}
	if(H>=R&&W>=C)
	solve();
}

Measured memory_bytes: 19804
from collections import Counter

N = int(input())
S = [0]*N
ht = Counter()
for i in range(N):
    S[i] = input()
    ht[S[i]] += 1
l = []
bc = -1
for kw, count in ht.most_common():
    if (bc != -1)and(bc != count):
        break
    l.append(kw)
    bc = count

l.sort()

for i in l:
    print(i)

Measured memory_bytes: 124924
# 反転させて扱いやすくしておく S[i]は10^iの個数を表すようになる
S = input()[::-1]

MOD = 10 ** 9 + 7
class modint:
    def __init__(self, x):
        self.x = x.x if isinstance(x, modint) else x % MOD
    def __str__(self): return str(self.x)
    __repr__ = __str__
    def __int__(self): return self.x
    __index__ = __int__
    def __add__(self, other): return modint(self.x + modint(other).x)
    def __sub__(self, other): return modint(self.x - modint(other).x)
    def __mul__(self, other): return modint(self.x * modint(other).x)
    def __pow__(self, other): return modint(pow(self.x, modint(other).x, MOD))
    def __floordiv__(self, other): return modint(self.x * pow(modint(other).x, MOD - 2, MOD))
    def __eq__(self, other): return self.x == modint(other).x
    def __ne__(self, other): return self.x != modint(other).x
    def __inv__(self): return pow(self.x, MOD - 2, MOD)

# 10^i%13を求める
def mod13_of_10pow(i):
    return [1, 10, 9, 12, 3, 4][i % 6]


# ans[k] : 13で割った余りがkになる数の個数
# 最後のans[5]が答えになる
ans = [modint(0)] * 13

for i, c in enumerate(S):
    if i == 0:
        if c != '?':
            ans[int(c)] += 1
        else:
            for q in range(10):
                ans[q] += 1
        continue

    tmp = [modint(0)] * 13

    m = mod13_of_10pow(i)
    ds = [int(c)] if c != '?' else [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    for d in ds:
        for k in range(13):
            tmp[(k + d * m) % 13] += ans[k]

    ans = tmp

print(ans[5])


Measured memory_bytes: 44444
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s=="RRR") cout << 3 << "\n";
  else if(s=="RRS"|| s=="SRR") cout << 2 << "\n";
  else if(s=="SSS") cout << 0 << "\n";
  else cout << 1 << "\n";
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int N;
    cin >> N;
    vector<vector<int>> graph(N);
    for(int i = 0; i < N - 1; ++i){
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[u].emplace_back(v);
        graph[v].emplace_back(u);
    }

    vector<double> dp(N);
    auto dfs = [&](auto&& self, int from = 0, int par = -1) -> double {
        double res = 0;
        for(int to : graph[from]){
            if(to == par)   continue;
            res += self(self, to, from);
        }
        int cnt = graph[from].size();
        if(par != -1)   --cnt;
        if(cnt != 0){
            res *= 1.0 / cnt;
            res += 1.0;
        }
        return dp[from] = res;
    };
    dfs(dfs);

    vector<double> dp2(N);
    auto rerooting = [&](auto&& self, int root = 0, int par = -1) -> void {
        for(int child : graph[root]){
            if(child == par)    continue;
            dp2[root] += dp[child];
        }
        double p = 1.0 / graph[root].size();
        dp2[root] *= p;
        dp2[root] += 1.0;
        for(int child : graph[root]){
            if(child == par)    continue;
            dp2[child] += (dp2[root] - p * dp[child] - 1.0) / p;
            if(graph[root].size() != 1){
                dp2[child] /= (int)graph[root].size() - 1;
                dp2[child] += 1.0;
            }
            self(self, child, root);
        }
    };
    rerooting(rerooting);

    cout << fixed << setprecision(10);
    for(int i = 0; i < N; ++i)  cout << dp2[i] << '\n';
}

Measured memory_bytes: 21840
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    vector<ll>l(n);
    vector<ll>d(n);
    rep(i,n){
        cin>>l[i];
        d[i]=-l[i];
    }
    sort(all(l));
    sort(all(d));
    ll cnt=0;
     rep(i,n-1){
        REP(j,i+1,n){
            auto itr=upper_bound(d.begin(),d.end(),-l[j]-l[i]);
            cnt+=max(0LL,(ll)(d.end()-itr-j-1));
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
// OURL: https://atcoder.jp/contests/agc035/tasks/agc035_a
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  auto as = make_v<ll>(3);
  auto cs = make_v<ll>(3);
  fill_v(as, -1);
  int cnt = 0;
  REP(i,N) {
    ll p;
    cin >> p;
    if (as[0] == p) {
      cs[0]++;
    } else if (as[1] == p) {
      cs[1]++;
    } else if (as[2] == p) {
      cs[2]++;
    } else {
      if (cnt < 3) {
        as[cnt] = p;
        cs[cnt] = 1;
        cnt++;
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  if (cs[0] == cs[1] && cs[1] == cs[2] && ((as[0] ^ as[1] ^ as[2]) == 0)) {
    cout << "Yes" << endl;
  } else if (cs[2] == 0 && ((as[0] == 0 && cs[0] * 2 == cs[1]) || (as[1] == 0 && cs[1] * 2 == cs[0]))) {
    cout << "Yes" << endl;
  } else if(cs[1] == 0 && cs[2] == 0 && as[0] == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
int main()
{
    int a,b;
    while (~scanf("%d %d", &a, &b)) {
        printf("%.10f\n", (double)a/b);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n,ans = 1e9;
   cin >> n;
   int x[n];
   for(int i=0;i<n;i++) cin >> x[i];
   for(int i=1;i<=100;i++){
       int cnt = 0;
       for(int j=0;j<n;j++){
         cnt += (x[j]-i)*(x[j]-i);
       }
       ans = min(ans,cnt);
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  // tokyo kyoto
  string a,b; // be is answer
  cin >> a >> b;
  bool yeah = false;
  if(a == b) yeah = true;
  
  for(int i = 0; b.size() > i; i++){
    char tmp = a.at(a.size() - 1);

    a = tmp + a.substr(0,a.size() - 1);
    if(a == b){
      yeah = true;
      break;
    }
  }
  if(yeah){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    vector<ll>ac(n+10,0),pen(n+10,0);
    for(ll u=0;u<m;u++)
    {
        ll num;
        string s;
        cin>>num>>s;
       if(s=="WA" && ac[num]==0)
       {
           pen[num]++;
       }
       if(s=="AC")
       {
           ac[num]=1;
       }
    }
    ll one=0,two=0;
    for(ll q=1;q<=n;q++)
    {
        one+=ac[q];
        if(ac[q]==1)
            two+=pen[q];
    }
    cout<<one;
    cout<<" ";
    cout<<two;
    return 0;
}


//252908XL

Measured memory_bytes: 1792
#include <string>
#include <iostream>

using namespace std;

int main()
{
	string S;

	getline(cin, S);

	for (string::size_type i = 0; i < (S.size() - 4); i++)
	{
		if (S.substr(i, 5) == "apple")
		{
			S.replace(i, 5, "peach"); i += 4;
		}
		else if (S.substr(i, 5) == "peach")
		{
			S.replace(i, 5, "apple"); i += 4;
		}
	}

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define repl(i, a, b) for(long long i = a; i < b; i++)
#define rrepl(i, a, b) for(long long i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
using pii = pair<int,int>;
using piii = pair<pii,int>;
using pll = pair<long long, long long>;
using plll = pair<pll, long long>;
// #pragma GCC optimize("Ofast")
// #define _GLIBCXX_DEBUG
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define isSquare(x) (sqrt(x)*sqrt(x) == x)
template<class T>inline bool chmax(T &a, const T &b) {if(a<b){a = b; return 1;} return 0; };
template<class T>inline bool chmin(T &a, const T &b) {if(a>b){a = b; return 1;} return 0; };
inline void in(void){return;}
template <typename First, typename... Rest> void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
// const int mod = 998244353;
const int INF = 1e9;
const long long INFLL = 1e18;
void iosetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
}
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
    os << p.first << " " << p.second;
    return os;
}
template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}
template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
    for(int i = 0; i < (int) v.size(); i++) {
        os << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return os;
}
template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
    for(T &in : v) is >> in;
    return is;
}
template<class T> vector<T> make_vec(size_t a) {return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S, T>& t){return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S, T>& t){return pair<S,T>(s.first-t.first, s.second-t.second);}
template<class S, class T> pair<S,T> operator*(const pair<S,T> &s, const S& t){return pair<S,T>(s.first*t, s.second*t);}
template <typename T> void Exit(T first){cout << first << endl;exit(0); };
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const pii dxy[4] = {pii(1,0), pii(0, 1), pii(-1, 0), pii(0, -1)};

//----------------------- edit from here ---------------------------------

int main(){
    iosetup();
    int n, m; cin >> n >> m;
    dsu d(n);
    rep(i, 0, m){
        int a, b; cin >> a >> b;a--, b--;
        d.merge(a, b);
    }
    cout << d.groups().size() - 1 << endl;
    

    return 0;
}

Measured memory_bytes: 8936
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;  
using namespace std;

typedef long long ll;

typedef tree<
pair <int, int>,
null_type,
less<pair <int, int>>,
rb_tree_tag,
tree_order_statistics_node_update>
os;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

const int N = 55;

int g[N][N];
int dp[N][N][2];
int n, m;

int get(int x, int y) {
  return x == 0 and y == 1;
}

int go(int x, int y, int last) {
  if(x == n - 1 and y == m - 1) {
    return get(last, g[x][y]);
  }
  if(dp[x][y][last] != -1) return dp[x][y][last];
  int gettis = get(last, g[x][y]);
  int cur = 1e9;
  if(x + 1 < n) cur = min(cur, gettis + go(x + 1, y, g[x][y]));
  if(y + 1 < m) cur = min(cur, gettis + go(x, y + 1, g[x][y]));
  return dp[x][y][last] = cur;
}

int main() {
  ll a, b, c; read(a, b, c);
  ll x, y; read(x, y);
  ll p = min(a + b, c + c);
  ll q = min(a, 2 * c);
  ll r = min(b, 2 * c);
  ll D = min(x, y);
  ll total = D * p;
  x -= D, y -= D;
  if(x) {
    total += q * x;
  }
  if(y) {
    total += r * y;
  }
  print(total);
}

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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}


 long long a,b,c,s,t,x,y,z;
 long long A,B,C,S,T,X,Y,Z;

 long long cnt;

 long double pi=3.14159265358979323846;

 string N,M;

unsigned long long D;

//long long mam(long long a, long long b){}

int main(){

	cin>>a;

	vector<ll> K(a);

	REP(i,a){
		cin>>K[i];
		x+=K[i];
	}

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

	if(x-K[a-1]>K[a-1]) cout<<"Yes";
	else cout<<"No";

	return 0;

}


Measured memory_bytes: 3628
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#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;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

#define GREATER "GREATER"
#define LESS "LESS"
#define EQUAL "EQUAL"

int main(int argc, char **argv) {
	string a, b;
	cin >> a >> b;
	if (a.length() > b.length()) cout << GREATER << endl;
	else if (a.length() < b.length()) cout << LESS << endl;
	else if (a == b) cout << EQUAL << endl;
	else if (a > b) cout << GREATER << endl;
	else cout << LESS << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
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; }
 
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 dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 
inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
 
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; int k; cin>>n>>k;
  double ans=0;
  reps(i,n){
    double tmp=1.0/n;
    double d=i;
    while(k>d){
      d*=2;
      tmp/=2.0;
    }
    ans+=tmp;
  }
  coutd(ans);
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

ll f(int n)
{
    ll ret = 0;
    for (int i = 0; i < n; i++)
        ret += i;
    return ret;
}

signed main()
{
    int n;
    vector<string> v;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        string tp;
        cin >> tp;
        vector<char> tmp;
        for (int j = 0; j < 10; j++)
        {
            tmp.push_back(tp[j]);
        }
        sort(all(tmp));
        char tmp2[10];
        for (int j = 0; j < 10; j++)
            tmp2[j] = tmp[j];
        string ret = tmp2;
        v.push_back(ret);
    }

    sort(all(v));

    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        // cout << "=" << i << endl;
        string tmp = v[i];
        int nn = 0;
        for (int j = i + 1; j <= n; j++)
        {
            // cout << tmp << ",," << v[j] << endl;
            if (j == n || v[j] != tmp)
            {
                nn = j - i;
                i = j - 1;
                // cout << "+" << nn << endl;
                break;
            }
        }
        cnt += f(nn);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	LL X, K, D;
	cin >> X >> K >> D;
	LL N=abs(X)/D;
	if(N>=K) cout << abs(abs(X)-K*D) << endl;
	else{
		if((K-N)%2==0) cout << abs(abs(X)-N*D) << endl;
		else cout << abs(abs(X)-(N+1)*D) << endl;
	}

	return 0;
}

Measured memory_bytes: 3620
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define all(x) x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(10)<<fixed
#define    debg(x)  cout<<"#x = "<<x<<"\n";
const    ld   PI=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}



int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{



ll n,x;
cin>>n>>x;
ll s=0;
int an=1;
while(n--)
{
	ll h;
	cin>>h;
	s+=h;
	if(s<=x)
	an++;
}

cout<<an;










}return 0;}

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

int main(){
    int N, D;
    cin >> N >> D;

    int canlook = 1 + D * 2;

    int ans;

    if (N % canlook == 0) ans = N / canlook;
    else ans = N / canlook + 1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <set>
#include <cstdio>
using namespace std;

int main(){
	int N;
	long long W,tV=0,tW=0,x=0;
	scanf("%d%lld",&N,&W);
	vector<pair<long long,long long> >v(N);
	for(int i=0;i<N;i++)scanf("%lld%lld",&v[i].first,&v[i].second),tV+=v[i].first,tW+=v[i].second;
	if(W>tW)W=tW;
	if(tW<2000000){
		vector<long long>bag(W+1);
		bag[0]=1;
		for(auto &e:v){
			x+=e.second;
			if(x>W)x=W;
			for(int j=x;j>=e.second;j--)if(bag[j-e.second]&&bag[j]<bag[j-e.second]+e.first)
				bag[j]=bag[j-e.second]+e.first;
		}
		for(int i=0;i<W;i++)bag[i+1]=max(bag[i+1],bag[i]);
		printf("%lld\n",bag[W]-1);
	}else if(tV<2000000){
		vector<long long>bag(tV+1);
		bag[0]=1;
		for(auto &e:v){
			x+=e.first;
			for(int j=x;j>=e.first;j--)if(bag[j-e.first]&&(!bag[j]||bag[j]>bag[j-e.first]+e.second))
				bag[j]=bag[j-e.first]+e.second;
		}
		int i=0,mi;
		for(;i<=tV;i++)if(bag[i]&&bag[i]-1<=W)mi=i;
		printf("%d\n",mi);
	}else if(N<=40){
		int n=N/2;
		set<pair<long long,long long> >se1,se2;
		for(int i=0;i<1<<n;i++){
			long long V=0,w=0;
			for(int j=0;j<n;j++)if(i&(1<<j))V+=v[j].first,w+=v[j].second;
			se1.emplace(w,V);
		}
		for(int i=0;i<1<<(N-n);i++){
			long long V=0,w=0;
			for(int j=0;j<(N-n);j++)if(i&(1<<j))V+=v[j+n].first,w+=v[j+n].second;
			se2.emplace(w,V);
		}
		for(auto it=se1.begin();it!=se1.end();){
			auto it2=it;
			for(++it2;it2!=se1.end()&&it->second>=it2->second;)it2=se1.erase(it2);
			++it;
		}
		for(auto it=se2.begin();it!=se2.end();){
			auto it2=it;
			for(++it2;it2!=se2.end()&&it->second>=it2->second;)it2=se2.erase(it2);
			++it;
		}
		long long r=0;
		for(auto &e1:se1){
			auto it=se2.lower_bound({W-e1.first+1,0});
			if(it!=se2.begin()){
				--it;
				r=max(r,e1.second+it->second);
			}
		}
		printf("%lld\n",r);
	}else{
		return 1;
	}
}

Measured memory_bytes: 133840