akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int *p,*n,*ans,m;

void sort(){
	int tmp;
	for(int i=m; i>0; i--){
		for(int k=0; k<i-1; k++){
			if(p[ans[k]] < p[ans[k+1]] || (p[ans[k]] == p[ans[k+1]] && n[ans[k]] > n[ans[k+1]])){
				tmp = ans[k];
				ans[k] = ans[k+1];
				ans[k+1] = tmp;
			}
		}
	}
}

int main(){
	int pin1,pin2,game,thr;
	bool sp,st1,st2;
	while(true){
		cin >> m;
		if(!m)
			return 0;
		p = new int[m];
		n = new int[m];
		ans = new int[m];
		for(int i=0; i<m; i++){
			sp = false;
			st1 = false;
			st2 = false;
			game = 1;
			cin >> n[i];
			p[i] = 0;
			ans[i] = i;
			while(true){
				cin >> pin1;
				if(sp){
					p[i]+=pin1;
					sp = false;
				}
				if(st2){
					p[i] += pin1;
					st2 = false;
				}
				if(st1){
					p[i] += pin1;
					st2 = true;
					st1 = false;
				}
				if(pin1 == 10){
					st1 = true;
				}else{
					cin >> pin2;
					if(st2){
						p[i] += pin2;
						st2 = false;
					}
					pin1 += pin2;
					if(pin1 == 10)
						sp = true;
				}
				p[i] += pin1;
				game++;
				if(game == 10){
					cin >> pin1;
					if(sp){
						p[i] += pin1;
					}
					if(st2){
						p[i] += pin1;
						st2 = false;
					}
					if(st1){
						p[i] += pin1;
						st2 = true;
					}
					p[i] += pin1;
					if(pin1 == 10){
						cin >> pin1;
						if(st2)
							p[i] += pin1;
						p[i] += pin1;
						cin >> pin1;
						p[i] += pin1;
					}
					else{
						cin >> pin2;
						if(st2)
							p[i] += pin2;
						p[i] += pin2;
						if(pin1 + pin2 == 10){
							cin >> pin1;
							p[i] += pin1;
						}
					}
					break;
				}
			}
		}
		sort();
		for(int i=0; i<m; i++)
			cout << n[ans[i]] << ' ' << p[ans[i]] << endl;
		delete[] n;
		delete[] p;
		delete[] ans;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
signed main(signed argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    int min=1e9+7,cnt=0;
    rep(i,n){
        int a;
        cin>>a;
        if(a<min){
            cnt=i+1;
            min=a;
        }
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 3184
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll l,r,lmod,rmod;
  cin >> l >> r;

  bool flg = false;
  ll ans = LLONG_MAX;
  for(ll i = l; i <= r;i++)
  {
    if(i % 2019 == 0)
    {
      cout << 0 << endl;
      return 0;
    }
    for(ll j = i + 1; j <= min(i + 2020,r);j++)
    {
      ans = min(ans, (i % 2019 * j % 2019)% 2019);
    }
  }  

  cout << ans << endl;
  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  char li ;
  cin >> li ;
  if(li=='a' || li=='i' || li=='u' || li=='e' || li=='o'){
    cout <<"vowel"<<endl ;
  }
  else{
    cout <<"consonant"<<endl ;
  }
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <string>

int main() {
  std::string s;
  std::cin >> s;
  std::list<bool> li;
  for (auto c : s) li.push_back(c=='1');
  for (auto itr = li.begin(); itr != li.end(); ) {
    if (itr != li.begin() && *std::prev(itr) != *itr) {
      li.erase(std::prev(itr));
      itr = li.erase(itr);
    } else {
      if (std::next(itr) != li.end() && *std::next(itr) != *itr) {
        li.erase(std::next(itr));
        itr = li.erase(itr);
      } else itr++;
    }
  }
  std::cout << s.size()-li.size() << std::endl;
}


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

using namespace std;

int n,m;

void solve(){
    int i,j;
    string str;
    cin >> n >> m;
    vector<int> accepted(n+1,0),wronged(n+1,0);
    int ac = 0,wa = 0;
    for(i = 0;i < m;i++){
        cin >> j >> str;
        if(str == "AC"){
            if(accepted[j] == 0){
                accepted[j] = 1;
                ac++;
            }
        }
        else if(accepted[j] == 0) wronged[j]++;
    }
    for(i = 1;i <= n;i++) if(accepted[i]) wa += wronged[i];
    long long ans = 0;
    cout << ac << ' ' << wa << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    println!("{}", (n - 2) / (k - 1) + 1);
}


Measured memory_bytes: 4352
#include <stdio.h>

int main()
{
    int n,x,t;
    scanf("%d %d %d",&n,&x,&t);
    if(n%x!=0)
    {
        printf("%d",((n/x)*t+t));
    }
    else
    {
        printf("%d",(n/x)*t);
    }

    return 0;
}


Measured memory_bytes: 1704
import itertools
 
n = int(input())
 
 
data = [[] for i in range(5)]
# print(data)
for i in range(n):
    tmp = str(input())
    if tmp[0] == "M":
        data[0].append(tmp)
    elif tmp[0] == "A":
        data[1].append(tmp)
    elif tmp[0] == "R":
        data[2].append(tmp)
    elif tmp[0] == "C":
        data[3].append(tmp)
    elif tmp[0] == "H":
        data[4].append(tmp)
 
ans = 0
for i, j, k in itertools.combinations([0, 1, 2, 3, 4], 3):
    ans += len(data[i])*len(data[j])*len(data[k])
print(ans)

Measured memory_bytes: 16396
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=1000000+19;
const int p=998244353;

int Pow(int a,int b){
	int res=1;
	for (;b;b>>=1,a=1ll*a*a%p) if (b&1) res=1ll*res*a%p;
	return res;
}

int fac[N],inv[N];
int n,m,ans,tmp,v1,v2;

int cal(int n,int m){
	return 1ll*fac[n+m]*inv[n]%p*inv[m]%p;
}
int cal2(int x1,int y1,int x2,int y2){
	if (x1>x2||y1>y2) return 0;
	return cal(x2-x1,y2-y1);
}

int main(){
	fac[0]=1;
	For(i,1,N) fac[i]=1ll*fac[i-1]*i%p;
	inv[N-1]=Pow(fac[N-1],p-2);
	for (int i=N-1;i;i--) inv[i-1]=1ll*inv[i]*i%p;
	n=IN(),m=IN();
	v1=cal(n-1,m);
	v2=cal(n,m-1);
	For(i,1,n+m+1){
		tmp=(0ll+tmp+v1+v2)%p;
		if (i&1){
			v1=(v1-1ll*cal2(0,0,i/2,i/2)*cal2(i/2,i/2+1,n-1,m)%p+p)%p;
			v2=(v2-1ll*cal2(0,0,i/2,i/2)*cal2(i/2+1,i/2,n,m-1)%p+p)%p;
		} else{
			v1=(v1+1ll*cal2(0,0,i/2-1,i/2)*cal2(i/2,i/2,n-1,m)%p+p)%p;
			v2=(v2+1ll*cal2(0,0,i/2,i/2-1)*cal2(i/2,i/2,n,m-1)%p+p)%p;
		}
		//printf("tmp[%d]=%d\n",i,tmp);
		ans=(ans+1ll*tmp*Pow(i,p-2))%p;
	}
	ans=1ll*ans*Pow(cal(n,m),p-2)%p;
	printf("%d\n",ans);
}

Measured memory_bytes: 8064
#-*- coding:utf-8 -*-

N, M = map(int, input().split())
hsh = {}
for i in range(M):
    hsh[int(input())] = True

acc = [0]*(N+1)
acc[0] = 1

for i in range(1,N+1):
    d = 0
    if i > 1 and i-2 not in hsh:  # 2段前が穴ではない
        if i-1 not in hsh:  # 1段前が穴ではない
            d += acc[i-1] + acc[i-2]
        else: 
            d += acc[i-2]
    else:  # 2段前が穴
        if i-1 not in hsh: # 1段前が穴ではない
            d += acc[i-1]
        else:
            d = 0
    acc[i] = d

# print(hsh)
# print(acc)
print(acc[-1]%1000000007)


Measured memory_bytes: 462708
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <tuple>
#define FOR0(var, max) for (ui (var) = 0; (var) < (max); ++(var))
#define FORINV(var, min, max) for (ui (var) = (max) - 1; (var) + 1 > (min); --(var))

using namespace std;

template <class T>
decltype(auto) max(const multiset<T>& s) {
  return max_element(s.begin(), s.end());
}

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

const static ui NMAX = 18;
const static ui SiMAX = 1<<18;
const static ui SMAX = 1000000000;

static ui N;
static multiset<ui> Si;

bool solve(void) {
  multiset<ui> confirmed;
  multiset<ui> remain = Si;

  auto first = max(remain);
  confirmed.insert(*first);
  remain.erase(first);

  FOR0(i, N) {
    multiset<ui> next;

    for (auto it = confirmed.rbegin(); it != confirmed.rend(); it++) {
      auto max_elem = *it;
      auto t = remain.lower_bound(max_elem);
      if (t == remain.begin()) { // nothing possible slime
        return false;
      }
      t = prev(t);
      next.insert(*t);
      remain.erase(t);
    }

    for (auto it = next.begin(); it != next.end(); it++) {
      confirmed.insert(*it);
    }
  }

  return confirmed.size() == Si.size();
}

int main(void) {
  cin >> N;
  FOR0(i, (1U << N)) {
    ui t;
    cin >> t;
    Si.insert(t);
  }
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 30976
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(void)
{
	int a, b, c;

	cin >> a >> b >> c;

	if (a < b)
	{
		if(b < c)
		{
			cout << "Yes" << endl;
			exit(0);
		}
	}
	cout << "No" << endl;
	
	return 0;
}

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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		// solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public boolean hasNext() {
		// return cnt < N;
		return cnt < 3;
	}

	String ans = "";

	public void readBody(String str) {
		// System.out.println(str);
		ans = ans + str.charAt(cnt);
		cnt++;
	}

	public void solve() {
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include <iostream>

using namespace std;

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	int left = A + B;
	int right = C + D;

	if (left > right) {
		cout << "Left" << endl;
	}
	else if (left == right) {
		cout << "Balanced" << endl;
	}
	else if (left<right) {
		cout << "Right" << endl;
	}

}





Measured memory_bytes: 3652
#include<stdio.h>
#include<math.h>
#define PI 3.141592654
int main()
{double a,b,C,c,s;
double S,L,h;
scanf("%lf%lf%lf",&a,&b,&C);
c=sqrt(a*a+b*b-2*a*b*cos(C*PI/180));
L=a+b+c;
s=L/2;
S=sqrt(s*(s-a)*(s-b)*(s-c));
h=(S*2)/a;
printf("%.8lf\n%.8lf\n%.8lf\n",S,L,h);
return 0;


}



Measured memory_bytes: 2060
#include <iostream>
#include <cstring>
#define ll long long
using namespace std;
int n, p, value[105];
ll memo[55][5005];
ll calculate(int i, ll sum){
    if(memo[i][sum]!=-1)return memo[i][sum];
    if(i>n){
        if(sum%2== p)return 1;
        else return 0;
    }
    ll t = calculate(i+1, sum+value[i]);
    ll nt = calculate(i+1, sum);
    memo[i][sum]=t+nt;
    return memo[i][sum];
}
int main(){
    memset(memo, -1, sizeof(memo));
    cin >> n >> p;
    for(int i=1; i<=n; i++){
        cin >> value[i];
    }
    cout << calculate(1, 0)<< endl;
    return 0;
}


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

int n , m , q;

int f(int x , int i , vector<int>& ans , vector<vector<int>>& qr){
    if(i == n){
    	int val = 0 ;
        for(auto i : qr){
        	int ai = i[0] , bi = i[1] , ci = i[2] , di = i[3] ;
        		if(ans[bi-1] - ans[ai-1] == ci){
        			val += di ;		
        		}
        }
        return val ;
    }
    int mx = 0 ;
    for(int j = x ; j <= m ; j++){
    	ans.push_back(j) ;
        mx = max(mx , f(j,i+1,ans,qr)) ;
        ans.pop_back() ;
    }
    return mx ;
}

int main()
{
    cin >> n >> m >> q ;
    vector<vector<int>> qr(q,vector<int>(4)) ;
    for(int i = 0 ; i < q ; i++){
    	for(int j = 0 ; j < 4 ; j++) cin >> qr[i][j] ;
    }
    vector<int> ans ;
    cout << f(1,0,ans,qr) ;
    return 0;
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{//change to Main
    static int INF = Integer.MAX_VALUE;
    static int[][] near = {{0,0,1,-1},{1,-1,0,0}};
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));//
    static StringTokenizer st;
    static StringBuilder sb;
    static String line;

    public static void main(String[] args) throws Exception {
        //int T = Integer.parseInt(in.readLine());//number of messages
        int T =1;
        for (int t = 0; t < T; t++) {
            solve();
            //st = new StringTokenizer(in.readLine());
            //int x = Integer.parseInt(st.nextToken());

        }//forLoop#1
    }//main

    public static void solve() throws Exception{

        char[] cars = {'a','b','c','d','e','f','g','h',
                'i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

        while((line = in.readLine())!=null){
            char[] buf = line.toCharArray();
            String s;

            for (int k = 0; k < 26; k++) {//k is key
                s = "";
                for (int i = 0; i < buf.length; i++) {
                    if(buf[i]>='a'&&buf[i]<='z')
                        {s+=(char)((buf[i]-'a'+k)%26+'a');}else{
                        s+=buf[i];
                    }//check next possible key
                }

                if (s.contains("the")||s.contains("this")||s.contains("that")){
                    System.out.println(s);
                    break;
                }
            }

        }


    }
}//class

Measured memory_bytes: 24544
#include<bits/stdc++.h>
using namespace std;
long long int a[44];
long long int calc(int n,long long int to){
	long long int T = 1;
	for(int i=0; i<n; i++)
		a[i] = 1;
	int q = n;
	while(T < to){
		int p = 0;
		for(int i=1; i<n; i++)
			if(a[i] < a[p])p=i;
		T /= a[p];
		q++;
		a[p]++;
		T *= a[p];
	}
	return q;
}
int main(){
	long long int N,A;
	cin >> N >> A;
	long long int res = N;
	for(int i=1; i<=40; i++)
		res = min(res, calc(i+1, N) + A * i);
	cout << res <<endl;
	return 0;
}


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

//https://atcoder.jp/contests/dp/tasks
int n;
ll MX = 1e18;
vector<vector<P>> dp;
vector<ll> a(n);

P rec(int l = 0,int r = n){
    if(r-l==1) return make_pair(0,a[l]);
    P &ret = dp[l][r];
    if(ret.first != MX) return ret;

    for(int i = l+1;i<r;i++){
        P L = rec(l,i);
        P R = rec(i,r);
        ll sum = L.second + R.second;
        ll cost = L.first + R.first + sum;
        ret = min(ret,make_pair(cost,sum));
    }

    return ret;
}

int main(){
    cin >> n;
    a.assign(n,0);
    rep(i,n) cin >> a[i];
    dp.assign(n+2,vector<P>(n+2,make_pair(MX,MX)));

    ll ans = rec(0,n).first;
    cout << ans << endl;

    
}

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

int main(){
  int sum;
  string a;

  while(1){
    sum=0;
    cin>>a;
    if((int)a.size()==1&&a[0]=='0') break;
    
    for(int i=0;i<(int)a.size();i++){
      sum+=a[i]-'0';
    }
    cout<<sum<<endl;
  }
  
  return 0;
}



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


nums = []
denom = int(N ** .5)

min_value = N - 1

while (1):
  if denom < 2:
    break
  if N % denom == 0:
    min_value = min(min_value, denom + N / denom - 2)
  denom -= 1
print(int(min_value))


Measured memory_bytes: 2940
from collections import Counter

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

Ss = [0]
S = 0
for A in As:
    S += A-1
    S %= K
    Ss.append(S)

ans = 0
cnt = Counter()
for i in range(N+1):
    ans += cnt[Ss[i]]
    cnt[Ss[i]] += 1
    if i >= K-1:
        cnt[Ss[i-K+1]] -= 1

print(ans)


Measured memory_bytes: 41352
#include<iostream>
using namespace std; // 575

const int MAX = 100;
int main() {
	int N, h[MAX];
	cin >> N;
	h[0] = 0;
	for (int i = 1;i <= N;++ i) cin >> h[i];
	int ans = 0;
	for (int i = 0;i < N;++ i) ans += max(0, h[i + 1] - h[i]);
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、操作を逆に考えると1ずつhを減らしていく作業になる
で、操作できるならより大きな範囲を操作すべきだから、0が存在しないなるべく大きな範囲をいっぺんに操作すべきね
また、端には0があると仮定しておこう
すると、操作回数はある高さの時点で残りが10101みたいになってるなら、
この分断された0の個数+1がそのまま操作回数
31231(+1)→20120(+2)→10010(+2)→00000、となる
この操作は全て次のように言える
1. 左から見ていく
2. 左の値>右の値となった場所に対し、差だけ足す
これでO(N)
*/

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

int main() {
    int n,a,b;
    cin >> n;
    if (n == 1){
        cout << "Hello World" << endl;
    }else{
        cin >> a;
        cin >> b;
        cout << a+b << endl;
    }
}



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

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int[] x = s.Split().Select(int.Parse).ToArray();
            if (x[2] <= x[0] + x[1])
                Console.WriteLine(x[1] + x[2]);
            else Console.WriteLine(x[0] + x[1] + x[1] + 1);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int M,N;
int b[512], r[512];

struct edge{int to, cap, rev;};

vector<edge> G[1024];
bool used[1024];

void add_edge(int from, int to, int cap){
  G[from].push_back((edge){to, cap, G[to].size()});
  G[to].push_back((edge){from, 0, G[from].size()-1});
}

int dfs(int v, int t, int f){
  //  cout << v << " " << t << " " << f << endl;
  if(v==t) return f;
  used[v] = true;
  rep(i,G[v].size()){
    edge &e = G[v][i];
    //    cout << "next " << e.to << " " << used[e.to] << " " << e.cap << endl;
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t){
  int flow = 0;
  for(;;){
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    //    cout << f << endl;
    if(f == 0) return flow;
    flow += f;
  }
}

int main(){
  while(scanf("%d%d", &M,&N) && M+N){
    rep(i,1024) G[i].clear();
    rep(i,M) scanf("%d", b+i);
    rep(i,N) scanf("%d", r+i);
    // 0~N-1 red
    // N~N+M-1 blue
    int s = M+N, t = s+1;
    rep(i,N) add_edge(s, i, 1);
    rep(i,M) add_edge(N+i, t, 1);
    rep(i,M) rep(j,N){
      if(__gcd(r[j], b[i]) != 1) add_edge(j, N+i, 1);
    }
    /*    rep(i,N+M+2){
      cout << G[i].size() << endl;
      rep(j,G[i].size()) cout << G[i][j].to << " " << G[i][j].cap <<  "  "; cout << endl;
      }*/
    printf("%d\n", max_flow(s, t));
  }
  return 0;
}

Measured memory_bytes: 7712
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    String S =sc.next();
    String T[] ={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
    for(int i=0;i<26;i++){
      if(S.equals(T[i])){System.out.println("A");System.exit(0);}
    }
    System.out.println("a");
  }
}


Measured memory_bytes: 26928
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
char map[2][53];
int main(void)
{
	int n,flag,i;
	const ll MOD=(1e+9)+7;
	ll ans;
	scanf("%d",&n);
	FOR(i,0,2) scanf("%s",map[i]);
	FOR(i,0,n){
		if(i!=n-1&&map[0][i]==map[0][i+1]){
			if(i==0) ans=6;
			else if(flag) ans=ans*3%MOD;
			else ans=ans*2%MOD;
			flag=1;
		}
		if(map[0][i]==map[1][i]){
			if(i==0) ans=3;
			else if(!flag) ans=ans*2%MOD; 
			flag=0;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
import math
from heapq import heappush, heappop


def rint(s):
    return -int(s)


def sum(a):
    s = 0
    for v in a:
        s += math.floor(-v)
    return s


n, m = list(map(int, input().split(" ")))
a = list(map(rint, input().split(" ")))
a.sort()

for i in range(m):
    v = heappop(a)
    heappush(a, v/2)

print(sum(a))


Measured memory_bytes: 14380
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define ll long long
const int inf = 1000000000; // 10^9

int main(){
    int x, y, z;
    cin >> x >> y >> z;

    cout << z << " " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;
const int MOD = 1e9 + 7;
const int nax = 1000006;
int cnt[nax];
ll powermod(ll base, ll exp) {
ll result = 1;
while (exp != 0) {
    if ((exp % 2) == 1) {
        result = (result * base) % MOD;
    }
    base = (base * base) % MOD;
    exp /= 2;
}
return result;
}
void primefactorization(ll int n){
    int freq = 0;
    while (n % 2 == 0) {
        n /= 2;
        freq++;
    }
    cnt[2] = max(cnt[2] , freq);

    for (size_t i = 3; i*i <= n; i += 2) {
        freq = 0;
        while (n % i == 0) {
            freq++;
            n /= i;
        }
        cnt[i] = max(cnt[i] , freq);

    }
    if(n > 2)

          cnt[n] = max(cnt[n] , 1); // it is case when n itself prime number
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    vector<int> v(n);
    ll int sum = 0;
    //memset(cnt , 0 , sizeof(cnt));
    REP(i,n){
        cin>>v[i];
        primefactorization(v[i]);
        sum += (powermod(v[i] , MOD-2 ) % MOD);
    }
    
    ll int ans = sum;
    for (size_t i = 2; i < nax; i++) {
        ans = (ans * powermod(i , cnt[i])) % MOD;
    
    }
    while (ans < 0) {
        ans = (ans + MOD) % MOD;
    }
    cout<<ans<<"\n";

    return 0;


}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  string s[257], k[257];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>k[i];
  }
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>s[i];
  }
  int count=0, c[300]={};
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
      if(s[i] == k[j]){
	count++;
	c[i]++;
	break;
      }
    }
    if(c[i] == 0) cout<<"Unknown"<<" "<<s[i]<<endl;
    else if(c[i] != 0 && count % 2 != 0) cout<<"Opened by"<<" "<<s[i]<<endl;
    else cout<<"Closed by"<<" "<<s[i]<<endl;
  }
  return 0;
}
      
      



Measured memory_bytes: 3216
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
memo = [0]*(n+1)
for i in range(n):
    memo[bisect.bisect_left(b,c[i])] += 1
for i in range(n-1,-1,-1):
    memo[i] += memo[i+1]
for i in range(n-1,-1,-1):
    memo[i] += memo[i+1]
memo = memo[1:]+[0]
ans = 0

for i in range(n):
    ans += memo[bisect.bisect_right(b,a[i])]
print(ans)

Measured memory_bytes: 23360
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    ll n, m;
    cin >> n >> m;

    ll ans = 0;

    if (m >= n*2){
        ans = n + (m-2*n)/4;
    }
    else{
        ans = m/2;
    }

    cout << ans << endl;


}


Measured memory_bytes: 3580
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

s = input()
k = INT()
n = len(s)

if len(set(list(s)))==1:
    print(n*k//2)
    exit()

l=[]
tmp=1
ans=0
for i in range(1,n):
    if s[i-1]==s[i]:
        tmp+=1
    else:
        l.append(tmp)
        tmp=1
l.append(tmp)
for i in l:
    ans+=i//2
ans*=k

if s[0]==s[-1]:
    a = l[0]
    b = l[-1]
    res = (a//2) + (b//2) - ((a+b)//2)
    print(ans-(res*(k-1)))
else:
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll P[1007];

int main(){
  ll N,K;
  cin >> N >> K;
  rep(i,N){
    cin >> P[i];
  }
  sort(P,P+N);
  ll  ANS=0;
  rep(i,K){
    ANS+=P[i];
  }
  cout << ANS << endl;
}


Measured memory_bytes: 3644
//082
import java.util.*;

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

        for(int i = 0;i<s.length();i++){
            if(i %2 != 1){
                sb.append(s.substring(i,i+1));
            }
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 28720
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      s: chars,
      t: chars,
    }

    let n = s.len();
    let m = t.len();

    // LCS
    let mut dp = vec![vec![0; m+1]; n+1];
    for i in 0..n {
        for j in 0..m {
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            if s[i] == t[j] {
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
            }
        }
    }

    let mut i = n;
    let mut j = m;

    let mut ans = vec![];
    loop {
        if i == 0 || j == 0 {
            break;
        }
        if dp[i][j] > dp[i-1][j] && dp[i][j] > dp[i][j-1] {
            i -= 1;
            j -= 1;
            ans.push(s[i]);
        } else if dp[i-1][j] > dp[i][j-1] {
            i -= 1;
        } else {
            j -= 1;
        }
    }
    ans.reverse();
    let s: String = ans.iter().map(|&v|v).collect();
    puts!("{}\n", s);
}


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

int main(){
  int N,M;
  cin>>N>>M;
  if((N==1)&&(M==0)){
    cout<<0<<endl;
    return 0;
  }
  int a[N];
  for (int i=0;i<N;i++){
    a[i]=-1;
  }
  int s[M];
  int c[M];
  for (int i=0;i<M;i++){
    cin>>s[i]>>c[i];
    if(a[s[i]-1]==-1){
      a[s[i]-1]=c[i];
    }
    else if(a[s[i]-1]==c[i]){
      continue;
    }
    else if(!(a[s[i]-1]==c[i])){
      cout<<-1<<endl;
      return 0;
    }
  }

  if((a[0]==0)&&(!(N==1))){
    cout<<-1<<endl;
    return 0;
  }
  if((a[0]==0)&&(N==1)){
    cout<<0<<endl;
    return 0;
  }
  if(N==1){
    cout<<a[0]<<endl;
    return 0;
  }
  if(a[0]==-1){
    a[0]=1;
  }
  for(int i=1;i<N;i++){
    if(a[i]==-1){
      a[i]=0;
    }
  }
  for(int i=0;i<N;i++){
    cout<<a[i];
  } 
    cout<<endl;
  return 0;
}

  
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

const int N=1e6+10; 
int n,m;
int a[N],sum=0;
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		int x;
		scanf("%d",&x);
		a[x]++;
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",a[i]);
	}
    return 0;
}


Measured memory_bytes: 4612
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int cnt=0;
        for(int i=1; i<=N; i++){
            int P = sc.nextInt();
            if(P != i){
                cnt++;
            }
        }
        if(cnt==0 || cnt==2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

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

public class Program
{
	static void Main(string[] args)
	{
		var S = Console.ReadLine();
		var count = 0;
		var targetChar = S[0];

		for (int i = 1; i < S.Length; i++)
		{
			if (targetChar == S[i])
			{
				count++;
				if (S[i] == '0')
				{
					targetChar = '1';
				}
				else
				{
					targetChar = '0';
				}
			}
			else
			{
				targetChar = S[i];
			}
		}

		Console.WriteLine(count);
	}
}


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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const ll INF = 2e18;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;



int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int a, b, x, y, d;
	cin >> a >> b >> x >> y >> d;
	while(d >= 60) {
		d -= 60;
		x--;
		if(x < 0) x += 24;
	}
	y -= d;
	if(y < 0) y += 60, x--;
	if(x < 0) x += 24;

	if(x < a) x += 24;
	int ans = (x-a) * 60 + (y-b);
	cout << ans;

}



Measured memory_bytes: 3652
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int64_t mod = 1e9 + 7;
unordered_map<int64_t, int64_t> memo;
int H, W, K;
vector<int> pattern(9);
  
int64_t search(int c, int r) {
  if(r == H) {
    if((c+1) == K) return 1;
    else return 0;
  }
  int64_t key = c * 1000 + r;
  if(memo.count(key)) return memo[key];
  
  int64_t ret = 0;
  int64_t add1, add2, add3;
  add1 = add2 = add3 = 0;
  int64_t pat1, pat2, pat3;
  pat1 = pat2 = pat3 = 0;
  if(c == 0) {
    add1 = search(c, r + 1);
    pat1 = pattern[max(0, W-2)];
    if(1 < W) {
      add2 = search(c + 1, r + 1);
      pat2 = pattern[max(0, W-3)];
    }
  } else if(c == (W - 1)) {
    add1 = search(c, r + 1);
    pat1 = pattern[max(0, W-2)];
    if(1 < W) {
      add2 = search(c - 1, r + 1);
      pat2 = pattern[max(0, W-3)];
    }
  } else {
    add1 = search(c, r + 1);
    pat1 = (pattern[max(0, c-1)] * pattern[max(0, W - 2 - c)]) % mod;
    if((c+1) < W) {
      add2 = search(c + 1, r + 1);
      pat2 = (pattern[max(0, c-1)] * pattern[max(0, W - 3 - c)]) % mod;
    }
    if(0 <= (c-1)) {
      add3 = search(c - 1, r + 1);
      pat3 = (pattern[max(0, c-2)] * pattern[max(0, W - 2 - c)]) % mod;
    }
  }
  add1 = (add1 * pat1) % mod;
  add2 = (add2 * pat2) % mod;
  add3 = (add3 * pat3) % mod;
  ret = (ret + add1) % mod;
  ret = (ret + add2) % mod;
  ret = (ret + add3) % mod;
  return memo[key] = ret;
}

int64_t search0(int c, int cmax, bool before) {
  if(c == cmax) {
    return 1;
  } else if(c > cmax) {
    return 0;
  }
  int ret = 0;
  if(before) {
    ret += search0(c+1, cmax, false);
  } else {
    ret += search0(c+1, cmax, false);
    ret += search0(c+1, cmax, true);
  }
  return ret;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin >> H >> W >> K;
  rep(i, W) {
    pattern[i] = search0(0, i, false);
    //cout << pattern[i] << endl;
  }
  int64_t answer = search(0, 0);
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3648
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
import heapq as hq
gcd = math.gcd
n = ni()
A = []
for i in range(n):
    A.append(ni())
A.sort()
A1 = A[:(n+1)//2]
A2 = A[(n+1)//2:]
#print(A1,A2)


if n%2==0:
    print(2*sum(A2) - 2*sum(A1) - A2[0] + A1[-1])

else:
    s1 = 2*sum(A2) - 2*sum(A1) + A1[-1]+A1[-2] #a1がa2より多い場合
    A1 = A[:n//2]
    A2 = A[n//2:]
    s2 = 2*sum(A2)  - 2*sum(A1) -A2[0] -A2[1]#a2がa1より多い場合
    print(max(s1,s2))


Measured memory_bytes: 14472
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   string a,b;
   cin >> n >> a >> b;
   f(i,0,n){
      cout << a[i] << b[i];
   }
   return 0;
}

Measured memory_bytes: 256
# Nodeクラス


class Node:
    def __init__(self, k):
        self.k = k
        self.p = None
        self.l = None
        self.r = None

# BinarySearchクラス


class BinarySearch:
    root = None

    def insert(self, k):
        y = None
        x = self.root
        z = Node(k)
        while x:
            y = x
            if z.k < x.k:
                x = x.l
            else:
                x = x.r
        z.p = y

        if y == None:
            self.root = z
        else:
            if z.k < y.k:
                y.l = z
            else:
                y.r = z

    def preParse(self, u):
        if u == None:
            return
        print("", str(u.k), end="")
        self.preParse(u.l)
        self.preParse(u.r)

    def inParse(self, u):
        if u == None:
            return
        self.inParse(u.l)
        print("", str(u.k), end="")
        self.inParse(u.r)


if __name__ == '__main__':

    n = int(input().rstrip())
    x = BinarySearch()

    for i in range(n):
        com = input().rstrip()
        if com.startswith("insert"):
            k = int(com.split(" ")[1])
            x.insert(k)
        else:
            x.inParse(x.root)
            print()
            x.preParse(x.root)
            print()



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

using namespace std;
const int manx = 200000+5;
struct node{
    int f;
    int data;
}sum[manx];
int N;
int va;
int main(){
    
    int k;
    cin>>N;
    cin>>k;
    for(int i = 1;i < N;i++){
        int a,b;
        cin>>a>>b;
        sum[b].f = a;
    }
    for(int i = 1;i <= manx;i++){
        sum[i].data = 0;
    }
    for(int i = 0;i < k;i++){
        int a;
        cin>>a>>va;
        sum[a].data += va;
    }
    for(int i = 2;i <= N;i++){
        sum[i].data += sum[sum[i].f].data;
    }
    for(int i = 1;i <= N;i++){
        cout<<sum[i].data<<" "; 
    }
    return 0;
}

Measured memory_bytes: 3968
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tpl;


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


#define ARRAY_MAX 100005
const int INF = 1e9;
const ll MOD = 1e9 + 7;

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




/******************************************************************************************/


int main() {

	
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n);
	priority_queue<tpl> que;
	vector<ll> po(100);

	ll hoge = 1LL;
	for (int i = 0; i < 36; i++)
	{
		po[i] = hoge;
		hoge *= 2LL;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		que.push(tpl(a[i], a[i], 0LL));
	}

	for (int i = 0; i < m; i++)
	{
		tpl tapi = que.top();
		que.pop();
		ll a, b, c;
		tie(a, b, c) = tapi;
		if (a == 0) {
			break;
		}
		//cout << a << " " << b << " " << c << endl;
		//cout << b / (c + 1) << " " << b << " " << c+1 << endl;
		que.push(tpl(b / (po[c+1]), b, c + 1));
	}

	ll ans = 0;
	while (!que.empty()) {
		tpl tapi = que.top();
		que.pop();
		ll a, b, c;
		tie(a, b, c) = tapi;
		ans += a;
	}

	cout << ans << endl;


	


	return 0;
}


Measured memory_bytes: 5620
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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 maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

int main(){
    ll N;
    string s; cin>>s;
    N=sz(s);
    vector<vector<ll> > dp(N,vector<ll>(2,0));
    if(s[0]=='1'){
        dp[0][0]=2;
        dp[0][1]=1;
    }
    else{
        dp[0][0]=1;
    }
    rep1(i,N-1){
        if(s[i]=='1'){
            dp[i][0]=(dp[i-1][0]*2)%MOD;
            dp[i][1]=(dp[i-1][0] + (dp[i-1][1]*3)%MOD)%MOD;
        }
        else{
            dp[i][0]=dp[i-1][0];
            dp[i][1]=(dp[i-1][1]*3)%MOD;
        }
    }
    cout<<(dp[N-1][1]+dp[N-1][0])%MOD<<endl;
}



Measured memory_bytes: 8776
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    if(360%t !=0){
        int a = 360/t;
        int b = 360 - (t*a);
        cout<<(360/b)*a;
    }
    else
        cout<<(360/t);
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/900 < b.F.F/900)
		return 1;
	if(a.F.F/900 > b.F.F/900)
		return 0;
	if(a.F.S <= b.F.S)
		return 1;
	return 0;
}

const int N = (2e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 8000;



void solve()
{
	int n, i, cnt;
	string s;
	cin >> s;
	n = s.length();
	if(s[0] != 'A')
	{
		cout << "WA";
		return;
	}
	if(s[1] == 'C' || s[n-1] == 'C')
	{
		cout << "WA";
		return;
	}
	cnt = 0;
	fo(i,2,n-1)
		if(s[i] == 'C')
			cnt++;
	if(cnt != 1)
	{
		cout << "WA";
		return;
	}
	fo(i,0,n)
	{
		if(s[i] != 'A' && s[i] != 'C' && s[i]-'A' >= 0 && s[i]-'A' <= 25)
		{
			cout << "WA";
			return;
		}
	}
	cout << "AC";
	return;
}

int main()
{
	sws;
	// clock_t clk;
	// clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	// cout << fixed << setprecision(6);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	// clk = clock() - clk;
	// cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	uint64_t n;
	uint64_t data[5];
	int i;
	uint64_t bn; /* bottle neck */
	if (scanf("%" SCNu64, &n) != 1) return 1;
	for (i = 0; i < 5; i++) {
		if (scanf("%" SCNu64, &data[i]) != 1) return 1;
	}
	bn = data[0];
	for (i = 1; i < 5; i++) {
		if (data[i] < bn) bn = data[i];
	}
	printf("%" PRIu64 "\n", 5 - 1 + (n + bn - 1) / bn);
	return 0;
}


Measured memory_bytes: 128