akhauriyash/Code-Regression huggingface dataset:
/* 実行時間1s制限の場合10^6 1,000,000 : 余裕をもって間に合う10^7
  10,000,000 : おそらく間に合う10^8 100,000,000 : 非常にシンプルな処理
  でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    //std::ifstream in(string(argv[0]) + ".txt");
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    map <string, int> m;

    int n;
    cin >> n;

    string s;
    rep(i, n) {
        cin >> s;
        m[s]++;
    }

    cout << m.size();

    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 19180
def factorization(n):
    arr = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr[i] = cnt

    if temp!=1:
        arr[temp]=1

    if arr==[]:
        arr[n] = 1

    return arr



N = int(input())
fac_dic = factorization(N) 
count = 0


for k,v in fac_dic.items():
  tmp = 1
  while(v >= tmp):
    v = v - tmp
    tmp += 1
    count += 1
  


print(count)



Measured memory_bytes: 9496
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, Q; cin >> N >> Q;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    sort(A.begin(), A.end());

    while(Q--) {
        int l, r; cin >> l >> r;
        int il = lower_bound(A.begin(), A.end(), l) - A.begin();
        int ir = upper_bound(A.begin(), A.end(), r) - A.begin();
        cout << ir - il << endl;
    }
    return 0;
}



Measured memory_bytes: 3148
#include <stdio.h>
int main(){
  int a,b,c,d=0,x;
  scanf("%d %d %d",&a,&b,&c);
  for(x=a;x<=b;x++)
    {  if(c%x==0){
	d++;}}printf("%d\n",d);
 return 0;   
}

Measured memory_bytes: 596
while True:
  c =0
  a = int(input())
  if a == 0:break
  else:
    me = 1000 -a
    while me != 0:
     if me >= 500:
        me -= 500 
        c +=1 
     elif me >= 100:
        me -= 100 
        c +=1
     elif me >= 50:
        me -= 50
        c+=1
     elif me >= 10:
        me -= 10
        c +=1
     elif me >= 5:
        me -= 5
        c +=1
     elif me >= 1:
        me -= 1
        c+=1
       
       
     
     
    print c

Measured memory_bytes: 4240
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define mem0(x) memset(x, 0, sizeof(x))
#define mem1(x) memset(x, -1, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define de(x) cout << #x << " = " << x << ", "
#define dl(x) cout << #x << " = " << x << endl
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i > b; i--)
#define setI freopen("input.txt", "r", stdin);
#define setIO freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout);
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---------------------------------------------------------//
const int N = 55;
const int M = 55 * 55;

struct Edge
{
	int u, v;
} e[M];
int n, m;
int pre[N], low[N], dfs_num;
vi g[N];

void tarjan(int u, int fa)
{
	low[u] = pre[u] = ++dfs_num;
	for (auto &v: g[u])
	{
		if (v == fa)  continue;
		if (!pre[v])
		{
			tarjan(v, u);
			low[u] = min(low[u], low[v]);
		}
		else  low[u] = min(low[u], pre[v]);
	}
}

int main()
{
	#ifdef LOCAL
		setI;
	#endif
//	ios::sync_with_stdio(false);
	scanf("%d%d", &n, &m);
	rep(i, 0, m)
	{
		scanf("%d%d", &e[i].u, &e[i].v);
		g[e[i].u].pb(e[i].v);
		g[e[i].v].pb(e[i].u);
	}
	tarjan(1, -1);
	bool ok = true;
	rep(i, 1, n + 1)
		if (!pre[i])
		{
			ok = false;
			break;
		}
	if (!ok)  printf("0\n");
	else
	{
		int ans = 0;
		rep(i, 0, m)
		{
			int u = e[i].u, v = e[i].v;
			if (low[u] > pre[v] || low[v] > pre[u])  ans++;
		}
		printf("%d\n", ans);
	}
	
	return 0;
}

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

#define MOD 1000000007

long long f[100200];

int mod_pow(long long n, long long m){

  long long ans = 1;
  while(m > 0){
    if(m & 1 == 1) ans = (ans * n) % MOD;
    n = (n*n) % MOD;
    m >>= 1;
  }

  return ans;
}

int gyaku(long long a){
  return mod_pow(a,MOD-2) % MOD ;
}

int comb(long long n, long long r){
  return f[n] * gyaku(f[r]) % MOD * gyaku(f[n-r]) % MOD;
}


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

  f[0] = 1;
  for(int i = 1;i < 100200;i++) f[i] = f[i-1] * i % MOD;

  map<int, int> mp;
  queue<int> que;

  int nn = m;
  int tmp = 2;
  while(nn != 1 && tmp*tmp <= nn){
    if(nn % tmp == 0){
      mp[tmp]++;
      if(mp[tmp] == 1){
        que.push(tmp);
      }
      nn /= tmp;
    }else{
      tmp++;
    }
  }

  if(nn != 1){
    mp[nn]++;
    if(mp[nn] == 1){
      que.push(nn);
    }
  }


  long long ans = 1;
  while(!que.empty()){
    ans = (ans * comb(mp[que.front()]+n-1,n-1)) % MOD;
    que.pop();
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 1024
#!python3.4
# -*- coding: utf-8 -*-
# abc154/abc154_a
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S,T = i2s().split()
    A,B = i2nn()
    U = i2s()
    d = {S:A, T:B}
    d[U] -= 1
    print(d[S], d[T])
    return

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int c[n - 1], s[n - 1], f[n - 1];
    rep(i, 0, n - 1) {
        cin >> c[i] >> s[i] >> f[i];
    }

    rep(i, 0, n - 1) {
        int time = 0;
        rep(j, i, n - 1) {
            if (j == i) {
                time += (s[j] + c[j]);
            } else {
                int x = s[j];
                while (x < time) {
                    x += f[j];
                }
                time = x + c[j];
            }
        }
        cout << time << endl;
    }
    cout << 0 << endl;
    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	int64 K;
	cin >> s >> K;
	int64 res = 0;
	vector<int64> cnt;
	REP(i, s.size()) {
	    if (i == 0 || s[i] != s[i-1]) cnt.push_back(1);
	    else cnt.back()++;
	}
	FOR(i, 1, cnt.size()-1) {
	    res += cnt[i]/2;
	}
//	REP(i, cnt.size()) {
//	    cout << cnt[i] << " ";
//	}
//	cout << endl;
//	cout << s[0] << " " << s.back() << endl;
	if (s[0] == s.back()) {
	    if (cnt.size() == 1) {
	        res = K*cnt[0]/2;
	    } else {
	        res *= K;
	        res += cnt[0]/2 + cnt.back()/2 + (cnt[0]+cnt.back())/2*(K-1);
	    }
	} else {
	    res += cnt[0]/2 + cnt.back()/2;
	    res *= K;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = set()
for i in range(1,10):
    for j in range(1,10):
        s.add(i * j)
print('Yes' if n in s else 'No')

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

int main() {
    int N, D, X;
    cin >> N >> D >> X;
    vector<int> A(N);
    for (int i=0; i<N; i++) cin >> A.at(i);
    for (int i=0; i<N; i++) {
        for (int j=0; j<D; j++) {
            if (j*A.at(i)+1>D) break;
            X++;
        }
    }
    cout << X;
}

Measured memory_bytes: 256
//////////////////////////      一      //////////////
/*
注意点：
1. 注意读题（对应1z//2.）
2.插入排序的插入位置（对应1z//1.）
3.插入排序的升降序控制（对应 1z//3.   1z//4.） 
*/
//------------------1z-------------- 
/*
#include<iostream>
using namespace std;
int a[105];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	for(int i=0;i<n-1;++i){						//4.原来没打 
		cout<<a[i]<<' ';						//4.					 
	}											//4.					
	cout<<a[n-1]<<endl;							//4.
	for(int i=1;i<n;++i){
		int t=a[i];
		int j=i-1;
		while(j>=0&&a[j]>t){					//3.升序是">",降序是"<" 
			a[j+1]=a[j];						 
			--j;
		}
		a[j+1]=t;								//1.后一位（原打成a[j]） 
		for(int i=0;i<n-1;++i){					//2.此循原来写外面了 
			cout<<a[i]<<' ';					//2. 
		}										//2.
		cout<<a[n-1]<<endl;						//2.
	}
	return 0;
}
*/
/////////////////////    答案    /////////////// 
/*
注意点：
1. 
*/
//----------------------自打1------------------ 
/*
#include<cstdio>
void trace(int A[],int N){
	for(int i=0;i<N;++i){
		if(i>0) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
} 
void insertionSort(int A[],int N){
	int v,j;
	for(int i=1;i<N;++i){
		v=A[i];
		j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			--j;
		}
		A[j+1]=v;					//2.是A[j+1](原打成A[j]) 
		trace(A,N);
	}
}
int main(){
	int n;
	scanf("%d",&n);					//1.别忘输入 
	int A[100];
	for(int i=0;i<n;++i){
		scanf("%d",&A[i]);
	}
	trace(A,n);
	insertionSort(A,n);
	return 0;
	
}
*/
//---------------------标准答案--------------------

