akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <thread>
#define endl "\n"
using namespace std;
#define ios ios_base::sync_with_stdio(false);
#define lll __int128_t
#define ll long long int
#define XOX
#define FOR(i,a,b) for(ll i=a;i<(ll)b;i++)
#define FORr(i,a,b) for(ll i =a;i>=(ll)b;i--)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,n)
#define print(arr)  for(auto a: arr) cout << a<< " "; cout << endl;
#define case(i) cout << "Case " << i << ": ";
#define in(a) ll a = read();
#define inp(arr,n) vector<ll>arr(n); for(auto &a: arr) a = read(); 
#define pb emplace_back
#define all(a) a.begin(), a.end()
#define mp make_pair
#define f first
#define s second
#define mod 998244353
#define pll pair<ll, ll>
inline ll read()
{
    ll x=0; static ll p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
    return x;
}
template<typename T> ostream& operator<<(ostream &os, const multiset<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T> ostream& operator<<(ostream &os, const set<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#define DEBUG
#ifdef DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
void solve(int pk);


int main()
{
  //freopen("in", "r", stdin);
   ll nn = 1;
   //nn= read();
 //  ios
  // cin >> nn;
    rep(i, nn) solve(i);
}
void solve(int tt)
{
    in(n)
    vector<pll>arr(n);
    for(auto &a: arr) {
        a.f = read();
        a.s = read();
    }
    rep(i, n){
        if(i+2 >= n) break;
        if(arr[i].f == arr[i].s){
            if(arr[i+1].f == arr[i+1].s){
                if(arr[i+2].f == arr[i+2].s){
                    cout << "Yes" << endl;
                    return;
                }
            }
        }
    }
    cout << "No" << endl;
    
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define ld long double
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';              

typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

const ll mod = 1e9 + 7;

int main(){

	IOS

	ll n,m,i,j,k;
	cin >> n >> m;

	char g[n][m];

	string s;

	forn(0,n,i){
		cin >> s;
		forn(0,m,j){
			g[i][j] = (s[j] == '.');
		}
	}

	ll left[n][m], right[n][m], up[n][m], down[n][m];

	memset(left, 0, sizeof left);
	memset(right, 0, sizeof right);
	memset(up, 0, sizeof up);
	memset(down, 0, sizeof down);

	forn(0,n,i){
		forn(0,m,j){
			if(!g[i][j]){
				left[i][j] = -1;
				right[i][j] = -1;
			}else{
				if(j)
					left[i][j] = left[i][j - 1] + 1;
				else
					left[i][j] = 0;
			}
		}
		forrev(m - 1,0,j){
			if(!g[i][j]){
				left[i][j] = -1;
				right[i][j] = -1;
			}else{
				if(j + 1 < m)
					right[i][j] = right[i][j + 1] + 1;
				else
					right[i][j] = 0;
			}
		}

	}

	forn(0,m,j){
		forn(0,n,i){
			if(!g[i][j]){
				down[i][j] = -1;
				up[i][j] = -1;
			}else{
				if(i)
					up[i][j] = up[i - 1][j] + 1;
				else
					up[i][j] = 0;
			}
		}
		forrev(n - 1,0,i){
			if(!g[i][j]){
				up[i][j] = -1;
				down[i][j] = -1;
			}else{
				if(i + 1 < n)
					down[i][j] = down[i + 1][j] + 1;
				else
					down[i][j] = 0;
			}
		}

	}

	ll ans = 0;


	// forn(0,n,i){
	// 	forn(0,m,j){
	// 		cerr << left[i][j] << ' ' << right[i][j] << ' ' << up[i][j] << ' ' << down[i][j]  << '\n';
	// 	}
	// }


	forn(0,n,i){
		forn(0,m,j){
			if(g[i][j]){
				ans = max(right[i][j] + left[i][j] + up[i][j] + down[i][j],ans);
			}
		}
	}
	cout << ans + 1 << '\n';
}

Measured memory_bytes: 129152
# -*- coding: utf-8 -*-
n = input()
m = len(n)-1
for i in range(2 ** m):
    ops = []
    N = [int(n[0]), int(n[1]), int(n[2]), int(n[3])]
    for j in range(m):
        if (i >> j) & 1:
            ops.append("+")
        else:
            N[j + 1] *= -1
            ops.append("-")
    if sum(N) == 7:
        print(n[0]+ops[0]+n[1]+ops[1]+n[2]+ops[2]+n[3]+"=7")
        break

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
	if (n & 1)
	  res = res * a % mod;
	a = a * a % mod;
	n >>= 1;
  }
  return res;
}
/****** define variable start ******/
ll n;
vl a;
/******* define variable end *******/
int solve() {
	cin >> n;
	a.resize(n);
	REP(i, n){
		cin >> a[i];
	}
	if(n % 2 == 0){
		vl left(n/2+1);
		vl right(n/2+1);
		left[0] = a[0];
		right[0] = a[1];
		for(ll i = 1; i < n / 2; i++){
			left[i] = left[i-1] + a[2*i];
			right[i] = max(left[i-1], right[i-1]) + a[2*i + 1];
		}
		cout << max(left[n/2-1], right[n/2-1]) << endl;
	}else{
		vl left((n-1)/2 + 1);
		vl mid((n-1)/2 + 1);
		vl right((n-1)/2 + 1);
		left[0] = a[0];
		mid[0] = a[1];
		right[0] = a[2];
		for(ll i = 1; i < (n-1)/2; i++){
			left[i] = left[i-1] + a[2*i];
			mid[i] = max(left[i-1], mid[i-1]) + a[2*i + 1];
			right[i] = max({left[i-1], mid[i-1], right[i-1]}) + a[2*i + 2];
		}
		cout << max({left[(n-1)/2-1], mid[(n-1)/2-1], right[(n-1)/2-1]}) << endl;
	}
	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 7164
#include <iostream>
#include<string.h>
#include<cstdio>
#include <stack>
#include <vector>
using namespace std;
#define INF 0x7ffffff
typedef long long ll;
const int maxn=1e5+10;
int pre[maxn];//存每个点的祖先
int dis[maxn];//这个点到祖先的距离
int findset(int x)
{
    if(x==pre[x])   return x;
    int root=findset(pre[x]);
    dis[x]=dis[pre[x]]+dis[x];//当前点x到根节点的距离=现在的距离+父节点到根节点的距离
    return pre[x]=root;//把每个子节点合并到他的祖先
}
bool unionset(int x,int y,int w)
{
    int fx=findset(x),fy=findset(y);
    if(fx==fy)
        return w==dis[y]-dis[x];
    pre[fy]=fx;
    dis[fy]=dis[x]+w-dis[y];
    return true;
}
int n,m;
int main()
{
   scanf("%d%d",&n,&m);
   for(int i=1;i<=n;i++)
    pre[i]=i;
   bool lose=true;
   for(int i=0;i<m;i++)
   {
       int x,y,w;
   scanf("%d%d%d",&x,&y,&w);
        if(lose)
       lose=unionset(x,y,w);
   }
   if(lose) printf("Yes\n");
   else     printf("No\n");
}


Measured memory_bytes: 1024
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e9
#define mod 1000000007
//priority_queue<llint,vector<llint>,greater<llint> > que;
//priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<vector<int>>g;
int n,m;

void solve(){
    cin >> n >> m;
    g.resize(n+1);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int>dist(n+1,inf);
    vector<int>pre(n+1);
    queue<int>que;

    dist[1]=0;
    que.push(1);
    //BFS
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(int nv:g[v]){
            if(dist[nv]!=inf)continue;
            dist[nv]=dist[v]+1;
            que.push(nv);
            pre[nv]=v;
        }
    }
    cout << "Yes" << endl;
    for(int i=1;i<=n;i++){
        if(i==1)continue;
        cout << pre[i] << endl;
    }
}

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


Measured memory_bytes: 10628
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  string s; cin >> s;
  string res = "$";
  for(int i = 0; i < n; ++i) {
    if(s[i] != res.back()) {
      res += s[i];
    }
  }
  cout << res.length() - 1 << endl;
}



