akhauriyash/Code-Regression huggingface dataset:
/**
 *    Author: "Robin Singh" !!
 *    rob_in_1
**/

#include <bits/stdc++.h>
using namespace std;

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

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define ff first
#define ss second
#define MP make_pair
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     
#define bk(i, j, k) for(int i = j-1; i >= k; i--)
#define mem(ptr, val)  memset(ptr, val, sizeof ptr)
#define sbit(n)  __builtin_popcount(n)
#define nl "\n"

typedef long double ld;
typedef pair<int, int> pii;
typedef vector <int> vi;
typedef vector < pair<int,int> > vpii;
const long double eps = 1e-9;
const int mod = 1e9+7;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

//*********************************!Template Ends Here!**********************************//

const int nn = 2e5+5;

void robin(){
    int n, k;
    cin >> n >> k;
    int c = n/2 + (n % 2 != 0);
    if(c >= k) cout << "YES";
    else cout << "NO";
}

int32_t main(){
    // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        robin();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    char tmp;
    string S;
    cin >> A >> B;

    if(A==1)
	A=14;
    if(B==1)
	B=14;
    
    
    // ans = max(A*B, C*D);
    
    // cout <<ans<<endl;
    
    if(A < B)
    	cout << "Bob"<<endl;
    else if(A>B)
    	cout <<"Alice"<<endl;
    else
	cout <<"Draw"<<endl;
    

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
    	
}


Measured memory_bytes: 256
import sys
from itertools import product

input = sys.stdin.readline


def main():
    N = int(input())
    F = [None] * N
    for i in range(N):
        F[i] = tuple(map(int, input().split()))
    P = [None] * N
    for i in range(N):
        P[i] = tuple(map(int, input().split()))

    ans = -float("inf")
    for comb in product(range(2), repeat=10):
        if sum(comb) == 0:
            continue
        c = [0] * N
        for j, is_open in enumerate(comb):
            if is_open:
                for i in range(N):
                    c[i] += F[i][j]
        profit = sum(P[i][c[i]] for i in range(N))
        ans = max(ans, profit)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007;
int main() {
	ll i,j,k,l,m,n,t,w;
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> w;
	ll maxValue = 100007;

	vector<pair<ll, ll> > weights(n);
  for (i = 0; i < n; i++){
    cin >> j >> k;
    weights[i] = make_pair(j, k);
  }

  vector<ll > dp(maxValue+1, w+1);

  ll ans = 0;
  dp[0] = 0;
  for (i = 0; i < n; i++)
  {
    vector<ll > newDP(maxValue+1, w+1);
    for (j = 0; j <= maxValue; j++){
      ll weight = weights[i].first, value = weights[i].second;
      newDP[j] = min(newDP[j], dp[j]);
      if (dp[j] > w - weight)
      {
        continue;
      }
      newDP[j + value] = min(newDP[j + value], dp[j] + weight);
      // cout << i << ' ' << j << ' ' << dp[j] << ' ' << weight << ' ' << newDP[j + value] << endl;
    }
    dp = newDP;
  }
  for (i = 0; i <= maxValue; i++){
		if(dp[i]<=w){
    	ans = max(ans, i);
		}
  }

	cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1904
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

// ナップサック

// 品物がN個しかなかったら、価値の最大は V_MXAX * N だと思ってたので
// jのループを1000*Nまでにしてたがなぜか通らなかった

ll N, W;
ll w[101], v[101];
ll dp[101][100001]; // dp[i][j] : i番目までの商品で価値j持って帰る際の最小の重さ

void input() {
	cin >> N >> W;
	for (int i = 1; i <= N; i++) cin >> w[i] >> v[i];
	for (int j = 0; j <= 100000; j++) dp[0][j] = LLINF;
}

void solve() {
	dp[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= 100000; j++) {
			if (j >= v[i]) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
			else dp[i][j] = dp[i - 1][j];
		}
	}

	int ans = 0;
	for (int j = 0; j <= (1000*N); j++) {
		if (dp[N][j] <= W) {
			// 持って帰れる
			ans = j;
		}
	}
	cout << ans << endl;
}

