akhauriyash/Code-Regression huggingface dataset:
N,M=map(int,input().split())
alist=list(map(int,input().split()))

alist.sort()
cblist = []
for i in range(M):
  B,C=map(int,input().split())
  cblist.append((C,B))
  
cblist.sort(reverse=True)
#print(alist)
#print(cblist)

index = 0
for (C,B) in cblist:
  for i in range(index,index+B):
    if i == len(alist):
      break
    
    if alist[i] < C:
      alist[i] = C
    else:
      break
      
  index += B
  if index >= len(alist):
    break
  
#print(alist)
print(sum(alist))

Measured memory_bytes: 71508
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_A
#include <iostream>
#include <string>
#include <cstdio>
#include <cctype>
#include <vector>

using namespace std;

void change(string &input){
    for(int i=0; i<input.size(); i++){
        if(std::islower(input[i])) input[i] = std::toupper(input[i]);
        else{
        if(std::isupper(input[i])) input[i] = std::tolower(input[i]);
        }
    }
}

int main(){
    vector<string> v;
    string buf;
    while (cin >> buf) {
        change(buf);
        v.push_back(buf);
    }

    for(int i=0; i<v.size()-1; i++){
        cout << v[i] << " ";
    }
    cout << v.back() << endl;

    return 0;
}

Measured memory_bytes: 1192
#include<cstdio>
#include<vector>
using namespace std;
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    while(n&&m){
        vector<bool> a(7368792, false);
        for(int i=n;i<=7368791;i++){
            if(!a[i]&&!m){
                printf("%d\n",i);
                break;
            }
            else if(!a[i]){
                for(int j=i*2;j<=7368791;j+=i){
                    a[j]=true;
                }
                m--;
            }
        }
        scanf("%d %d",&n,&m);
    }
}


Measured memory_bytes: 3608
mod = 10**9 + 7

N = int(input())

total10 = 1
total9 = 1
total8 = 1

for i in range(N):
    total10 = (10*total10)%mod
    total9 = (9*total9)%mod
    total8 = (8*total8)%mod

if N ==2:
    print(2)
else:
    print((total10-2*total9+total8)%mod)

Measured memory_bytes: 63212
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	nums := ScanNums(n)
	sortedNums := make([]int, n)
	copy(sortedNums, nums)
	sort.Ints(sortedNums)
	max := sortedNums[n-1]
	secondMax := sortedNums[n-2]
	for _, num := range nums {
		if num != max {
			fmt.Println(max)
		} else {
			fmt.Println(secondMax)
		}
	}
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 8448
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1000005
using namespace std;
int n,l;
struct point{
	double x,y;
	point(){}
	point(double x,double y):x(x),y(y){}
	friend point operator+(const point &a,const point &b)  {return point(a.x+b.x,a.y+b.y);}
	friend point operator-(const point &a,const point &b)  {return point(a.x-b.x,a.y-b.y);}
	friend double dot(const point &a,const point &b)  {return a.x*b.x+a.y*b.y;}
	friend double cross(const point &a,const point &b)  {return a.x*b.y-a.y*b.x;}
}p[N],Q[N<<1];
int main(){
	int x,y,L=N,R=N;
	scanf("%d%d%d%d",&n,&l,&y,&x);
	Q[++R]=point(x,1.0*x*y),printf("%lf\n",1.0*y);
	for(int i=1;i<n;++i){
		scanf("%d%d",&y,&x);
		p[i]=point(Q[L].x-x,Q[L].y-(1.0*x*y));
		while(L<R&&Q[R-1].x-p[i].x>=l)  R--;
		if(L!=R){
			double slope=(Q[R].y-Q[R-1].y)/(Q[R].x-Q[R-1].x);
			if(Q[R].x-p[i].x>l){
				Q[R].y=Q[R-1].y+(l-(Q[R-1].x-p[i].x))*slope;
				Q[R].x=p[i].x+l;
			}
		}
		while(L<R&&cross(Q[L]-p[i],Q[L+1]-p[i])>=0)  L++;
		Q[--L]=p[i];
		printf("%lf\n",(Q[R].y-p[i].y)/l);
	}
	return 0;
}