Measured memory_bytes: 704
N = int(input())
h_list = [int(h) for h in input().split()]

h_min = min(h_list)
for i in range(N):
    h_list[i] -= h_min
ans = h_min
judge = 0
while judge == 0:
    for i in range(N):
        if h_list[i] != 0:
            r = i
            break
        r = -1
    if r == -1:
        break
    for j in range(r,N):
        if h_list[j] == 0:
            l = j-1
            break
        l = j
    temp = h_list[r:l+1]
    temp_min = min(temp)
    for k in range(r,l+1):
        h_list[k] -= temp_min
    ans += temp_min
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
#define sz(x) (int)x.size()
#define endl "\n"
#define len(a) a.length()
using namespace std;

signed main(){
    fast_io;
    ll n;
    cin>>n;
    vector<ll>a(n);
    ll sum=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll min_ans=LLONG_MAX;
    for(ll i=1;i<=100;i++){
        ll cur=0;
        for(ll j=0;j<n;j++){
            cur+=abs(a[j]-i)*abs(a[j]-i);
        }
        min_ans=min(min_ans,cur);
    }
    cout<<min_ans;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin >> n;
	vector<int> a(n), b(n), d(n);
	ll sumpos = 0;
	ll sumneg = 0;
	ll oddcnt = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
		d[i] = a[i] - b[i];
		if (d[i] > 0) sumpos += d[i];
		if (d[i] < 0)
		{
			sumneg += -d[i];
			if (abs(d[i]) % 2 == 1)
			{
				oddcnt++;
			}
		}
	}

	sumneg -= oddcnt;
	if (sumneg >= 2 * sumpos)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 384
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, M = sc.nextInt()
    val S = Array.fill(M)(0)
    for {
      i <- 0 until M
    } {
      val ki = sc.nextInt()

      for {
        _ <- 0 until ki
      } {
        val s = sc.nextInt()
        S(i) |= (1 << (s - 1))
      }
    }
    val P = Array.fill(M)(sc.nextInt())

    // 電球iのスイッチは, マスクを与えている.
    // (1 << sij)のfoldでマスクを形成し, ビットと&をとって, ビットを足し合わせて2で割った場合, piに等しければ点灯する
    // つまり, 全てのスイッチの状態を変化させ
    // 全ての電球について, その状態で, 全て条件を満たす場合につき, カウントする
    val r = (for {
      s <- 0 until Math.pow(2, N).toInt
      if (0 until M).forall { k =>
        (0 until N).foldLeft(0)((sum, b) => if (((s & (1 << b)) & S(k)) == (1 << b)) (sum + 1) % 2 else sum) == P(k)
      }
    } yield s).size

    println(r)
  }

}


