akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

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

int main()
{
	cout << fixed << setprecision(10);

	int h, w, k;
	cin >> h >> w >> k;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	x1--;
	y1--;
	x2--;
	y2--;

	vector<string> m(h);
	REP(i, h)
	{
		cin >> m[i];
	}


	vector<vector<int>> dist(h, vector<int>(w, INF));

	queue <tuple<int, int, int>> q;
	q.emplace(0, x1, y1);

	dist[x1][y1] = 0;

	while (q.empty() == false)
	{
		auto [c, x, y] = q.front();
		if (dist[x][y] != c)continue;
		q.pop();

		REP(j, 4)
		{
			int nx = x;
			int ny = y;
			FOR(i, 1, k + 1)
			{
				nx += dx[j];
				ny += dy[j];
				if (nx < 0 || h <= nx || ny < 0 || w <= ny)break;
				if (m[nx][ny] == '@')break;

				if (dist[nx][ny] <= c)break;

				if (dist[nx][ny] != c + 1)
				{
					dist[nx][ny] = c + 1;
					q.emplace(c + 1, nx, ny);
				}
			}
		}
	}
	if (dist[x2][y2] == INF)
	{
		cout << -1;
		return 0;
	}
	cout << dist[x2][y2];
	return 0;
}


Measured memory_bytes: 12128
# coding: utf-8

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import

def array2d(row, col, init = None):
    return [[init for _ in range(col)] for _ in range(row)]

N, W = map(int, input().split(" "))
v = []
w = []
for i in range(N):
    vi, wi = map(int, input().split(" "))
    v.append(vi)
    w.append(wi)

dpt = array2d(N + 1, W + 1)

def dp(i, j):
    if dpt[i][j] is not None:
        return dpt[i][j]
    if i == 0:
        dpt[i][j] = 0
        return 0
    if j < w[i-1]:
        dpt[i][j] = dp(i-1, j)
        return dpt[i][j]
    dpt[i][j] = max(dp(i-1, j), dp(i, j-w[i-1]) + v[i-1])
    return dpt[i][j]

for i in range(N + 1):
    for j in range(W + 1):
        dp(i, j)
print(dp(N, W))

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

ll fact[100005], factinv[100005];
const ll m = 1000000007;
ll powm(ll b, ll p)
{
    if (p == 0)
        return 1;
    if (p % 2 == 1)
        return b * powm(b, p - 1) % m;
    else
    {
        ll t = powm(b, p / 2);
        return t * t % m;
    }
}
ll inv(ll x)
{
    return powm(x, m - 2);
}
void fac(int k)
{
    fact[0] = 1;
    for (int i = 1; i < k; i++)
    {
        fact[i] = fact[i - 1] * i % m;
    }
    for (int i = 0; i < k; i++)
    {
        factinv[i] = inv(fact[i]);
    }
}
ll ncrmod(int n, int r)
{
    return fact[n] * factinv[r] % m * factinv[n - r] % m;
}
int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    fac(100005);
    ll ans = 0;
    for (int i = k - 1; i < n; i++)
    {
        ans = (ans + a[i] * ncrmod(i, k - 1)) % m;
        ans = (ans - a[n - 1 - i] * ncrmod(i, k - 1)) % m;
        ans = (ans + m) % m;
    }
    cout << ans % m << endl;
}


Measured memory_bytes: 5540
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w = map(int, readline().split())
a = [readline().rstrip().decode() for _ in range(h)]
dp = [[0] * w for _ in range(h)]
mod = 10 ** 9 + 7
dp[0][0] = 1

for i in range(h):
    for j in range(w):
        if a[i][j] != '#':
            if i != h - 1:
                if a[i + 1][j] != '#':
                    dp[i + 1][j] += dp[i][j]
                    dp[i + 1][j] %= mod
            if j != w - 1:
                if a[i][j + 1] != '#':
                    dp[i][j + 1] += dp[i][j]
                    dp[i][j + 1] %= mod
print(dp[-1][-1] % mod)


Measured memory_bytes: 43700
INF = 10 ** 14

def compute_edge(arr, q)
  i = arr.bsearch_index { |x| x >= q }
  return [arr.last] if i.nil?
  return [q] if arr[i] == q
  return [arr[0]] if i == 0
  return [arr[i - 1], arr[i]]
end

def lazy_faith(s, t, q)
  ans = INF
  compute_edge(s, q).each do |se|
    min_cost = INF
    cost = (se - q).abs
    compute_edge(t, se).each do |te|
      min_cost = [min_cost, cost + (se - te).abs].min
    end
    ans = [ans, min_cost].min
  end

  compute_edge(t, q).each do |te|
    min_cost = INF
    cost = (te - q).abs
    compute_edge(s, te).each do |se|
      min_cost = [min_cost, cost + (se - te).abs].min
    end
    ans = [ans, min_cost].min
  end
  ans