#include<stdio.h>

/* 按顺序输出数组元素 */
void trace(int A[],int N){
	int i; 
	for(i=0;i<N;++i){
		if(i>0) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
} 

/* 插入排序 */
void insertionSort(int A[],int N){
	int j,i,v;
	for(i=1;i<N;++i){
		v=A[i];
		j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			--j;
		}
		A[j+1]=v;
		trace(A,N);
	}
}

int main(){
	int N,i,j;
	int A[100];
	
	scanf("%d",&N);
	for(int i=0;i<N;++i) scanf("%d",&A[i]);
	
	trace(A,N);
	insertionSort(A,N);
	
	return 0;
}


Measured memory_bytes: 2684
#include <iostream>
#include <algorithm>
using namespace std;
long long a[200010],sum[200010]={0};
int main(){
	long long i,n,x=0;
	cin >> n ;
	for(i=0;i<n;i++){
		cin >> a[i];
		x += a[i];
		sum[i] = x;
	}
	int l = 0, r = 2;
	long long ans = sum[n-1];
	for(i=1;i<n-2;i++){
		while(min(sum[i]-sum[l],sum[l])<min(sum[i]-sum[l+1],sum[l+1])){
			l++;
		}
		while(min(sum[n-1]-sum[r],sum[r]-sum[i])<min(sum[n-1]-sum[r+1],sum[r+1]-sum[i])){
			r++;
		}
		ans = min(ans,max({sum[l],sum[i]-sum[l],sum[r]-sum[i],sum[n-1]-sum[r]})-min({sum[l],sum[i]-sum[l],sum[r]-sum[i],sum[n-1]-sum[r]}));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():

    for _ in range(22):
        h, w = ZZ()
        if h == 0 and w == 0: break
        A = [input() for _ in range(h)]
        D = [(1, 0), (-1, 0), (0, 1), (0, -1)]
        done = [[False] * w for _ in range(h)]
        ans = 0

        def dfs(x, y, fluit):
            if done[x][y]: return
            done[x][y] = True
            for dx, dy in D:
                nx, ny = x+dx, y+dy
                if 0 <= nx < h and 0 <= ny < w and A[nx][ny] == fluit: dfs(nx, ny, fluit)

        ans = 0
        for i in range(h):
            for j in range(w):
                if done[i][j]: continue
                ans += 1
                dfs(i, j, A[i][j])
        print(ans)

    return

if __name__ == '__main__':
    main()



Measured memory_bytes: 18796
import java.util.Scanner;

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

    int a = sc.nextInt();
    int b = sc.nextInt();

    if((a * b)%2 == 1){
    	System.out.println("Odd");
   	}else if((a * b)%2 == 0){
    	System.out.println("Even");
    }
  }
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;
const ll mod = 1e9 + 7;

int main(void)
{
	string s;
	cin >> s;
	int n = s.size();
	vector<vector<ll>> dp(100010, vector<ll>(2, 0));
	constexpr int low = 0;
	constexpr int eq = 1;
	dp[0][low] = 1;
	dp[0][eq] = 2;
	for (int i = 1; i < n; i++) {
		if (s[i] == '1') {
			dp[i][low] = dp[i - 1][low] * 3;
			dp[i][low] += dp[i - 1][eq];
			dp[i][eq] = dp[i - 1][eq] * 2;
		}
		else {
			dp[i][low] = dp[i - 1][low] * 3;
			dp[i][eq] = dp[i - 1][eq];
		}
		dp[i][low] %= mod;
		dp[i][eq] %= mod;
	}
	cout << (dp[n-1][low] + dp[n-1][eq]) % mod << endl;

}


Measured memory_bytes: 5760
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int h, w;
string s[30][30];

string solve() {
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == "snuke") {
                stringstream ss;
                ss << (char)('A'+j);
                ss << i+1;
                return ss.str();
            }
        }
    }
    return "err";
}