Measured memory_bytes: 55820
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int p=0,q;
    long long a,b,k;
    cin>>a>>b>>k;
    q=k;
    if((b-a)/k>=2){
            for(int i = 0; i < k; i++){
                cout<<a+p<<endl;
                p++;
            }
            for(int i = 0; i < k; i++){
                cout<<b-q+1<<endl;
                q--;
            }

    }
    else{
        for(int i = 0;i <= b-a; i++){
            cout<<a+i<<endl;
        }
    }
  return 0;
}

Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <unordered_set>
#include <set>

#define prev asasddlsa
#define rank aljds

using namespace std;

typedef long long ll;

template<typename T>
void print(const vector<T>& s){
    for (auto x : s)
        cout << x << " ";
    cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; i++)
        cin >> s[i];
    ll answer = 0;
    sort(s.begin(), s.end());
    // print(s);
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            answer += lower_bound(s.begin(), s.end(), s[i] + s[j]) - s.begin() - j - 1;
        }
    }
    cout << answer << endl;
    return 0;
}

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

int main() {
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" <<endl;
    }
    return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pf push_front
#define sz(x) (int)(x).size()
#define lb lower_bound 
#define ub upper_bound 
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<string> vs;
typedef unsigned long long ull;
typedef long double ld;
typedef map<int,int> mii;

const int MOD = 1e9+7;
const ld PI = acos((ld)-1);

void solve () {
	string str;
	cin >> str;
	int n = str.length();
	int ans = 0;
	int cnt = 0;
	for (int i = 0;i < n;++i) {
		if (str[i] == 'S') {
			cnt = 0;
		} else {
			++cnt;
			ans = max(ans,cnt);
		}
	}
	cout << ans << '\n';
}

