akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int MOD = 998244353;
const int MAXN = 200000;
using ll = long long;

vector<pair<int, int>> input;
vector<int> x, r; //r[i] is the last robot that you can influence with the ith robot
vector<int> memo;

struct segtree{
    int i, j, val;
    segtree *l, *r;
    segtree(vector<int> &ar, int _i, int _j) : i(_i), j(_j){
        if (i == j){
            val = ar[i];
            l = r = nullptr;
        }
        else{
            int k = (i+j)/2;
            l = new segtree(ar, i, k);
            r = new segtree(ar, k+1, j);
            val = max(l->val, r->val);
        }
    }
    void update(int _i, int _val){
        if (_i <= i and j <= _i){
            val = _val;
        }
        else if(_i < i or j < _i){
            //nothing
        }
        else{
            l->update(_i, _val);
            r->update(_i, _val);
            val = max(l->val, r->val);
        }
    }
    int query(int _i, int _j){
        if (_i <= i and j <= _j){
            return val;
        }
        else if (_j < i or j < _i){
            return 0;
        }
        else{
            return max(l->query(_i, _j), r->query(_i, _j));
        }
    }
};

int main(){
    int n; cin >> n;
    for (int i = 0; i < n; ++i){
        int xi, di; cin >> xi >> di;
        input.push_back({xi, di});
        x.push_back(xi);
    }
    sort(input.begin(), input.end());
    sort(x.begin(), x.end());

    r.resize(n);
    r[n - 1] = n - 1;
    segtree * seg = new segtree(r, 0, n - 1);
    for (int i = n-2; i >= 0; --i){
        int pos = lower_bound(x.begin(), x.end(), input[i].first + input[i].second) - x.begin() - 1; 
        seg->update(i, pos);
        
        r[i] = seg->query(i, pos);
        
        seg->update(i, r[i]);
    }
    memo.resize(n+100);
    memo[n] = 1;
    for (int i = n-1; i >= 0; --i){
        memo[i] = (memo[r[i] + 1] + memo[i + 1]) % MOD;
    }
    cout << memo[0] << endl;
}


Measured memory_bytes: 22896
#include<iostream>

using namespace std;


int main(){

	int a, b;


	cin >> a >> b;


	if (a<b){
		cout << "a < b" << endl;
	}
	else if (a>b){
		cout << "a > b" << endl;
	}
	else if (a==b){
		cout << "a == b" << endl;
	}



}


Measured memory_bytes: 3088
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
    bool a[55556];
    a[1] = false;
    for (int i = 2; i <= 55555; i++) {
        a[i] = true;
    }
    for (int i = 2; i <= 55555; i++) {
        if(a[i]) {
            for (int j = 2 * i; j <= 55555; j += i) {
                a[j] = false;
            }
        }
    }
    int n;
    cin >> n;
    int count = 11;
    while (n) {
        if ((a[count])&&(count%5==1)){
            cout << count << " " ;
            n--;
        }
        count++;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
ll M=1e9+7;
int n;double dp[301][301][301];
double solve(int c1,int c2,int c3)
{
      double k=c1+c2+c3;
      if(dp[c1][c2][c3]!=-1)return dp[c1][c2][c3];
   


   double a1=0,a2=0,a3=0;
     if(c1!=0)a1=(solve(c1-1,c2,c3)+1.0)*c1/k;
     if(c2!=0)a2=(solve(c1+1,c2-1,c3)+1.0)*c2/k;
     if(c3!=0)a3=(solve(c1,c2+1,c3-1)+1.0)*c3/k;

     return dp[c1][c2][c3]=a1+a2+a3+(n-k)/k;

}




int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
      //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
   
   cin>>n;int a[n];
   int a1=0,a2=0,a3=0;
   fr(i,0,n)
   {cin>>a[i];
     if(a[i]==1)a1++;else if(a[i]==2)a2++;else if(a[i]==3)a3++;}
  fr(i,0,301)fr(j,0,301)fr(k,0,301)dp[i][j][k]=-1;dp[0][0][0]=0;

  cout<<setprecision(12)<<solve(a1,a2,a3)<<endl;
    
    
}

Measured memory_bytes: 213504
using System;