void input() {
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++)
            cin >> s[i][j];
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 256
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0008
 */
#include <iostream>
#include <vector>

using namespace	std;

int
main()
{
	ios_base::sync_with_stdio(false);

	vector<int> m(51);
	for (int i = 0; i < 10000; i++) {
		m[ i % 10 + i / 10 % 10 + i / 100 % 10 + i / 1000 ]++;
	}

	int n;
	while (cin >> n) {
		cout << m[n] << endl;
		cin.ignore();
	}
	return 0;
}

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

/*
    すべての＃が、隣接マスに＃をもつならばYes。そうでなければNo
*/

int main() {
    int H, W;
    cin >> H >> W;

    vector<vector<char>> M(H, vector<char>(W));
    int dx[4] = {1, 0,  0, -1};
    int dy[4] = {0, 1, -1,  0};

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> M[i][j];
        }
    }

    bool result = true;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (M[i][j] == '#') {
                int c_n = 0;
                for (int d = 0; d < 4; d++)
                {
                    int cx = i + dx[d];
                    int cy = j + dy[d];
                    if (cx < 0 || H<= cx)
                        continue;
                    if (cy < 0 || W <= cy)
                        continue;
                    
                    if (M[cx][cy] == '#')
                        c_n++;
                }
                if (c_n == 0) {
                    result = false;
                    break;
                }
            }
        }
        
    }

    if (result) {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void)
{
  while(true) {
    int n, k[105];
    cin >> n;
    if(!n) break;
    REP(i, n) cin >> k[i];
    string s;
    cin >> s;
    int t[105];
    REP(i, s.size()) {
      if('a' <= s[i] && s[i] <= 'z') {
        t[i] = s[i] - 'a' + 1;
      } else {
        t[i] = s[i] - 'A' + 27;
      }
    }
    int cnt = 0;
    REP(i, s.size()) {
      t[i] -= k[cnt];
      if(t[i] <= 0) t[i] += 52;
      cnt++;
      if(cnt == n) cnt = 0;
    }
    //REP(i, s.size()) cout << t[i] << " "; cout << endl;
    REP(i, s.size()) {
      if(1 <= t[i] && t[i] <= 26) {
        cout << (char)('a' + t[i] - 1);
      } else {
        cout << (char)('A' + t[i] - 27);
      }
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3172
#include <iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(a + b == 2 && c == 0 || a + b == 0 && c == 1) cout << "Open";
  else cout << "Close";
  cout << endl;
  return 0;
}

Measured memory_bytes: 1156
#coding:utf-8
h, w, a, b = map(int, input().split())

if a > (w//2) or b > (h//2):
    print('No')
else:
    for _ in range(h-b):
        print('0'*(w-a) + '1'*a)
    for _ in range(b):
        print('1'*(w-a) + '0'*a)

Measured memory_bytes: 3956
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */
 
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007
 
const long double PI = 3.141592653589793236L;
 
typedef long long int ll;
typedef long double ld;
 
using namespace std;

void solve()
{
    int n;
    cin >> n;

    vector<vector<int>> d(n, vector<int> (2));

    for(int i = 0; i < n; i++)
    {
        cin >> d[i][0] >> d[i][1];
    }

    for(int i = 0; i < n - 2; i++)
    {
        bool is_valid = true;
        for(int j = 0; j < 3; j++)
        {
            if(d[i + j][0] != d[i + j][1])
            {
                is_valid = false;
                break;
            }
        }

        if(is_valid)
        {
            cout << "Yes\n";
            return;
        }
    }

    cout << "No\n";
    
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int T = 1;
    //cin >> T;

    while (T--)
    {
        solve();
    }
    
    return 0;
}
 


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if (A==B){
    cout << C << endl;
  }
  if (B==C){
    cout << A << endl;
  }
  if (C==A){
    cout << B << endl;
  }
}

Measured memory_bytes: 256
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2, cos, pi
from fractions import Fraction

n, m = map(int, stdin.readline().split())
g = [[] for _ in range(n+1)]

for _ in range(m):
    a, b = map(int, stdin.readline().split())
    g[a].append(b)
    g[b].append(a)

signposts = [0]*(n+1)

queue = dq([1])

visited = [0]*(n+1)
visited[1] = 1
while queue:
    parent = queue.popleft()
    for children in g[parent]:
        if not visited[children]:
            # print('dbg:', parent, children)
            signposts[children] = parent
            queue.append(children)
            visited[children] = 1

if 0 in signposts[2:]:
    print('No')
else:
    print('Yes')
    print(*signposts[2:], sep='\n')















# t = int(stdin.readline())
# for _ in range(t):
# n, m = map(int, stdin.readline().split())
# nums = list(map(int, stdin.readline().split()))
# n = int(input())
# if n%10 in [2, 4, 5, 7, 9]:
#     print('hon')
# elif n%10 in [0, 1, 6, 8]:
#     print('pon')
# else:
#     print('bon')

# k = int(input())
# s = input()

# ans = s[:k] + ('...' if len(s) > k else '')
# print(ans)

# hrhand, minhand, hr, minut = map(int, stdin.readline().split())

# angmin =360*minut/60
# anghr =360*(hr + minut/60)/12


# totang = abs(angmin - anghr)


# print((hrhand**2 + minhand**2 - 2*hrhand*minhand*cos(totang*pi/180))**0.5)



Measured memory_bytes: 102136
#include <bits/stdc++.h>
using namespace std;
//ｎ番目のリュカ数を返す関数


int main() {
  int N;
  cin >> N ;
  int64_t L2=0;
  if(N==1){
    L2=1;
  }
 
  
  else{
  int64_t L0=2;
  int64_t L1=1;
    L2=0;
  
    for(int i=0; i<N-1; i++){
      L2=L1+L0;
      L0=L1;
      L1=L2;
      
    }
  }
  
  
  cout << L2 << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const int mod = 1e9+7;


main(){
    string s;cin>>s;
    int n = s.size();
    if(s[n-1]=='s'){
        cout<<s<<"es";
    }
    else cout<<s<<"s";
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

#define int long long

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

#define INF (3e9)

using namespace std;

bool search(int x, int A, int B)
{
    int ret = 0;
    for (int i = max(x/2-50, 1LL); i <= min(x/2+50, x); ++i)
    {
        int first = i;
        if (first >= A) ++first;
        int second = x + 1 - i;
        if (second >= B) ++second;
        ret = max(ret, first * second);
    }
    return ret < A*B;
}

int solve(int A, int B)
{
    if (A > B) swap(A, B);

    int lo = 0;
    int hi = INF;
    int ans = 0;
    while (lo <= hi)
    {
        int mid = (hi + lo) / 2;
        if (search(mid, A, B))
        {
            ans = mid;
            lo = mid + 1;
        }
        else
        {
            hi = mid - 1;
        }
    }
    return ans;
}

signed main()
{
    int Q;
    cin >> Q;

    REP(i, Q)
    {
        int A, B;
        cin >> A >> B;

        int ans = solve(A, B);
        printf("%lld\n", ans);
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Map<String, Integer> map = new HashMap<>();

		for (int i = 0; i < n; i++) {
			String key = scanner.next();
			if (map.containsKey(key)) {
				map.put(key, map.get(key) + 1);
			} else {
				map.put(key, 1);
			}
		}

		int m = scanner.nextInt();
		for (int i = 0; i < m; i++) {
			String key = scanner.next();
			if (map.containsKey(key)) {
				map.put(key, map.get(key) - 1);
			} else {
				map.put(key, -1);
			}
		}

		int max = -1000000000;
		for (int val : map.values()) {
			max = Math.max(max, val);
		}
		if (max >= 0)
			System.out.println(max);
		else
			System.out.println(0);
	}
}

Measured memory_bytes: 21716
#include <stdio.h>
long long f(long long b,long long x){
	return x<b?x:f(b,x/b)+x%b;
}
long long g(){
	long long n,s,b=2,r=-1,z;
	scanf("%lld%lld",&n,&s);
	if(n<s)return -1;
	if(n==s)return n+1;
	for(;b*b<=n;b++)if(f(b,n)==s)return b;
	for(b=1;b*b<=n&&b<=s;b++){
		if((n-s)%b==0&&f(z=(n-s)/b+1,n)==s)r=z;
		//if(!~r&&s==1)r=n;
	}
	return r;
}
int main(){printf("%lld\n",g());}

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

 int main()
 {
   int n; cin>>n;
   long long int s=0;
   
   for(int i=1;i<=n;i++)
   {
     if( i%3==0 || i%5 ==0 )
       s+=0;
     else s+=i;
   }
   cout<<s;
 }

Measured memory_bytes: 3644
//Meri hr baat bs yaad hai tumhari , mera apna koi kissa nhi!!
#include<iostream>
#include<bits/stdc++.h>
#define ll long long int 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define md 1000000007
double PI=3.1415926535;
const int N =  (int)(1 * 1e6 + 10);

using namespace std;

int main()

{
    ll n , p;
    cin>>n;
    ll a[n] , b[n];
    cin>>a[0];
    p = a[0];
    for(ll i = 1 ; i <=n-1 ; i++)
    {
        cin>>a[i];
        p=(p^a[i]);
    }
    for(ll i = 0 ; i < n ; i++)
    {
        b[i]=(p^a[i]);
        cout<<b[i]<<" ";
    }


}

Measured memory_bytes: 6752
#include<stdio.h>
#include<limits.h>
  
int main(){
  
  int M[105][105],d[105],array[105],P[105];
  int i,j,ji,n;
  int ans = 0,ka = 1,min = 0;
   
  scanf("%d",&n);
   
  for(i = 0; i < n; i++){
   
    for(j = 0; j < n; j++){
      scanf("%d",&M[i][j]);
    }
     
    d[i] = INT_MAX;
    array[i] = 0;
     
  }
   
  d[0] = 0;
  array[0] = 1;
  P[0] = 0;
   
//M[0][0]
 
  while(1){
 
    for(i = 0; i < ka ; i++){
      for(j = 0 ; j < n ; j++){
 
      if(array[P[i]] == 0 || array[j] == 0){
        if(M[P[i]][j] != -1 && d[ka] >= M[P[i]][j]){
 
          d[ka] = M[P[i]][j];
                        ji = j;
 
        }
      }
    }
      }
 
      ka++;
      array[ji] = 1;
      P[i] = ji;
 
      if(ka > n) break;
 
  }
     
    for(i = 0; i < n; i++){
      ans += d[i];
    }
 
    printf("%d\n",ans);
 return 0;
}

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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);
//  freopen(Task".out", "w", stdout);
  string s; cin >> s;
  deque<char> dq[2];
  for (auto c : s){
    dq[0].push_back(c);
    dq[1].push_front(c);
  }
  int q; cin >> q;
  int cur = 0;
  while (q--){
    int t; cin >> t;
    int op = cur ^ 1;
    if (t == 1){
      cur = op;
    } else {
      int f; char c;
      cin >> f >> c;
      if (f == 1){
        dq[cur].push_front(c);
        dq[op].push_back(c);
      } else {
        dq[op].push_front(c);
        dq[cur].push_back(c);
      }
    }
  }
  while(not dq[cur].empty()){
    cout << dq[cur].front();
    dq[cur].pop_front();
  }
}



Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin>>k;
    string s;
    cin>>s;
    for(int i=0; i<s.length(); i++)
    {
       if(k>=s.length())
       {
           cout<<s<<endl;
           return 0;
       }
       else
       {
        for(i=0; i<k; i++)
        {
            cout<<s[i];
        }
        cout<<"..."<<endl;
        return 0;
       }
    }
}


Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			String a=sc.next();
			int l=sc.nextInt();
			if(Integer.parseInt(a)==0&&l==0) break;
			String[] aa=a.split("");
			int num=1;
			int[] data = new int[21];
			while(true){
				if(num==21) break;
				Integer[] a0=new Integer[l];
				Integer[] a0r=new Integer[l];
				int max=0,min=0,by=1;
				if(num==1){
					for(int i=0;i<l;++i){
						if(a.length()+i<l){ a0[i]=0; a0r[i]=0; }
						else{ a0[i]=Integer.parseInt(aa[i-(l-a.length())]); a0r[i]=a0[i];}
					}
					for(int i=l-1;i>=0;--i){
						data[0]+=a0[i]*by;	by*=10;
					}
					by=1;
				} else {
					String an = an=Integer.toString(data[num-1]);;
					String[] anr=an.split("");
					for(int i=0;i<l;++i){
						if(an.length()+i<l){ a0[i]=0; a0r[i]=0; }
						else{ a0[i]=Integer.parseInt(anr[i-(l-an.length())]); a0r[i]=a0[i]; }
					}
				}
				Arrays.sort(a0);
				Arrays.sort(a0r,Collections.reverseOrder());
				for(int i=l-1;i>=0;--i){
					min+=a0[i]*by; max+=a0r[i]*by;
					by*=10;
				}
				data[num]=max-min;
				num++;
			}
			int ansi=21,ansj=21;
			for(int j=0;j<20;++j){
				for(int i=j+1;i<21;++i){
					if(data[j]==data[i]){
						if(i<ansi){ ansi=i; ansj=j;}
					}
				}
			}
			System.out.println(ansj+" "+data[ansi]+" "+(ansi-ansj));
		}
	}
}



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

