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

int H, W;
int MAX = 0; //最大値
char S[20][20];

int dh[4] = {-1, 0, 1, 0 };  //移動方向(縦)
int dw[4] = {0, -1, 0, 1};  //移動方向(横)


int dist(int h, int w){
  int Max = 0;
  vector<vector<int>> d(20, vector<int>(20, -1));  //d[i][j] = (i,j)までの最大距離
  queue<P> q;
  d[h][w] = 0;  //開始地点は0
  q.push({h, w});

  while(!q.empty()){
    P p = q.front(); q.pop();
    int th = p.first; int tw = p.second;  //キュー内の座標
    Max = max(Max, d[th][tw]);  //現在位置は移動可能位置...最大値更新
    
    for(int i = 0; i < 4; i++){
      int sh = th + dh[i]; int sw = tw + dw[i];
      if(sh < 0 || sh >= H || sw < 0 || sw >= W) continue;
      if(S[sh][sw] == '#') continue;
      if(d[sh][sw] < 0){  //訪れたことがない場所は最短距離
        d[sh][sw] = d[th][tw] + 1;
        q.push({sh, sw});  //next
      }
    }
  }

  return Max;
  
}


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

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++) cin >> S[i][j];
  }
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(S[i][j] == '#') continue;
      MAX = max(MAX, dist(i, j));
    }
  }

  cout << MAX << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long a=sc.nextLong();
long b=sc.nextLong();
long l=lcm(a,b);
System.out.println(l);


}
public static long lcm(long a,long b)
{
return (a*b)/gcd(a,b);
}
public static long gcd(long a,long b)
{
if(a==0)
return b;
return gcd(b%a,a);
}
}



Measured memory_bytes: 21844
// 解説に従い実装

#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll N, A;

bool check(ll time) {
    if (time >= N) return true;

    FOR(cookie_eat_num, 1, 41) {
        ll remain_time = time - A * cookie_eat_num;

        // 例えばクッキーを2回食べる場合
        // クッキーが増えるのを待っている時間をt1, t2, t3とする。
        // ここでt1 + t2 + t3 == remain_time
        // t経過後に生成されるクッキーの量はt1*t2*t3である
        // クッキーの量を最大になるためには、
        // t1, t2, t3がなるべく等しい整数になるように分割する
        ll division_num = cookie_eat_num + 1;
        if (division_num > remain_time) break;

        ll base = remain_time / division_num;
        ll add_one = remain_time - base * division_num;
        ll cookie_num = 1;
        REP(d, division_num) {
            cookie_num *= (base + (add_one > 0));
            --add_one;
            if (cookie_num >= N) return true;
        }
    }
    return false;
}