int main () {
#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 3608
S = input()
N = len(S)

ans = [1] * N
for i in range(N-1):
    if S[i] == S[i+1] == "R":
        ans[i+2] += ans[i]
        ans[i] = 0

for i in range(N-1, 1, -1):
    if S[i] == S[i-1] == "L":
        ans[i-2] += ans[i]
        ans[i] = 0

print(*ans)


Measured memory_bytes: 6400
package main

import (
	"fmt"
)

// https://atcoder.jp/contests/abc158/tasks/abc158_b
func main() {
	var n, a, b, output int
	fmt.Scanf("%d %d %d", &n, &a, &b)
	output = n / (a + b) * a
	if n%(a+b) < a {
		output += n % (a + b)
	} else {
		output += a
	}
	fmt.Println(output)
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<double> cost(n);
    for (int i = 0; i < n; i++){
        cost[i] = fabs(T - 0.006*h[i] - a);
    }

    int ans = distance(cost.begin(), min_element(cost.begin(), cost.end()));
    cout << ans + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]

def dfs(i, a, b, c):
    if i == N:
        if min(a, b, c) > 0:
            return abs(A - a) + abs(B - b) + abs(C - c) - 30
        else:
            return float('inf')
    
    tmp0 = dfs(i + 1, a, b, c)
    tmpa = dfs(i + 1, a + L[i], b, c) + 10
    tmpb = dfs(i + 1, a, b + L[i], c) + 10
    tmpc = dfs(i + 1, a, b, c + L[i]) + 10
    ans = min(tmp0, tmpa, tmpb, tmpc)
    
    return ans

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
X,K,D = map(int,input().split())
X = abs(X)
ans = int(1e9) + 7
val = X//D
# print(val)
if val > K:
    print(X - (D*K))
else:
    K -= val
    if K % 2 == 0:
        print(X - (D*val))
    else:
        print(abs(X - (D*val) - D))


Measured memory_bytes: 61776
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  char b;
  sc.scan(b);

  if (b == 'A') {
    writeln("T");
    return;
  } else if (b == 'T') {
    writeln("A");
    return;
  } else if (b == 'C'){
    writeln("G");
    return;
  } else if (b == 'G') {
    writeln("C");
    return;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }

    Scanner kbd = new Scanner(System.in);

    void run(){
	while(kbd.hasNext()){
	    int m = kbd.nextInt();
	    int t = kbd.nextInt();
	    int p = kbd.nextInt();
	    int r = kbd.nextInt();
	    if(m!=0) solve(m, t, p, r); // m>=120より
	}
    }

    void solve(int m, int t, int p, int r){
	Data[] data = new Data[t]; // チームごとのデータ記録
	for(int i=0; i<t; i++){
	    data[i] = new Data(i+1, p);
	}
	while(r>0){
	    int time = kbd.nextInt();
	    int team = kbd.nextInt();
	    int pro = kbd.nextInt();
	    boolean cor;
	    int c = kbd.nextInt();
	    if(c==0)  cor = true;
	    else cor = false;
	
	    // 読み込み
	    data[team-1].sendPro(time, pro, cor);
	    r--;
	}
	// ソート
	 final boolean[][] same = new boolean[t+1][t+1];
	Arrays.sort(data, new Comparator<Data>(){
		public int compare(Data d1, Data d2){
		    int p1 = d1.getSolved();
		    int p2 = d2.getSolved();
		    if(p1 != p2) return p2-p1;
		    int time1 = d1.getTime();
		    int time2 = d2.getTime();
		    if(time1 != time2) return time1-time2;
		    int t1 = d1.getN();
		    int t2 = d2.getN();
		    same[t1][t2] = same[t2][t1] = true;
		    return t2-t1;
		}
	    }
	    );

	// 出力
	System.out.print(data[0].getN());
	for(int i=1; i<data.length; i++){
	    if(same[data[i].getN()][data[i-1].getN()])
		System.out.print("=");
	    else
		System.out.print(",");
	    System.out.print(data[i].getN());
	}
	System.out.println();
    }
}

class Data{
    int team;  //チーム番号
    int solved; // 解けた問題数
    int alltime; // かかった時間
    int[] pena;  // ペナルティ保存
    boolean[] solve;  // 解けているかどうか

    Data(int t, int p){  // p = 問題数
 	team = t;
	pena = new int[p];
	solve = new boolean[p];
    }

    void sendPro(int t, int p, boolean c){
	if(c){
	    alltime += (t + pena[p-1]);
	    solved++;
	    pena[p-1] = 0;
	}
	else pena[p-1] += 20;
    }

    int getTime(){ return alltime; }
    int getSolved(){ return solved; }
    int getN(){ return team;}
}

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

int main() {
	int N, H; cin >> N >> H;
	vector<int> a(N), b(N);
	int ma = 0;
	for(int i = 0; i < N; ++i) {
		cin >> a[i] >> b[i];
		ma = max(a[i], ma);
	}
	vector<int> c, d;
	for(int i = 0; i < N; ++i) {
		if(b[i] >= ma) {
			c.push_back(a[i]), d.push_back(b[i]);
		}
	}
	sort(rbegin(c), rend(c));
	sort(rbegin(d), rend(d));
	N = c.size();

	int ans = 0;
	for(int i = 0; i < N && H > 0; ++i, ++ans) {
		H -= d[i];
	}
	ans += (max(0, H) + c[0] - 1) / c[0];

	cout << ans << endl;
}

Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define MOD 1000000007