using namespace std;

int main(int argc, const char *argv[]) {
  using ll = long long;
  ll n;
  cin >> n;

  auto f = [](ll a, ll b) -> ll {
    return max(to_string(a).size(), to_string(b).size());
  };

  ll ans = -1;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ans = ans < 0 ? f(i, n / i) : min(ans, f(i, n / i));
    }
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <iostream>
#include <vector>

//
// Union-Find Tree size version
//
// verify:AOJ DSL_1_A
//
struct UnionFindSize {
    std::vector<int> data;
    const int n;
    UnionFindSize(int num) : n(num) { data.assign(n, -1); }
    int find(int k) {
        assert(0 <= k && k < n);
        if (data[k] < 0) return k;
        return (data[k] = find(data[k]));
    }
    bool unite(int x, int y) {
        assert(0 <= x && x < n);
        assert(0 <= y && y < n);
        x = find(x), y = find(y);
        if (x == y) return false;
        if (data[x] > data[y]) std::swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    int size(int k) {
        assert(0 <= k && k < n);
        return (-data[find(k)]);
    }
    bool same(int x, int y) {
        assert(0 <= x && x < n);
        assert(0 <= y && y < n);
        return find(x) == find(y);
    }
};

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    UnionFindSize uf{n};
    vector<int> ans;
    for (int i = 0; i < q; ++i) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com) {
            ans.push_back(uf.same(x, y));
        } else {
            uf.unite(x, y);
        }
    }
    for (auto &a : ans) {
        cout << a << endl;
    }

    return 0;
}