end


A, B, Q = gets.split.map(&:to_i)
s = []
A.times{ s << gets.to_i }
t = []
B.times{ t << gets.to_i }
Q.times do
  puts lazy_faith(s, t, gets.to_i)
end


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

#define mp              make_pair
#define pb              push_back
#define ff              first
#define ss              second
#define inc(A,B)        A=(A+(B))%MOD
#define mul(A,B)        (ll(A)*ll(B)%ll(MOD))
#define sub(a,b)        (((a)-(b)+MOD)%MOD)

typedef long long ll;
typedef pair < ll ,int > pli;
typedef pair < int ,int > pii;
typedef complex < ll > pt;

const int MAX_N = 500;
const int MOD = 1e9 + 7;

int n, c;
int col[MAX_N][MAX_N];
int mat[MAX_N][MAX_N];
int cost[3][MAX_N];
vector <pii> groups[3];

void floydWarshall () {
  for ( int k = 0; k < c; ++k )
    for ( int i = 0; i < c; ++i )
      for ( int h = 0; h < c; ++h )
        col[i][h] = min ( col[i][h], col[i][k] + col[k][h] );
}

void divide () {
  for ( int i = 0; i < n; ++i )
    for ( int h = 0; h < n; ++h )
      groups[(i+h+2)%3].pb ( mp ( i, h ) );
}

void doCostFor ( int ind ) {
  for ( pii &it : groups[ind] )
    for ( int i = 0; i < c; ++i )
      cost[ind][i] += col[mat[it.ff][it.ss]][i];
}

int genRes () {
  int res = INT_MAX;
  for ( int i = 0; i < c; ++i ){
    for ( int h = 0; h < c; ++h ) {
      if ( h == i ) continue;
      for ( int j = 0; j < c; ++j ) {
        if ( j == h or j == i ) continue;
        res = min ( res, cost[0][i]+cost[1][h]+cost[2][j] );
      }
    }
  }
  return res;
}

int main() {

//  freopen ( "in.txt" , "r" , stdin );
//  freopen ( "out.txt" , "w" , stdout );

  scanf ( "%d%d", &n, &c );
  for ( int i = 0; i < c; ++i )
    for ( int h = 0; h < c; ++h )
      scanf ( "%d", &col[i][h] );

  for ( int i = 0; i < n; ++i ) {
    for ( int h = 0; h < n; ++h ) {
      scanf ( "%d", &mat[i][h] );
      --mat[i][h];
    }
  }

  for ( int i = 0; i < c; ++i )
    col[i][i] = 0;

//  floydWarshall ();
  divide ();
  for ( int i = 0; i < 3; ++i )
    doCostFor ( i );

  printf ( "%d\n", genRes () );


  return 0;

}

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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef vector<ll,ll> vll;
typedef pair<ll,ll> pll;

ld DP[3001][3001];

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n;
	cin >> n;
	vector<ld> prob(n);
	M00(i, 3001) M00(j, 3001) DP[i][j] = 0;
	M00(i, n) cin >> prob[i];
	DP[0][0] = 1.0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= i; j++) {
			DP[i][j] = DP[i-1][j] * (1.0 - prob[i-1]);
			if(j > 0)
				DP[i][j] += DP[i-1][j-1] * prob[i-1];
		}
	}
	ld ans = 0;
	for(int j = 0; j <= n; j++) {
		if(j > n - j) ans += DP[n][j];
	}
	cout << fixed << setprecision(12);
	finish(ans);

}


Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main() {
  string s;
  cin>>s;
  int n=s.size();

  vector<int> p(n);
  int cnt=0;
  rep(i,n){
    if(s[i]=='R') cnt++;
    else {
      p[i-1]+=(cnt+1)/2;
      p[i]+=cnt/2;
      cnt=0;
    }
  }

  for(int i=n-1;i>=0;i--){
    if(s[i]=='L') cnt++;
    else {
      p[i+1]+=(cnt+1)/2;
      p[i]+=cnt/2;
      cnt=0;
    }
  }

  rep(i,n){
    cout << p[i];
    if(i!=n-1) cout << " ";
  }

  cout << endl;
}

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

