akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll n,k;
  std::cin>>n>>k;

  std::vector<ll> p(n);
  for(auto&& e:p)std::cin>>e;

  std::sort(all(p));

  ll ans=0;
  rep(i,0,k)ans+=p[i];

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#define rep(i, n) for(i=1; i<=n; i++)
using namespace std;
int main() {
    int n, m, i;
    cin >> n >> m;
    //map<int, int> roads;
    vector<int> roads(n, 0);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        roads[a-1]++;
        roads[b-1]++;
    }
    for(auto it = roads.begin(); it!=roads.end(); it++){
        cout << *it << "\n";
    }
    return 0;
}

Measured memory_bytes: 3628
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{
    ldb a;ldb b;
    cin>>a>>b;
    a=a*b;
    cout<<(int)a<<endl;
    
    
    
    
}


int32_t main()
{
    IOS;
    //pre();
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

const int mod = 998244353;

LL f[200123]{1}, inv[200123], y[200123]{1};

LL qpow(LL x, int n) {
	LL ans = 1;
	while(n) {
		if(n & 1) ans = ans * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return ans;
}

int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	Rep(i, n) f[i] = f[i-1] * i % mod;
	inv[n] = qpow(f[n], mod-2);
	for(int i = n-1; i >= 0; --i) inv[i] = inv[i+1] * (i+1) % mod;
	Rep(i, n) y[i] = y[i-1] * (m-1) % mod;
	LL ans = 0;
	for(int i = 0; i <= k; ++i) {
		ans += y[n-1-i] * f[n-1] % mod * inv[i] % mod * inv[n-1-i] % mod;
	}
	ans = ans % mod * m % mod;
	if(ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8252
s=input()
a,b=0,[0]*2019
b[0]+=1
for i in range(len(s)-1,-1,-1):
    a=(a+int(s[i])*pow(10,len(s)-i-1,2019))%2019
    b[a]+=1
c=0
for i in b:
    c+=i*(i-1)
print(c//2)

Measured memory_bytes: 9220
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		
		int threeDigitValue = 100*x + 10*y + z;
		if (threeDigitValue%4 == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}



int main() {

	int n, m;
	cin >> n >> m;
	vector<ll > a(n), q(m);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, m) {
		cin >> q[i];
	}
	vector<int> t(n);
	FOR(i,n/2,  n) {
		int b = a[i + i - n + 1];
		int c = a[i] - b;
		t[i] = b + c / 2;
		
	}

	vector<ll> sum(n), odd(n), even(n);
	rep(i, n) {
		if (i == 0) {
			sum[i] = a[i];
		}
		else {
			sum[i] = sum[i - 1] + a[i];
		}
	}

	rep(i, n) {
		if (i == 1) {
			odd[i] = a[i];
		}
		else if (i % 2 == 1) {
			odd[i] = odd[i - 2] + a[i];
		}
	}

	rep(i, n) {
		if (i == 0) {
			even[i] = a[i];
		}
		else if (i % 2 == 0) {
			even[i] = even[i - 2] + a[i];
		}
	}

	rep(i, m) {
		int x = lower_bound(t.begin(), t.end(), q[i]) - t.begin();
		ll t0 = sum[n - 1] - sum[x-1];
		if (2 * x - n - 1 < 0) {
			cout << t0 << endl;
		}
		else if ((2 * x - n - 1) % 2 == 0) {
			cout << even[2 * x - n - 1] + t0 << endl;

		}
		else {
			cout << odd[2 * x - n - 1] + t0 << endl;
		}
	}

}




Measured memory_bytes: 6016
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();

    char[][] A = new char[H][W];
    for (int i = 0; i < H; i++) {
      String line = sc.next();
      for (int j = 0; j < line.length(); j++) {
        A[i][j] = line.charAt(j);
      }
    }
    
    int ans = resolve(A);
    
    System.out.println(ans);
    //System.out.println(Arrays.deepToString(A));
  }
  
  // up, down, left, right
  private static final int[] dx = { 0, 0, -1, 1 };
  private static final int[] dy = { -1, 1, 0, 0 };

  private static int resolve(char[][] a) {
    
    Queue<Node> queue = new ArrayDeque<Node>();

    // initial scan
    for (int i = 0; i < a.length; i++) {
      for (int j = 0; j < a[i].length; j++) {
        if (a[i][j] == '#') {
          queue.add(new Node(j, i, 0));
        }
      }
    }
    
    int max = 0;
    while (!queue.isEmpty()) {
      Node node = queue.remove();
      for (int i = 0; i < 4; i++) {
        int x = node.x + dx[i];
        int y = node.y + dy[i];
        int distance = node.distance + 1;
        if (y < 0 || a.length <= y || x < 0 || a[y].length <= x) {
          continue;
        }
        if (a[y][x] == '.') {
          a[y][x] = '#';
          queue.add(new Node(x, y, distance));
          max = Math.max(max, distance);
        }

      }
    }

    return max;
  }
  
  static class Node {
    final int x;
    final int y;
    final int distance;
    Node(int x, int y, int distance) {
      this.x = x;
      this.y = y;
      this.distance = distance;
    }
  }
}


Measured memory_bytes: 65616
import string
import sys


def main():
    str1 = sys.stdin.read()
    dict1 = {}
    for char in str1.lower():
        if not char.isalpha():
            continue
        elif dict1.__contains__(char):
            dict1[char] += 1
        else:
            dict1[char] = 1
    for char in string.ascii_lowercase:
        print(char + ' : ' + (str(dict1[char]) if dict1.__contains__(char) else '0'))


if __name__ == '__main__':
    main()



Measured memory_bytes: 6676
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define For(i,j,k) for(int i=j;i<=k;++i)
#define Dor(i,j,k) for(int i=j;i>=k;--i)
using namespace std;
const int N=1e5+10;
int a[N];
int main(){
	int n,ans=0;
	scanf("%d",&n); 
	For(i,1,n){
		scanf("%d",&a[i]);
		ans+=abs(a[i]-a[i-1]);
	}ans+=abs(a[n]);
	For(i,1,n){
		printf("%d\n",ans+abs(a[i-1]-a[i+1])-abs(a[i-1]-a[i])-abs(a[i+1]-a[i]));
	}
	return 0;
}


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

#define MAX 10000

int main(){
  int n, *A, i, *B, C[MAX];

  scanf("%d",&n);

  A = (int *)malloc(sizeof(int) * n + 1);
  B = (int *)malloc(sizeof(int) * n + 1);

  for(i = 1; i < n + 1; i++){
    scanf("%d",&A[i]);
  }

  for(i = 0; i < MAX; i++) C[i] = 0;

  for(i = 0; i < n; i++) C[A[i + 1]]++;

  for(i = 0; i < MAX; i++) C[i] = C[i] + C[i-1];

  for(i = n; i > 0; i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }

  for(i = 1; i < n; i++) printf("%d ",B[i]);
  printf("%d\n", B[n]);

  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int availables = 0;
  int h;
  for(int n = 0; n < N; ++n) {
    cin >> h;
    if(h >= K) {
      availables++;
    }
  }
  cout << availables << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;


ll copy(ll x){
	return x;
}
vector<vector<ll>> a(400,vector<ll>(400));
vector<vector<ll>> b(400,vector<ll>(400));
//不平路の有無はd[i][i] < 0となるiがあるかどうかで確かめられる。あったら負閉路が存在

ll d[301][301];// d[u][v]は辺e=(u,v)のコスト(存在しない場合はINF、ただしd[i][i]=0とする) 
void warshall_floyd(int V) {
	for (int k = 0; k < V; k++)
		for (int i = 0; i < V; i++)
			for (int j = 0;j < V; j++) a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
}

int main(){
	int n;cin>>n;//頂点数
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cin>>a[i][j];
			b[i][j] = copy(a[i][j]);
		}
	}
	warshall_floyd(n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if (a[i][j] < b[i][j]){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	ll ans = 0;
	vector<vector<bool>> used(n,vector<bool>(n,false));
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			bool flag = true;
			for(int k = 0; k < n; k++) {
				if (a[i][k] + a[k][j] == a[i][j] && i != k && j != k){
					flag = false;
				}
			}
			if (flag)used[i][j] = true;
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if (used[i][j])ans += b[i][j];
		}
	}
	cout << ans << endl; 

	return 0;
}

