akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define FOR(a, b, c) for (int (a) = (b); (a) < (c); ++(a))
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 10e4;
    FOR (i, 0, s.size() - t.size() + 1) {
        int k = 0;
        REP (j, t.size()) {
            if (s[i + j] != t[j]) {
                k += 1;
            }
        }
        ans = min(ans, k);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)  	
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const int maxn = 1e6+5;
const double pi = acos(-1.0);
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }
ll read()     //输入外挂
{
    ll res = 0, ch, flag = 0;
    if ((ch = getchar()) == '-')
        flag = 1;
    else if (ch >= '0' && ch <= '9')
        res = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9')
        res = res * 10 + ch - '0';
    return flag ? -res : res;
}
int main() {
    ll n, m;
    cin >> n >> m;
    if (n >= m) {
        for (ll i = 0; i < n; i++) {
            cout << m;
        }
    }
    else {
        for (ll i = 0; i < m; i++)
            cout << n;
    }
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define ar array
#define pii pair<int, int>

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int N = 1e4 + 4;

int cnt[N];

int f(int x, int y, int z) {
    return (x * x + y * y + z * z + x * y + y * z + z * x);
}

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

    int n;
    cin >> n;
    for (int x = 1; x * x <= n; x++) {
        for (int y = 1; x * x + y * y + x * y <= n; y++) {
            for (int z = 1; f(x, y, z) <= n; z++) cnt[f(x, y, z)]++;
        }
    }
    for (int i = 1; i <= n; i++) cout << cnt[i] << '\n';
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  bool B=true;
  vl a(n,0),b(n,0);
  rep(i,n){
    cin >> s[i];
    ll S=s[i].size();
    rep(j,S){
      if(s[i][j]=='('){
        a[i]++;
      }
      else{
        a[i]--;
      }
      b[i]=min(b[i],a[i]);
    }
  }
  vector<P> p(n,{0,0});
  ll now=0;
  rep(i,n){
    if(a[i]>=0&&b[i]>=0){
      now+=a[i];
    }
    else{
      p[i].first=a[i];
      p[i].second=b[i];
    }
  }
  vector<P> q(n,{0,0}),r(n,{0,0});
  rep(i,n){
    if(p[i].first>=0){
      q[i].second=p[i].first;
      q[i].first=p[i].second;
    }
    else{
      r[i].first=p[i].first-p[i].second;
      r[i].second=p[i].first;
    }
  }
  sort(q.begin(),q.end());
  reverse(q.begin(),q.end());
  rep(i,n){
    if(q[i].first<0){
      if(now+q[i].first<0){
        B=false;
      }
      else{
        now+=q[i].second;
      }
    }
  }
  sort(r.begin(),r.end());
  reverse(r.begin(),r.end());
  rep(i,n){
    if(r[i].second<0){
      if(now+(r[i].second-r[i].first)<0){
        B=false;
      }
      else{
        now+=r[i].second;
      }
    }
  }
  if(B&&now==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	vector<char> hoge;
	int N;
	string s;
	
	cin>>N;
	cin>>s;
	
	for(int i = 0; i < s.size(); i++){
		if(hoge.size() && hoge.back() == s[i]){
			
		} else {
			hoge.push_back(s[i]);
		}
	}
	
	cout<<hoge.size()<<endl;
	
	
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <string>
using namespace std;
bool check(int h, int w, int N, int M, const vector<string>& A, const vector<string>& B){
    if(h < 0 || h+M-1 >= N || w < 0 || w + M-1 >= N) return false;
    for(int i = h; i < h+M; ++i){
        for(int j = w; j < w+M; ++j){
            if(A[i][j] != B[i-h][j-w]){
                return false;
            }
        }
    }
    return true;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 0; i < M; ++i) cin >> B[i];
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            if(check(i, j, N, M, A, B)){
                cout << "Yes" << '\n';
                return 0;
            }
        }
    }
    cout << "No" << '\n';
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int cnt_odd = 0;   // 奇数
  int cnt_evn1 = 0;  // 2で1回だけ割れる
  int cnt_evn2 = 0;  // 2で2回以上割れる
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a & 1) {
      cnt_odd++;
    } else if (a & 2) {
      cnt_evn1++;
    } else {
      cnt_evn2++;
    }
  }

  // 奇数の隣には必ず4の倍数
  if (cnt_odd > cnt_evn2 + 1) {  // 1 4 1 4 1
    cout << "No" << endl;
    return 0;
  }

  // 2で1回だけ割れるものは、奇数の隣に置けない
  // -> 必ず4の隣に置く
  // -> 奇数と同じとみなせる
  // -> 全部繋げたものをひとつの奇数とみなす
  if (cnt_evn1 && cnt_odd + 1 > cnt_evn2 + 1) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    int a, b, q;
    cin >> a >> b >> q;
    ll s[a+2], t[b+2];
    for (int i = 1; i <= a; i++) {
        cin >> s[i];
    }
    for (int i = 1; i <= b; i++) {
        cin >> t[i];
    }
    s[0] = t[0] = -1e10;
    s[a+1] = t[b+1] = 2e10;

    while (q--) {
        ll x;
        cin >> x;

        int s1 = lower_bound(s, s+a+2, x) - s;
        int t1 = lower_bound(t, t+b+2, x) - t;

        ll ans = 2e10;
        for (int i = -1; i <= 0; i++) {
            for (int j = -1; j <= 0; j++) {
                ll d1 = abs(x - s[s1+i]) + abs(s[s1+i] - t[t1+j]);
                ll d2 = abs(x - t[t1+j]) + abs(t[t1+j] - s[s1+i]);
                ans = min(ans, min(d1, d2));
            }
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int x = n % 10;
  switch(x){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      printf("hon\n");
      break;
      
    case 0:
    case 1:
    case 6:
    case 8:
      printf("pon\n");
      break;
      
    case 3:
      printf("bon\n");
      break;
  }
}

Measured memory_bytes: 3632
N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
answer = 0
while len(T) > 0:
    limit = T[0] + K
    counter = 0
    while counter < C:
        if len(T) == 0:
            break
        if T[0] > limit:
            break
        del T[0]
        counter += 1
    answer += 1
print(answer)


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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    ll i,j,n,t=1,k=0,cnt=0,mini=LLONG_MAX,maxi=LLONG_MIN,ans=0;
    ll m;
    cin>>n>>k;
    ll a[n];
    rep(i,0,n) cin>>a[i];
    n--,k--;
    cout<<n/k+(n%k!=0);
    return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
//cout << fixed << setprecision(12);
//stoi("123");convert string to int
//to_string(123);convert int to string 

using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

//ll  pfx[100007][32];

int main(){
	Lancer();
	ll  n, sum, s, res = 0;
	cin >> n >> sum;
	for (int i = 0; i <= n; i++){
		s =sum- i;
		for (int j = 0; j <= n; j++){
			if (s - j <= n && i + j + (s - j) == sum && s-j>=0)
				res++;
		}
	}
	cout << res;
	cout << endl;
	return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define ll long long
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)

int main(){
	int n[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	scanf("%d",&k);
	printf("%d",n[k-1]);
	return 0;
}

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

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

int H, W;
int a[10][10];

int main() {
    int cnt = 0;
    cin >> H >> W;
    for (int i = 0; i < H; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < W; j++)
        {
            if(s[j] == '#') {
                a[i][j] = 1;
                cnt++;
            }
            else a[i][j] = 0;
        }
    }

    vector<vector<int>> dist(10, vector<int>(10, -1));
    queue<pair<int, int>> que;
    dist[0][0] = 0;
    que.push(make_pair(0, 0));

    while (!que.empty())
    {
        int x, y;
        tie(y, x) = que.front();
        que.pop();

        for (int i = 0; i < 2; i++)
        {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= W || ny >= H) continue;
            if(dist[ny][nx] != -1) continue;
            if(a[ny][nx] = 0) continue;
            dist[ny][nx] = dist[y][x] + 1;
            que.push(make_pair(ny, nx));
        }
    }

    if(dist[H-1][W-1] == -1) cout << "Impossible" << endl;
    else if(cnt != dist[H-1][W-1] + 1) cout << "Impossible" << endl;
    else cout << "Possible" << endl;
}

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