Measured memory_bytes: 3328
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  ulong N, M; readf("%d %d\n", &N, &M);
  auto A = readln.split.to!(ulong[]);

  ulong sum;
  foreach(a; A) {
    sum += a;
  }

  writeln(sum >= N ? "Yes" : "No");
}


Measured memory_bytes: 3744
n,m = map(int,input().split())
h = [int(x) for x in input().split()]

mem = [[] for _ in range(n)]

for i in range(m):
    a, b = map(int,input().split())
    mem[a-1].append(b-1)
    mem[b-1].append(a-1)

ans = 0



for j in range(n):
    flag = 1
    for k in range(len(mem[j])):
        if h[j] <= h[mem[j][k]]:
            flag = 0
    if flag ==  1:
        ans += 1

print(ans)

Measured memory_bytes: 29344
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

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

	for (auto iter = s.begin(); iter != s.end(); ++iter)
	{
		if (*iter == '1') { *iter = '9'; }
		else if (*iter == '9') { *iter = '1'; }
	}

	cout << s << endl;

	return 0;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string q = Console.ReadLine();
            int an = 0;
            for (int i = 0; i < 4; i++)
            {
                if (q[i] == '+')
                {
                    an++;
                }
                else { an -= 1; }
            }
            Console.Write(an);
        }
    }
}

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