int main(void)
{
    cin.sync_with_stdio(false);
    cin >> N >> A;

    ll lo = 0;
    ll hi = N;
    while (lo < hi) {
        ll k = (lo + hi) / 2;
        if (check(k)) hi = k;
        else lo = k + 1;
    }
    cout << lo << endl;
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int A = 0;
    int tmp;
    for(int i = 0; i < 3; i++){
        cin >> tmp;
        A += tmp;
    }
    if (A < 22) cout << "win" << endl;
    else cout << "bust" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100005;
int a[N], cnt[N * 2];
long long id[N * 2];
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	long long init = 0;
	for (int i = 1; i < n; i++)
	{
		int l = a[i], r = a[i + 1];
		if (l > r)
			r += m;
		init += r - l;
		if (l + 1 < r)
		{
			cnt[l + 1]++;
			cnt[r + 1]--;
			id[l + 1] += l;
			id[r + 1] -= l;
		}
	}
	for (int i = 1; i <= m * 2; i++)
	{
		cnt[i] += cnt[i - 1];
		id[i] += id[i - 1];
	}
	long long ans = init;
	for (int i = 1; i <= m; i++)
	{
		long long now = init - 1ll * cnt[i] * i + id[i] + cnt[i] - 1ll * cnt[i + m] * (i + m) + id[i + m] + cnt[i + m];
		ans = min(ans, now);
	}
	cout << ans << endl;
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
ll r,c;

vector<string> arr;
ll visit2[100][100];
void dfs(ll i,ll j)
{
    if(i+1<r)
    {
        if((visit2[i][j]+1<visit2[i+1][j])&&arr[i+1][j]=='.')
        {
            visit2[i+1][j]=visit2[i][j]+1;
            dfs(i+1,j);
        }
    }
    if(i-1>=0)
    {
        if((visit2[i][j]+1<visit2[i-1][j])&&arr[i-1][j]=='.')
        {
            visit2[i-1][j]=visit2[i][j]+1;
            dfs(i-1,j);
        }
    }
    if(j+1<c)
    {
        if((visit2[i][j]+1<visit2[i][j+1])&&arr[i][j+1]=='.')
        {
            visit2[i][j+1]=visit2[i][j]+1;
            dfs(i,j+1);
        }
    }
    if(j-1>=0)
    {
        if((visit2[i][j]+1<visit2[i][j-1])&&arr[i][j-1]=='.')
        {
            visit2[i][j-1]=visit2[i][j]+1;
            dfs(i,j-1);
        }
    }
    return;
}
void solve()
{
    cin>>r>>c;
    //arr.assign(r,"");
    arr=vector<string>(r,"");
    fr(i,0,r)
    {
        cin>>arr[i];
    }
    ll ct=0;
    fr(i,0,r)
    {
        fr(j,0,c)
        {
            visit2[i][j]=inf;
            if(arr[i][j]=='.')
            {
                ct++;
            }
        }
    }
    //visit2=vector<VL>(r,VL(c,inf));
    visit2[0][0]=1;
    if(arr[0][0]=='#'||arr[r-1][c-1]=='#')
    {
        cout<<"-1\n";
        return;
    }
    dfs(0,0);
    if(visit2[r-1][c-1]==inf)
    {
        cout<<"-1\n";
    }
    else
    {
        cout<<ct-visit2[r-1][c-1]<<endl;
    }
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3920
from fractions import gcd

N, M = map(int, input().split())
S = input()
T = input()


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


n = N // gcd(N, M)
m = M // gcd(N, M)

for i in range(gcd(N, M)):
    if S[i * n] != T[i * m]:
        print("-1")
        break
else:
    print(lcm(N, M))


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

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

Measured memory_bytes: 3564
while (n = gets.to_i) != 0
  max = 0
  amax = -100000
  temp = 0
  n.times do
    a = gets.to_i
    if a > amax
      amax = a
    end
    if temp + a > 0
      temp += a
      if temp > max
        max = temp
      end
    else
      temp = 0
    end
  end
  if amax > 0
    puts max
  else
    puts amax
  end
end

Measured memory_bytes: 6096
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int maxhapiness(int a[],int b[],int c[],int n)
    {
        int dp[n+1][3]={-1},i;   
        dp[0][0]=a[0];
        dp[0][1]=b[0];
        dp[0][2]=c[0];
        for(i=1;i<n;i++)
            {
                      dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
                      dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
                      dp[i][2]=max(dp[i-1][1]+c[i],dp[i-1][0]+c[i]);
            }
        return max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    }


int main()
{
        int a[100001],b[100001],c[100001],i,n;
        cin >> n; 
        for(i=0;i<n;i++)
            {
                cin >> a[i] >> b[i] >> c[i]; 
            }
        cout << maxhapiness(a,b,c,n);
    return 0;
}



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

using namespace std;
using ll = long long;

static int table[300][600][301];

ll solve(vector<string> field){
	const int n = field.size(), m = field[0].size();
	for(int i = 0; i < n; ++i){ field[i] += string(n, '.'); }
	const int max_k = min(n, m);
	for(int k = 0; k < max_k; ++k){
		for(int x = 0; x < n + m; ++x){
			for(int y = 0; y < n; ++y){ table[k][x][y] = 0; }
		}
	}
	for(int k = 0; k < max_k; ++k){
		for(int x = 0; x < n + m; ++x){
			for(int y = 0; y < n; ++y){
				const int i0 = y, i1 = y + k;
				const int j0 = x - i0, j1 = x - i1;
				if(i1 >= n || j1 < 0){ continue; }
				if(field[i0][j0] != '#'){ continue; }
				if(field[i1][j1] != '#'){ continue; }
				table[k][x][y] += 1;
			}
		}
	}
	for(int k = 0; k < max_k; ++k){
		for(int x = 0; x < n + m; ++x){
			int acc = 0;
			for(int i = 0; i < n; ++i){
				const int t = table[k][x][i];
				table[k][x][i] = acc;
				acc += t;
			}
			table[k][x][n] = acc;
		}
	}
	ll answer = 0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			if(field[i][j] != '#'){ continue; }
			for(int k = 0; k < max_k; ++k){
				const int y = i, x = j + i + k * 2;
				if(x >= n + m){ continue; }
				answer += table[k][x][min(n, i + k)];
				answer -= table[k][x][y];
			}
		}
	}
	return answer;
}

vector<string> rotate(const vector<string>& a){
	const int n = a.size(), m = a[0].size();
	vector<string> b(m, string(n, ' '));
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			b[j][i] = a[i][m - 1 - j];
		}
	}
	return b;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<string> field(n);
	for(int i = 0; i < n; ++i){ cin >> field[i]; }
	ll answer = 0;
	answer += solve(field);
	field = rotate(field);
	answer += solve(field);
	field = rotate(field);
	answer += solve(field);
	field = rotate(field);
	answer += solve(field);
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 212224
/************************************
	Name: 荆国浩 
	E-mail: 1839714778@qq.com 
************************************/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stdio.h>
#include <fstream>
#include <stack>
#define rep(N) for(int i=0;i<N;i++)
#define pii pair<int,int>
#define For(I,N) for(int I=0;I<N;I++)
#define mp make_pair
typedef unsigned long long ull;
using namespace std;
vector <pair<int,int> >vec[100005];
ull dist[100005];
bool visit[100005];

