akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

ostream& operator<<(ostream& s, const FiniteField& v) { s << v.Value(); return s; }

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

  int n;
  cin >> n;
  vector<int> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  sort(xs.begin(), xs.end());

  vector<FiniteField> p2s(n + 1);
  p2s[0] = 1;
  for (int i = 1; i <= n; i++) {
    p2s[i] = p2s[i - 1] * 2;
  }

  FiniteField ans = 0;
  for (int i = 0; i < n; i++) {
    FiniteField d = xs[i];
    d *= p2s[i] * (FiniteField(n - i - 1) * p2s[n - i - 2] + p2s[n - i - 1]);
    // cout << d << endl;
    ans += d;
  }
  for (int i = 0; i < n; i++) {
    ans *= 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using pll=pair<ll,ll>;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i,l,r) for(ll i = (l); i <= (ll)(r); i++)
#define rep3(i,l,r) for(ll i = (l); i >= (ll)(r); i--)
#define dup(x,y) (((x)+(y)-1)/(y)) //a/bの除算の切り上げ
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; }
const int inf = 1001001001;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = acos(-1);
 
//a^b=b^a
//a^(b^c)=(a^b)^c
//a^a=0
//a+b=a^b + 2(a&b)
//(4a)^(4a+1)^(4a+2)^(4a+3)=0
 
// union by size + path having
class UnionFind {
public:
   vector <ll> par; // 各元の親を表す配列
   vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
   // Constructor
   UnionFind(ll sz_): par(sz_),siz(sz_, 1LL){
       for (ll i=0; i<sz_; i++) par[i]=i; // 初期では親は自分自身
   }
   void init(ll sz_){
       par.resize(sz_);
       siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
       for (ll i=0; i<sz_; i++) par[i]=i; // 初期では親は自分自身
  }
 
   // Member Function
   // Find
   ll root(ll x){ // 根の検索
      while (par[x]!=x){
           x=par[x]=par[par[x]]; // x の親の親を x の親とする
       }
       return x;
  }
 
   // Union(Unite, Merge)
   bool unite(ll x, ll y){
       x=root(x);
       y=root(y);
       if (x==y) return false;
       // merge technique（データ構造をマージするテク．小を大にくっつける)
       if (siz[x]<siz[y]) swap(x, y);
       siz[x]+=siz[y];
       par[y]=x;
       return true;
  }
 
  bool same(ll x, ll y){ // 連結判定
       return root(x)==root(y);
  }
 
  ll size(ll x){ // 素集合のサイズ
      return siz[root(x)];
  }
};
 
ll modpow(ll x, ll n){
   x=x%mod;
   if(n==0) return 1;
 
   else if(n%2==1){
       return (x*modpow(x, n-1))%mod;
   }
   else return modpow((x*x)%mod, n/2)%mod;
}
 
ll com(ll n, ll k){
   ll x=1;
   for(int i=n-k+1; i<=n; i++){
      x=x*i%mod;
   }
 
   ll y=1;
   for(int i=1; i<=k; i++){
       y=y*i%mod;
   }
   y=modpow(y,mod-2);
 
   return x*y%mod;
}
 
bool is_prime(const unsigned n){
   switch(n){
       case 0: // fall-through
       case 1: return false;
       case 2: // fall-through
       case 3: return true;
  }
 
   if(n%2==0 || n%3==0) return false;
 
   for(unsigned i = 5; i*i<=n; i+=6) {
       if(n%i==0) return false;
       if(n%(i+2)==0) return false;
   }
 
   return true;
}
 
int digsum(int n){
   int res=0;
   while(n > 0) {
       res+=n%10; //ここをres++;に変えたら桁数を求める関数になる,res+=n%10;なら格桁の和
       n/=10;
   }
   return res;
}
vector<ll> divisor(ll n){
   vector<ll> ret;
   for(ll i=1; i*i<=n; i++){
       if(n%i==0){
           ret.push_back(i);
           if(i*i!=n) ret.push_back(n/i);
       }
   }
   sort(ret.begin(),ret.end());
   return ret;
}

vector<ll> yakusuu_cnt(ll n){
    vector<ll> cnt(n);
    for(ll i=1; i<=n; i++){
        for(ll j=i; j<=n; j+=i){
            cnt[j]++;
        }
    }
    return cnt;
}
 