using namespace std;

int main()
{
    string str;
    cin >> str;
    int q;
    cin >> q;

    for (int i = 0; i <  q; i++)
        {
            string command;
            cin >> command;
            int a, b;
            cin >> a >> b;
            if(command == "print")
            {
                for (; a <= b; a++)
                {
                    cout << str[a];
                }
                cout << endl;
            }
            else if(command == "reverse")
            {
                for (; a < b;a++,b--)
                {
                    swap(str[a], str[b]);
                }
            }
            else
            {
                string p;
                cin >> p;
                for (int i = 0; a+i <= b; i++)
                {
                    str[a+i] = p[i];
                }
            }
        }
    return 0;
}



Measured memory_bytes: 3232
N, D = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    p = ls[i][0]
    q = ls[i][1]
    if p**2 + q**2 <= D**2:
        ans += 1
print(ans)        

Measured memory_bytes: 45456
#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>;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int main() {
  string str;
  cin >> str;
  rep(i,4) cout << str.at(i);
  cout << " ";
  rep(i,8) cout << str.at(i+4);
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
using namespace std;
int LIM=2e5+10;
v h(LIM),arr(LIM),dp(2*LIM,0);
int n;
void update(ll index,ll value)
{
    index+=n-1;
    while (index>=1)
    {
        dp[index]=max(dp[index],value);
        index=index/2;
    }
}
ll query(ll l,ll r)
{
    l+=n-1;
    r+=n-1;
    ll ans=-1;
    while (l<=r)
    {
        if (l%2==1)
        {
            ans=max(ans,dp[l]);
            l++;
        }
        if (r%2==0)
        {
            ans=max(ans,dp[r]);
            r--;
        }
        l=l/2;
        r=r/2;
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    vector<p> height(n+1);
    for (ll i=1; i<=n; i++)
    {
        cin>>h[i];
        height[i]=p(h[i],i);
    }
    for (ll i=1; i<=n; i++)
        cin>>arr[i];
    sort(height.begin()+1,height.end());
    ll ans=0;
    for (int i=1; i<=n; i++)
    {
        ll k=height[i].second;
        ll temp=query(1,k)+arr[k];
        update(k,temp);
        ans=max(ans,temp);
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#define MOD 1000000007
using namespace std;

int main(){
    long long a,b,x;
    cin >> a >> b >> x;
    long long  count=0;

    long long a_sum, b_sum;

    if(a != 0){
        a_sum = (a - 1) / x;
    }
    else a_sum = -1;
    b_sum = b / x;
    count = b_sum - a_sum;

    cout << count << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    vector<char> players{ 'a', 'b', 'c' };
    map<char, string> hands;
    for (const char player : players)
    {
        cin >> hands[player];
    }
    char player = 'a';
    for (;;)
    {
        if (hands[player].empty())
        {
            cout << static_cast<char>(player - 0x20) << endl;
            break;
        }
        char nextPlayer = hands[player].front();
        hands[player].erase(hands[player].begin());
        player = nextPlayer;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool Pa(string S)
{
  string T=S;
  reverse(T.begin(),T.end());
  if(T==S)
    return true;
  return false;
}
int main()
{
  string S;
  cin>>S;
  int N=S.length();
  if(Pa(S)&&Pa(S.substr(0,N/2))&&Pa(S.substr(N/2+1,N/2)))
    puts("Yes");
  else	puts("No");
  return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int answer = 0;

	for (int i = 1; i <= n; i += 2)
	{
		int count = 0;
		for (int j = 1; j <= i; j++)
		{
			if (i % j == 0)
			{
				count++;
			}
		}
		if (count == 8)
		{
			answer++;
		}
	}

	cout << answer << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int ch[4];
    int i=0,n,p;
    scanf("%d",&n);
    while(n!=0)
    {
        p=n%10;
        ch[i]=p;
        n=n/10;
        i++;
    }
    if(ch[3]==ch[2]&&ch[2]==ch[1])
        printf("Yes\n");
    else if(ch[0]==ch[1]&&ch[1]==ch[2])
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

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

const int N = 1000 * 100 + 10;
int sz[N], n;
vector<int> adj[N];

void dfs(int root, int par = 0) {
	int res = 0;
	for (auto u: adj[root])
		if (u ^ par) {
			dfs(u, root);
			sz[root] += sz[u];
			res += sz[u] % 2;
		}
	sz[root]++;
	res += (n - sz[root]) % 2;
	if (res > 1) {
		cout << "First\n";
		exit(0);
	}
}

int main() { 
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1, v, u; i < n; i++) {
		cin >> v >> u;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	if (n & 1)
		return cout << "First\n", 0;
	dfs(1);
	cout << "Second\n";
	return 0;
}


Measured memory_bytes: 9556
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

ll A, B, C, res;

int main() {
	cin >> A >> B >> C;
	if (C > A + B + 1) {
		res = A + B + 1 + B;
	}
	else {
		res = B + C;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
object Main extends App {

  def solve(s: String): Boolean = {
    val chars = s.toCharArray.toSet
    val counts = { for (c <- chars) yield s.count(_ == c) }
    counts.forall(_ % 2 == 0)
  }

  val sc = new java.util.Scanner(Console.in)
  val s = sc.next()
  val ans = solve(s)
  if (ans) print("Yes") else println("No")
}

Measured memory_bytes: 25536
#include<stdio.h>

int main()
{
    int n,v,j;
    scanf("%d",&n);
    int A[n];
    for(int x=0;x<n;x++)
    {
        scanf("%d",&A[x]);
        if(x != n-1)
        {
            printf("%d ",A[x]);
        }else {
            printf("%d\n",A[x]);
        }
    }
    for(int i=1;i<n;i++){
        v = A[i];
        j = i - 1;
        while(j >=0 && A[j] > v)
        {
            A[j+1] = A[j];
            j--;
            A[j+1] = v;
        }
        for(int cont = 0;cont < n;cont ++)
        {
            if(cont != n-1)
            {
                printf("%d ",A[cont]);
            }else {
                printf("%d\n",A[cont]);
            }
        }
    }
    return 0;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 L;
    cin >> L;

    i64 L_=L;

    vector<int> qs;
    while(L>2){
        if(L%2){
            --L;
            qs.push_back(0);
        }else{
            L/=2;
            qs.push_back(1);
        }
    }

    reverse(begin(qs),end(qs));

    int N=2,M=2,x=2;
    vector<tuple<int,int,int>> es={make_tuple(1,2,0),make_tuple(1,2,1)};
    for(int q:qs){
        if(q==0){
            es.push_back(make_tuple(1,N,x));
            ++M;
            ++x;
        }else{
            for(auto& e:es) get<2>(e)=get<2>(e)*2;
            es.push_back(make_tuple(N,N+1,0));
            es.push_back(make_tuple(N,N+1,1));
            ++N;
            M+=2;
            x*=2;
        }
    }

    assert(x==L_);
    cout << N << " " << M << endl;
    for(auto e:es){
        int u,v,w;
        tie(u,v,w)=e;
        cout << u << " " << v << " " << w << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define PI 3.14159265358979

using namespace std;

int main(void){
  int n;
  cin >> n;
  int a = 0, b = 0, d;

  for (int i = 0; i < n; i++){
    cin >> d;
    a += d*d;
    b += d;
  }


  cout << (b * b - a) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n=int(input())\n"
"s=list(input())\n"
"a=[0]*(n+1)\n"
"b=[0]*(n+2)\n"
"for i in range(n):\n"
"  a[i+1]=a[i]\n"
"  b[n-i]=b[n-i+1]\n"
"  if s[i]=='W':\n"
"    a[i+1]+=1\n"
"  if s[n-i-1]=='E':\n"
"    b[n-i]+=1\n"
"print(min(a[i]+b[i]-1for i in range(1,n+1)))\n"
"\"";
  system(s);
  return 0;
}            

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


#define ll long long
#define MOD 1000000007
#define PI 3.1415


int main(){
    int n;
    cin>>n;
    vector<ll> a(n);

    for(int i=0;i<n;i++)cin>>a.at(i);
    sort(a.begin(),a.end(),greater<ll>());

    ll ans=0;

    for(int i=1;i<n;i++){
        ans += a.at(floor(i/2));
    }
    cout<<ans<<endl;



}



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

using namespace std;
#define ll long long

int main(){
  ll N, K;
  cin >> N >> K;
  ll ret = 0;
  if(K == 0){
    cout << N * N << endl;
  } else {
    for(ll i=K+1; i<=N; i++){ // b                                                                              
      for(ll j=0; j<=N/i; j++){ // a/b                                                                          
        if(j == N/i){
          ret += max(N - i * j - K + 1, (ll)0);
        } else {
          ret += i - K;
        }
      }
    }
    cout << ret << endl;
  }
  return 0;
}


Measured memory_bytes: 384
N = int(input())
S = [input() for i in range(N)]
AC, WA, TLE, RE = 0, 0, 0, 0
AC = S.count("AC")
WA = S.count("WA")
TLE = S.count("TLE")
RE = S.count("RE")
print('AC x {}'.format(AC))
print('WA x {}'.format(WA))
print('TLE x {}'.format(TLE))
print('RE x {}'.format(RE))


Measured memory_bytes: 82608
#include<cmath>
#include<cstdio>
#include<vector>

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

using namespace std;

const int N_MAX=2850; // 2800->RE, 2900->MLE

void Gauss_Jordan(int n,double A[N_MAX][N_MAX+1],const double *b,double *x){
	rep(i,n) A[i][n]=b[i];

	rep(i,n){
		int piv=i;
		for(int j=i;j<n;j++) if(abs(A[j][i])>abs(A[piv][i])) piv=j;
		rep(j,n+1) swap(A[i][j],A[piv][j]);

		for(int j=i+1;j<=n;j++) A[i][j]/=A[i][i];
		rep(j,n) if(i!=j) for(int k=i+1;k<=n;k++) A[j][k]-=A[j][i]*A[i][k];
	}

	rep(i,n) x[i]=A[i][n];
}

void Gauss_Seidel(int n,const double A[N_MAX][N_MAX+1],const double *b,double *x){
	rep(_,300){
		rep(i,n){
			double y=b[i];
			rep(j,n) if(j!=i) y-=A[i][j]*x[j];
			x[i]=y/A[i][i];
		}
	}
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	bool G[10][10]={};
	int deg[10]={};
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		G[u][v]=G[v][u]=true;
		deg[u]++;
		deg[v]++;
	}

	vector<int> V; // 訪問済みの頂点集合としてありえるもの全体
	rep(S,1<<n){
		if((S&1)==0) continue;

		bool vis[10]={true};
		int Q[10],head=0,tail=0;
		Q[tail++]=0;
		while(head<tail){
			int u=Q[head++];
			rep(v,n) if(G[u][v] && !vis[v] && (S>>v)&1) {
				vis[v]=true;
				Q[tail++]=v;
			}
		}

		bool ok=true;
		rep(u,n) if(((S>>u)&1)!=vis[u]) ok=false;
		if(ok) V.push_back(S);
	}

	int k=0;
	vector< pair<int,int> > T; // ありうる状態の全体 ( 訪問済みの頂点集合と今いる頂点のペア )
	int id[1<<10][10]; // T の逆写像
	rep(i,V.size()) rep(u,n) if((V[i]>>u)&1) {
		T.push_back(make_pair(V[i],u));
		id[V[i]][u]=k++;
	}

	// x[i] := 状態 i からスタートして全頂点を巡り終える時刻の期待値
	static double A[N_MAX][N_MAX+1],b[N_MAX],x[N_MAX];
	rep(i,k){
		int S=T[i].first,u=T[i].second;
		if(S!=(1<<n)-1){
			rep(v,n) if(G[u][v]) {
				int S2=S;
				if(((S>>v)&1)==0) S2|=1<<v;
				int j=id[S2][v];
				A[i][j]=-1.0/deg[u];
			}
			A[i][i]=1;
			b[i]=1;
		}
		else{ // 全頂点を巡り終えた状態
			A[i][i]=1;
		}
	}

	rep(u,k) x[u]=1; // 適当な初期ベクトル

	if(k<2000) Gauss_Jordan(k,A,b,x);
	else       Gauss_Seidel(k,A,b,x);

	printf("%.9f\n",x[0]);

	return 0;
}

Measured memory_bytes: 63816
n, Y = [int(s) for s in input().split(' ')]
 
for x in range(n, -1, -1):
    if Y < x*10000:
        continue
    
    for y in range(n-x, -1, -1):
        if Y < x*10000+y*5000:
            continue
        if (Y-x*10000-y*5000) % 1000 != 0:
            continue
            
        z = int((Y-x*10000-y*5000)/1000)
        if n == x+y+z:
            print('{} {} {}'.format(x, y, z))
            exit()
            
print('-1 -1 -1')

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

int main(){
  int X, N, max, s;
  cin >> X >> N;
  max = 0;
  vector<int> a;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    a.push_back(A);
  }
  for (int i = 0; i < N-1; i++) {
    s = a[i+1] - a[i];
    if (s > max) {
        max = s;
    }
  }
  if (X-a[N-1] + a[0] > max) {
      max = X - a[N-1] + a[0];
  }
  cout << X - max << endl;
}

Measured memory_bytes: 1400
#![allow(unused_imports)]
#![allow(dead_code)]
use datastructure::*;
use grapth::*;
use input_scanner::*;
use math::*;
use string_algorithm::*;
use util::*;

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};

fn main() {
    let mut scan = Scanner::new();
    let a: u64 = scan.next();
    let b = scan.next_word();

    let mut c: u64 = 0;
    c += (b[0] as u64 - 48) * 100;
    c += (b[2] as u64 - 48) * 10;
    c += (b[3] as u64 - 48) * 1;

    println!("{}",a * c / 100);
}

mod datastructure {}
mod grapth {}
mod math {}
mod string_algorithm {}
mod util {}
mod input_scanner {
    pub struct Scanner {
        bytes: Vec<u8>,
        begin: usize,
        end: usize,
    }

    impl Scanner {
        pub fn new() -> Self {
            use std::io::Read;
            let mut buffer: Vec<u8> = Vec::new();
            std::io::stdin().read_to_end(&mut buffer).unwrap();
            let end = (0..buffer.len())
                .find(|i| buffer[*i].is_ascii_whitespace())
                .unwrap_or(buffer.len());
            Scanner {
                bytes: buffer,
                begin: 0,
                end: end,
            }
        }
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let s: &str =
                unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
            let ret: T = s.parse::<T>().ok().expect("Parse error.");
            self.skip();
            ret
        }
        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
        pub fn next_word(&mut self) -> Vec<u8> {
            let r = Vec::from(&self.bytes[self.begin..self.end]);
            self.skip();
            r
        }
        fn skip(&mut self) {
            self.begin = (self.end..self.bytes.len())
                .find(|i| !self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
            self.end = (self.begin..self.bytes.len())
                .find(|i| self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
        }
    }
}


Measured memory_bytes: 2136
N, L = map(int, input().split())
min_n = 300
sum_n = 0
for i in range(1, N + 1):
  sum_n += (L + i - 1)
  if min_n > abs(L + i - 1):
    min_n = abs(L + i - 1)
    eat_apple_taste = L + i - 1
print(sum_n - eat_apple_taste)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
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; }

int h[101010], dp[101010];
int main(){
  int N; cin >> N;
  rep(i, 0, N) cin >> h[i];
  rep(i, 1, N) dp[i] = 1e9 + 1;
  rep(i, 0, N) {
    chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }
  cout << dp[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 1024
k, n = map(int, input().split())

a = list(map(int, input().split()))
li = []

for i in range(n-1):
    li.append(a[i+1] - a[i])
    
li.append(a[0] + abs(k - a[-1]))

#print(li)

print(sum(li) - max(li))

Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
using Tree = vector<pair<int, int>>;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << b + c - min(a, b + c) << endl;
}

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

int main() {
  int A, B;
  vector<int> a;
  cin >> A >> B;
  
   a = {0, 0, 0, 0};
  a.at(A) = 1;
  a.at(B) = 1;
  for(int i=1;i < 4;i++){
    //cout << i << endl;
    if(a.at(i) == 0){
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



const int MAX = 1000000;
bool IsPrime[MAX];
vector<int> Era(int n = MAX) {
    vector<int> res;
	IsPrime[0] = false; IsPrime[1] = false; 
	for (int i = 2; i < n; ++i) IsPrime[i] = true;
	for (int i = 2; i < n; ++i) {
		if (IsPrime[i]) {
            res.push_back(i);
			for (int j = i*2; j < n; j += i) IsPrime[j] = false;
		}
	}
    return res;
}

int n;

int main() {
    vint prime = Era();
    vint sum(prime.size() + 1, 0);
    for (int i = 0; i < prime.size(); ++i) {
        sum[i+1] = sum[i] + prime[i];
    }
    while (cin >> n) {
        if (n == 0) break;
        
        cout << sum[n] << endl;
    }
    return 0;
}


Measured memory_bytes: 2696
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i, n) for(int i=1; i<n; i++)
using namespace std;

int main(){
    int N; cin >> N;
    int A[N];
    int tmp;
    A[0] = 0;
    rep(i, N) A[i] = 0;
    rep(i, N){
        cin >> tmp;
        A[tmp-1]++;
    }
    cout << A[0] << endl;
    rep(i, N) cout << A[i] << endl;
}
    


Measured memory_bytes: 4416
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;

int main(){
    int H,W;cin >> H >> W;
    vector<vector<int>> vec(W);
    for(int i = 0;i < H;i++){
        string s;cin >> s;
        for(int j = 0;j < W;j++){
            if(s.at(j) == 'B'){
                vec.at(j).push_back(i);
            }
        }
    }
    int ans = 0;
    for(int i = 0;i < W-1;i++){
        for(int j = i;j < W;j++){
            if(vec.at(i).empty() || vec.at(j).empty())continue;
            ans = max(ans, abs(i-j) + abs(vec.at(i).back()-vec.at(j).back()));
            ans = max(ans, abs(i-j) + abs(vec.at(i).back()-vec.at(j).front()));
            ans = max(ans, abs(i-j) + abs(vec.at(i).back()-vec.at(j).back()));
            ans = max(ans, abs(i-j) + abs(vec.at(i).front()-vec.at(j).back()));
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 6560
import java.util.*;

public class Main{

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

    static long lcm(long a,long b){
        return a/gcd(a,b)*b;
    }
    public static void main(String[] srgs){
        Scanner sc=new Scanner(System.in);

        int n=sc.nextInt();
        int[][][] in=new int[n][][];
        for(int i=0;i<n;i++){
            int m=sc.nextInt();
            in[i]=new int[m][2];
            for(int j=0;j<m;j++){
                in[i][j][0]=sc.nextInt();
                in[i][j][1]=sc.nextInt();
            }
        }
        int out=0,N=1<<n;
        for(int i=0;i<N;i++){
            int c=0,t=1;
            for(int j=0;j<n;j++)if((i>>j&1)==1){
                c++;
                for(int k=0;k<in[j].length;k++){
                    if((i>>(in[j][k][0]-1)&1)+in[j][k][1]==1)
                        t=0;
                }
            }
            if(t==1)out=Math.max(out,c);
        }
        System.out.println(out);
    }
}


Measured memory_bytes: 22612
a, b = gets.strip.split.map(&:to_i)

for i in 1..999
    h1 = i * (i + 1) / 2
    h2 = (i + 1) * (i + 2) / 2
    if h1 - a == h2 - b
        puts (h1 - a)
        break
    end
end


Measured memory_bytes: 1788
#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>;

int main() {
  int N, K; cin >> N >> K;
  int pattern=K; N--;
  
  while (N > 0){
    pattern *= K - 1;
    N --;
  }
  cout << pattern << endl;
  return 0;
}


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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	string s; cin >> s;
	vector<char> st;
	const int n = s.size();
	st.push_back(s[0]);
	int tot = 0;
	for (int i = 1; i + 1 < n; ++i) {
		if (st.back() != s[i + 1]) {
			tot++;
			while (st.size() > 1 && st[st.size() - 1] != s[i + 1]) {
				st.pop_back();
				tot++;
			}
		}
		else st.push_back(s[i]);
	}
	puts(tot % 2 == 1 ? "First" : "Second");

	return 0;
}


Measured memory_bytes: 768
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
node=[]
if n%2==0:
    for i in range(n):
        for j in range(i,n):
            if j==i or j==n-1-i:
                continue
            node.append((i+1,j+1))
else:
    for i in range(n):
        for j in range(i,n):
            if j==i or j==n-2-i:
                continue
            node.append((i+1,j+1))
    
print(len(node))
for i in node:
    print(*i) 

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

int w, h, n;

void fill(vector<vector<int>> &maze, int x, int y, int a)
{
	if (a == 1)
	{
		for (int i = 0; i < h; ++i)
			for (int j = 0; j < w; ++j)
				if (j < x)
					maze[i][j] = 1;
	}
	else if (a == 2)
	{
		for (int i = 0; i < h; ++i)
			for (int j = 0; j < w; ++j)
				if (j >= x)
					maze[i][j] = 1;
	}
	else if (a == 3)
	{
		for (int i = 0; i < h; ++i)
			for (int j = 0; j < w; ++j)
				if (i < y)
					maze[i][j] = 1;
	}
	else 
	{
		for (int i = 0; i < h; ++i)
			for (int j = 0; j < w; ++j)
				if (i >= y)
					maze[i][j] = 1;
	}
}

int main()
{
	cin >> w >> h >> n;
	vector<vector<int>> maze(h, vector<int>(w, 0));
	for (int i = 0; i < n; ++i)
	{
		int x, y, a; cin >> x >> y >> a;
		fill(maze, x, y, a);
	}
	int ans = 0;
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			if (!maze[i][j])
				ans++;
	cout << ans << endl;
}



Measured memory_bytes: 3636
def COMinit(n, MOD):
    fact = [1, 1]
    fact_inv = [1, 1]
    inv = [0, 1]
    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        fact_inv.append((fact_inv[-1] * inv[i]) % MOD)
    return fact, fact_inv

MOD = 10**9+7
def resolve():
    def dfs1(r_topo, par):
        for idx in reversed(r_topo):
            for to in G[idx]:
                if to == par[idx]:
                    continue


    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(lambda x:int(x)-1, input().split())
        G[a].append(b)
        G[b].append(a)

    fact, fact_inv = COMinit(N, MOD)

    topo = []
    P = [-1] * N
    node = [0]
    while node:
        v = node.pop()
        topo.append(v)
        for to in G[v]:
            if to == P[v]:
                continue
            P[to] = v
            node.append(to)

    # 葉のサイズを格納
    size = [1]*N
    for e in reversed(topo):
        if e == 0:
            break
        size[P[e]] += size[e]

    dp1 = [1]*N
    for e in reversed(topo):
        dp1[e] = dp1[e] * fact[size[e] - 1] % MOD
        if e == 0:
            break
        dp1[P[e]] = (dp1[P[e]] * dp1[e] % MOD) * fact_inv[size[e]] % MOD

    dp2 = [0] * N
    dp2[0] = dp1[0]
    for e in topo[1:]:
        p = P[e]
        tmp = (dp2[p] * fact[N - 1 - size[e]] % MOD) * fact[size[e]] % MOD
        red = (tmp * fact_inv[N - 1] % MOD) * pow(dp1[e], MOD - 2, MOD) % MOD

        size_red = N - size[e]
        tmp = (dp1[e] * red % MOD) * fact[N - 1] % MOD
        dp2[e] = (tmp * fact_inv[size[e] - 1] % MOD) * fact_inv[size_red] % MOD

    print(*dp2, sep="\n")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 170260
import math as m
N,M = map(int,input().split())
divisor = []
for i in range(1,m.floor(pow(M,1/2)) + 1):
  if M % i == 0:
    divisor.append(i)
    divisor.append(M // i)
ans = 1
for e in divisor:
  if e > ans and e <= M // N:
    ans = e
print(ans)

Measured memory_bytes: 3060
n, d = STDIN.gets.chomp.split(' ').map(&:to_i)

x = Array.new(0)
for i in 1..n
  x.push(STDIN.gets.chomp.split(' ').map(&:to_i))
end

count = 0
for j in 0..(n-1)
  for k in 0..(n-1-(j+1))
    sum =  0
    for l in 0..(d-1)
      sum += (x[j][l] - x[k+(j+1)][l]) ** 2
    end
    rt = Math.sqrt(sum)
    if rt.floor == rt.ceil then
      count += 1
    end
  end
end

puts count

Measured memory_bytes: 3836
#include<iostream>
#include<utility>
#include<vector>
#include<stack>
#include<map>
using namespace std;
using Graph = vector<vector<int>>;

void solve() {
	int n, root = 0, c = 1; cin >> n;
	Graph graph(n);
	vector<bool>seen(n, false);
	stack<int>todo;
	vector<int>parent(n, 0);
	map<pair<int, int>, int>ans;
	int input[n][2];
	for (int i = 0; i < n - 1; i++) {
		int a, b; cin >> a >> b; a--; b--;
		graph[a].emplace_back(b);
		graph[b].emplace_back(a);
		input[i][0] = a; input[i][1] = b;
	}
	for (int i = 1; i < n; i++) {
		if (graph[root].size() < graph[i].size()) {
			root = i;
		}
	}
	seen[root] = true;
	for (auto to : graph[root]) {
		parent[to] = root;
		ans[make_pair(root, to)] = c;
		ans[make_pair(to, root)] = c;
		todo.push(to);
		c++;
	}
	while (!todo.empty()) {
		int from = todo.top(), c = 1;
		todo.pop();
		seen[from] = true;
		for (auto to : graph[from]) {
			if (!seen[to]) {
				todo.push(to);
				parent[to] = from;
				if (c == ans[make_pair(parent[from], from)])c++;
				ans[make_pair(from, to)] = c;
				ans[make_pair(to, from)] = c;
				c++;
			}
		}
	}
	cout << graph[root].size() << endl;
	for (int i = 0; i < n - 1; i++) {
		cout << ans[make_pair(input[i][0], input[i][1])] << endl;
	}
}

int main() {
	solve();
}

Measured memory_bytes: 19712
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int n, i;
	scanf("%d", &n);
	
	long int A[100001], B[100001], cnt=0;
	lop(i, n+1){ scanf("%ld", &A[i]); }
	lop(i, n){ scanf("%ld", &B[i]); }
	
	lop(i, n){
		if(A[i]>B[i]){ cnt+=B[i]; B[i]=0; }
		else { B[i]-=A[i]; cnt+=A[i]; }
		
		if(B[i]<A[i+1]){ A[i+1]-=B[i]; cnt+=B[i]; }
		else{ cnt+=A[i+1]; A[i+1]=0; }
	}
	
	printf("%ld", cnt);
	 
	return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
using namespace std;
long long k,a,b;
int main(void)
{
     int i,j,n,m;
     scanf("%lld%lld%lld",&k,&a,&b);
     if(a>=k)
          printf("1\n");
     else
     {
          if(a<=b)
          {
               printf("-1\n");
          }
          else
          {
               /*if(k%(a-b)!=0)
               {
                    printf("%lld\n",k/(a-b)*2+1);
               }
               else
               {
                    if(2*b>=a)
                         printf("%lld\n",k/(a-b)*2-3);
                    else if()
                    else
                         printf("%lld\n",k/(a-b));
               }*/
               long long w=k-a;
               if(w%(a-b)==0)
                    printf("%lld\n",w/(a-b)*2+1);
               else
                    printf("%lld\n",w/(a-b)*2+3);
          }
     }
     return 0;
}


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

int main(){
    int a, b, c; cin >> a >> b >> c;
    if(a + b == c) cout << "Yes" << endl;
    else if(b + c == a) cout << "Yes" << endl;
    else if(c + a == b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

void print(vector<int> &A) {
	for (int i = 0; i < A.size(); i++)
		printf("%d ", A[i]);
	printf("\n");
}

void print_matrix(vector< vector<int> > &m) {
	for (int i = 0; i < m.size(); i++)
		print(m[i]);
}

class graph {
public:
	int n;
	vector< vector<int> > adj;

	graph(int _n) {
		n = _n;
		adj = vector< vector<int> >(n, vector<int>());
	}

	void add_edge(int u, int v) {
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	void bfs(int root, vector<int> &distance) {
		queue< pair<int, int> > q;
		q.push(make_pair(root, 0));
		distance[root] = 0;

		while ( !q.empty() ) {
			pair<int, int> curr = q.front();
			q.pop();

			int u = curr.first;
			int d = curr.second;

			for (int v : adj[u]) {
				if ( distance[v] == INT_MAX ) {
					distance[v] = 1 + d;
					q.push(make_pair(v, 1 + d));
				}
			}
		}
	}

	int diameter() {
		vector<int> distance(n, INT_MAX);

		int root = 0;
		bfs(root, distance);
		int farther = root;
		for (int i = 0; i < n; i++) {
			if (distance[i] > distance[farther])
				farther = i;
		}
		// print(distance);

		for (int i = 0; i < n; i++)
			distance[i] = INT_MAX;

		root = farther;
		bfs(root, distance);
		farther = root;
		for (int i = 0; i < n; i++) {
			if (distance[i] > distance[farther])
				farther = i;
		}
		// print(distance);

		return distance[farther];
	}
};

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

	graph *g = new graph(n);

	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		g->add_edge(u - 1, v - 1);
	}

	int d = g->diameter();
	// cout << d << endl;

	string ans = ((d - 1) % 3 == 0 ? "Second" : "First");
	cout << ans << endl;

	return 0;
}

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()

ll gcd(ll a, ll b);

ll sum(int n);

void go(){
   int n;cin>>n;
   vector<int> g(n);
   int s1=0;
   for(int i=0;i<n;i++){
      cin>>g[i];
      s1+=g[i];
   }
   int s2=0;
   int ans=1e9;
   for(int k : g){
      s2+=k;
      int diff=abs(s2-(abs(s1-s2)));
      if(diff<ans)
         ans=diff;
   }
   cout << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

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

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
import sys
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

n = Ii()
if n%1000 == 0:
  print(0)
else:
  print(1000-n%1000)

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	int input;
	int cnt5 = 0, cnt7 = 0;

	rep(i, 3) {
		cin >> input;
		if (input == 5) cnt5++;
		else if (input == 7) cnt7++;
	}

	if (cnt5 == 2 && cnt7 == 1) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define loop(a,b) for(ll i=a;i<b;i++)
#define iloop(a,b) for(int i=a;i<b;i++)
#define it(c) for(auto it=c.begin();it!=c.end();it++)
#define MOD 1000000007

using namespace std;

void Thai_Jase() {
    ll n,h=0;
    cin>>n;
    ll a[n];
    loop(0,n) {
        cin>>a[i];
    }
    loop(0,n) {
        if(i==0) continue;
        if(a[i]<a[i-1]) {
            h+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout << h;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int ts=1;
    while(ts--) {
      Thai_Jase();
    }
    return 0;
}

Measured memory_bytes: 5248