akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template <class T> void chmax(T &t, const T &f) { if (t < f) t = f; }

constexpr int MAX_N = 2005;

int N;
char A[MAX_N][MAX_N];

// bool B[MAX_N][MAX_N];
bitset<MAX_N> B[MAX_N];

// bool dp[MAX_N][MAX_N];
bitset<MAX_N> dp[MAX_N], DP[MAX_N];

int main() {
  for (; ~scanf("%d", &N); ) {
    for (int i = 2; i <= N; ++i) {
      scanf("%s", A[i] + 1);
    }
    for (int i = 0; i <= N + 1; ++i) {
      B[i].reset();
    }
    B[0][N + 1] = true;
    B[N + 1][0] = false;
    for (int i = 1; i <= N; ++i) {
      B[0][i] = false;
      B[i][0] = true;
      B[N + 1][i] = false;
      B[i][N + 1] = true;
    }
    for (int i = 1; i <= N; ++i) for (int j = 1; j < i; ++j) {
      B[i][j] = (A[i][j] == '1');
      B[j][i] = (A[i][j] == '0');
    }
    // memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= N + 1; ++i) {
      dp[i].reset();
      DP[i].reset();
    }
    for (int i = 0; i <= N; ++i) {
      dp[i][i + 1] = true;
      DP[i + 1][i] = true;
    }
    for (int w = 2; w <= N + 1; ++w) {
      for (int i = 0; i <= N + 1 - w; ++i) {
        const int j = i + w;
        // for (int k = i + 1; k < j; ++k) {
          // if ((B[i][k] || B[j][k]) && dp[i][k] && dp[k][j]) {
            // dp[i][j] = true;
            // break;
          // }
        // }
        dp[i][j] = DP[j][i] = ((B[i] | B[j]) & dp[i] & DP[j]).any();
      }
    }
// for(int i=0;i<=N+1;++i){for(int j=0;j<=N+1;++j){cout<<dp[i][j];}cout<<endl;}
    int ans = 0;
    for (int i = 1; i <= N; ++i) {
      if (dp[0][i] && dp[i][N + 1]) {
        ++ans;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}


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

int main()
{
	int h, w;
	while (true) {
		cin >> h >> w;
		if (h == 0 && w == 0) { break; }
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long ll;
const int MAXN = 100;

int bubblesort(int *A, int N) {
	int flag = 1;
	int count = 0;
	while (flag) {
		flag = 0;
		for (int i = N - 1; i > 0; i--) {
			if (A[i - 1] > A[i]) {
				swap(A[i - 1], A[i]);
				flag = 1;
				count++;
			}
		}
	}
	return count;
}

int main() {
	int  N, count;
	int A[MAXN];
	cin >> N;
	rep(i, N)cin >> A[i];
	count = bubblesort(A, N);
	rep(i, N) {
		if (i != N - 1)cout << A[i] << " ";
		else cout << A[i] << endl;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3080
n,k = map(int,input().split())
#combinationの値を計算
m = max(k-1,n-k+1)
c = []

for l in range(m+1):
  temp = [] #その段を作る
  for j in range(l+1):
    if j==0 or j==l:
      temp.append(1)
    else:
      comb = c[l-1][j-1]+c[l-1][j]
      temp.append(comb)
  c.append(temp)
  
for i in range(1,k+1):
  if i-1>n-k:
    ans = 0
  else:
    ans = c[k-1][i-1] * c[n-k+1][i]
  print(ans%(10**9+7))

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

#define pb push_back

using namespace std;

int main(){
	int n, k, c;
	vector<int> early, late;
	string s;
	cin>>n>>k>>c;
	//getline(cin, s);
	cin>>s;
	//early-greedy
	int idx = 0;
	while(early.size() < k){
		if(s[idx] == 'o'){
			early.pb(idx);
			idx+=c+1;
		}
		else{
			idx++;
		}
	}

	//late-greedy
	idx = n-1;
	while(late.size() < k){
		if(s[idx] == 'o'){
			late.pb(idx);
			idx-=c+1;
		}
		else{
			idx--;
		}
	}
	reverse(late.begin(), late.end());

	for(int i=0;i<k;i++){
		//cout<<early[i]<<" "<<late[i]<<"\n";
		if(early[i] == late[i])
			cout<<early[i]+1<<"\n";
	}
	return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  if(a>b) cout << "a > b" << "\n";
  if(a<b) cout << "a < b" << "\n";
  if(a==b) cout << "a == b" << "\n";
  return 0;
}

Measured memory_bytes: 1124
X=int(input())

import math
def prime_num(k):
    for divisor in range(2, math.floor(math.sqrt(k))+1):
            if k % divisor == 0:
                return False
    else:
        return True
      
for i in range(X,100010):
    if prime_num(i)==True:
        print(i)
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct Meet{
	int beg;
	int end;
	int num;
}meet[100000];
class setMeet{
	public:
		void init();
		void solve();
		private:
			int n,ans;
};
void setMeet::init(){
	int s,e;
	cin>>n;
	int i;
	for(i=0;i<n;++i)
	{
		cin>>s>>e;
		int min,max;
		max=s+e;
		min=s-e;
		meet[i].beg=min;
		meet[i].end=max;
		meet[i].num=i+1;
	}
}
bool cmp(Meet x,Meet y)
{
	if(x.end==y.end)
	return x.beg>y.beg;
	return x.end<y.end;
}
void setMeet::solve(){
	sort(meet,meet+n,cmp);
	int i;
	ans=1;
	int last=meet[0].end;
	for(i=1;i<n;++i)
	{
		if(meet[i].beg>=last)
		{
			ans++;
			last=meet[i].end;
		 } 
	}
	cout<<ans<<endl;
}
int main(){
	setMeet sm;
	sm.init();
	sm.solve();
	return 0;
}

Measured memory_bytes: 1408
// D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    int kazu[1005];
    int ans = 0;
    cin >> n;
    int ruiseki[1005];
    vector<int>a;
    for (int i = 0; i < n; i++) {
        int l;
        cin >> l;
        a.push_back(l);
        
    }
    sort(a.begin(), a.end());

    for (int i = 0; i < a.size() - 2; i++) {
        for (int j = i+1; j < a.size() - 1; j++) {
            for (int k = j+1; k < a.size(); k++) {
                if (a[i] + a[j] > a[k]) {
                    ans++;
                }
                else {
                    break;
                }
            }
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{ 
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var num = Input.num;
        var ar = Enumerable.Repeat(0, num).Select(_ => Input.num).ToArray();
        WriteLine(ar.All(v => v % 2 == 0) ? "second" : "first");

    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(_ => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 17444
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n = int(input().strip())
    a = list(map(lambda x : int(x) - 1, input().strip().split()))
    
    l=[0 for i in range(n)]
    for i in range(n-1):
        l[a[i]]+=1
        
    for i in range(n):
        print(l[i])
if __name__ == '__main__':
    main()

Measured memory_bytes: 109600
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
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 (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

int main() {

	int n;
	cin >> n;

	vector<ll> c(n), s(n), f(n);

	rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];

	vector<ll> ans(n);
	ll tmp;

	rep(i, n - 1) {
		tmp = 0;
		repl(j, i, n - 1) {
			if(tmp <= s[j]){
				tmp = c[j] + s[j];
			}
			else {
				ll cnt = (tmp - s[j] - 1) / f[j] + 1;
				tmp = c[j] + s[j] + f[j] * cnt;
			}
		}
		ans[i] = tmp;
	}

	rep(i, n - 1) {
		cout << ans[i] << endl;
	}
	cout << 0;


	return 0;
}


ll gcd(ll a, ll b) {
	if (a % b == 0)return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

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

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    string s;
    cin >> s;

    int ans = 0;
    int tmp = 0;
    for (char ch : s) {
        if (ch == 'A' or ch == 'C' or ch == 'G' or ch == 'T') {
            tmp ++;
        } else {
            ans = max(ans, tmp);
            tmp = 0;
        }
    }

    cout << max(ans, tmp) << endl;

    return 0;
}


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

int main()
{
	int n;
	cin>>n;
	
	int a[n],b[n];
	
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[n-i-1];
	}
	
	int val=-1;
	
	for(int i=0;i<n;i++)
	{
		if(a[i]==b[i])
		{
			val=a[i];
			break;
		}
	}
	
	if(val==-1)
	{
		cout<<"Yes"<<endl;
		
		for(int i=0;i<n;i++)
		{
			cout<<b[i]<<' ';
		}
		cout<<endl;
	}
	else
	{
		vector<int> t_change,available;
		
		for(int i=0;i<n;i++)
		{
			if(a[i]!=val && b[i]!=val)
			{
				available.push_back(i);
			}
			if(a[i]==val && b[i]==val)
			{
				t_change.push_back(i);
			}
		}
		
		if(t_change.size()>available.size())
		{
			cout<<"No"<<endl;
		}
		else
		{
			
			for(auto i:t_change)
			{
				int ind=*(available.end()-1);
				
				swap(b[i],b[ind]);
				available.pop_back();
			}
			
			cout<<"Yes"<<endl;
		
			for(int i=0;i<n;i++)
			{
				cout<<b[i]<<' ';
			}
			cout<<endl;
		}
	}
	return 0;
}

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

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }
template <class S>
string to_string(unordered_set<S> s);
template <class S>
string to_string(set<S> s);
template <class S, class T>
string to_string(map<S, T> m);
template <class T>
string to_string(vector<T> v);

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S>
string to_string(set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

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

int main() {
  cin.tie(0);
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> mp(H);
  FOR(i, H) cin >> mp[i];
  vector<vector<int>> color(H, vector<int>(W, -1));
  int ct = 0;
  FOR(i, H) {
    int last = -1;
    FOR(j, W) {
      if (mp[i][j] == '#') {
        ct++;
        for (int j2 = j; j2 > last; --j2) color[i][j2] = ct;
        last = j;
      }
    }
    if (last != -1) {
      for (int j2 = W - 1; j2 > last; --j2) color[i][j2] = ct;
    }
  }
  FOR(j, W) {
    int last = -1, lastc;
    FOR(i, H) {
      if (color[i][j] != -1) {
        ct++;
        for (int i2 = i; i2 > last; --i2) color[i2][j] = color[i][j];
        last = i;
        lastc = color[i][j];
      }
    }
    if (last != -1) {
      for (int i2 = H - 1; i2 > last; --i2) color[i2][j] = lastc;
    }
  }
  FOR(i, H) {
    FOR(j, W) cout << color[i][j] << " ";
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 1280
#include<cstdio>
#include<cmath>
using namespace std;
int n,x=2;
int main(){
	scanf("%d",&n);
	for(int i=1;i<8;++i){
		if(x>n){
			printf("%d\n",x/2);
			break;
		}
		x*=2;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define shandom_ruffle random_shuffle
#define pb push_back
#define nl puts("")
using ll = long long;
using pii = pair<ll,ll>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vlll = vector<vll>;
using mpll = map<ll,ll>;
using stch = stack<char>;
using stvll = stack<vll>;
const ll nax = 1000*1007;
const ll mno = 1007;
const ll mod = 1e9 + 7;
const ll mxN = 1e5;
const ll rc = 64;
const ll MOD = 998244353; 
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i = 1; i <= n; ++i) {
      for(ll j = 1; j <= n; ++j) {
          ll x = __gcd(i, j);
          for(ll k = 1; k <= n; ++k) {
              ans += __gcd(k, x);
          }
      }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,m;
  int64_t sum=0;
  bool t=true;
  cin >> n >> m;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum+=a[i];
  }
  sort(a,a+n,greater<int>());
  for(int i=0;i<m;i++){
    if(a[i]<(double)sum/(4*m)){
    t=false;
    cout << "No" << endl;
      break;
    }
  }
  if(t)cout << "Yes" << endl; 
}


Measured memory_bytes: 3588
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define STR_MAX 4000
#define BUF_SIZE (STR_MAX+10)

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

enum {
    ENUM_RED,
    ENUM_GREEN,
    ENUM_BLUE,
    ENUM_ALL
};

char table[256] = {
    ['R'] = ENUM_RED,
    ['G'] = ENUM_GREEN,
    ['B'] = ENUM_BLUE,
};

#define TYPE_ALL ((1<<ENUM_ALL)-1)

int main(void) {
    int len = get_int(); // length
    char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    int i, j, k;
    char type[BUF_SIZE] = {0};
    for(i = 0; i < len; i++) {
        type[i] = table[str[i]];
    }
    uint64_t cum[3][STR_MAX+1] = {0};
    for(i = 0; i < ENUM_ALL; i++) {
        for(j = 1; j <= len; j++) {
            cum[i][j] = (type[j-1] == i);
        }
    }
    // cumulative
    for(i = 0; i < ENUM_ALL; i++) {
        for(j = 1; j <= len; j++) {
            cum[i][j] += cum[i][j-1];
        }
    }

    uint64_t cnt = 0;
    int middle;
    for(j = 1; j < len-1; j++) {
        int middle = type[j];
        int c1 = (middle+1)%ENUM_ALL;
        int c2 = (middle+2)%ENUM_ALL;
        // [0, j) * (sum - [0, j+1))
        cnt += (cum[c1][j] * (cum[c2][len] - cum[c2][j+1]));
        cnt += (cum[c2][j] * (cum[c1][len] - cum[c1][j+1]));
#ifdef DEBUG
        printf("cnt: %llu\n", cnt);
#endif
    }

    uint64_t exclude = 0;
    int dist;
    for(dist = 1; dist < len; dist++) {
        for(i = 0; i < len; i++) {
            if(i + dist*2 >= len) continue;
            int tp = (1<<type[i]) | (1<<type[i+dist]) | (1<<type[i+dist*2]);
            if(tp == TYPE_ALL) exclude++;
        }
    }
#ifdef DEBUG
    printf("%llu - %llu\n", cnt, exclude);
#endif
    printf("%llu\n", cnt - exclude);

    return 0;
}

Measured memory_bytes: 1848
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int extgcd(int a, int b, int &x, int &y){
    int d = a;
    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
    return d;
}

int gcd_multi(vec a){
    if(a.size() == 1) return a[0];
    int x, y, g;
    g = a[0];
    FOR(i, 1, a.size()) g = extgcd(g, a[i], x, y);
    return g;
}

signed main(){

    int N, K; cin >> N >> K;
    vec A(N); readvec(A);

    int g = gcd_multi(A);
    SORT(A);

    if(K % g == 0 && K <= A[N - 1]){
        cout << "POSSIBLE";
    }else{
        cout << "IMPOSSIBLE";
    }
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    double h, a;

    cin >> h >> a;

    cout << std::ceil(h/a) << endl;

    return 0;
}

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

int main(){
    int A, B, C, N, M ,K;

    cin >> N >>K;
    
    if(K == 1) cout << "YES" << endl;
    else if((N-1)/(K-1) >=2) cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,i,k;//kは答え
  k=0;
  cin>>n;
  vector<int> vec(n);
  for(i=0; i<n; i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(), vec.end());
  if(vec.at(0)>-1){
    for(i=1; i<n; i++){
      k=vec.at(i)+k;
    }
    k=k-vec.at(0);
    cout<<k<<endl;
    for(i=1; i<n-1; i++){
      cout<<vec.at(0)<<" "<<vec.at(i)<<endl;
      vec.at(0)=vec.at(0)-vec.at(i);
    }
    cout<<vec.at(n-1)<<" "<<vec.at(0)<<endl;
  }
  else if(vec.at(n-1)<0){
    for(i=0; i<n-1; i++){
      k=k-vec.at(i);
    }
    k=k+vec.at(n-1);
    cout<<k<<endl;
    for(i=0; i<n-1; i++){
      cout<<vec.at(n-1)<<" "<<vec.at(i)<<endl;
      vec.at(n-1)=vec.at(n-1)-vec.at(i);
    }
  }
  else{
    for(i=1; i<n-1; i++){
      if(vec.at(i)<0){
        k=k-vec.at(i);
      }
      else{
        k=k+vec.at(i);
      }
    }
    k=k+vec.at(n-1)-vec.at(0);
    cout<<k<<endl;
    for(i=1; i<n-1; i++){
      if(vec.at(i)<0){
        cout<<vec.at(n-1)<<" "<<vec.at(i)<<endl;
        vec.at(n-1)=vec.at(n-1)-vec.at(i);
      }
      else{
        cout<<vec.at(0)<<" "<<vec.at(i)<<endl;
        vec.at(0)=vec.at(0)-vec.at(i);
      }
    }
    cout<<vec.at(n-1)<<" "<<vec.at(0)<<endl;
  }
}

Measured memory_bytes: 2304
package main

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

func fill(s []int, x int) {
	for i := 0; i < len(s); i++ {
		s[i] = x
	}
}

func main() {
	N := readInt()
	M := readInt()

	dp := make([]int, 1<<uint(N))
	fill(dp, math.MaxInt64)

	dp[0] = 0
	for i := 0; i < M; i++ {
		a := readInt()
		b := readInt()
		m := 0
		for i := 0; i < b; i++ {
			c := readInt()
			m |= 1 << uint(c-1)
		}
		for j := (1 << uint(N)) - 2; j >= 0; j-- {
			if dp[j] == math.MaxInt64 {
				continue
			}
			if dp[j]+a < dp[j|m] {
				dp[j|m] = dp[j] + a
			}
		}
	}
	if dp[(1<<uint(N))-1] == math.MaxInt64 {
		fmt.Println(-1)
	} else {
		fmt.Println(dp[(1<<uint(N))-1])
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

typedef long long ll;

int main()
{
    int M1, M2, D1, D2;
    cin >> M1 >> D1 >> M2 >> D2;
    bool A = ((M1 + 1) == M2) && D2 == 1;

    cout << (A ? 1 : 0) << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

x=0
y=0
a.sort()
i=1
while (i<len(a)):
  if a[i-1]==a[i]:
    x=y
    y=a[i]
    i+=2
  else:
    i+=1

print(x*y)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
#define ll long long
#define W 1000000007
using namespace std;

int main(){
	int n,x;
	cin>>n>>x;
	int a[n];
	lp2(i,n)cin>>a[i];
	sort(a,a+n);
	int sum=a[0],num=1,f=0;
	lp3(i,1,n){
		if(sum>=x){
			f=1;
			break;
		}
		sum+=a[i];
		num++;
	}
	if(sum>x)num--;
	if(f==0&&sum<x)num--;
	cout<<num<<endl;
	return 0;
}


Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var [n,m,x] = nexts(3);
  var a = nextm(n,m+1);
  var ans = 1e9;
  for(var i = 1; i < 1<<n; i++){
    var j = i, t = 0, sum = 0, tot = xArray(0,m);
    while(j){
      if(j & 1){
        sum += a[t][0];
        for(var k = 1; k <= m; k++)tot[k-1] += a[t][k];
      }
      j >>= 1, t++;
    }
    var flag = 1;
    for(var j = 0; j < m; j++)if(tot[j] < x)flag = 0;
    if(flag && ans > sum)ans = sum;
  }
  return ans === 1e9 ? -1 : ans;
}

Measured memory_bytes: 34464
#include<stdio.h>

int main(){
    int N,frag = 0,Nfrag = 0;
    scanf("%d",&N);
    int a[N];
    for (int i = 0; i < N; i++)
    {
        scanf("%d",&a[i]);
    }
    while(frag == 0){
        for (int i = 0; i < N; i++)
        {
            if(a[i] % 2 == 1){
                frag = 1;
            }
        }
        if(frag == 0){
            for (int i = 0; i < N; i++)
            {
                a[i] /= 2;
            }
            Nfrag++;
        }
    }
    printf("%d",Nfrag);
    
    
}

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

bool is_month(ll a) {
  if (1 <= a && a <= 12) {
    return true;
  }
  return false;
}

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

  ll n;
  cin >> n;
  ll a, b;
  a = n / 100;
  b = n % 100;

  if (is_month(a) && is_month(b)) {
    cout << "AMBIGUOUS" << endl;
  } else if (is_month(a)) {
    cout << "MMYY" << endl;
  } else if (is_month(b)) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int a[6], b[]={0,0,0,0};
    for (int i=0; i<6; i++) {
        cin >>a[i];
        b[a[i]-1]++;
    }

    bool f=true;
    for (int i=0; i<4; i++)
        if (b[i]>2) f=false;

    if (f) cout << "YES" << endl;
    else   cout << "NO"  << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>
using namespace std;
int main() {

	int n; cin >> n;
	int sum[60] = {}, all = 0;
	map<string, int> s;

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

		string ss; int t;
		cin >> ss >> t;

		s[ss] = i;
		all += t;

		if (i == 0) { sum[0] = t; }
		else { sum[i] = sum[i - 1] + t; }
	}
	
	string x; cin >> x;
	cout << all - sum[s[x]] << endl;

	return 0;
}

Measured memory_bytes: 256
from math import *
#import sys 
#cin = sys.stdin()

cnt = [[0] * 20 for i in range(20)]

ans = 0
for _ in range(int(input())):
    t = input().strip().split('.')
    if (len(t) > 1):
        b = int(t[0])*1000000000 + int(t[1]) * 10 ** (9 - len(t[1]))
    else:
        b = int(t[0]) * 1000000000
    x, y = 0, 0
    while (b % 2 == 0) and (x <= 18):
        x += 1
        b //= 2
    while (b % 5 == 0) and (y <= 18):
        y += 1
        b //= 5
    #print(x, y)
    for i in range(20):
        for j in range(20):
            if (i + x >= 18) and (j + y >= 18):
                ans += cnt[i][j]
    cnt[x][y] += 1
print(ans)


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

struct UnionFind {
    vector<int> par;
    UnionFind(int N) : par(N) {
        for (int i=0; i<N; i++) par[i]=i;
    }
    int root(int x) {
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x, int y) {
        int rx=root(x);
        int ry=root(y);
        if (rx==ry) return;
        par[rx]=ry;
    }
    bool same(int x,int y) {
        int rx=root(x);
        int ry=root(y);
        return rx==ry;
    }
};

int main() {
   int n,q;
   cin >> n >> q;
   UnionFind tree(n);
   for (int i=0; i<q; i++) {
       int com,x,y;
       cin >> com >> x >> y;
       if (com==1) cout << tree.same(x,y) << endl;
       else tree.unite(x,y);
   }
}


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


int main(){
    int A, B;
    cin >> A >> B;

    if(A >= 13) cout << B << endl;
    if(A >= 6 && A <= 12) cout << B/2 << endl;
    if(A <= 5) cout << 0 << endl;

    return 0;
}


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

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

  int ans = 0;
  REP(i, 3) if(s[i] == t[i]) ans++;
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n,q;
  cin >> n >> q;
  dsu D(n);
  for(int i=0;i<q;i++){
    int t,u,v;
    cin >> t >> u >> v;
    if(t == 0){
      D.merge(u, v);
    }
    else {
      if(D.same(u, v)){
        cout << 1 << endl;
      }
      else{
        cout << 0 << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4024
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cctype>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
inline void outi(int x) {if (x > 9) outi(x / 10);putchar(x % 10 + '0');}
inline void outl(ll x) {if (x > 9) outl(x / 10);putchar(x % 10 + '0');}


using namespace std;

long long arr[200005];
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	
	int n,f;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	f = arr[0];
	long long suma = 0, sumb = 0;
	for(int i=1;i<n;i++){
		if(arr[i] < f){
			suma += f - arr[i];
		}else if(arr[i] > f){
			f = arr[i];
		}
	}
	cout<<suma<<endl;
	return 0;
}


Measured memory_bytes: 5108
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
	const int N = 3;
	std::vector<int> A(N);
	for(int i = 0; i < N; i++) {
		std::cin >> A[i];
	}

	std::sort(A.begin(), A.end());
	
	int result = 0;
	for(int i = 1; i < N; i++) {
		result += A.at(i) - A.at(i - 1);
	}

	std::cout << result << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;
constexpr int64_t MOD = 1'000'000'007;

int main(void) {
    int N, K;
    cin >> N >> K;

    int64_t ans = 0;
    for(int64_t k=K; k<=N+1; k++) {
        int64_t mx = k*(2*N-k+1) / 2;
        int64_t mn = k*(k-1)/2;
        ans += mx-mn+1;
        ans%= MOD;
    }

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


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,p;
  cin >> n >> p;
  map<ll, ll> mp = prime_factor(p);
  ll ans = 1;
  for(auto v: mp){
    if(v.second >= n){
      REP(i, v.second/n) ans *= v.first;
    }
  }

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

Measured memory_bytes: 256
base = 127
mask = (1 << 32) - 1
def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = set()
    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.add(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.add(e)
    return tmp
t = tuple(ord(c) for c in input())
tl = len(t)
q = int(input())
h = dict()
c = dict()
a = []
for _ in range(q):
    p = input()
    if p in c:
        a.append(c[p])
        continue
    p = tuple(ord(c) for c in p)
    pl = len(p)
    if pl > tl:
        a.append(0)
        continue
    bs = min(19, pl)
    keys = calc_hash(p, bs, pl)
    if bs not in h:
        h[bs] = calc_hash(t, bs, tl)
    a.append(1 if keys.issubset(h[bs]) else 0)
print('\n'.join(map(str, a)))



Measured memory_bytes: 1073704
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <numeric>

using namespace std;

typedef long long ll;

int main(void){
    ll n,m;
    cin >> n >> m;
    n = n - 2 < 0 ? n : n - 2;
    m = m - 2 < 0 ? m : m - 2;
    cout << n * m << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;
import java.math.BigInteger;


class Main{
	public static void main(String args[]){
		
		Scanner input = new Scanner(System.in);

		int a,b,c,d;
		a = b = c = d = 0;

		if(input.hasNextInt())a = input.nextInt();
		if(input.hasNextInt())b = input.nextInt();	
		if(input.hasNextInt())c = input.nextInt();
		if(input.hasNextInt())d = input.nextInt();


		BigInteger A = BigInteger.valueOf(a);
		BigInteger B = BigInteger.valueOf(b);
		BigInteger max1 = A.multiply(BigInteger.valueOf(c));
		BigInteger max2 = A.multiply(BigInteger.valueOf(d));
		BigInteger max3 = B.multiply(BigInteger.valueOf(c));
		BigInteger max4 = B.multiply(BigInteger.valueOf(d));

		int ca = max1.compareTo(max2);
		int cb = max3.compareTo(max4);

		BigInteger f1,f2;
		if(ca>0)f1 = max1;
		else f1 = max2;
		if(cb>0)f2 = max3;
		else f2 = max4;

		int cf = f1.compareTo(f2);
		if(cf>0)System.out.println(f1);
		else System.out.println(f2);


		
	}
}

Measured memory_bytes: 36076
s = input()
t = input()

base = 3
MOD = 1004535809

def rolling_hash(s, base, MOD):
    l = len(s)
    h = [0]*(l + 1)
    for i in range(l):
        h[i+1] = (h[i] * base + ord(s[i])) % MOD
    return h

s = s * ((len(t) + len(s) - 1)//len(s) * 2)
rh0 = rolling_hash(s, base, MOD)
B = 0
for c in t:
    B = (B * base + ord(c)) % MOD
N = len(s)//2
M = len(t)
R = [0]*N
L = pow(base, M, MOD)
r = 0
for i in range(N):
    if (rh0[i+M] - rh0[i]*L) % MOD == B:
        R[i] = 1
if not any(R):
    print(0)
    exit(0)

S = []
for i in range(N):
    if R[i-M] and R[i] == 0:
        S.append((i - M) % N)
if not S:
    print(-1)
    exit(0)

ans = 0
for v in S:
    d = 1
    while R[v-M]:
        d += 1
        v = (v - M) % N
    ans = max(ans, d)
print(ans)

Measured memory_bytes: 95068
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            List<String> input = Arrays.asList(br.readLine().split(" "));
            List<Integer> numbers = new ArrayList<>();

            for (String s : input) {
                numbers.add(Integer.parseInt(s));
            }

            int result = 0;
            if (numbers.get(0) - numbers.get(1) * 2 > 0) {
                result = numbers.get(0) - numbers.get(1) * 2;
            }

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

ll X;

ll pow(ll x){
    ll res = 1;
    for(int i = 0; i < 5; i++) res *= x;
    return res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> X;
    vector<ll> v;
    for(int i = 0; i <= 1000; i++){
        v.push_back(pow(i));
    }
    for(int i = 0; i <= 1000; i++){
        for(int j = 0; j <= 1000; j++){
            if(v[i] - v[j] == X){
                cout << i << " " << j << endl;
                return 0;
            }
            if(v[i] + v[j] == X){
                cout << i << " " << -j << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)


Measured memory_bytes: 230888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll ans=0;
    ll N,K;
    int r,s,p;
    cin >> N >> K;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    rep(j,K) {
        string a;
        for (int i=j; i < N; i += K) {
            a.push_back(t[i]);
        }
        char l = 0;
        for (int i=0; i<(int)a.size(); ++i) {
            if (a[i] == 's') {
                if (l != 'r') {
                    ans += r;
                    l = 'r';
                } else {
                    l = 0;
                }
            }
            if (a[i] == 'p') {
                if (l != 's') {
                    ans += s;
                    l = 's';
                } else {
                    l = 0;
                }
            }
            if (a[i] == 'r') {
                if (l != 'p') {
                    ans += p;
                    l = 'p';
                } else {
                    l = 0;
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3760
import java.util.ArrayList;
import java.util.*;
class Main{
     public static void main(String[] args) {
      Scanner sc=new Scanner(System.in);
      int a=sc.nextInt();
      int b=sc.nextInt();
      int c=sc.nextInt();
      List<Integer> l=new ArrayList();
      l.add(a);
      l.add(b);
      l.add(c);
      Collections.sort(l);
      if((l.get(0)==l.get(1) && l.get(1)!=l.get(2)) || (l.get(0)!=l.get(1) && l.get(1)==l.get(2))){
         System.out.println("Yes");
         System.exit(0);
      }else{
         System.out.println("No");
         System.exit(0);
      }
   }
}  

Measured memory_bytes: 35768
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map>       // pair
#include <string>
#include<stdio.h>
using namespace std;

int main(int argc, const char *argv[])
{
    long long N;
    vector<long long> P (5);
    cin>>N;
    for(int i =0 ; i < 5 ; i ++)
    {
        cin>>P[i];
    }
    
    long long out = 5;
    long long Q = 0, R = 0;
    long long times;
    long long max_times = 0;
    for(int i = 0; i < 5; i ++)
    {
        Q = N/P[i];
        R = N%P[i];
        if(R == 0)
        {
            times = Q;
        }
        else
        {
            times = Q + 1;
        }
        if(times > max_times)
        {
            max_times = times;
        }
    }
    out = out - 1 + max_times;

    cout << out;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

static const int NMAX = 1e5;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

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

	int n;
	string s;
	cin >> n >> s;
	for(int i = 0; i < (int) s.size(); ++i)
	{
		int c = s[i] - 'A';
		c+= n;
		c%= 26;
		s[i] = (char) (c+'A');
	}
	cout << s;

    return 0;
}

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

using namespace std;


int main() {
    int n;
    cin>>n;
    
    vector<int> b;
     int sum=0;
    int temp;
    

    for(int i=0;i<n;i++)
    {
        cin>>temp;
        b.push_back(temp);
    }
    sum=b[0];
     for(int i=0;i<n-1;i++)
    {
        sum = sum+ min(b[i],b[i+1]);
    }
    
    cout<<sum;
    
}

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

l = [0] *(10005)

for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            k = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if k <= 10004:
                l[k] += 1

for i in range(1, n+1):
    print(l[i])

Measured memory_bytes: 9236
H, W = map(int, input().split())
graph = [list(input()) for _ in range(H)]


def count_bomb(x, y):
    bomb = 0
    one_steps = ((1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1))
    for dx, dy in one_steps:
        nx, ny = x + dx, y + dy
        if (0 <= nx < H) and (0 <= ny < W):
            if graph[nx][ny] == "#":
                bomb += 1
    return bomb


for x in range(H):
    for y in range(W):
        if graph[x][y] == ".":
            graph[x][y] = str(count_bomb(x, y))
for line in graph:
    print("".join(line))


Measured memory_bytes: 3188
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

H, W = MAP()
A = [input() for _ in range(H)]

cnt_w = sum([X.count("#") for X in A])

if cnt_w == H+W-1:
	print("Possible")
else:
	print("Impossible")

Measured memory_bytes: 5200
#include<algorithm>//sort(all(変数),greater<型名>())で降順に、*max_element(all(変数))で最大値を獲得
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric>
//xとyのgcdは__gcd(x,y),xとyのlcmは(x*y)/__gcd、accumulate(all(変数),0)で要素の全加算
#include<queue>//priority_queue<型名> 変数
#include<set>
#include<stack>
#include<string>
#include<vector>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }

int main(){
  int n;  cin >> n;
  int x = n%10;
  if(x==2 or x==4 or x==5 or x==7 or x==9){
    cout << "hon";
  }else if(x==3){
    cout << "bon";
  }else{
    cout << "pon";
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve() {
    int N; cin>>N;
    vector<int> a(N);
    int maxi=0,mini=N;
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
        chmax(maxi,a[i]);
        chmin(mini,a[i]);
    }

    if(maxi-mini>1){
        cout<<"No"<<endl;
        return;
    }

    if(maxi==mini){
        if(mini==N-1) cout<<"Yes"<<endl;
        else if(N/mini>=2) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        return;
    }

    int mini_cnt,maxi_cnt=0;
    for (int i = 0; i < N; ++i) {
        if(a[i]==maxi) maxi_cnt++;
    }
    mini_cnt=N-maxi_cnt;

    if(mini_cnt<maxi&&maxi<=mini_cnt+maxi_cnt/2){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}


#define SINGLE
int main() {
#ifdef SINGLE
    solve();
#else
    int N;
    cin>>N;
    for(int i=0;i<N;++i){
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 3796