int main() {
  long n,m;
  cin >> n >> m;
  long ans = 0;
  if(n <= m/2){
    ans = n;
    m = m -2*n;
    m = m/4;
    ans += m;
  }
  else {
    ans = m/2;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import copy

n = int(input())

l = list(input().split())
C1 = []

for v in l:
    s = v[0]
    m = int(v[1])
    C1.append((s, m))

C2 = copy.deepcopy(C1)

for i in range(n):
    for j in range(n-1, i, -1):
        if C1[j][1] < C1[j-1][1]:
            C1[j], C1[j-1] = C1[j-1], C1[j]

for i in range(n):
    minj = i
    for j in range(i,n):
        if C2[j][1] < C2[minj][1]:
            minj = j
    C2[i], C2[minj] = C2[minj], C2[i]

result1 = [t[0]+str(t[1]) for  t in C1]
result2 = [t[0]+str(t[1]) for  t in C2]

print(" ".join(result1))
print("Stable")
print(" ".join(result2))
if result1 == result2:
    print("Stable")
else:
    print("Not stable")



Measured memory_bytes: 6348
#include<bits/stdc++.h>
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) 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 F(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define VE(i,v) for(int i = 0;i < (v).size();i++)

using namespace std;
#define trace(...) cerr<<__FUNCTION__<<":"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned int ui;
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
typedef pair<ll,ll> pll;
typedef vector<pll> vpll; 
 




int main()

{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int T;
	T=1;
	for(int tc=1; tc<=T;tc++)
	{
		int A, B;
		cin >> A >>B;
		set<int> ch;
		ch.insert(A);
		ch.insert(B);
		if(ch.find(1)==ch.end())
			cout<<"1\n";
		if(ch.find(2)==ch.end())
			cout<<"2\n";
		if(ch.find(3)==ch.end())
			cout<<"3\n";

	}
 
 
 
	return 0;
}
 
 


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

using namespace std;

int w, h, nchoco, choco[10][10];
bool visited[10][10];
int dy[]={-1, 0, 1, 0};
int dx[]={0, 1, 0, -1};
int tdy[4];
int tdx[4];

bool dfs(int y1, int x1, int y2, int x2, int &cnt){
  cnt++;
  if(cnt*2==nchoco) return true;
  visited[y1][x1]=visited[y2][x2]=true;
  for(int i=0;i<4;i++){
    int ty1,  tx1, ty2, tx2;
    ty1=y1+dy[i];
    tx1=x1+dx[i];
    ty2=y2+tdy[i];
    tx2=x2+tdx[i];
    if(ty1<0 || ty1>=h) continue;
    if(ty2<0 || ty2>=h) continue;
    if(tx1<0 || tx1>=w) continue;
    if(tx2<0 || tx2>=w) continue;
    if(ty1==ty2 && tx1==tx2) continue;
    if(visited[ty1][tx1] || visited[ty2][tx2]) continue;
    if(choco[ty1][tx1]==0 || choco[ty2][tx2]==0) continue;
    if(dfs(ty1, tx1, ty2, tx2, cnt)) return true;
  }
  return false;
}

string solve(){
  if(nchoco%2!=0) return "NO";
  for(int i=0;i<4;i++){
    tdy[i]=dy[i];
    tdx[i]=dx[i];
  }
  for(int a=0;a<2;a++){
    for(int b=0;b<4;b++){
      rotate(tdy, tdy+1, tdy+4);
      rotate(tdx, tdx+1, tdx+4);
      for(int c=0;c<h;c++){
	for(int d=0;d<w;d++){
	  if(choco[c][d]==0) continue;
	  for(int e=0;e<h;e++){
	    for(int f=0;f<w;f++){
	      if(c==e && d==f) continue;
	      if(choco[e][f]==0) continue;
	      int cnt=0;
	      fill(visited[0], visited[10], false);
	      if(dfs(c, d, e, f, cnt)) return "YES";
	    }
	  }
	}
      }
    }
    tdy[1]=dy[3];
    tdx[1]=dx[3];
    tdy[3]=dy[1];
    tdx[3]=dx[1];
  }
  return "NO";
}

main(){
  while(1){
    cin >> w >> h;
    if(w==0 && h==0) break;
    nchoco=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> choco[i][j];
	if(choco[i][j]==1) nchoco++;
      }
    }
    fill(visited[0], visited[10], false);
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 904
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }


//aI aO aT aJ aL aS aZ

ll ni,no,nt,nj,nl,ns,nz;

void run() {
	scanf("%lld%lld%lld%lld%lld%lld%lld",&ni,&no,&nt,&nj,&nl,&ns,&nz);
	ll ret=0;
	REP(nijl,2) {
		ll ci=ni-nijl,cj=nj-nijl,cl=nl-nijl,cur=3*nijl;
		if(ci<0||cj<0||cl<0) continue;
		cur+=no; cur+=2*(ci/2); cur+=2*(cj/2); cur+=2*(cl/2); if(cur>ret) ret=cur;
	}
	printf("%lld\n",ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    string a,b,c; cin >> a >> b >> c;
    cout << ((a[a.size()-1] == b[0] && b[b.size()-1] == c[0])?"YES":"NO") <<endl; return 0;
}


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

#define int long long

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

int N, M;
string A[100], B[100];

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int cur = 0;
        for (int j = 0; j < N; j++) {
            if (A[i] == A[j]) {
                cur++;
            }
        }
        for (int j = 0; j < M; j++) {
            if (A[i] == B[j]) {
                cur--;
            }
        }
        ans = max(cur, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] L = new int[N];
        for (int i = 0; i < N; i++) {
            L[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                for (int k = j+1; k < N; k++) {
                    if (L[i] != L[j] && L[i] != L[k] && L[j] != L[k]) {
                        if (L[i] + L[j] > L[k]
                            && L[j] + L[k] > L[i]
                            && L[k] + L[i] > L[j]) {
                            ans++;
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 36828
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int k,x,y;
  vector<int> di;
  vector<string> ds;
  
  cin>>k;
  cin>>x;
  rep(i,x){
    int ini;
    string ins;
    cin>>ins;
    cin>>ini;
    bool used = false;
    rep(i,ins.size()){
      if(ins[i] != 'D'){
	used = true;
	break;
      }
    }
    if(used)continue;
    di.push_back(ini);
    ds.push_back(ins);
  }

  cin>>y;
  rep(i,y){
    int ini;
    string ins;
    cin>>ins;
    cin>>ini;
    bool used = false;
    rep(i,ins.size()){
      if(ins[i] != 'D'){
	used = true;
	break;
      }
    }
    if(used)continue;
    di.push_back(ini);
    ds.push_back(ins);
  }
  int res = 0;
  for(int i = 0 ; i < int(1 << di.size()) ; i++){
    int cnt = 0;
    int sum = 0;
    bool used = false;
    for(int j = 0 ; j < di.size() ; j ++){
      if((i/(1<<j))%2){
	//cout<<j<<" ";
	cnt += ds[j].size();
	if(cnt > k){
	  used = true;
	  break;
	}
	sum += di[j];
      }
    }		
    if(used){
      continue;
    }
    //cout<<"cnt"<<cnt<<" ";
    res = max(sum,res);
    //cout<<endl;
  }
  cout<<res<<endl;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

P f(P p, int x, int y) {
    ll a = p.first, b = p.second;

    ll n = max((a + x - 1) / x, (b + y - 1) / y);

    return P(x * n, y * n);
}

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

    vector<int> T(N), A(N);
    rep(i, N) {
        cin >> T[i] >> A[i];
    }

    P ans = P(T[0], A[0]);
    rep(i, N) {
        ans = f(ans, T[i], A[i]);
    }

    cout << ans.first + ans.second << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;cin>>s;
    for(int i=0;s[i+1];i++){
        if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2]){
            cout<<i+1<<" "<<(s[i+2]?i+3:i+2)<<"\n";
            return 0;
        }
    }
    cout<<-1<<" "<<-1<<"\n";
    return 0;
}


Measured memory_bytes: 512
from collections import defaultdict

data = defaultdict()
cnt = defaultdict(int)
for i in range(3):
    s = input()
    data[chr(ord("a") + i)] = s

turn = "a"
while 1:
    cnt[turn] += 1
    if cnt[turn] > len(data[turn]):
        ans = ord(turn) - (ord("a") - ord("A"))
        break

    turn = data[turn][cnt[turn] - 1]
print(chr(ans))

Measured memory_bytes: 3316
#include<cstdio>
int a[501][501],b[250001];
int main(){
    int h,w,n=0;
    scanf("%d%d",&h,&w);
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            scanf("%d",&a[i][j]);
            b[(i-1)*w+((i%2==1)?(j-1):(w-j))]=a[i][j];
        }
    }
    for(int i=0;i<h*w-1;i++){
        if(b[i]%2==1){
            b[i+1]++;
            n++;
        }
    }
    printf("%d\n",n);
    for(int i=1;i<=h;i+=2){
        for(int j=1;j<=w-1;j++){
            if(a[i][j]%2==1){
                a[i][j+1]++;
                printf("%d %d %d %d\n",i,j,i,j+1);
            }
        }
        if(i<h){
            if(a[i][w]%2==1){
                a[i+1][w]++;
                printf("%d %d %d %d\n",i,w,i+1,w);
            }
            for(int j=w;j>1;j--){
                if(a[i+1][j]%2==1){
                    a[i+1][j-1]++;
                    printf("%d %d %d %d\n",i+1,j,i+1,j-1);
                }
            }
            if(i+1<h && a[i+1][1]%2==1){
                a[i+2][1]++;
                printf("%d %d %d %d\n",i+1,1,i+2,1);
            }
        }
    }
}


Measured memory_bytes: 3968
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int inM = in.nextInt();
		int inD = in.nextInt();
		System.out.println(solvex(inM, inD));
		in.close();
	}

	private static int solvex(int inM, int inD) {
		int r = 0;
		for (int d10 = 2; d10 <= inD / 10; d10++)
			for (int d1 = 2; d1 <= 9 && d1 <= inD - d10 * 10; d1++)
				if (d10 * d1 <= inM)
					r++;
		return r;
	}
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const LL INF = 1e18;
const LL MOD = 1e9 + 7;

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

void END(){cout << 1 << endl; exit(0);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  vector<VB> check(10, VB(10, false));
  VB left(10, false);
  VI ct(n, 0);
  VB num(10, false);
  int v = 0;
  REPR(i, n)
  {
    ct[i] = v;
    if (num[s[i]-'0']) continue;
    num[s[i]-'0'] = true;
    v++;
  }
  REP(i, n-2)
  {
    if (left[s[i]-'0']) continue;
    left[s[i]-'0'] = true;
    REP2(j, i+1, n-1)
    {
      if (check[s[i]-'0'][s[j]-'0']) continue;
      check[s[i]-'0'][s[j]-'0'] = true;
      ans += ct[j];
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
    int t[5],mini,min = 10,ans = 0;
    for (int i = 0; i < 5; i++)
    {
        scanf("%d",&t[i]);
        if(t[i] % 10 != 0)
        {
            if(min > t[i] % 10)
            {
                min = t[i] % 10;
                mini = i;
            }
        }
    }

    for (int i = 0; i < 5; i++)
    {
        if(mini == i)
        {
            ans += t[i];
        }
        else
        {
            if(t[i] % 10 == 0)
            {
                ans += t[i];
            }
            else
            {
                ans += t[i] + 10 - t[i] % 10;
            }
        }
    }

    printf("%d\n",ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin>>t;
	ll a[t],b[t];
	for(int i = 0;i <t; i++)
	{
		cin>>a[i];
		b[i] = a[i];
	}
	ll ans = 0,sum = 0,sum2=0;
	for(int i = 1; i<t; i+=2)
	{
		if(i==1)
		{
			if(b[i-1]>=0)
			{
				ans += b[i-1]+1;
				b[i-1] = -1;
			}
		}
		sum += b[i]+b[i-1];
		if(sum<=0)
		{
			ans += (1-sum);
			sum = 1;
		}
		if(i<t-1)
		{
			sum2 = sum+b[i+1];
			if(sum2>0)
			{
				ans += (sum2+1);
				b[i+1] -= (sum2+1);
			}
			else if(sum2==0) 
			{
				ans++;
				b[i+1]--;
			}
		}
	}
	sum = 0,sum2=0;
	ll ans2 = 0;
	for(int i = 0; i<t;i+=2)
	{
		sum += a[i];
		if(i!=0) sum+=a[i-1];
		if(sum<=0)
		{
			ans2 += (1-sum);
			sum = 1;
		}
		if(i<t-1)
		{
			sum2 = sum+a[i+1];
			if(sum2>0)
			{
				ans2 += (sum2+1);
				a[i+1] = -(sum+1);
			}
			else if(sum2==0) 
			{
				ans2++;
				a[i+1]--;
			}
		}
	}
	// cout<<ans<<" "<<ans2<<endl;
	cout<<min(ans,ans2)<<endl;
	return 0;
}

Measured memory_bytes: 1792
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 1e9+1;
//
//
bool oper(const pair<ll, ll>& fst, const pair<ll, ll>& snd){
    return (fst.first + fst.second) < (snd.first + snd.second);
}
void solve(){
    ll n;
    cin>>n;
    vector<pair<ll, ll>> vec(n);
    for(int i = 0; i < n; i++)
        cin>>vec[i].first>>vec[i].second;
    sort(vec.begin(), vec.end(), oper);
    ll ans = 0;
    pair<ll, ll> fst = vec[0], snd = vec[n-1];
    ans = max(ans, abs(snd.first - fst.first) + abs(snd.second - fst.second));
    // cout<<ans;
    for(int i = 0; i < n; i++)
        vec[i].second = MAX - vec[i].second;
    sort(vec.begin(), vec.end(), oper);
    fst = vec[0], snd = vec[n-1];
    ans = max(ans, abs(snd.first - fst.first) + abs(snd.second - fst.second));
    cout<<ans;
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 6360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int k,x; cin >> k >> x;
    vector<int> v;
    v.push_back(x);
    REP(i,1,k){
        if(i+x<=1000000){
            v.push_back(i+x);
        }
    }
    REP(i,1,k){
        if(x-i>=-1000000){
            v.push_back(x-i);
        }
    }
    sort(ALL(v));
    for(auto a:v){
        cout << a << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma region

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10) << boolalpha;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  string S;
  cin >> S;
  rep(i, S.length()) {
    cout << "x";
  }
  cout << endl;
}


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

using lint = long long;
#define bit(n) ((lint)1 << n);
const int INF = 1e9;
const lint LINF = 1e18;

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

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

    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200005
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
		ll n;
		cin >> n;
		vector<ll> a(maxn),sum(maxn);
		for (int i=0 ; i<n ; i++) 
		{
			cin >> a[i];
			sum[i] = a[i];
		}
		sum[n] = 0;
		for (int i=n-1 ; i>=0 ; i--)
		sum[i]+=sum[i+1];
		
		ll ans = 0;
		for (int i=0 ; i<n ; i++)
		ans = (ans + (a[i] * (sum[i + 1] % MOD))) % MOD;
		cout << ans << endl;
		return 0;
}  


Measured memory_bytes: 6364
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 1050;

int N, M;
long long para[MAX_N][3];

int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= N; i++) {
        std::cin >> para[i][0] >> para[i][1] >> para[i][2];
    }
    
    long long ret = 0;
    for (int p0 = -1; p0 <= 1; p0 += 2) {
        for (int p1 = -1; p1 <= 1; p1 += 2) {
            for (int p2 = -1; p2 <= 1; p2 += 2) {
                std::vector<long long> vec;
                for (int i = 1; i <= N; i++) {
                    vec.push_back(para[i][0]*p0 + para[i][1]*p1 + para[i][2]*p2);
                }
                std::sort(vec.begin(), vec.end(), std::greater<long long>());
                long long tmp = 0;
                for (int i = 0; i < M; i++) {
                    tmp += vec[i];
                }
                ret = std::max(ret, tmp);
            }
        }
    }

    std::cout << ret << std::endl;

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)


void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	ll n,x,y; cin >> n;
//	vvi a(n,vi(n));
	vector<pii> v;
	REP(i,n) {
		cin >> x >> y;
		v.push_back({y,x}); // deadline, time needed
	}
	SORT(v);
	ll t=0, ok=1;
	REP(i,n){
		t+=v[i].second;
		if(t>v[i].first){
			ok=0;
			break;
		}
	}
	if(ok) OUT("Yes");
	else OUT("No");
    return 0;
}