Measured memory_bytes: 2816
from collections import deque

def print_dict_multi_low(a_dict):
    for k, v in a_dict.items():
        print("{0} {1}".format(k, v))
        
def calc_round_robin(A, q):
    t = 0
    B = {}
    queue = deque([])
    for k, v in A.items():
        queue.append((k, v))
    
    while queue:
        k, v = queue.popleft()
        residual = int(v) - q
        if residual > 0:
            queue.append((k, residual))
            t += q
        else:
            t += (q + residual)
            B[k] = t
    print_dict_multi_low(B)

def read_n_lows_dict_input(n):
    a_dict = dict(input().split() for _ in range(n))
    return a_dict

n, q = (map(int,input().split()))
A = read_n_lows_dict_input(n)

calc_round_robin(A, q)


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

int main()
{
    int ans = 0;
    string str;
    string sample = "CODEFESTIVAL2016";
    cin >> str;
    for (int i = 0; i < str.size(); i++)
    {
        if (str[i] != sample[i])
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    for(int p=0; p < n; p++){
        string input;
        cin >> input;

        bool firstIsNatural = true;
        for(int i=0; i < input.size(); i++){
            if(i%2 == 0 && input.substr(i,1) == "L") firstIsNatural = false;
            else if(i%2 == 1 && input.substr(i,1) == "R") firstIsNatural = false;

            if(i != 0) if(input[i] == input[i-1]) firstIsNatural = false;
        }
        bool secondIsNatural = true;
        for(int i=0; i < input.size(); i++){
            if(i%2 == 1 && input.substr(i,1) == "L") secondIsNatural = false;
            else if(i%2 == 2 && input.substr(i,1) == "R") secondIsNatural = false;
            if(i != 0) if(input[i] == input[i-1]) secondIsNatural = false;
        }
        if(firstIsNatural || secondIsNatural) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1340
#include <bits/stdc++.h> 
#define ll long long
using namespace std;
int main() 
{ 
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    int dp[n];
    memset(dp,1000000000,sizeof(dp));
    dp[1]=dp[0]+abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1];
} 


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N), rev(N);
    for(int i = 0; i < M; ++i){
        int a, b;
        cin >> a >> b;
        graph[a].emplace_back(b);
        rev[b].emplace_back(a);
    }
    
    vector<int> vs;
    vector<bool> used(N, false);
    auto dfs = [&](auto&& self, int from) -> void {
        used[from] = true;
        for(int to : graph[from]){
            if(!used[to])   self(self, to);
        }
        vs.emplace_back(from);
    };
    for(int v = 0; v < N; ++v){
        if(!used[v])    dfs(dfs, v);
    }
    reverse(vs.begin(), vs.end());
    
    vector<int> idx(N, -1);
    int K = 0;
    auto rdfs = [&](auto&& self, int from) -> void {
        idx[from] = K;
        for(int to : rev[from]){
            if(idx[to] == -1)   self(self, to);
        }
    };
    for(int v : vs){
        if(idx[v] == -1){
            rdfs(rdfs, v);
            ++K;
        }
    }
    
    vector<vector<int>> scc_set(K);
    for(int v = 0; v < N; ++v){
        scc_set[idx[v]].emplace_back(v);
    }
    
    cout << K << '\n';
    for(int i = 0; i < K; ++i){
        int num = scc_set[i].size();
        cout << num << ' ';
        for(int j = 0; j < num; ++j){
            cout << scc_set[i][j];
            cout << ((j == num - 1) ? '\n' : ' ');
        }
    }
}