ll k;
queue<string> q;

string bfs() {
    ll cnt = 0;
    string s = "";

    for (int i = 1; i <= 9; ++i) {
        q.push(to_string(i));
    }

    while (!q.empty()) {
        s = q.front();
        q.pop();
        cnt++;
        if (cnt == k) break;

        int num = atoi(&s[(int)s.length()-1]);
        if (num == 0) {
            q.push(s + to_string(num));
            q.push(s + to_string(num + 1));
        } else if (num == 9) {
            q.push(s + to_string(num - 1));
            q.push(s + to_string(num));
        } else {
            q.push(s + to_string(num - 1));
            q.push(s + to_string(num));
            q.push(s + to_string(num + 1));
        }
    }
    return s;
}

int main () {
    cin >> k;
    cout << bfs() << endl;
}


Measured memory_bytes: 9804
# -*- coding: utf-8 -*-
a, b = map(int, raw_input().split())
if a % 3 == 0:
    print 'Possible'
elif b % 3 == 0:
    print 'Possible'
elif (a + b) % 3 == 0:
    print 'Possible'
else:
    print 'Impossible'

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

	public static void main(String[] args) {

		//入力の読み込み処理
		Scanner sc = new Scanner(System.in);
		double R = sc.nextInt();

		//計算結果の表示
		System.out.print(2 * R * 3.14);
	}
}