Measured memory_bytes: 28928
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
	int nums[16384], ans[8192];
	int i, j, n, size, half, p;
	
	while(scanf("%d", &n), n){
		size = 0;
		half = (n-1) / 2;
		for(i=1; i<n; ++i)
			nums[size++] = (i*i) % n;

		sort(nums, nums + size);
		size = unique(nums, nums + size) - nums;

		memset(ans, 0, (half+1)*4);
		for(i=0; i<size; ++i){
			for(j=0; j<i; ++j){
				++ans[(p=abs(nums[i]-nums[j]))>half?n-p:p];
			}
		}
		for(i=1; i<=half; ++i)
			printf("%d\n", ans[i]*2);
	}

	return 0;
}

Measured memory_bytes: 824
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
double pi=3.141592653589;

int main(){
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  int akaku=h*60+m;
  int bkaku=12*m;
  int dkaku=abs(akaku-bkaku);
  double ans;
  double drad=(double)dkaku*pi/360;
  ans=sqrt((double)a*(double)a+(double)b*(double)b-2*(double)a*(double)b*cos(drad));
  cout<<fixed<<setprecision(10);
  cout<<ans<<endl;
 
}
    

Measured memory_bytes: 4172
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define vi vector<int>
#define ppi pair<int,pi>
#define ld long double
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << end
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define f(i, begin, end) for (__typeof(end) i = (begin); i != (end) ; i += 1 - 2 * ((begin) > (end)))
#define nl cout<<"\n";
#define endl "\n"
#define par(a,n) f(i,0,n) cout<<a[i]<<" "; nl
//void prt(int x) {cerr << x;}
#define vv(n,m) vector <vector <int> > v(n, vector <int> (m));

#define er(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... brgs>
void err(istream_iterator<string> it, T a, brgs... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);	
}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef pair<int,int> pii;
typedef vector<pii> vpii;
const int mod = 1000000007;
 int N = 3e7;
int div1[10000001]; 
// int kadane(int*a, int n);
// bool isPrime(int n);
// int mpow(int a, int b);
void sol(int n) 
{ 
  
     
    
    f(i,0,n) div1[i]=0;
  
    // For every number from 1 to n 
    for (int i = 1; i <= n; i++) { 
  
        // Increase divisors count for 
        // every number divisible by i 
        for (int j = 1; j * i <= n; j++) 
            div1[i * j]++; 
    } 
  
    // Print the divisors 
    int s=0;
    for (int i = 1; i <= n; i++) 
        s+=i*div1[i];
    cout<<s<<endl;
} 
void solve(){
    int n;
    cin>>n;
    sol(n);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // int t;
    // cin>>t;
    // while(t--)
    solve();
        
}

int mpow(int a, int b){ /* pow(a, b) % m */
  int m=mod;
  int x=1;
  while (b>0){
    if (b&1){
      x=(x * a) % m;
    }
    a=(a*a) % m; /* compute the next power of 2 */
    b>>=1; /* this is equivalent to b = floor(b / 2) */
  }
  return x;
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
} 

int kadane(int*a, int n){
    int max_so_far = INT_MIN, max_ending_here = 0;
    f(i,0,n){
        max_ending_here+=a[i];
        max_so_far = max(max_so_far, max_ending_here);
        if(max_ending_here<0) max_ending_here=0;
    }
    return max_so_far;
}

Measured memory_bytes: 81696
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??°??????????????°?????????
		int n = sc.nextInt();
		//??°?????????	0?????¨?????????????????? ??\???????????°????????§??¨????????????
		for(int i = 1; i<= n; i++){
		//?????¶??? 3???????????°??????????????¨??? contains??????????????????????????????????????§?????????????????????String????????´???????????¨??????????????????toString????????´
			if(i % 3 ==0 || Integer.toString(i).contains("3")){
					//?????????????¬?
					System.out.print(" " + i);
			}
		}
		//??????
		System.out.println();
	}
}