class A{
  static void Main(){
    string N = Console.ReadLine();
    double[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
    Array.Sort(Ar);
    double Temp = Ar[0];
    for (int i = 0; i < int.Parse(N) - 1; i++){
      Temp = (Temp + Ar[i + 1]) / 2;
    }
    Console.WriteLine(Temp);
  }
}

Measured memory_bytes: 27456
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    char c;
    cin >> c;
    if(c=='A')cout<<"T"<<endl;
    if(c=='C')cout<<"G"<<endl;
    if(c=='G')cout<<"C"<<endl;
    if(c=='T')cout<<"A"<<endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define f(i,a,n) for(i=a;i<n;i++)
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define test() ll tc;cin>>tc;while(tc--)

using namespace std;

/*ll fact(ll n);

ll comb(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}

ll fact(ll n)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
        res = ((res%mod * i%mod)%mod)%mod;
    return res;
}


ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

*/



int main()
{
        fast();
        ll n,i;
        cin>>n;
        ll a[n];
        f(i,0,n)
        {
            cin>>a[i];
        }
        ll dp[n];
        dp[0]=0;
        dp[1]=abs(a[1]-a[0]);
        for(ll i=2;i<n;i++)
        {
            dp[i]=min((abs(a[i]-a[i-1])+dp[i-1]),(abs(a[i]-a[i-2])+dp[i-2]));
        }
        cout<<dp[n-1];



        return 0;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            char[][] island = new char[12][12];
            int[][] map = new int[12][12];
            for (int i = 0; i < 12; i++) {
                Arrays.fill(map[i], 999);
            }
            int c = 0;
            while (sc.hasNext()) {
                String s = sc.nextLine();
                if (s.equals("")) {
                    break;
                }
                island[c++] = s.toCharArray();
            }
            int count = 0;
            for (int i = 0; i < 12; i++) {
                for (int j = 0; j < 12; j++) {
                    if (island[i][j] != '0') {
                        if (i == 0 && j == 0) {
                            map[i][j] = count++;
                        } else {
                            if (i - 1 >= 0 && island[i][j] == island[i - 1][j]) {
                                if (map[i][j] >= 0) {
                                    map[i][j] = Math.min(map[i][j], map[i - 1][j]);
                                }
                            } else if (j - 1 >= 0 && island[i][j] == island[i][j - 1]) {
                                map[i][j] = Math.min(map[i][j], map[i][j - 1]);
                            } else if (j + 1 < 12 && island[i][j] == island[i][j + 1]) {
                                for (int k = j; k < 11; k++) {
                                    if (i - 1 >= 0 && island[i][k] == island[i][k + 1] && island[i][k + 1] == '1' && island[i - 1][k + 1] == '1') {
                                        map[i][j] = map[i - 1][k + 1];
                                        count--;
                                        break;
                                    }
                                }
                                map[i][j] = count++;
                            } else {
                                map[i][j] = count++;
                            }
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
}



Measured memory_bytes: 26000
def addValue(ok,ng,diff):
    if diff<=8:
        ok+=1
    else:
        ng+=1
    return ok,ng

while True:
    n=input()
    if n==0:break
    Lok=Lng=Dok=Dng=Mok=Mng=0
    for i in range(n):
        temp=raw_input().split()
        MM=int(temp[1])
        hh,mm=map(int,temp[0].split(":"))
        diff=MM-mm if MM-mm>=0 else MM-mm+60
        if 11<=hh<15:
            Lok,Lng=addValue(Lok,Lng,diff)
        elif 18<=hh<21:
            Dok,Dng=addValue(Dok,Dng,diff)
        elif 21<=hh<=23 or 0<=hh<2:
            Mok,Mng=addValue(Mok,Mng,diff)
    print "lunch",int(float(Lok)/(Lok+Lng)*100) if Lok+Lng!=0 else "no guest"
    print "dinner",int(float(Dok)/(Dok+Dng)*100) if Dok+Dng!=0 else "no guest"
    print "midnight",int(float(Mok)/(Mok+Mng)*100) if Mok+Mng!=0 else "no guest"

Measured memory_bytes: 4288
#include <stdio.h>

int main(void){
	int h,w;
	int i,j;
	int temp;
	scanf("%d%d",&h,&w);
	char s[h][51];
	for(i=0;i<h;i++)scanf("%s",s[i]);
	int func(int x,int y){
		int k;
		int sum = 0;
		int dx[9] = {-1,-1,-1,0,0,0,1,1,1};
		int dy[9] = {-1,0,1,-1,0,1,-1,0,1};
		for(k=0;k<9;k++){
			if(x+dx[k]<0 || x+dx[k]>h-1 || y+dy[k]<0 || y+dy[k]>w-1)continue;
			if(s[x+dx[k]][y+dy[k]]=='#'){
				sum++;
			}
		}
		return sum;
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(s[i][j]=='.'){
				temp = func(i,j);
				s[i][j]= temp+'0';
			}
		}
	}
	for(i=0;i<h;i++)printf("%s\n",s[i]);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<string.h>

using namespace std;

struct Node{
	int key;
	Node *prev, *next;
};

Node *nil;

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node* listSearch(int key){
	Node *cur = nil->next;
	while (cur != nil&&cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t){
	if (t == nil)return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

int main(){
	int n, key;
	char com[20];
	scanf("%d", &n);
	init();
	for (int i = 0; i < n; i++){
		scanf("%s %d", com, &key);
		if (com[0] == 'i'){
			insert(key);

		}
		else if (com[0] == 'd'){
			if (strlen(com)>6){
				if (com[6] == 'F')deleteFirst();
				else if (com[6] == 'L')deleteLast();
			}
			else{
				deleteKey(key);
			}
		}
	}
	Node *cur = nil->next;
	int isf = 0;
	while (1){
		if (cur == nil)break;
		if (isf++ > 0)printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

Measured memory_bytes: 34412
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    ll n, A;
    cin >> n >> A;

    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    
    vector<vector<vector<ll> > > dp(
        n + 1,
        vector<vector<ll> >(n + 1, vector<ll>(n * 50 + 1))
    );


    rep(j, n + 1) {
        dp[j][0][0] = 1;
    }
    repi(j, n + 1) {
        repi(k, n + 1) {
            repi (s, n * 50 + 1) {
                if (j == 4 && k == 2 && s == 8) {
 //                   put("A");
                }

                if (s - x[j - 1] >= 0) {
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s - x[j - 1]];
                }
                else {
                    dp[j][k][s] = dp[j-1][k][s];
                }
            }
        }
    }

    // int cnt = 0;
    // for (ll i = 0; i < n - 2; i++) {
    //     for (ll j = i + 1; j < n - 1; j++) {
    //         for (ll k = j + 1; k < n; k++) {
    //             if (x[i] + x[j] + x[k] == 15) {
    //                 cout << i << " " << j << " " << k << endl;
    //                 cnt++;
    //             }
    //         }
    //     }
    // }
 //   cout << "TOTAL " << cnt << endl;

    ll sum = 0;
    repi(k, n + 1) {
        sum += dp[n][k][k * A];
    }

    put(sum);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 55220
// AOJ 1371: Infallibly Crack Perplexing Cryptarithm
// 2018.1.8 bal4u@uu

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

#define INF 0x7fffffff

int sz;
char raw[35], str[35], *p; int len;
char tr[128];
char token[9] = "()01+-*="; int tlen = 8;
char assign[8];
char used[8];
int ans;

int expr();

int factor()
{
	int x, f;

	f = 0; if (*p == '-') { while (*p == '-') p++, f = !f;	}
	if (*p == '(') {
		p++; if ((x = expr()) == INF) return INF;
		if (*p++ != ')') return INF;
	} else {
		x = 0;
		if (*p == '0') { p++; if (*p == '0' || *p == '1') return INF; }
		else if (*p == '1') {
			while (*p == '0' || *p == '1') x = (x << 1) + (*p++ & 1);
		} else return INF;
	}
	if (f) x = -x;
	return x;
}

int term()
{
	int x, y;

	if ((x = factor()) == INF) return INF;
	while (1) {
		if (*p != '*') break;
		p++;
		if ((y = factor()) == INF) return INF;
		x *= y;
	}
	return x;
}

int expr()
{
	int x, y, op;

	if ((x = term()) == INF) return INF;
	while (1) {
		if      (*p == '+') op = 1;
		else if (*p == '-') op = 0;
		else break;
		p++;
		if ((y = term()) == INF) return INF;
		if (op) x += y; else x -= y;
	}
	return x;
}

void calc()
{
	int par, eq, a, b;
	char *eq_p;

	memcpy(str, raw, len+1);
	par = 0, eq = 0;
	for (p = str; *p; p++) {
		if (isalpha(*p)) *p = assign[tr[*p]];
		if (*p == '=') {
			eq = 1, eq_p = p;
			if (par) return;
		}
		else if (*p == '(') par++;
		else if (*p == ')') par--;
	}
	if (!eq || par) return;
	if (*str == '=' || *(str+len-1) == '=') return;

	*eq_p++ = 0;
	p = str, a = expr();
	if (a == INF || *p != 0) return;
	p = eq_p, b = expr();
	if (b == INF || *p != 0) return;
	if (a == b) ans++;
}

void rec(int k)
{
	int i;

	if (k == sz) { calc(); return; }
	for (i = 0; i < tlen; i++) {
		if (used[i]) continue;
		used[i] = 1;
		assign[k] = token[i];
		rec(k+1);
		used[i] = 0;
	}
}

int main()
{
	int eq;

	eq = 0;
	memset(tr, -1, sizeof(tr));
	fgets(raw, 35, stdin);
	for (p = raw; *p > ' '; p++) {
		if (*p == '=') eq = 1;
		else if (isalpha(*p)) { if (tr[*p] < 0) tr[*p] = sz++; }
	}
	*p = 0, len = p-raw;

	if (sz + eq > 8) { puts("0"); return 0; }
	if (eq) tlen = 7;
	rec(0);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1912
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int n; cin >> n;
	int sum = 0;
	rep(i, 0, n) {
		int a; cin >> a; sum += a;
	}
	cout << sum / n << endl;
	return 0;
}

Measured memory_bytes: 3004
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  string S;
  cin >> N >> K >> S;
  for ( int i = 0; i < N; i++){
    if (i+1 == K){
      if(S[i] == 'A') cout <<'a';
      if(S[i] == 'B') cout <<'b';
      if(S[i] == 'C') cout <<'c';
    }
    else{
      cout <<S[i];
    }
  }
}


Measured memory_bytes: 256
n, k = map(int, input().split())
d = []
a = []
for _ in range(k):
    d.append(int(input()))
    a.append(list(map(int, input().split())))
s = [0] * n
for ai in a:
    for i in range(len(ai)):
        s[ai[i] - 1] += 1
ans = 0
for si in s:
    if si == 0:
        ans += 1
print(ans)


Measured memory_bytes: 67772
#include<bits/stdc++.h>
using namespace std;
void solveA()
{
  long long a,b,tem;
  cin>>a>>b;
  tem=(a+b);
  if(tem%2==0)
  {
    cout<<tem/2<<endl;
  }
  else
  {
    cout<<"IMPOSSIBLE"<<endl;
  }
}
void solveB()
{
  int n,i,j,count;
  cin>>n;
  int ar[n];
  for(i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  j=1;
  count=0;
  for(i=0;i<n;i++)
  {
    if(ar[i]!=j)
    {
      count++;
    }
    if(count>2)
    {
      cout<<"NO"<<endl;
      return;
    }
    j++;
  }
  cout<<"YES"<<endl;
}
void solveC()
{
  int a,b,x,y;
  cin>>a>>b;
  x=max(a,b);
  y=min(a,b);
  if((x-y)>=2)
  {
    cout<<2*x-1<<endl;
  }
  else
  {
    cout<<x+y<<endl;
  }
}
void solveD()
{
  int n,i,j;
  cin>>n;
  int ar[n];
  for(i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  int count=n;
  for(i=n-1;i>=0;i--)
  {
    for(j=i-1;j>=0;j--)
    {
      if(ar[i]<ar[j])
      {
        count--;
        break;
      }
    }
  }
  cout<<count<<endl;
}
void solveE()
{
  int h,w,x,y,H,W;
  cin>>H>>W;
  cin>>h>>w;
  x=h*W;
  y=(H-h)*w;
  cout<<(H*W)-(x+y)<<endl;
}
void solveF()
{
  int n,m,c,i,j;
  cin>>n>>m>>c;
  int b[m];
  int ar[n][m];
  for(i=0;i<m;i++)
  {
    cin>>b[i];
  }
  for(i=0;i<n;i++)
  {
    for(j=0;j<m;j++)
    {
      cin>>ar[i][j];
    }
  }
  int count=0;
  int sum;
  for(i=0;i<n;i++)
  {
    sum=0;
    for(j=0;j<m;j++)
    {
      sum=sum+ar[i][j]*b[j];
    }
    if((sum+c)>0)
    {
      count++;
    }
  }
  cout<<count<<endl;
}
void solveG()
{
  int a,b,c,tem;
  cin>>a>>b>>c;
  tem=b/a;
  if(tem>c)cout<<c<<endl;
  else cout<<tem<<endl;
}
void solveH()
{
  int a,b,c,tem,i;
  cin>>a>>b>>c;
  tem=min(a,b);
  vector<int>vec;
  for(i=1;i<=tem;i++)
  {
    if(a%i==0&&b%i==0)
    {
      vec.push_back(i);
    }
  }
  cout<<vec[vec.size()-c]<<endl;
}
void solveI()
{
  double t,x;
  cin>>t>>x;
  cout<<fixed<<setprecision(10)<<t/x<<endl;
}
void solveJ()
{
  int n,i;
  cin>>n;
  int ar[n];
  for(i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  sort(ar,ar+n);
  int sum=0;
  for(i=0;i<n-1;i++)
  {
    sum=sum+ar[i];
  }
  if(ar[n-1]<sum)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
void solveK()
{
  int A,B,x,y;
  cin>>A>>B;
  x=max((A+B),(A-B));
  y=max(x,A*B);
  cout<<y<<endl;
}
void solveM()
{
  int i,j;
  char ar[3][3];
  for(i=0;i<3;i++)
  {
    for(j=0;j<3;j++)
    {
      cin>>ar[i][j];
    }
  }
  for(i=0;i<3;i++)
  {
    for(j=0;j<3;j++)
    {
      if(i==j)cout<<ar[i][j];
    }
  }
}
bool check(int n)
{
  int sum=0,t,tem=n;
  while(tem!=0)
  {
    t=tem%10;
    sum=sum*10+t;
    tem=tem/10;
  }
  if(sum==n)return 1;
  else return 0;
}
void solveN()
{
  int a,b,i;
  cin>>a>>b;
  int count=0;
  for(i=a;i<=b;i++)
  {
    if(check(i))count++;
  }
  cout<<count<<endl;
}
void solveO()
{
  int tem;
  cin>>tem;
  if(tem>=30)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
int main()
{
  // solveA();
  //solveB();
  // solveC();
  // solveD();
// solveE();
 //solveF();
// <solveG();
//solveH();
//solveI();
//solveJ();
//solveK();
//solveM();
//solveN();
solveO();
  return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(M);
  int sum=0;
  for(int i =0;i<M;i++){
    cin >> A[i];
    sum=sum+A[i];
  }
  
  int asobi = N-sum;
  if(asobi>=0)cout << asobi << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

string S[100];
int main()
{
	int A, B;
	cin >> A >> B;
	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 100; j++) {
			S[i].push_back('.');
		}
	}
	for (int i = 50; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			S[i].push_back('#');
		}
	}
	A--; B--;
	int i = 99, j = 2;
	while (A > 0) {
		S[i][j] = '.';
		j += 4;
		if (j >= 100) {
			i--;
			j = i % 2 * 2;
		}
		A--;
	}
	i = 0; j = 0;
	while (B > 0) {
		S[i][j] = '#';
		j += 4;
		if (j >= 100) {
			i++;
			j = i % 2 * 2;
		}
		B--;
	}
	cout << 100 << " " << 100 << endl;
	for (int i = 0; i < 100; i++) {
		cout << S[i] << endl;
	}
}

Measured memory_bytes: 256
/**
 * Boris Sokolov
 * Software Engineer at Ring Labs
 * Kiev, Ukraine | Los Angeles, CA
 */

#pragma comment(linker, "/STACK:500000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <exception>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll INF = static_cast<ll>(1e18);
const int MOD = static_cast<int>(1e9) + 7;

int a[(int)2e5 + 9];

int main() {
    //freopen("in.txt", "rt", stdin);
    //freopen("out.txt", "wt", stdout);
    int n;
    scanf("%d", &n);

    ll total_sum = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        total_sum += a[i];
    }
    ll res = INF;
    ll current_sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        current_sum += a[i];
        res = min(res, abs(current_sum - (total_sum - current_sum)));
    }

    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
using namespace std;

const long long mod = 998244353;
char S[303]; int L;

void add(long long& a, long long b)
{
	a += b;
	if (a >= mod)
		a -= mod;
}

pair<int, int> chk[303][303]; bool seen[303][303];

void go(int i, int z, int o, int f)
{
	if (seen[L - i + z + o + f][i]){
		auto& p = chk[L - i + z + o + f][i];
		if (p.first <= z && z + f <= p.second) return;
		p.first = min(p.first, z);
		p.second = max(p.second, z + f);
	}
	else{
		seen[L - i + z + o + f][i] = 1;
		chk[L - i + z + o + f][i] = { z, z + f };
	}
	if (i == L) return;

	if (S[i] == '0' && o) go(i + 1, z, o - 1, f + 1);
	else if (S[i] == '0' && (z || f)) go(i + 1, z, o, f);

	if (S[i] == '1' && z) go(i + 1, z - 1, o, f + 1);
	else if (S[i] == '1' && (o || f)) go(i + 1, z, o, f);

	if (i + 1 < L && S[i] == '0' && S[i + 1] == '0') go(i + 2, z + 1, o, f);
	if (i + 1 < L && S[i] == '1' && S[i + 1] == '1') go(i + 2, z, o + 1, f);
	if (i + 1 < L && S[i] != S[i + 1]) go(i + 2, z, o, f + 1);
}

long long D[303][303][303], R[303][303][303];
int zc[303], oc[303], pin[303];

int main()
{
	scanf ("%s", S);
	while (S[L]) L++;
	for (int i = L-1; i >= 0; i--){
		zc[i] = zc[i + 1];
		oc[i] = oc[i + 1];
		if (S[i] == '0') zc[i]++;
		if (S[i] == '1') oc[i]++;
	}

	go(0, 0, 0, 0);

	D[L][0][0] = 1;
	for (int i = L; i >= 0; i--){
		for (int j = 0; j <= i; j++) for (int k = 0; j + k <= i; k++){
			R[i][j][k] = D[i][j][k];
			if (j) add(R[i][j][k], R[i][j - 1][k]);
			if (k) add(R[i][j][k], R[i][j][k - 1]);
		}
		for (int j = 0; j <= i; j++) for (int k = 0; j + k <= i; k++){
			if (i == 0 || S[i - 1] != '0') add(D[i][j + 1][k], D[i][j][k]);
			else add(D[i - 1][j][k], D[i][j][k]);
			if (i == 0 || S[i - 1] != '1') add(D[i][j][k + 1], D[i][j][k]);
			else add(D[i - 1][j][k], D[i][j][k]);
		}
	}

	long long ans = 0;
	for (int l = 1; l <= L; l++) {
		memset(pin, -1, sizeof(pin));
		for (int i = 0; i <= L; i++) if (seen[l][i]){
			for (int j = chk[l][i].first; j <= chk[l][i].second; j++) pin[j + zc[i]] = i;
		}

		long long ret = 0;
		for (int j = 0; j <= L; j++) if (pin[j] != -1){
			int p = pin[j];
			int z = j - zc[p];
			int o = l - j - oc[p];
			if (o >= 0){
				add(ans, R[p][z][o]);
				add(ret, R[p][z][o]);
			}
		}
	}

	printf ("%lld\n", ans);

	return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

struct SegmentTree{
  int N;
  vector <ll> Table[22];
  void Make(){
    for (int i = 0; i < 22; i++){
      Table[i].resize((1<<i));
    }
    return;
  }

  ll Sum(int num){
    int now = 21; ll ans = Table[now][num];
    while (num > 0){
      if (num % 2 == 0){
        now--; num = num / 2 - 1;
      }else{
        num--;
      }
      ans += Table[now][num];
    }
    return ans;
  }

  void Add(int num, ll val){
    for (int i = 21; i >= 0; i--){
      Table[i][num] += val;
      num /= 2;
    }
  }
};

int N, Q, C[int(5e5 + 5)], Last[int(5e5 + 5)];
int ans[int(5e5 + 5)];
pair <Pii, int> P[int(5e5+5)];

int main(){
  cin >> N >> Q;
  for (int i = 1; i <= N; i++) cin >> C[i];
  for (int i = 0; i < Q; i++){
    int L, R; cin >> L >> R;
    P[i] = {{R, L}, i};
  }
  sort(P, P + Q);

  SegmentTree ST; 
  ST.N = N; ST.Make();
  int R = 1;
  for (int i = 0; i < Q; i++){
    for (int j = R; j <= P[i].fi.fi; j++){
      ST.Add(j, 1);
      if (Last[C[j]] != 0){
        ST.Add(Last[C[j]], -1);
      }
      Last[C[j]] = j;
    }
    R = P[i].fi.fi + 1;

    ll now = ST.Sum(P[i].fi.fi) - ST.Sum(P[i].fi.se - 1);
    ans[P[i].se] = now;
  }

  for (int i = 0; i < Q; i++){
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 48276
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var map = {};
  for(var i = 0; i < N; i++){
    if(map[list[i]] == null){
      map[list[i]] = 0;
    }
    map[list[i]]++;
  }
  list.sort(function(a,b){
    return b - a;
  });
  var count = 0;
  for(var i = 0; i < N; i++){
    var Ai = list[i];
    if(map[Ai] <= 0){
      continue;
    }
    var beki = 0;
    while(Ai >= Math.pow(2, beki)){
      beki++;
    }
    var check = Math.pow(2, beki) - Ai;
    if(check == Ai){
      if(map[Ai] >= 2){
        map[Ai] -= 2;
        count++;
      }
    }else{
      if(map[check] >= 1){
        map[check]--;
        map[Ai]--;
        count++;
      }
    }
  }
  myout(count);
}


Measured memory_bytes: 77704
N,M = map(int,input().split())
Data = []
for _ in range(N):
    a,b = map(int,input().split())
    Data.append([a,b])
Data.sort(key=lambda x:x[0])

sum1 = 0
left = M 
for i in range(N):
    a,b = Data[i]
    if left <= b:
        sum1 += a * left 
        break
    else:
        sum1 += a * b
        left -= b

print(sum1)

Measured memory_bytes: 21224
package main
 
import(
  "fmt"
  "bufio"
  "os"
  "strings"
  "strconv"
  "log"
  "sort"
)
 

func main(){
  a := Rr()
  sort.Strings(a)
  fmt.Printf("%s %s %s\n",a[0],a[1],a[2])
}


var sc = bufio.NewScanner(os.Stdin)

func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}



//入力関係ライブラリ(Atcoder:yamanobori_oldさんのもの)
func make_liner(maxByte int) *bufio.Scanner {
  liner := bufio.NewScanner(os.Stdin)
  liner.Buffer(make([]uint8, 0, 8192), maxByte)
  return liner
}
func word_spliter() *bufio.Scanner {
  words := make_liner(8192) 
  words.Split(bufio.ScanWords)
  return words
}

func eGetLine(r *bufio.Scanner) string {
  if r.Scan() {
    return r.Text()
  }
  err := r.Err()
  if err != nil {
    log.Fatal(err)
  }
  // EOF
  return ""
}

func eGetInt(r *bufio.Scanner) int {
  line := eGetLine(r)
  return eAtoi(line)
}

func eAtoi(s string) int {
  n, err := strconv.Atoi(s)
  if err != nil {
    log.Fatal(err)
  }
  return n
}


Measured memory_bytes: 1108
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def divisor(n: int):
    """1からsqrt(n)までの約数を全部返す
    
    Args:
        n (int): [description]
    
    Yields:
        int: [description]
    """
    for i in range(1, math.ceil(math.sqrt(n)) + 1):
        if n % i == 0:
            yield i


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    S = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # h_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    if S <= 10**9:
        y = 1
        x = S
        print(' '.join([str(i) for i in [0, 0, x, 0, 0, y]]))
        return

    x = 10**9
    y = math.ceil(S / 10**9)

    a = 1
    b = x * y - S

    logger.debug('{}'.format([x * y - a * b]))

    print(' '.join([str(i) for i in [0, 0, x, a, b, y]]))


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3"""
        output = """1 0 2 2 0 1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """100"""
        output = """0 0 10 0 0 10"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """311114770564041497"""
        output = """314159265 358979323 846264338 327950288 419716939 937510582"""
        self.assertIO(input, output)


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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int n;
string s;
map<string, int> cnt;
 
int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif
	
	cin >> n;
	int max_num = INT_MIN;
	forn(i , n) {
		cin >> s;
		++cnt[s];
		max_num = max(max_num, cnt[s]);
	}
	for (auto it : cnt) {
		if (it.se == max_num) cout << it.fi << '\n';
	}
		
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

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

int main()
{
ll n , k ;
cin >> n >> k ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
vector<ll> s;
s.push_back(0);
rep(i,n){
  s.push_back(a[i]+s[i]);
}
vector<ll> ss;
ss.push_back(0);
rep(i,n){
  if(a[i]>0)ss.push_back(a[i]+ss[i]);
  else ss.push_back(0+ss[i]);
}
rep(i,n-k+1){
  ans=max(ans,(s[k+i]-s[i]>0 ? s[k+i]-s[i]:0)+ss[i]+ss[n]-ss[k+i]);
}
cout << ans << endl;
return 0;
}

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

int main(){
    char a,b; cin >> a >> b;
    if(a>b) cout << '>';
    else if (a<b) cout << '<';
    else cout << "=";
}

Measured memory_bytes: 256
import java.util.*;

@SuppressWarnings("unchecked")
class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);
        int INF = Integer.MAX_VALUE/2;

        while(true){
            int w = sc.nextInt(), h = sc.nextInt();
            if(w==0 && h==0) break;

            ArrayList[] list = new ArrayList[5];
            for(int i=0; i<5; i++) list[i] = new ArrayList<int[]>();

            int sx = 0, sy = 0, gx = 0, gy = 0;
            for(int i=0; i<h; i++){
                char[] line = sc.next().toCharArray();
                for(int j=0; j<w; j++){
                    if(line[j]=='S'){ sx = j; sy = i;}
                    if(line[j]=='G'){ gx = j; gy = i;};
                    if(Character.isDigit(line[j])) list[line[j]-'1'].add(new int[]{j, i});
                }
            }


            int midx = 0, min = INF;
            for(int start=0; start<5; start++){
                int[][] dp = new int[5][];
                for(int i=1; i<=4; i++){
                    int idx = (start + i) % 5;
                    int before = (idx + 4) % 5;
                    dp[idx] = new int[list[idx].size()];
                    Arrays.fill(dp[idx], INF);
                    for(int j=0; j<list[idx].size(); j++){
                        int[] pos = (int[])list[idx].get(j);
                        if(i==1){
                            dp[idx][j] = Math.abs(sx - pos[0]) + Math.abs(sy - pos[1]);
                            continue;
                        }
                        for(int k=0; k<list[before].size(); k++){
                            int[] bpos = (int[])list[before].get(k);
                            int dist = dp[before][k] + Math.abs(pos[0] - bpos[0]) + Math.abs(pos[1] - bpos[1]);
                            if(i==4){
                                dist += Math.abs(gx - pos[0]) + Math.abs(gy - pos[1]);
                                if(dist<min){
                                    min = dist;
                                    midx = start + 1;
                                }
                            }
                            dp[idx][j] = Math.min(dp[idx][j], dist);
                        }
                    }
                }
            }
            if(min!=INF) System.out.println(midx+" "+min);
            else System.out.println("NA");
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 72688
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    ll n;
    cin >> n;
    ll x = 1;
    if(n == x){
        cout << x << endl;
        return 0;
    }
    while (1){
        if(x*x > n){
            cout << fixed << setprecision(0) << pow(x-1,2) << endl;
            return 0;
        }else{
            x++;
        }
    }
  
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int m,cnt;
int G[MAX];
void insertionsort(int *A,int n,int g){
  int i,j,v;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j=j-g;
      cnt++;
    }
      A[j+g]=v;
  }
}
void shellsort(int *A,int n){
  int i;
  G[0]=1;
  i=0;
  while(++i<=MAX){
    if(G[i-1]>n){
      m=i-1;
      break;
    }
    if(i<MAX-1){
      G[i]=G[i-1]*(3+1);
    }
  }
  for(i=m-1;i>=0;i--){
    insertionsort(A,n,G[i]);
  }
}
int main(){
  int i,n,*A;
  scanf("%d",&n);
  A=malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  shellsort(A,n);
  printf("%d\n",m);
  for(i=m-1;i>0;i--) printf("%d ",G[i]);
  printf("%d\n%d\n",G[i],cnt);
  for(i=0;i<n;i++)printf("%d\n",A[i]);
  free(A);
  return 0;
}


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

int n;
long long int a;
set<long long int> paper{};

int main(void){
    // Here your code !
    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
      scanf("%lld", &a);
      if (paper.find(a) == paper.end()) {
        paper.insert(a);
      }
      else {
        paper.erase(a);
      }
    }

    printf("%d\n", paper.size());
    return 0;
}


Measured memory_bytes: 4864
#include<stdio.h>
#define max	1000000000000000000
int main()
{
	long long x,y,z;
	scanf("%lld%lld",&x,&y);
	z=x+x;
	if(x==y||x%y==0||y==1)
	{
		printf("-1\n");
		return 0;
	 } 
	 if(x==1)
	{
		printf("%lld\n",y+1);
		return 0;
	}
//	if(x<y)
//	{
//		z=y-y%x+x;
//	}
	while(z<=max&&z>=1&&(((z%y))==0))
	{
		z+=x;
	}
	if(z<=max&&z>=1&&((z%y)!=0))
		printf("%lld\n",z);
	else 
		printf("-1\n");
//	printf("%lld\n",z);
	return 0;
}
//x*z这个数%y！=0 

Measured memory_bytes: 128
# D - Ki
from collections import deque

N, Q = map(int, input().split())
g = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

# 各頂点に得点を持たせておく
point = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    p -= 1
    point[p] += x

ans = [0] * N

d = deque()
d.append((0,0,0))

while len(d)>0:
    v = d.popleft()
    ans[v[0]] += v[2] + point[v[0]]
    for gi in g[v[0]]:
        if gi!=v[1]:
            d.append((gi, v[0], ans[v[0]]))

print(' '.join(map(str, ans)))

Measured memory_bytes: 73168
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#define ll long long
using namespace std;
 
const int N=300005;
const int inf=1000000000;
 
struct seg{
	int x,id;
	seg(){}
	seg(int x,int id):x(x),id(id){}
	friend bool operator<(seg a,seg b){
		if (a.x!=b.x) return a.x<b.x;
		return a.id<b.id;
	}
};
struct node{
	int l,r;
	node(){}
	node(int l,int r):l(l),r(r){}
}a[N];
int n,l,r,now,cnt,l1,l2,r1,r2,d1,d2,nx1,nx2,fir;
ll ans,sum;
bool vis[N];
multiset<seg> s1,s2;
multiset<seg>::iterator it;
 
ll solve(){
	int i;ll sum=0;
	s1.clear(); s2.clear();
	for (i=1;i<=n;i++){
		s1.insert(seg(a[i].r,i));
		s2.insert(seg(-a[i].l,i));
		vis[i]=0;
	}
	for (i=1;i<=n;i++){
		if ((i&1)!=(fir&1)){
			it=s1.begin();
			while (vis[(*it).id]){
				s1.erase(s1.find(*it));
				it=s1.begin();
			}
			vis[(*it).id]=1;
			l=a[(*it).id].l; r=a[(*it).id].r;
			if (now<l) sum+=1ll*abs(l-now),now=l;
			if (now>r) sum+=1ll*abs(now-r),now=r;
			s1.erase(s1.find(*it));
		}
		else{
			it=s2.begin();
			while (vis[(*it).id]){
				s2.erase(s2.find(*it));
				it=s2.begin();
			}
			vis[(*it).id]=1;
			l=a[(*it).id].l; r=a[(*it).id].r;
			if (now<l) sum+=1ll*abs(l-now),now=l;
			if (now>r) sum+=1ll*abs(now-r),now=r;
			s2.erase(s2.find(*it));
		}
	}
	sum+=1ll*abs(now);
	return sum;
}

int main(){
	int i,j;
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d%d",&l,&r);
		a[i]=node(l,r);
	}
	fir=0; now=0;
	ans=solve();
	fir=1; now=0;
	ans=max(ans,solve());
	printf("%lld\n",ans);
	return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

const int N = 1000 + 10;

vector<int> g[N];
vector<int> x;

int rec(int curr)
{
  if (g[curr].empty()) return 0;

  const int M = 5000 + 10;
  static bool dp[2][M];

  int sum = 0;
  vector<pair<int, int>> v;
  each (next, g[curr]) {
    int y = rec(next);
    sum += x[next] + y;
    v.push_back(make_pair(x[next], y));
  }

  fill(&dp[0][0], &dp[2 - 1][M - 1] + 1, false);
  int a = 0;
  int b = 1;
  dp[a][0] = true;
  each (i, v) {
    for (int j = 0; j < M; ++j) {
      dp[b][j] = false;
    }
    for (int j = 0; j < M; ++j) {
      if (j + i.first < M) dp[b][j + i.first] |= dp[a][j];
      if (j + i.second < M) dp[b][j + i.second] |= dp[a][j];
    }
    a = (a +  1) % 2;
    b = (b +  1) % 2;
  }

  int y = -1;
  for (int i = 0; i <= x[curr]; ++i) {
    if (dp[a][i]) {
      y = sum - i;
    }
  }
  if (y == -1) throw "";
  
  return y;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    x.resize(n);
    vector<int> p(n - 1);
    each (i, p) cin >> i;
    each (i, x) cin >> i;

    fill(g, g + N, vector<int>());
    each (i, p) --i;
    for (int i = 0; i < p.size(); ++i) {
      g[p[i]].push_back(i + 1);
    }

    try {
      rec(0);
      cout << "POSSIBLE" << endl;
    } catch (const char* e) {
      cout << "IMPOSSIBLE" << endl;
    }
  }

  return 0;
}


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



int main(){
	int a, b;
	cin >> a >> b;
	for(;;){
//		cout << a << " " << b << endl;
		if(a>b){
			int tmp = a;
			a = b;
			b = tmp;
		}
		if(a==0) break;
		b = b%a;
	}
	cout << b << endl;
	return 0;
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >>d;   
  if(a*b >= c*d){
    cout << a*b << endl;
  } else {
    cout << c*d << endl;
  }
  return 0;
}

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

long long N,Y;

int main(){
	while(cin >> N >> Y){
		bool judge = true;
		long long a = -1,b = -1, c = -1;
		for(int i=0;i<=N;i++){
			if(i*10000>Y) continue;
			for(int j=0;i+j<=N;j++){
				if(i*10000+j*5000>Y) continue;
				if(i*10000+j*5000+(N-i-j)*1000==Y){
					a = i;
					b = j;
					c = N-i-j;
					break;
				}
			}
		}
		cout << a << " " << b << " " << c << endl; 
	}
}

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


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    long long x,k,d; cin >> x >> k >> d;
    x = (long long)abs(x);
	long long tmp = min(k, x / d);
	k -= tmp, x -= tmp * d;
	if (k % 2)x -= d;
    cout << (long long)abs(x) << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define rep(i,j,k) for(int i=j; i<k; ++i)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io 
	string s,t; cin>>s>>t;
	cout<<(t+s);
	return 0;
}

Measured memory_bytes: 256
n = int(input())

talk = []
for i in range(n):
    a = int(input())
    talk += [[list(map(int,input().split())) for _ in range(a)]]
    
ans = 0
    
for i in range(2 ** n):
    result = [True] * n
    
    for j in range(n):
        if ((i >> j) & 1):
            result[n - 1 -j] = False
    check = 1       
    for k in range(n):
        for x, y in talk[k]:
            if result[k] == True:
                if result[x-1] == y:
                    continue
                else:
                    check = 0
                    break
        else:
            continue
        break
    
    if check == 1:
        ans = max(ans, sum(result))
            
print(ans)


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

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

  int a;
  int ans = 0;
  for (int i=1;i<=n;i++) {
    cin >> a;
    if ((i % 2 != 0) && (a % 2 != 0)) ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int N;
int A[16];

int main() {
    cin >> N;
    int x[16][16], y[16][16];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        for (int j = 0; j < A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }

    int ans = 0;
    for (int bit = 0; bit < (1<<N); bit++) {
        bool f = true;
        for (int i = 0; i < N; i++) {
            if (bit & (1<<i)) {
                for (int j = 0; j < A[i]; j++) {
                    if (((bit >> (x[i][j] - 1)) & 1) != y[i][j]) {
                        f = false;
                        break;
                    }
                }
            }

            if (!f) break;
        }

        if (f) {
            bitset<16> bt(bit);
            ans = max(ans, (int)bt.count());
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String t = sc.next();
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < s.length();i++){
			sb.append(s.charAt(i));
			sb.append(t.charAt(i));

		}
		System.out.println(new String(sb));





	}
}


class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}


Measured memory_bytes: 21460