Measured memory_bytes: 79528
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
ans = 0
s_count = 0
t_count = 0

for i in set(s):
    s_count = 0
    t_count = 0
    for j in s:
        if j == i:
            s_count += 1
    for k in t:
        if k == i:
            t_count +=1
    
    ans = max(ans, s_count - t_count)
print(ans)

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

#define _USE_MATH_DEFINES
#define reb(i,b,n)         for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n)           reb(i,0,n)
#define each(it,v)         for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v)        for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vsort(v)           sort((x).begin(), (x).end()
#define rvsort(v)          sort((x).rbegin(), (x).rend()
#define mp(a, b)           make_pair(a, b)
#define fi                 first
#define se                 second
#define pb                 push_back
#define dbg(x)             cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;
#define dbgArr(table, n)   rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define dbg2Arr(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}

using namespace std; using std::stringstream;

typedef long long       ll; typedef unsigned long long ull; typedef long double     ld;
typedef pair <int, int> P;  typedef pair <int, P>      PP;
typedef vector<int>     vi; typedef vector<vi>         vvi; typedef vector<ll>      vl;
typedef vector<P >      vP; typedef vector<char>       vc;  typedef vector<string>  vs;

static const int    INF  = 0x3f3f3f3f;
static const ll     INFL = 0x3f3f3f3f3f3f3f3fLL;
static const double EPS  = 1e-9;
static const ll     MOD  = 1000000007LL;

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

int main(int argc, char *argv[])
{
    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>

#define rep(i,n) for(int (i)=0;i < (n);(i)++)
#define ll long long
#define INF 9223372036854775807

using namespace std;

// input
ll n,k;

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

  cin >> n >> k;
  ll mod = n % k;

  ll ans = min(mod,-(mod - k));
  cout << ans;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<pll> py(M);
  vector<vector<ll>> town(N);
  for (ll i = 0; i < M; ++i)
  {
    ll p, y;
    cin >> p >> y;
    town.at(p - 1).push_back(y);
    py.at(i) = {p, y};
  }
  for (ll i = 0; i < N; ++i)
  {
    sort(town.at(i).begin(), town.at(i).end());
  }
  for (ll i = 0; i < M; ++i)
  {
    ll temp = 1000000 + py.at(i).first;
    string t_str = to_string(temp);
    ll temp2 = 1000000 + lower_bound(town.at(py.at(i).first - 1).begin(), town.at(py.at(i).first - 1).end(), py.at(i).second) - town.at(py.at(i).first - 1).begin() + 1;
    string t2 = to_string(temp2);
    cout << t_str.substr(1) << t2.substr(1) << endl;
  }
}