Measured memory_bytes: 29520
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
//orz yht
using namespace std;
int a[200005],b[200005],n,k,l;
map<pair<int, int>,int> m;
int f1(int x){
	if(a[x]==x)
	return x;
	else
	return a[x]=f1(a[x]);
}
int f2(int x){
	if(b[x]==x)
	return x;
	else
	return b[x]=f2(b[x]);
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n>>k>>l;
	for(int i=1;i<=n;i++){
		a[i]=i;
		b[i]=i;
	}
	for(int i=1;i<=k;i++){
		int x,y;
		cin>>x>>y;
		a[f1(x)]=f1(y);
	}
	for(int i=1;i<=l;i++){
		int x,y;
		cin>>x>>y;
		b[f2(x)]=f2(y);
	}
	for(int i=1;i<=n;i++)
    m[mp(f1(i),f2(i))]++;
	for(int i=1;i<=n;i++)
	cout<<m[mp(a[i],b[i])]<<" ";
	//system("pause");
	return 0;
}

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

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

    for(int i = 1; i < s.length(); i++){
        if(s[i-1] == s[i]){
            cout << "Bad" << endl;
            break;
        }
        if(i+1 == s.length()){
            cout << "Good" << endl;
        }
    }
    return 0;
}

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

int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    int d = a / b;
    int r = a % b;
    double f = double(a) / double(b);
    cout << d;
    cout << " ";
    cout << r;
    cout << " ";
    cout << fixed << setprecision(5) << f;
    cout << endl;
    
}



Measured memory_bytes: 3288
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=2e5+10;
const ll MOD=1e9+7;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
int N,K;
ll A[MAXN];
void solve()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>K;
    int pos=0;
    for(int u=0;u<N;u++){
        cin>>A[u];
        if(A[u]>0)pos++;
    }
    sort(A,A+N);
    ll ans=1;
    if(K==N){
        for(int u=0;u<K;u++)ans=(MOD+ans*A[u]%MOD)%MOD;
    }
    else if(pos==0){
        if(K%2==1){
            for(int u=N-1;u>=N-K;u--)ans=(MOD+ans*A[u]%MOD)%MOD;
        }
        else {
            for(int u=0;u<K;u++)ans=(MOD+ans*A[u]%MOD)%MOD;
        }
    }
    else {
        priority_queue<ll,vector<ll>,greater<ll>>npq;
        vector<ll>cand;
        for(int u=0;u<N;u++){
            if(A[u]<=0)npq.push(A[u]);
        }
        for(int u=N-1;u>=N-K;u--){
            if(A[u]>0)cand.push_back(A[u]);
        }
        if((K-cand.size())%2==1)cand.pop_back();
        int ptr=cand.size()-1;
        while(npq.size()>1){
            ll n1=npq.top();npq.pop();
            ll n2=npq.top();npq.pop();
            if(cand.size()<K){
                cand.push_back(n1);
                cand.push_back(n2);
            }
            else if(ptr>0){
                if(cand[ptr]*cand[ptr-1]<n1*n2){
                    cand[ptr--]=n1;
                    cand[ptr--]=n2;
                }
            }
        }
        for(ll t:cand)ans=(ans*t%MOD+MOD)%MOD;
    }
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 9484
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N, X, Y;
	scanf("%d %d %d", &N, &X, &Y);
	int ans[N];
	fill_n(ans, N, 0);
	for (int i = 1; i <= N; ++i) {
		for (int j = i + 1; j <= N; ++j) ++ans[min(j - i, abs(Y - j) + abs(X - i) + 1)];
	}
	for (int i = 1; i < N; ++i) printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
S = input()

list_s = []
count = 0
if len(S) == N:
  for i in range(1,N):
    for a in S:
      if a == "A":
        list_s.append("A")
      elif a == "B":
        list_s.append("B")
      elif a == "C":
        list_s.append("C")
      else:
        break
      
      b = ''.join(list_s)
      if b == "ABC":
        count = count + 1
        break
    list_s = [] 
    S = S[1:]
      
      
      

print(count)
        


Measured memory_bytes: 3060
def gcd (a,b):
  if a%b==0:
    return b
  if b%a==0:
    return a
  if a>b:
    return gcd(b,a%b)
  return gcd(a,b%a)