Measured memory_bytes: 27192
#include <stdio.h>

//#define DEBUG
#define N 5

void swap(int* a,int* b)
{
    int tmp=*b; *b=*a; *a=tmp;
}

int main(void)
{
#ifdef DEBUG
    FILE *fp=fopen("input.txt","r");
#else
    FILE *fp=stdin;
#endif

    int data[5];
    fscanf(fp,"%d %d %d %d %d\n",
            data+0,data+1,data+2,data+3,data+4);
    int i,j;
    for(i=0;i<N;i++){
        for(j=i+1;j<N;j++){
            if(data[i]<data[j]){
                swap(data+i,data+j);
            }
        }
    }
    printf("%d %d %d %d %d\n",
            data[0],data[1],data[2],data[3],data[4]);
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N;
	scanf("%d",&N);

	vector<int> V;
	int tmp;

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&tmp);
		V.push_back(tmp);
	}

	int num_query;
	scanf("%d",&num_query);

	int command,left,right;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %d %d",&command,&left,&right);

		if(command == 0){
			printf("%d\n",*min_element(V.begin()+left,V.begin()+right));
		}else{
			printf("%d\n",*max_element(V.begin()+left,V.begin()+right));
		}
	}

	return 0;
}




Measured memory_bytes: 3260
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/









int N;
string s;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> s;
	map<char, int> cnt;
	fore(c, s) cnt[c]++;

	if (cnt['B'] < cnt['R']) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using UM = unordered_multimap<ll, ll>;

void f(ll node, ll current_score, vector<ll>& counter, const UM& tree, const vector<ll>& scores)
{
    if (counter[node - 1] != -1) {
        return;
    }

    current_score += scores[node - 1];
    counter[node - 1] = current_score;

    auto range_it = tree.equal_range(node);
    while (range_it.first != range_it.second) {
        f(range_it.first->second, current_score, counter, tree, scores);
        range_it.first++;
    }
}

void solve(long long N, long long Q, std::vector<long long>&& a, std::vector<long long>&& b, std::vector<long long>&& p, std::vector<long long>&& x)
{
    UM tree;
    for (ll i = 0; i < N - 1; ++i) {
        tree.emplace(a[i], b[i]);
        tree.emplace(b[i], a[i]);
    }

    vector<ll> scores(N);
    for (ll i = 0; i < Q; ++i) {
        scores[p[i] - 1] += x[i];
    }

    vector<ll> counter(N, -1);
    f(1, 0, counter, tree, scores);
    replace(begin(counter), end(counter), -1, 0);
    copy(begin(counter), end(counter), ostream_iterator<ll>(cout, " "));
    cout << "\n";
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    long long N;
    scanf("%lld",&N);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    std::vector<long long> p(Q);
    std::vector<long long> x(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&p[i]);
        scanf("%lld",&x[i]);
    }
    solve(N, Q, std::move(a), std::move(b), std::move(p), std::move(x));
    return 0;
}


Measured memory_bytes: 47092
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = Integer.parseInt(sc.next());
		int H = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		int y = Integer.parseInt(sc.next());
		int r = Integer.parseInt(sc.next());
		if ((x + r) <= W && (y + r) <= H && (x - r) >= 0 && (y - r) >= 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}
}

Measured memory_bytes: 26224
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 55;
const int mod = 1e9 + 7;

int n;
string s1, s2;

int dp[maxn][5][5];

void read_input()
{
    cin >> n >> s1 >> s2;
    s1 = " " + s1;
    s2 = " " + s2;
}

