akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void){
  int h[5]={};
  int rock,scissors,paper;

  while(1){
    rock=0; scissors=0; paper=0;
    for(int i=0;i<5;i++){
      scanf("%d",&h[i]);
      if(h[0]==0) break;//

      switch(h[i]){
        case 1:
          rock++;
          break;
        case 2:
          scissors++;
          break;
        case 3:
          paper++;
          break;
        default:
          break;
      }
    }
    if(h[0]==0) break;//

    if(rock!=0 && scissors!=0 && paper==0){
      for(int i=0;i<5;i++){
        if(h[i]==1) printf("1\n");
        else printf("2\n");
      }
    }
    else if(rock==0 && scissors!=0 && paper!=0){
      for(int i=0;i<5;i++){
        if(h[i]==2) printf("1\n");
        else printf("2\n");
      }
    }
    else if(rock!=0 && scissors==0 && paper!=0){
      for(int i=0;i<5;i++){
        if(h[i]==3) printf("1\n");
        else printf("2\n");
      }
    }
    else{
      for(int i=0;i<5;i++){
        printf("3\n");
      }
    }

  }
  return 0;
}



Measured memory_bytes: 2076
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in xrange(n)]

def make2d_arr(w,h,val =INF):
    return [[val for i in xrange(w)]for i in xrange(h)]

table = {"A":"T", "C":"G", "G":"C", "T":"A" }
S = raw_input()

ans = 0
for i in xrange(len(S)):
    for j in xrange(i,len(S)):
        if S[j] in table:
            ans = max(ans,j-i+1)
        else:
            break
print ans


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n;
    cin >> n;
    vector<P> rp(n), bp(n);

    rep(i, n){ cin >> rp[i].first >> rp[i].second;}
    rep(i, n){ cin >> bp[i].first >> bp[i].second;}
    sort(bp.begin(), bp.end());
    sort(rp.begin(), rp.end());

    int ans = 0;
    rep(i, n){
        P p = bp[i];
        P x = {-1, -1};
        int mpoint = -1; 
        rep(j, n){
            if(p.first < rp[j].first && rp[j].first != 1000) {
                break;
            } else {
                if (p.second > rp[j].second){
                    if (x.second < rp[j].second){
                        x = rp[j];
                        mpoint = j;
                    }
                }
            }
        }
        if (mpoint != -1){
            ans++;
            rp[mpoint] = {1000, 1000};            
        }
    }

    cout << ans << endl;

}



