akhauriyash/Code-Regression huggingface dataset:
// ABC 049 D 連結
#include <algorithm>
#include <complex>
#include <string>
#include <deque>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <queue>
#include <utility>
#include <vector>
#include <map> // for map
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using ll = long long;
using P = pair<int, int>;


struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n, -1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x);y = find(y);
        if (x == y) return false;
        if(d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {return find(x) == find(y);}
    int size(int x) {return -d[find(x)];}

};

int main() {
    int N, K, L;
    cin >> N >> K >> L;
    UnionFind road(N), railway(N);
    rep(i, K) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        road.unite(p, q);
    }
    rep(i, L) {
        int r, s;
        cin >> r >> s;
        r--; s--;
        railway.unite(r, s);
    }

    // copy
    map<pair<int, int>, int> cnt;
    for (int i = 0; i < N; i++){
        cnt[make_pair(road.find(i), railway.find(i))]++;
    }
    for (int i = 0; i < N; i++) {
        if (i >= 1) cout << " ";
        cout << cnt[make_pair(road.find(i), railway.find(i))];
    }
    cout << endl;
    


    return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin >> s >> t;
	int ans = 0;
	for(int i = 0;i<s.length();i++){
        if(s[i]!=t[i]) ans++;
	}
	cout << ans;
return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long double a,b,h,m;
    cin>>a>>b>>h>>m;
    long double ans,x,y,degree;
    x=h*30+m*0.5;
    y=m*6;
    degree=abs(x-y);
    degree=min(degree,360-degree);
    long double PI=3.141592653589793;
    long double rad=degree*PI/180.0;
    ans=sqrt(a*a+b*b-2*a*b*cos(rad));
    cout << std::fixed << std::setprecision(20) << ans << endl;
    cout<<endl;
}

Measured memory_bytes: 4168
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    bool flag = false;
    for (int i = 1; i <= b; ++i) {
        if (a*i % b == c) flag = true;
    }
    if (flag) cout << "YES\n";
    else cout << "NO\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
  int H;
  int W;
  int h;
  int w;
  scanf("%d %d",&H,&W);
  scanf("%d %d",&h,&w);
  int total = H*W;
  int ans = total - w*H	- W*h +	h*w;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
// Ref : https://book.mynavi.jp/ec/products/detail/id=35408

#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
	int key;
	Node *parent, *left, *right;
};

// These pointer adress is NULL until first store (root == NIL).
// NIL adress is permanently NULL for defining empty node.
Node *root, *NIL;

void myInsert(int k) {
	Node *y = NIL; // parent
	Node *x = root; // comparison
	Node *z; // insertion

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}

	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

void inOrderPrint(Node *n) {
	if (n == NIL) return;
	inOrderPrint(n->left);
	cout << " " << n->key;
	inOrderPrint(n->right);
}

void preOrderPrint(Node *n) {
	if (n == NIL) return;
	cout << " " << n->key;
	preOrderPrint(n->left);
	preOrderPrint(n->right);
}

Node * myFind(Node *n, int k) {
	while (n != NIL && n->key != k) {
		if (k > n->key)	n = n->right;
		else n = n->left;
	}
	return n;
}

void myDelete(Node *n) {
	Node *deletion, *children, *parent;

	if (n->left == NIL || n->right == NIL) { // deleted node has 0 or 1 children node. 
		deletion = n;
	}
	else { // deleted node has 2 children node;
		deletion = n->right;
		while (deletion->left != NIL) {
			deletion = deletion->left;
		}
	}

	if (deletion->left != NIL) children = deletion->left;
	else children = deletion->right;

	parent = deletion->parent;
	if (parent == NIL) root = n;
	else if (parent->left == deletion) parent->left = children;
	else parent->right = children;

	if (children != NIL) children->parent = parent;

	if (deletion != n) n->key = deletion->key;

	free(deletion);
}

int main() {
	int n, x;
	char com[7];
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> com;
		if (com[0] == 'i') {
			cin >> x;
			myInsert(x);
		}
		else if (com[0] == 'p') {
			inOrderPrint(root);
			cout << endl;
			preOrderPrint(root);
			cout << endl;
		}
		else if (com[0] == 'f') {
			cin >> x;
			if (myFind(root, x) == NIL) cout << "no";
			else cout << "yes";
			cout << endl;
		}
		else if (com[0] == 'd') {
			cin >> x;
			myDelete(myFind(root, x));
		}
	}

	return 0;
}


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

int main(){
	int n;
	while(cin >> n){
		n %= 39;
		if(!n) n=39;
		if(n>9)cout << "3C" << n << endl;
		else cout << "3C" << 0 << n << endl;
	}
	return 0;
}

Measured memory_bytes: 0
from itertools import combinations_with_replacement
from itertools import combinations
N = int(input())

alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]
cand = {"a"}
for i in range(N-1):
    nex_cand = set()
    for c in cand:
        for j in range(i+2):
            a = alpha[j]
            if all(v in c for v in alpha[:j]):
                nex_cand.add(c+a)
    cand = nex_cand

print("\n".join(sorted(cand)))