int add(int x, int y)
{
    x += y;
    if(x >= mod) x -= mod;
    return x;
}

void solve()
{
    fill_n(&dp[0][0][0], sizeof(dp) / sizeof(dp[0][0][0]), 0);
    dp[0][0][0] = 1;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < 4; ++j)
            for(int k = 0; k < 4; ++k)
            {
                if(dp[i][j][k] == 0) continue;
                if(s1[i + 1] == s2[i + 1])
                {
                    for(int col = 1; col < 4; ++col)
                    {
                        if(col == j || col == k) continue;
                        dp[i + 1][col][col] = add(dp[i + 1][col][col], dp[i][j][k]);
                    }
                }
                else
                {
                    for(int col1 = 1; col1 < 4; ++col1)
                        for(int col2 = 1; col2 < 4; ++col2)
                        {
                            if(col1 == col2 || col1 == j || col2 == k) continue;
                            dp[i + 2][col1][col2] = add(dp[i + 2][col1][col2], dp[i][j][k]);
                        }
                }
            }
    int ans = 0;
    for(int j = 1; j < 4; ++j)
        for(int k = 1; k < 4; ++k)
            ans = add(ans, dp[n][j][k]);
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 3652
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int t,h,s;
  while(1){

    cin>>t>>h>>s;
    if(t==-1 && h==-1 && s==-1)break;
    int all=7200;//7200second
    int total=s+60*h+3600*t;//used

    all-=total;
    total=all;
    int hour=all/3600;
    all%=3600;
    int minute=all/60;
    all%=60;
    int second=all;
    printf("%02d:%02d:%02d\n",hour,minute,second);

    all=total*3;
    hour=all/3600;
    all%=3600;
    minute=all/60;
    all%=60;
    second=all;
    printf("%02d:%02d:%02d\n",hour,minute,second);

  }

}

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

int main(){
    string s; cin >> s;
    vector<int> num;
    for(auto si:s){
        int i = si - '0';
        num.push_back(i);
    }
    string out;
    for(int bit = 0; bit < (1 << 3); bit++){
        int eq = num[0];
        string eq_s = to_string(eq);
        rep(i, num.size()-1){
            if (bit >> i & 1){
                eq += num[i+1];
                eq_s += "+" + to_string(num[i+1]);
            }
            else{
                eq -= num[i+1];
                eq_s += "-" + to_string(num[i+1]);
            }
        }
        if (eq == 7) out = eq_s + "=7";
    }
    cout << out << endl;
}

Measured memory_bytes: 256
// ABC152_D
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <cstring>  // std::memset
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;
#define rep(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define repr(i, n) for (ll i=n-1; i >= 0; i++)  // n-1 ~ 0
#define rep1(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define all(vec) (vec).begin(), (vec).end()
#define sum(vec) accumulate(all(vec), 0LL)  // 0 は初期値
#define min_vec(vec) min_element(all(vec))  // iterator: * を先頭につける
#define max_vec(vec) max_element(all(vec))  // iterator: * を先頭につける
#define idx(vec, element_iter) distance((vec).begin(), element_iter)
const ll INF = 1LL<<60;  // 10^18（const int inf = 1<<29;）
const double PI = acos(-1);

ll dp[20010][2][2];

pll getLeftRightDigit(ll n) {
    // 左端（最大位），右端（最小位）の数字を取得
    string n_str = to_string(n);
    ll first = (ll)(n_str.front() - '0');
    ll second = (ll)(n_str.back() - '0');  // n%10 でも OK
    return pll(first, second);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    // input(sunippets: inpv, inpn, inps)
    ll N;
    cin >> N;
    
    // calculation
    // 数字のペアの数を前処理として計算
    map<pll, ll> mp;
    rep1(i, N) {
        pll p = getLeftRightDigit(i);
        mp[p]++;
    }
    
    // 各ペアの集計値の積を足していく：(1, 9), (9, 1)
    ll res = 0;
    for (ll i = 0; i <= 9; i++) {
        for (ll j = 0; j <= 9; j++) {
            pll a(i, j), b(j, i);
            res += mp[a] * mp[b];
        }
    }
    
    cout << res << "\n";
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
const ull MOD = 1000000007;


int main() {
  ull N, K;
  cin >> N >> K;
  ull sum = 0;
  for (ull i = K; i <= N + 1; i++) {
    sum += (N+1-i)*i % MOD;
    sum++;
  }
  cout << sum % MOD << endl;
}


Measured memory_bytes: 3636
# B - Bingo
A = []
for _ in range(3):
    tmp = list(map(int,input().split()))
    A.extend(tmp)
B = [0]*9
N = int(input())
for _ in range(N):
    tmp = int(input())
    for i in range(9):
        if tmp==A[i]:
            B[i] = 1
ans = 'No'
for i,j,k in [(0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6)]:
    if B[i]+B[j]+B[k]==3:
        ans = 'Yes'
print(ans)

Measured memory_bytes: 9052