int main() {
	input();
	solve();

	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1e9 + 7;

int main() {
  string str, subl = "", subr = "";
  int q;
  int flag = 0;
  cin >> str >> q;
  rep(i, q) {
    int t, s;
    char c;
    cin >> t;
    if (t == 2) cin >> s >> c;
    if (t == 1) {
      flag += 1;
    }
    if (t == 2) {
      if (s == 1) {
        if (flag % 2 == 0) {
          subl += c;
        } else {
          subr += c;
        }
      } else {
        if (flag % 2 == 0) {
          subr += c;
        } else {
          subl += c;
        }
      }
    }
  }
  if (flag % 2 == 0) {
    reverse(ALL(subl));
    cout << subl << str << subr << endl;
  } else {
    reverse(ALL(subr));
    reverse(ALL(str));
    cout << subr << str << subl << endl;
  }
  return 0;
}

Measured memory_bytes: 1088
#include <iostream>
#include <cmath>
#include <string>
typedef long long ll;
using namespace std;

ll n;

void solve()
{
    ll count;
    count = n - 1;
    for (ll x = 1; x < floor(sqrt(n)) + 1; x++)
    {
        if (n % x == 0)
        {
            ll y = n / x;
            count = min(x + y - 2, count);
        }
    }

    cout << count;
}

int main()
{
    cin >> n;

    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
// vector<int> vec(3); = vector<int> vec={0,0,0}
// vec.at()
// sort(num.begin(),num.end(), greater<int>());
// reverse(num.begin(),num.end());

// 切り上げ　a/b+1
//  1からNの総和　N*(N+1)/2
 
int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  
  if(N<K){
  	cout << N*X << endl;
  }else{
  	cout << K*X + (N-K)*Y << endl;
  }
}

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

int main() {

  while( true ) {

    long long int n, m, h, k;
    cin >> n >> m >> h >> k;
    if ( n == 0 ) break;

    vector< long long int > s;
    for ( long long int i = 0; i < n; i++ ) {
      long long int in;
      cin >> in;
      s.push_back( in );
    }

    vector< pair< long long int, long long int > > b;
    for ( long long int i = 0; i < m; i++ ) {
      long long int in_a, in_b;
      cin >> in_a >> in_b;
      b.push_back( make_pair( -in_b, in_a ) );
    }

    sort( b.begin(), b.end() );

    vector< long long int > a;
    for ( long long int i = 0; i < n; i++ ) {
      a.push_back( i );
    }

    long long int c[100000][2];
    for ( long long int i = 0; i < m; i++ ) {
      long long int k = b[i].second;
      swap( a[k], a[k-1] );
      c[i][0] = a[k];
      c[i][1] = a[k-1];
    }

    long long int cnt = 0;
    for ( long long int i = 0; i < k; i++ ) {
      cnt += s[ a[i] ];
    }

    long long int ans = cnt;
    for ( long long int i = 0; i < m; i++ ) {
      cnt = 0;
      for ( long long int j = 0; j < k; j++ ) {
	if ( c[i][0] == a[j] ) {
	  cnt += s[ c[i][1] ];
	}else if ( c[i][1] == a[j] ) {
	  cnt += s[ c[i][0] ];
	}else {
	  cnt += s[ a[j] ];
	}
      }
      ans = min( ans, cnt );
    }

    cout << ans << endl;

  }

  return 0;

}

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

using namespace std;

const char en = '\n';
using  ll =          long long;
using ull = unsigned long long;
#define REP(i  ,n) for(int i=0;i<n;i++)
#define FOR(i,s,g) for(int i=s;i<g;i++)
const ll INFL = 810810191911451400;
const int INF =       1919114514;

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

	int pasta=INF,juice=INF,buf;
	REP(i, 3){
		cin>>buf;
		pasta=min(pasta,buf);
	}
	REP(i, 2){
		cin>>buf;
		juice=min(juice,buf);
	}

	cout<<pasta+juice-50<<en;
	return 0;
}

Measured memory_bytes: 3180
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#define INF 2000

using namespace std;

 
int main(){
	int n,m,x,y,len;//n个点，m条边；
	cin>>n>>m;
	int disy[105][105],disx[105][105];//两个邻接矩阵表示两个图
	//disx为更新后的保存两点间最短路径的图，disy保存最开始的图 
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)	disy[i][j]=0,disx[i][j]=0;
			else disy[i][j]=INF,disx[i][j]=INF;
		}
	}
	for(int i=0;i<m;i++){
		cin>>x>>y>>len;
		x-=1,y-=1;
		disy[x][y]=len,disy[y][x]=len;
		disx[x][y]=len,disx[y][x]=len;
	}
	for(int k=0;k<n;k++){//枚举所有中间点
		for(int i=0;i<n;i++){//枚举所有起点 
			for(int j=0;j<n;j++){//枚举所有终点 
				disx[i][j]=min(disx[i][j],disx[i][k]+disx[k][j]);
				//更新两点间距离为最短路径的距离 
			} 
		} 
	}
	int ans=0;//最开始所有边都是最短路径
	for(int i=0;i<n;i++){//邻接矩阵是对称的， 
		for(int j=0;j<n;j++){
			if(disx[i][j]!=disy[i][j]&&disy[i][j]!=2000)
				ans++;
		}
	}
	cout<<ans/2;
 	return 0;
}


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

int e, y;