def lcm (a,b):
  return ((a*b)//gcd(a,b))
inp=list(map(int,input().split()))
a=inp[0]
b=inp[1]
print (lcm(a,b))

Measured memory_bytes: 9136
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<long long> in(n), a(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> in[i];
  }
  sort(in.begin(), in.end());
  for (int i = 0; i < n; i++) {
    a[i + 1] = a[i] + in[i];
  }
  for (int i = n; i > 0; i--) {
    if (a[i] - a[i - 1] > 2 * a[i - 1]) {
      cout << n - i + 1 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, M = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    print(max(-1,N-sum(A)))




if __name__ == "__main__":
    main()


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin>>n;
vector<ll>A(n);
rep(i,n)cin>>A[i];
sort(A.begin(),A.end(),greater<ll>());
ll ans=A[0];
int idx=1;
int cnt=0;
reps(i,n,2){
    ans+=A[idx];
    cnt++;
    if(cnt==2){
        idx++;
        cnt=0;
    }
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 4768
import Data.List
f [] a b = (b-a)
f (x:xs) a b
  | x-a < b-y = (b-y) `min` f xs a y
  | otherwise = (x-a) `min` f xs x b 
  where y = 24-x
main = do
  getLine
  ds <- map read . words <$> getLine
  print $ f (sort ds) 0 24

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

int main(){
	int N, D;
	cin >> N >> D;
	int d = 2 * D + 1;
	int ans;
	if(N % d == 0) ans = N / d;
	else ans = N / d + 1;
	cout << ans << endl;
}

Measured memory_bytes: 256
"use strict";
function Main(input) {
   const args = input.split(' ').map(m => parseInt(m));
   const A = args.shift();
   const P = args.shift();
   let p = P + A * 3;
   console.log(Math.trunc(p / 2));

}

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

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

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

    int maxNumber = 1;
    int maxCount = 0;
    for (int i = 1; i <= N; i++) {
        int count = 0;
        int tmp = i;
        while (tmp % 2 == 0) {
            tmp /= 2;
            count++;
        }
        if (count > maxCount) {
            maxCount = count;
            maxNumber = i;
        }
    }

    cout << maxNumber << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAX=200050;
int chk[MAX],n,m;
vector<int> conn[MAX];
queue<int> ret;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        conn[t1].push_back(t2);
        conn[t2].push_back(t1);
    }
    ret.push(1);
    for(int i=0;i<3;i++){
        int r=ret.size();
        for(int j=0;j<r;j++){
            int t=ret.front();
            ret.pop();
            if(chk[t]==0){
                chk[t]=1;
                for(int k=0;k<conn[t].size();k++) if(chk[conn[t][k]]==0) ret.push(conn[t][k]);
            }
        }
    }
    if(chk[n]) printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
}


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

#define N 3
#define SPACE 9
#define QUEUE_MAX 400000
#define TRUE 1
#define FALSE 0

typedef struct P {
  int steps;
  int board[N*N];
  int space;
} puzzle;

int solve(puzzle);

puzzle queue[QUEUE_MAX];
int q_top = 0;
int q_tail = 0;

puzzle q_pop() {
  puzzle result = queue[q_top];
  q_top++;
  q_top %= QUEUE_MAX;

  return result;
}

void q_push(puzzle p) {
  queue[q_tail] = p;
  q_tail++;
  q_tail %= QUEUE_MAX;
}

int q_size(){
  if(q_tail >= q_top){
    return q_tail - q_top;
  }
  else {
    return q_tail + QUEUE_MAX - q_top;
  }
}

struct node {
  struct node* nodes[N*N + 1];
};

typedef struct node * NodePointer;

NodePointer makeNode() {
  NodePointer node;

  node = malloc(sizeof(struct node));

  for(int i = 0; i < N*N + 1; i++){
    node->nodes[i] = NULL;
  }

  return node;
}

NodePointer memTree;

int exists(puzzle *p){
  NodePointer current = memTree;
  
  for(int i = 0; i < N*N; i++){
    // printf("%d, ", p->board[i]);
    if(current->nodes[p->board[i]] == NULL){
      //printf("DEPTH = %d NOT FOUND\n", i);
      return FALSE;
    }

    current = current->nodes[p->board[i]];
  }
  
  //printf("FOUND!!\n");
  return TRUE;
}

void addToMem(puzzle *p){
  NodePointer current = memTree;
  
  for(int i = 0; i < N*N; i++){
    //printf("DEPTH = %d ADDING\n", i);
    if(current->nodes[p->board[i]] == NULL){
      current->nodes[p->board[i]] = makeNode();
    }

    current = current->nodes[p->board[i]];
  }
}
  

int main() {
  puzzle input;
  for(int i = 0; i < N*N ; i++){
    scanf("%d", &(input.board[i]));
    if(input.board[i] == 0) {
      input.board[i] = SPACE;
      input.space = i;
    }
      
    //    printf("%d ", input.board[i]);
  }

  memTree = makeNode();

  input.steps = 0;

  //debug
  //addToMem(&input);
  //exists(&input);
  
  printf("%d\n", solve(input));

  
  return 0;
}

int gameClear(puzzle* p){
  for(int i = 0; i < N*N ; i++){
    if(p->board[i] != i + 1){
      return FALSE;
    }
  }

  return TRUE;
}

//solve by BFS
int solve(puzzle s) {
  int result = 0;

  int dx[4] = {0,1,0,-1};
  int dy[4] = {-1,0,1,0};
  char dir[4][6] = {"up", "right", "down", "left"};
  //printf("steps %d\n", s.steps);

  q_push(s);
  addToMem(&s);

  while(q_size() > 0){
    puzzle u = q_pop();
    //printf("steps %d\n", u.steps);

    if(gameClear(&u)){
      result = u.steps;
      break;
    }
    int col = u.space / N;
    int row = u.space % N;
    //printf("space (%d, %d)\n", col, row);
    
    for(int i = 0; i < 4; i++){
      int tc = col + dy[i];
      int tr = row + dx[i];

      if(tc < 0 || tr < 0 || tc >= N || tr >= N){
	continue;
      }

      //printf("try to %s\n", dir[i]);
      puzzle v = u;
      int tmp = v.board[tc*N + tr];
      v.board[tc*N + tr] = v.board[u.space];
      v.board[u.space] = tmp;

      if(!exists(&v)){
	v.space = tc*N + tr;
	v.steps = u.steps + 1;
	q_push(v);
	addToMem(&v);
      }
    }
  }
  return result;
}
  



Measured memory_bytes: 66156
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    a, b, c = i_map()

    if a <= c and c <= b:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string ans;
    int c[3][3];
    REP(i,3){
        REP(j,3){
            cin>>c[i][j];
        }
    }
    vector<int>a;
    vector<int>b;
    a.pb(c[0][1]-c[0][0]);
    a.pb(c[0][2]-c[0][1]);
    b.pb(c[1][0]-c[0][0]);
    b.pb(c[2][0]-c[1][0]);
    REP(i,3){
        REP(j,2){
            if(c[i][j+1]-c[i][j]!=a[j]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    REP(i,3){
        REP(j,2){
            if(c[j+1][i]-c[j][i]!=b[j]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

int main(){
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(Q + 1);
  for(int i = 1; i <= Q; i++){
    cin >> A[i];
  }
  vector<int> OKnum(N + 1, 0), point(N + 1);
  for(int i = 1; i <= Q; i++){
    OKnum[A[i]]++;
  }
  for(int i = 1; i <= N; i++){
    point[i] = K - (Q - OKnum[i]);
  }
  for(int i = 1; i <= N; i++){
    if(point[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 5*(int)1e5 + 10;
// make sure N size is correctttt!!!!!!!!!


int n, m;
vector<int> g[N];

int par[N];
int indeg[N];
vector<int> topo; //Stores lexicographically smallest toposort

bool toposort() //Returns 1 if there exists a toposort, 0 if there is a cycle
{  
   priority_queue<int, vector<int>, greater<int> > pq;
   for(int i=1;i<=n;i++)
      for(auto &it:g[i])
         indeg[it]++;
   for(int i=1;i<=n;i++)
   {
      if(!indeg[i]){
         par[i] = 0;
         pq.push(i);
         break;
      }
   }
   while(!pq.empty())
   {
      int u=pq.top();
      pq.pop();
      topo.push_back(u);
      for(auto &v:g[u])
      {
         indeg[v]--;
         if(!indeg[v]){
            par[v] = u;
            pq.push(v);
         }
      }
   }

   if(sz(topo)<n)
      return 0;
   return 1;
}

vector<int> rev[N];

int32_t main(){_

   cin>>n>>m;

   for (int i = 0; i < n-1+m; ++i)
   {
      int a, b;
      cin>>a>>b;
      g[a].pb(b);
   }

   toposort();

   for (int i = 1; i <= n; ++i)
   {
      cout<<par[i]<<'\n';
   }

   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 36084
fun main (args : Array<String>) {
	val s = readLine()
	val S : String = s!!.toString()
	var list : MutableList<String> = mutableListOf()
	var count : Int = 0
	for (i in S) {
		list.add(i.toString())
	}
	for (i in 1..list.size - 1) {
		if (list[i - 1] == list[i]) {
			if (list[i - 1].toInt() == 0) {
				list[i] = "1"
				count++
			} else {
				list[i] = "0"
				count++
			}
		}
	}
	println("${count}")
}

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

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define mp make_pair
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const long long MXN = 3e5 + 100;
const long long MNN = 1e3 + 1;
const long long MOD = 998244353;
const long long INF = 1e18;
const long long OO = 1e15;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, b[MXN], ind[MXN], mx;

int main(){
	ios;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> b[i];
		ind[b[i]] = i;
	}
	llong cnt = 1;
	for(int i = 1; i <= n; i++){
		if(ind[i] < ind[i + 1]){
			cnt++;
		}else{
			cnt = 1;
		}
		mx = max(cnt, mx);
	}
	cout << n - mx;
	return 0;
}


Measured memory_bytes: 3840
import java.util.*;
import static java.lang.Math.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a[] = new int[3];
        for(int i=0; i<3; i++){
          a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[0] + a[1]);
        
    }
}


Measured memory_bytes: 21716
/*
                _____________   ______________       __
               / _________  /\ /_____   _____/\     / /\
              / /\       / /  \\    /  /\    \ \   / /  \
             / /  \_____/ /   / \__/  /  \____\/  / /   /
            / /   /    / /   /    /  /   /       / /   /
           / /   /    / /   /    /  /   /       / /   /
          / /   /    / /   /    /  /   /       / /   /
         / /___/____/ /   /    /  /   /       / /___/________
        /____________/   /    /__/   /       /______________/\
        \            \  /     \  \  /        \              \ \
         \____________\/       \__\/          \______________\/
           ___       ___               ___    ___________
          /  /\     /  /\             /  /\  /_______   /\
         /  /__\___/  /  \           /  /  \ \      /  /  \
        /____    ____/   /          /  /   /  \____/  /   /
        \   /   /\   \  /          /  /   /       /  /   /
         \_/   /  \___\/ ___      /  /   /       /  /   /
          /   /   /     /  /\    /  /   /       /  /   /
         /   /   /     /  /__\__/  /   /       /  /___/____
        /___/   /     /___________/   /       /___________/\
        \   \  /      \           \  /        \           \ \
         \___\/        \___________\/          \___________\/

          A FAN OF FIZZYDAVID

*/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
//orz jzm
#define ll long long
#define ull unsigned ll
#define orz int
#define yjz main
#define fizzydavid return
#define ak 0
#define la ;
#define plusonesecond {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define minusonesecond exit(0)
const double EPS = 1e-8;
const ll PR = 19260817;
const ll inv2 = 500000004;
const ll inv3 = 333333336;
map<int, int> mp;
orz yjz() {
	int n;
	cin>>n;
	while(n--) {
		int x;
		cin>>x;
		mp[x]++;
	}
	int last=0, now=0;
	for(map<int, int>::iterator it=mp.begin(); it!=mp.end(); it++) {
		if(it->second>1&&it->second<4) {
			last=now;
			now=it->first;
		} else if(it->second>3) {
			now=last=it->first;
		}
	}
	cout<<(ll)last*(ll)now<<endl;
	fizzydavid ak la
}

Measured memory_bytes: 4992
/*
   ,##.                   ,==.
 ,#    #.                 \ o ',
#        #     _     _     \    \
#        #    (_)   (_)    /    ; 
 `#    #'                 /   .'  
   `##'                   "=="
*/

#include <bits/stdc++.h>
#define ll long long
#define null NULL
#define int long long

using namespace std;

const int INF = 1e9;

int query(int a, int b) {
	int p = a * b - 1;
	int l = 0, r = INF;
	while (l != r) {
		int mid = (l + r) / 2;
		if ((mid + 1) * (mid + 1) <= p)
			l = mid + 1;
		else
			r = mid;
	}
	int q = l;
	if (a > b)
		swap(a, b);
	if (q * (q + 1) <= p) {
		if (a <= q) {
			return 2 * q - 1;
		}
		else {
			if (q * (q + 2) <= p)
				return 2 * q;
			else
				return 2 * q - 1;
		}
	}
	else {
		return 2 * q - 2;
	}
}

int n;

signed main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		cout << query(a, b) << '\n';
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	long long ans = 0;
	long long X, Y;
	cin >> X >> Y;

	while (X <= Y)
	{
		ans++;
		X *= 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int i,a[103],n,j=0,k=0;
	priority_queue <int> pq;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		pq.push(a[i]);
	}
	for(i=0;i<n;i++){
		if(i%2==0){
			j+=pq.top();
			pq.pop();
		}
		if(i%2==1){
			k+=pq.top();
			pq.pop();
		}
	}
	printf("%d",j-k);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  	int p;
    cin >> p;
    int t = int( float(p)/1.08f );
    for(int i=t-1;i<t+3;i++) {
       int p2 = int(float(i)*1.08f);
  //  printf("%d %d %d\n",t,p,p2);
  if (p==p2) {
    cout << i << endl;
    return 0;
  }
    }
    cout << ":(" << endl;
    return 0;
      
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

queue<P> q1, q2;
int cnt = 0, ans = 0, sum = 0;
void add(){
  P p = q1.front();
  sum += p.fi;q2.push(p);
  if(p.se == 0)cnt++;
  q1.pop();
}

void erase(){
  P p = q2.front();
  sum -= p.fi;
  if(p.se == 0)cnt--;
  q2.pop();
}

signed main(){
  int n, k;string str;
  cin >> n >> k >> str;
  
  int now = 0;
  while(true){
    int pos = n;
    repi(i,now,n)if(str[i] != str[i+1]){
      pos = i+1;break;
    }
    q1.push(P(pos-now, str[now] == '1'));now = pos;
    if(pos == n)break;
  }
  
  while(q1.size()){
    add();
    while(cnt > k)erase();
    chmax(ans, sum);
  }
  
  cout << ans << endl;
  return 0;
}

// 6 2 001100





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

int main(){
	int A,B,C;
	char D,E;
	cin >> A >> D >> B >> E >> C;
	if(A < 2019){
		cout << "Heisei" << endl;
	}
  else if (A==2019&&B < 5){
    cout << "Heisei" << endl;
  }
	else{

		cout << "TBD" << endl;
	}
}

Measured memory_bytes: 256
(lambda NK,S:
    (lambda N,K,O:
        (lambda P:
            (lambda Sdash:print(
                    sum(map(
                            lambda i: (lambda j:(0 <= j < N) and (Sdash[i] == Sdash[j]))(i + (-1 if Sdash[i] == "L" else 1))
                            ,
                            range(N)
                    ))
            ))(''.join(
                [
                    (
                        lambda val,key:[val,("R" if val[0] == "L" else "L")*len(val)][key%2 and key//2<P]
                    )(O[k],k)
                        for k in range(len(O))]
            ))
        )(
            min(len(O)//2,K)
        )
    )(
        NK[0],NK[1],__import__("re").findall(r"(R+|L+)",S)
    )
)(
    tuple(map(int,input().split())),input()
)

Measured memory_bytes: 6336
#include<iostream>
using namespace std;
#define MOD 1000000007

long long functional(long long N, long long rem);


int main(){
    long long N;
    cin >> N ;
    if(N == 1) cout << 1 << endl;
    else cout << functional(N,N) << endl;

}

//First rem must be N
long long functional(long long rem, long long N){
    long long next = rem * (N-1);
    // cout << "next is " << rem << "*" << N-1 << "=" << next << endl;
    long long reminder = next % MOD;
    // cout << "reminder is " << reminder << endl;
    if(N - 1 == 1) return reminder;
    else functional(reminder, N -1);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2*1e5+10,Mod=1e9+7;
typedef long long ll;
#define pb push_back
int n,q,val[N],ans[N];
vector<int> G[N];
void dfs(int u,int p,int temp)
{
  ans[u]=temp+val[u];
  for(auto v:G[u])
  {
    if(v!=p) dfs(v,u,temp+val[u]);
  }
}
int main()
{
  cin>>n>>q;
  for(int i=1;i<n;i++)
  {
    int a,b;
    cin>>a>>b;
    G[a].pb(b);
    G[b].pb(a);
  }
  for(int i=1;i<=q;i++)
  {
    int x,y;
    cin>>x>>y;
    val[x]+=y;
  }
  dfs(1,0,0);
  for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 27264
#include <iostream>
#include <stdio.h>
#define min(a,b) ((a) < (b) ? (a) : (b))
using namespace std;

int main(){
	int height, width, map[50][50];
	cin >> height >> width;
	for (int i = 0; i < height; i++){
		for (int j = 0; j < width; j++){
			scanf("%1d",&map[i][j]);
		}
	}
	for (int i = 1; i < width; i++){
		map[0][i] += map[0][i - 1];
	}
	for (int i = 1; i < height; i++){
		map[i][0] += map[i-1][0];
	}
	for (int i = 1; i < height; i++){
		for (int j = 1; j < width; j++){
			map[i][j] += min(map[i - 1][j], map[i][j - 1]);
		}
	}
	cout << map[height - 1][width - 1] << endl;
	return 0;
}

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int main() {
	ios::sync_with_stdio(0);

	int n, x, t;
	cin >> n >> x >> t;
	cout << (n + x - 1) / x * t << endl;

	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	vector<int> h(n);
	rep(i,n)cin>>h[i];
	int min=0;
	rep(i,n){
		if(min<h[i]){
			min=h[i]-1;
		}else if(min==h[i]){
			//nothing
		}else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;

	return 0;
}

Measured memory_bytes: 640
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
using namespace std;
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	int a,b;
	cin>>a>>b;
	if(a%3==0 || b%3==0 || (a+b)%3==0)
	cout<<"Possible";
	else
	cout<<"Impossible";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

vector< vector<int> > points;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, d;
	cin >> n >> d;
	for(int i=0; i<n; i++) {
		vector<int> point;
		for(int j=0; j<d; j++) {
			int x;
			cin >> x;
			point.push_back(x);
		}
		points.push_back(point);
	}
	int ans = 0;
	for(int i=0; i<n; i++) {
		for(int j=i+1; j<n; j++) {
			int calc = 0;
			for(int t=0; t<d; t++) {
				calc += (points[i][t]-points[j][t])*(points[i][t]-points[j][t]);
			}
			int sq = sqrt(calc);
			if(sq*sq == calc) ans++;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    #if 1
    int ans = 0;
    while(ans<=(b*100)){
        ans++;
        if((int)((double)ans*0.08)==a){
            if((int)((double)ans*0.1)==b){
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;

    #else


    double basePriseA,basePriseB;
    basePriseA = (double)a/0.08;
    basePriseB = (double)b/0.1;
    // cout << basePriseA << endl;
    // cout << basePriseB << endl;
    int preAns = 0;
    if(basePriseA>basePriseB){
        preAns = basePriseA;
    }else{
        preAns = basePriseB;
    }
    int ans = -1;
    if((int)(preAns*0.08)==a){
        if((int)(preAns*0.1)==b){
            ans=preAns;
        }
    }
    int newAns = ans;
    if(ans!=-1){
        while(newAns>0){
            newAns--;
            if(((int)(newAns*0.08)==a)&&((int)(newAns*0.1)==b)){
                ans=newAns;
            }
        }
    }
    cout << ans << endl;
    #endif
    return 0;
}

Measured memory_bytes: 256