akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, int num=0){
  if(num == 0) num = (int)v.size();
  if(is_reverse) for(int i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
  else for(int i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  for(int i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

bool check(ll a, ll b, ll c){
  bool res = false;
  if(a + b > c){
    if( b+c > a){
      if( c+ a > b){
        if(a != b){
          if( b != c){
            if(c != a){
              res = true;
            }
          }
        }
      }
    }
  }
  return res;
}
int main(){
  int N;
  cin >> N;
  vector<ll> L(N);
  for(int i=0; i<N; i++) cin >> L[i];
  sort(L.begin(), L.end());

  ll ans = 0;
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      for(int k=j+1; k<N; k++){
        if(check(L[i], L[j], L[k])) ans++;
      }
    }
  }
  

  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  vector<pair<ll, ll>> v(n);
  for (auto &e : v)
    cin >> e.first >> e.second;

  sort(v.begin(), v.end(), [](pair<ll, ll> a, pair<ll, ll> b) {if(a.second==b.second)return a.first<b.first; else return a.second<b.second; });
  ll sum = 0;
  bool flag = true;
  for (int i = 0; i < n; ++i)
  {
    sum += v[i].first;
    if (sum > v[i].second)
      flag = false;
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<string>
using namespace std;
bool appear[3][3];

int main(){
  vector<vector<int>> data(3,vector<int>(3));
  for(int i =0;i<3;i++){
    for(int j =0;j<3;j++){
      cin>>data.at(i).at(j);
    }
  }
  int n;
  cin>>n;
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin>>b.at(i);
  }
  for(int i =0;i<3;i++){
    for(int j =0;j<3;j++){
      appear[i][j]=false;
      for(int k=0;k<n;k++){
        if(data.at(i).at(j)==b.at(k)) appear[i][j]=true;
      }
    }
  }
  string ans="No";
  for(int i = 0;i<3;i++){
    if(appear[i][0]&&appear[i][1]&&appear[i][2]) ans="Yes";
  }
  for(int i = 0;i<3;i++){
    if(appear[0][i]&&appear[1][i]&&appear[2][i]) ans="Yes";
  }
  if(appear[0][0]&&appear[1][1]&&appear[2][2]) ans="Yes";
  if(appear[0][2]&&appear[1][1]&&appear[2][0]) ans="Yes";
  
  cout<<ans<<endl;
}
  


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;



int main() {
    int d,i,j,k;
    int c[26];
    int s[365][26];
    cin >> d;
    for(i = 0; i < 26; ++i) cin >> c[i];
    for(i = 0; i < d; ++i) for(j = 0; j < 26; ++j) cin >> s[i][j];

    int arr[365] = {};

    int t1,t2,s1,s2, diff, count;
    count = 0;
    int max, loc;
    for(i = 0; i < 365; ++i) {
        max = *max_element(s[i],s[i+1]);
        loc = find(s[i],s[i+1],max)-s[i];
        arr[i] = loc;
    }
    
    
    while(true) {
        label1:
        for(i = 0; i < d; ++i) {
            for(j = 0; j < 26; ++j) {
                if(arr[i]==j) continue;
                if(count>10000000) goto label2;
                ++count;
                for(s1 = i+1; s1 < d; ++s1) {
                    if(arr[s1]==arr[i]) break;
                }
                for(t1 = i-1; t1 >= 0; --t1) {
                    if(arr[t1]==arr[i]) break;
                }
                for(s2 = i+1; s2 < d; ++s2) {
                    if(arr[s2]==j) break;
                }
                for(t2 = i-1; t2 >= 0; --t2) {
                    if(arr[t2]==j) break;
                }
                diff = s[i][j]-s[i][arr[i]]+(((s1-i)*(s1-i-1))/2+((i-t1)*(i-t1-1))/2-((s1-t1)*(s1-t1-1))/2)*c[arr[i]] + (-((s2-i)*(s2-i-1))/2-((i-t2)*(i-t2-1))/2+((s2-t2)*(s2-t2-1))/2)*c[j];
                if(diff>0) {
                    arr[i] = j;
                    goto label1;
                }
            }
        }
    }
    label2:
    for(i = 0; i < d; ++i) {
        cout<<(arr[i]+1)<<"\n";
    }


    return 0;
}

Measured memory_bytes: 3716
using System;

	class Program
	{
		static void Main(string[] args)
		{
			string[] values = Console.ReadLine().Split(' ');
			int n = int.Parse(values[0]);
			int l = int.Parse(values[1]);
			int min = l;			
			int total = 0;
			int ans = 0;
			for (int i = 1; i <=n; i++)
			{
				total = total + l+i-1;
				if (Math.Abs(min)>Math.Abs(l+i-1))
				{
					min = l+i-1;
				}
			}
			ans = total - min;
			Console.WriteLine(ans);

		}
	}



Measured memory_bytes: 13140
def main():
    N = int(input())
    s = input()
    t = input()
    ss = tt = ''
    l = 0
    for i in range(N):
        ss = s[-1-i] + ss
        tt = tt + t[i]
        if ss == tt:
            l = len(ss)
    print(2 * N - l)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
X = gets.chomp.to_i
def rating(rate)
  if 400 <= rate && rate <= 599
    return "8"
  elsif 600 <= rate && rate <= 799
    return "7"
  elsif 800 <= rate && rate <= 999
    return "6"
  elsif 1000 <= rate && rate <= 1199
    return "5"
  elsif 1200 <= rate && rate <= 1399
    return "4"
  elsif 1400 <= rate && rate <= 1599
    return "3"
  elsif 1600 <= rate && rate <= 1799
    return "2"
  elsif 1800 <= rate && rate <= 1999
    return "1"
  end
end

print(rating(X), "\n")

Measured memory_bytes: 14368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf = 1e14;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,l;
	cin >> n >> m >> l;
	vector<vector<ll>> dist(n+1, vector<ll>(n+1, inf));
	for (int q = 0; q < m; q++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		dist[a][b] = c;
		dist[b][a] = c;
	}
	for (int q = 1; q <= n; q++)
	{
		for (int w = 1; w <= n; w++)
		{
			for (int e = 1; e <= n; e++)
			{
				dist[w][e] = min(dist[w][e], dist[w][q]+dist[q][e]);
			}
		}
	}
	vector<vector<ll>> norefuel(n+1, vector<ll>(n+1, inf));
	for (int q = 1; q <= n; q++)
	{
		for (int w = 1; w <= n; w++)
		{
			if (dist[q][w] <= l)
			{
				norefuel[q][w] = 1;
			}
		}
	}
	for (int q = 1; q <= n; q++)
	{
		for (int w = 1; w <= n; w++)
		{
			for (int e = 1; e <= n; e++)
			{
				norefuel[w][e] = min(norefuel[w][e], norefuel[w][q] + norefuel[q][e]);
			}
		}
	}
	int t;
	cin >> t;
	while (t--)
	{
		int a,b;
		cin >> a >> b;
		cout << (norefuel[a][b] == inf ? -1 : norefuel[a][b]-1) << "\n";
	}
	return 0;
}


Measured memory_bytes: 4776
/*         
               JAI SHREE RAM    */
 
 
 
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define int             long long
#define mp              make_pair
#define pr              pair<long long,long long>
#define vr              vector<long long>
#define mod            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
#define fill(a,b)       memset(a, b, sizeof(a))
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 

const int N = 1000001;
  vector <int> a;
int power(int x, unsigned int y) 
{ 
    int res = 1;     
   
    while (y > 0) 
    { 
        
        if (y & 1) 
            res = res*x; 
        y = y>>1; // y = y/2 
        x = x*x;  // Change x to x^2 
    } 
    return res; 
}
 
long long maxSubArray(long long a[], int sze)
{
   long long max_so_far = 0, max_ending = 0;
   for (int i = 0; i < sze; i++)
   {
       max_ending = max_ending + a[i];
       if (max_ending < 0)
           max_ending = 0;
       else if (max_so_far < max_ending)
           max_so_far = max_ending;
   }
   return max_so_far;
}
 
 
 
ll factorialNumInverse[N + 1]; 
ll naturalNumInverse[N + 1]; 
ll fact[N + 1]; 
  
 
void InverseofNumber(ll p) 
{ 
    naturalNumInverse[0] = naturalNumInverse[1] = 1; 
    for (int i = 2; i <= N; i++) 
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p; 
} 
void InverseofFactorial(ll p) 
{ 
    factorialNumInverse[0] = factorialNumInverse[1] = 1; 
  
    
    for (int i = 2; i <= N; i++) 
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; 
} 
void factorial(ll p) 
{ 
    fact[0] = 1; 
  
    // precompute factorials 
    for (int i = 1; i <= N; i++) { 
        fact[i] = (fact[i - 1] * i) % p; 
    } 
} 
  
ll Binomial(ll N, ll R, ll p) 
{ 
    // n C r = n!*inverse(r!)*inverse((n-r)!) 
    ll ans = ((fact[N] * factorialNumInverse[R]) 
              % p * factorialNumInverse[N - R]) 
             % p; 
    return ans; 
} 

 
void solve()
{
    int n;
    cin>>n;
    
    int ma1=-1e18,ma2=-1e18,mi1=1e18,mi2=1e18;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        
        if(x+y>=ma1)ma1=x+y;
         if(x+y<mi1)mi1=x+y;
        
        if(x-y>ma2)ma2=x-y;
        if(x-y<mi2)mi2=x-y;
    }
    int ans=max(ma1-mi1,ma2-mi2);
    
    cout<<ans<<"\n";
}
 
int32_t main()
{ 
      
      ios;
      int test;
     
      
      test=1;
   //  cin>>test;
    
      while(test--)
      {
          solve();
      }
       
    
    return 0;
	}

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

int main(void) {
	int N;
	vector<int> V;

	cin >> N;
	V.resize(N + 1, 0);
	int sum = 0;
	for (int i = 1; i <= N; ++i) {
		int w;
		cin >> w;
		sum += w;
		V[i] = V[i - 1] + w;
	}

	int ans = 100 * 100;
	for (int t = 1; t < N; ++t) {
		int s1 = V[t];
		int s2 = sum - s1;
		int d = abs(s1 - s2);
		ans = min(d, ans);
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;
typedef long double ldouble;

int N, K;
char S[1000020];

void solve(){
	scanf("%d%d", &N, &K);
	scanf("%s", S+1);
	for(int i=N+1;i<1000020;i++)S[i] = 'B';
	int sp = 1;
	if(K > 3 * N + 10){
		int t = 3 * N + 10;
		if((K&1) != (t&1))K = t + 1;
		else K = t;
	}
	int rev = 0;
	for(int i=1;i<=K;i++){
		if((S[sp] == 'A') ^ rev){
			S[sp] = (S[sp] == 'A' ? 'B' : 'A');
		}
		else{
			if(rev) S[sp+N] = 'A';
			++sp; rev ^= 1;
		}
	}
	for(int i=sp;i<sp+N;i++){
		if((S[i] == 'A') ^ rev)printf("A");
		else printf("B");
	}
	puts("");
}

int main(){
	int Tc = 1; // scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		//printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define maxn 410
#define all 400
#define p 998244353
using namespace std;
typedef long long ll;
template<typename T> inline void read(T &x)
{
    x=0;char c=getchar();bool flag=false;
    while(!isdigit(c)){if(c=='-')flag=true;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    if(flag)x=-x;
}
int n,s1,s2;
ll ans;
int a[maxn],b[maxn];
ll f[maxn][maxn][maxn],inv[maxn];
void init()
{
    inv[0]=inv[1]=1;
    for(int i=2;i<=all;++i) inv[i]=(p-p/i)*inv[p%i]%p;
}
int main()
{
    init(),read(n);
    for(int i=1;i<=n;++i)
        read(a[i]),read(b[i]),s1+=a[i],s2+=b[i];
    f[0][0][0]=p-1;
    for(int i=1;i<=n;++i)
    {
        ll v=1;
        for(int j=0;j<=s1;++j)
            for(int k=0;k<=s2;++k)
                f[i][j][k]=f[i-1][j][k];
        for(int t=0;t<b[i];++t,v=v*a[i]%p*inv[t]%p)
            for(int j=a[i];j<=s1;++j)
                for(int k=t;k<=s2;++k)
                    f[i][j][k]=(f[i][j][k]-f[i-1][j-a[i]][k-t]*v%p+p)%p;
    }
    for(int j=1;j<=s1;++j)
    {
        ll v=1;
        for(int k=0;k<=s2;++k,v=v*k%p*inv[j]%p)
            ans=(ans+f[n][j][k]*s1%p*inv[j]%p*v%p)%p;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 519056
from itertools import combinations
n = int(input())
a = []
xy = [] #xy[i人目][j個目][0: x, 1: y]
for i in range(n):
    a.append(int(input()))
    xy.append([])
    for _ in range(a[i]):
        xy[i].append([int(i) for i in input().split()])
ans = 0
for i in range(n + 1): #i人の正直者
    b = list(combinations(list(range(n)), i))
    for j in range(len(b)): #組み合わせj
        flag = False
        #print(b[j])
        for k in b[j]: #人k
            for l in range(a[k]): #証言l
                if (xy[k][l][0] - 1 in b[j] and xy[k][l][1] != 1) or ((not xy[k][l][0] - 1 in b[j]) and xy[k][l][1] == 1):
                    flag = True
                    break
                #print(xy[k][l][0], xy[k][l][1])
            if flag:
                break
        if not flag:
            #print('YES', j)
            ans = i
print(ans)


Measured memory_bytes: 5364
from math import sqrt
from itertools import product
import sys

n = int(input())
p = []
def factorization(arg):
    while arg % 2 == 0:
        p.append(2)
        arg //= 2
    for i in range(3, int(sqrt(arg)) + 1, 2):
        while arg % i == 0:
            p.append(i)
            arg //= i
    if arg > 1:
        p.append(arg)
if n == 1:
    print(1)
else:
    factorization(n)
    min = sys.maxsize
    for bit in range(2 ** len(p)):
        a = 1
        b = 1
        for i in range(len(p)):
            if ((bit >> i) & 1):
                a *= p[i]
            else:
                b *= p[i]
        if min > len(str(a)) if len(str(a)) >= len(str(b)) else len(str(b)):
            min = len(str(a)) if len(str(a)) >= len(str(b)) else len(str(b))
    print(min)

Measured memory_bytes: 68400
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    if n == 0:
        if a[0] == 1:
            print(1)
        else:
            print(-1)
        return
    if a[0] == 1:
        print(-1)
        return
    k = 1-a[0]
    M = [1]
    p = 1
    for i in range(n):
        if k <= 0:
            print(-1)
            return
        M.append(min(p,k) << 1)
        k = M[i+1] - a[i+1]
        p <<= 1
    if k < 0:
        print(-1)
        return
    s = a[-1]
    ans = s
    for i in range(n)[::-1]:
        s = min(M[i],s+a[i])
        ans += s
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 702456
#include <iostream>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <memory>
#include <iterator>
#include <stdexcept>
#include <utility>
#include <string>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

template<typename T>
string convert(T t) {
    ostringstream out;
    out << t;
    return out.str();
}

string convert(string s) {
    return '"' + s + '"';
}

string convert(const char* s) {
    string out("\"");
    return out + s + "\"";
}

template<typename T, typename V>
string convert(pair<T, V> p) {
    return "(" + convert(p.first) + ' ' + convert(p.second) + ")";
}

template<class Iterator>
string convert(Iterator start, Iterator end) {
    string out = "";
    out += '{';
    for (auto s = start; s != end; s++) {
        out += convert(*s) += ' ';
    }
    out += '}';
    return out;
}
template<typename T> string convert(vector<T> container) { return convert(container.begin(), container.end()); }
template<typename T> string convert(set<T> container) { return convert(container.begin(), container.end()); }
template<typename T, typename V> string convert(map<T, V> container) { return convert(container.begin(), container.end()); }
template<typename T> string convert(unordered_set<T> container) { return convert(container.begin(), container.end()); }
template<typename T, typename V> string convert(unordered_map<T, V> container) { return convert(container.begin(), container.end()); }

template<typename... Args>
void debug(int id, Args... args) {
    cout << '(' << id << "):";
    ostream* rubbish[] = { &(cout << ' ' << convert(args))... };
    cout << '\n';
}

template<typename T = int>
vector<T> listinput(int length) {
    vector<T> out(length);
    for (int i = 0; i < length; i++) {
        cin >> out[i];
    }
    return out;
}

template<typename T = int>
vector<T> listinput() {
    int length;
    cin >> length;
    return listinput<T>(length);
}

template<typename T = int>
vector<vector<T>> gridinput(int rows, int cols) {
    vector<vector<T>> out(rows, vector<T>(cols));
    for (int r = 0; r < rows; r++) {
        for (int c = 0; c < cols; c++) {
            cin >> out[r][c];
        }
    }
    return out;
}

int main() {
    vector<int> stones = listinput();
    vector<int> DP(stones.size(), 0);

    DP[0] = 0;
    DP[1] = DP[0] + abs(stones[0] - stones[1]);

    for (int i = 2; i < stones.size(); i++) {
        DP[i] = min(DP[i - 1] + abs(stones[i] - stones[i-1]), DP[i - 2] + abs(stones[i] - stones[i-2]));
    }

    cout << DP[stones.size() - 1] << '\n';
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define ten(n) ((int)1e##n)
#define fst first
#define snd second
using ll=long long;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pil=pair<int,ll>;using pli=pair<ll,int>;
using vs=vector<string>;using vvs=vector<vs>;using vvvs=vector<vvs>;
using vb=vector<bool>;using vvb=vector<vb>;using vvvb=vector<vvb>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<class T> bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
ll ri(){ll l;cin>>l;return l;} string rs(){string s;cin>>s;return s;}
template<class T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<'('<<p.fst<<", "<<p.snd<<')';}
ostream&operator<<(ostream&o,const vb&t){forr(e,t)o<<"#."[e];return o;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&t){o<<"{";forr(e,t)o<<e<<",";o<<"}"<<endl;return o;}
#ifdef LOCAL
vs s_p_l_i_t(const string&s,char c){vs v;stringstream ss(s);string x;while(getline(ss,x,c))v.emplace_back(x);return move(v);}
void e_r_r(vs::iterator it){cerr<<endl;}
template<class T,class... Args>void e_r_r(vs::iterator it,T a,Args... args){cerr<<it->substr((*it)[0]==' ',it->length())<<" = "<<a<<", ";e_r_r(++it,args...);}
#define out(args...){vs a_r_g_s=s_p_l_i_t(#args,',');e_r_r(a_r_g_s.begin(),args);}
#else
#define out(args...)
#endif

void Main() {
  int n = ri();
  vector<int> A(3*n);
  rep(i, 3*n) A[i] = ri();

  priority_queue<int, vector<int>, greater<int>> lq;
  priority_queue<int> rq;

  vl L(n+1);
  {
    ll lsum = 0;

    rep(i, n) {
      lsum += A[i];
      lq.emplace(A[i]);
    }

    L[0] = lsum;

    rep(i, n, 2*n) {
      int a = A[i];
      lsum += a;
      lq.emplace(a);
      int rem = lq.top(); lq.pop();
      lsum -= rem;
      L[i-n+1] = lsum;
    }
  }

  vl R(n+1);
  {
    ll rsum = 0;
    rep(i, 2*n, 3*n) {
      rsum += A[i];
      rq.emplace(A[i]);
    }

    R[n] = rsum;

    rrep(i, n, 2*n) {
      int a = A[i];
      rsum += a;
      rq.emplace(a);
      int rem = rq.top(); rq.pop();
      rsum -= rem;
      R[i-n] = rsum;
    }
  }

  out(L);
  out(R);

  ll ans = -1e18;
  rep(i, n+1) {
    amax(ans, L[i] - R[i]);
  }

  cout << ans << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 4216
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

bool is_add(ll N, ll k) {
    if (k == 1) return false;
    while (1) {
        if (N % k != 0) break;
        N /= k;
    }

    if ((N - 1) % k == 0)
        return true;
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;
    ll ans = 0;

    for (ll k = 1; k * k <= N - 1; k++) {
        if ((N - 1) % k == 0) {
            ll k2 = (N - 1) / k;
            if (N % k != 0) ans++;
            if(k != k2)
                if (N % k2 != 0) ans++;
        }
    }

    for (ll k = 1; k * k <= N; k++) {
        if (N % k == 0) {
            ll k2 = N / k;
            if (is_add(N, k)) ans++;
            if (k2 != k)
                if (is_add(N, k2)) ans++;

        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n,k;
    cin>>n;
    int ans=0;
    for(k=0;k<n;k++){
        int x;
        cin>>x;
        if(x%2==1) ans++;
    }

    if(ans%2==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


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

int N;
long long K;
vector<int> A, B;

vector<int> dp;

const int MAX = 200200;
vector<int> same[MAX];
vector<int> nxtA, nxtB;

void print_result(int piv) {
    if (piv == -1) return;
    while (piv < N) {
        if (nxtA[piv] != -1) {
            piv = nxtA[piv];
            continue;
        } else {
            cout << A[piv++] << endl;
        }
        // cout << piv << endl;
    }
}

int main() {

    cin >> N >> K;

    A.resize(N);
    REP(i, N) cin >> A[i];

    // B : Aを2回繰り返した配列
    REP(i, 2 * N) B.emplace_back(A[i % N]);

    // same[i] : 数iが格納されているindexのvector
    REP(i, 2 * N) same[B[i]].emplace_back(i);

    // all_diff : Aの要素がすべて異なる
    bool all_diff = true;
    // nxtA[i] : Aの中で, A[i]と同じ数が次に現れるindexの次のindex (無ければ-1)
    nxtA.resize(N);
    REP(i, N) nxtA[i] = (same[A[i]][(int)(upper_bound(same[A[i]].begin(), same[A[i]].end(), i) - same[A[i]].begin())] + 1);
    REP(i, N) {
        if (nxtA[i] > N) {
            nxtA[i] = -1;
        } else {
            all_diff = false;
        }
    }

    // if (all_diff) {
    //     if (K % (N + 1) != 0) {
    //         print_result((K - 1) % (N + 1));
    //     }
    //     return 0;
    // }

    // nxtB[i] : Bの中で, B[i]と同じ数が次に現れるindexの次のindex
    nxtB.resize(N);
    REP(i, N) nxtB[i] = (same[B[i]][(int)(upper_bound(same[B[i]].begin(), same[B[i]].end(), i) - same[B[i]].begin())] + 1) % N;

    int cur = 0;
    while (true) {
        if (nxtB[cur] == 0) {
            if (nxtA[cur] == -1) dp.emplace_back(cur);
            dp.emplace_back(-1);
            break;
        }
        if (nxtA[cur] != -1) {
            cur = nxtA[cur];
            continue;
        }
        dp.emplace_back(cur);
        cur = nxtB[cur];
    }

    // REP(i, N) cerr << i << " : " << nxtA[i] << ' ' << nxtB[i] << ' ' << dp[i] << endl;
    // cerr << "dpsize " << dp.size() << endl;

    print_result(dp[(K - 1) % (int)dp.size()]);

}

Measured memory_bytes: 18160
#include <cstdio>
#include <vector>

using namespace std;

const int mod = 1000000007;
vector <int> v[5000];
long long a[5001];
int dp[2][5000][5001][2];

int dfs(int x, int y) {
    int c = 1, i, j, k, l, r;
    
    dp[0][x][1][0] = 1;
    
    for (i = 0; i < v[x].size(); i++) {
        int nx = v[x][i];
        
        if (nx == y) continue;
        
        int p = dfs(nx, x);
        
        for (j = 1; j <= c; j++) {
            for (k = 0; k < 2; k++) {
                if (dp[0][x][j][k] == 0) continue;
                
                for (l = 1; l <= p; l++) {
                    for (r = 0; r < 2; r++) {
                        if (dp[0][nx][l][r] == 0) continue;
                        
                        dp[1][x][j + l][(k + r) % 2] += (long long)dp[0][x][j][k] * dp[0][nx][l][r] % mod;
                        if (dp[1][x][j + l][(k + r) % 2] >= mod) dp[1][x][j + l][(k + r) % 2] -= mod;
                        
                        dp[1][x][j][(k + r + 1) % 2] += (long long)dp[0][x][j][k] * dp[0][nx][l][r] % mod * a[l] % mod;
                        if (dp[1][x][j][(k + r + 1) % 2] >= mod) dp[1][x][j][(k + r + 1) % 2] -= mod;
                    }
                }
            }
        }
        
        c += p;
        
        for (j = 1; j <= c; j++) {
            for (k = 0; k < 2; k++) {
                dp[0][x][j][k] = dp[1][x][j][k];
                dp[1][x][j][k] = 0;
            }
        }
    }
    
    return c;
}

int main() {
    int n, i, j, k;
    long long ans = 0;
    
    a[2] = 1;
    for (i = 4; i <= 5000; i += 2) a[i] = a[i - 2] * (i - 1) % mod;
    
    scanf("%d", &n);
    
    for (i = 0; i < n - 1; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        y--;
        
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    dfs(0, -1);
    
    for (i = 1; i <= n; i++) {
        for (j = 0; j < 2; j++) {
            if (dp[0][0][i][j] == 0) continue;
            
            if (j % 2 == 0) {
                ans += dp[0][0][i][j] * a[i] % mod;
            } else {
                ans -= dp[0][0][i][j] * a[i] % mod;
            }
        }
    }
    
    printf("%lld\n", (ans % mod + mod) % mod);
    
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int>costs(n);
    for(int i = 0;i < n; i++){
        cin >> costs[i];
    }
    vector<int>dp(n);
    dp[0] = 0;
    dp[1] = abs(costs[0]-costs[1]);
    for(int i = 2;i<dp.size();i++){
        dp[i] = min(dp[i-1] + abs(costs[i-1] - costs[i]), dp[i-2] + abs(costs[i-2] - costs[i]));
    }
    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop pop_back()
#define sz size()
using namespace std;
typedef long long ll;
bool isPrime(ll n)
{
    if(n==1)
        return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
        return false;
    return true;
}
int lcm(ll a, ll b)
{
    ll temp = __gcd(a, b);

    return temp ? (a / temp * b) : 0;
}
unordered_map<ll,ll>mapp;
ll ma=-999;
///////////////////////////////////////////
ll n,m,i,j,in=-1,cnt,sum;
vector<ll>vi;
string s,t;
long double r;
long double mi=100000000;
ll a[200000],c,x,y;
int main(){
    cin>>s;
    for(i=0;i<s.sz;i++){
        if(s[i]=='1'){
            t+='1';
        }
        else if(s[i]=='0')
            t+='0';
        else if(t!="" && s[i]=='B'){
            t.pop;
        }
    }
    cout<<t;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
	const char *comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#define pi 3.141592653589
#define MOD 1000000007
#define to() int t; cin>>t; while(t--)
#define pb push_back
#define in insert
#define mp make_pair
#define ff first
#define ss second
#define si(s) s.size()
#define fori(it,v) for(it=v.begin();it!=v.end(); it++)
#define for1(low,high,k) for(int i=low;i<high;i+=k)
#define for11(low,high,k) for(int j=low;j<high;j+=k)
#define for2(low,high,k) for(int i=low;i<=high;i+=k)
#define rev(high,low,k)  for(int i=high;i>=low ;i-=k)
#define all(x) x.begin(), x.end()
#define fil(x,i) memset(x,i,sizeof(x));
#define setbits(x) __builtin_popcount(x)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;

void i_o() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin) ;
	freopen("output.txt", "w", stdout) ;
#endif
}

int main()
{
	boost;
	i_o();
	ll n,x,m; cin>>n>>x>>m;
	vector<ll>v;
	unordered_map<ll,int>um;
	ll ans=0;
	while(n>0  && um.find(x)==um.end()){
		um[x]=v.size();
		v.pb(x); ans+=x;
	//	trace(x,v.size()-1);
		n--;
		x=(x*x)%m;
	}
	if(n>=1 && x>0){
		int len=v.size()-um[x];
		//trace(len);
		//trace(x,um[x]);
		ll r=n/(len*1LL);
		if(r>0){
			ll sum=0;
			for1(um[x],(int)v.size(),1) sum+=v[i];
			ans+=r*sum;
		}
		int d=n%len;
		for(int i=um[x];i<um[x]+d;i++) ans+=v[i];
	}

	cout<<ans<<endl;

	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back

// min -> ng = -1, ok = SZ(A)
// max -> ok = -1, ng = SZ(A)
ll bsearch(vec A, ll x, ll ok, ll ng, ll pos)
{
    ll mid;

    while(abs(ok - ng) > 1) {
        mid = (ok + ng) / 2;
        if(A[pos] * A[mid] <= x) ok = mid;
        else ng = mid;
    }

    return ok;
}


int main()
{
    ll N, K;
    cin >> N >> K;
    vec A(N);
    REP(i,0,N) cin >> A[i];
    
    ASC(A);

    ll X, S;
    ll left = -INF, right = INF;
    ll ok, ng, m;
    while(right - left > 1) {
        S = 0;
        X = (left + right) / 2;
        REP(i,0,N) {
            if(A[i] > 0) {
                ok = -1; ng = N;
                while(ng - ok > 1) {
                    m = (ok + ng) / 2;
                    if(A[i] * A[m] <= X) ok = m;
                    else ng = m;
                }
                S += 1 + ok;
            }
            else if(A[i] < 0) {
                ok = N; ng = -1;
                while(ok - ng > 1) {
                    m = (ok + ng) / 2;
                    if(A[i] * A[m] <= X) ok = m;
                    else ng = m;
                }
                S += N - ok;
            }
            else if(X >= 0) S += N;
            if(A[i] * A[i] <= X) --S;
        }
        if(S / 2 >= K) right = X;
        else left = X;
    }
    PR(right);

    return 0;
}

/*

min X : A[i]A[j] <= X となるA[i]A[j]がK個以上

*/

Measured memory_bytes: 1792
class SegmentTree:
    seg_len = 1
    node = []
    def __init__(self, n):
        while self.seg_len < n:
            self.seg_len <<= 1
        self.node = [ 0 for _ in range(self.seg_len*2) ]

    def add(self, idx, v):
        idx += self.seg_len
        self.node[idx] += v
        while True:
            idx //= 2
            if idx == 0:
                break
            self.node[idx] = self.node[idx*2] + self.node[idx*2+1]

    def sum(self, l, r):
        l += self.seg_len
        r += self.seg_len
        ret = 0
        while l < r:
            if l & 1 == 1:
                ret += self.node[l]
                l += 1
            if r & 1 == 1:
                ret += self.node[r-1]
                r -= 1
            l //= 2; r //= 2;
        return ret


n, k = map(int, input().split())
p = [ int(x) for x in input().split() ]

seg_tree = SegmentTree(n)
for i in range(n):
    seg_tree.add(i, (1+p[i])/2)

ans = 0
for i in range(n-k+1):
    ans = max(ans, seg_tree.sum(i, i+k))

print(ans)


Measured memory_bytes: 111624
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    string s;
    cin >> s;
    vector<int>arr(26,0);
    for (auto ss: s) {
        arr[ss - 'a']++;
    }
    rep(i, 26) {
        if (arr[i] == 0) {
            cout << char('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
d,g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]
 
ans = float("inf")
 
for bit in range(1 << d):
    count = 0
    sum = 0
    L=[]
 
    for i in range(d):
        if bit & (1 << i):
            sum += pc[i][0] * (i + 1) * 100 + pc[i][1]
            count += pc[i][0]
        else:
            L.append(i+1)
            
    if sum < g:
        n = min(pc[max(L)-1][0], -(-(g - sum) // (max(L) * 100)))
        count += n
        sum += n * max(L) * 100
 
    if sum >= g:
        ans = min(ans, count)
print(ans)

Measured memory_bytes: 3064
# 解説AC(のつもり)
n = gets.to_i
s = []
m = 0
d = 0
while m != n do
  if (n - m) % (2 ** (d + 1)) != 0
    s[d] = 1
    m += (-2) ** d
  else
    s[d] = 0
  end
  d += 1
end
puts (s.empty?) ? 0 : s.reverse.join


Measured memory_bytes: 1788
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	double a,b;
	cin >> a >> b;
	P((int)ceil((a+b)/2.0));
}

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


Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(X: Long, Y: Long, Z: Long){
    println((X-Z)/(Y+Z))
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val X = sc.next().toLong()
    val Y = sc.next().toLong()
    val Z = sc.next().toLong()
    solve(X, Y, Z)
}



Measured memory_bytes: 31400
#include <bits/stdc++.h>
using namespace std;
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);

    int n;
    cin>>n;
    cout<<(1000-n%1000)%1000<<endl;
    return 0;
}

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

int main(){
    int n,m;cin>>n>>m;
    string s;cin>>s;
    vector<int>a,b;
    map<int,int>c;
    for(int i=0;i<=n;++i){
        if(s[i]=='0'){
            a.push_back(i);
            c[i]=1;
        }
    }
    int now=n;
    while(now>0){
        int l=lower_bound(a.begin(),a.end(),now-m)-a.begin();
        if(a[l]==now){
            cout<<-1<<endl;
            return 0;
        }
        b.push_back(now-a[l]);
        now=a[l];
    }
    reverse(b.begin(),b.end());
    for(int i=0;i<b.size();++i){
        if(i!=b.size()-1)cout<<b[i]<<" ";
        else cout<<b[i]<<endl;
    }
}

Measured memory_bytes: 6136
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	for(int i=1;i<=5;i++) {
    		int x = sc.nextInt();
    		if(x==0) {
    			System.out.println(i);
    		}
    	}

    }
}

Measured memory_bytes: 27036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,k;cin>>n>>k;
    ll ans =0;
    for(ll b=k+1;b<=n;b++){
        ans+=(b-k)*(n/b);
        ll extra = n%b - max(0ll , k-1);
        ans+=max(0ll,extra);
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<vector<int>> f(n, vector<int>(10, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> f[i][j];
        }
    }
    vector<vector<int>> p(n, vector<int>(11, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> p[i][j];
        }
    }
    int res = -0x3f3f3f3f;
    for (int i = 1; i < 1024; i++) {
        int r = 0;
        for (int j = 0; j < n; j++) {
            int c = 0;
            for (int k = 0; k < 10; k++) {
                c += ((i >> k) & 1) * f[j][k];
            }
            r += p[j][c];
        }
        res = max(res, r);
    }
    cout << res << endl;
}




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

using namespace std;

using int64 = long long;

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

  int64 a, b, c;
  cin >> a >> b >> c;
  int count = 0;
  for (int i = 0; i < 100; i++) {
    if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
      break;
    }
    int64 na = (b + c) / 2;
    int64 nb = (c + a) / 2;
    int64 nc = (a + b) / 2;
    a = na;
    b = nb;
    c = nc;
    count++;
  }
  if (count == 100) count = -1;
  cout << count << endl;
}


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

int a[200005];
int b[200005];
int main(){
  int n;
  cin >> n;
  int tmp;
  int ans;
  int count=0;
  for(int i=1;i<n+1;i++)cin >> a[i];
  for(int i=n;i>0;i--){
    tmp=i;
    ans=0;
    while(tmp<=n){
      ans+=b[tmp];
      tmp+=i;
    }
    if(ans%2!=a[i]){
      b[i]++;
      count++;
    }
  }
  cout << count << endl;
  for(int i=1;i<n+1;i++)if(b[i]>0)cout << i <<endl;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n;
    cin>>n;
    vector<int> x(n);
    rep(i,n) cin>>x[i];
    int ans =1000000007;

    for(int i=1;i<=100;i++){
            int sum=0;
        rep(j,n){
            sum += (x[j]-i)*(x[j]-i);
        }
        ans=min(sum,ans);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
int cmp(const void *a,const void *b){
  return *(int *)b-*(int *)a;
}
int main(void){
  int n,i,j,s[100];
  while(1){
    scanf("%d",&n);
    if(!n)
      break;
    memset(s,0,sizeof(s));
    for(i=0;i<n;i++){
      for(j=0;j<5;j++){
        int t;
        scanf("%d",&t);
        s[i]+=t;
      }
    }
    qsort(s,n,sizeof(int),cmp);
    printf("%d %d\n",s[0],s[n-1]);
  }
  return 0;
}

Measured memory_bytes: 604
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int H, W;
	std::vector<std::string> S;
	std::cin >> H >> W;
	S.resize(H);
	for (auto& s : S) {
		std::cin >> s;
	}
	
	auto ismine = [&](int x, int y)->char{
		if (x < 0 || x >= W || y < 0 || y >= H)
			return 0;
		else
			return (S[y][x] == '#') ? 1 : 0;
	};
	
	for (int y = 0; y < H; ++y) {
		for (int x = 0; x < W; ++x) {
			if (!ismine(x, y)) {
				S[y][x] = '0' +
					ismine(x-1, y-1) +
					ismine(x-1, y  ) +
					ismine(x-1, y+1) +
					ismine(x  , y-1) +
					ismine(x  , y+1) +
					ismine(x+1, y-1) +
					ismine(x+1, y  ) +
					ismine(x+1, y+1);
			}
		}
	}
	for (auto& s : S) {
		std::cout << s << "\n";
	}
}


Measured memory_bytes: 256
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;
int main(){
    int a,i=1;
    while(cin >> a){
        if(a==0) break;
        else{
            cout << "Case " << i << ": " << a << endl;
        }
        i++;
    }
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;

int N,A[200000],B[200000];

int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i]>>B[i];
	}
	sort(A,A+N);
	sort(B,B+N);
	if(N&1){
		cout<<B[N/2]-A[N/2]+1<<endl;
	}
	else{
		cout<<(B[N/2-1]+B[N/2]-A[N/2-1]-A[N/2]+1)<<endl;
	}
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int need_cnt(char c) {
    return 26 - (c - 'a');
}

char rot(char c, int k) {
    int n = ((c - 'a') + k) % 26;
    return (char) n + 97;
}

int main() {
    string s;
    int K;
    cin >> s >> K;
    string ans;
    rep(i, s.size()) {
        char c = s[i];

        if (i == s.size() - 1) {
            ans += rot(c, K);
        } else {
            if (c == 'a' || K <= 0) {
                ans += c;
                continue;
            }
            
            int cnt = need_cnt(c);
            if (cnt <= K) {
                K -= cnt;
                ans += rot(c, cnt);
            } else {
                ans += c;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
from collections import defaultdict
from heapq import heappush, heappop

def dijkstra(V, E, s):
    '''
    Input:
        V = list(range(N))
        E = defaultdict(dict)
        s (in V) : start vertex
    Output:
        dist: the list of the minimum cost from s to arbitrary vertex v in the given graph
    '''
    INF = float('inf')
    N = len(V)
    dist = [INF]*N
    heap = []
    heappush(heap, (0, s))
    while heap:
        d, v = heappop(heap)
        # don't need to check when the stored value is greater than provisional distance
        if d > dist[v]:
            continue
        dist[v] = d
        for u, c in E[v].items():
            temp = d + c
            if temp < dist[u]:
                heappush(heap, (temp, u))
    return dist

N = int(input())
V = list(range(N))
E = defaultdict(dict)
for _ in range(N-1):
    a, b, c = map(int, input().split())
    E[a-1][b-1] = c
    E[b-1][a-1] = c
Q, K = map(int, input().split())
dist = dijkstra(V, E, K-1)
for _ in range(Q):
    x, y = map(int, input().split())
    ans = dist[x-1] + dist[y-1]
    print(ans)

Measured memory_bytes: 72168
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n-1):
  if a[i] == a[i+1] - 1:
    ans += c[a[i]-1]
print(sum(b) + ans)

Measured memory_bytes: 3064