int main() {
	cin >> e >> y;
	
	if (e == 0) {
		if (y <= 1911) { cout << "M" << y - 1868 + 1 << endl; }
		else if (y <= 1925) { cout << "T" << y - 1912 + 1 << endl; }
		else if (y <= 1988) { cout << "S" << y - 1926 + 1 << endl; }
		else { cout << "H" << y - 1989 + 1 << endl; }
	}
	else {
		if (e == 1) { y += 1868 - 1; }
		if (e == 2) { y += 1912 - 1; }
		if (e == 3) { y += 1926 - 1; }
		if (e == 4) { y += 1989 - 1; }
		cout << y << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
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
def cmb(n, r, mod):
   if ( r<0 or r>n ):
       return 0
   r = min(r, n-r)
   return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5+100
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
   g1.append( ( g1[-1] * i ) % mod )
   inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
   g2.append( (g2[-1] * inverse[-1]) % mod )
N,M=map(int,input().split())
A=factorization(M)
ans=1
if M==1:
 print(1)
else:
 for i in range(len(A)):
  ans*=cmb(N+A[i][1]-1, N-1, mod)
  ans%=(10**9+7)
 print(ans)

Measured memory_bytes: 57968
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

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

	vector<pair<int, int>> s(N);
	vector<pair<int, int>> t(N);

	for (int i = 0; i < N; ++i) {
		int S, T, X;
		cin >> S >> T >> X;
		s[i].first = S - X;
		s[i].second = X;
		t[i].first = T - X;
		t[i].second = X;
	}
	vector<int> D(Q);
	for (auto &x : D) {
		cin >> x;
	}

	sort(s.rbegin(), s.rend());
	sort(t.rbegin(), t.rend());

	multiset<int> x;

	for (auto d : D) {
		//cout << "D=" << d << endl;

		while (!s.empty() && s.back().first <= d) {
			//cout << "insert " << s.back().second << endl;
			x.insert(s.back().second);
			s.pop_back();
		}
		while (!t.empty() && t.back().first <= d) {
			//cout << "erase " << t.back().second << endl;
			auto it = x.find(t.back().second);
			if (it != x.end()) {
				x.erase(it);
			}
			t.pop_back();
		}
		
		if (x.empty()) {
			cout << -1 << endl;
		}
		else {
			cout << *x.begin() << endl;
		}
	}
}


Measured memory_bytes: 14592
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for i in range(n):
    d[a[i]] += 1

tot = 0
for key in d:
    if d[key] == 1: continue
    tot += cmb(d[key], 2)

#print(d)
for i in range(n):
    if d[a[i]] == 1:
        print(tot)
    elif d[a[i]] == 2:
        print(tot-1)
    else:
        print(tot - (d[a[i]] - 1))

Measured memory_bytes: 26772
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
ans = 0
for i in 0..n-1
  ans += b[a[i]-1]
  ans += c[a[i-1]-1] if (i != 0 && a[i]-a[i-1]==1)
end
puts ans


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(){
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ac = a/c;
	ll bc = b/c;
	ll ad = a/d;
	ll bd = b/d;
	ll ans = 0;
	if(ac*c == a) ans--;
	if(ad*d == a) ans--;
	ll x = c*d;
	int aa = min(c, d);
	int bb = max(c, d);
  ll r = aa % bb;
  while(r!=0){
    aa = bb;
    bb = r;
    r = aa % bb;
  }
	ll ko = x/bb;
	ll ako = a/ko;
	ll bko = b/ko;
	if(ako*ko == a) ans++;
	cout << ans +b-a+1 -(bc-ac) -(bd-ad) +(bko-ako)<< endl;
}

Measured memory_bytes: 256
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

a, b, c = MAP()
print("Yes" if c-a-b > 0 and a**2+b**2+c**2-2*(a*b+b*c+c*a) > 0 else "No")

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

int n, k;
vector<long long> w;
bool check( long long p )
{
	bool res = true;
	int j = 0;
	long long sum = 0;
	for( int i = 0; i < n; i++ ) {
		if( w[i] > p ) {
			res = false;
			break;
		}
		if( sum + w[i] > p ) {
			j++;
			sum = 0;
			if( j >= k ) {
				res = false;
				break;
			}
		}
		sum += w[i];
	}
	return res;
}

int main()
{
	cin >> n >> k;
	w = vector<long long>( n );
	for( int i = 0; i < n; i++ ) {
		cin >> w[i];
	}

	long long l = 0;
	long long r = 100000 * 10000;
	while( r - l > 1 ) {
		long long m = ( l + r ) / 2;
		if( check( m ) ) {
			r = m;
		}
		else {
			l = m;
		}
	}
	long long ans = r;

	cout << ans << endl;
}



Measured memory_bytes: 4424
#include <cstdio>
#include <string>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

int main() {
    char c;
    scanf("%c", &c);
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') printf("vowel\n");
    else printf("consonant\n");
}

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

int main(void) {
    int a,b;
    while (1){
        cin >> a;
        if (cin.eof())
            break;
        cin >> b;
        cout << floor(log10(a+b)+1) << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    string s;
    cin >> s;

    int a[3] = {0};
    rep(i, 3) a[s[i] - 'a']++;

    rep(i, 3)
    {
        if (a[i] != 1)
        {
            cout << "No" << '\n';
            return 0;
        }
    }
    cout << "Yes" << '\n';
    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  if(s == "zyxwvutsrqponmlkjihgfedcba"){
    cout << "-1\n";
    return 0;
  }
  
  vector<bool> x(26, false);
  if(s.size() < 26){
    for(int i = 0; i < s.size(); i++){
      x.at(s.at(i) - 'a') = true;
    }
    cout << s;
    for(int i = 0; i < 26; i++){
      if(x.at(i) == false){
        cout << (char) (i + 'a') << '\n';
        return 0;
      }
    }
  }
  
  string t = s;
  for(int i = 25; i >= 0; i--){
    x.at(t.at(i) - 'a') = true;
    for (int j = t.at(i) - 'a' + 1; j < 26; j++) {
      if (x.at(j) == true) {
        t.at(i) = j + 'a';
        cout << t << '\n';
        return 0;
      }
    }
    t.pop_back();
  }
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define M 1010
#define N 1000000
#define D double
#define LL long long
#pragma GCC optimize(2)
using namespace std;
int x;
int main()
{
	std::ios::sync_with_stdio(false);
	cin>>x;
	if(x==1) cout<<0;
	if(x==0) cout<<1;
	return 0;
}
/*
*/


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

signed main(){
    int cur=0;
    string S;
    cin>>S;
    while(cur<S.size()&&S[cur]!='C')cur++;
    if(cur==S.size()){
        cout<<"No"<<endl;
        return 0;
    }
    while(cur<S.size()&&S[cur]!='F')cur++;
    cout<<(cur!=S.size()?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        sum ^= A[i];
    }

    //sumで1が立っているbitはどう分けても1になるので考えなくて良い
    //つまり各Aについてsumを反転させたものだけでマスクをかける
    for (ll i = 0; i < N; i++) {
        A[i] &= ~sum;
    }

    //残ったものについて最適化していく
    ll next_position = 0;
    ll rank = -1;
    for (ll i = 59; i >= 0; i--) {
        //i桁目が立っているものを先頭に持っていって下位を消していく
        for (ll j = next_position; j < N; j++) {
            if (A[j] & (1ull << i)) {
                //立っているので先頭へ
                swap(A[j], A[next_position]);
                for (ll k = next_position + 1; k < N; k++) {
                    if (A[k] & (1ull << i)) {
                        A[k] ^= A[next_position];
                    }
                }
                if (next_position++ == 0) {
                    rank = min(i, N - 1);
                }
                break;
            }
        }
    }

    //答えとして立たせることができるかどうかを確認
    ll ans = 0;
    next_position = 0;
    for (ll i = 59; i >= 0; i--) {
        //初めてiが立っているところで制御
        for (ll j = next_position; j < N; j++) {
            if (A[j] & (1ull << i)) {
                //ansに応じてなんやかんやする
                if ((ans & (1ull << i)) == 0) {
                    ans ^= A[j];
                }
                next_position++;
                break;
            }
        }
    }
    ans = ans * 2 + sum;

    cout << ans << endl;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, X, T;
  cin >> N >> X >> T;
  ll ans = ceil((long double)N / X) * T;
  cout << ans << endl;
  return 0;
}


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

int main() {
	// your code goes here
	int N, W;
	cin>>N>>W;
	
	vector<int> v(N, 0), w(N, 0);
	vector<vector<long long>> dp(N+1, vector<long long>(W+1, 0));
	
	for(int i=0; i<N; i++) cin>>w[i]>>v[i];
	
	for(int i=0; i<=N; i++){
		for(int j=0; j <= W; j++){
			if(i == 0 || j == 0)
				dp[i][j] = 0;
			else if(w[i-1] > j)
				dp[i][j] = dp[i-1][j];
			else
				dp[i][j] = max(dp[i-1][j-w[i-1]] + v[i-1], dp[i-1][j]);
		}
	}
	
	cout<<dp[N][W];
	return 0;
}

Measured memory_bytes: 83024
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    lint prev = 2, cur = 1;
    range(i, 0, N - 1) {
        lint tmp = cur;
        cur = cur + prev;
        prev = tmp;
    }
    cout << cur << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  cin >> N;
  set<int> s;
  rep(i, 1, 9) {
    rep(j, 1, 9) { s.insert(i * j); }
  }
  if (s.find(N) == s.end()) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}
void solve() {
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <bitset>
using namespace std;

int main(void){
    string s;
    cin >> s;

    for(int bit=0; bit < (1<<(s.length() - 1)); ++bit){
        int tmp = s[0] - '0';
        for(int i = 0; i < 3; i++){
            if(bit & (1<<i)){
                tmp += (s[i + 1] - '0');
            } else{
                tmp -= (s[i + 1] - '0');
            }
        }
        if(tmp == 7){
            cout << s[0];
            for(int i = 0; i < 3; i++){
                if(bit & (1<<i))
                    cout << "+";
                else
                    cout << "-";
                cout << s[i + 1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

if t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2:
    print("infinity")
    exit(0)
if t1 * a1 + t2 * a2 > t1 * b1 + t2 * b2:
    a1, b1 = b1, a1
    a2, b2 = b2, a2
if a1 < b1:
    print("0")
    exit(0)

l, r, labe, ans = 2, 10**18, False, 10**18

while l <= r:
    m = l + (r - l) // 2
    xa = (m - 1) * (t1 * a1 + t2 * a2) + t1 * a1
    xb = (m - 1) * (t1 * b1 + t2 * b2) + t1 * b1
    if xa == xb:
        labe = True
        ans = m
        break;
    elif xa < xb:
        ans = m
        r = m - 1
    else :
        l = m + 1

if labe:
    print(2 * (ans - 1))
else :
    print(2 * (ans - 1) - 1)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define Int int64_t
using namespace std;
const Int M=(Int)(1e9+7);

inline Int mmul(Int a,Int b){if(a>=M)a=a%M;if(b>=M)b=b%M;if(a*b>=M)return(a*b)%M;return(a*b);}
inline Int madd(Int a, Int b){if(a>=M)a=a%M;if(b>=M)b=b%M;if(a+b>=M)return(a+b)%M;return(a+b);}



int main()
{
    int A,B;
    cin>>A>>B;
    cout<<string(max(A,B),char(min(A,B)+'0'));
}

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

int main(){
    using namespace std;
    unsigned long Q;
    cin >> Q;
    constexpr auto M{205891132094649UL};
    const auto& calc = [](auto a, auto b, auto c, auto d){
        auto u{b}, l{b}, p{M};
        while(p /= 3)if((a / p + (4 - a / p % 3) % 3) * p <= c){
            if(b / p % 3 == 1){
                u = b / (3 * p) * 3 * p + 2 * p;
                l = b / (3 * p) * 3 * p + p - 1;
                break;
            }
        }
        return c - a + min(u - b + max(u, d) - min(u, d), b + d - 2 * l);
    };
    for(unsigned long _{0}, a, b, c, d; _ < Q; ++_){
        cin >> a >> b >> c >> d;
        if(--a > --c)swap(a, c), swap(b, d);
        if(--b > --d){
            b = M - b - 1;
            d = M - d - 1;
        }
        cout << max(calc(a, b, c, d), calc(b, a, d, c)) << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(1 <=a && a <=100 && 1 <=b && b <= 100){
        printf("%d %d\n",a*b,a+a+b+b);
    }
    
    return 0;
}


Measured memory_bytes: 2028
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <array>

using namespace std;

class LCSubseq
{
public:
  int solve( const string x, const string y );
};

int LCSubseq::solve( const string x, const string y )
{
  vector<vector<int>> dp( 1 + x.size(), vector<int>( 1 + y.size(), 0 ) );
  
  for ( auto i = 0; i < (int)x.size(); ++i )
    for( auto j = 0; j < (int)y.size(); ++j )
      {
        if ( x[i] == y[j] )
          dp[i+1][j+1] = dp[i][j] + 1;
        else
          dp[i+1][j+1] = max( dp[i+1][j], dp[i][j+1] );
      }
  
  cout << dp[x.size()][y.size()] << endl;
  
  return 0;
}

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

  LCSubseq l;

  string x, y;
  
  for ( auto i = 0; i < n; ++i )
    {
      cin >> x;
      cin >> y;
      l.solve( x, y );
    }
  
  return 0;
}

Measured memory_bytes: 5044
// Igorjan94, template version from 13 October 2017. C++17 version, modified 18 march 2020 (writeln<tuple>, whole->all) {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <iomanip>

using namespace std;

#define FOR(i, m, n) for (int i = m; i <  (int) (n); ++i)
#define ROF(i, m, n) for (int i = m; i >= (int) (n); --i)
#define forn(i, n)   for (int i = 0; i < (int) (n); ++i)
#define  fori1(n)    for (int i = 1; i < (int) (n); ++i)
#define  forj1(n)    for (int j = 1; j < (int) (n); ++j)
#define   fori(n)    for (int i = 0; i < (int) (n); ++i)
#define   forj(n)    for (int j = 0; j < (int) (n); ++j)
#define     SZ(a)    int(size(a))

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

#define pb push_back
#define all(a) begin(a), end(a)
#define ints(a...) int a; readln(a)

//Igorjan
//}}}

void run()
{
    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> has(n + 1, {0, 0, 0});
    map<char, int> m = {{'R', 0}, {'G', 1}, {'B', 2}};
    ROF(i, n - 1, 0)
        has[i] = has[i + 1],
        has[i][m[s[i]]]++;
    ll ans = 0;
    fori(n)
        FOR(j, i + 1, n)
        if (s[i] != s[j])
        {
            ans += has[j][0] + has[j][1] + has[j][2] - has[j][m[s[i]]] - has[j][m[s[j]]];
            if (int k = j + (j - i); k < n && s[k] != s[i] && s[k] != s[j])
                ans--;
        }

    cout << ans << "\n";
}

//{{{
int main()
{
    ios_base::sync_with_stdio(false);
    run();
    cerr << fixed << setprecision(0) << "Execution time = " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 3356
import sys
from collections import Counter
from itertools import combinations

n, *s = [s[0] for s in sys.stdin.read().split()]

def main():
    c = Counter(s)
    res = 0
    for i, j, k in combinations('MARCH', 3):
        res += c[i] * c[j] * c[k]
    print(res)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 10812
# ABC122C - GeT AC
n, q = list(map(int, input().rstrip().split()))
s = input().rstrip()
arr = [list(map(int, input().rstrip().split())) for _ in range(q)]
cnt = [0] * (n + 1)
for i in range(n):
    if s[i : i + 2] == "AC":
        cnt[i + 1] = cnt[i] + 1
    else:
        cnt[i + 1] = cnt[i]
for i, j in arr:
    print(cnt[j - 1] - cnt[i - 1])


Measured memory_bytes: 30660
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<double> p(N);
    rep(i, N) cin >> p[i];
    vector<double> e(N);
    rep(i, N) { e[i] = (p[i] * (p[i] + 1.0)) / (2.0 * p[i]); }
    vector<double> sum(N + 1);
    rep(i, N) { sum[i + 1] = sum[i] + e[i]; }
    double res = 0;
    rep(i, N - K + 1) { res = max(res, (sum[i + K] - sum[i])); }
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

Measured memory_bytes: 4992
n = int(input())
w = list(map(int,input().split()))

mindiff = 0
for s in range(n):
    di = abs(sum(w[0:s+1]) - sum(w[s+1:n]))
    if s == 1:
        mindiff = di
    else:
        if di < mindiff:
            mindiff = di

print(mindiff)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MOD 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define P pair<ll, ll>
#define VII vector<P>
#define P_B push_back

int n, k;
ll v[3000];
ll DP[3000][3000];

ll backtrack(int beg, int end) {

	if(beg > end) return 0;	
	if(DP[beg][end] != -1) return DP[beg][end];
	
	return DP[beg][end] =  max(v[beg] - backtrack(beg+1, end), v[end] - backtrack(beg, end-1));
}

int main() {
	
	// ll T; cin>>T; while(T--) 
	{
		
		int n;
		cin>>n;
		memset(DP, -1, sizeof(DP));
		for (int i = 0; i < n; i++) cin>>v[i];
		cout<<backtrack(0, n-1);

	}	
	return 0;
}

Measured memory_bytes: 74104
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	string s;
	cin >> s;
	int i;
	for(i = 0; i <= 4; i++){
		cout << s[i];
	}
	cout << " ";
	for(i = 6; i <= 12; i++){
		cout << s[i];
	}
	cout << " ";
	for(i = 14; i <= 18; i++){
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <chrono>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define fin cin
#define fout cout
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
#define all(x) x.begin(), x.end()
#define left vadia
#define lb lower_bound
#define right puta
using namespace std;
using namespace __gnu_pbds;
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
typedef pair<ll, ll> pii;
typedef vector<vector<char>> mat;
typedef pair<int, string> pis;
const ll mod = 1e9+7;
const int MAXN = 2e5+5;
const int MAXV = 1e6+5;
typedef vector<int> vi;
typedef pair<int, pair<int, int>> piii;

int32_t main() {
	int x;
	cin >> x;
	cout << !x << endl;	
}

Measured memory_bytes: 3620
N,M = list(map(int, input().split()))

consumed = {}
for i in range(M):
    s,c = list(map(int, input().split()))

    if s > N:
        print(-1)
        exit()
    if s == 1 and c == 0 and N != 1:
        print(-1)
        exit()

    if s in consumed:
        if consumed[s] != c:
            print(-1)
            exit()

    consumed[s] = c

ans = [str(consumed.get(i,0)) for i in range(1,N+1)]
if ans[0] == '0':
    if len(ans) > 1:
        ans[0] = '1'

print(int(''.join(ans)))


Measured memory_bytes: 3064
XN = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
tmp=100
tmp_i=0
for i in range(102):
  if not i in p:
    if abs(XN[0]-i)<tmp:
      tmp=abs(XN[0]-i)
      tmp_i=i
print(tmp_i)

"""
10 5
4 7 10 6 5
"""

Measured memory_bytes: 9192
// AOJ 0599
#include<cstdio>
#include<algorithm>
#include<functional>
#include<vector>
#define rep(i,a) for(int i=0;i<(a);++i)

const int MAX_M = 10000, MAX_N = 500, INF = 1<<29;

int M, N;
int P[MAX_M];
int C[MAX_N], E[MAX_N];
int dp[MAX_N+1][MAX_M+1];

int main()
{
	scanf( "%d%d", &M, &N );
	rep( i, M )
		scanf( "%d", P+i );
	rep( i, N )
		scanf( "%d%d", C+i, E+i );

	std::sort( P, P+M, std::greater<int>() );

	rep( i, N+1 ) rep( j, M+1 )
		dp[i][j] = INF;
	dp[0][0] = 0;
	rep( i, N ) rep( j, M+1 )
	{
		dp[i+1][j] = std::min( dp[i+1][j], dp[i][j] );

		dp[i+1][std::min(M,j+C[i])] = std::min( dp[i+1][std::min(M,j+C[i])], dp[i][j]+E[i] ); 
	}

	int ans = 0, sum = 0;
	rep( j, M+1 )
	{
		ans = std::max( ans, sum-dp[N][j] );

		if( j < M )
			sum += P[j];
	}

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

	return 0;
}

Measured memory_bytes: 20652
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextInt
    val s = sc.next
    sc.close()

    3200 <= a match {
      case true => println(s)
      case _    => println("red")
    }
  }
}

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

int main(){
  int n,i,s=0,t=0;
  cin >> n;
  vector<int> w(n);
  for(i=0;i<n;i++){
    cin >> w.at(i);
    s += w.at(i);
  }
  int md=s,d;
  for(i=0;i<n-1;i++){
    s -= w.at(i);
    t += w.at(i);
    if(s>t){
      d=s-t;
    }else{
      d=t-s;
    }
    md=min(md,d);
  }
  
  cout << md << endl;
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1e9)

int n,m,ans,a[100],b[100];
bool g[100][100]={},connect=true,visit[100]={};

void DFS(int v){
  visit[v] = 1;
  for(int v2=0; v2<n; v2++){
    if(!visit[v2] && g[v][v2]==1){//v2が未訪問かつvとv2が連結しているなら
      DFS(v2);
    }
  }
}

int main(){
  cin >> n >> m;
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]][b[i]]=1;
    g[b[i]][a[i]]=1;
  }
  
  rep(i,m){
    rep(j,100){
      visit[j] = 0;
    }
    g[a[i]][b[i]] = g[b[i]][a[i]]=0;
    DFS(0);
    rep(k,n){
      if(visit[k]==false){//未訪問の頂点があったら非連結
        connect=false;
      }
    }
    if(!connect){//非連結だったら答え++
      ans++;
    }
    //リセット
    g[a[i]][b[i]] = g[b[i]][a[i]] = 1;
    connect = 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>
using namespace std;
int main() {
    string text;
    cin>>text;
    unordered_set<char> us;
    for(int i=0; i<text.size(); i++){
        us.insert(text[i]);
    }
    cout << ((us.size()==2) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3628
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3 
    ^lb   ^ub */
#include <bits/stdc++.h>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define assign_if_greater(V, T) V=max(V,T)
using namespace std;
typedef long long ll;
typedef long double ld;
int N;
int A,B,C;
int l[10];
int main() {
  cout << fixed << setprecision(15);
  cin >> N;
  cin >> A >> B >>C;
  REP(i,N)
    cin >> l[i];
  int ans=1000*1000;
  int t[]={A,B,C};
  REP(i,1<<(2*N)) {
    vector<int> vs[4];
    REP(j,N) {
      int k=(i>>(j*2)) & 3;
      vs[k].pb(l[j]);
    }
    if (vs[0].size()>0 && vs[1].size()>0 && vs[2].size()>0) {
      int cost=0;
      REP(j,3)
        cost += (vs[j].size()-1)*10;
      REP(j,3)
        cost += abs(accumulate(ALL(vs[j]),0)-t[j]);
      ans=min(ans,cost);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }








vector<vector<int> > v(100005);
map<pii, int> mp;
void dfs(int bef, int now) {
    
    int c = 1;
    for (int nxt : v[now]) {
        if (nxt == bef) continue;
        
        if (c != mp[pii(min(bef, now), max(bef, now))]) {
            mp[pii(min(nxt, now), max(nxt, now))] = c;
            ++c;
        } else {
            ++c;
            mp[pii(min(nxt, now), max(nxt, now))] = c;
            ++c;
        }
        dfs(now, nxt);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<pii> ans;
    
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        
        v[a].eb(b);
        v[b].eb(a);
        ans.eb(pii(min(a, b), max(a, b)));
    }
    
    dfs(-1, 0);
    int ma = 0;
    rep(i, n - 1) chmax(ma, mp[ans[i]]);
    cout << ma << endl;
    rep(i, n - 1) {
        cout << mp[ans[i]] << endl;
    }
    
}


Measured memory_bytes: 15868
n, y = gets.split.map(&:to_i)

a = b = c = -1

valid = false
([2_000, y / 10_000].min).downto(0) do |i|
  break if valid

  ((y - 10_000 * i) / 5_000).downto(0) do |j|
    rest = y - 10_000 * i - 5_000 * j

    k = rest / 1_000
    valid = k && (i + j + k == n)

    if valid
      a, b, c = [i, j, k]
      break
    end
  end
end

puts [a, b, c].join(" ")


Measured memory_bytes: 1788
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int a = getInt();
  const int b = getInt();
  if(b % a == 0) printf("%d\n", a + b);
  else printf("%d\n", b - a);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
#define int long long
#define mid (l+r)/2
int n,m,cnt,t,top,ru[N],chu[N],a[N],b[N],dis[N],head[N];
int tree[N<<7],L[N<<7],R[N<<7],sum[N<<7],gs[N<<7],f[N][20];
struct node{
	int too,next,col,zh;
}edge[N*2];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
void add(int a,int b,int c,int d)
{
	edge[++top].too=b;edge[top].col=c;edge[top].zh=d;
	edge[top].next=head[a];head[a]=top;
}
bool pd(int x,int y)
{
	if(ru[x]<=ru[y]&&chu[x]>=chu[y])return true;
	return false;
}
int LCA(int x,int y)
{
	if(pd(x,y))return x;
	if(pd(y,x))return y;
	int k=x;
	for(int i=17;i>=0;i--)
		if((f[k][i]>0)&&(!pd(f[k][i],y)))k=f[k][i];
	return f[k][0];
}
int update(int pre,int l,int r,int x,int val)
{
    int rt=++cnt;
    L[rt]=L[pre];R[rt]=R[pre];sum[rt]=sum[pre];gs[rt]=gs[pre];
    if(l==r)
	{
		gs[rt]=gs[pre]+1;sum[rt]=sum[pre]+val;
		return rt;
	}
    if(x<=mid)L[rt]=update(L[pre],l,mid,x,val);
    else R[rt]=update(R[pre],mid+1,r,x,val);
    return rt;
}
int query1(int x,int y,int xx,int yy,int l,int r,int col)
{
	if(l==r)
	{
//		cout<<sum[x]+sum[y]-sum[xx]-sum[yy]<<endl;
		return sum[x]+sum[y]-sum[xx]-sum[yy];
	}
	if(col<=mid)return query1(L[x],L[y],L[xx],L[yy],l,mid,col);
	else return query1(R[x],R[y],R[xx],R[yy],mid+1,r,col);
}
int query2(int x,int y,int xx,int yy,int l,int r,int col)
{
	if(l==r)
	{
//		cout<<gs[x]+gs[y]-gs[xx]-gs[yy]<<endl;
		return gs[x]+gs[y]-gs[xx]-gs[yy];
	}
	if(col<=mid)return query2(L[x],L[y],L[xx],L[yy],l,mid,col);
	else return query2(R[x],R[y],R[xx],R[yy],mid+1,r,col);
}
void dfs(int u,int fa,int dep,int col,int zh)
{
	dis[u]=dep;
	tree[u]=update(tree[fa],1,100001,col,zh);
	ru[u]=++t;f[u][0]=fa;
	for(int i=head[u];i;i=edge[i].next)
	{
		int v=edge[i].too;
		if(v==fa)continue;
		dfs(v,u,dep+edge[i].zh,edge[i].col,edge[i].zh);
	}
	chu[u]=++t;
}
signed main()
{
	n=read();m=read();	
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read(),z=read(),zz=read();
		add(x,y,z,zz);
		add(y,x,z,zz);
	}
	dfs(1,0,0,100001,0);
	for(int i=1;i<=17;i++)
        for(int j=1;j<=n;j++)
            f[j][i]=f[f[j][i-1]][i-1];
	while(m--)
	{
		int col=read(),k=read(),x=read(),y=read();
		if(x==y){puts("0");continue;}
//		if(ru[x]>ru[y])swap(x,y);
		int lca=LCA(x,y);
		int ans=dis[x]+dis[y]-2*dis[lca];
		int xu=query1(tree[x],tree[y],tree[lca],tree[lca],1,100001,col);
		ans=ans-xu;
		int gs=query2(tree[x],tree[y],tree[lca],tree[lca],1,100001,col);
		ans=ans+gs*k;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 104704
#include<stdio.h>

int main(void) {
	int N, X[100];
	int i = 0;
	int P = 0;
	int sum = 0;
	int min = 0;

	scanf("%d", &N);

	while (i < N) {
		scanf("%d", &X[i]);
		sum = sum + X[i];
		i++;
	}

	 P = (double)sum / N + 0.5;

	 i = 0;
	 while (i < N) {
		 min = min + (X[i] - P) * (X[i] - P);
		 i++;
	 }

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

	return 0;

}

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

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

    vector<int> num(26, 0);
    for (char c : s) {
        num[c - 'a']++;
    }

    set<string> st;
    for (int i = 0; i < 26; i++) {
        for (int j = s.size() - 1; j >= 0; j--) {
            if (s[j] == i + 'a') {
                for (int k = 1; k <= K; k++) {
                    st.insert(s.substr(j, k));
                }
            }
        }

        if (st.size() >= K) {
            int counter = 0;
            for (auto itr = st.begin(); itr != st.end(); itr++) {
                if (++counter == K) {
                    cout << *itr << endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// 2???????????????????????????????±???????
double dot(P a, P b) {
    return (a.X * b.X + a.Y * b.Y);
}

// 2???????????????????????????????±???????
double cross(P a, P b) {
    return (a.X * b.Y - a.Y * b.X);
}

P projection(P a1, P a2, P p) {
    return a1 + dot(a2-a1, p-a1) / norm(a2-a1) * (a2-a1);
}

P reflection(P a1, P a2, P p) {
    return 2.0 * projection(a1, a2, p) - p;
}

int main() {
    P p1, p2; cin >> p1.X >> p1.Y >> p2.X >> p2.Y;
    int q; cin >> q;
    rep(i,0,q) {
        P b; cin >> b.X >> b.Y;
        P ans = reflection(p1, p2, b);
        printf("%.10f %.10f\n", ans.X, ans.Y);
    }
    return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> x >> t >> y;

	if(y*t>=x)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 3648