Measured memory_bytes: 8576
import java.math.*;
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N =  sc.nextInt();
	    int M =  sc.nextInt();
	    int[] z = new int[N];
	    for (int i = 0; i < M; i++){
            int s = sc.nextInt();
            int c = sc.nextInt();
        if ((z[s-1] != 0 && z[s-1] != c) || (N >= 2 && s == 1 && c == 0)){
            System.out.println(-1);
            return;
        }
        z[s-1] = c;
	    }
	    if (N >= 2 && z[0] == 0){
            z[0] = 1;
        }
	    for (int i = 0; i < z.length; i++){
            System.out.print(z[i]);
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); i++)

int main()
{
    int N;
    int ans = 0;
    cin >> N;
    rep(i, 1, N+1)
    {
        if(to_string(i).size() % 2 != 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main() {
  int number, sum = 0;
  cin >> number;
  for (int hat = 0; hat < 8; hat++){
    if (std::pow(10, hat) <= number && number < std::pow(10, hat + 1)){
      for (int i = 0; i <= hat; i++){
        int level;
        level = number / std::pow(10, i);
        sum = sum + level % 10;
      }
      break;
    }
    else{
      continue;
    }
  }
  if (number % sum == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

struct task {
    task(ll x, ll y)
    {
        len = x;
        deadline = y;
    }

    ll len;
    ll deadline;

    bool operator<(const task &lhs) const {
        if(this->deadline == lhs.deadline)
        {
            return this->len < lhs.len;
        }
        else
        {
            return this->deadline < lhs.deadline;
        }
    }
};

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<task> tasks;
    for(int i=0;i<n;++i)
    {
        int len, dl;
        cin >> len >> dl;
        tasks.PB(task(len, dl));
    }

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

    ll cur = 0;
    bool ret = true;
    for(int i=0;i<n;++i)
    {
        cur += tasks[i].len;
        if (cur > tasks[i].deadline)
        {
            ret = false;
            break;
        }
    }

    cout << (ret ? "Yes" : "No") << endl;
}

Measured memory_bytes: 6384
N,K = map(int,input().split())
src = list(map(int,input().split()))

cums = [0]
p_cums = [0]
for a in src:
    cums.append(cums[-1] + a)
    p_cums.append(p_cums[-1] + max(0,a))

ans = -float('inf')
for l in range(N-K+1):
    r = l + K
    tmp = p_cums[l]
    tmp += max(0, cums[r] - cums[l])
    tmp += p_cums[-1] - p_cums[r]
    ans = max(ans, tmp)
print(ans)


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

using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define bg begin()
#define ed end()
#define sz size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

int main(){
	ll K; cin>>K;
	ll t=K/50;
	ll s=K%50;
	vector<ll> A(51,49+t);
	rep1(i,s){
		rep1(j,50){
			if(j==i) A[j]+=50;
			else A[j]--;
		}
	}
	cout<<50<<endl;
	rep1(i,50){
		printf("%lld ",A[i]);
	}
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
int main() {
	int n, t;
	ll ans = 0;
	cin >> n;
	vector<int> a(n);
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n - 1) {
		ans += a[i] / 2;
		a[i] %= 2;
		ans += t = min(a[i], a[i + 1]);
		a[i] -= t, a[i + 1] -= t;
	}
	ans += a[n - 1] / 2;
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;

int main()
{
  int n; cin >> n;
  for(int i = 0; i < n; i++)
  {
    int a; cin >> a;
    if(!(a & 1)) if(a % 3 && a % 5)
    {
      cout << "DENIED";
      return 0;
    }
  }
  cout << "APPROVED";

  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	List<String> list=new ArrayList<String>();
	for(int i=0;i!=a;i++) {
		String str=scan.next();
		if(!list.contains(str)) {
			list.add(str);
			}
	}
	System.out.println(list.size()==4?"Four":"Three");
	scan.close();
}
}

Measured memory_bytes: 21844
/**
  *  Worg
  */
#include <cstdio>
#include <vector>
#include <cassert>
#include <algorithm>

#define lsb(x) (x & (-x))

//FILE *fin = freopen("main.in", "r", stdin); FILE *fout = freopen("main.out", "w", stdout);

const int kMaxSteps = 100;

/*-------- Structures --------*/
struct Fenwick {
    std::vector<int > v;
    int n;

    Fenwick(const int _n) {
        n = _n;
        v = std::vector<int >(n + 1, 0);
    }

    void Update(int index, int value) {
        for(int i = index; i <= n; i += lsb(i)) {
            v[i] += value;
        }
    }

    int Query(int index) {
        int answer = 0;
        for(int i = index; i > 0; i -= lsb(i)) {
            answer += v[i];
        }
        return answer;
    }
};
/*-------- Data --------*/
int N;
std::vector<int > a, b, c;
/*-------- --------*/

void ReadInput() {
    scanf("%d", &N);
    a.resize(N); b.resize(N); c.resize(N);

    for(int i = 0; i < N; i++) {
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
    }
}

bool Comp(int i, int j) {
    return (a[i] * b[j]) > (b[i] * a[j]);
}

double Solve() {
    std::vector<int > id(N);

    for(int i = 0; i < N; i++) {
        if(b[i] < 0) {
            a[i] *= -1; b[i] *= -1; c[i] *= -1;
        }
        id[i] = i;
    }

    std::sort(id.begin(), id.end(), Comp);

    double left = -1e9, right = 1e9;
    std::vector<std::pair<double, int > > elements(N);

    for(int step = 0; step < kMaxSteps; step ++) {
        double mid = 0.5 * (right + left);

        for(int i = 0; i < N; i++) {
            elements[i] = {(double)(c[id[i]] - a[id[i]] * mid) / b[id[i]], i};
        }
        std::sort(elements.begin(), elements.end());

        Fenwick f = Fenwick(N);

        long long inversionCount = 0;
        for(int i = 0; i < N; i++) {
            inversionCount += f.Query(elements[i].second + 1);
            f.Update(elements[i].second + 1, 1);
        }

        if(inversionCount >= (1LL * N * (N - 1) / 2 + 1) / 2) {
            right = mid;
        } else {
            left = mid;
        }
    }

    return 0.5 * (left + right);
}

int main() {
    ReadInput();

    for(int i = 0; i < 2; i++) {
        printf("%.14f ", Solve());

        for(int j = 0; j < N; j++) {
            std::swap(a[j], b[j]);
        }
    }
    printf("\n");

	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
const int INF_INT = 2147483647;
const long long INF_LONG = 9223372036854775807;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
int main() {
  ll n;  cin >> n;
  vector<int> v(0);

  int num=0;
  ll m=0;

  rep (i, 200) {
    ll k = m;
    m += pow(26, i + 1);
    if (m >= n) {
      m = k;
      num = i + 1;
      break;
    }
  }

  n -= m;
  --n;

  rep (i, num) {
    v.push_back(n % 26);
    n /= 26;
  }

  for (int i=v.size()-1; i>=0; --i) {
    char a = 'a';
    a += v[i];
    cout << a;
  }
  cout << endl;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
 
    ll N; cin >> N;
    ll ans = N - 1;
    for (int i= 1 ; i<1000010; i++) {
        if (N % i == 0) {
            ans = min(ans, i + N / i - 2);
        }
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  int d=a/(b+c);
  int f=a-d*(b+c);
  int e=b*d;
  if(f<=b)
    e+=f;
  else
    e+=b;
    cout<<e;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b = LI()
    print(min(n * a, b))
    return

#B
def B():
    n, d = LI()
    x = LIR(n)
    a = list(itertools.combinations(range(n), 2))
    ans = 0
    for a1,a2 in a:
        b = 0
        for bi in range(d):
            b += (x[a1][bi] - x[a2][bi])** 2
        if float.is_integer(math.sqrt(b)):
            ans += 1
    print(ans)
    return

#C
def C():
    l, r = LI()
    ans = 2018
    if l // 2019 == r // 2019:
        for i in range(l, r + 1):
            for k in range(i+1, r + 1):
                ans = min(ans, (i * k) % 2019)
        print(ans)
    else:
        print(0)
    return

#D
def D():
    n = II()
    a = LI()
    a = a + [a[0]]
    ans = [0] * n
    x = 0
    for i in range(1, n, 2):
        x = x + a[i + 1] - a[i]
    ans[1] = a[0] - x
    ans[0] = ans[1] + 2 * x
    for i in range(2, n):
        ans[i] = (a[i - 1] - ans[i - 1] // 2) * 2
    print(" ".join(map(str, ans)))

    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 20028
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
	let ll = 0;
	while (true){
		if(input[ll][0] === '0') break; 
		var n = parseInt(input[ll][0],10);
		var v_w = input[ll + 1].map(e => parseInt(e, 10));
		dp = [];
		for (var i = 0; i < n; i++){
			dp.push([]);
			for (var j = 0; j < n; j++){
				dp[i].push(-1);
			}
		}
		console.log(kukanDP(v_w, 0, n - 1));
		// console.log(dp);

		ll += 2;
	}
}

function kukanDP(w, l, r){
	// console.log(dp);
	// console.log("lr", l, r, dp);
	// console.log(dp);
    //既に計算済み？
    if(dp[l][r] != -1) return dp[l][r];

    //これ以上取り除けない？
    if(Math.abs(l - r) < 1) {
		// console.log("1",l,r, dp);
		return dp[l][r] = 0;
	}

	if(Math.abs(l - r) === 1 && Math.abs(w[l] - w[r]) <= 1) {
		return dp[l][r] = 2;
	}

	let res = 0;
	
    //パターン1.
    if (Math.abs(w[l] - w[r]) <= 1 && dp[l + 1] != null && kukanDP(w, l + 1, r - 1) === Math.abs(r - l) - 1){
		// console.log("here", l, r);
        //[l , r)がはじき出せるので
        res = Math.abs(r - l) + 1;
    }

    //パターン２.区間を分ける
    for(let mid = l; mid <= r - 1; mid++){
        res = Math.max(res , kukanDP(w, l, mid) + kukanDP(w, mid + 1, r));
	}
	// console.log("2",l,r, dp);
    return dp[l][r] = res;
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));




Measured memory_bytes: 26684
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100009
#define MAXM 320
#define EPS 1e-9
#define MOD 1000000007
#define INF 1000000009
#define FOR(x,n) for(int x=0; x<n; x++)
#define FOR1e(x,n) for(int x=1; x<=n; x++)
#define pb push_back
#define all(x) x.begin(), x.end()
typedef long long ll;

set<int> sol;

void printsol() {
	for (auto v : sol) {
		printf("%d ", v);
	}
	printf("\n");
}

int main() {
	int n;
	scanf("%d", &n);
	
	if (n == 3) {
		printf("2 5 63\n"); return 0;
	}

	int mod3 = 0;

	for (int i = 2; i <= 30000 && (int)sol.size() < n; i += 2) {
		sol.insert(i); mod3 = (mod3 + i)%3;
	}

	if (sol.size() == n) {
		if (mod3 == 2) {
			sol.erase(2); sol.erase(6); 
			sol.insert(3); sol.insert(9);
		} else if (mod3 == 1) {
			sol.erase(4); sol.erase(6); 
			sol.insert(3); sol.insert(9);
		} else {
			sol.erase(2); sol.erase(4);
			sol.insert(3);	sol.insert(9);
		}
		printsol();
	} else {
		int rem = n - (int)sol.size();
		if (rem%2 == 0) {
			if (mod3 == 1) { sol.erase(4); sol.erase(6); }
			else if (mod3 == 2) { sol.erase(2); sol.erase(6); }
		}
		if (rem%2 == 1) {
			if (mod3 == 1) { sol.erase(4); }
			else if (mod3 == 2) { sol.erase(2); }
			else { sol.erase(6); }
		}
		for (int i = 3; (int)sol.size() < n; i += 6) {
			sol.insert(i);
		}
		printsol();
	}
}

Measured memory_bytes: 1280
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    W, H, x, y = mi()

    s = W*H/2
    cut = 1 if W/2 == x/1 and H/2 == y/1 else 0

    print(s, cut)

    return

main()


Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  unmap  unordered_map<int,int>
#define	 unset	unordered_set<int>
#define  maxpq  priority_queue<int>
#define  minpq  priority_queue<int, vector<int>, greater<int>>
#define ll long long
#define fs first
#define ss second//typedef second ss;
#define fora(i,n) for(int i=0;i<n;i++)
#define endl "\n"
using namespace std;

int main(){
	fastio;
	int t;
	cin>>t;
	if(t>=400 && t<=599)
      cout<<8;
    else if(t>=600 && t<=799) 
      cout<<7;
  else if(t>=800 && t<=999)
    cout<<6;
  else if(t>=1000 && t<=1199)
    cout<<5;
  else if(t>=1200 && t<=1399)
    cout<<4;
  else if(t>=1400 && t<=1599)
    cout<<3;
  else if(t>=1600 && t<=1799)
    cout<<2;
  else if(t>=1800 && t<=1999)
    cout<<1;
  cout<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    int n, x, t; cin>> n >> x >> t;
    if(n % x == 0) cout<< n/x *t << endl;
    else cout<< (n/x +1)*t << endl;
}

Measured memory_bytes: 3620
l,r = map(int,input().split())
n = r - l + 1
if n >= 2019:
	print(0)
else:
	l_to_r = []
	for i in range(l,r+1):
		l_to_r.append(i % 2019)
	ans = []
	for i in range(n-1):
		for j in range(i+1,n):
			ans.append(l_to_r[i] * l_to_r[j] % 2019)
	print(min(ans))


Measured memory_bytes: 107276
#include <iostream>
#define ll long long
using namespace std;
int main() {
    ll a, b, c;
    int k;
    cin >> a >>b>>c>>k;
    if (k <= a) {
        cout << k;
    }else if (k <=(a+b)){
        cout << a;
    }else {
        cout << a - (k-a-b);
    }
}

Measured memory_bytes: 3608
// acdart
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cstdlib>
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define SZ(x) ((int)(x).size())
#define MAXN 10010
#define MAXM
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
/*********default*********/
 
int main()
{
	int n;
	long long a[110];
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
	}
	sort(a, a + n);
	int x;
	long long t = 0x3ffffffffffff;
	for (x = -100; x <= 100; x++){
		long long s = 0;
		for (int i = 0; i < n; i++){
			s += (a[i] - x) * (a[i] - x);
		}
		t = min(s, t);
	}
	printf("%lld\n", t);
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};
use std::collections::{HashSet, HashMap, BinaryHeap, VecDeque};

static MOD: i64 = 1e9 as i64 + 7;

fn main() {
    input! {
        s: usize,
    }
    let mut dp = vec![0; s + 1];
    let mut sum = vec![0; s + 1];
    for i in 3..=s{
        dp[i] = 1 + sum[i - 3];
        dp[i] %= MOD;
        sum[i] = sum[i - 1] + dp[i];
        sum[i] %= MOD;
    }
    let ans = dp[s];
    println!("{}", ans);
}


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

using namespace std;

using ll = long long;
const ll INF = 1e16;
const int MAXN = 5050;

using Arr = array<ll, 2>;

int N;
int A[MAXN];
vector<int> adj[MAXN];

vector<Arr> dfs(int v, int p) {
   vector<Arr> dp(1);
   dp[0][0] = A[v];
   if (A[v] > 0) dp[0][1] = A[v];
   else dp[0][1] = INF;
   for (int u : adj[v]) if (u != p) {
      auto nxt = dfs(u, v);
      vector<Arr> ndp(dp.size() + nxt.size(), Arr{INF, INF});
      for (int i = 0; i < int(dp.size()); ++i) {
         for (int j = 0; j < int(nxt.size()); ++j) {
            // cut this edge
            if (nxt[j][0] < 0 || nxt[j][1] < INF) {
               ndp[i + j + 1][0] = min(ndp[i + j + 1][0], dp[i][0]);
               ndp[i + j + 1][1] = min(ndp[i + j + 1][1], dp[i][1]);
            }
            if (dp[i][0] < INF && nxt[j][0] < INF) {
               ndp[i + j][0] = min(ndp[i + j][0], dp[i][0] + nxt[j][0]);
            }
            if (dp[i][1] < INF && nxt[j][1] < INF) {
               ndp[i + j][1] = min(ndp[i + j][1], dp[i][1] + nxt[j][1]);
            }
         }
      }
      dp = move(ndp);
   }
   return dp;
}

int main() {
   ios_base::sync_with_stdio(false);
   cin >> N;
   for (int i = 1; i <= N; ++i) cin >> A[i];
   for (int i = 0; i < N - 1; ++i) {
      int v, u;
      cin >> v >> u;
      adj[v].emplace_back(u);
      adj[u].emplace_back(v);
   }
   auto ans = dfs(1, -1);
   int z = 0;
   while (ans[z][0] >= 0 && ans[z][1] == INF) z++;
   cout << z << "\n";
   return 0;
}


Measured memory_bytes: 1544
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
int main()
{
    ll n,k;
    cin >>n>>k;
    ll ans=0;
    while(k<=n)
    {
        ll res=(k*(n-k+1+n)/2-k*(k-1)/2+1+mod)%mod;
        ans=(ans+res)%mod;
        k++;
    }
    ans++;
    cout <<ans%mod<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

int gcd(int m, int n) {
    return n == 0 ? m : gcd(n, m % n);
}
int lcm(int m, int n) {
    return (m / gcd(m, n)) * n;
}

signed main() {
    cin >> N;
    int mx = 0;
    ans = 1;
    REPS(i, N) {
        ll tmp = 0;
        int j = i;
        while (j % 2 == 0) {
            j /= 2;
            tmp++;
        }
        if (mx < tmp) {
            mx = tmp;
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include"bits/stdc++.h"
using namespace std;

int main() {

	int N;
	cin >> N;

	double x;
	string u;
	double sum;
	double ans = 0;

	for (int i = 0; i < N; i++) {
		cin >> x >> u;
		if (u == "BTC") {
			sum = x * 380000.0;
		}
		else {
			sum = x;
		}
		ans = ans + sum;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <limits>
#include <typeinfo>

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


using namespace std;

int main(int argc, char* argv[])
{
  long long X,A,B;

  cin >> X >> A >> B;

  if((B-A)<=0){
    cout << "delicious" <<endl;
  }else if((B-A)<=X){
    cout << "safe" <<endl;
  }else{
    cout << "dangerous" <<endl;
  }

  return 0;
}


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

bool isIn(int arr[], int n, int len){
    int flag = 0;
    for(int i = 0; i < len; i++){
        if(arr[i] == n){
            flag = 1;
            break;
        }
    }

    if(flag == 1){
        return true;
    }
    else{
        return false;
    }
}


int main(){

    int x, y, flag = 0, group1[7] = {1, 3, 5, 7, 8, 10, 12}, group2[4] = {4, 6, 9, 11}, group3[1] = {2};

    cin >> x >> y;

    if(isIn(group1, x, 7) && isIn(group1, y, 7)){
        flag = 1;
    }
    else if(isIn(group2, x, 4) && isIn(group2, y, 4)){
        flag = 1;
    }
    else if(isIn(group3, x, 1) && isIn(group3, y, 1)){
        flag = 1;
    }

    if(flag == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;

}






Measured memory_bytes: 3596
package main

import "fmt"

type node struct {
	v          byte
	prev, next *node
}

type deque struct {
	head, tail node
}

func newDeq() *deque {
	dq := new(deque)
	dq.head.prev = nil
	dq.head.next = &dq.tail
	dq.tail.prev = &dq.head
	dq.tail.next = nil
	return dq
}
func (dq *deque) isEmpty() bool {
	if dq.head.next == &dq.tail {
		return true
	}
	return false
}

func (dq *deque) pushBack(v byte) {
	nn := new(node)
	nn.v = v
	dq.tail.prev.next = nn
	nn.prev = dq.tail.prev
	nn.next = &dq.tail
	dq.tail.prev = nn
}
func (dq *deque) popBack(v *byte) bool {
	if dq.tail.prev == &dq.head {
		return false
	}
	*v = dq.tail.prev.v
	dq.tail.prev.prev.next = &dq.tail
	dq.tail.prev = dq.tail.prev.prev
	return true
}
func (dq *deque) pushFront(v byte) {
	nn := new(node)
	nn.v = v
	dq.head.next.prev = nn
	nn.next = dq.head.next
	nn.prev = &dq.head
	dq.head.next = nn
}
func (dq *deque) popFront(v *byte) bool {
	if dq.head.next == &dq.tail {
		return false
	}
	*v = dq.head.next.v
	dq.head.next.next.prev = &dq.head
	dq.head.next = dq.head.next.next
	return true
}

func rev(s string) string {
	r := make([]byte, len(s))
	i, j := len(s)-1, 0
	for i >= 0 {
		r[j] = s[i]
		j++
		i--
	}
	return string(r)
}

func main() {
	fq, bq := newDeq(), newDeq()
	var S string
	fmt.Scan(&S)
	var Q, rcnt int
	fmt.Scan(&Q)
	for i := 0; i < Q; i++ {
		var t int
		fmt.Scan(&t)
		if t == 1 {
			fq, bq = bq, fq
			rcnt++
		} else {
			var f int
			var c byte
			fmt.Scanf("%d %c", &f, &c)
			if f == 1 {
				fq.pushBack(c)
			} else {
				bq.pushBack(c)
			}
		}
	}
	if rcnt%2 == 1 {
		S = rev(S)
	}
	var c byte
	for fq.popBack(&c) {
		fmt.Printf("%c", c)
	}
	fmt.Printf("%s", S)
	for bq.popFront(&c) {
		fmt.Printf("%c", c)
	}
	fmt.Println()
}


Measured memory_bytes: 11648
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

LL d[1000000], t[1000000]; //F[1000000];
LL n, m;
int main() {
	
	std::cin >> n;
	for (LL i = 0; i < n; i++) {
		std::cin >> d[i];
	}
	std::cin >> m;
	for (LL j = 0; j < m; j++) {
		std::cin >> t[j];
	}
	std::sort(d, d + n);
	std::sort(t, t + m);
	LL i = 0;
	for (LL j = 0; j < n; j++) {
		if (t[i] == d[j])
			i++;
	}
	std::cout <<(i==m?"YES":"NO") <<std::endl;
	return 0;
}

Measured memory_bytes: 5888
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, m := scanInt(), scanInt()
	cnt := make([]int, m)
	for i := 0; i < n; i++ {
		k := scanInt()
		for i := 0; i < k; i++ {
			cnt[scanInt()-1]++
		}
	}

	ans := 0
	for i := 0; i < m; i++ {
		if cnt[i] == n {
			ans++
		}
	}
	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 1780