int main(){
  
    ll n;
    cin >> n;
    auto x=yakusuu_cnt(n);
    ll ans=0;
    for(ll i=1; i<=n; i++){
        ans+=(i*x[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 81400
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	string s;
	cin >> s;
	int ans = 0;
	string be, now;
	rep(i, s.size()) {
		now += s[i];
		if (now != be) {
			be = now;
			now = "";
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int D,N;
    cin>>D>>N;
    if(N==100)N++;
    if(D==0){
        cout<<N<<endl;
    }
    else if(D==1){
        cout<<N*100<<endl;
    }
    else if(D==2){
    
    cout<<N*10000<<endl;
    }

}

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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;

    int d[10][10];

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

    for(int k = 0; k < 10; k++) {
        for(int i = 0; i < 10; i++) {
            for(int j = 0; j < 10; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            int a;
            cin >> a;

            if(a != -1) {
                ans += d[a][1];
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

n,a,b,c=l_in()
S=[s_in() for _ in range(n)]
current = [a,b,c]

def add_a():
    current[0]+=1
    res.append('A')

res = []

for i, s in enumerate(S):
    if s == 'AB':
        if a == 0 and b == 0:
            break
        if a > b:
            a -= 1
            b += 1
            res.append('B')
        elif a < b or i == n-1:
            a += 1
            b -= 1
            res.append('A')
        else:
            if 'A' in S[i+1]:
                a += 1
                b -= 1
                res.append('A')
            else:
                a -= 1
                b += 1
                res.append('B')
                
                
    if s == 'AC':
        if a == 0 and c == 0:
            break
        if a > c:
            a -= 1
            c += 1
            res.append('C')
        elif a<c  or i == n-1:
            a += 1
            c -= 1
            res.append('A')
        else:
            if 'A' in S[i+1]:
                a += 1
                c -= 1
                res.append('A')
            else:
                a -= 1
                c += 1
                res.append('C')
            
    if s == 'BC':
        if c == 0 and b == 0:
            break
        if b > c:
            b -= 1
            c += 1
            res.append('C')
            
        elif b<c  or i == n-1:
            b += 1
            c -= 1
            res.append('B')
        else:
            if 'B' in S[i+1]:
                b += 1
                c -= 1
                res.append('B')
            else:
                b -= 1
                c += 1
                res.append('C')
            
else:
    print('Yes')
    [print(r) for r in res]
    exit()

print('No')
            
            
        


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

#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).rend()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a, n) sort(a, a + n)
#define sortvec(V) sort(all(V))

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

typedef unordered_map<int, int, custom_hash> u_map;
typedef unordered_set<int, int, custom_hash> u_set;
typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef priority_queue<int> p_queue;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

int binpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
double dist(int x, int y){
    return sqrt(x * x + y * y);
}
void solve()
{
    int n, d;
    cin >> n >> d;
    int cnt = 0;
    while(n--){
        int x, y;
        cin >> x >> y;
        if(dist(x, y) <= d) cnt++;
    }
    cout << cnt << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}

Measured memory_bytes: 3864
import math

while True:
    b = int(input())
    if b == 0:
        break

    maxfs = math.floor((-1 + math.sqrt(1 + 8 * b)) / 2)

    minf = 1000000001
    lenf = 0
    flag = False

    for lengthf in range(2, maxfs+1)[::-1]:
        a0 = int(lengthf * (lengthf + 1) / 2)

        if b == a0:
            minf = 1
            lenf = lengthf
            flag = True
            break

        if (b - a0) % lengthf != 0:
            continue

        n = int((b - a0) / lengthf)
        minf = n + 1
        lenf = lengthf
        flag = True
        break

    if not flag:
        minf = b
        lenf = 1

    print(minf, lenf)


Measured memory_bytes: 5672
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,m;
    cin>>n>>m;
    vector<int> box(n);
    vector<bool> red(n);
    red[0]=true;
    rep(i,n) box[i]=1;
    int x,y;
    rep(i,m){
        cin>>x>>y;
        box[x-1]--,box[y-1]++;
        if(red[x-1]) red[y-1]=true;
        if(box[x-1]==0) red[x-1]=false;
    }
    int cnt=0;
    rep(i,n) if(red[i]) cnt++;
    cout<<cnt;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define F(n) for(int i=0;i<n;++i)
#define Fj(n) for(int j=0;j<n;++j)

int main(){
    long n,d;
    cin >> n >> d;
    long x[n][d]; 
    F(n) Fj(d) cin >> x[i][j];
    long cnt=0;
    double len=0;
    F(n){
        for(int j=i+1;j<n;++j){
            len=0;
            for(int k=0;k<d;++k){
                len += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            len = sqrt(len);
            if(len==(int)len) ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);

    for (int i = 0; i < N;i++)
        cin >> h[i];

    sort(h.begin(), h.end());
    int min_df = 1e9;
    for (int i = 0; i< N - K + 1; i++)
    {
        min_df = min(min_df, h[i + K - 1] - h[i]);
    }

    cout << min_df;
    return 0;
}


Measured memory_bytes: 640
import math
K = int(input())
ans = 0
d = [[math.gcd(i, j) for i in range(0, K+1)] for j in range(0, K+1)]

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += d[i][d[j][k]]
print(ans)

Measured memory_bytes: 9264
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char s[100010];
    scanf("%s", s);
    int len = strlen(s);
    int p[27];
    memset(p, 0, sizeof(p));
    int i;
    for(i = 0; i < len; i++)
    {
        p[s[i]-'a']++;
    }
    int num = 0;
    for(i = 0; i < 26; i++)
    {
        if(p[i] > 1)
        {
            num++;
        }
    }
    if(num == 0)
    {
        if(len % 2 == 1)
        {
            printf("First\n");
        }
        else printf("Second\n");
    }
    else
    {
        if(s[0] == s[len - 1])
        {
            if(len % 2 == 1)
            {
                printf("Second\n");
            }
            else printf("First\n");
        }
        else
        {
            if(len % 2 == 1)
            {
                printf("First\n");
            }
            else printf("Second\n");
        }
    }
    return 0;
}

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

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define rrep()
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int v[3];
    rep(i,0,3)cin>>v[i];
    sort(v,v+3);
    
    int ans=0;
    ans+=v[2]-v[1];
    if((v[1]-v[0])%2==0)cout<<ans+(v[1]-v[0])/2<<endl;
    else cout<<ans+(v[1]-v[0])/2+2<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 1

#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <random>
#include <ctime>

const long long INF = 10000000000000000;

using namespace std;

void show(vector<bool> x){
	for(int i=0;i<x.size();i++){
		cout<<x[i]<<" ";
	}
	cout<<endl;
}

int main(){

	int N,A,B;
	cin>>N>>A>>B;
	vector<long long> X(N);
	vector<bool> vis(N);
	for(int i=0;i<N;i++){
		cin>>X[i];
		vis[i]=false;
	}
	vis[0]=true;
	long long int ans=0;
	int now=0;
	for(int i=0;i<N-1;i++){
		long long tmp=A*(X[i+1]-X[i]);
		if(tmp<B){
			if(i!=now) ans+=B;
			now=i+1;
			ans+=tmp;
			vis[i]=true;
			vis[i+1]=true;
			//show(vis);
		}
		
	}
	for(int i=0;i<N;i++){
		if(!vis[i]){
			ans+=B;
		//	show(vis);
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include<cmath>

using namespace std;


int main(void){
    
    int N;
    int A[1000000];
    cin >> N;
    A[0]=0;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
    }
    A[N+1] = 0;
    int length = 0;
    for(int i = 0; i <= N; i++){
        length += abs(A[i] - A[i+1]);
    }
    for(int i = 1; i <= N; i++){
        cout << length - abs(A[i - 1] - A[i]) -abs(A[i + 1] - A[i]) + abs(A[i - 1] - A[i + 1]) << endl;
    }
    
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<ll> x(n);
  rep(i,n){
    cin>>x[i];
  }
  ll ans=LLONG_MAX;
  rep(i,100){
    ll P=i+1;
    ll sum=0;
    rep(j,n){
      sum+=abs(x[j]-P)*abs(x[j]-P);
    }
    ans=min(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
M = sorted(L, reverse=True)
u = 0
c = [0]*3
for i in range(N):
  for j in range(i,N):
    for k in range(j,N):
      if(L[k]<L[i]+L[j] and L[i] < L[k]+L[j] and L[j]<L[i] + L[k] and
         (not(L[i]==L[j])) and (not(L[j]==L[k])) and (not(L[i]==L[k]))):
        u+=1
print(u)

Measured memory_bytes: 9224
'use strict';
(function(stdin) {
  var inputs  = stdin.toString().trim().split(' ');
  var a = parseInt(inputs[0]);
  var b = parseInt(inputs[1]);
  var c = parseInt(inputs[2]);

  console.log(a<b && b<c ? 'Yes' : 'No');

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

int main() {
  int N, total_alice = 0, total_bob = 0;
  cin >> N;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  // for(int i = 0; i < N; i++){
  //   cout << vec.at(i) <<endl;
  // }
  
  for (int i = 0; i < N; i++){
    if (i % 2 == 0){
      total_alice += vec.at(i);
    }else if (i % 2 != 0){
      total_bob += vec.at(i);
    }
  }
  cout << total_alice - total_bob << endl;
}






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

int main(){
    long long A, B, C, K;
    cin >> A >> B >> C >> K;
    if (K <= A) {
        cout << K;
    }
    else if (K <= A + B) {
        cout << A;
    }
    else {
        cout << 2 * A + B - K;
    }
} 

Measured memory_bytes: 3604
from sys import stdin
N, Q = list(map(int, stdin.readline().rstrip().split(' ')))
edge = [list(map(int, stdin.readline().rstrip().split(' '))) for _ in range(N-1)]
vals = [list(map(int, stdin.readline().rstrip().split(' '))) for _ in range(Q)]

res = [0] * N
for i, v in vals:
    res[i-1] = res[i-1] + v

edge.sort()
for p, d in edge:
    res[d-1] = res[d-1] + res[p-1]

print(' '.join(map(str, res)))

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

using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll dx[] = { 1, 0 , -1,  0 }, dy[] = { 0, 1, 0, -1 };

int main() {
	ll n;
	string s;
	cin >> n >> s;
	ll cnt = 0;

	rep(i, n) {
		if (s[i] == '.') cnt++;
	}


	if (cnt == 0 || cnt == n) cout << 0;
	else {
		ll l, r, ans = cnt;
		l = 0;
		r = cnt;
		rep(i, n) {
			if(s[i] == '.'){
				r--;
			}
			else {
				l++;
			}
			ans = min(ans, l + r);
		}
		cout << ans;
	}


	return 0;
}



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

Measured memory_bytes: 3768
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define LL       long long
#define PR       pair<LL, LL>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    double r;
    cin >> r;
    double ans = 2.0 * PI * r;
    cout << fixed << setprecision(20) << ans << '\n';
    return 0;
}


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

#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
//#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define mii map<int,int>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi 3.14159265359
#define INF 0x7fffffff
#define next Next
using namespace std;
typedef long long LL;
int main(){
	int n;
	scanf("%d",&n);
	int a[100005];
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	sort(a,a+n);
	int now=0,cnt=0;
	int ans=0;
	for(int i=0;i<n;i++){
		if(a[i]==now)
		cnt++;
		else{
			if(cnt<now)
			ans+=cnt;
			else
			ans+=cnt-now;
			cnt=1;
			now=a[i];
		}
//		printf("%d %d\n",cnt,now);
	}
	if(cnt<now)
	ans+=cnt;
	else
	ans+=cnt-now;
	printf("%d\n",ans);
}


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

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

using namespace std;

int main()
{
  int N,M;
  cin >> N >> M;
  int A[N],counter[N];
  rep(i,N)
    {
      cin >> A[i];
      counter[i] = 0;
    }

  rep(i,M)
    {
      int B;
      cin >>B;
      rep(j,N)
	{
	  if(A[j] <= B)
	    {
	      counter[j]++;
	      break;
	    }
	}
    }

  int mex = 0;
  rep(i,N)
    {
      if(counter[i] > counter[mex])
	{
	  mex = i;
  	}
    }

  cout << mex+1 << endl;
  return 0;
}

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

int main(void){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;

    if(a == b){
        for(int i = 0; i < a; i++) cout << a;
    }else if(a > b){
        for(int i = 0; i < a; i++) cout << b;
    }else{
        for(int i = 0; i < b; i++) cout << a;
    }

    return 0;


}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(){
  int a,b,x,i;
  scanf("%d %d",&a,&b);
  if(b==100){
    x = 1000 * a + b;
  }else if(b >= 10){
    x = 100 * a + b;
  }else{
    x = 10 * a + b;
  }
  for(i=1;i<=x;i++){
    if(i*i>x){
      i = -1;
      break;
    }else if(i*i==x){
      break;
    }
  }
  if(i==-1){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//#define int long long
inline int read() {
	int x=0,f=1; char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())
		if(ch=='-')f=-f;
	for(;ch>='0'&&ch<='9';ch=getchar())
		x=x*10+ch-'0';
	return x*f;
}
#define _ read()
int l[23],mx,sum,flag;
main() {
	int n=_;
	for( int i=1;i<=n;i++ ) l[i]=_,mx=max(l[i],mx);
	for( int i=1;i<=n;i++ ) {
		if(l[i]==mx&&!flag) {
			flag=1; continue;
		}else sum+=l[i];
	}
	return puts(sum>mx?"Yes":"No"),0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
const int M = 1000000007;
const double PI = atan(1) * 4;
const int oo = 1000000000;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back 
#define all(c) (c).begin(),(c).end()
int n,v[N];

int main(){
	cin>>n;
	for(int i=0; i<n; ++i)
		scanf("%d",&v[i]);
	int ans=0;
	for(int i=0; i<n-1; ++i)
		if(v[i]==i+1 && v[i+1]==i+2){
			swap(v[i],v[i+1]);
			++ans;
		}
	for(int i=0; i<n-1; ++i)
		if(v[i]==i+1 || v[i+1]==i+2)
			swap(v[i],v[i+1]),++ans;
	cout<<ans<<endl;
	
}




Measured memory_bytes: 640
n,m = map(int, input().split())
ab = []
for _ in range(m):
    ab.append(list(map(int, input().split())))
ans = {}
for i in range(1, n+1):
    ans.update({i : 0})
for i in range(m):
    for j in range(2):
        if ab[i][j] in ans:
            ans[ab[i][j]] += 1
for v in ans.values():
    print(v)


Measured memory_bytes: 3060
from sys import stdin
import math


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    a,b = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = math.ceil((a+b)/2)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 38256
from sys import stdin
N=int(input())
nodes=[None]*N
sibling=[None]*N
dep=[0]*N
parent_list=[None]*N
degree=[0]*N
class node_tree():
    def __init__(self,node):
        self.node=node
        self.left=None
        self.right=None
        self.brother=None
        self.up=None
for i in range(N):
    node,left,right = list(map(int, (stdin.readline().strip().split())))
    if nodes[node] is not None:
        parent=nodes[node]
    else:parent=node_tree(node)
    if left!=-1:
        if nodes[left] is not None:
            left_node=nodes[left]
        else:left_node=node_tree(left)
        parent.left=left_node
        left_node.up=parent

    if right!=-1:
        if nodes[right] is not None:
            right_node=nodes[right]
        else:right_node=node_tree(right)
        parent.right=right_node
        right_node.up=parent
    if left!=-1 and right!=-1:
        left_node.brother=right_node
        right_node.brother=left_node
    if left!=-1:
        nodes[left] = left_node
    if right!=-1:
        nodes[right] = right_node
    nodes[node]=parent

def search_root(u):
    if u.up!=None:
        return search_root(u.up)
    else:
        return u.node
oya=search_root(nodes[0])

def search_depth(u,p):
    dep[u.node]=p
    if u.right is not None and u.left is not None:
        degree[u.node]=2
    elif u.left is not None:
        degree[u.node]=1
    elif u.right is not None:
        degree[u.node] = 1
    else:degree[u.node]=0

    if u.right is not None:
        parent_list[u.right.node]=u.node
        search_depth(u.right,p+1)
    if u.left is not None:
        parent_list[u.left.node]=u.node
        search_depth(u.left,p+1)
def search_height(u):
    h1,h2=0,0
    if u.right is not None:
        h1=search_height(u.right)+1
    if u.left is not None:
        h2=search_height(u.left)+1
    return max(h1,h2)

def search_sib(u):
    if u.brother is not None:
        sibling[u.node]=u.brother.node
        sibling[u.brother.node]=u.node
    if u.left is not None:
        search_sib(u.left)
    if u.right is not None:
        search_sib(u.right)
search_sib(nodes[oya])
search_depth(nodes[oya],0)
word_list=["internal node","leaf"]
for i in range(N):
    height = search_height(nodes[i])
    if height>=1:word=word_list[0]
    else:word=word_list[1]
    if i==oya:
        parent_list[oya]=-1
        sibling[oya]=-1
        word="root"
    if sibling[i] is None:sibling[i]=-1
    print(("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s" % \
           (nodes[i].node, parent_list[i],sibling[i],degree[i], dep[i], height,word)))


Measured memory_bytes: 5628
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ints;
int main() {
	ints h, w;
	cin >> h >> w;
	if (!(h % 3) || !(w % 3))cout << "0\n";
	else {
		ints ans = min(h, w);
		for (ints i = 1; i < h; i++) {
			ints a = i*w, b = (h - i)*ceil((double)w / 2), c = (h - i)*(w / 2);
			ans = min(ans, max(a, max(b, c)) - min(min(a, b), c));
		}
		for (ints i = 1; i < w; i++) {
			ints a = i*h, b = (w - i)*ceil((double)h / 2), c = (w - i)*(h / 2);
			ans = min(ans, max(a, max(b, c)) - min(min(a, b), c));
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import itertools
import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
lis=[]
for i in range(1,N+1):
    if i%3==0:
        lis.append(i)
    else:
        S=str(i)
        if '3' in S:
            lis.append(i)

ans=' '.join([str(i) for i in lis])
print(' '+ans)


Measured memory_bytes: 6076
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        
        System.out.print( (double) W * H / 2.0 + " " );
        
        boolean isOK = (double)x == (double) W / 2.0 && (double)y == (double) H / 2.0;
        System.out.println( isOK ? 1 : 0 );
    }
}


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

int main(){
  int n,x,sum=0,minnum=1000;
  cin>>n>>x;
  vector<int> num(n);
  for(int &a:num){
    cin>>a;
    sum+=a;
    minnum = min(minnum,a);
  }
  x-=sum;
  cout<<n+x/minnum<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int desc(const void *a, const void *b) { //クイックソート
  return *(int *)a - *(int *)b;
}
int conbination(int n,int r);
int main(){
    int n;
    int l[2001];
    scanf("%d",&n);
    int i,j;
    for(i=0;i<n;i++){
        scanf("%d",&l[i]);
    }
     //qsort(l, n, sizeof(int), desc);
     	for(int i = 0; i < n; i++)
		for(int j = i; j < n; j++)
			if (l[i] > l[j])
			{
				int Temp = l[i];
				l[i] = l[j];
				l[j] = Temp;
			}
 
    // for(i=0;i<n;i++){
        //printf("%d ",l[i]);
  //  }
    int k;
    int count = 0;
    for(i=0;i<n-2;i++){
        for(j=i+1;j<n-1;j++){
            for(k=j+1;k<n;k++){
                int a = l[i],b = l[j],c = l[k];

                if(a < b+c && b < a+c && c < a+b){
                  // if(k==n-1){
                    //     count += k-(j+1)+1;
                 //  }
                   count ++;
                }
                else{
                  //  count += k-(j+1);
                    break;
                }
                
            }
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
// ※※※ 解答不能 ※※※
// tourist氏
// https://atcoder.jp/contests/agc039/submissions/7866772
#include <bits/stdc++.h>
using namespace std;

int main(){
    string s;
    cin >> s;
    long long k;
    cin >> k;
    int n = (int) s.size();
    if(s == string(n, s[0])){
        cout << n * k / 2 << '\n';
    }else{
        int ans1 = 0;
        for(int i = 0; i + 1 < n; i++){
            if(s[i % n] == s[(i + 1) % n]){
                ++ans1;
                ++i;
        }
    }
    int ans2 = 0;
    for(int i = 0; i + 1 < 2 * n; i++){
        if(s[i % n] == s[(i + 1) % n]){
            ++ans2;
            ++i;
        }
    }
    cout << ans1 + (ans2 - ans1) * (k - 1) << '\n';
    }
    return 0;
}

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

const int INF = 1001001001;

int main() {
    int n, m; cin >> n >> m;
    vector<int> C(m);
    rep(i, m){
        cin >> C[i];
    }
    vector<int> T(n+1);
    rep(i, n+1){
        T[i] = INF;
    }
    T[0] = 0;
    for (int i = 0; i < m; i++){
        for (int j = C[i]; j < n+1; j++){
            T[j] = min(T[j], (T[j - C[i]])+1);
        }
    }
    cout << T[n] << endl;

    return 0;
}


Measured memory_bytes: 3160
#include<stdio.h>
int main(void) {
    int W, H, x, y, r;
    scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
    if((x > 0 && x < W) && (y > 0 && y < H)) {
        if((r <= W-x && r <= x) && (r <= H-y && r <=y)) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 2104
n, q = map(int, input().split())
queue = []
for i in range(n):
  k, v = input().split()
  queue.append([k, int(v)])

time = 0

while len(queue) > 0:
  if queue[0][1] > q:
    time += q
    queue[0][1] -= q
    queue.append(queue.pop(0))
  else:
    time += queue[0][1]
    print(queue.pop(0)[0], time)

#print(" ".join(map(str, S)))


Measured memory_bytes: 13016
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n,k=gi
a = gi
k -= 1
n -= 1
puts (n.to_f / k).ceil


Measured memory_bytes: 8796
#include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; ++i)

int main(void) {
  int n, i, j;
  scanf("%d", &n);
  rep(i, n) {
    int r, r1, d, d1;
    scanf("%d%d", &d, &r);
    r1 = r % 30;
    r /= 30;
    r *= 5;
    d1 = d % 100;
    d /= 100;
    if(r1 && d1) printf("%d %d %d %d\n", r + d, r + d + 1, r + d + 5, r + d + 6);
    else if(r1 && !d1) printf("%d %d\n", r + d, r + d + 5);
    else if(!r1 && d1) printf("%d %d\n", r + d, r + 1 + d);
    else printf("%d\n", r + d);
  }
  return 0;
}


Measured memory_bytes: 2732
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
    A[i] -= i+1;
  }
  sort(A.begin(), A.end());
  vector<ll> sum(N, 0LL);
  sum[0] = A[0];
  for(int i=1; i<N; i++){
    sum[i] += sum[i-1] + A[i];
  }
  // for(int i=0; i<N; i++)
  //   cout << A[i] << ' ';
  // cout << endl;
  // for(int i=0; i<N; i++)
  //   cout << sum[i] << ' ';
  // cout << endl;
  ll ans = 1e+15;
  for(int i=0; i<N; i++){
    ll b = A[i];
    ll tmp = (sum[N-1] - sum[i]) - sum[i] - b * (N-(i+1)-(i+1));
    if(tmp < ans)
      ans = tmp;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
N = int(input())
P = list(map(int,input().split()))

Correct = []
for i in range(N):
  Correct.append(i+1)
  
count = 0
for i in range(N):
  if(Correct[i] != P[i]): 
    count += 1

if((count == 0)or(count == 2)):
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3064
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define N 100010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define mod 1000000007
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define FOR(i, x, y) for (int i = x; i <= y; i++)
//#define tr(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

//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>;

int n, k;
int ans;

int main()
{
	cin >> n >> k;
	
	int in = 1;
	while(n--) {
		if(in <= k)
			in += in;
		else if(in > k)
			in += k;
	}
	cout << in;
}

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


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    rep(i,n){
        if(i==k-1){
            s[i] = towlower(s[i]);
        }
        cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
n = int(s)
s2 = input().split()
k2 = [int(el) for el in s2]
a_dic = {}
cnt_dic = {}
for i in range(len(k2)):
  key = k2[i]
  if key in a_dic:
    a_dic[key] = a_dic[key] + 1
  else:
    a_dic[key] = 1

cnt = 0
for el in a_dic.items():
  if el[1] > 1:
    wk = (el[1] * (el[1] - 1 )) /2
    cnt += wk
    cnt_dic[el[0]] = wk
  else:
    cnt_dic[el[0]] = 0
    
for k in range(len(k2)):
  k_cnt = cnt_dic[k2[k]]
  wk2 = 0
  if k_cnt > 0:
    nn = a_dic[k2[k]] - 1
    wk2 = (nn * (nn - 1 )) /2
  print( int(cnt - cnt_dic[k2[k]] + wk2))
  

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

bool check_possibility(int diff, int x1, int y1, int x2, int y2);

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

    vector<int> t, x, y;
    t.push_back(0);
    x.push_back(0);
    y.push_back(0);
    for(int i=0; i<N; i++)
    {
    	int a, b, c;
        cin >> a >> b >> c;
        t.push_back(a);
        x.push_back(b);
        y.push_back(c);
    }

    for(int i=0; i<N; i++)
    {
      if(!check_possibility(t[i+1]-t[i], x[i], y[i], x[i+1], y[i+1]))
      {  
      	 cout << "No" << endl;
      	 return 0; 
      }  
    }

    cout << "Yes" << endl;

	return 0;
}

bool check_possibility(int diff, int x1, int y1, int x2, int y2)
{
    int n = abs(x1-x2) + abs(y1-y2);
    int z = diff-n;
    if(z<0) return false;
    else if(z%2==0) return true;
    else return false;
}

Measured memory_bytes: 1644
import java.util.*;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		long N = Long.parseLong(in.readLine());

		long result = 0;
		if (N == 1) {
			result = 0;
		} else if (N == 2) {
			result = 1;
		} else {
			result = (1 + N - 1) * (N - 1) / 2;
		}
		System.out.println(result);

	}

}


Measured memory_bytes: 21332
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;

int Q;
const int N = 300005;
long long C[N];
long long D[N];
vector<int>G[N];

void dfs(int u, int par, long long s){
    D[u] += s;

    for (int i = 0; i < G[u].size(); i++){
        int w = G[u][i];
        if (w == par)continue;
        s += C[w];
        dfs(w, u, s);
        s -= C[w];
    }
}

int main() {
    int n;
    scanf("%d %d", &n, &Q);
    for (int i = 0; i < n - 1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);

    }

    for(int i = 0; i < Q; i++){
        int p, x;
        scanf("%d %d", &p, &x);
        p--;
        C[p] += x;
    }

    dfs(0, 0, C[0]);
    for (int i = 0; i < n; i++){
        printf("%lld ", D[i]);
    }
    cout << endl;
	return 0;
}


Measured memory_bytes: 34944
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct UnionFind{
  vector<int> parent;
  vector< ll > dist;
  UnionFind(int x=1){
    parent.clear();
    parent.resize(x,-1);
    dist.clear();
    dist.resize(x,0);
  }
  int find(int x){
    if(parent[x]<0)return x;
    int r=find(parent[x]);
    dist[x]+=dist[ parent[x] ];
    return parent[x]=r;    
  }
  ll depth(int x){
    find(x);
    return dist[x];
  }
  bool same(int x,int y){
    return (find(x)==find(y));
  }
  int size(int x){
    return -parent[find(x)];
  }
  void unite(int x,int y,ll k=0){
    k+=depth(y);
    k-=depth(x);
    k*=-1;
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(size(x)<size(y)){
      swap(x,y);
      k*=-1;
    }
    parent[x]+=parent[y];
    parent[y]=x;
    dist[y]=k;
  }
};
int main(){
  int n,q;
  while(cin>>n>>q,n){
	  UnionFind T(n);
	  for(int i=0;i<q;i++){
		char type;
		int x,y;
		cin>>type>>x>>y;
		x--;y--;
		if(type=='!'){
		  int a;
		  scanf("%d",&a);
		  T.unite(x,y,a);
		}else{
		  if(!T.same(x,y)){
			printf("UNKNOWN\n");
		  }else{
			printf("%lld\n",T.depth(x)-T.depth(y));
		  }
		}
	  }
  }
  return 0;
}

/*
int n;
vi in;
int dp[310][310];
int f(int l,int r){
	if(dp[l][r]+inf)return dp[l][r];
	if(r-l<2)return dp[l][r]=0;
	int out=-inf;
	loop(i,l,r-1)if(abs(in[i]-in[i+1])<2){
		out=max(out,f(l,i)+2+f(i+2,r));
	}
	int t=f(l+1,r-1);
	if(t==r-l-2){
		if(abs(in[l]-in[r-1])<2)out=max(out,r-l);
	}
	out=max(out,f(l+1,r));
	out=max(out,f(l,r-1));
//	cout<<l<<" "<<r<<" "<<out<<endl;
	return dp[l][r]=out;
}
int main(){
	while(cin>>n,n){
		in=vi(n);
		rep(i,n)cin>>in[i];
		rep(i,310)rep(j,310)dp[i][j]=-inf;
		cout<<f(0,n)<<endl;;
	}
}
*/



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

const int MAX_N = 2e5;
int n;
int a[MAX_N];

int sub[MAX_N];

void solve() {
    for (int i = 0; i < n; i++) {
        sub[a[i] - 1]++;
    }

    for (int i = 0; i < n; i++) {
        cout << sub[i] << endl;
    }
}

int main() {
    cin >> n;
    for (int i = 1; i < n; i++) {
        cin >> a[i];
    }
    solve();
}

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

using namespace std;

int main(){
  int N, T, tmp, c;
  cin >> N >> T;
  vector<int> cost;
  for (int i=0; i<N; i++){
	cin >> tmp >> c;
    if (c <= T) cost.push_back(tmp);
  }
  
  if (cost.size() == 0){
	cout << "TLE" << endl;
  }
  else{
    sort(cost.begin(), cost.end());
    cout << cost[0] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int const MAX = 200003;
long long a[MAX];

int main() {
	a[0] = 0;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		a[i] = a[i - 1] + x;
	}
	sort(a, a + n + 1);
	long long ans = 0;
	long long  cnt = 1;
	long long now = a[0];
	for (int i = 1; i <= n; i++) {
		if (now == a[i]) {
			cnt++;
		}
		else {
			now = a[i];
			ans += cnt * (cnt - 1) / 2;
			cnt = 1;
		}
	}
	ans += cnt * (cnt - 1) / 2;
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define int                 long long
#define pb                  push_back
#define mp                  make_pair
#define pii                 pair<int,int>
#define vi                  vector<int>
#define vvi                 vector< vi > 
#define vpii                vector< pair<int,int> > 
#define mii                 map<int,int>
#define pqb                 priority_queue<int>
#define pqs                 priority_queue<int,vi,greater<int> >
#define loop(i,a,b)         for(int i=a;i<b;i++)
#define LOOP(i,a,b)         for(int i=a;i<=b;i++)
#define looprev(i,a,b)      for(int i=a;i>=b;i--)
#define rloop(it,c)         for(auto& it : c)
#define sz(a)               a.size()
#define all(c)              c.begin(),c.end()
#define tr(i,c)             for(auto i = c.begin(); i != c.end(); i++)
#define present(c,x)        (c.find(x) != c.end())
#define cpresent(c,x)       (find(all(c),x) != c.end())
#define spresent(s,x)       (s.find(x) != s.npos)           //use 'x' while passing to parameters  ||  we can also use cpresent(c,x)
#define setbits(x)          __builtin_popcountll(x)
#define zrobits(x)          __builtin_ctzll(x)
#define SETINT(a,x)         memset(a, x, sizeof(a))
#define SETCHAR(str,x)      memset(str, x, sizeof(str)      //use 'x' while passing to parameters  
#define mod                 1000000007
#define inf                 1e18
#define ps(x,y)             fixed<<setprecision(y)<<x
#define w(x)                int x; cin>>x; while(x--)
mt19937                     rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

 
int raise(int a,int n,int m)
{
  
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}
 
int floor1(int n,int k)
{
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}
 
int ceil1(int n,int k)
{
    return floor1(n+k-1,k);
}
 
 
void Gur27()
{
    ios::sync_with_stdio(0); cin.tie(0); 

}

int32_t main()
{
    Gur27();
    int a,b;
    cin>>a>> b;
    cout<<a*b<<'\n';
        
    
    return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int t = a+b;
    if(t<24) { 
    	System.out.print(t);
    }else {
    	System.out.print(t-24);
    }
}
}

Measured memory_bytes: 35604
#include <cstdio>

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

  for (int i=0; i<=100; ++i)
    for (int j=0; j<=100; ++j)
      if (4*i + 7*j == N)
        return !printf("Yes\n");

  printf("No\n");
}


Measured memory_bytes: 128