akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <deque>
 
#define ll long long
#define cint const int
#define ld long double
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define add +
#define minus -
#define squer(a) sqrt(a)
#define mod % 
 
using namespace std;

int n;

int main () {
	cin >> n;
	int c1 = (n % 10) + (n % 100 / 10) * 10;
	int c2 = (n % 1000 / 100) + (n % 10000 / 1000) * 10;
	if (c1 > 12 || c1 == 0) {
		if (c2 > 12 || c2 == 0) {
			cout << "NA";
			return 0;
		}
	}
	if (c1 <= 12 && c1 != 0) {
		if (c2 <= 12 && c2 != 0) {
			cout << "AMBIGUOUS";
			return 0;
		}
	}
	if (c1 <= 12 && c1 != 0) {
		cout << "YYMM";
		return 0;
	}
	if (c2 <= 12 && c2 != 0) {
		cout << "MMYY";
		return 0;
	}
	return 0;
}

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

g = None
if 400 <= x <= 599:
    g = 8
elif 600 <= x <= 799:
    g = 7
elif 800 <= x <= 999:
    g = 6
elif 1000 <= x <= 1199:
    g = 5
elif 1200 <= x <= 1399:
    g = 4
elif 1400 <= x <= 1599:
    g = 3
elif 1600 <= x <= 1799:
    g = 2
elif 1800 <= x <= 1999:
    g = 1

print(g)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