Measured memory_bytes: 19476
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <map>
#include <string>
#include <cmath>
using namespace std;

int main(){
  string n;
  cin >> n;
  if(stoi(n)%10==0) {
    cout<<10<<endl;
    return 0;
  }
  int cnt=0;
  string k="";
  for(int i=0;i<n.length();i++){
    k=n.at(i);
    cnt+=stoi(k);
  }
  cout<< cnt <<endl;
  return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int a,b,c=0;
	cin>>a>>b;
	string s;
	cin>>s;
	for0(i,s.size()){ if(s[i]=='-')c++;}
	if(c==1 && s[a]=='-') pf("Yes");
	else pf("No");
	
	return 0;
}

Measured memory_bytes: 256
def merge(p, q):
    result=[]
    i,j=0,0
    #p[i]とq[j]を比べて小さい方をresultに加える。
    while i<len(p) and j<len(q):
        #.appendで加える。小さかった方の数字を一つ進める。
        #これで小さいものから順にresultに加えることができる。
        if p[i] <= q[j]:
            result.append(p[i])
            i+=1
        else:
            result.append(q[j])
            j+=1
    #片方の配列が全て比較済みとなると、そこで上のwhile分は終了してしまう
    #なのでまだ比較していない要素が残っている配列をそのままresultに連結する
    #これは.extendを使う。まだ比較していない要素はスライスで簡単に分けることができる。
    if i<len(p):result.extend(p[i:])
    if j<len(q):result.extend(q[j:])
    #resultを返して終了
    return result

