akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rep(i,x,y) for(int i=x;i<=y;++i)

const int INF=1<<30;
typedef long long ll;
using namespace std;

priority_queue<int,vector<int>,greater<int> >Q;
priority_queue<int>q;

const int maxn=300000+10;

ll L[maxn],R[maxn];

int a[maxn];

int main()
{
	int n;cin>>n;
	rep(i,1,n*3) scanf("%d",a+i);

	
	ll sum=0;
	rep(i,1,n) Q.push(a[i]),sum+=a[i]; L[n]=sum;
	rep(i,n+1,2*n)
	{
		if(a[i] > Q.top()) 
		{
			sum-=Q.top();Q.pop();
			sum+=a[i];Q.push(a[i]);
		}
		L[i]=sum;
	}

	
	sum=0;
	for(int i=n*3;i>n*2;--i) q.push(a[i]),sum+=a[i]; R[n*2+1]=sum;
	for(int i=n*2;i>n;--i){
		if(a[i]<q.top())
		{
			sum=sum-q.top()+a[i];
			q.pop();q.push(a[i]);
		}
		R[i]=sum;
	}

//	rep(i,1,n*3) printf("%lld ",L[i]);puts("");
//	rep(i,1,3*n) printf("%lld ",R[i]);puts("");

	ll ans=-1ll<<50;
	rep(i,n,2*n) ans=max(ans,L[i]-R[i+1]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5240
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007
\
int main() {
  int N;
  cin >>N;
  vector<int> A(N,0);
  int Boss;
  rep(i, N-1){
  cin >> Boss;
    A[Boss-1]++;
  }
  rep(i, N)
    cout <<A[i] << endl; 
  
}

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

class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String strArr[] = br.readLine().split(" ");
        int a = Integer.parseInt(strArr[0]);
        int b = Integer.parseInt(strArr[1]);

      	int c = a / b;
      	int d = a % b;
      	String e = String.format("%5f", 1.0 * a / b); 
      
        System.out.println(c + " " + d + " " + e);
    }
}


Measured memory_bytes: 24724
#include <iostream>

using namespace std;

int ans[20010];