void dfs(int x)
{
	queue<pair<ull,ull> >que;
	que.push(mp(x,0));
	while(!que.empty())
	{
//		cout<<1<<endl;
		ull nx=que.front().first;
		ull ns=que.front().second;
		que.pop();
		rep(vec[nx].size())
		{
			if(visit[vec[nx][i].first]) continue;
			visit[vec[nx][i].first]=true;
			dist[vec[nx][i].first]=ns+vec[nx][i].second;
			que.push(mp(vec[nx][i].first,dist[vec[nx][i].first]));
		}
	}
	dist[x]=0;
}

int main()
{
//	freopen("input.txt","r",stdin);
	ull n,x,y,z;
	cin>>n;
	rep(n-1)
	{
		cin>>x>>y>>z;
		vec[--x].push_back(mp(--y,z));
		vec[y].push_back(mp(x,z));
	}
	ull q,k;
	cin>>q>>k;
	dfs(--k);
//	rep(n)
//	{
//		cout<<dist[i]<<' ';
//	}
//	cout<<endl;
	rep(q)
	{
		cin>>x>>y;
		cout<<dist[--x]+dist[--y]<<endl;
	}
	return 0;
}

Measured memory_bytes: 9600
#include<cstdio>
#include<cmath>
using namespace std;
int h[100001];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",h+i);
    }
    h[1]--;
    for(int i=2;i<=n;i++){
        if(h[i]<h[i-1]){
            printf("No\n");
            return 0;
        }else if(h[i]>h[i-1]){
            h[i]--;
        }
    }
    printf("Yes\n");
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  //input output template
  /*
  int N;
  cin >> N;
  cout << "Hello, world!" << endl;
  */
  
  int num;
  cin >> num;
  
  long long ans=0;
  
  for(int i=1;i<=num;i++){
    if(i % 3 == 0) continue;
    if(i % 5 == 0) continue;
    ans += (long long)i;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string w;
    cin >> w;
    string res = "Yes";
    rep(i,w.size()){
        char target = w.at(i);
        int64_t count = 0;
        rep(j,w.size()){
            if(w.at(j) == target) count++;
        }
        if(count%2){
            res = "No";
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cctype>
#include <cstdio>
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;
using namespace std;
#define rep(i, n) for(i64 i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(i64 i = m;i < n;i++)
#define SORT(x) sort(x.begin(),x.end())
#define REVE(x) reverse(x.begin(),x.end())
#define all(x) (x).begin(),(x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(),x.end(),x.begin() ,::toupper);
#define down(x) transform(x.begin(),x.end(),x.begin() ,::tolower);
using LL = long long;
using ULL = unsigned long long;
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(){
    i64 n,k,l,a,b,c;
    string aa, bb, cc;
    cin >> n >> a >> b;
    cout << (n * a > b ? b : n * a);

}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	
	int n;
	cin >> n;
	vector<int> a(n);
	int mi = 10000000, mx = -10000000;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		mi = min(mi, a[i]);
		mx = max(mx, a[i]);
	}
	long long ans = LLONG_MAX;
	for(int i = mi; i <= mx; i++) {
		long long tmp = 0;
		for(int j = 0; j < n; j++) {
			tmp += (i - a[j]) * (i - a[j]);
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int count=0;
		for (int i = 1; i < n+1; i++) {
			count += i;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
$stdin.each do |s|
  n = nil
  (?0..?9).each do |x|
    res = s.gsub("X", x)
    a, b, c = res.split(/[^\d]/).map(&:to_i)
    if a + b == c && !res[/(\D|^)0\d/]
      n = x
      break
    end
  end
  if n
    puts n
  else
    puts "NA"
  end
end

Measured memory_bytes: 6120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,t,p;
    cin>>n;
    long long int ara[n];
    string s[n],x;
    for(i=0;i<n;i++){
        cin>>s[i]>>ara[i];
    }
    cin>>x;
    for(i=0;i<n;i++){
        if(x==s[i]){
            p=i;break;
        }
    }
    long long int su=0;
    for(i=i+1;i<n;i++){
        su+=ara[i];
    }
    cout<<su<<endl;
}


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cout << #a << " = " << a << endl

const ll inf = 1e15;
const ll mod = 1e9+7;

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

ll N, C;

ll solve(vector<ll> x, vector<ll> v) {
    vector<ll> S(N, 0);
    S[0] = v[0];
    FOR(i, 1, N) S[i] = S[i-1] + v[i];
    REP(i, N) S[i] -= x[i];
    
    vector<ll> T(N, 0); 
    T[N-1] = v[N-1];
    RREP(i, N-2) T[i] = T[i+1] + v[i];
    RREP(i, N-1) T[i] -= (C - x[i]);
    RREP(i, N-2) T[i] = max(T[i], T[i+1]);
    
    ll res = 0;
    REP(i, N) {
        ll val = 0;
        
        val += S[i];
        res = max(res, val);
        
        val -= x[i];
        if (i != N-1) val += T[i+1];
        
        res = max(res, val);
    }
    return res;
}

int main() {
    cin >> N >> C;
    vector<ll> x(N), v(N); REP(i, N) cin >> x[i] >> v[i];
    
    ll ans = 0;
    ans = max(ans, solve(x, v));
    
    reverse(ALL(x));
    REP(i, N) x[i] = C - x[i];
    reverse(ALL(v));
    
    ans = max(ans, solve(x, v));
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#define N 100000
#define NIL -1

typedef struct{
  int p;
  int l;
  int r;
} Node_t;

Node_t T[N];
int n,D[N];

void setDep(int u,int p){
  D[u]=p;
  if(T[u].r!=NIL) setDep(T[u].r,p);
  if(T[u].l!=NIL) setDep(T[u].l,p+1);
}

int main(){
int i,j=0,id,k,c,l,r,op;
scanf("%d",&n);

for(i=0;i<n;i++){
  T[i].p=T[i].l=T[i].r=NIL;
}

for(i=0;i<n;i++){
  scanf("%d%d",&id,&k);
  for(j=0;j<k;j++){
    scanf("%d",&c);
    if(j==0) T[id].l=c;
    else T[l].r=c;
    l=c;
    T[c].p=id;
    }
  }

for(i=0;i<n;i++){
  if(T[i].p==NIL) r=i;
  }

  setDep(r,0);

  for(i=0;i<n;i++){ //??????
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,D[i]);
    if(T[i].p == NIL) printf("root, ");
    else if(T[i].l == NIL) printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    for(j=0,op=T[i].l; op != NIL; j++, op = T[op].r){
      if(j) printf(", ");
      printf("%d",op);
    }
    /*op=T[i].l;//?????????????????¨???
    while(op!=NIL){
      if(j) printf(", ");
      printf("%d",op);
      op=T[op].r;
      j++;
    }*/
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 5296
N,M = map(int, input().split())
cnt = [0] * (N + 1)
for _ in range(M):
    a,b = map(int, input().split())
    cnt[a] += 1
    cnt[b] += 1

flag = True if all(c % 2 == 0 for c in cnt) else False

if flag:
    print('YES')
else:
    print('NO')

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n,m;
    while (cin >> n >> m) {
        set<int> ac; map<int,int> wa; 
        FOR(i,0,m) {
            int p; string s; cin >> p >> s;
            if (in_(p,ac))
                continue;
            if (s == "AC")
                ac.insert(p);
            else
                wa[p]++;
        }
        int pen = 0;
        FOR_ALL(i,wa) if (in_(i->first,ac))
            pen += i->second;
        cout << ac.size() << " " << pen << endl;
    }
    return 0;
}


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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 300;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, d;
    cin >> n >> d;
    ll a[n];
    rep(i, 0, n)
        cin >> a[i];
    ll pref[n + 1], suff[n + 1];
    pref[0] = d;
    rep(i, 0, n)
        if (a[i] >= pref[i] * 2)
            pref[i + 1] = pref[i];
        else if (a[i] >= pref[i])
            pref[i + 1] = a[i] - pref[i];
        else
            pref[i + 1] = pref[i] - a[i];
    suff[n] = 1;
    repb(i, n - 1, -1)
        if (a[i] >= suff[i + 1] * 2)
            suff[i] = suff[i + 1];
        else
            suff[i] = suff[i + 1] + a[i];
    int q;
    cin >> q;
    rep(i, 0, q)
    {
        int x;
        cin >> x;
        x--;
        if (pref[x] >= suff[x + 1])
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}


Measured memory_bytes: 13696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long pwr = 1;
		for (int i = 1; i <= n; i++) {
			pwr = pwr * i % 1000000007;
		}
		System.out.println(pwr);
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

int D;
vector<int> c(26);
vector<vector<int>> s;
vector<int> spa(26,0);//経過日数
vector<int> t;
vector<set<int>> schedule(26);//各コンテストが何日目に開催されるか
ll contest(int day,int x){//day日にコンテストxを開催した時の満足度の増加量 1-indexed
    ll now=s.at(day-1).at(x-1);
    rep(i,26){
        if(i==x-1){
            spa.at(i)=0;
            continue;
        }
        spa.at(i)++;
        now-=spa.at(i)*c.at(i);
    }
    return now;
}

int main() {
    std::chrono::system_clock::time_point  start, end; // 型は auto で可
 start = std::chrono::system_clock::now();

    cin>>D;
    rep(i,26)cin>>c.at(i);
    s.resize(D,vector<int>(26));
    rep(i,D)rep(j,26){cin>>s.at(i).at(j);}
    t.resize(D);

    //rep(i,D)cin>>t.at(i);
    rep(i,D){
        t.at(i)=rand()%26+1;
    }

    rep(i,26){
        schedule.at(i).insert(0);
    }
    rep(i,D){
        schedule.at(t.at(i)-1).insert(i+1);
    }
    rep(i,26){
        schedule.at(i).insert(D+1);
    }
    ll ans=0;
    rep(i,D){
        ans+=contest(i+1,t.at(i));
        //cout<<ans<<endl;問題A用
    }
    //改善前のansがもとまっている

    double elapsed;
    
    while(elapsed<1800){//時間が許す限り
        int d,q;
        //cin>>d>>q;
        d=rand()%D+1;
        q=rand()%26+1;
        ll oldans=ans;

        int x=t.at(d-1);
        t.at(d-1)=q;
        int bx,nx;
        auto p=lower_bound(schedule.at(x-1).begin(),schedule.at(x-1).end(),d);
        p--;
        bx=*p;
        p++;p++;
        nx=*p;
        schedule.at(x-1).erase(d);
        int bq,nq;
        auto itr=lower_bound(schedule.at(q-1).begin(),schedule.at(q-1).end(),d);
        nq=*itr;
        itr--;
        bq=*itr;
        schedule.at(q-1).insert(d);
        ans+=s.at(d-1).at(q-1)-s.at(d-1).at(x-1);
        ans+=(d-bq)*(nq-d)*c.at(q-1);
        ans-=(d-bx)*(nx-d)*c.at(x-1);
        //cout<<ans<<endl;
        if(ans<oldans){
            schedule.at(x-1).insert(d);
            schedule.at(q-1).erase(d);
            ans=oldans;
        }
        end = std::chrono::system_clock::now();  // 計測終了時間
        elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
    }
    rep(i,D){
        cout<<t.at(i)<<endl;
    }
}

Measured memory_bytes: 3932
/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#ifndef ONLINE_JUDGE
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#else
#define DBG(x)
#define endl "\n"
#endif

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;

int calc(string s1,string s2)
{
    int ans = 0;
    for(int i=0;i<(int)s1.size();i++)
        ans += (s1[i]!=s2[i]);

    return ans;
}

int main()
{
    optimizeIO();

    string s,t;
    cin>>s>>t;

    int slen = s.size();
    int tlen = t.size();

    int mn = INT_MAX;

    for(int i=0;i<slen-tlen+1;i++)
    {
        string temp = s.substr(i,tlen);
        DBG(temp);
        mn = min(mn,calc(s.substr(i,tlen),t));
    }

    cout<<mn<<endl;



    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
//#include <vector>
#include <string>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main(){
  string str;
  cin >> str;
  int count = 0;

  for(int i = 0;i < str.size();i++){
    if(str.substr(i,1) == "x")count++;
  }

  if(count > 7)cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 256
import decimal,math
from collections import Counter,defaultdict
from fractions import gcd
from bisect import bisect_right,bisect_left
decimal.getcontext().prec = 10
s=raw_input()
res=1
pre=s[0]
cur=""
for i in range(1,len(s)):
	cur=cur+s[i]
	if(cur!=pre):
		res=1+res
		pre=cur
		cur=""
	# print cur,pre	
print res

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

using namespace std;

const int maxn = 4010,inf = 0x7fffffff;
int n,k,head[maxn],to[maxn],nextt[maxn],tot = 1,ans = inf;

struct node
{
    int x,y;
}e[maxn];

void add(int x,int y)
{
    to[tot] = y;
    nextt[tot] = head[x];
    head[x] = tot++;
}

namespace task2
{
    int res;

    void dfs(int u,int fa,int len,int limit)
    {
        if (len > k / 2)
            res++;
        for (int i = head[u];i;i = nextt[i])
        {
            int v = to[i];
            if (v == fa || v == limit)
                continue;
            dfs(v,u,len + 1,limit);
        }
    }

    void solve2(int x,int y)
    {
        res = 0;
        dfs(x,0,0,y);
        dfs(y,0,0,x);
        ans = min(ans,res);
    }

    void solve()
    {
        for (int i = 1; i < n; i++)
            solve2(e[i].x,e[i].y);
    }
}

namespace task1
{
    int res;

    void dfs(int u,int fa,int len)
    {
        if (len > k / 2)
            res++;
        for (int i = head[u];i;i = nextt[i])
        {
            int v = to[i];
            if (v == fa)
                continue;
            dfs(v,u,len + 1);
        }
    }

    void solve()
    {
        for (int i = 1; i <= n; i++)
        {
            res = 0;
            dfs(i,0,0);
            ans = min(ans,res);
        }
    }
}

int main()
{
    scanf("%d%d",&n,&k);
    for (int i = 1; i < n; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        e[i].x = x,e[i].y = y;
        add(x,y);
        add(y,x);
    }
    if (k % 2 == 0)
        task1::solve();
    else
        task2::solve();
    printf("%d\n",ans);

    return 0;
}


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

#define fst() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define endl '\n'
typedef long long ll;

string s[55];
int dist[55][55];
int main()
{
  fst();
  int h,w,i,j,x,y,c=0;
  cin>>h>>w;
  f(i,0,h)
  {
    cin>>s[i];
    f(j,0,w)
    {
      if(s[i][j]=='.') c++;
    }
  }
  f(i,0,h)
  {
    f(j,0,w) dist[i][j]=-1;
  }
  dist[0][0]=1;
  queue<pair<int,int> > q;
  q.push({0,0});
  pair<int,int> p;
  while(!q.empty())
  {
    p=q.front();
    x=p.first,y=p.second;
    //cout<<x<<" "<<y<<" "<<dist[x][y]<<endl;
    q.pop();
    if(x>0 && s[x-1][y]=='.' && dist[x-1][y]==-1) dist[x-1][y]=dist[x][y]+1,q.push({x-1,y});
    if(x<h-1 && s[x+1][y]=='.' && dist[x+1][y]==-1) dist[x+1][y]=dist[x][y]+1,q.push({x+1,y});
    if(y>0 && s[x][y-1]=='.' && dist[x][y-1]==-1) dist[x][y-1]=dist[x][y]+1,q.push({x,y-1});
    if(y<w-1 && s[x][y+1]=='.' && dist[x][y+1]==-1) dist[x][y+1]=dist[x][y]+1,q.push({x,y+1});
  }
  if(dist[h-1][w-1]==-1) cout<<-1;
  else cout<<c-dist[h-1][w-1];
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const int INF = 2e9;
const ll large_P = 1e9 + 7;


int main(){
  int X, Y, Z;
  cin >> X >> Y >> Z;
  
  cout << Z << " ";
  cout << X << " ";
  cout << Y << endl;
  
  
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

X = int(input())
ans = 0
ans += (X // 500) * 1000
X = X % 500
ans += (X // 5) * 5
X = X % 5

print(ans)


    
    

Measured memory_bytes: 9392
petern = 0
n = input()
Ln = input()
L = list(map(int, Ln.split(' ')))
for i in range(0, len(L)) :
    moji1 = L[i]
    for j in range(i+1, len(L)):
        moji2 = L[j]
        for k in range(j+1, len(L)):
            moji3 = L[k]
            if moji1 != moji2 and moji2 != moji3 and moji3 != moji1 :
                if moji1+moji2 > moji3 and moji2+moji3 > moji1 and moji3+moji1 > moji2 :
                    petern += 1
print(petern)


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

int main(){
    int N,L[100];

    cin >> N;
    for(int i = 0 ; i < N ; i++){
        cin >> L[i];
    }
    int max = L[0];
    int sum = L[0];
    for(int i = 1 ; i < N ; i++){
        if(max < L[i]){
            max = L[i];
        }
        sum += L[i];
    }

    if((sum - max) > max){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
#include <cstdlib>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 200000+5
#define eps 1e-8
#define mp make_pair
#define pb push_back
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<ll,ll> pll;
const ll MOD=998244353;
inline void read(ll &f){
    f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
ll n;
priority_queue<pair<pll,ll>,vector<pair<pll,ll> >,greater<pair<pll,ll> > > pq;
struct position{
    ll pos,dat;
    ll tar;
    bool operator <(const position &q){
        return pos<q.pos;
    }
};
position g[DMAX];
vector<ll> v[DMAX];
bool fa[DMAX];
ll cnt[DMAX];
ll DFS(ll now){
    cnt[now]=1;
    ll tot=1;
    for(int i=0;i<v[now].size();i++){
        tot=tot*DFS(v[now][i])%MOD;
    }
    cnt[now]+=tot;
    if(cnt[now]==MOD){
        cnt[now]--;
    }
    return cnt[now];
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    read(n);
    for(int i=1;i<=n;i++){
        read(g[i].pos),read(g[i].dat);
        g[i].tar=g[i].pos+g[i].dat;
    }
    sort(g+1,g+n+1);
    for(int i=n;i>=1;i--){
        while(!pq.empty() && g[i].tar>pq.top().first.first){
            v[i].pb(pq.top().second);
            fa[pq.top().second]=1;
            pq.pop();
        }
        pq.push(mp(mp(g[i].pos,g[i].dat),i));
    }
    ll ans=1;
    for(int i=1;i<=n;i++){
        if(!fa[i]){
            ans=ans*DFS(i)%MOD;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 30208
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

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

  int int_a = atoi(a.c_str());
  int int_b = atoi(b.c_str());

  if (int_b > int_a)
    rep(i, int_b) cout << int_a;

  else
    rep(i, int_a) cout << int_b;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

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

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    int A[3];
    REP(i, 3) {
        cin >> A[i];
    }
    sort(A, A + 3);
    int cnt = 0;
    int m = A[2] - A[1];
    A[0] += m;
    cnt += m;
    int n = A[2] - A[0];
    if (n % 2 == 0) {
        cnt += n / 2;
    } else {
        cnt += 1;
        cnt += (n + 1) / 2;
    }
    print(cnt);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <list>
#include <iomanip>
#include <set>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
const int MOD=1000000007;
const int INF=1000000000;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
int face[4];
int main(int argc,char const* argv[])
{
  int magic=0;
  memset(face,0,sizeof(face));
  string s;
  cin >> s;
  int nowface=0;
  for(int i=0;i<s.size();i++)
    {
      if(s[i]=='R')
	{
	  nowface=(nowface+1)%4;
	  face[nowface]++;
	}
      else
	{
	  nowface=(nowface-1)%4;
	}
      if(nowface==0)
	{
	  if(face[0]>0 && face[1]>0 && face[2]>0 && face[3])
	    {
	      magic++;
	    }
	  memset(face,0,sizeof(face));
	}
    }
  cout << magic << endl;
  return 0;
}



Measured memory_bytes: 3204
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define VECV(a,n,m) vector<vector<int>> a(n, vector<int>(m));
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin>>N;
  cout<<2*PI*N<<endl;


}

Measured memory_bytes: 3764
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)

#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


using namespace std;
using ll = long long;
using P = pair<ll,ll>;


const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);


#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define pb push_back
#define fir first
#define scn second
#define ednl endl


#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
vector<int> ki[200000];
vector<int> Hilin(200000);
bool lck[200000];
vector<int> Ans(200000);
struct struct_ni_semikoron_wo_tsukewasurete_CE_dasuno_yametai{
  int /*Windows*/x,p;
};
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int n,q;cin>>n>>q;
  //木面倒くさいですよね！そんなあなたに何もないです、諦めろ
  for(int i = 0; n-1 > i; i++){
    int a,b;cin>>a>>b;a--;b--;
    ki[a].push_back(b);
    ki[b].push_back(a);
  }
  for(int i = 0; q > i; i++){
    int p,x;cin>>p>>x;p--;
    Hilin[p]+=x;
  }
  //木の人「」木は人じゃないですよ？
  //BFSが楽そうですね、やりたくない
  //天下をとる競プロer甜花ちゃん「ひぃん」
  //コメント書くためだけにGoogle検索したの時間の無駄遣いすぎる
  //諦めてBFSを書く Never Escape https://www.youtube.com/watch?v=z_B9iJ8r4ic
  //これ次からヘッダーコメントにするか
  queue<struct_ni_semikoron_wo_tsukewasurete_CE_dasuno_yametai> A;
  //カスだろ
  A.push({0,Hilin[0]});
  lck[0] = true;
  //深夜テンションでStreakを繋ぐな
  while(A.size()){
    struct_ni_semikoron_wo_tsukewasurete_CE_dasuno_yametai Z = A.front();A.pop();
    Ans[Z.x] = Z.p;
    for(int i = 0; ki[Z.x].size() > i; i++){
      if(!lck[ki[Z.x][i]]){
        lck[ki[Z.x][i]] = true;
        A.push({ki[Z.x][i],Z.p+Hilin[ki[Z.x][i]]});
        //かなりカスな変数名とかつけてるせいでかなりタイピングに時間かかってませんか？
      }
    }
  }
  //Queue.Empty()とか使うタイミングないでしょ(sizeだと形こわいかんじがするけど)
  //これでWA出したらかなり笑うよね、笑いました
  //writerさん優しいのでintで許してくれそう
  //このBFS、TLEする気がしてきまして。。。どうしようかなぁ
  //計算量は(N+K)!!!多分大丈夫！TLEでたらJudgeのせいにするわ


  //前処理をする人「ぜんしょーり」
  //前処理をここに書く予定だったのに前に書いてしまった人「@luckYrat_」

  for(int i = 0; n > i; i++){
    cout << Ans[i];
    if(i+1 != n)cout << " ";
  }
  cout << endl;

}


Measured memory_bytes: 17396
#include<cstdio>
#include<iostream>
#include<algorithm>
#define SIZE 10010

using namespace std;

int main()
{
    int n,i,a,total=0;
    int tmp=-1;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        if(a>=tmp)
        {
            total++;
            tmp=a;
        }
    }
    printf("%d\n",total);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < N; X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007

using namespace std;

int main(){

    //n = mのときはn! * m! * 2
    //abs(n - m) == 1のときは n! * m!
    //それ以外の時は0
    //階乗は大きな数になるので逐次10^9+7で割っていく

    int n,m;
    cin >> n >> m;

    int bigger = max(n,m);

    //fact[0] = 1, fact[1] = 1;
    vector<ll> fact(2,1);

    for(int i = 2; i <= bigger; i++){
        fact.pback((fact[i - 1] * i) % MODN);
    }

    ll ans = 0;

    if(n == m){
        ans = (fact[n] * fact[m]) % MODN;
        ans = (ans * 2) % MODN;
    }else if(abs(n - m) == 1){
        ans = (fact[n] * fact[m]) % MODN;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;	
	}
	return o;
}
long long n,k,i,j,x,y,a[5005],zz[5005],sum[5005],b[5005],c[5005],top;
long long f[5005][5005],jc[5005],ans;
long long zzz(long long z){
	if(zz[z]==z) return z;
	return zz[z]=zzz(zz[z]);	
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(i=1;i<=n;i++){
		a[i]=read();
		zz[i]=i;
		sum[i]=1;
	}
	for(i=1;i<=n;i++)
		if(a[i]!=-1){
			x=zzz(a[i]);
			y=zzz(i);
			if(x!=y){
				if(a[x]==-1)
					swap(x,y);
				zz[x]=y;
				sum[y]+=sum[x];
			}
		}
	for(i=1;i<=n;i++)
		if(zz[i]==i){
			top++;
			b[top]=sum[i];
			if(a[i]==-1)
				c[top]=1;
		}
	jc[0]=1;
	f[0][0]=1;
	for(i=1;i<=top;i++){
		jc[i]=jc[i-1]*i%mo;
		f[i][0]=1;
		if(c[i]==0){
			for(j=1;j<=i;j++)
				f[i][j]=f[i-1][j];
		}
		else{
			k++;
			for(j=1;j<=i;j++)
				f[i][j]=(f[i-1][j]+f[i-1][j-1]*b[i])%mo;
		}
	}
	ans=(top-k)*ksm(n-1,k)%mo;
	for(i=1;i<=k;i++)
		if(i==1)
			ans=(ans+(f[top][i]-k)*ksm(n-1,k-i))%mo;
		else
			ans=(ans+f[top][i]*ksm(n-1,k-i)%mo*jc[i-1])%mo;
	ans=(n*ksm(n-1,k)-ans+mo)%mo;
	pus(ans,2);
    return 0;
}

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

using namespace std;
using ll = long long;

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

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

  int ans_n = *max_element(a.begin(), a.end());
  int ans_r = 0;

  auto d = [&](int n) { return min(n, ans_n - n); };

  for (int i = 0; i < n; i++) {
    if (ans_n == a[i])
      continue;
    if (d(ans_r) < d(a[i])) {
      ans_r = a[i];
    }
  }

  cout << ans_n << " " << ans_r << endl;

  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string a, b, c;
    cin >> a >> b >> c;
    cout << a[0] << b[0] << c[0];

}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;
int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	string W[N];
	int a[N];
	int b = 1;
	
	for(int i = 0; i < N; ++i){
		cin >> W[i];
		a[i] = W[i].size();
	}
	
	for(int j = 0; j < N-1; ++j){
		if(W[j][a[j]-1] != W[j+1][0]){
			b = 0;
		}
		
	}
	for(int k = 0; k < N; k++){
		for(int l = k+1; l < N; l++){
			if(W[k] == W[l]){
				b = 0;
			}
		}
	}
	if(b == 1) {
	cout << "Yes" << endl;
	}else if(b == 0){
		cout << "No" << endl;
	}
}

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

for a in range(n+1):
    for b in range(n+1):
        c = n - a - b
        if c < 0:
            break
        if 10000*a + 5000*b + 1000*c == y:
            print(a, b, c)
            exit()

print(-1, -1, -1)


Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n,A,B,C,D;
	scanf("%d %d %d %d %d",&n,&A,&B,&C,&D);
	for(int i=0;i<n;i++){
		ll l=1ll*(n-i-1)*C-1ll*i*D,r=1ll*(n-i-1)*D-1ll*i*C;
	//	cout<<l<<" "<<r<<endl;
		if(abs(B-A)>=l&&abs(B-A)<=r){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
S = list(input())
size = len(S)
b = [] 
cnt = 0 
now = S[0]
for i in range(size):
  if S[i] == now :
    cnt += 1
  else:
    b.append(cnt)
    now = S[i]
    cnt = 0
b.append(cnt)
print("{}".format(len(b)-1))

Measured memory_bytes: 4652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a <= k){
        cout << "Yay!" << endl;
    }
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256