Measured memory_bytes: 5336
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template

//main
signed main(){
  int N;cin>>N;
  typedef pair<string,int> P;
  std::vector<P> v(N),w(N);
  for(int i=0;i<N;i++){
    int a;string s;cin>>s>>a;
    v[i]=P(s,-a);
    w[i]=P(s,-a);
  }
  sort(v.begin(),v.end());
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(v[i]==w[j]){
        cout<<j+1<<endl;
        break;
      }
    }
  }
}


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

using namespace std;

struct expand_type {
    template <typename... T>
    expand_type (T&&...) {}
};
template <typename... ArgTypes>
void print (ArgTypes... args) {
    expand_type {0, (cerr << args << ", ", 0)...};
    cerr << "\b\b \n";
}
#define printv(x) cerr << "["; for(auto i : (x)) cerr << i << ", "; cerr << "\b\b]\n";
#define __lcm(a,b) a * b / __gcd(a, b)

typedef unsigned long long ull;
typedef long double ld;


void solve () {

}

int main () {
    std::ios::sync_with_stdio (false);
    cin.tie (nullptr);
    cout.tie (nullptr);
    char c;
    cin >> c;
    cout << (c >= 'a' ? 'a' : 'A') << endl;
    return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>;
using namespace std;
 
const int N = 1e5 + 100;
const int NN = 1e8 + 100;
 
int n, h[N], d[N];
int main ()
{
    cin >>n;
    for (int i = 1; i<=n; i++)
    {
        d[i] = NN;
        cin >>h[i];
    }
    d[1] = 0;
    d[2] = abs(h[2] - h[1]);
    for (int i = 3; i<=n; i++)
    {
        int mi = 1e9;
        for (int u = 1; u <=2; u++)
        {
            //cout <<d[i - u] <<" " <<h[i] <<" " <<h[i - u] <<" - " <<i <<" " <<u <<endl;
            mi = min(mi, d[i - u] + abs(h[i] - h[i - u]));
        }
        d[i] = mi;
    }
    cout <<d[n];
    return 0;
}

Measured memory_bytes: 1024
A,B,C = map(int,input().split())
ans = 0
if A%2 == B%2 == C%2:
    ans -= 1
elif A%2 == B%2:
    A += 1
    B += 1
elif B%2 == C%2:
    B += 1
    C += 1
else:
    C += 1
    A += 1
D = [A,B,C]
D.sort()
ans += (2*D[2]-D[1]-D[0])//2
print(ans+1)

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

double make_distance(pair<int, int> a, pair<int, int> b){
    int x1 = a.first;
    int y1 = a.second;
    int x2 = b.first;
    int y2 = b.second;
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}

double calculate(vector<int> v, vector<P> p) {
    double ret = 0;
    for (int i = 1; i < v.size(); i++) {
        ret += make_distance(p[v[i]], p[v[i-1]]);
    }
    return ret;
}

void permutation(int k, int n, set<int> st, vector<int> row, vector<vector<int>> &matrix) {
    if (k < n-1) {
        for (auto itr = st.begin(); itr != st.end(); itr++) {
            set<int> copy_st = st;
            vector<int> copy_row = row;
            copy_row.push_back(*itr);
            copy_st.erase(*itr);
            permutation(k+1, n, copy_st, copy_row, matrix);
        }
    }
    if (k == n-1) {
        auto itr = st.begin();
        row.push_back(*itr);
        matrix.push_back(row);
    }
}

int main() {
    int n;
    cin >> n;
    vector<P> a;
    rep(i,n) {
        int x, y;
        cin >> x >> y;
        a.push_back(make_pair(x, y));
    }
    set<int> st;
    rep(i,n) {
        st.insert(i);
    }
    vector<int> row;
    vector<vector<int>> matrix;
    permutation(0, n, st, row, matrix);
    double sum_distance = 0;
    rep(i,matrix.size()) {
        sum_distance += calculate(matrix[i], a);
    }
    double ans = sum_distance / matrix.size();
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 3384
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int key = 0;
        int num = 0;
        boolean flag = false;
        Map<Integer, Integer> map = new HashMap<>();

        for(int i = 1; i < N; i++) {
        	key = sc.nextInt();
        	flag = map.containsKey(key);
        	if(flag) {
        		num = map.get(key);
        		num++;
        		map.put(key, num);
        	} else {
        		map.put(key, 1);
        	}
        }

        for(int j = 1; j <= N; j++) {
        	if(map.get(j) != null) {
        		System.out.println(map.get(j));
        	} else {
        		System.out.println(0);
        	}
        }
    }
}