typedef long long ll;
 
using namespace std;

ll dfs(vector<vector<int>>& nodes, ll& k, int curr, int from) {
  int color_num = from == -1 ? k - 1 : k - 2;
  ll case_num = 1;
  for (int& next : nodes[curr]) {
    if (next == from) continue;
    case_num *= color_num;
    case_num %= MOD;
    color_num--;
  }
  for (int& next : nodes[curr]) {
    if (next == from) continue;
    case_num *= dfs(nodes, k, next, curr);
    case_num %= MOD;
  }
  return case_num;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<vector<int>> nodes(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    nodes[a].push_back(b);
    nodes[b].push_back(a);
  }
  cout << dfs(nodes, k, 0, -1) * k % MOD << endl;
  return 0;
}

Measured memory_bytes: 11520
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define ROOP() while (true)

int main(){
    
    string S,T;
    cin >> S >> T;

    vector<int> s[26];
    vector<int> t[26];
    for(int i=0; i<T.size(); i++){
        s[S[i]-'a'].push_back(i);
        t[T[i]-'a'].push_back(i);
    }

    set<vector<int>> s2;
    set<vector<int>> t2;
    for(int i=0; i<26; i++){
        s2.insert(s[i]);
        t2.insert(t[i]);
    }

    if(s2 == t2) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 4360
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        a: [u64; n],
    }

    for i in k .. n {
        let right = a[i];
        let left = a[i - k];
        if left < right {
            println!("Yes");
        } else {
            println!("No");
        }
    }


}