int main(void) {
	int N;
	cin >> N;
	if (N == 3) {
		cout << "2 5 63" << endl;
	}
	else if (N == 4) {
		cout << "2 5 20 63" << endl;
	}
	else if (N == 5) {
		cout << "2 5 20 30 63" << endl;
	}
	else {
		int sum = 0;
		int num = 2;
		for (int i = 0; i < N; i++) {
			while (!(num % 2 == 0 || num % 3 == 0)) {
				num++;
			}
			ans[i] = num;
			sum += num % 6;
			sum %= 6;
			num++;
		}
		switch (sum % 6) {
		case 2:
			ans[4] = 30000;
			break;
		case 3:
			ans[5] = 30000;
			break;
		case 5:
			ans[5] = 30000 - 2;
			break;
		}
		for (int i = 0; i < N - 1; i++) {
			cout << ans[i] << " ";
		}
		cout << ans[N - 1] << endl;
	}
	//system("pause");
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second

mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = 1e9 + 7;

ll addmod(ll a, ll b) {
    return (a % MOD + b % MOD) % MOD;
}
ll mulmod(ll a, ll b) {
    ll res = 0;
    a %= MOD;
    b %= MOD;
    if (b > a) swap(a, b);
    while (b > 0) {
        if (b % 2) res = (res + a) % MOD;
        a = (a * 2) % MOD;
        b /= 2;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  
  	int n;
    cin >> n;
    vi a;
    for (int i = 0, j; i < n; i++) {
        cin >> j;
        if (i == 0) a.push_back(j);
        else if (j != a.back()) a.push_back(j);
    }

    n = a.size();
    vl dp(n);
    map<int, ll> ct;
    ct[a[0]]++;
    for (int i = 1; i < n; i++) {
        dp[i] = addmod(dp[i], dp[i - 1]);
        dp[i] = addmod(dp[i], ct[a[i]]);
        ct[a[i]] = addmod(ct[a[i]], dp[i - 1] + 1);
    }

    cout << addmod(dp[n - 1], 1) << endl;
}

/*
1 3 1 2 3 2 4
1   1
  3     3
      2   2

USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)    
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  string s; cin >> s;
  string ans;
  rep(i, s.size()) {
    switch(s[i]) {
    case'0':
    case'1':
      ans.push_back(s[i]);
      break;
    case 'B':
      if(ans.size()>0) {
	ans.erase(ans.size()-1);
      }
      break;
    }
  }

  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static int n;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        n = sc.nextInt();
        int[] cnt = new int[n + 1];
        Arrays.fill(cnt, 1);
        long ans = 0;
        for (int i = 2; i <= n; i++) {
            if (cnt[i] == 1) {
                for (int j = i; j <= n; j += i) {
                    int e = 0, tmp = j;
                    while (tmp % i == 0) {
                        tmp/=i;
                        e++;
                    }
                    cnt[j] *= (e + 1);
                }
            }
            ans += 1l*i * cnt[i];
        }
        out.println(ans+1);
        out.flush();
        out.close();
    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        Scanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int n) throws IOException {
            int[] ans = new int[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextInt();
            return ans;
        }
    }
}


Measured memory_bytes: 72116
n,m = map(int, input().split())
dat_n = []
dat_m = []
for i in range(n):
    a,b = map(int, input().split())
    dat_n.append((a, b))
for i in range(m):
    a,b = map(int, input().split())
    dat_m.append((a, b))
for i in range(n):
    a, b = dat_n[i]
    index = -1
    distance = 1000000001
    for j in range(m):
        c,d = dat_m[j]
        t = abs(a-c) + abs(b-d)
        if t < distance:
            index = j + 1
            distance = t
    print(index)


Measured memory_bytes: 39280
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
 
    vector<int> L1, L2;
    int last = -1e9;
    for(int i=0; i<N; i++){
        if(S[i] == 'o' && last+C < i){
            last = i;
            L1.push_back(i);
        }
        if(L1.size() == K) break;
    }
    int stock = 1e9;
    for(int i=N-1; i>=0; i--){
        if(S[i] == 'o' && stock >= C){
            L2.push_back(i);
            stock = 0;
        }else{
            stock++;
        }
        if(L2.size() == K) break;
    }
 
    reverse(L2.begin(), L2.end());
    for(int i=0; i<K; i++) if(L1[i] == L2[i]) cout << L1[i]+1 << endl;
    return 0;
}


Measured memory_bytes: 3448
import java.util.Scanner;

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

        int N = sc.nextInt();
        int K = sc.nextInt();

        System.out.println(solve(N, K));

        sc.close();
    }

    static int solve(int N, int K) {
        return (N % K == 0) ? 0 : 1;
    }
}

Measured memory_bytes: 35640
#include<stdio.h>
int main()
{
    int k,s,x,y,z,count;
    while(scanf("%d%d",&k,&s)!=EOF)
    {
        count=0;
        for(x=0;x<=k;x++)
        {
            for(y=0;y<=k;y++)
            {
                z=s-x-y;
                if(z>=0&&z<=k)
                {
                    count++;
                }
            }
        }
        printf("%d\n",count);
    }
    return 0;
    
}


Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

	fiveCount := 0
	sevenCount := 0

	for i := 0; i < 3; i++ {
		x := nextInt()
		if x == 5 {
			fiveCount++
		} else if x == 7 {
			sevenCount++
		}
	}

	if fiveCount == 2 && sevenCount == 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int N;
while(cin >> N) {
    if(N < 1000) cout << "ABC" << endl;
    else cout << "ABD" << endl;
}
return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

string s;vector<int> l;
int dp[110000][2];
signed main(){
  cin>>s;int n = s.length();
  l.resize(n);
  rep(i,n)l[i] = (int)(s[i]-'0');
  dp[0][0] = 1;dp[0][1] = 2;
  repd(i,1,n){
    add(dp[i][0], dp[i-1][0]*3);
    if(l[i] == 1)add(dp[i][0], dp[i-1][1]);
    add(dp[i][1], dp[i-1][1]*(l[i]+1));
  }
  cout << (dp[n-1][0] + dp[n-1][1]) % MOD << endl;
}


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

using namespace std;
typedef long long ll;
const int MAXN = 2000 + 4;
int n, k;
vector< int> adj[MAXN];
pair< int, int>  edd[MAXN];
int h[MAXN], par[MAXN];
bool mark[MAXN];

void dfs( int u){
	mark[u] = true;
	for( int i = 0; i < adj[u].size(); i ++){
		int v = adj[u][i];
		if(!mark[v]){
			h[v] = h[u] + 1;
			dfs( v );
		}
	}
	return;
	
}
 
void clnn(){
	for( int i = 0 ; i < n; i ++){
		mark[i] = false;
		h[i] = 0;
		par[i] = 0;
	}
	return;
}
 
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> k;
	int ans = n;
	for( int i = 0; i < n - 1 ; i ++){
		int a, b;
		cin >> a >> b;
		a --, b --;
		adj[a].push_back( b );
		adj[b].push_back( a );
		edd[i] = {a, b};
	}
	if(k % 2 == 0){
		for(int i = 0; i < n; i++){
			clnn();
			dfs(i);
			int tmp = 0;
			for(int j = 0 ; j < n; j++){	
				if(h[j] > k/2){
					tmp ++;
				}
			}
			ans = min(ans, tmp);
		}
	}
	else{
		for(int i = 0; i < n - 1; i ++){
			clnn();
			int a, b;
			a = edd[i].first;
			b = edd[i].second;
			mark[a] = true;
			mark[b] = true;
			dfs(a);
			dfs(b);
			int tmp = 0;
			for(int j = 0; j <  n; j++){	
				if(h[j] > k/2){
					tmp++;
				}
			}
			ans = min(ans, tmp);	
		}	
	}
	cout << ans << endl;
		
	
 
 
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		String s=scan.next();
		String p=scan.next();
		
		int m=s.length();
		
		for(int i=0;i<m;i++){
			if(s.charAt(i)==p.charAt(0)){
				int j;
				for(j=0;j<p.length();j++){
					if(s.charAt((i+j)%m) != p.charAt(j))
						break;
				}
				if(j==p.length()){
					System.out.println("Yes");
					return;
				}
				
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 26164
N,K=map(int,input().split())
MOD = 998244353
dp = [0]*(N*3)

LR = []
for _ in range(K):
    l, r = map(int, input().split())
    LR.append((l,r))

LR.sort()

imos = [0]*(N*3)
dp[1] = 1
imos[1] = 1
for i in range(1, N):
    if i >= 2:
        dp[i+1] += dp[i]

    for l, r in LR:
        dp[i+l] += dp[i]
        dp[i+l] %= MOD
        dp[i+r+1] -= dp[i]
        dp[i+r+1] %= MOD
    
    

print(dp[N]%MOD)



Measured memory_bytes: 82888
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n= scan.nextInt();
		if(n<=999) {
			System.out.println("ABC");
		}
		else {
			System.out.println("ABD");
		}
		
	}
}


Measured memory_bytes: 22868
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = INPUT()

    left, right = 0, S[1:].count('E')
    ans = left + right
    for i in range(N-1):
        if S[i] == 'W':
            left += 1
        if S[i+1] == 'E':
            right -= 1

        ans = min(ans, left + right)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10488
#include<iostream>
#include<stdio.h>

int main(){
	int i;
	char s[21];

	scanf("%s",s);
	for(i=0;s[i]!='\0';i++);
	if(i>0) i--;
	for(;i>=0;i--) std::cout<<s[i];
	std::cout<<std::endl;
	
	return 0;
	}

Measured memory_bytes: 1144
#include<iostream>
#include<string>
using namespace std;
int main(int argc, char const *argv[]) {
  int n=0;
  int ans=0;
  string  s;
  cin>>n;
  int a[n];
  cin>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='I'){
      a[i]=1;
    }else{
      a[i]=-1;
    }
  }
  for(int i=0;i<n-1;i++){
    a[i+1]+=a[i];
  }
  for(int i=0;i<n;i++){
    if(ans<=a[i]){
      ans=a[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> to(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--; b--;
        to[a]++;
        to[b]++;
    }
    rep(i,n){
        cout << to[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
    int n,count;
    char s[1000000];

    scanf("%d",&n);
    scanf("%s",s);

    for(int i=0;i<n;i++){
        while(s[i]==s[i+1]){
            i++;
        }
        count++;
    }
    printf("%d\n", count);

}

Measured memory_bytes: 256
n,m,*t=map(int,open(0).read().split())
e=[[]for _ in range(n+1)]
for a,b in zip(t[::2],t[1::2]):
    e[a].append(b)
    e[b].append(a)
f=[0]*-~n
f[1]=1
a=[1]
while 1:
    for v in e[a[-1]]:
        if not f[v]:
            f[v]=1
            a.append(v)
            break
    else:
        break
b=[1]
while 1:
    for v in e[b[-1]]:
        if not f[v]:
            f[v]=1
            b.append(v)
            break
    else:
        break
a=a[:0:-1]+b
print(len(a),*a)

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        string s;
        cin>>s;
        int n = s.length();
        for(int i=0;i<n;i++)if(s[i]=='?')s[i]='D';
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 3732
k,n=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for x in range(n-1):
  b=a[x+1]-a[x]
  ans=max(ans,b)
  
c=k-a[n-1]+a[0]

print(k-max(ans,c))



Measured memory_bytes: 32204
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().rstrip().split()))
A = sorted(A)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    
    return divisors

def main():
    if len(A) <= 2:
        print(max(A))
        exit()
    else:
        all_divisors = list(set(make_divisors(A[0]) + make_divisors(A[1])))

    ans = 1
    for divisor in all_divisors:
        cnt = 0
        for a in A:
            if a % divisor != 0:
                cnt += 1
            if cnt == 2:
                break
        if cnt < 2:
            ans = max(ans, divisor)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14428
using System;
using System.Linq;

namespace ABC163
{
    class B
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var ans = NM[0] - A.Sum();
            if (0 <= ans) Console.WriteLine(ans);
            else Console.WriteLine(-1);
        }
    }
}


Measured memory_bytes: 29216
#include <iostream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;


int main() {
	int n, m;
	cin >> n >> m;
	if (n < m) {
		for (int i = 0; i < m; ++i)
			cout << n;
	}
	else {
		for (int i = 0; i < n; ++i)
			cout << m;
	}
 	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ll MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll N,K;
    string s;
    cin>>N>>K>>s;
    
    VEC(ll,w,0);
    w.push_back(0);
    bool sf=false,ssf=false,ss0f=false;
    ll cnt=0;
    REP(i,N){
        sf=s[i]=='1';
        if(sf){
            if(ss0f){
                w.push_back(cnt);
                //s(cnt);
            }
            ssf=true;
            ss0f=false;
            cnt++;
        }else{
            if(ssf){
                w.push_back(cnt);
                //s(cnt);
            }
            ssf=false;
            ss0f=true;
            cnt++;
        }
    }
    w.push_back(cnt);
    //sl(cnt);
    
    ll m=0;
    sf=s[0]=='1';
    if(w.size()/2<=K){
        cout<<w[w.size()-1];return 0;
    }
    if(sf){
        FOR(i,1,w.size()-K*2){
            //sl(i+K*2,i-1)
            m = max(m,w[i+K*2]-w[i-1]);
            i++;
        }
    }else{
        m = max(m,w[K*2]-w[0]);
        FOR(i,2,w.size()-K*2){
            //sl(i+K*2,i-1)
            m = max(m,w[i+K*2]-w[i-1]);
            i++;
        }
    }
    if(s[s.length()-1]=='0'){
        m = max(m,w[w.size()-1]-w[w.size()-1-K*2]);
    }
    cout<<m;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1528
n = int(raw_input())
arr = map(int, raw_input().split())

tri = n * (n + 1) / 2
s = sum(arr)

if s % tri != 0:
    print "NO"
else:
    num = s / tri
    diff = map(lambda i: arr[(i + 1) % n] - arr[i], range(n))
    diff = map(lambda x: x - num, diff)
    poss = all(map(lambda x: x <= 0 and x % n == 0, diff))
    poss = poss and sum(diff) == -n * num
    print "YES" if poss else "NO"


Measured memory_bytes: 12236
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int mx=max(a,max(b,c));
	int res;
	if(mx==a)
	{
		while(k--)
		{
			a=2*a;
		}
		res=a+b+c;
	}
	else if(mx==b)
	{
		while(k--)
		{
			b=2*b;
		}
		res=a+b+c;
	}
	else
	{
		while(k--)
		{
			c=2*c;
		}
		res=a+b+c;
	}
	
	cout<<res<<"\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b=sc.nextInt(), h=sc.nextInt(), m=sc.nextInt();
		final double ji = 0.5, fun = 6.0;
		double now_ji =ji*(h*60+m), now_fun=fun*m;
		if(now_ji==now_fun) {
			System.out.println(Math.abs(a-b));
		}else {
			double dis = Math.abs(now_ji-now_fun)*Math.PI/180;
			double ans = Math.sqrt(a*a+b*b-2*a*b*Math.cos(dis));
			System.out.printf("%.10f\n",ans);
		}
	}
}


Measured memory_bytes: 36144
#include <stdio.h>
int main(void)
{
	int a;
	int b;
	
	scanf("%d %d", &a, &b);
	
	if (a > b) {
		printf("a > b\n");
	}
	else if (a < b) {
		printf("a < b\n");
	}
	else {
		printf("a == b\n");
	}
	
	return (0);
}

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

int main(){
	string s; cin >> s;
	ll k; cin >> k;
	ll po[26] = {};
	string ans;
	for(ll i = 1; i < 26; ++i) po[i] = 26 - i;
	ll dp[s.size()] = {po[s[0] - 'a']};
	for(ll i = 1; i < s.size(); ++i){
		dp[i] = dp[i - 1] + po[s[i] - 'a'];
		if(dp[i] > k){
			k -= dp[i - 1];
			for(ll j = 0; j < i; ++j) ans += 'a';
			for(ll j = i; j < s.size(); ++j){
				if(k >= po[s[j] - 'a']){
					k -= po[s[j] - 'a'];
					ans += 'a';
				}else{
					ans += s[j];
				}
			}
			if(k){
				ans[s.size() - 1] += k % 26;
				if(ans[s.size() - 1] > 'z') ans[s.size() - 1] = 'a' + ans[s.size() - 1] - 'z' - 1;
			}
			break;
		}
	}
	if(ans.empty()){
		for(ll i = 0; i < s.size() - 1; ++i) ans += 'a';
		k -= dp[s.size() - 1];
		k %= 26;
		ans += 'a' + k;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
int main()
{
    int n;
	ll k;
	cin>>n>>k;
	ll c[100010];
	ll ans=0;
	for(int i=k; i>=1; i--){
		c[i]=powmod(k/i, n);
		for(int j=2*i; j<=k; j+=i){
			(c[i]+=MOD-c[j])%=MOD;
		}
		(ans+=c[i]*i)%=MOD;
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4336
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    A = [int(i) for i in input().split()]
    A.sort()
    B = [True]*(10**6+1)

    from collections import Counter
    c = Counter(A)
    bl = set()
    for k, v in c.items():
        if v >= 2:
            bl.add(k)

    ans = 0
    for a in set(A):
        if a not in bl and B[a]:
            ans += 1
        for i in range(1, 10**6):
            if 10**6 < a*i:
                break
            B[a*i] = False
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 137004
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

from collections import deque

n=I()
s=deque()
abc=[chr(i) for i in range(97,123)]
sub=26
while n>0:
    dg=n%26
    n//=26
    if dg==0:
            n-=1
    s.appendleft(abc[dg-1])
for i in s:
    print(i,end="")
print()

Measured memory_bytes: 9468
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int N;
    char S[105];
    scanf("%d",&N);
    scanf("%s",S);
    int i;

    if(N%2!=0)
    {
        printf("No");
    }
    else
    {
        int bn=N/2;
        for(i=0; i<bn; i++)
        {
            if(S[i]!=S[i+bn])
            {
                printf("No");
                return 0;
            }
        }
        printf("Yes");

    }
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int n,A[50];

int solve(int i, int m){
  if(m == 0)return 1;
  if(i >= n)return 0;
  int res = solve(i + 1, m) || solve(i + 1,m - A[i]);
  return res;
}

int main(){
  int q,M,i;

  scanf("%d",&n);
  for(i = 0; i < n; i++)scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&M);
    if(solve(0,M))printf("yes\n");
    else printf("no\n");
  }

  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<class Z> Z gcd(Z a, Z b) {
  while (b) swap(a %= b, b);
  return a;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (auto&& e : a) cin >> e;
  auto f = [&](const auto& f, V<> a) -> bool {
    int s = 0;
    for (int i = 0; i < n; ++i) {
      s ^= a[i] - 1 & 1;
    }
    if (s) return true;
    int odd = count_if(begin(a), end(a), [](int x) { return x & 1; });
    if (odd != 1) return false;
    for (int i = 0; i < n; ++i) if (a[i] & 1) {
      if (a[i] == 1) return false;
      --a[i];
    }
    int g = accumulate(begin(a), end(a), 0, gcd<int>);
    for (auto&& e : a) e /= g;
    return !f(f, a);
  };
  cout << (f(f, a) ? "First" : "Second") << '\n';
}

Measured memory_bytes: 10112
package main

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

func main() {
	badge := []string{"AAA", "AA", "A", "B", "C", "D", "E"}
	badgeLen := len(badge)
	short := []float64{35.5, 37.5, 40, 43, 50, 55, 70}
	long := []float64{71, 77, 83, 89, 105, 116, 148}

	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		time := strings.Split(stdin.Text(), " ")

		sT, _ := strconv.ParseFloat(time[0], 64)
		lT, _ := strconv.ParseFloat(time[1], 64)

		sR, lR, t := 0, 0, 0.0
		for _, t = range short {
			if sT < t {
				break
			}
			sR++
		}
		for _, t = range long {
			if lT < t {
				break
			}
			lR++
		}
		rank := ""
		if sR >= badgeLen || lR >= badgeLen {
			rank = "NA"
		} else if sR >= lR {
			rank = badge[sR]
		} else {
			rank = badge[lR]
		}
		fmt.Println(rank)
	}
}


Measured memory_bytes: 1104
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

signed main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    PRINT(max(max(a * c, a * d), max(b * c, b * d)));
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
vector <char> str;
int dp[3005][3005];
string s, t;
int slen, tlen;
int main(){
    getline(cin, s);
    getline(cin, t);
    slen = s.length();
    tlen = t.length();
    for(int i = 0 ; i<= tlen ; i++){
        for(int j = 0 ; j<=slen ; j++){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
                continue;
            }
            if(t[i-1] == s[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    int i = tlen, j = slen;
    while(i > 0 && j > 0){
        if(t[i-1] == s[j-1]){
            str.push_back(t[i-1]);
            i--;
            j--;
            
        }
        else{
            if(dp[i-1][j] > dp[i][j-1]){
                i--;
            }
            else j--;
        }
    }
    reverse(str.begin(), str.end());
    for(auto i : str) cout << i;
}

Measured memory_bytes: 38268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

int n, q;
vector<vi> g(2e5+10);
vl c(2e5+10);
vl ans(2e5+10);

void dfs(int i, int p, int co) {
//  cerr << i << " " << p << " " << co << endl;
  co += c[i];

  ans[i-1] += co;

  for (auto&& j : g[i]) {
    if (j != p) {
      dfs(j, i, co);
    }
  }
}

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

  cin >> n >> q;
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  rep(i, q) {
    int a, b;
    cin >> a >> b;

    c[a] += b;
  }

  dfs(1, 0, 0);

  rep(i, n) {
    cout << ans[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 25856
N,M,K=map(int,input().split())
pr=998244353
MAX_NUM = 2*10**5 + 5
fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]
fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % pr
    inv[i] = pr - inv[pr%i] * (pr // i) % pr
    finv[i] = finv[i-1] * inv[i] % pr
def c(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % pr) % pr
a=0
for i in range(K+1):
    a=(a+M*pow(M-1,N-1-i,pr)*c(N-1,i))%pr
print(a)

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

int main()
{
  int a = 0;
  string s;
  cin >> s;
  if (s[0] == '1') a++;
  if (s[1] == '1') a++;
  if (s[2] == '1') a++;
  cout << a << endl;
}


Measured memory_bytes: 256
/*
                    Author: Ankit Kaul
    **********************Code Belongs to Respective Author Only************************************
    */
    /*#pragma GCC optimize("O3")
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
    #include <bits/stdc++.h>
    #define endl       '\n'
    #define PI          3.141592653589
    #define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #define M           1000000007
    #define int         long long int
    #define inf         INT_MAX
    #define pb          emplace_back
    #define pf          emplace_front
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
    #define mi          map<int,int>
    #define mii         map<pii,int>
    #define all(a)      (a).begin(),(a).end()
    #define rall(a)     (a).rbegin(),(a).rend()
    using namespace std;
    int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
    int power(int x,int n){
        int result=1;
        while(n>0)
        {   if(n % 2 ==1)
            result=(result * x) % M;
            x=(x*x)% M;
            n=n/2;
        }
    return result % M;
    }      
    bool isPrime(int n) 
    { 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
    } 
    signed main()
    {   jaldi
        int n,x;
        cin>>n>>x;
        if(n>=10)
        cout<<x;
        else
        cout<<x+((10-n)*100);        
    }   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int l[N],r[N],a[N];
int col[3],cnt[3],id[3];
char s[N]; 
signed main(){
	cin>>(s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n;++i)
		l[i]=i-1,r[i]=i+1;
	r[0]=1; l[n+1]=n; 
	for(int i=1;i<=n;++i)
		cnt[s[i]-'A']++;
	if(!(cnt[0] && cnt[1] && cnt[2])) return 0;
	for(int i=n-1;i>=1;--i)
		if(s[i]==s[i+1]) r[i]=r[i+1],l[r[i]]=i;
	for(int i=0;i<3;++i)
		col[i]=i,cnt[i]=0;
	for(int i=r[0];i<=n;i=r[i])
		cnt[s[i]-'A']++;
	sort(col,col+3,[](int x,int y){return cnt[x]<cnt[y];});
	for(int i=0;i<3;++i)
		id[col[i]]=i,cnt[i]=0;
	for(int i=1;i<=n;++i)
		a[i]=id[s[i]-'A'];
	a[0]=a[n+1]=3;
	for(int i=r[0];i<=n;i=r[i])
		cnt[a[i]]++;
	for(int i=r[0];i<=n;i=r[i])
		if(cnt[2]>cnt[1] && a[i]==2 && a[l[i]]!=a[r[i]]){
			cnt[2]--;
			l[r[i]]=l[i];
			r[l[i]]=r[i];
		}
	for(int i=r[0];i<=n;i=r[i])
		if(cnt[2]>cnt[1] && a[l[i]]==0 && a[r[i]]==0 && a[i]==2){
			cnt[2]--;cnt[0]--;
			r[l[i]]=r[r[i]];
			l[r[r[i]]]=l[i];
		}
	for(int i=0;i<=n;i=r[i])
		if(cnt[2]>cnt[0] && (i==0 || a[i]==0)){
			while(cnt[2]>cnt[0] && a[r[i]] && a[r[r[i]]] && a[r[r[r[i]]]] && a[r[i]]+a[r[r[i]]]==3){
				cnt[1]--;cnt[2]--;
				l[r[r[r[i]]]]=i;
				r[i]=r[r[r[i]]];
			}
		} 
	for(int i=r[0];i<=n;i=r[i])
		cout<<char(col[a[i]]+'A');
	return 0;
}

Measured memory_bytes: 16280
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string str;
	cin >> str;
    if(str == "abc" || str == "acb" || str == "bac" || str == "bca" || str == "cab" || str == "cba")
	    {
	    	cout << "Yes" << endl;
		}
		else
		    {
		    	cout << "No" << endl;
			}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

    string s; cin>>s;
    int q; cin>>q;
    bool head = true;
    vector<char> h, t;
    while(q--){
        int x; cin>>x;
        if(x == 1){
            if(head) head = false;
            else head = true;
        }
        else{
            int f; cin>>f;
            char c; cin>>c;
            if(f == 1){
                if(head) h.emplace_back(c);
                else t.emplace_back(c);
            }
            else{
                if(head) t.emplace_back(c);
                else h.emplace_back(c);
            }
        }
    }

    // h reverse
    reverse(h.begin(), h.end());

    string ans = "";
    for(auto i : h) ans += i;
    ans += s;
    for(auto i : t) ans += i;

    if(head){
        cout << ans << endl;
    }
    else{
        reverse(ans.begin(), ans.end());
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1448
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, D) = Read2Longs();
            var count = 0;
            for(var i = 0; i < N; i++)
            {
                var (x, y) = Read2Longs();
                if(x*x + y*y <= D * D)
                {
                    count++;
                }
            }
            return count;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 41392
#include<stdio.h>
 
static const int N = 1000;
 
void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}
 
int main(){
  int n, i, j, key;
  int A[N+1];
  scanf("%d", &n);
 
  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
   
  trace(A, n);
 
  for(i = 2; i <= n; i++){
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
    }
    trace(A, n);
  }
 
  return 0;
}

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

string check(string str) {
    int n;
    while((n = str.find("Hoshino")) != string::npos) {
        str[n + 6] = 'a';
    }
    return str;
}

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

    string line;
    getline(cin, line);

    for (int i = 0; i < n; i++) {
        getline(cin, line);
        cout << check(line) << endl;
    }
}

Measured memory_bytes: 1216
#Coins
n=int(input())
p=list(map(float,input().split()))
dp=[[0]*(n+1) for _ in range(n)]
dp[0][0]=1-p[0]
dp[0][1]=p[0]
a=1-p[0]
for i in range(1,n):
    a*=1-p[i]
    dp[i][0]=a
for i in range(1,n):
    for j in range(1,i+2):
        dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i]
sum=0
for i in range(n//2+1,n+1):
    sum+=dp[n-1][i]
print(sum)

Measured memory_bytes: 311176
#pragma GCC optimize(2)
#include<iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <cstring>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <map>
#include <unordered_map>
#include <vector> 
#include <bitset>
#include <cctype>
#include <set>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN = 205;
const int MAXM = 50005;
const int MOD = 1e9+7;

#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mst(X,Y) memset(X,Y,sizeof(X)) 
#define rep(i, a, n) for (int i=(a); i<=(n); i++)
#define per(i, a, n) for (int i=(a); i>=(n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) { cerr << " " << to_string(H);    debug_out(T...);}
template <typename T> inline T max(T a, T b, T c) { return max(max(a, b),c); }


int main()
{closeSync;
#ifdef DEBUG
	// freopen("C:/Users/86159/Desktop/a2.in.txt", "r", stdin);
	// freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif  
	string str;
	cin>>str;
	if (str=="SSS")
		cout<<"0\n";
	else if (str=="RSS")
		cout<<"1\n";
	else if (str=="SRS")
		cout<<"1\n";
	else if (str=="SSR")
		cout<<"1\n";
	else if (str=="RRS")
		cout<<"2\n";
	else if (str=="RSR")
		cout<<"1\n";
	else if (str=="SRR")
		cout<<"2\n";
	else if (str=="RRR")
		cout<<"3\n";
    return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace Collections
{
	class program
	{
    //static long MAX_LONG = 5000000000000000;
		static void Main(string[] args)
		{

			// 入力
      //int[] input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
			string S = Console.ReadLine();
			string T = Console.ReadLine();

			int ret = 0;
			if(S[0] == T[0])
				ret++;

			if(S[1] == T[1])
				ret++;


			if(S[2] == T[2])
				ret++;


			Console.WriteLine(ret + "");
    }
	}
}


Measured memory_bytes: 13140
import sys

input = sys.stdin.readline

n, m = map(int, input().split())
mod = 10 ** 9 + 7
broken_steps = [False for _ in range(n)]

for _ in range(m):
    a = int(input())
    broken_steps[a - 1] = True

steps = [0 for _ in range(n + 1)]
steps[0] = 1

for i in range(n):
    if not broken_steps[i]:
        steps[i + 1] = (steps[i] + steps[i - 1]) % mod

print(steps[n])


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin>>n>>m;
    int a[m+1];
    int sum = 0;
    for(int i=0; i<m; i++){
        cin>>a[i];
        sum += a[i];
    }
    if(sum < n){
        cout<< n-sum << "\n";
    }
    else if(sum == n){
        cout<<"0\n";
    }
    else{
        cout << "-1\n";
    }

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k;
    cin>>n>>k;
    vector<ll>dp(n,INT_MAX);
    vector<ll>A(n);
    for (ll i = 0;i<n;i++){
        cin>>A[i];
        if (i==0){dp[i] = 0;continue;}
        ll cnt = 0;
        while (cnt<=k && i>=cnt){
            dp[i] = min(abs(A[i-cnt]-A[i])+dp[i-cnt],dp[i]);
            cnt++;
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int n,A[50];

int solve(int i,int m){
	if( m == 0 )return 1;
	if( i >= n )return 0;
	int res = solve(i+1,m)||solve(i+1,m-A[i]);
	return res;
}

int main(){
	int q,M,i;
	
	scanf("%d",&n);
	for( i = 0; i < n; i++ )scanf("%d",&A[i]);
	scanf("%d",&q);
	for( i = 0; i < q; i++ ){
		scanf("%d",&M);
		if( solve(0, M) )printf("yes\n");
		else printf("no\n");
	}
	
	return 0;
}


Measured memory_bytes: 2124
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;

int main(){
    int ma;
    while(scanf("%d",&ma),ma){
        int n;
        scanf("%d",&n);
        int stage[256]={0};
        bool D[300][300]={{0}};
        reps(i,1,n+1)scanf("%d",&stage[i]);
        rep(i,n+1){
            reps(j,1,ma+1){
                /*行先i+j*/
                if(stage[i+j]==0)D[i][i+j]=1;
                else if(stage[i+j]>=1)D[i][min(i+j+stage[i+j],n+1)]=1;
                else if(stage[i+j]<=-1)D[i][max(0,i+j+stage[i+j])]=1;
            }
        }
        /*WarshallFloyd*/
        rep(k,n+2){
            rep(i,n+2){
                rep(j,n+2){
                    if(D[i][k] && D[k][j]) D[i][j] = 1;
                }
            }
        }
        bool f = true;

        rep(i,n+1)if(D[0][i] && !D[i][n+1])f =false;
        printf("%s\n",(f) ? "OK" : "NG");
    }
	return 0;
}

Measured memory_bytes: 1264