# mergesort(a): 配列 a をマージソートしたものを返す。
def mergesort(a):
    #要素が一つになるまで分割したらそれ自体を返す。
    if len(a)==1:return a
    #最初の半分を切り取ってソート
    p=mergesort(a[:len(a)//2])
    #残りの半分を切り取ってソート
    q=mergesort(a[len(a)//2:])
    #merge関数で連結させる
    return merge(p,q)

N, K = map(int, input().split())
tree_list = mergesort([int(input()) for i in range(N)])

gap = mergesort([tree_list[i+K-1]-tree_list[i] for i in range(N-K+1)])
print(gap[0])


Measured memory_bytes: 12928
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10, PW = 1e9, LST = 1e5;

struct node {
	node* lt[26];
	vector<ll> cnt;
	vector<ll> nds;
	ll cntH = 0;
};

node* rt = new node();

vector<ll> us(26);
void add(string& s, int ind, node* cur, node* par = 0) {
	if (ind == s.size()) {
		par->nds.push_back(s.back() - 'a');
	}
	else {
		if (cur->lt[s[ind] - 'a']) {
			add(s, ind + 1, cur->lt[s[ind] - 'a'], cur);
		}
		else {
			cur->lt[s[ind] - 'a'] = new node();
			add(s, ind + 1, cur->lt[s[ind] - 'a'], cur);
		}
	}
}

void add2(string& s, int ind, node* cur) {
	if (cur->cnt.size() == 0) {
		cur->cnt.resize(26);
	}
	if (ind == s.size() - 1) {
		
	}
	else {
		if (cur->lt[s[ind] - 'a']) {
			add2(s, ind + 1, cur->lt[s[ind] - 'a']);
		}
		else {
			cur->lt[s[ind] - 'a'] = new node();
			add2(s, ind + 1, cur->lt[s[ind] - 'a']);
		}
	}
	if (!us[s[ind] - 'a']) cur->cnt[s[ind] - 'a']++;
	us[s[ind] - 'a'] = 1;
}

void bfs(node* cur, node* par = 0) {
	for (int i = 0; i < 26; i++) {
		if (cur->lt[i]) {
			bfs(cur->lt[i], cur);
		}
	}

	if (par != 0) {
		if (cur->cnt.size() != 26) return;
		for (int i = 0; i < 26; i++) {
			par->cnt[i] += cur->cnt[i];
		}
	}
}

ll ans(node* cur) {
	ll ret = 0;
	for (auto c : cur->nds) {
		ret += cur->cnt[c] - 1;
	}

	for (int i = 0; i < 26; i++) {
		if (cur->lt[i]) ret += ans(cur->lt[i]);
	}

	return ret;
}

int main()
{
	fastInp;

	ll n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		reverse(s.begin(), s.end());
		us.clear();
		us.resize(26);
		add(s, 0, rt);
		add2(s, 0, rt);
	}

	bfs(rt);

	cout << ans(rt);
	return 0;
}

Measured memory_bytes: 541808
#include <bits/stdc++.h>
        using namespace std;
        #define int long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18
 
        bool check(int n,int k){
            while(n%k==0){
                n=n/k;
            }
            return n%k==1;
        }
        
        signed main() {
 
  
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        int n;
        cin>>n;
        int fl=1;
        while(n>0){
            if(n%10==7){
                cout<<"Yes";
                fl=0;
                break;
            }
            n=n/10;
        }
        if(fl)
        cout<<"No";
 
 
        return 0;
    }

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    ll a, b, h, m;
    cin >> a >> b >> h >> m;
    double ra = 2*PI*a, rb = a*PI*b;
    double pa = 2 * PI * (60 * h + m) / (12 * 60) , pb = 2 * PI * m / 60, p = abs(pa - pb);
    double ans = sqrt(pow(a, 2) + pow(b, 2) - 2* a*b*cos(p));
    printf("%.9f\n", ans);
    return 0;
}

Measured memory_bytes: 4192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
#B 
s = input()

kisu = ['R','U','D']
gusu = ['L','U','D']

flg = False

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] in kisu:
            flg = True
        else:
            flg = False
            break
    else:
        if s[i] in gusu:
            flg = True
        else:
            flg = False
            break
                
if flg:
    print('Yes')
    
else:
    print('No')

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

int main(){
  long long l, r;
  cin >> l >> r;
  if(r-l > 3000){
    cout << 0 << endl;
  }else{
    long long res=2018;
    for(long long i=l; i<r; i++){
      for(long long j=i+1; j<=r; j++){
        res = min(res, (i*j)%2019);
      }
    }
    cout << res << endl;
  }
  return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
typedef long long int lli;
typedef pair<int, int> P;

int main() {
    int sx, sy, tx, ty;
    string ans = "";
    cin >> sx >> sy >> tx >> ty;
    // 1週目
    REP(i, tx-sx) {
        ans += "R";
    }
    REP(i, ty-sy) {
        ans += "U";
    }
    REP(i, tx-sx) {
        ans += "L";
    }
    REP(i, ty-sy) {
        ans += "D";
    }
    // 2週目
    ans += "D";
    REP(i, tx-sx+1) {
        ans += "R";
    }
    REP(i, ty-sy+1) {
        ans += "U";
    }
    ans += "L";
    ans += "U";
    REP(i, tx-sx+1) {
        ans += "L";
    }
    REP(i, ty-sy+1) {
        ans += "D";
    }
    ans += "R";
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

	int a,b,k,tmp,i,n;

	n=0;

	scanf("%d%d%d",&a,&b,&k);

	if(a>b)
	{
		tmp=a;
		a=b;
		b=tmp;
	}

	for(i=a; i>=1; i--)
	{
		if((b%i==0)&&(a%i==0)) n=n+1;
		if(n==k)
		{
			printf("%d",i);
			break;
		}
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
// map<int,int> mp;

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

  vector<string> A = { "SUN","MON", "TUE", "WED", "THU", "FRI", "SAT"};
  int ans;
  for (int i = 0; i < 7; i++) {
    if (s == A[i]) ans = 7-i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lowbit(i) ((i)&-(i)) 

using namespace std;

typedef long long ll;

int n;
ll b1[100100],b2[100100];

void add(ll *bit,int i,ll x)
{
	while(i<=n)
	{
		bit[i]+=x;
		i+=lowbit(i);
	}
}

ll sum(ll *bit,int x)
{
	ll s=0;
	while(x>0)
	{
		s+=bit[x];
		x-=lowbit(x);
	}
	return s;
}

void add(ll x,ll y,ll s)
{
	add(b1,x,s);add(b1,y+1,-s);
	add(b2,x,x*s);add(b2,y+1,-(y+1)*s);
}

ll sum(ll x)
{
	return (x+1)*sum(b1,x+1)-sum(b2,x+1);
}

int main()
{
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout); 
	int q;
	scanf("%d%d",&n,&q);
	n+=10;
	memset(b1,0,sizeof(b1));
	memset(b2,0,sizeof(b2));
	for(int i=0;i<q;i++)
	{
		int com;
		scanf("%d",&com);
		if(com==0)
		{
			ll x,y,s;
			scanf("%lld%lld%lld",&x,&y,&s);
			add(x,y,s);
		}
		else
		{
			ll x,y;
			scanf("%lld%lld",&x,&y);
			printf("%lld\n",sum(y)-sum(x-1));
		}
	}
	return 0;
}

Measured memory_bytes: 4756
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
ans = 0
summation = 0
for i in range(n):
    d, c = [int(item) for item in input().split()]
    ans += c
    summation += d * c
print(ans - 1 + summation // 9 - (summation % 9 == 0))

Measured memory_bytes: 3060
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var L=Arr.shift();
for(var i=0;i<L;i++){
   var str=Arr[i];
   str=str.replace(/\-\>/g,"A");
   str=str.replace(/\<\-/g,"Z");
   var m=str.split("");
   var arr=[m[0]];
   var n=1;
   m.forEach(function(v){
      if(v=="A")n++;
      else if(v=="Z")n--;
      else {
         if(n==0){arr.unshift(v);n=1;}
         if(n>arr.length)arr.push(v);
      }
   });
   console.log(arr.join(""));
}

Measured memory_bytes: 9520
import java.util.Scanner;

//How Many Islands?
public class Main{

	static int h;
	static int w;
	static int[][] map;
	
	static int[][] move = {{0,1},{0,-1},{1,0},{-1,0},{1,1},{-1,-1},{1,-1},{-1,1}};
	
	static void dfs(int i, int j){
		map[i][j] = 0;
		for(int k=0;k<8;k++){
			int ni = i+move[k][0];
			int nj = j+move[k][1];
			if(0<=ni&&ni<h&&0<=nj&&nj<w&&map[ni][nj]==1)dfs(ni, nj);
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if((w|h)==0)break;
			map = new int[h][w];
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)map[i][j]=sc.nextInt();
			int c = 0;
			for(int i=0;i<h;i++)
				for(int j=0;j<w;j++)
					if(map[i][j]==1){
						c++;
						dfs(i, j);
					}
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 12000
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
#include <map>
#include <limits>
#include <algorithm>
#include <numeric>

using namespace std;


string _main(int a, int b){
  if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){
    return "Possible";
  }else{
    return "Impossible";
  }
}


int main(int argc, char *argv[])
{
  string line;
  getline(cin, line);
  int a = 0;
  int b = 0;
  istringstream iss(line);
  iss >> a;
  iss >> b;
  cout << _main(a, b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,ans=2e9;
  cin >> n;
  ll a[n],b[n+1];
  b[0]=0;
  for(ll i=0;i<n;i++){
    cin >> a[i];
    b[i+1] = b[i]+a[i];
  }
  for(ll i=1;i<n;i++){
    ans = min(ans,abs(b[n]-2*b[i]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<string.h>

int main(){
  char str[100];
  int judge=0;
  int no_flag=0;
  int len;
  int i=0,j=0;

  scanf("%s",str);

  len=strlen(str);

  for(int i=0;i<len;i++){
    for(int j=0;j<len;j++){
      if(str[i]==str[j]){
        judge++;
      }
    }
    if(judge%2==1){
      no_flag++;
      break;
    }
    judge=0;
  }

  if(no_flag==0)printf("Yes");
  else printf("No");

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
//#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
const lli INF = 1e18L+5;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
void dfs(lli node,lli par,vector<lli> tree[],lli *dp)
{
	
	dp[node]=dp[node]+dp[par];
	//what_is(node);
	for(lli i=0;i<tree[node].size();i++)
	{
		lli child=tree[node][i];
		if(child!=par)
		{
			dfs(child,node,tree,dp);
		}
	}
	
}
int main()
{
//cout.precision(10);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
		lli x,y,n,q,i,j;
		cin>>n>>q;
		vector<lli> tree[n+1];
		for(i=0;i<n-1;i++)
		{
			cin>>x>>y;
			tree[x].pb(y);
			tree[y].pb(x);
		}
		lli dp[n+1]={0};
		for(i=0;i<q;i++)
		{
			cin>>x>>y;
			dp[x]+=y;
		}
		dfs(1,0,tree,dp);
		for(i=1;i<=n;i++)
		cout<<dp[i]<<" ";
	}
}


Measured memory_bytes: 27392
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class abc125b
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var V = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);
        var C = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);

        var X = 0; var Y = 0;
        for(var i = 0; i != N; ++i) {
            if(V[i] > C[i]) {
                X += V[i];
                Y += C[i];
            }
        }
        Console.WriteLine(X - Y);
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define endl '\n'
#define gcd __gcd
#define lcm(a,b) (a*b)/gcd(a,b)
#define inf 0xFFFFFFFF/2
#define uinf 0xFFFFFFFF
#define infl 0xFFFFFFFFFFFFFFFF/2
#define uinfl 0xFFFFFFFFFFFFFFFF
#define TEST int t; cin>>t; while(t--)
#define rep(i,a,b) for(int i=(int)a; i<b; i++)
#define repc(i,a,c) for(int i=(int)a; c; i++)
#define reps(i,a,b,s) for(int i=(int)a; i<b; i+=s)
#define repcs(i,a,c,s) for(int i=(int)a; c; i+=s)
#define repn(i,n)  for(int i=0; i<n; i++)
#define per(i,a,b) for(int i=b; i >= a; i--)
#define linv(a,n)  vector<int> a(n); for(int i=0; i<n; i++) cin>>a[i];
#define linp(a,n)  int arr[n]; for(int i=0; i<n; i++) cin>>a[i];
#define lgenv(t,a,n) vector<t> a(n); for(int i=0; i<n; i++) cin>>a[i];
#define lgenp(t,a,n) t a[n]; for(int i=0; i<n; i++) cin>>a[i];
#define lgeni(t,a,n,v) t a[n]; memset(a, v, (sizeof(a)/sizeof(t)));
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define SZ(x) (x).size()
#define DEBUG_ARR(a,n) for(int i=0; i<n; i++) cerr<<a[i]<<" "; cerr<<endl;
#define PRINT_ARR(a,n) for(int i=0; i<n; i++) cout<<a[i]<<" "; cout<<endl;
#define RD_I(fi) freopen(fi, "r", stdin);
#define RD_O(fo) freopen(fo, "w", stdout);
#define RD_IO(fi,fo) RD_I(fi); RD_O(fo);
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long llu;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector< vector<int> > vvi;

int main()
{
	FIO
	int n;
	cin>>n;
	linv(d,n);
	int m;
	cin>>m;
	linv(t,m);
	map<int, int> hmap;
	repn(i, n)
	{
		if(hmap.find(d[i]) == hmap.end())
			hmap[d[i]] = 1;
		else
			hmap[d[i]]++;
	}
	bool poss = true;
	repn(i,m)
	{
		if(hmap.find(t[i]) == hmap.end())
		{
			poss = false;
			break;
		}
		else if(hmap[t[i]] <= 0)
		{
			poss = false;
			break;
		}
		else
			hmap[t[i]]--;
	}
	cout<<(poss ? "YES" : "NO")<<endl;
	return 0;
}


Measured memory_bytes: 11264
#include<iostream>
using namespace std;
int main(){
	int n,m,c;
	cin >> n >> m >> c;
	int b[m];
	for(int i=0;i<m;i++) cin >> b[i];
	int ans=0;
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=0;j<m;j++){
			int a;
			cin >> a;
			sum+=a*b[j];
		}
		sum+=c;
		if(sum>0) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1127
# クラスカル or プリム法

import math


class UnionFind:
    def __init__(self, n):
        self.n = n
        # 各要素の親要素の番号を格納するリスト
        # 根がルートの時は、グループの要素数を格納　最初は全て根で要素数1
        self.parents = [-1] * n

    # 再帰 groupの根を返す
    # 経路圧縮あり
    def find(self, x):
        # 0より小さい場合は根
        if self.parents[x] < 0:
            # indexを返す
            return x
        else:
            # 根になるまで親を辿る
            # 経路圧縮 根のindexが全ての親に再帰的につく
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # groupを併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        # 最初から統合されている
        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x
        # 根のグループ数を追加 xの方グループの要素数が多い前提なので多い方に寄せる
        self.parents[x] += self.parents[y]
        # 親(根)のindexを入れる
        self.parents[y] = x

    # xのgroupのサイズ
    def size(self, x):
        return - self.parents[self.find(x)]

    # 根が同じか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # ルートが同じ要素を返す
    def members(self, x):
        root = self.find(x)
        # 根が同じ要素
        return [i for i, in range(self.n) if self.find(i) == root]

    # 全ての根の要素を返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を数える 遅い
    def group_count(self):
        return len(self.roots())

    # {root: [要素]}
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


while True:
    n = int(input())
    uf = UnionFind(n)
    if n == 0:
        break
    cell = []
    for _ in range(n):
        x, y, z, r = map(float, input().split())
        cell.append((x, y, z, r))

    edge = []
    for i in range(n):
        for j in range(i + 1, n):
            dis = math.sqrt(
                (cell[i][0] - cell[j][0]) ** 2 + (cell[i][1] - cell[j][1]) ** 2 + (cell[i][2] - cell[j][2]) ** 2)
            #print(dis)
            if dis < (cell[i][3] + cell[j][3]):
                uf.union(i, j)
            else:
                edge.append((dis - (cell[i][3] + cell[j][3]), i, j))
    edge.sort()
    ans = 0
    num = n
    for c, a, b in edge:
        # 同じグループでなかったら統合
        if not uf.same(a, b):
            uf.union(a, b)
            ans += c
            num -= 1
            # グループ数は開催する都市の数になったら終了
            if num == 1:
                break
    print('{:.3f}'.format(ans))


Measured memory_bytes: 6272
//length of the longest path in a directed acyclic graph
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9+5;

int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
   	//dp[i] = true if the first player wins if there are i stones remaining
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin>>a[i];
    bool dp[k+1];
    memset(dp,0,sizeof(dp));
    for(int i = 0; i <= k; i++){
        for(int x: a){
            if(i >= x && !dp[i-x]) dp[i] = true;
        }
    }
    (dp[k])?cout<<"First":cout<<"Second";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#ifdef Rahul
# define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
# define error(...) 42;
#endif
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
int const MOD = 1e9 + 7;
i64 const INF = 1e18 + 42;
/***********************************************************************/
const int N = 1e5 + 42;
vector<int> g[N];
int ans[N];
int32_t main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v; cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<pair<int, int>> q = {{1, -1}};
  for (int i = 0; i < SZ(q); ++i) {
    auto [u, w] = q[i];
    if (ans[u]) continue;
    ans[u] = w;
    for (int v : g[u]) q.push_back({v, u});
  }
  cout << "Yes\n";
  for (int i = 2; i <= n; ++i) {
    cout << ans[i] << '\n';
  }
}


Measured memory_bytes: 14040
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int X = N;
    int S = 0;
    int i = 10;
    while(N > 0){
        S += N%i;
        N /= i;
    }
    if(X%S == 0) cout << "Yes" << endl; 
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int NN=10000 +13;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}

bool checkk(int pos,int a,int b,int k){
	int per=pos/(k+1);
	b-=per;
	a-=pos-per;
	if(a<0||b<0)return false;
	if(b<a)return true;
	if((a+b)/(min(a,b)+1)<=k)return true;
	else return false;
}
int get_split(int a,int b,int k){
	int l=0,r=a+b;
	while(l!=r){
		if(r-l==1){
			if(r%(k+1)==0)
				break;
		}
		int mid=(l+r+1)>>1;
		if(mid%(k+1)==0)mid+=1;
		if(checkk(mid,a,b,k)){
			l=mid;
		}
		else r=mid-1;
	}
	return l;
}
LL a,b;
LL l,r;
void printa(int k,int l,int r){
	for(int i=l;i<=r;++i){
		if(i%(k+1))putchar('A');
		else putchar('B');
	}
}
void printb(int k,int l,int r){
	for(int i=l;i<=r;++i){
		if((a+b-i+1)%(k+1))putchar('B');
		else putchar('A');
	}
}
int main(){
	//freopen("test.in","r",stdin);
	int q=read();
	for(int i=1;i<=q;++i){
		a=read(),b=read(),l=read(),r=read();
		LL k=(a+b)/(min(a,b)+1);
		int p=get_split(a,b,k);
		if(p<l){
			printb(k,l,r);
		}
		else if(p>=r){
			printa(k,l,r);
		}
		else{
			printa(k,l,p);
			printb(k,p+1,r);
		}
		putchar('\n');
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int h, w, n = 0,m=0,f;
  int a[2] = { -1, -1 };
  cin >> h >> w;
  int mp[h][w],v[h*w][4];
  rep(i,h)
    rep(j,w)
      cin>>mp[i][j];
  rep(i,h){
    f=i%2;
    rep(j,w)
    {
      if ((f?mp[i][w-1-j]:mp[i][j])%2) {
        if (a[0] == -1) {
          a[0] = i;
          a[1] = f?w-1-j:j;
        } else {
          a[0]=-1;
          n=m;
        }
      }
      if (a[0] != -1) {
        v[m][0]=a[0]+1;
        v[m][1]=a[1]+1;
        v[m][2]=a[0]+1+(j==w-1);
        v[m][3]=a[1]+1+(j!=w-1?(f?-1:1):0);
        if(j==w-1)
          a[0]++;
        else
          f?a[1]--:a[1]++;
        m++;
      }
    }
  }
  cout << n << endl;
  rep(i,n)printf("%d %d %d %d\n", v[i][0],v[i][1],v[i][2],v[i][3]);
  return 0;
}


Measured memory_bytes: 7040
n, a, b = map(int, input().split())
s = input()

n_all = 0
n_for = 0
for s1 in s:
    if s1 == "a":
        if n_all < a + b:
            print("Yes")
            n_all += 1
        else:
            print("No")
    elif s1 == "b":
        if n_all < a + b and n_for < b:
            print("Yes")
            n_all += 1
            n_for += 1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 4016
#include<map>
#include<set>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define sz(a) ((int)(a).size())
#define vi vector<int>
#define pii pair<int,int>
#define R(a) scanf("%d",&a)
#define per(i,a,b) for(int i=a;i>=int(b);i--)
#define rep(i,a,b) for(int i=a;i<=int(b);i++)
#define rix(i,x) for(int i=last[x];i;i=pre[i])
ll pow(ll a,ll b,ll M){ll t=1;for(a%=M;b;b>>=1){if(b&1)t=t*a%M;a=a*a%M;}return t;}
int gcd(int a,int b){
	return !a?b:gcd(b%a,a);
}
int main(){
	int n,k;cin>>n>>k;int d=0,t=0;
	rep(i,1,n){
		int x;R(x);
		d=gcd(d,x);t=max(t,x);
	}
	if(t>=k&&k%d==0)puts("POSSIBLE");else puts("IMPOSSIBLE");
}


Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    a = I()

    print(a+a**2+a**3)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10104
#include<stdio.h>
#include<string.h>
#define LEN 100005
#define MAX 100000
typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n,m;

void enqueue(P x){
  if (isFull() == 1) printf("??¨?????????????????????????????????\n");
  Q[tail] = x;
	 
  if (tail + 1 == MAX) tail = 0;
  else tail++;
 
}

P dequeue(){
  P x;
  if (isEmpty()==1) printf("??¨???????????¢?????????????????????\n");
  x = Q[head];
  
  if (head + 1 == MAX) head = 0;
  else head++;
  return x;
}

void initialize(){
  head = tail = 0;
      }
int isEmpty(){
  if(head == tail) return 1;
  else return 0;
      }
int isFull(){
  if(head == (tail + 1) % MAX) return 1;
  else return 0;
      }

int main(){
  int elaps = 0, c=0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n+1;
  while(n != 0){
    u =Q[head];
    u.t = Q[head].t - q;
    if(u.t > 0){
      elaps = elaps + q;
      enqueue(u);
      Q[head] = dequeue();
    }
    else {
      elaps = elaps + Q[head].t;
      printf("%s",Q[head].name);
      printf(" %d\n",elaps);
      Q[head] = dequeue();
      n--;
    }
  }
      
    

  
  return 0;
}

Measured memory_bytes: 10756
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

#define NIL (-1)

typedef struct Node {
	int parent;
	int left;
	int right;
} Node;

Node nodes[100000];
int depth[100000] = { 0 };

void setDepth(int idx, int dep)
{
	depth[idx] = dep;

	if (nodes[idx].right != NIL) setDepth(nodes[idx].right, dep);
	if (nodes[idx].left != NIL) setDepth(nodes[idx].left, dep + 1);
}

void printType(int idx)
{
	if (nodes[idx].parent == NIL) cout << "root, ";
	else if (nodes[idx].left == NIL) cout << "leaf, ";
	else cout << "internal node, ";
}

void printChildren(int idx)
{
	int left = nodes[idx].left;

	if (left == NIL) cout << "[]" << endl;
	else {
		cout << '[' << left;

		while (nodes[left].right != NIL) {
			left = nodes[left].right;
			cout << ", " << left;
		}

		cout << ']' << endl;
	}
}

void printTree(int n)
{
	rep(i, n) {
		printf("node %d: parent = %d, depth = %d, ", i, nodes[i].parent, depth[i]);
		printType(i);
		printChildren(i);
	}
}

int main()
{
	int n, id, k, c, pc, root;

	cin >> n;

	rep(i, n) {
		nodes[i].parent = NIL;
		nodes[i].left = NIL;
		nodes[i].right = NIL;
	}

	rep(i, n) {
		cin >> id >> k;
		rep(j, k) {
			cin >> c;
			nodes[c].parent = id;
			if (j == 0) nodes[id].left = c;
			else nodes[pc].right = c;
			pc = c;
		}
	}

	rep(i, n) if (nodes[i].parent == NIL) root = i;

	setDepth(root, 0);
	printTree(n);

	return 0;
}


Measured memory_bytes: 7820
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N, M;
    cin >> N >> M;
    lint A[N];
    cins(A, A + N);
    pair<lint, lint> CB[M];
    for(int i = 0; i < M; i++){
        cin >> CB[i].second >> CB[i].first;
    }
    sort(A, A + N);
    sort(CB, CB + M, greater<>());
    int now = 0;
    for(auto i: CB){
        lint C = i.first, B = i.second;
        while(now < N && B){
            A[now] = max(A[now], C);
            now++, B--;
        }
    }
    lint ans = 0;
    for(int i = 0; i < N; i++){
        ans += A[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
import java.util.*;

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

      int n = Integer.parseInt(sc.next());

      int[] L = new int[n];
      for(int i=0;i<n;i++){
        L[i] = Integer.parseInt(sc.next());
      }

      Arrays.sort(L);

      int cnt = 0;

      for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
          for(int k=j+1;k<n;k++){
            boolean a = (L[i]<(L[j]+L[k]));
            boolean b = (L[j]<(L[k]+L[i]));
            boolean c = (L[k]<(L[i]+L[j]));
            if(a && b && c){
              cnt++;
            }
            int sa1=0;
            if(!a){
              sa1 = L[i]-L[j]-L[k];
            }
            i += sa1;
            if(j>=n-1 || i>=n-2){
              break;
            }
          }
          if(i>=n-2){
            break;
          }
        }
      }


      System.out.println(cnt);

    }
}


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

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  map<string, int>m;
  rep(i, n){
    string s;cin>>s;
    m[s]++;
  }
  cout<<"AC x "<<m["AC"]<<endl;
  cout<<"WA x "<<m["WA"]<<endl;
  cout<<"TLE x "<<m["TLE"]<<endl;
  cout<<"RE x "<<m["RE"]<<endl;

  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int n; cin >> n;
    map<string, int> mp;
    while(n--)
    {
        string s; cin >> s;
        mp[s]++;
    }

    int mx = 0;
    for(auto [_, c] : mp) mx = max(mx, c);
    for(auto [s, c] : mp) if(c == mx) cout << s << endl;
    
    return 0;
}

Measured memory_bytes: 19200
;;; body

(defun solve (n k x)
  (flet ((calc-dist (i-left i-right)
           (min (+ (abs i-left) (abs (- i-right i-left)))
                (+ (abs i-right) (abs (- i-right i-left))))))
    (if (= n 1)
        (abs (aref x 0))
        (reduce #'min 
                (loop for i below (1+ (- n k)) collect
                     (calc-dist (aref x i)
                                (aref x (1- (+ i k)))))))))

(defun main ()
  (let ((n (read))
        (k (read)))
    (let ((x (make-array n
                         :initial-contents (loop repeat n collect (read)))))
      (princ (solve n k x))
      (fresh-line))))

#-swank (main)


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

typedef long long ll;
const int maxn = 200010;
int n, a[maxn], lst[maxn], nxt[maxn], fir[maxn], f[maxn];
ll k; bool used[maxn];
vector<int> b, V;

int main() {
    scanf("%d %lld", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if (!fir[a[i]]) fir[a[i]] = i;
    }
    for (int i = n; i; i--) {
        nxt[i] = lst[a[i]], lst[a[i]] = i;
    }
    for (int i = n; i; i--) {
        if (!nxt[i]) f[i] = fir[a[i]] + 1;
        else f[i] = f[nxt[i] + 1];
    }
    b.push_back(1);
    while (b.back()) {
        b.push_back(f[b.back()]);
    }
    b.pop_back();
    int cur = b[(k - 1) % b.size()];
    for (int i = max(1, cur); i <= n; i++) {
        if (!used[a[i]]) {
            V.push_back(a[i]), used[a[i]] = 1;
        } else {
            while (used[a[i]]) used[V.back()] = 0, V.pop_back();
        }
    }
    for (int x : V) printf("%d ", x);
    return 0;
}

Measured memory_bytes: 7284
import copy
N = int(input())
output = []
dic = {}
A = []

for i in range(N):
  num = int(input())
  A.append(num)
  dic[i] = num

A = sorted(A)
max_1 = A[-1]
max_2 = A[-2]

for i in range(N):
  tmp = dic[i]
  if tmp == max_1:
    output.append(max_2)
  else:
    output.append(max_1)
print(*output, sep="\n")

Measured memory_bytes: 36360
def big_one_multiply(A, b):
  carry = 0
  M = []
  for i in range(len(A)):
    x = int(A[-i-1]) * int(b) + carry
    M.insert(0, x % 10)
    carry = x // 10
  if carry > 0:
    M.insert(0, carry)
  return M

def big_big_plus(A, B):
  carry = 0
  S = []
  if len(A) > len(B):
    B = [0] * (len(A) - len(B)) + B
  elif len(A) < len(B):
    A = [0] * (len(B) - len(A)) + A
  for i in range(len(A)):
    x = int(A[-i-1]) + int(B[-i-1]) + carry
    S.insert(0, x % 10)
    carry = x // 10
  if carry > 0:
    S.insert(0, carry)
  return S
    

tmp = input().split(" ")
A = list(tmp[0])
B = list(filter(lambda n: n != ".", list(tmp[1])))

ans = [0]
for i in range(len(B)):
  ans = big_big_plus(ans, big_one_multiply(A, B[-i-1]) + [0] * i)

z = "".join([str(n) for n in ans[:-2]])
w = ""
flag = False
for i in range(len(z)):
  if z[i] != "0" or flag:
    w += z[i]
    flag = True
    
print(w) if w else print(0)

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

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,r) RFOR(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define lower(a,x) lower_bound(all(a), x) - a.begin();
#define COUNT(a,x)  upper_bound(all(a), x) - lower_bound(all(a), x);
#define MCOUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x);
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end());
#define scan(x) scanf("%lld",&x);
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 5555555555555555555;
const ll mod = 1000000007;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

ll cou[33];
int main(void) {
  cin >> n >> m;
  ll two = 0, one = 0, four = n * m;
  if (n % 2 == 1) {
	four -= m;
	two += m;
  }
  if (m % 2 == 1) {
	four -= n;
	two += n;
  }
  if (n % 2 == 1 && m % 2 == 1) {
	one++;
	two -= 2;
	four++;
  }
  rep(i, n) rep(j, m) {
	char c;
	cin >> c;
	cou[c - 'a']++;
  }
  //cout << four << " " << two << " " << one << endl;
  four /= 4; two /= 2;
  rep(i, 33) {
	if (four == 0) break;
	tmp = cou[i] / 4;
	four -= tmp;
	cou[i] -= tmp * 4;
  }
  rep(i, 33) {
	if (two == 0) break;
	tmp = cou[i] / 2;
	two -= tmp;
	cou[i] -= tmp * 2;
  }

  if (four == 0 && two == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
def bubble_sort(a, n):
    for i in range(n):
        for j in range(n - 1, i, -1):
            if a[j]['value'] < a[j - 1]['value']:
                tmp = a[j]
                a[j] = a[j - 1]
                a[j - 1] = tmp


def selection_sort(a, n):
    is_stable = True

    for i in range(n):
        minj = i
        samei = n
        for j in range(i+1, n, 1):
            if a[j]['value'] == a[i]['value']:
                samei = j
            if a[j]['value'] < a[minj]['value']:
                minj = j
                if samei < minj:
                    is_stable = False
        tmp = a[i]
        a[i] = a[minj]
        a[minj] = tmp

    return is_stable

def print_list_split_whitespace(a):
    for x in a[:-1]:
        print(x['design'] + str(x['value']), end=' ')
    print(a[-1]['design'] + str(a[-1]['value']))


n = int(input())

a = input().split()
for i in range(n):
    s = a[i]
    a[i] = {'design': s[0], 'value': int(s[1])}
b = a.copy()
c = a.copy()

bubble_sort(a, n)
print_list_split_whitespace(a)

print("Stable")

is_stable = selection_sort(b, n)
print_list_split_whitespace(b)

if is_stable:
    print("Stable")
else:
    print("Not stable")


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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int X;
  cin >> X;
  int A;
  cin >> A;
  int B;
  cin >> B;
  cout << (X - A) % B << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <utility>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
	int y, m, d;
	char sep1, sep2;
	cin >> y >> sep1 >> m >> sep2 >> d;

	bool is_tbd = false;
	if (y == 2019 && m >= 5) {
		is_tbd = true;
	}
	if (y >= 2020) {
		is_tbd = true;
	}

	if (is_tbd) {
		cout << "TBD" << endl;
	}
	else {
		cout << "Heisei" << endl;
	}

	return 0;
}


Measured memory_bytes: 256