Measured memory_bytes: 3608
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
signed main(){
  ll a,b,c,d,tmp,ans=0;
  cin >> a >> b >> c >> d;
  tmp = c/gcd(c,d)*d;
  ans = (b/c)-(a/c) + (b/d)-(a/d);
  if(a%c==0) ans++;
  if(a%d==0) ans++;
  ans -= (b/tmp)-(a/tmp);
  if(a%tmp==0) ans--;
  ans = b-a+1-ans;
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
   
#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, h[N], a[N];
ll t[4 * N];

ll get (int r, int v = 1, int tl = 1, int tr = n) {
   if (tl > r) return 0;
   if (tr <= r) return t[v];
   int tm = tl + tr >> 1;
   return max (get (r, v + v, tl, tm), get (r, v + v + 1, tm + 1, tr));
}

void upd (int pos, ll val, int v = 1, int tl = 1, int tr = n) {
   if (tl == tr) {
      t[v] += val;
      return;
   }
   int tm = tl + tr >> 1;
   if (pos <= tm) upd (pos, val, v + v, tl, tm);
   else upd (pos, val, v + v + 1, tm + 1, tr);
   t[v] = max (t[v + v], t[v + v + 1]);
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> h[i];
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i <= n; i ++) {
      upd (h[i], get (h[i]) + a[i]);
   }
   cout << t[1];
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

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

int main() {
    int n;
    cin >> n;
    vector<string> s (n);
    for(int i=0; i<n; i++){
        cin >> s.at(i);
        sort(s.at(i).begin(),s.at(i).end());
    }
    ll ans = 0;
    sort(s.begin(),s.end());
    map<string,int> m;
    for(int i=0; i<n; i++){
        if(m.count(s.at(i))){
            ans += m.at(s.at(i));
            m[s.at(i)] += 1;
        }
        else{
            m[s.at(i)] = 1;
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;

const int MAX_N = 100010;
int par[MAX_N];
int rnk[MAX_N];

void init(int n) {
    rep(i,n) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rnk[x] < rnk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rnk[x] == rnk[y]) rnk[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    int N, M, K, A, B, C, D;
    cin >> N >> M >> K;
    vector<vector<int>> fr(N), bl(N);
    vector<int> g(N, 1);
    init(N);
    rep(i, M) {
        cin >> A >> B;
        A--;
        B--;
        fr[A].push_back(B);
        fr[B].push_back(A);
        if (!same(A, B)) {
            int x = g[find(A)] + g[find(B)];
            unite(A, B);
            g[find(A)] = x;
            //cout << A << B << g[A] << g[B] << endl;
        }
    }
    rep(i, K) {
        cin >> C >> D;
        C--;
        D--;
        bl[C].push_back(D);
        bl[D].push_back(C);
    }
    rep(i, N) {
        ll ans = g[find(i)] - fr[i].size() - 1;
        rep(j, bl[i].size()) {
            if (same(i, bl[i][j])) ans--;
        }
        cout << ans;
        if (i == N - 1) cout << endl;
        else cout << " ";
    }
    //rep(i, N) cout << g[find(i)] << endl;
}

Measured memory_bytes: 13048
n, k = gets.chomp.split.map(&:to_i)
s = gets.chomp

if s[k-1] == "A"
  s[k-1] = "a"
elsif s[k-1] == "B"
  s[k-1] = "b"
elsif s[k-1] == "C"
  s[k-1] = "c"
end

puts s

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

typedef long long ll;

long long int modPow(long long int a, long long int n){//繰り返し自乗法(a^n mod p)。計算量 O(logN)
    long long int p = pow(10, 9) + 7;//任意のp(素数) modのやつで使える 
    if(n == 0){
        return 1;
    }
    if(n == 1){
        return a % p;
    }
    if (n % 2 == 1){ 
        return (a * modPow(a, n - 1)) % p;
    }      
    long long t = modPow(a, n / 2);
    return (t * t) % p;
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }

    for(int i = k; i < n; i++){
        if(a.at(i) > a.at(i - k)){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    
    /*ll border = 1;
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
        if(i < k){
            border *= a.at(i);
        }
    }

    ll tmp = border;
    for(int i = k; i < n; i++){
        tmp /= a.at(i - k);
        tmp *= a.at(i);
        //cout << border << endl;
        if(tmp > border){
            border = tmp;
            cout << "Yes" << endl;
        }else{
            border = tmp;
            cout << "No" << endl;
        }
    }*/

}

Measured memory_bytes: 4836
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    VI a(n);
    REP(i,n){
        cin >> a[i];
    }

    int b = 0;
    REP(i,n){
        if(a[i]%2==1){
            b++;
        }
    }

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


Measured memory_bytes: 1656
str = gets.chomp.reverse
n = str.size/5
for i in 0..n
	target = str[0..6]
	if target.include?("resare")
		str.slice!("resare")
	elsif target == "remaerd"
		str.slice!("remaerd")
	elsif target.include?("esare")
		str.slice!("esare")
	elsif target.include?("maerd")
		str.slice!("maerd")
	end
end
if str == ""
	puts "YES"
else
	puts "NO"
end



Measured memory_bytes: 75260
from heapq import *
n, k = map(int, input().split())
d = list(map(int, input().split()))

res = 0
num = min(k, n)
for a in range(num + 1):
    for b in range(num + 1 - a):
        trash = k - (a + b)
        s = d[:a] + d[-b:] if b != 0 else d[:a]
        heapify(s)
        for _ in range(min(trash, a + b)):
            tmp = heappop(s)
            if tmp > 0:
                heappush(s, tmp)
                break
        res = max(res, sum(s))
print(res)


Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = int(input())
    MOD = 10 ** 9 + 7

    if S <= 2:
        print(0)
        exit()

    dp = [1] * (S + 1)
    dp[0] = 0
    dp[1] = 0
    dp[2] = 0


    for i in range(3, S + 1):
        for j in range(i - 3, 1, -1):
            dp[i] += dp[j]
            dp[i] %= MOD

    print(dp[S] % MOD)


if __name__ == '__main__':
    main()



Measured memory_bytes: 64516
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
	ll n;
	cin>>n;
	ll h[n];
	
	
	for (ll i = 0; i < n; i++) {
		cin>>h[i];
	}
	ll len = 0;
	ll val = 0;
	for (ll i = 1; i < n; i++) {
		if (h[i - 1] >= h[i]) {
			len += 1;
		} else {
			len = 0;
		}
		val = max(len, val);
	}
	cout << val;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
//グラフDFS
void dfs(ll x, vector<vector<ll>> &g, vector<bool> &see, vector<pair<ll, ll>> &ans, ll &cnt)
{
  //点xに対する処理
  see[x] = 1;
  for (auto p : g[x])
  {
    if (see[p])
      continue;
    //進む辺に対する処理（これは木構造でオイラーツアーするために使う）
    dfs(p, g, see, ans, cnt);
    //戻る辺に対する処理
  }
  ans[x].first = cnt;
  cnt++;
}
int main()
{
ll n, m;
cin >> n >> m;
vector<vector<ll>> g(n);
rep(i, m)
{
  ll a, b;
  cin >> a >> b;
  g[a].push_back(b);
}
ll cnt = 1;
vector<bool> see(n);
vector<pair<ll, ll>> ans(n);
rep(i, n) ans[i].second = i;
rep(i, n)
{
  if (!see[i])
    dfs(i, g, see, ans, cnt);
}
sort(ans.begin(),ans.end());
reverse(ans.begin(),ans.end());
rep(i,n)cout << ans[i].second << endl;
return 0;
}


Measured memory_bytes: 3932
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  vector<vector<int>> c(3, vector<int>(3));
  REP(i, 3) REP(j, 3) cin >> c[i][j];

  int a[3];
  for(a[0] = 0; a[0] <= 100; a[0]++){
    for(a[1] = 0; a[1] <= 100; a[1]++){
      for(a[2] = 0; a[2] <= 100; a[2]++){
        vector<vector<int>> tmp = c;
        bool f = true;
        REP(i, 3) REP(j, 3) tmp[i][j] -=a[i];
        REP(i, 3) if(tmp[0][i] != tmp[1][i] || tmp[1][i] != tmp[2][i]) f = false;
        if(f){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

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

int main(void){
    int n;
    cin>>n;
    int a,b,c;
    for (int i = 0; i < n; ++i) {
        cin>>a>>b>>c;
        int m=max(a,max(b,c));
        if(m*m*2==a*a+b*b+c*c)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    vector<int> h(n, 0);
    vector<ll> a(n, 0);
    for(int& val: h)
        cin >> val;
    for(ll& val: a)
        cin >> val;
    map<int, ll> tree;
    tree[0] = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        // maintain a increasing
        auto it = tree.lower_bound(h[i]);
        ll cur = prev(it)->second + a[i];
        vector<int> rev; // remove
        while(it != tree.end() && it->second <= cur) {
            rev.push_back(it->first);
            ++it;
        }
        for(int k: rev)
            tree.erase(k);
        tree[h[i]] = cur;
        ans = max(ans, cur);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 15104
n, m, q = map(int, input().split())
tmp = [[0] * 510 for _ in range(510)]
for _ in range(m):
    l, r = map(int, input().split())
    tmp[l][r] += 1
for i in range(1, 501):
    for j in range(1, 501):
        tmp[i][j] += tmp[i-1][j]
        tmp[i][j] += tmp[i][j-1]
        tmp[i][j] -= tmp[i-1][j-1]
for _ in range(q):
    ans = 0
    ll, rr = map(int, input().split())
    print(tmp[rr][rr]-tmp[rr][ll-1]-tmp[ll-1][rr]+tmp[ll-1][ll-1])
    

Measured memory_bytes: 77772
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N;
	cin >> N;

	vector<int> A(N + 1, 0);

	for (int i = 1; i <= N; i++)
	{
		cin >> A[i];
	}

	int Bcnt = 0;
	vector<int> B(N + 1, 0);

	for (int i = N; i >= 1; i--)
	{
		int total = 0;
		for (int j = i + i; j <= N; j += i)
		{
			total ^= B[j];
		}

		if (total != A[i])
		{
			Bcnt++;
			B[i] = 1;
		}
	}

	cout << Bcnt << "\n";
	for (int i = 1; i <= N; i++)
	{
		if (B[i])
		{
			cout << i << " ";
		}
	}

	return 0;
}

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

using namespace std;

bool palin(string s, int l, int r){
  for(int i=l;i<=r;i++){
    if(s[i]!=s[r-i]) return false;
  }
  return true;
}

int main(){
  double n;
  cin>>n;
  double res = (n/3);
  res = pow(res,3);
  printf("%.12f\n",res);
}

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

const int n = 1299709;
bool is_prime[n + 1];
vector<int> prime_list;

void init() {
    for (size_t i = 2; i <= n; i++) {
        is_prime[i] = true;
    }
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime_list.push_back(i);
            for (int j = 2 * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
}

void solve(const int& k) {
    if (is_prime[k]) {
        cout << 0 << endl;
        return;
    }
    auto greater_prime_number_iterator = upper_bound(prime_list.begin(), prime_list.end(), k);
    cout << *greater_prime_number_iterator - *(greater_prime_number_iterator - 1) << endl;
}

int main() {
    init();
    int k;
    while (true) {
        cin >> k;
        if (k == 0) {
            break;
        }
        solve(k);
    }
}


Measured memory_bytes: 4528
d=int(input())
c=list(map(int,input().split()))
sa=[list(map(int,input().split())) for _ in range(d)]
last=[-1]*26
ty=[int(input())-1 for _ in range(d)]
sat=0
for day,i in enumerate(ty):
  last[i]=day
  sat+=sa[day][i]
  for j in range(26):
    sat-=c[j]*(day-last[j])
  print(sat)
  

"""
18398
35037
51140
65837
79325
"""

Measured memory_bytes: 68564
#include<bits/stdc++.h>
    using namespace std;
    int n, a[200001];
    int main()
    {
        int n;
        scanf("%d", &n);
        for (int i = 0; i < n; ++i)
            scanf("%d", &a[i]);
        sort(a, a + n);
        int ma = a[n - 1], z = (ma + 1) / 2, i;
        for (i = 0; i < n; ++i){
            if (a[i] <= z && a[i + 1] > z) break;
        }
        if (z - a[i] > a[i + 1] - z) printf("%d %d\n", ma, a[i + 1]);
        else printf("%d %d\n", ma, a[i]);
        return 0;
    }


Measured memory_bytes: 640
a = []

for i in range(3):
    a.append(list(map(int, input().split())))

n = int(input())

b = []

for i in range(n):
    b.append(int(input()))

ans = "No"
flag = 0

#yoko
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            flag += 1
    if flag == 3:
        ans = "Yes"
    flag = 0

#tate
for j in range(3):
    for i in range(3):
        if a[i][j] in b:
            flag += 1
    if flag == 3:
        ans = "Yes"
    flag = 0

#naname1
for i in range(3):
    for j in range(3):
        if i == j:
            if a[i][j] in b:
                flag += 1
        if flag == 3:
            ans = "Yes"
flag = 0

#naname2
for i in range(3):
    for j in range(3):
        if i + j == 2 :
            if a[i][j] in b:
                flag += 1
        if flag == 3:
            ans = "Yes"
flag = 0

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define mod MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    ll n; cin >> n;
    ll a[n];
    ll sum[n];
    cin >> a[0];
    sum[0] = a[0];
    for(ll i = 1; i < n; i++){
        cin >> a[i];
        sum[i] = sum[i-1] + a[i];
    }
    ll sum_all = sum[n-1];
    ll mn = 1000000000000000000;
    
    for(ll i = 1; i < n; i++){
        ll diff = abs(sum_all - sum[i-1] - sum[i-1]);

        mn = min(mn, diff);
    }
    cout << mn << endl;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string s;
    cin >> s;
    ll k;
    cin >> k;
    ll ret = 0;
    ll n   = s.size();
    if (n == 1) {
        if (k == 1)
            cout << 0 << "\n";
        else
            cout << k / 2 << "\n";
        return 0;
    }
    if (n == 2) {
        if (s[0] == s[1])
            cout << k << "\n";
        else
            cout << 0 << "\n";
        return 0;
    }

    bool dup       = false;
    bool rep       = false;
    int trailfront = 1;
    int trailend   = 1;
    for (int i = 1; i < n; ++i) {
        if (s[i] == s[i - 1])
            trailfront++;
        else
            break;
    }
    for (int i = n - 2; i >= 0; --i) {
        if (s[i] == s[i + 1])
            trailend++;
        else
            break;
    }
    if ((s[0] == s[1]) && trailfront % 2 == 0)
        dup = true;
    if ((s[n - 2] == s[n - 1] && trailend % 2 == 0))
        dup = true;
    if (s[0] == s[n - 1])
        rep = true;

    bool allsame = true;
    for (int i = 1; i < int(s.size()); ++i) {
        if (s[i] != s[i - 1]) {
            allsame = false;
            break;
        }
    }
    if (allsame) {
        cout << ll(n) * k / 2 << "\n";
        return 0;
    }
    for (int i = 1; i < int(s.size()); ++i) {
        if (s[i] == s[i - 1]) {
            ret++;
            s[i] = '0';
        }
    }
    ret *= k;
    if (rep && !dup) {
        ret += k - 1;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  string s,t; cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), [](char x, char y) -> bool { return x > y; });
  string ans = "No";
  if(s < t) {
    ans = "Yes";
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MAX_N = 2e5+7;

ll N;
vvl G(MAX_N);
vl cs(MAX_N), tree_size(MAX_N), color_cnts(MAX_N,0);
vl ans(MAX_N);

ll nc2(ll x) { return x*(x-1)/2; }

void calc_size(int v, int par = -1) {
    tree_size[v] = 1;
    for (auto to : G[v]) {
        if (to == par) continue;
        calc_size(to, v);
        tree_size[v] += tree_size[to];
    }
}
void dfs(int v, int par = -1) {
    ll prev_cnt = color_cnts[cs[v]];
    for (auto to : G[v]) {
        if (to == par) continue;
        ll prev = color_cnts[cs[v]];
        dfs(to, v);
        ll diff = color_cnts[cs[v]] - prev;
        ll cnt = tree_size[to] - diff;
        // cerr << v << "->" << to << ": " << cnt << endl;
        ans[cs[v]] -= nc2(cnt);
    }
    color_cnts[cs[v]] = prev_cnt + tree_size[v];
}

int main() {
    cin >> N;
    ans.assign(MAX_N, nc2(N));
    rep(i,N) cin >> cs[i+1], ans[cs[i+1]]++;
    rep(i,N-1) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    calc_size(1);
    dfs(1);
    rep(c,N) ans[c+1] -= nc2(N-color_cnts[c+1]);
    rep(i,N) cout << ans[i+1] << "\n";
    return 0;
}


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

int main(){
    vector<char> num(4);
    for(int i=0; i<4; i++){
        cin >> num[i];
    }
    for(int i=0; i<(1<<3); i++){
        int sum = num[0]-'0';
        string ret = "";
        ret += num[0];
        for(int j=0; j<3; j++){
            if((i&1<<j)==0){
                sum += num[j+1]-'0';
                ret += "+";
            }else{
                sum -= num[j+1]-'0';
                ret += "-";
            }
            ret += num[j+1];
        }
        if(sum == 7){
            cout << ret << "=7" << endl;
            break;
        }
    }
    return 0;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	long A, ans = 0;
	priority_queue<long> a;
	for (int i = 0; i < N; ++i) {
		cin >> A;
		a.push(A);
	}
	while (M) {
		--M;
		long b = a.top();
		a.pop();
		a.push(b / 2);
	}
	while (!a.empty()) {
		ans += a.top();
		a.pop();
	}
	cout << ans;
}

Measured memory_bytes: 1400
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll kai(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y&1){
    return (x*kai(x,y-1))%MOD;
  }else{
    ll t = kai(x,y/2);
    return (t*t)%MOD;
  }
}

ll comb(ll a,ll b,vector<ll> &p){
  if(a == 0)return 1;
  if(b == 0)return 1;
  ll ans = p[a+b];
  ans = (ans*kai(p[a],MOD-2))%MOD;
  ans = (ans*kai(p[b],MOD-2))%MOD;
  return ans;
}

ll mind(int x,vector<int> &v){
  int ok = v.size()-1,ng = -1;
  while(ok - ng > 1){
    int next = (ok+ng)/2;
    if(v[next] > x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}

ll maxd(int x,vector<int> &v){
  int ok = 0,ng = v.size();
  while(ng - ok > 1){
    int next = (ok+ng)/2;
    if(v[next] < x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}


int main(){
  int X;
  cin >> X;
  if(X >= 30){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001

int main() {
    string s;
    cin >> s;
    bool x=true;
    int i=0;
    while(i<s.size()) {
        if(s.size()-i<5){
            cout << "NO" << endl;
            return 0;
        }

        if(s[i]=='d' && s[i+1]=='r' && s[i+2]=='e' && s[i+3]=='a' && s[i+4]=='m'){
            if(s.size()>i+6){
                if(s[i+5]=='d'){
                    i += 5;
                }
                else if(s[i+5]=='e' && s[i+6]=='r'){
                    if(s.size()>i+7){
                        if(s[i+7]=='d'||s[i+7]=='e') i+=7;
                        else if(s[i+7]=='a') i += 5;
                        else {
                            x=false;
                            break;
                        }
                    }
                    else break;
                }
                else {
                    x=false;
                    break;
                }
            }
            else break;
        }
        else if(s[i]=='e' && s[i+1]=='r' && s[i+2]=='a' && s[i+3]=='s' && s[i+4]=='e'){
            if(s.size()>i+5){
                if(s[i+5]=='d') i+=5;
                else if(s[i+5]=='r') i+=6;
                else if(s[i+5]=='e') i+= 5;
                else {
                    x=false;
                    break;
                }
            }
            else break;
        }
        else {
            x=false;
            break;
        }
    }

    if(x==false) cout << "NO" << endl;
    else cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 3724
using System;
using System.Reflection;

namespace atcoderTutorial
{
	class Program
	{
		static void Main(string[] args)
		{
			string input = Console.ReadLine();
			char[] results = input.ToCharArray();
			int con = 0;

			if(results[1] != 'R')
            {
				if (results[0] == 'R' || results[2] == 'R')
					con = 1;
            }

			else if(results[1] == 'R')
            {
				con = 1;
				if (results[0] == 'R')
					con++;
				if (results[2] == 'R')
					con++;
            }

			Console.WriteLine(con);
		}
	}

	
}


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

ll temp1,temp2,temp;
char tempc;

#define forn(i,n) for(int i=0;i<int(n);i++)

#define N 1000000007
#define mp make_pair
#define pb push_back
#define f first
// #define s second
#define pi pair<int,int>
#define pl pair<ll,ll>
#define int ll
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)

ll binpow(ll a, ll b)
{
    a%=N;b=b%(N-1);
    ll res=1;
    while(b>0)
    {
        if(b&1) res=res*a%N;
        a=a*a%N;
        b>>=1;
    }
    return res%N;
}

int gcd(int a,int b)
{
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
}

int simpow(int a,int b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1) res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}

// struct DSU {
//     vector<int> sz;
//     vector<int> parent;
 
//     void make_set(int v) {
//         parent[v] = v;
//         sz[v] = 1;
//     }
 
//     int find_set(int v) {
//         if (v == parent[v])
//             return v;
//         return parent[v] = find_set(parent[v]);
//     }
 
//     void union_sets(int a, int b) {
//         a = find_set(a);
//         b = find_set(b);
//         if (a != b) {
//             if (sz[a] < sz[b])
//                 swap(a, b);
//             parent[b] = a;
//             sz[a] += sz[b];
//         }
//     }
 
//     DSU(int n) {
//         sz.resize(n+1);
//         parent.resize(n+1);
//         for (int i = 1; i <= n; i++) make_set(i);
//     }
// };

signed main()
{
    int n; cin >> n;
    vector <int> v(n);
    forn(i,n) cin >> v[i];
    vector <int> a(n);
    forn(i,n) a[i]=i-v[i];
    map <int,int> m;
    forn(i,n) m[i+v[i]]++;
    int ans=0;
    forn(i,n) ans+=m[a[i]];
    cout << ans << endl;
}

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

#define UP 0//North
#define DOWN 1//South
#define RIGHT 2//East
#define LEFT 3//West

int Direct(int s){
	if((s>=65) && (s<=77)){
		return UP;
	}
	if((s>=78) && (s<=90)){
		return DOWN;
	}
	if((s>=97) && (s<=109)){
		return RIGHT;
	}
	return LEFT;
}

void calc(int N,char *S){
	int x=0,y=0;
	int d;

	for(int i=0;i<N;i++){
		d=Direct(S[i]);
		if(d==UP){
			y--;
		}
		if(d==DOWN){
			y++;
		}
		if(d==RIGHT){
			x++;
		}
		if(d==LEFT){
			x--;
		}
	}

	printf("%d\n",(abs(x)+abs(y)));

	d=0;
	if(x>0){
		for(int i=0;i<x;i++){
			printf("a");
		}
	}else{
		x*=-1;
		for(int i=0;i<x;i++){
			printf("n");
		}
	}
	if(y>0){
		for(int i=0;i<y;i++){
			printf("N");
		}
	}else{
		y*=-1;
		for(int i=0;i<y;i++){
			printf("A");
		}
	}
	printf("\n");
}

int main(){
	int N;
	char *S;

	scanf("%d",&N);
	S=(char*)malloc(sizeof(char)*N);


	scanf("%s",S);

	calc(N,S);


	return 0;
}


Measured memory_bytes: 2132
#include<iostream>

using namespace std;

int main(void){
	int w, h, x, y, r;
	while(cin >> w >> h >> x >> y >> r){
		if(x - r >= 0 && y - r >= 0 && x + r <= w && y + r <= h)
		cout << "Yes" << endl;
		else
		cout << "No" << endl;
	}
	return 0;
}

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

int a, b;
string op;

int main() {
  while(1){
    cin >> a >> op >> b;

    if(op == "+"){
      cout << a+b << endl;
    }else if(op == "-"){
      cout << a-b << endl;
    }else if(op == "*"){
      cout << a*b << endl;
    }else if(op == "/"){
      cout << a/b << endl;
    }else{
      break;
    }
  }
}

Measured memory_bytes: 3132
/*#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
ll mod=998244353;

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    double ar[n];
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    sort(ar,ar+n);
    double ans=(ar[0]+ar[1])/2;
    for(int i=2;i<n;i++){
        ans=(ans+ar[i])/2;
    }
    std::cout << std::fixed;
	cout<<std::setprecision(6)<<ans<<endl;

    return 0;
}*/

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

const int N=200001;
int vis[N],val[N];
vector<int> adj[N];

void dfs(int x){
    vis[x] = 1;
    int i, ch;
    for(i = 0; i < adj[x].size(); i++){
        ch = adj[x][i];
        if(vis[ch] == 0){
            //hi[ch] = hi[x] + 1;
            //par[ch]=x;
            val[ch]+=val[x];
            dfs(ch);
        }
    }
}
int main() {
	int n,m;double a=0,b=0,ans=0;int a1,b1;
	cin>>n>>m;
	for(int i=0;i<n-1;i++){
	    cin>>a1>>b1;
	    adj[a1].push_back(b1);adj[b1].push_back(a1);
	}
	for(int i=0;i<m;i++){
        cin>>a1>>b1;
        val[a1]+=b1;
	}
	//hi[1]=0;
	dfs(1);
	for(int i=1;i<n+1;i++)cout<<val[i]<<" ";

	return 0;
}


Measured memory_bytes: 24320
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n, k; cin >> n >> k;
  vector<long long> x(n), y(n); REP(i, n) cin >> x[i] >> y[i];
  long long ans = LINF;
  REP(p, n) REP(q, n) REP(r, n) REP(s, n) {
    if (x[p] < x[q] && y[r] < y[s]) {
      long long L = min({x[p], x[q], x[r], x[s]});
      long long R = max({x[p], x[q], x[r], x[s]});
      long long U = max({y[p], y[q], y[r], y[s]});
      long long D = min({y[p], y[q], y[r], y[s]});
      int cnt = 0;
      REP(i, n) {
        if (L <= x[i] && x[i] <= R && D <= y[i] && y[i] <= U) ++cnt;
      }
      if (cnt >= k) ans = min(ans, (R - L) * (U - D));
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;cin>>n;
    string s;cin>>s;
    string s1;
    int l=s.length();
    for(int i=0;i<l;i++)
    {
        s[i]=s[i]+n;
        if(s[i]>'Z')
            s[i]=s[i]-26;
    }
    cout<<s;
}

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

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //string[] str = Console.ReadLine().Split(' ');
            //int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');

            int n = int.Parse(str[0]);
            int m = int.Parse(str[1]);
            int q = int.Parse(str[2]);

            var a = new int[q,4];

            for(int i = 0; i < q; i++)
            {
                str = Console.ReadLine().Split(' ');
                for(int j = 0; j < 4; j++)
                {
                    a[i, j] = int.Parse(str[j]);
                }
            }

            

            var ans = new int[n];
            for (int i = 0; i < n; i++) ans[i] = 1;

            int max = 0;

            while (ans[0]<=m)
            {
                int temp = 0;
                for(int i = 0; i < q; i++)
                {
                    if (ans[a[i, 1]-1] - ans[a[i, 0]-1] == a[i, 2]) temp += a[i, 3];
                }
               // Console.WriteLine("ans={0},{1},{2}, notoki {3}",ans[0],ans[1],ans[2],temp);

                max = Max(max, temp);

                ans[n - 1]++;
                for(int i = n - 1; i > 0; i--)
                {
                    if (ans[i] > m)
                    {
                        ans[i - 1]++;
                        for(int j=i;j<n;j++)
                        ans[j] = ans[i - 1];
                    }
                }

            }

            Console.WriteLine(max);

            //ここまで
        }

        static int Max(int a, int b)
        {
            if (a > b) return a;
            else return b;
        }


    }

}


Measured memory_bytes: 27340
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a) for(i = 0 ; i < a ; i++)
#define whln(t) while(t--)
#define whlp(t) while(t++)
ll i=0,j=0;


int main(void){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif
	 // int t ;
	 // cin>>t;
	 // whln(t){
  	char a ;
  	cin>>a;
  	if(isupper(a))
  		cout<<"A";
  	else
  		cout<<"a";

}
//   *****  *******   !
//   *		     *    !
//   ***       *      !
//   *       *        !
//   *****  *******   !

Measured memory_bytes: 3544
import itertools
N=int(input())
L = list(map(int, input().split()))
ans=0
for i in itertools.combinations(L, 3):
    x,y,z=i
    if x==y or x==z or y==z:
        continue
    if x+y>z and x+z>y and y+z>x:
        ans+=1

print(ans)


Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1005;
const char END = '\n';

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

	double N;
	ll sub;
	cin >> N;
	sub = N / 2;
	sub = N - sub;

	double Ans = sub / N;
	cout << Ans;
	cout << END;

	return 0;
}

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

bool beki[1000];

int main()
{
    string s;
    cin >> s;
    int memai = 0;
    int memzi = 0;
    bool flag = false;
    int ans = 0;
    int i = 0;
    while (true)
    {
        if (s[i] == 'A')
        {
            memai = i;
            break;
        }
        ++i;
    }
    i = s.size();
    while (true)
    {
        if (s[i] == 'Z')
        {
            memzi = i;
            break;
        }
        --i;
    }

    cout << memzi - memai + 1 << endl;
}

Measured memory_bytes: 640
from sys import exit

d = dict()

for i in range(3):
    tmp = list(map(int, input().split()))
    for j in range(3):
        d[(i, j)] = tmp[j]

N = int(input())
d_inv = {v: k for k, v in d.items()}
for _ in range(N):
    try:
        d[d_inv[int(input())]] = 0
    except KeyError:
        pass
for i in range(3):
    if d[(i, 0)] == d[(i, 1)] == d[(i, 2)] == 0 \
            or d[(0, i)] == d[(1, i)] == d[(2, i)] == 0:
        print('Yes')
        exit()
if d[(0, 0)] == d[(1, 1)] == d[(2, 2)] == 0 \
        or d[(0, 2)] == d[(1, 1)] == d[(2, 0)] == 0:
    print('Yes')
    exit()
print('No')


Measured memory_bytes: 3064
N,T=map(int,input().split())
CT=[]
for i in range(N):
    CT.append(list(map(int,input().split())))
CT=sorted(CT,key=lambda x:x[1],reverse=True)

C=1001
for i in range(N):
    if CT[i][1] <= T:
        C=min(C,CT[i][0])

if C==1001:
    print('TLE')
else:
    print(C)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define mk make_pair
#define pb push_back
#define pa pair<int,int>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<"\n"
using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-') w=-1;ch=getchar();} while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();} return w*s;}
struct node{int to,next;} e[1010100];
int n,h[1010010],tot,dis[1010100];
inline void add(int from,int to){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;}
queue<int> q;
inline int BFS(int S){
	memset(dis,-1,sizeof(dis));
	dis[S]=1;
	q.push(S);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(rint i=h[u];i;i=e[i].next){
			int to=e[i].to;
			if(dis[to]==-1) dis[to]=dis[u]+1,q.push(to);
		}
	}
	int Max=0,o=S;
	for(rint i=1;i<=n;++i) if(Max<dis[i]) Max=dis[i],o=i;
	return o;
}
int f[1010010];
int main()
{	
	n=read();
	for(rint i=1;i<n;++i){int x=read(),y=read();add(x,y);add(y,x);}
	int x=BFS(1);
	int y=BFS(x);
	int tmp=dis[y];
	f[0]=0;f[1]=1;f[2]=0;
	for(rint i=3;i<=tmp;++i){
		if(f[i-1]&&f[i-2]) f[i]=0;
		else f[i]=1;
	}
	if(f[tmp]==1){
		cout<<"First\n"; 
	}else cout<<"Second\n";
	return 0;
}	

Measured memory_bytes: 15360
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    N = int(input())
    ans = 0
    for i in range(1,N+1):
        if not(i%3==0 or i%5==0):
            ans += i
    print(ans)
main()


Measured memory_bytes: 9052
s = input()
n = len(s)
res = 0
for i in range(2**(n-1)):
    k = 0
    b = bin(i)[2:]
    for j in range(len(b)):
        if b[-(j+1)] == '1':
            res += int(s[k:j+1])
            k = j+1
    res += int(s[k:])

            
print(res)

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

int main() {
  int ninzu;
  
  cin >> ninzu;
  
  int kumi = 0;
  int center = 0;
  kumi = ninzu / 2;
  if(ninzu % 2 != 0) center = (ninzu + 1) / 2;
  
  // (最小+最大) * 組み合わせ + 奇数個の場合の中央値
  cout << (1 + ninzu) * kumi + center;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int res=abs(a-b);
	if(res%2){
		cout<<"Borys"<<endl;
	}else{
		cout<<"Alice"<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding Space*/
int main(){
  int n; cin >> n;
  string s; cin >> s;
  string ans = s;
  int ss = s.size();
  int l = 0;
  rep(i,ss){
    if(s[i] == ')'){
      if(l > 0)
        l--;
      else
        ans = "(" + ans;
    }
    if(s[i] == '(')
      l++;
  }
  rep(i,l)
    ans = ans +')';
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;


signed main(){
	int A,B;
	cin >> A >> B;
	if(A + B > 9)out("error");
	else out(A + B);
}

Measured memory_bytes: 3608
#include<stdio.h>
#define N 250 //max nodes is up to 250

typedef struct{
  int key; //key
  int par; //parrent
  int left; //left side
  int right; //right side
}node;

void ndset(int,int);

node T[N]; //identifying each nodes 

int main(){
  int n,i;

  scanf("%d",&n);

  for(i=0; i<n; i++) T[i].par = -1;

  for(i=0; i<n; i++) scanf("%d",&T[i].key);

  for(i=0; i<n; i++){

    if(i != 0) T[i].par = (i+1)/2-1;
    if(2*(i+1)-1 < n) T[i].left = 2*(i+1)-1;
   
    else T[i].left = -1;
    if(2*(i+1) < n) T[i].right = 2*(i+1);
   
    else T[i].right = -1;

  }

  for(i=0; i<n; i++){

    printf("node %d: key = %d, ", i+1, T[i].key);

    if(T[i].par != -1) printf("parent key = %d, ",T[T[i].par].key);
    if(T[i].left != -1) printf("left key = %d, ",T[T[i].left].key);
    if(T[i].right != -1) printf("right key = %d, ",T[T[i].right].key);

    printf("\n");

  }

  return 0;
}

Measured memory_bytes: 604
import queue

H, W = map(int, input().split())
s, count = [], 0
for _ in range(H):
    h = list(input())
    count += h.count('.')
    s.append(['#'] + h + ['#'])
s = [['#'] * (W+2)] + s + [['#'] * (W+2)]
around = [[-1, 0], [0, -1], [1, 0], [0, 1]]

ans, que, already = count + 1, queue.Queue(), set([1 + W])
que.put([1, 1, 1])
while not que.empty():
    q = que.get()
    if q[0] == W and q[1] == H:
        ans = q[2]
        break
    else:
        for a in around:
            nextx, nexty = q[0] + a[0], q[1] + a[1]
            if nextx + W*nexty not in already and s[nexty][nextx] == '.':
                que.put([nextx, nexty, q[2] + 1])
                already.add(nextx + W*nexty)

print(count - ans)

Measured memory_bytes: 4080
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    *c, = map(lambda x: tuple(x), b.items())
    c.sort(key=lambda x: x[0])
    ans = 0
    c = [c[0]] + c + [c[-1]]
    for x, y, z in zip(c, c[1:], c[2:]):
        v = y[0]
        tmp = y[1]
        if v - x[0] == 1:
            tmp += x[1]
        if v - z[0] == -1:
            tmp += z[1]
        ans = max(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15832