Measured memory_bytes: 5624
#include <iostream>
#include <algorithm>
//#include <iomanip>
using namespace std;
int main() {

	int r, g, b, n;
	cin >> r >> g >> b;
	n = r * 100 + g * 10 + b;
	if (n % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

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

public class Main {
	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    StringBuilder sb = new StringBuilder();
	    int n = 0;
	    int count = 0;
	    while (true) {
    		String line = "";
    		if (count % 2 == 0) {
	    		line = br.readLine();
			    if ("0".equals(line)) break;

			    n = Integer.parseInt(line);

    		} else {
			    String[] input = br.readLine().split(" ");

		    	double total = 0d;
		    	double average = 0d;
		    	double var = 0d;
		    	double foo = 0d;
		    	double stdev = 0d;

		    	for (int i = 0; i < n; i++) {
		    		total += Double.parseDouble(input[i]);
		    	}

		    	average = total / n;

		    	for (int i = 0; i < n; i++) {
		    		var += Math.pow(Double.parseDouble(input[i]) - average, 2);
		    	}
		    	foo = var / n;

		    	stdev = Math.sqrt(var / n);

		    	sb.append(stdev).append("\n");
    		}
    		count++;
	    }
	    System.out.print(sb.toString());
	}
}

Measured memory_bytes: 26544
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

H,N = inputIL()
M = inputILL(N)


cospa = max(a/b for a,b in M)

dp = [[0 for j in range(H+1)] for i in range(N)]
a0, b0 = M[0]
dp[0] = [((j+(a0-1))//a0)*b0 for j in range(H+1)]

for i in range(1,N):
  a,b = M[i]
  for j in range(H+1):
    if j <= a:
      dp[i][j] = min(dp[i-1][j],b)
    else:
      dp[i][j] = min(dp[i-1][j] , dp[i][j-a]+b)

print(dp[-1][-1])

Measured memory_bytes: 134388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n, k;
  cin >> n >> k;
  vl a(n), b(n);
  rep(i, n) {
    cin >> a[i];
  }
  rep(i, n) {
    cin >> b[i];
  }

  sort(a.begin(), a.end());
  sort(b.rbegin(), b.rend());

  auto round_up = [](ll a, ll b) {
    if (a < 0) return 0LL;
    return (a+b-1)/b;
  };

  auto f = [&](ll x) {
    ll cnt = 0;
    rep(i, n) {
      cnt += round_up(a[i]*b[i]-x, b[i]);
    }
    return cnt<=k;
  };

  ll ng = -1;
  ll ok = 5e18;
  while (ok-ng > 1) {
    ll mid = (ok+ng)/2;

    if (f(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  cout << ok << endl;
}


Measured memory_bytes: 3456
#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;
    vector<int> A(n);
    int s = 0;
    rep(i, n) {
        cin >> A[i];
        s += A[i];
    }
    vector<int> B;
    for (int i = 1; i*i <= s; ++i) {
        if (s % i == 0) {
            B.push_back(i);
            B.push_back(s/i);
        }
    }
    int ans = 0;
    for (int x: B) {
        vector<int> C(n);
        int t = 0;
        rep(i, n) {
            C[i] = A[i] % x;
            t += C[i];
        }
        sort(C.begin(), C.end());
        int u = 0;
        rep(i, n-t/x) u += C[i];
        if (u <= k) {
            ans = max(ans, x);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  char a, t;
  cin >> a >> t;
  if (a == 'H') cout << t << '\n';
  if (a == 'D') {
    if (t == 'H') cout << 'D' << '\n';
    else cout << 'H' << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    N = int(input())
    a_list = list(map(int, input().split()))

    cnt = 0


    for i in range(N-1):
        if a_list[i] == a_list[i+1]:
            add_num = a_list[i+1]
            while True:
                add_num += 1
                if add_num not in a_list:
                    a_list[i+1] = add_num
                    break
            cnt += 1
    
    print(cnt)
    


    

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <stdio.h>

int main()
{
	int n,x,sum = 0,max = -1;
	scanf("%d",&n);
	for(int i = 0;i < n;i++){
		scanf("%d",&x);
		if(x >= max){
			max = x;
			sum++;
		}
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
a,b=map(int, input().split())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

r=list(set(divisor(a)) & set(divisor(b)))

ans=1
for i in r:
    if is_prime(i):
        ans+=1

print(ans)



Measured memory_bytes: 5192
S = input()

if S[0] == "A":
    T = S[2:-1]
    flag = 0
    ok = -1
    for i in T:
        if i == "C" and flag ==0:
            ok = T.index("C")
            flag = 1
        elif i == "C" and flag == 1:
            ok = -1
            break
    if ok >= 0:
        H = S[1:]
        F = H[:ok+1] + H[ok+2:]
        t = False
        for k in F:
            if k.isupper():
                t = True
        if not t:
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 9012
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <list>
#include <numeric>
using namespace std;
 
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define pb push_back
 
int INF = INT_MAX / 10;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int W, H; cin >> W >> H;
	vector<int> a(2);
	a[0] = W + 1; a[1] = H + 1;
	vector<i_i> p;
	while (W--) {
		int x; cin >> x;
		p.pb(i_i(x, 0));
	}
	while (H--) {
		int x; cin >> x;
		p.pb(i_i(x, 1));
	}
	sort(p.begin(), p.end());
	ll ans = 0;
	for (i_i z: p) {
		int t = z.second;
		a[t]--;
		ans += (ll)a[!t] * z.first;
	}
	cout << ans << endl;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define all_acc(x) (x).begin(),(x).end(),0LL
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

int accumulate(int* a,int n){
    return accumulate(a,a+n,0LL);
}

int accumulate(vector<int> a){
    return accumulate(a.begin(),a.end(),0LL);
}

signed main(){ 
   int n,m,k; cin>>n>>m>>k;

   vector<int> A(n+1),B(m+1);
   A[0]=0; B[0]=0;
   for(int i=1;i<=n;i++){
       int ai; cin>>ai;
       A[i]=ai+A[i-1];
   }
   for(int i=1;i<=m;i++){
       int bi;cin>>bi;
       B[i]=bi+B[i-1];
   }

   int ans=0,j=m;

   for(int i=0;i<=n;i++){
       if(k<A[i]) break;
       while(B[j]>k-A[i]){
           j--;
       }
       ans=max(ans,i+j);
   }

   cout<<ans<<endl;
}  

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

#define endl '\n'
#define rep(i,s,n)      for (int i = s ; i < n ; i++)
#define repp(i,s,n)    for (int i = s ; i <= n ;i++)
#define all(a)      a.begin(),a.end()
#define sz(v)    (int)v.size()
#define NumofDigits(n)    ((long long)log10(n)+1)
#define Unique(n)         (n).erase(unique(all(n)), (n).end())
#define test    int s ; cin >> s; while (s--)
#define readArr    int n ; cin >> n ; int arr[n]; rep(i,0,n)cin>>arr[i]
#define isvowel(a)   (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fast        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll ;

void readFromText ()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
}

const double Pi = acos(-1.0);

bool isMultiBy4 (int a ){
    return a%4==0;
}

bool myFun (int i , int j ) {

}

const int MAX = 1e6;
int mn [MAX+9];
int freq[MAX+9];
int pref[MAX+9];

int main()
{
    fast;
//    readFromText();
    int a , b; cin >> a >> b ;
    bool state = false ;
    int j = a ;
    for (int i = 0 ; i <= a ; i++,j--){
        if ((i*2+j*4)==b)state=true;
    }
    if (state)cout << "Yes" ;
    else cout << "No" ;
    return 0;
}



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

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

using namespace std;

typedef long long ll;
const int MAX = 10010;

struct Data { int s,t,e; };

int N,M,L;
ll b[MAX],c[MAX];

int main(){
  cin >> N >> M;
  vector<Data> arr;
  int s,t,e;
  while( cin >> s >> t >> e, s|t|e ) arr.push_back((Data){s,t,e});
  cin >> L;
  rep(i,L) {
    rep(j,M) cin >> b[j];
    memset(c,0,sizeof(c));
    rep(k,arr.size()) {
      c[arr[k].s-1] += (ll)arr[k].e * b[arr[k].t-1];
    }
    rep(k,N){
      if( k ) printf(" ");
      cout << c[k];
    } puts("");
  }

  return 0;
}

Measured memory_bytes: 2004
#include<iostream>
#include<cstdio>
#define mod 1000000007
using namespace std;
int main() {
	long long a,b;
	scanf("%lld %lld",&a,&b);
	if(abs(a-b)>1) {
		printf("0");
	} else {
		long long sum=1;
		if(abs(a-b)==0) {
			for(long long i=a; i>=1; i--) {
				sum*=i;
				sum%=mod;
			}
			sum*=sum*2;
			sum%=mod;
		} else {
			for(long long i=a; i>=1; i--) {
				sum*=i;
				sum%=mod;
			}
			for(long long i=b; i>=1; i--) {
				sum*=i;
				sum%=mod;
			}
		}
		printf("%lld",sum);
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j] <= x) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

int main(void) {
  int i, q;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  q = partition(0,n-1);

  for(i=0; i<n; i++) {
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 2096
X, Y = map(int,input().split())

MOD = 10**9 + 7

def comb(n, r):
    if n < r or n < 0 or r < 0:
        return 0

    n += 1
    over = 1
    under = 1
    for i in range(1,r + 1):
      over = over * (n - i) % MOD
      under = under * i % MOD
    return over * pow(under, MOD - 2, MOD) % MOD

if (X + Y) % 3 != 0:
    print(0)
else:
    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3
    print(comb(a+b, a))



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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define bil ((ll)1e9)
#define mod ((ll)1e9+7)

ll pow_mod(ll,ll);

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<int> a(n);
    for(auto &x:a)
        cin >> x;
    
    ll ans=0;
    if(n%2==0){
        ans=pow_mod(2,n/2);
    }else{
        ll x=n/2;
        ans=pow_mod(2,x);
    }

    sort(a.begin(),a.end());
    if(n%2==1){
        a.erase(a.begin());
        n-=1;
    }

    for(int i=0;i<n-1;i+=2){
        if(a[i]!=a[i+1]){
            cout << 0 << endl;
            return 0;
        }
    }

    cout << ans << endl;

    return 0;
}

ll pow_mod(ll x,ll y){
    if(y==0){
        return 1;
    }else if(y%2==0){
        ll t=pow_mod(x,y/2);
        return t*t%mod;
    }else if(y%2==1){
        return pow_mod(x,y-1)*x%mod;
    }

    return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

int N;
const int MAXN = 100001;
typedef vector<vector<int> > Graph;
int color[MAXN] = {0};
int a[MAXN],b[MAXN];
map<pair<int,int>, int> M;
int K;

void search(Graph &G, int pair_node, int color) {
    int counter = 0;
    for(int nn : G[pair_node]) {
        counter++;
        if(counter==color)counter++;
        if(M[{nn,pair_node}] != 0 || M[{pair_node,nn}] != 0){
            counter--;
            continue;
        }
        M[{nn,pair_node}] = counter;
        M[{pair_node,nn}] = counter;
        search(G, nn, counter);
    }
}



int main(){
    cin >> N;
    pair<int,int> p = {0,0}; //{接点数,ノードの番号}s
    Graph G(N+1);
    
    rep(i,N-1) {
        cin >> a[i] >> b[i];
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
        if(G[a[i]].size() > p.first)p = {G[a[i]].size(),a[i]};
        if(G[b[i]].size() > p.first)p = {G[b[i]].size(),b[i]};
    }
    K = p.first;
    search(G, p.second, 0);
    cout << p.first << endl;


    rep(i,N-1) {
        cout << M[{a[i],b[i]}] << endl;
    }



    return 0;
}

Measured memory_bytes: 23304
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	int A, B; cin >> A >> B;

	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else cout << "Impossible" << endl;

}

Measured memory_bytes: 3572
/*input
4 6
#..#..
.....#
....#.
#.#...
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define mod 1000000007
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define out(container) cout << #container << " "; for (auto it : container) cout << it << " "; cout << endl;

template < typename T> int sz(T x) {return x.size();}
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
    int x = 1 % mod;
    while(b){
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

bool isPrime (ll n) {
    if(n == 1) return 0;
    if(n == 2 or n == 3) return 1;
    if(n % 2 == 0 or n % 3 == 0) return 0;

    for(ll i = 5; i * i <= n; i += 6) if(n % i == 0 or n % (i + 2) == 0) return 0;
    return 1;
}


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

  int n, m;
  cin >> n >> m;
  vector <vector <int> > vec(n, vector <int>(m, 0)), arr(n, vector <int> (m, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;
      if (c == '.') vec[i][j] = 1, arr[i][j] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (vec[i][j] == 0) continue;
      vec[i][j] += vec[i][j - 1];
    }
    int cur = vec[i][m - 1];
    for (int j = m - 1; j >= 0; j--) {
      if (vec[i][j] == 0) {
        if (j) cur = vec[i][j - 1];
      }
      vec[i][j] = cur;
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 1; i < n; i++) {
      if (arr[i][j] == 0) continue;
      arr[i][j] += arr[i - 1][j];
    }
    int cur = arr[n - 1][j];
    for (int i = n - 1; i >= 0; i--) {
      if (arr[i][j] == 0) {
        if (i) cur = arr[i - 1][j];
      }
      arr[i][j] = cur;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(ans, vec[i][j] + arr[i][j] - 1);
    }
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 31616
import java.util.*;


public class Main{
	public static void main( String args[] ) {
		String input;
		int counter  = 0;
		Scanner scan = new Scanner( System.in);
		
		input = scan.next();
		
		
		
		for( int i = 0; i < input.length();  i++) {
			if( input.charAt(i) == '1') {
				counter++;
			}
		}
		
		
		System.out.println( counter );
		
		scan.close();
		
	}
}

Measured memory_bytes: 22740
N = int(input())
As = list(map(int, input().split()))
A = [As[i] - (i+1) for i in range(N)]
A.sort()
b1 = A[N//2]
b2 = A[N//2 -1]
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += abs(A[i] -b1)
    ans2 += abs(A[i] - b2)
print(min(ans1, ans2))






Measured memory_bytes: 26180
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

template<class T> using V = vector<T>;
template<class T> using V2 = V<V<T>>;



void solve(){
  int a, b, c; cin >> a >> b >> c;
  cout << max(0, c - (a-b)) << endl;
}

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

Measured memory_bytes: 256
program prob1
    implicit none
    character(len=19)::S
    character(len=5)::S1,S3
    character(len=7)::S2
    character(len=1)::a,b
    read(*,*) S1,S2,S3
    S(1:5) = S1
    S(6:6) = " "
    S(7:13) = S2
    S(14:14) = " "
    S(15:19) = S3
    write(*,'(a)') S
    stop
end program

Measured memory_bytes: 2888
void main() {
    writeln("ABC", readln.chomp);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

int main() {
    using namespace std;
    unsigned long K;
    cin >> K;
    deque<pair<unsigned long, unsigned long>> dfs;
    bitset<100000> visited;
    dfs.emplace_back(1, 1);
    while(!dfs.empty()){
        auto i = dfs.front().first, d = dfs.front().second;
        dfs.pop_front();
        if(!i)return 0 % printf("%lu\n", d);
        visited[i] = true;
        if(!visited[i * 10 % K])dfs.emplace_front(i * 10 % K, d);
        if(!visited[++i %= K])dfs.emplace_back(i, d + 1);
    }
}

Measured memory_bytes: 1408
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

class Program {
    static void Main(string[] args) {
        var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        Console.WriteLine(a[0] + a[1] >= a[2] ? "Yes" : "No");
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  rep(i,n){
    cin >> x[i];
    y[i] = x[i];
  }
  sort(x.begin(),x.end());
  int mid_a = x[n/2 - 1];
  int mid_b = x[n/2];
  rep(i,n){
    if(y[i] < mid_b) cout << mid_b << endl;
    else cout << mid_a << endl;
  }
  return 0;
}


Measured memory_bytes: 3712