bool isPrime(ll x){
    if(x == 2)return 1;
    else if(x < 2 || x%2 == 0)return 0;
    else{
        double sq = sqrt(x);
        for(int i = 3;i<=sq;i+=2)if(x%i == 0)return 0;
        return 1;
    }
    
}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n,0);
    rep(i,n)cin >> a.at(i);
    ll ans = 0;
    rep(i,n)if(isPrime(a.at(i)))ans++;
    cout << ans << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  int x;
  for(int i = 0; i < N; ++i) {
    cin >> x;
    ans += 2 * min(abs(x), abs(K - x));
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {

  int n, ans = 0;
  char a = 0, b = 0, c;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> c;
    //cerr << a << ' ' << b << ' ' << c << '\n';
    if(a == 'A' && b == 'B' && c == 'C'){
      ans++;
    }
    a = b;
    b = c;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3620
n, k = map(int, input().split())
x = list(map(int,input().split()))

a = []

for i in range(n-k+1):
    left = x[i]
    right = x[i+k-1]
    a.append(min(abs(left)+abs(right-left),abs(right)+abs(left-right)))

print(min(a))

Measured memory_bytes: 14252
#include <iostream>

int main() {
  int a, b;
  std::cin >> a >> b;

  if (a % 2 == 0 || b % 2 == 0) {
    std::cout << "No" << std::endl;
  } else {
    std::cout << "Yes" << std::endl;
  }

  return 0;
}

Measured memory_bytes: 256
n, k, q = map(int, input().split())
a_list = [int(input()) for _ in range(q)]
if k > q:
    for _ in range(n):
        print('Yes')
else:
    point_list = [0 for _ in range(n)]
    for a in a_list:
        point_list[a-1] += 1

    all_sum = sum(point_list)

    for point in point_list:
        if k - all_sum + point > 0:
            print('Yes')
        else:
            print('No')

Measured memory_bytes: 8640
N, Y = gets.chomp.split.map(&:to_i)
ans = "-1 -1 -1"

for i in 0..N do
  is_break = false
  for j in 0..(N - i) do
    k = N - i - j
    if 10000 * i + 5000 * j + 1000 * k == Y then
      ans = "#{i} #{j} #{k}"
      is_break = true
      break
    end
  end
  break if is_break
end

puts ans


Measured memory_bytes: 3836
#include <algorithm>
#include <vector>

template <typename T>
struct BIT {
  using value_type = T;
  using Index1 = int;
  std::vector<value_type> A;
  const int N, N2;
  BIT(int N) : A(N + 1, 0), N(N), N2(1 << std::__lg(N)) {}
  void add(Index1 a, value_type w) {
    for (Index1 x = a; x <= N; x += x & -x) {
      A[x] += w;
    }
  }
  value_type sum(Index1 a) const {
    value_type ret = 0;
    for (Index1 x = a; x > 0; x -= x & -x) {
      ret += A[x];
    }
    return ret;
  }
  Index1 lower_bound(value_type w) const {
    if (w <= 0) return 0;
    Index1 x = 0;
    for (int k = N2; k > 0; k >>= 1) {
      if (x + k <= N && A[x + k] < w) {
        w -= A[x + k];
        x += k;
      }
    }
    return x + 1;
  }
};


#include <cstdio>

#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

template<typename T=int>T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
template<typename T=int>void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}

int main() {
  int N = rd(), Q = rd();
  BIT<int> bit(N);
  for (int i = 0; i < Q; i++) {
    int c = rd(), x = rd(), y = rd();
    if (c == 0) {
      bit.add(x, y);
    } else {
      wr(bit.sum(y) - bit.sum(x - 1));
    }
  }
}

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

int main(){
  string S;
  cin >> S;
  int md = 1000000007;
  int Slen = S.size();
  vector<vector<long long> > dp(Slen+1, vector<long long>(4,0));
  string ABC = "ABC";
  for (int i=Slen; i>-1; i--){
    for (int j=0; j<4; j++){
      if (i==Slen){
        if (j==3) dp[i][j] = 1;
        else dp[i][j] = 0;
      } else {
        if (j==3){
          if (S[i] == '?') dp[i][j] = 3*dp[i+1][j]%md;
          else dp[i][j] = dp[i+1][j]%md;
        } else {
          int m1=1, m2=0;
          if (S[i] == '?') m1 = 3;
          if ((S[i] == '?') || (S[i] == ABC[j])) m2 = 1;
          dp[i][j] = (m1*dp[i+1][j]%md + m2*dp[i+1][j+1]%md)%md;
        }
      }
    }
  }
  cout << dp[0][0] << endl;
}


Measured memory_bytes: 7424
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

import itertools as iter
import math
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

H = num()
e_num = 1
enemies = [H]
ans = 0
while 1:
    if H == 1:
        ans += e_num
        break
    H = math.floor(H/2)
    ans += e_num
    e_num *= 2
print(ans)


Measured memory_bytes: 66028
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
   int n; cin>>n;
   vector<int> v(n);
   vector<int> c(n);
   for(int i=0;i<n;i++) cin>>v[i];
   for(int i=0;i<n;i++) cin>>c[i];
   int ans=0;
   for(int i=0;i<n;i++){
      if((v[i]-c[i])>0) ans+=(v[i]-c[i]);
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

class Main {
  private static BufferedReader buf;
  public static void main(String[] args) throws IOException {
    buf = new BufferedReader(new InputStreamReader(System.in));
    String str = buf.readLine();
    String[] s = str.split(" ", 0);
    int W = Integer.parseInt(s[0]);
    int H = Integer.parseInt(s[1]);
    int x = Integer.parseInt(s[2]);
    int y = Integer.parseInt(s[3]);
    int r = Integer.parseInt(s[4]);
    if ((y+r<=H)&&(y-r>=0)&&(x+r<=W)&&(x-r>=0)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 24400
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int a, b; cin >> a >> b;
    int ans = a + b;
    ans = max(ans, a - b);
    ans = max(ans, a * b);
    cout << ans << endl;
}

Measured memory_bytes: 256
H,W = map(int, input().split())
grid = []
grid.append(["."]*(W+2))
for i in range(H):
    s = ["."]+list(input())+["."]
    grid.append(s)
grid.append(["."]*(W+2))
for i in range(1,H+1):
    for j in range(1,W+1):
        if grid[i][j] != "#":
            temp = [grid[i-1][j-1],grid[i-1][j],grid[i-1][j+1],grid[i][j-1],grid[i][j+1],grid[i+1][j-1],grid[i+1][j],grid[i+1][j+1]]
            bom = str(temp.count("#"))
            grid[i][j] = bom
for i in range(1,H+1):
    print("".join(grid[i][1:W+1]))

Measured memory_bytes: 40688
#include <stdio.h>

int main(void) {
  int N;
  scanf("%d", &N);
  int shou1;
  int amari;
  int shou2;
  shou1 = N / 100;
  amari = N % 100;
  shou2 = amari / 10;
  amari = amari % 10;
  if (shou1 == 7 || shou2 == 7 || amari == 7) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1636
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define sd(x)   scanf("%g",&x)
#define ss(s)	scanf("%s",s)
#define pd(x)   printf("%g\n",x)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define nline   printf("\n")
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define fitr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int main()
{
 int n,x,t;
 si(n);
 si(x);   
 si(t);
 int res = 0,rest = 0;
 while(n>res){
 res = res + x;
 rest = rest + t;
}
pi(rest);                            
}

Measured memory_bytes: 3824
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[1001],n;
int main(){
	cin>>n;for(int i=0;i<n;i++)cin>>a[i];
	int maxn=1000000000;
	for(int i=-100;i<=100;i++){
		int sum=0;
		for(int j=0;j<n;j++)sum+=(a[j]-i)*(a[j]-i);
		maxn=min(maxn,sum);
	}
	cout<<maxn<<endl;
}

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

int main() {
  ll n, y;
  cin >> n >> y;

  for (ll i = 0; i <= n; i++) {
    for (ll j = 0; j <= n; j++) {
      if (i + j > n) continue;
      ll z = n - i - j;
      if (y == (i * 10000 + j * 5000 + z * 1000)) {
        printf("%lld %lld %lld\n", i, j, z);
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
import numpy as np

A = np.array(list(list(map(int, input().split())) for l in range(3)))
N = int(input())
b = np.array(list(int(input()) for l in range(N)))
bingo = np.zeros((3, 3))
bingo = bingo == 1

for b_i in b:
    hantei = A == b_i
    bingo = np.logical_or(bingo, hantei)

for i in range(3):
    if all(bingo[i]) or all(bingo[:,i]):
        print('Yes')
        exit()

if (bingo[0,0] and bingo[1,1] and bingo[2,2]) or (bingo[0,2] and bingo[1,1] and bingo[2,0]):
    print('Yes')
    exit()

print('No')

Measured memory_bytes: 14432
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int L[M], R[M];
    for(int i = 0; i < M; i++) cin >> L[i] >> R[i];
    //処理
    int maxL = 1;
    int minR = N;
    for(int i = 0; i < M; i++)  {
        maxL = max(maxL, L[i]);
        minR = min(minR, R[i]);
    }
    int ans = minR - maxL + 1; //区間の長さなので
    ans = max(ans, 0); //負だったら0にする
    cout << ans << endl;
    return 0;
}

/*
1 ~ 3を 1以上3以下と考える
以上だけ考えると、一番うしろから始まる以上の範囲を満たせばよい
以下だけ考えると、一番前から始まる以下の範囲を満たせば良い
よってmax(Li) ~ min(Ri)を満たすカードが通るカード
*/

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
    int H, W;

    while(true){
        cin >> H >> W;
        if(H == 0 && W == 0)
            break;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(i == 0 || i == H - 1 || j == 0 || j == W - 1){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  vector<int> x(m); REP(i, m) cin >> x[i];
  sort(ALL(x));
  vector<int> sa;
  REP(i, m-1) sa.push_back(x[i+1]-x[i]);
  sort(ALL(sa));
  long long ans = 0;
  for (int i : sa) ans += i;
  int now = 0;
  for (int i = sa.size()-1; now < n-1 && i >= 0; --i) {
    ans -= sa[i];
    ++now;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1276
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <array>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

const int maxa = 1e6 + 1;
vector<int> spf(maxa + 1, 0);
vector<bool> can(maxa + 1, true);

int main() {

	iota(spf.begin(), spf.end(), 0);

	for (int i = 2; i * i <= maxa; i++) {
		if (spf[i] == i) {
			for (int j = i * i; j <= maxa; j += i) spf[j] = min(spf[j], i);
		}
	}

	int n; cin >> n;
	int gd = 0;
	vector<int> a(n); for (int i = 0; i <= n - 1; i++) cin >> a[i], gd = gcd(gd, a[i]);

	bool is_setwise = (gd == 1);
	bool is_pairwise = true;


	for (int i = 0; i <= n - 1; i++) {
		int x = a[i];

		while (x != 1) {
			int pfac = spf[x];

			if (can[pfac] == false) {
				is_pairwise = false;
				break;
			}
			can[pfac] = false;

			while (x % pfac == 0) x /= pfac;
		}

		if (!is_pairwise) break;
	}

	if (is_pairwise) cout << "pairwise coprime";
	else if (is_setwise) cout << "setwise coprime";
	else cout << "not coprime";


	return 0;
}

Measured memory_bytes: 11076
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int c[14],  N;

bool dfs(int sum, stack<int> st){
  if(st.size() == N){
    bool f = true;
    while(!st.empty()){
      if(!f) printf(" ");
      f = false;
      printf("%d", st.top());
      st.pop();
    }
    puts("");
    return true;
  }
  rep(i, 14){
    if(c[i] == 0)continue;
    if((sum - i) % i != 0)continue;
    st.push(i);
    c[i]--;
    if(dfs(sum-i, st)) return true;;
    c[i]++;
    st.pop();
  }
  return false;
}


int main(){
  while(scanf("%d", &N) && N){
    memset(c, 0, sizeof(c));

    int sum = 0;
    rep(i, N){
      int in;
      scanf("%d", &in);
      sum += in;
      c[in]++;
    }

    stack<int>st;
    if(!dfs(sum, st)) puts("No");
  }
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  
///////
int ans[100001];
void dfs(int i,int pr,int c,vector<int> gr0[],vector<int> gr1[])
{
	ans[i]=c;
	for(auto r:gr0[i])
	{
		if(r!=pr)
			dfs(r,i,c,gr0,gr1);
	}
	for(auto r:gr1[i])
	{
		if(r!=pr)
			dfs(r,i,!c,gr0,gr1);
	}
}
signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n;
	cin>>n;
	vector<int> gr0[n+1];
	vector<int> gr1[n+1];
	for(int i=1;i<n;++i)
	{
		int x,y,w;
		cin>>x>>y>>w;
		if(w%2)
		{
			gr1[x].push_back(y);
			gr1[y].push_back(x);
		}
		else
		{
			gr0[x].push_back(y);
			gr0[y].push_back(x);
		}
	}
	dfs(1,1,1,gr0,gr1);
	for(int i=1;i<=n;++i)
		cout<<ans[i]<<"\n";
}


Measured memory_bytes: 13824
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MAX = 2e5+10;
ll n;
ll len;
ll u0,v0;
ll a[MAX];
ll ans[MAX];
vector<ll> adj[MAX];
vector< stack<ll> > dp(MAX);

void dfs(ll cur,ll par)
{
    bool flag = 0;
    ll ind;
    if(a[cur] < dp[1].top())
    {
        dp[1].push(a[cur]);
        ind = 1;
    }
    else if(a[cur] > dp[len].top())
    {
        len++;
        flag = true;
        dp[len].push(a[cur]);
        ind = len;
    }
    else
    {
        ll left = 2;
        ll right = len;
        while(left<=right)
        {
            ll mid = (left+right)/2;
            if(dp[mid].top() >= a[cur])
            {
                right = mid-1;
            }
            else left = mid+1;
        }
        ind = right + 1;
        dp[ind].push(a[cur]);
    }
	
    ans[cur] = len;
    for(ll i=0;i<adj[cur].size();i++)
    {
        if(adj[cur][i] == par)continue;
        dfs(adj[cur][i],cur);
    }
    dp[ind].pop();
    len-=flag;
}
int main()
{
    ///freopen("path_02.txt","r",stdin);
    ///freopen("path_02_out.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(ll i=1;i<n;i++)
    {
        cin>>u0>>v0;
        adj[u0].push_back(v0);
        adj[v0].push_back(u0);
    }
    dp[1].push(a[1]);
    len = 1;
    ans[1] = 1;
    for(ll j=0; j<adj[1].size(); j++)
    {
        dfs(adj[1][j],1);
    }
    for(ll j=1; j<=n; j++)
    {
        cout<<ans[j]<<endl;
    }
    return 0;
}


Measured memory_bytes: 164440
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	int x = b * 2 + 1;
	int ans = 0;
	if (a % x == 0)
	{
		ans = a/x;
	}
	else
	{
		ans = a / x + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        String todayWeather = scanner.next();
//        System.out.println(todayWeather.equals("Sunny") ? "Cloudy" : todayWeather.equals("Cloudy") ? "Rainy" : "Sunny");

        Scanner scanner = new Scanner(System.in);
        String stepStrng = scanner.next();

        char[] stepChar = new char[stepStrng.length()];
        for(int i = 0; i < stepStrng.length(); i++){
            stepChar[i] = stepStrng.charAt(i);
        }

        boolean easy = true;
        for (int i = 0; i < stepChar.length; i++) {
            if (i % 2 == 0 && (stepChar[i] == 'R' || stepChar[i] == 'U' || stepChar[i] == 'D')) {
                continue;
            } else if (i % 2 == 1 && (stepChar[i] == 'L' || stepChar[i] == 'U' || stepChar[i] == 'D')) {
                continue;
            } else {
                easy = false;
            }
        }

        System.out.println(easy ? "Yes" : "No");

    }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int lunlun(long n) {
  long a = n % 10, b, diff;
  n /= 10;
  for(; n > 0; n /= 10) {
    b = n % 10;
    diff = a - b;
    if(diff > 1 || diff < -1) {
      return false;
    }
    a = b;
  }

  return true;
}

long next(long n) {
  if(n < 10) {
    return n + 1;
  }

  long a, b;
  a = n % 10 + 1;
  //cout << "a == " << a << endl;
  n /= 10;
  int i;
  for(i = 0; n > 0; i++) {
    b = n % 10;
    if(a == 10 || a - b == 2) {
      a = b + 1;
    } else {
      break;
    }
    n /= 10;
  }
  //cout << "n == " << n << endl;
  //cout << "i == " << i << endl;
  //cout << "a == " << a << endl;


  n *= 10;
  n += a;
  a %= 10;
  for(; i > 0; i--) {
    if(a > 0) {
      a -= 1;
    }

    n = n * 10 + a;
  }

  return n;
}

int main2() {
  cout << next(123) << endl;
}

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

  long n = 0;
  for(int i = 0; i < K; i++) {
    n = next(n);
  }

  cout << n;

  return 0;
}


Measured memory_bytes: 3196
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = B[A[0]-1]
for i in range(1, N):
    if A[i] == A[i-1]+1:
        ans += C[A[i-1]-1]
    ans += B[A[i]-1]
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main(void){
    // Your code here!
    int H,N;
    cin >> H >> N;
    
    int sum = 0,temp;
    
    for(int i=0;i<N;i++){
        cin >> temp;
        sum += temp;
    }
    
    if((H-sum)>0){
        cout << "No" << endl;
        return 0;
    }
    
    cout << "Yes" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    priority_queue<int> que;
    rep(i,0,N)que.push(V[i]);

    ll sum = 0;
    rep(i,0,M){
        int num = que.top();
        que.pop();
        que.push(num / 2);
    }

    rep(i,0,N){
        sum += que.top();
        que.pop();
    }
    cout << sum << endl;
}

Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);
        String[] you = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
	    String s=gs();
	    //int b=gi();
	    
	    for(int i=0; i< you.length;i++) {
	    	if(s.equals(you[i])) {
	    		 System.out.print(7-i);
	    		 return;
	    	}
	    }


	    //System.out.print(s);

//        if (a<10 && b<10) {
//        	System.out.print(a*b);
//        } else {
//        	System.out.print(-1);
//        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35564
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

int gcd2(int a,int b)
{
  int r=1;
  while(r!=0){
    r=a%b;
    a=b;
    b=r;
  }
  return a;
}

int gcd3(int a,int b, int c)
{
  int t,ans;
  t=gcd2(a,b);
  ans=gcd2(t,c);
  return ans;

}
int main(void)
{
  int k,s,t,u,ans=0;
  scanf("%d",&k);

  for(s=1;s<=k;s++){
    for(t=1;t<=k;t++){
      for(u=1;u<=k;u++){
        ans+=gcd3(s,t,u);
      }
    }
  }
  printf("%d",ans);


	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main(void){
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];

	ll ans = 0LL;
	
	while(1){
		int idx = -1;
		rep(i,n){
			if(a[i]<n) continue;
			if(idx == -1 or a[idx] < a[i]) idx = i;
		}
		if(idx == -1) break;
		const ll num = a[idx]/n;
		ans += num;
		rep(i,n) if(i!=idx) a[i]+=num;
		a[idx]%=n;
	}

	cout << ans << endl;

	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

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

const ll SIZE = 1e5+10;

ll n;

int main(){
    cin >> n;

    ll ma = 0;
    ll mem_num[101],mem_num2[101];
    mem_num[0] = mem_num2[0] = 26;
  for(int i = 1; i < 101; i++){
      mem_num[i] = mem_num[i-1]*26;
      mem_num2[i] = mem_num[i];
      if(mem_num[i] > 1000000000000001LL){
          ma = i;
          for(int j = 1; j <= i; j++){
              mem_num[j] += mem_num[j-1];
          }
          
          break;
      }
  }

    string ans;
    --n;
    string wor = "abcdefghijklmnopqrstuvwxyz";
  for(int i = ma; i >= 0; i--){
      if(mem_num[i] <= n){
       ll tmp = (n-mem_num[i])/mem_num2[i];
       //   cout << i << " " << tmp << endl;
       ans += wor[tmp];
       ++tmp;
       n -= tmp*mem_num2[i];
      }
  }
  ans += wor[n];
  cout << ans << endl;
  
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
#include<algorithm>
#define int long long int
int binary_search(int arr[],int start,int end,int val)
{
	if(start>end)
	   return -1;
	else
	{
		int mid=(start+end)/2;
		if(arr[mid]>val)
		{
			int x=mid;
			int y=binary_search(arr,start,mid-1,val);
			if(y==-1)
			   return x;
			else
			   return y;
		}
		else
		{
			return binary_search(arr,mid+1,end,val);
		}
	}
}
int32_t main()
{
      int n;
      cin>>n;
      int arr1[n],arr2[n],arr3[n],j;
      for(j=0;j<n;j++)
           cin>>arr1[j];
      for(j=0;j<n;j++)
      {
		  cin>>arr2[j];
	  }
	  for(j=0;j<n;j++)
	  {
		  cin>>arr3[j];
	  }
	  sort(arr1,arr1+n);
	  sort(arr2,arr2+n);
	  sort(arr3,arr3+n);
	  int suffix[n+1]={0};
	  for(j=n-1;j>=0;j--)
	  {
		  int index=binary_search(arr3,0,n-1,arr2[j]);
		  if(index!=-1)
		  {
			  suffix[j]+=(n-index);
		  }
	  }
	  for(j=n-1;j>=0;j--)
	      suffix[j]+=suffix[j+1];
	  int answer=0;
	  for(j=0;j<n;j++)
	  {
		  int index=binary_search(arr2,0,n-1,arr1[j]);
		  if(index!=-1)
		  {
			  answer+=suffix[index];
		  }
	  }
	  cout<<answer<<endl;
}


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

typedef long long ll;

int main() {
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    for ( ll i = 0; i < N; ++i){
        cin >> A[i];
    }
    
    ll x;
    ll sho, amari;
    sho = ( N - K ) / ( K - 1 );
    amari = ( N - K ) % ( K - 1 );
    x = sho + 1;
    if ( amari != 0 ) ++x;
    
    cout << x << endl;
    
    return 0;
}


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

const int N = 100005;

int n;
int a[N];

int cnt[N];

int solve() {
  scanf("%d", &n);

  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    ++cnt[a[i]];
    sum += a[i];
  }


  int q;
  scanf("%d", &q);
  while (q--) {
    int b, c;
    scanf("%d %d", &b, &c);

    sum -= 1LL * cnt[b] * b;
    sum += 1LL * cnt[b] * c;

    cnt[c] += cnt[b];
    cnt[b] = 0;

    printf("%lld\n", sum);
  }

  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 4492
def solve():  # 073C - Write and Erase
    N = int(input())
    joisino_list = {}
    cnt = 0

    for _ in range(N):
        a = int(input())

        if a in joisino_list:
            joisino_list[a] += 1
        else:
            joisino_list[a] = 1

    for i in joisino_list.values():
        if i % 2:
            cnt += 1

    print(cnt)
    
  
solve()

Measured memory_bytes: 15072
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair
#define foreach(c, it) for(typeof(c) it = (c).begin(); it != (c).end(); it++)

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int MAX = 1000000;
const int INF = 2 << 28;
const double EPS = 1e-10;

int p[4 * MAX + 1], op[4  *MAX + 1];
vector < int > num;
int main() {
    
    for(int i = 0; i < 2 + MAX + 1; i++)
        p[i] = op[i] = INF;
    
    for(int i = 1; i < 200; i++) {
        num.push_back(i * (i + 1) * (i + 2) / 6);
        p[i * (i + 1) * (i + 2) / 6] = 1;
        if((i * (i + 1) * (i + 2) / 6) % 2) op[i * (i + 1) * (i + 2) / 6] = 1;
    }

    for(int i = 1; i <= MAX; i++) {
        for(int j = 0; j <num.size(); j++) {
            if(p[i] != INF) {
                p[i + num[j]] = min(p[i] + 1, p[i + num[j]]);
            }
            if(op[i]  != INF && num[j] % 2) {
                op[i + num[j]] = min(op[i] + 1, op[i + num[j]]);
            }
        }
    }
    
    int N;
    while(cin >> N, N) {
        cout << p[N] << " " << op[N] << endl;
    }
}

Measured memory_bytes: 23736
#include<stdio.h>
#include<math.h>

int main(void){
    double x1, y1, x2, y2, distance;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    distance = sqrt((pow(x2-x1, 2) + pow(y2-y1, 2)));
    printf("%f\n", distance);
    
    return 0;
}


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

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

    int H, W;
    cin >> H >> W;
    int a[H + 1][W + 1];
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            cin >> a[i][j];
        }
    }

    int i = 1;
    int j = 1;
    vector<vector<int>> res;
    while (i <= H && j <= W) {
        if (i % 2 == 1) {
            if (j == W) {
                if (a[i][j] % 2 && i != H) {
                    a[i][j]--;
                    a[i + 1][j]++ ;
                    res.push_back({i, j, i + 1, j});
                   // printf("%d %d %d %d\n", i, j, i + 1, j);
                }
                i++;
            } else {
                if (a[i][j] % 2 == 1) {
                    a[i][j]--;
                    a[i][j + 1]++ ;
                    res.push_back({i, j, i, j + 1});
                    // printf("%d %d %d %d\n", i, j, i, j + 1);
                }
                j++;
            }
        } else {
            if (j == 1) {
                if (a[i][j] % 2 == 1 && i != H) {
                    a[i][j]--;
                    a[i + 1][j]++ ;
                    res.push_back({i, j, i + 1, j});
                    // printf("%d %d %d %d\n", i, j, i + 1, j);
                }
                i++;
            } else {
                if (a[i][j] % 2 == 1) {
                    a[i][j]--;
                    a[i][j - 1]++ ;
                    res.push_back({i, j, i, j - 1});
                    // printf("%d %d %d %d\n", i, j, i, j - 1);
                }
                j--;
            }
        }
    }

    printf("%d\n", static_cast<int>(res.size()));
    // cout << res.size() << '\n';
    for (const auto &row: res) {
        printf("%d %d %d %d\n", row[0], row[1], row[2], row[3]);
    }

    return 0;
}


Measured memory_bytes: 10032
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int N = scan.nextInt();
		 ArrayList<Work> work = new ArrayList<>(N);
		 
		 for (int i = 0; i < N; i++ ) {
			 work.add(new Work(scan.nextInt(),scan.nextInt()));
		 }
		 
		 Collections.sort(work);
		 
		 String result_msg = "Yes";
		 int used_working_time = 0;
		 for (int i = 0; i < N; i++ ) {
			 if (work.get(i).dead_line - used_working_time < work.get(i).amount_work) {
				 result_msg = "No";
				 break;
			 }
			 used_working_time += work.get(i).amount_work;
		 }
		 
		 System.out.println(result_msg);
		 
		 scan.close();
		 
	}
	
	static class Work implements Comparable<Work> {
		int amount_work;
		int dead_line;
		
		public Work(int a, int d) {
			amount_work = a;
			dead_line = d;
		}
		
		@Override
		public int compareTo(Work w) {
			return this.dead_line - w.dead_line;
		}
	}

}


Measured memory_bytes: 106208
import sys
readline = sys.stdin.readline

N = int(readline())
graph = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, readline().split())
    graph[a].append(b)
    graph[b].append(a)

parent = [0] * (N + 1)
order = []
stack = [1]
while stack:
    x = stack.pop()
    order.append(x)  # 行きがけ順探索リスト
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x  # 親ノードを記録
        stack.append(y)

MOD = 10**9 + 7
half = pow(2, MOD - 2, MOD)
power_inv = [1] * (N + 1)
size = [1] * (N + 1)
for i, v in enumerate(order[::-1], 1):
    p = parent[v]
    x = size[v]  # vの子孫ノード数（自分も含む）をとる
    size[p] += x  # 親にノード数を加算
    power_inv[i] = power_inv[i - 1] * half % MOD  # [1, 1/2, 1/4, ...]

ans = sum((1 - power_inv[i] - power_inv[N - i] + power_inv[N]) % MOD for i in size[2:])  # 解法1の確率式(ノード1を除く)
ans += (1 - power_inv[N]) - N * power_inv[1]  # +  - N/2 
ans %= MOD

print(ans)

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

int main(){
    int N, k;
    cin >> N >> k;
    vector<long long> A(N);
    for(int i = 0; i < N; i++)cin >> A[i];
    
    long long ans = 0;
    for(int i = 1; i < N; i++){
        long long dis = A[i] + A[i - 1] - k;
        if(dis <= 0)continue;
        ans += dis;
        A[i] -= dis;
        if(A[i] < 0)A[i] = 0;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

int sec(string s) {
	auto hms = s.split(":").map!(to!int).array;
	return hms[0]*60*60 + hms[1]*60 + hms[2];
}
void main(){
	while(true) {
		auto n = readInt();
		if(n == 0) return;

		auto t = new int[](24*4000);
		for(int i; i < n; ++i) {
			auto l = readln().chomp().split();
			++t[sec(l[0])];
			--t[sec(l[1])];
		}
		for(int i = 1; i < t.length; ++i) {
			t[i] += t[i-1];
		}
		writeln(reduce!(max)(t));
	}
}

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

int main() {
  int N,A,B;
  cin >>N >> A >> B;  
  int a=0;
  int b=0;
  int c=0;
  int p[N];
  for(int i=0;i<N;i++){
    cin >> p[i] ;
    if (p[i]<=A){
      a++;
    }
    else if (p[i]<=B){
      b++;
    }
    else {
      c++;
    }
  }
      cout << min(a,min(b,c))<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
 
#define DEBUG(x) cerr << #x << " = " << x << endl
 
struct Node {
    int left, right, sum;
    Node() : left(0), right(0), sum(0) { }
    Node(int l, int r, int s) : left(l), right(r), sum(s) { }
};
 
inline int Pow(int n, int k) {
    int r = 1;
    for(int i = 0; i < k; i++) r *= n;
    return r;
}
 
int main() {
    int N, X, M; cin >> N >> X >> M;
    vector<Node> cover;
    for(int i = 0; i < M; i++) {
        int l, r, s; cin >> l >> r >> s;
        l--, r--;
        cover.push_back(Node(l,r,s));
    }
    vector<int> cage(N);
    vector<int> ans_v;
    int ans_i = 0;
    for(int num = 0, len = Pow(X+1,N); num < len; num++) {
        // DEBUG(num);
        for(int i = 0; i < N; i++) {
            cage[i] = (num % Pow(X+1,i+1)) / Pow(X+1,i);
        }
 
#if 0
        for(int i = N - 1; i >= 0; i--) {
            cerr << cage[i] << " \n"[i == 0];
        }
#endif
 
        bool f = true;
        for(int i = 0; i < M; i++) {
            int s = 0;
            for(int j = cover[i].left; j <= cover[i].right; j++) {
                s += cage[j];
            }
            if(s != cover[i].sum) {
                f = false;
                break;
            }
        }
        if(f) {
            int s = accumulate(cage.begin(), cage.end(), 0);
            if(s >= ans_i) {
                ans_v = cage;
            }
        }
    }
    if(ans_v.empty()) {
        cout << -1 << endl;
    }
    else {
        for(int i = 0; i < N; i++) {
            cout << ans_v[i] << " \n"[i == N - 1];
        }
    }
}

Measured memory_bytes: 1208
while True:
    N,M = map(int,input().split())
    if N == 0:
        break
    expect = 0
    a = []
    exsum = 0
    for i in range(N): #二次元配列を作る
        a.append(list(map(int,input().split())))
        exsum += a[i][0]*a[i][1] #誰も雇わなかった場合の期待値
    b = sorted(a, key=lambda x: x[1]) #危険度の高い区間ほど後ろにくるように並べる
    i = N-1
    while M > 0 and i >= 0: #危険度が高い区間（配列のうしろ）から順に人を雇っていく
        if b[i][0] <= M:
            exsum -= b[i][0]*b[i][1]
            M -= b[i][0]
            i -= 1
        else:
            exsum -= b[i][1]*M
            M = 0
            i -= 1
    print(exsum)


Measured memory_bytes: 7224
#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
#define pb push_back
#define input l1 t;cin>>t;while(t--)
l1 min(l1 a,l1 b){
    l1 ma=(a<b)?a:b;
    return ma;
}
l1 max(l1 a,l1 b){
    l1 ma=(a>b)?a:b;
    return ma;
}
l1 gcd(l1 a, l1 b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
# define pie 3.14159265358979323
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    l1 n,m,x;
    cin>>n;
    vector<l1 >a,b;
   for(l1 i=0;i<n;i++){
       b.pb(0);
   }
    l1 s=0;
    for(l1 i=1;i<n;i++){
        cin>>x;
        b[x-1]++;
    }
    for(l1 i=0;i<n;i++){
        cout<<b[i]<<endl;
    }
        
}
 

Measured memory_bytes: 5340
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(int argc, char const *argv[])
{
    int n,m;cin>>n>>m;
    vector<ll> a(n);
    vector<pair<ll,ll>> cb(m) ;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(), a.end());
    for(int i=0;i<m;i++){
        int b,c;cin>>b>>c;
        cb[i]=make_pair(c,b);
    }
    sort(cb.begin(), cb.end());
    reverse(cb.begin(), cb.end());
    int idx =0;
    bool is_done = false;
    for(int i=0;i<m;++i){
        for(int j=0;j<cb[i].second;j++){
            // idx += j;
            if(idx==n){
                is_done = true;
                break;
            }
            if(a[idx]<cb[i].first){
                a[idx]=cb[i].first;
                idx++;
            }
            else{
                is_done = true;
                break;
            }
        }
        if(is_done)break;
    }
    
    ll sum =0;
    for(int i=0;i<n;i++)sum+=a[i];
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 2560
/*----------------by syr----------------*/
/*
  -----  -----  -----
  |   |  |---|    _/
  |   |  | \_    /
  -----  |   \  -----

  |---\  \   /  |\  /|
  |   |   \_/   | \/ |
  |   |   / \   |    |
  |---/  /   \  |    |
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i,x,y) for(int i=(x);i<(y);++i)
#define REP(i,x,y) for(int i=(x);i<=(y);++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;

const int INF=1e9+7;
const int maxn=1e3+5;

int n,m;
int dp[maxn][maxn];
char s[maxn][maxn];

int main(){
	scanf("%d%d",&n,&m);
	FOR(i,0,n) scanf("%s",s+i);
	dp[0][0]=1;
	FOR(i,0,n){
		FOR(j,0,m){
			if(i) dp[i][j]+=dp[i-1][j],dp[i][j]%=INF;
			if(j) dp[i][j]+=dp[i][j-1],dp[i][j]%=INF;
			if(s[i][j]=='#') dp[i][j]=0;
		}
	}
	printf("%d\n",dp[n-1][m-1]);
	return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
int main(){
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    for(ll i = 1;i <= n;i++){
        if(i > k){
            ans += (n / i) * (i - k);
            ans += max(0LL,n % i - k + 1LL);
        }
    }
    if(k != 0){
        cout << ans << endl;
    }
    else cout << n * n << endl;
} 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main(){
    double a;
    int b = 0;
    int c = 0;
    int x, y;
     
    cin >> x >> y;
    a = (double)x / y;
    b = x % y;
    c = x / y;
    cout << c << " " << b << " " << fixed << setprecision(5) << a << endl;
}


Measured memory_bytes: 3288
#include <iostream>
#include <utility>

#define maxS 1005
#define MOD 1000000007

using namespace std;

typedef long long ll;

bool grid[maxS][maxS];
int h, w;
ll cache[maxS][maxS];

ll rec(int r, int c) {
    if (r >= h || c >= w || !grid[r][c]) return 0;
    if (r == h-1 && c == w-1) return 1;
    if (cache[r][c] != -1) return cache[r][c];
    return cache[r][c] = (rec(r+1, c) + rec(r, c+1))%MOD;
}

int main() {
    cin >> h >> w;
    for (int r = 0; r<h; r++) {
        for (int c = 0; c<w; c++) {
            cache[r][c] = -1;
            char f;
            cin >> f;
            grid[r][c] = (f == '.');
        }
    }
    cout << rec(0, 0) << endl;
    return 0;
}

Measured memory_bytes: 9216
k = int(input())
n = len(input())
p = 10**9 + 7
a = 1
fct = [a]
for i in range(1, n + k + 1):
    a = (a * i) % p
    fct.append(a)
b = pow(fct[-1], p - 2, p)
inv = [b]
for i in range(1, n + k + 1)[::-1]:
    b = (b * i) % p
    inv.append(b)
inv.reverse()
ans = 0
pow25, pow26 = [1], [1]
for i in range(1, k + 1):
    pow25.append((pow25[-1] * 25) % p)
    pow26.append((pow26[-1] * 26) % p)
for i in range(k + 1):
    c = fct[i + n - 1] * inv[i] * inv[n - 1]
    ans += pow25[i] * pow26[k - i] * c
    ans %= p
print(ans)


Measured memory_bytes: 201004
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ARounding solver = new ARounding();
        solver.solve(1, in, out);
        out.close();
    }

    static class ARounding {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            w.println(s.nextInt() < s.nextInt() ? 0 : 10);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21588
package main

import "fmt"

var (
	c   [3][3]int
	ans string
)

func dfs(a0 int) {
	b := make([]int, len(c))
	for j := range b {
		b[j] = c[0][j] - a0
		if b[j] < 0 {
			return
		}
	}
	flg := false
	for i := 1; i < len(c); i++ {
		for j := range make([]struct{}, len(c)-1) {
			if c[i][j]-b[j] != c[i][j+1]-b[j+1] {
				flg = true
				break
			}
		}
		if flg {
			break
		}
	}
	if !flg {
		ans = "Yes"
		return
	}
	dfs(a0 + 1)
}

func main() {
	for i := range c {
		for j := range c[i] {
			fmt.Scan(&c[i][j])
		}
	}
	ans = "No"
	dfs(0)
	fmt.Println(ans)
}


Measured memory_bytes: 512