Measured memory_bytes: 67556
#include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

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

	string o, e;
	cin >> o >> e;

	for (int i = 0; i < o.size(); i++) {
		cout << o[i];
		if (i < e.size()) {
			cout << e[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>power;
int main()
{
    ll q;
    ll x;
    cin>>n>>q;
    FOR(i,q)
    {
        cin>>a;
        sum+=a;
    }
    x=n-sum;
    if(x<0) x=-1;
    cout<<x<<endl;
    return 0;
}


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

using namespace std;

int main(){
    int x;
    cin >> x;
    
    int s, aux;
    aux = x / 500;
    s = aux * 1000;
    x = x - (aux * 500);
    aux = x / 5;
    s = s + (aux * 5);

    cout << s << endl;


    
    return 0;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int H, W;
	char a[110][110];
	
	cin >> H >> W;
	
	rep(i, H)
		rep(j, W)
			cin >> a[i][j];
	
	rep(i, H+2){
		rep(j, W+2){
			if(j == 0 || j == W+1 || i == 0 || i == H+1)
				cout << '#';
			else
				cout << a[i-1][j-1];
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
m = A[0]

dp = [False] * (K+1)

for k in range(m, K+1):
  for a in A:
    if k - a < 0:
      continue
    if not dp[k-a]:
      dp[k] = True
      break

if dp[K]:
  print('First')
else:
  print('Second')

Measured memory_bytes: 3828
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int lis[200000];
int AC[200000];
int main(){
    int N,M;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int a;
        string b;
        cin>>a>>b;
        if(b[0]=='A')AC[a]=1;
        else{
            if(AC[a]==0)lis[a]++;
        }
    }
    int ans=0;
    int answa=0;
    for(int i=1;i<=N;i++){
        if(AC[i]!=0){
            ans++;
            answa+=lis[i];
        }
    }
    cout<<ans<<" "<<answa<<endl;
    return 0;
}


Measured memory_bytes: 1024
import numpy as np
N, W = map(int, input().split())
wv = np.array([list(map(int, input().split())) for _ in range(N)])

dp = np.zeros(W+1, dtype=np.int64)

for w, v in wv:
    dp[w:] = np.maximum(dp[w:], dp[:W-w+1]+v)

ans = dp[W]
print(ans)


Measured memory_bytes: 21160
#include <bits/stdc++.h>   
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a; return gcd(b, a % b);}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
  #ifndef ONLINE_JUDGE   
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main(){
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll mult=1;
    bool ok=1,ok2=1;
    for(ll i=0;i<n;i++){
        if(a[i]==0){
            cout<<0<<endl;
            return 0;
        }
        else{
            ok2=0;
        }
    }
    for(ll i=0;i<n;i++){
        if(mult*a[i]>INF){
            ok=0;
            break;
        }
        else{
            mult*=a[i];
        }
        if(mult==0 and ok2==0){
          cout<<-1<<endl;
          return 0;
        }
    }
    if(mult==0 and ok2==0){
        cout<<-1<<endl;
        return 0;
    }
    if(mult<0 or mult>INF){
        ok=0;
    }
    if(ok==0){
        cout<<-1<<endl;
    }
    else{
        cout<<mult<<endl;
    }
    //printclock;
    return 0;
}

Measured memory_bytes: 4372
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)

char board[12][6];
char tmpb[12][6];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print() {
  int i,j;
  rep(i,12) {
    rep(j,6) {
      cout<<board[i][j];
    }
    cout<<endl;
  }
}

bool isok(int x,int y) {
  return (x >= 0 && x < 6 && y >= 0 && y < 12);
	  }

bool erase() {
  bool isb[12][6];
  int i,j,k,l;
  bool update = false;
  memset(isb, false, sizeof(isb));
  rep(i,12) {
    rep(j,6) {
      if(isb[i][j]) continue;
      isb[i][j] = true;
      if(board[i][j] == '.' || board[i][j] == 'O') continue;

      queue<pair<int,int> > Q;
      vector<pair<int,int> > vv;
      Q.push(make_pair(i,j)); vv.push_back(make_pair(i,j));
      while(!Q.empty()) {
	pair<int,int> p = Q.front(); Q.pop();
	int x = p.second,y = p.first;
	rep(k,4) {
	  if(isok(x+dx[k],y+dy[k]))
	    if(board[y+dy[k]][x+dx[k]] == board[y][x] && !isb[y+dy[k]][x+dx[k]]) {
	      Q.push(make_pair(y+dy[k],x+dx[k]));
	      isb[y+dy[k]][x+dx[k]] = true;
	      vv.push_back(make_pair(y+dy[k],x+dx[k]));
	    }
	}
      }

      if(vv.size() >= 4) {
	update = true;
	rep(k,vv.size()) {
	  int x = vv[k].second,y = vv[k].first;
	  rep(l,4) {
	    if(isok(x+dx[l],y+dy[l]))
	      if(board[y+dy[l]][x+dx[l]] == 'O')
		board[y+dy[l]][x+dx[l]] = '.';
	  }
	  board[vv[k].first][vv[k].second] = '.';
	}
      }
    }
  }

  return update;
}

void drop() {
  int i,j,k;
  for(i=11; i>=0; --i) {
    rep(j,6) {
      if(board[i][j] == '.') {
	k = i;
	while(k >= 0) {
	  if(!(board[k][j] == '.')) {
	    board[i][j] = board[k][j];
	    board[k][j] = '.';
	    break;
	  }
	  k--;
	}
      }
    }
  }
}

int solve() {
  bool update = false;
  int t = 0;
  while(true) {
    //cout<<t<<endl;
    update = erase();
    //cout<<"end erase "<<update<<endl;
    //print();
    if(!update) return t;
    t++;
    drop();
    //cout<<"end drop"<<endl;
    //print();
  }
}

void input() {
  int i,j;
  string s;
  rep(i,12) {
    cin>>s;
    rep(j,6)
      board[i][j] = s.at(j);
  }
  return;
}

int main() {
  int t;
  cin>>t;
  while(t--) {
    memset(board,0,sizeof(board));
    memset(tmpb, 0, sizeof(tmpb));
    input();
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 0
N,M = map(int,input().split())
#nC2+mC2
def comb(n,k):
    n1, k = n+1, min(k, n-k)
    numer = denom = 1
    for i in range(1,k+1):
        numer = numer*(n1-i)
        denom = denom*i
    return numer//denom
if N >= 2 and M >= 2:
    ans = comb(N,2)+comb(M,2)
elif N < 2 and M >= 2:ans = comb(M,2)
elif N >= 2 and M < 2:ans = comb(N,2)
else:ans = 0
print(ans)

Measured memory_bytes: 3064