akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
 
//****************************************************                
#define f(var,start,end) for(ll var = start; var <end ; ++var)
#define rf(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define vvll vector<vector<ll>>
#define mtp make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define nl cout<<"\n"
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions
void solve();

int binary(int a[],int l,int r,int find)
{
    if(l>r)
    {
        return -1; 
    }else
    {
        int mid=(l+r)/2;
        if(a[mid]==find)
        {
            return mid+1;
        }else if(a[mid]>find)
        {
            binary(a,l,mid-1,find);
        }else
        {
            binary(a,mid+1,r,find);
        }   
    }   
}

int main()
{
    FAST_IO;
    ll testcases = 1;
    // cin >> testcases; //comment for 1 test case
    while(testcases--)
    {
        solve();
    }
}

void solve()
{
	vll a(5);
	ll ans;
	f(x,0,5)
	{
		cin>>a[x];
		if(a[x]==0)
		{
			ans=x+1;
		}
	}
	cout<<ans;
	nl;
}

Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

long long gcd(long long a, long long b){
    while(b != 0){
        long long tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

long long lcm(long long a, long long b){
    return a / gcd(a, b) * b;
}

long long solve(long long n, long long c, long long d)
{
    long long ans = n;
    ans -= n / c + n / d;
    ans += n / lcm(c, d);
    return ans;
}

int main()
{
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long ans = solve(b, c, d) - solve(a-1, c, d);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
import sys

input = sys.stdin.readline


def main():
    x = int(input())

    q, r, = divmod(x, 11)
    if r == 0:
        ans = 2 * q
    elif r <= 6:
        ans = 2 * q + 1
    else:
        ans = 2 * q + 2

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    // we choose k cards.
    // find the maximum sum.
    if(a >= k){
        cout << k << endl;
    }
    else if(a + b >= k){
        cout << a << endl;
    }
    else  { // 2 2 4 , k = 5.
        cout << a*1 + (k-(a+b))*-1;
    }
}





Measured memory_bytes: 3592
#include <stdio.h>
#include <string.h>

void reverse(char str[]);

int main(void) {
  
  char str[30];
  int i;

  fgets(str,sizeof(str),stdin);

  str[strlen(str)-1]='\0';

  for(i=0;i<strlen(str);i++) {
    printf("%c",str[strlen(str)-i-1]);
  }

  printf("\n");

  return 0;

}

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

int main() {
  long long N, s{}, ans{1000};
  cin >> N;
  vector<int> A(N);
  for (auto &a: A) cin >> a;
  for (int i = 0; i!= N; ++i) {
    if (i != N - 1 && A[i] < A[i+1]) {
      s += ans / A[i];
      ans -= ans / A[i] * A[i];
    } else if (i == N - 1 || A[i] > A[i+1]) {
      ans += s * A[i];
      s = 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long n;

	std::cin >> n;

	std::map<long long, long long> m;

	for (long long i = 0; i < n; i++)
	{
		long long a;
		std::cin >> a;
		m[a]++;
	}

	for (auto a : m) {
		if (a.second > 1) {
			std::cout << "NO" << std::endl;
			return 0;
		}
	}

	std::cout << "YES" << std::endl;

	return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int X, Y, Z; 
  cin >> X >> Y >> Z;
  swap(X, Y);
  swap(X, Z);
  cout << X << " " << Y << " " << Z << endl;
}


Measured memory_bytes: 256
n,x = map(int,input().split())
A = [0]+list(map(int,input().split()))
count = 0
for i in range(n):
    if A[i]+A[i+1] > x:
        count += A[i+1]+A[i]-x
        A[i+1] = x-A[i]
print(count)

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

ans=0
for i in range(1,n+1):
  if i>=k:
    ans+=1/n
    continue
  else:
    j=1
    while True:
      if 2**j>=(k/i):
        ans+=(1/n)*0.5**j
        break
      else:
        j+=1
print(ans)

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main()
{
    long A,B,C,A1,B1,C1,count=0;
    cin>>A>>B>>C;
    if(A%2!=0||B%2!=0||C%2!=0){
        cout<<count<<endl;
        exit(0);
    }
    if(A==B&&B==C){
        cout<<-1<<endl;
        exit(0);
    }
    while(1){
        A/=2;
        B/=2;
        C/=2;
        count++;
        if(A%2!=0&&B%2!=0&&C%2!=0){
            count+=1;
            break;
        } 
        if(A%2!=0||B%2!=0||C%2!=0) break;
    }
    cout<<count<<endl;

}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::vector<long long> A){
    vector<vector<ll>> dp(2001, vector<ll>(2001, 0));
    vector<pair<ll, int>> a(N);
    rep(i,0,N) a[i] = {A[i], i};
    sort(all(a), greater<>());
    ll answer = 0;
    rep(i,0,N+1) rep(j,0,N-i+1) {
        ll lValue = 0, rValue = 0;
        if (i>0) lValue = dp[i-1][j] + a[i+j-1].first * abs((i-1)-a[i+j-1].second);
        if (j>0) rValue = dp[i][j-1] + a[i+j-1].first * abs((N-j)-a[i+j-1].second);
        dp[i][j] = max(lValue, rValue);
        answer = max(dp[i][j], answer);
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 34996
inputs = input().split(' ')
n = int(inputs[0])
a = int(inputs[1])
b = int(inputs[2])
sum = a + b

if n <= a:
    print(n)
elif n <= sum:
    print(a)
else:
    loop = n // sum
    num = n - loop * sum
    if num <= a:
        print(loop * a + num)
    else:
        print(loop * a + a)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

  //vi to[200005];

  int N, Q; cin >> N >> Q;
  vvi to(N,vi());
  REP(i,N-1) {
    int a, b; cin >> a >> b;
    --a; --b;
    to[a].PB(b);
    to[b].PB(a);
  }

  vi ans(N);
  //ans.resize(N);
  REP(i,Q) {
    int p, x; cin >> p >> x;
    --p;
    ans[p] += x;
  }

  vector<bool> checked(N,false);
  queue<int> que;
  que.push(0);
  checked[0] = true;

  while (!que.empty()) {
    int node = que.front();
    que.pop();
    int point = ans[node];
    for (auto &next : to[node]) {
      if (!checked[next]) {
        ans[next] += point;
        que.push(next);
        checked[next] = true;
      }
    }
  }

  REP(i,N) {
    //cout << ans[i] << endl;
    //cout << ans[i] << "\n";
    printf("%d\n",ans[i]);
  }

  /*for (auto &a : ans) {
    cout << a << endl;
  }*/
  
  return 0;
}

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

int main(void){

  float a, b, c;
  int C;
  double S, L, h;
  double rad;
  scanf("%f %f %d", &a, &b, &C);
  rad =  C * M_PI_2 / 90;
  h = b * sin (rad);
  S = (a * h) / 2;
  c = sqrt (h * h + (a - (b * cos (rad))) *  (a - (b * cos (rad))));
  L = a + b + c;

  printf ("%f\n", S);
  printf ("%f\n", L);
  printf ("%f\n", h);

  return 0;

}

Measured memory_bytes: 648
using System;
using System.Collections.Generic;
using System.Linq;

public static class Program
{
    public static void Main(string[] args)
    {
        var abk = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var cnt = 0;
        for (int i = Math.Min(abk[0], abk[1]); i > 0; i--)
        {
            if (abk[0] % i == 0 && abk[1] % i == 0)
                cnt++;
            if (cnt == abk[2])
            {
                Console.WriteLine(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 13268
check = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
    b,f,r,v = map(int,input().split())
    check[b-1][f-1][r-1] += v
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(f" {check[i][j][k]}", end="")
        print()
    if i<3:
        print("####################")


Measured memory_bytes: 5640
from itertools import permutations, combinations,combinations_with_replacement,product

X =int(input())

s =str(X/100)

s_list =s.split('.')

A =[0,1,2,3,4,5]

for h in range(1,int(s_list[0])+1):
    for i in combinations_with_replacement(A,h):
        if sum(i) == int(s_list[1]):
            #print(i)
            print("1")
            exit()

print("0")


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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, int> pi;

#define N 55

int dp[N][N][101], a[N], inf = 1e9;

int call(int l, int r, int k)
{
    if(l>r || k<=0) return 0;
    if(dp[l][r][k] != inf){
        return dp[l][r][k];
    }
    //cout << l << " " << r << " " << k << endl;

    int c1 = a[l]+call(l+1, r, k-1);
    int c2 = a[r]+call(l, r-1, k-1);
    int c3 = call(l+1, r, k-2);
    int c4 = call(l, r-1, k-2);
    //cout << c1 << " "<< c2 << " "<< c3 << " "<< c4 << "\n";
    return dp[l][r][k] = max({c1, c2, c3, c4});
}

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

    for(int i=0; i<55; i++){
        for(int j=0; j<55; j++){
            for(int ii=0; ii<101; ii++){
                dp[i][j][ii] = inf;
            }
        }
    }

    cout << call(0, n-1, k) << "\n";

    return 0;
}


Measured memory_bytes: 1408
n,a,b=map(int,input().split())
mod=10**9+7

if n==2:
    print(0)
    exit()

f=(pow(2,n,mod)-1)

x=1
y=1
for i in range(a):
    x=x*(n-i)%mod
    y=y*(a-i)%mod
nca=(x*pow(y,mod-2,mod)%mod)

x=1
y=1
for i in range(b):
    x=x*(n-i)%mod
    y=y*(b-i)%mod
ncb=(x*pow(y,mod-2,mod)%mod)

print((f-nca-ncb+mod)%mod)

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    bool flag3 = true;
    rep(i, N) {
        char co;
        cin >> co;
        if (co == 'Y') flag3 = false;
    }

    if (flag3) cout << "Three" << endl;
    else cout << "Four" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{int N,M,ans,ans1;
cin>>N>>M;
int b=N-M;
ans1 =1;
for(int i=0;i<M;i++)
{
ans1=ans1*2;
}
ans=(b*100)*ans1;
ans=ans+ans1*(1900*M);
cout<<ans;
return 0;
}

Measured memory_bytes: 256
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

int main()
{
    int n;
    scanf("%d",&n);
    int x=n,s=0;
    if (n<=1000)
    {
        printf("%d",1000-n);
    }
    else
    {
        if(n%1000==0)
        {
            printf("%d",n-n);
        }else
        {
            while(n>=10)
            {
                int r=n%10;
                n=n/10;
                s++;
            }
            n++;
            n=n*pow(10,s);
            printf("%d",n-x);
        }
    }

    return 0;
}

Measured memory_bytes: 2476
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var buffer = Console.ReadLine().Split();
            var N = int.Parse(buffer[0]);
            var X = int.Parse(buffer[1]);

            var val = 0;
            int ans = 1;
            foreach (var v in Console.ReadLine().Split())
            {
                val = val + int.Parse(v);

                if (val > X)
                    break;
                ans++;
            }

            Console.WriteLine(ans);
        }
    }
}


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

def enough(n):
    used = 0
    for h in src:
        if h <= B*n: continue
        h -= B*n
        used += (h-1)//(A-B) + 1
        if used > n: return False
    return True

ng = 0
ok = 10**9
while ok - ng > 1:
    m = (ok+ng) // 2
    if enough(m):
        ok = m
    else:
        ng = m
print(ok)


Measured memory_bytes: 7072
n = int(input())
t, a = map(int, input().split())
heights = [int(x) for x in input().split()]

result = -1
min_value = 10 ** 9
for i, h in enumerate(heights):
  temp = abs(a - (t - h * 0.006))
  if temp < min_value:
    result = i + 1
    min_value = temp
    
print(result) 

Measured memory_bytes: 9256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    string s;
    cin>>n>>s>>k;
    char x=s[k-1];
    rep(i,n){
      if(s[i]!=x){
        s[i]='*';
      }
      cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d,r1,r2;
cin>>a>>b>>c>>d;r1=a*b;r2=c*d;
if(r1>r2)
cout<<r1;
else if(r2>r1)
cout<<r2;
else 
cout<<r1;
return 0;
}

Measured memory_bytes: 256
/*
 * 2437.cc: DNA
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const int MAX_M = 50;

typedef long long ll;

const ll MOD = 1000000007;

/* typedef */

typedef map<string,int> msi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

int na, nt, ng, nc;
msi ntmap;
vs elms[MAX_M];
vpii eps[MAX_M];
int lens[MAX_M];
ll dp[MAX_N * 4 + 1][MAX_N + 1][MAX_N + 1][MAX_N + 1];

/* subroutines */

void parse(int k) {
  if (lens[k]) return;

  int len = 0;
  vs &ek = elms[k];
  vpii &epk = eps[k];
  
  for (int i = 0; i < ek.size(); i++) {
    if (ek[i][0] == '[') {
      int bits = 0;
      for (int j = 0; j < ek[i].size() - 1; j++)
	switch (ek[i][j]) {
	case 'A': bits |= 1; break;
	case 'T': bits |= 2; break;
	case 'G': bits |= 4; break;
	case 'C': bits |= 8; break;
	}
      epk.push_back(pii(1, bits));
      len++;
      //cout << ek[i]; printf(" = %x\n", bits);
    }
    else {
      int id = ntmap[ek[i]];
      epk.push_back(pii(0, id));

      parse(id);
      len += lens[id];
    }
  }

  lens[k] = len;
}

void rec(int len, int k) {
  vpii &epk = eps[k];

  for (vpii::iterator vit = epk.begin(); vit != epk.end(); vit++) {
    if (vit->first == 0) {
      int &id = vit->second;
      rec(len, id);
      len += lens[id];
    }
    else {
      int &bits = vit->second;

      for (int ia = 0; ia <= na; ia++)
	for (int it = 0; it <= nt; it++)
	  for (int ig = 0; ig <= ng; ig++) {
	    ll &dp0 = dp[len][ia][it][ig];
	    if (dp0 > 0) {
	      if (ia < na && (bits & 1))
		dp[len + 1][ia + 1][it][ig] =
		  (dp[len + 1][ia + 1][it][ig] + dp0) % MOD;
	      if (it < nt && (bits & 2))
		dp[len + 1][ia][it + 1][ig] =
		  (dp[len + 1][ia][it + 1][ig] + dp0) % MOD;
	      if (ig < ng && (bits & 4))
		dp[len + 1][ia][it][ig + 1] =
		  (dp[len + 1][ia][it][ig + 1] + dp0) % MOD;
	      if (bits & 8)
		dp[len + 1][ia][it][ig] =
		  (dp[len + 1][ia][it][ig] + dp0) % MOD;
	    }
	  }

      len++;
    }
  }
}

/* main */

int main() {
  cin >> na >> nt >> ng >> nc;

  int m;
  cin >> m;

  for (int i = 0; i < m; i++) {
    string ntv, line;
    cin >> ntv;
    getline(cin, line);

    ntv.erase(ntv.size() - 1);
    ntmap[ntv] = i;

    int pos = 0;
    while (pos < line.size()) {
      while (pos < line.size() && line[pos] == ' ') pos++;
      string e;
      while (pos < line.size() && line[pos] != ' ') e += line[pos++];
      elms[i].push_back(e);
    }
    //printf("%lu\n", elms[i].size());
  }

  parse(0);
  int n = lens[0];
  //printf("n=%d\n", lens[0]);

  if (n != na + nt + ng + nc) {
    puts("0");
    return 0;
  }

  dp[0][0][0][0] = 1;
  rec(0, 0);

  printf("%lld\n", dp[n][na][nt][ng]);

  return 0;
}

Measured memory_bytes: 201976
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var NAB = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = NAB[0];
            var A = NAB[1];
            var B = NAB[2];

            var output = Math.Min(N * A, B);
            Console.WriteLine(output);
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


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

using namespace std;

#define ll long long

ll l[100050] = {};
ll r[100050] = {};

int main() {
	ll n, m;
	ll ans = 0;
	ll Lmax = 0;
	ll Rmin = 100005;
	cin >> n >> m;

	for (ll i = 0; i < m; i++) {
		cin >> l[i] >> r[i];
	}

	for (ll i = 0; i < m; i++) {
		if (l[i] > Lmax) {
			Lmax = l[i];
		}

		if (r[i] < Rmin) {
			Rmin = r[i];
		}
	}

	if (Lmax <= Rmin) {
		ans = Rmin - Lmax + 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int n, m;
string s;
vector<int> vec;


int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	if (e - a > f) {
		cout << ":(";
	}
	else {
		cout << "Yay!";
	}

}

Measured memory_bytes: 256
s = list(input())
set_s = set(list(s[:]))
n = len(s)

ans = float("inf")
if len(set_s) == 1:
    print(0)
    exit()
for target in set_s:
    l = s[:]
    for i in range(n):
        for j in range(n-1-i):
            if l[j] == target or l[j+1] == target:
                l[j] = target
        l = l[:-1]
        if len(set(list(l))) == 1:
            break
    ans = min(ans, i+1)
print(ans)

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

int dp[101][10101];

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

    for (int i = 0; i < n; i++) {
        int v, w;
        cin >> v >> w;
        for (int j = 0; j < 10101; j++) {
            if (j - w >= 0) {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    int ans = 0;
    for (int j = 0; j <= W; j++) {
        ans = max(ans, dp[n][j]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 7056
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long int
using namespace std;

typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef pair<int, PII> PIP;
typedef vector<PIP> VPP;

int n, m, x;
int h[100001];
VP node[100001];

priority_queue<PIP, VPP, greater<PIP> > reew;
bool visited[100001];

int dijk()
{
  reew.push(MP(0, MP(1, x)));

  while(!reew.empty()){
    PIP now = reew.top();
    reew.pop();

    if(!visited[now.S.F]){
      visited[now.S.F] = true;

      if(now.S.F == n){
        return now.F + h[n] - now.S.S;
      }

      for(int i = 0; i < node[now.S.F].size(); i++){
	PIP now2 = now;
	if(now2.S.S < node[now2.S.F][i].F){
	  now2.F += node[now2.S.F][i].F - now2.S.S;
	  now2.S.S = node[now2.S.F][i].F;
	}
	if(now2.S.S <= h[now2.S.F]){
	  if(now2.S.S - node[now2.S.F][i].F > h[node[now2.S.F][i].S]){
	    reew.push(MP(now2.F + now2.S.S - h[node[now2.S.F][i].S], MP(node[now2.S.F][i].S, h[node[now2.S.F][i].S])));
	  }
	  else{
	    reew.push(MP(now2.F + node[now2.S.F][i].F, MP(node[now2.S.F][i].S, now2.S.S - node[now2.S.F][i].F)));
	  }
	}
      }
    }
  }

  return -1;
}

signed main()
{
  scanf("%lld%lld%lld", &n, &m, &x);
  for(int i = 1; i <= n; i++){
    scanf("%lld", &h[i]);
  }
  for(int i = 0; i < m; i++){
    int a, b, t;
    scanf("%lld%lld%lld", &a, &b, &t);
    node[a].PB(MP(t, b));
    node[b].PB(MP(t, a));
  }

  printf("%lld\n", dijk());

  return 0;
}

Measured memory_bytes: 33796
# C - Many Requirements

n, m, q = map(int, input().split())
lst = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    lst.append((a, b, c, d))  # 得点を先頭に

def allseq(n, m):
    if n == 0:
        yield []
    else:
        for rest in allseq(n - 1, m):
            for i in range(rest[-1] if len(rest) > 0 else 1, m+1):
                yield rest + [i]

x = 0
for seq in allseq(n, m):
    s = 0
    for a, b, c, d in lst:
        if seq[b-1] - seq[a-1] == c:
            s += d
    x = max(x, s)

print(x)


Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for(int i = (s); i < (int)(n); i++)

int main(){
    int k; cin >> k;
    string s; cin >> s;
    
    if(s.size() <= k) cout << s << endl;
    else{
        rep(i, k) cout << s.at(i);
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){
    ll N;
    cin >> N;
    string s;
    cin >> s;
    s += "#####";
    ll ans = 0;
    rep(i, s.size()){
        if(s[i] == '#')break;
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
ls = [tuple(map(int,input().split())) for _ in range(M)]
ls.sort(key=lambda x:x[1],reverse=True)
ls.sort(key=lambda x:x[0],reverse=True)
r = N
cnt = 0
for i in range(M):
    a,b = ls[i]
    if b <= r:
        cnt += 1
        r = a
print(cnt)

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a);i>(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1000000000;
const LL MOD = 1000000007;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  int N;
  cin >> N;
  double S=0;
  
  REP(i,N) {
    int A;
    cin >> A;
    S += 1/(double)A;
  }
  cout << fixed << setprecision(7) << 1/S << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define ALL(C) (C).begin(),(C).end()
#define INPUT(P) std::cin>>(P)
#define INPUT2(P1,P2) std::cin>>(P1)>>(P2)
#define INPUT3(P1,P2,P3) std::cin>>(P1)>>(P2)>>(P3)
#define INPUTS(I,N,V) REP(I,N) std::cin>>V[I]
#define OUTPUT(P) std::cout<<P<<std::endl
#define OUTPUT2(P1,P2) std::cout<<P1<<" "<<P2<<std::endl
#define OUTPUT3(P1,P2,P3) std::cout<<P1<<" "<<P2<<" "<<P3<<std::endl
#define OUTPUTS(I,N,V) REP(I,N) std::cout<<V[i]<<std::endl
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
int i,j,k;
int N;
string S;
int cumsum_west[300000];
int cumsum_east[300000];
int east_sum;
int west_sum;
int answer=INT_MAX;
inline void solve(){
  INPUT2(N,S);
  REP(i,N){
    if(S[i]=='E')east_sum++;
    if(S[N-i-1]=='W')west_sum++;
    cumsum_east[i]=east_sum;
    cumsum_west[N-i-1]=west_sum;
  }
  REP(i,N){
    answer=min(answer,cumsum_west[0]-cumsum_west[i]+cumsum_east[N-1]-cumsum_east[i]);
  }
  OUTPUT(answer);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

using namespace std;

int main(){
  double n;
  cin >> n;
  vector<pair<double,string>> x(n);
  double sum=0;
  for(int i=0;i<n;i++){
    cin >> x[i].first >> x[i].second;
    if(x[i].second=="JPY"){
      sum += x[i].first;
    }
    else{
      sum+= x[i].first*380000.0;
    }
  }
  cout << setprecision(30);
  cout << sum << endl;
}

Measured memory_bytes: 256
N = gets.to_i
info = readlines

num = 1
arr = []
ans = []
sum = 0

N.times do
    arr.push(num)
    num += 1
end

paterns = arr.permutation(N).to_a
paterns.each do |patern|
    index = 0
    (N-1).times do
        x = info[patern[index]-1].split(" ")[0].to_i - info[patern[index+1]-1].split(" ")[0].to_i
        y = info[patern[index]-1].split(" ")[1].to_i - info[patern[index+1]-1].split(" ")[1].to_i
        sum += Math.sqrt(x*x + y*y)
        index += 1
    end
end

puts sum/paterns.count  



Measured memory_bytes: 8700
#include <cstdio>
#include <algorithm>

int main()
{
  int n, k;
  scanf("%d%d", &n, &k);
  int ans = 0;
  for (int i = 0; i < n; ++i)
  {
    int d;
    scanf("%d", &d);
    ans += std::min(d, k - d) * 2;
  }
  printf("%d\n", ans);
  return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<pair<string, ll>> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    string X;
    cin >> X;
    ll ans = 0;
    bool ok = false;
    rep(i, N) {
        string s = items[i].first;
        ll t = items[i].second;
        if (ok) {
            ans += t;
        }
        if (s == X) {
            ok = true;
        }
    }
    cout << ans << '\n';

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef  vector<int> vi ;
typedef  vector<string> vs ;
typedef  vector<long long> vl ;
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) FOR(i,0,n)
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a<c && b>c)
    cout<<"Yes"<<endl;
  else if(a>c && b<c)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;  
}


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

int main()
{
	int N, max_pow = 1;
  	scanf("%d", &N);
  	for (int b = 2; b * b <= N; b++){
    	for (int p = 2; pow(b, p) <= N; p++){
        	if (max_pow < pow(b, p)){
            	max_pow = pow(b, p);
            }
        }
    }
  	printf("%d", max_pow);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SZ(v) (int((v).size()))
#define ALL(vec) (vec).begin(),(vec).end()
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
using namespace std;
 
using i64 = long long int;
template <typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template <typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
 
void err(__attribute__((unused)) istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl;
  err(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& os, const pair<T1, T2>& buf) {
  return os << "(" << buf.first << ": " << buf.second << ")";
}
template<typename T>
inline ostream &operator << (ostream & os,const vector<T>& v) {
  bool first = true;
  os << "[";
  for (const auto &e: v) {
    if(!first) os << ", ";
    os << e;
    first = false;
  }
  return os << "]";
}
template<typename T>
inline ostream &operator << (ostream & os, multiset<T>& v) {
  bool first = true;
  os << "{";
  for (auto ii = v.begin(); ii != v.end(); ++ii) {
    if(!first) os << ", ";
    os << *ii;
    first = false;
  }
  return os << "}";
}
template<typename T>
inline ostream &operator << (ostream & os,const unordered_set<T>& v) {
  bool first = true;
  os << "{";
  for (const auto &x : v) {
    if(!first) os << ", ";
    os << x;
    first = false;
  }
  return os << "}";
}
template<typename T1, typename T2>
inline ostream &operator << (ostream & os,const map<T1, T2>& v) {
  bool first = true;
  os << "{";
  for (const auto &e : v) {
    if(!first) os << ", ";
    os << e;
    first = false;
  }
  return os << "}";
}
template<typename T>
ostream &operator << (ostream & os,const vector<vector<T>>& v) {
  for (auto &u: v) os << '\n' << u;
  return os;
}
template<typename T>
void finish(T ans) {cout << ans << '\n'; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18;
#define PI 3.14159265358979323846
/***********************************************************************/
signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  i64 n, r, g, b;
  cin >> r >> g >> b >> n;
  i64 ans = 0;
  for (int i = 0; r * i <= n; ++i) {
    for (int j = 0; g * j + r * i <= n; ++j) {
      i64 rem = n - g * j - r * i;
      ans += rem % b == 0;
    }
  }
  cout << ans << '\n';
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
void solve(){
	int x,y;
	cin>>x>>y;
	for(int i=0;i<=100;i++){
		int a=x-i;     //Are no of turtles
		if(a>=0){
			if((i*2+a*4)==y){
				cout<<"Yes"<<endl;
				return ;
			}
		}
	}
			cout<<"No"<<endl;
			return;
}
int main(){
	solve();
}

Measured memory_bytes: 3680
def main():
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(n)]
    ans = n
    st = set(i for i in range(1, m+1))
    while len(st) > 1:
        dic = {v:0 for v in st}
        for i in range(n):
            for v in a[i]:
                if v in st:
                    dic[v] += 1
                    break
        tmp = max(dic.values())
        if ans > tmp:
            ans = tmp
        for key in dic.keys():
            if dic[key] == tmp:
                st.remove(key)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 74820
n = int(input())
s = input()
ans = 0
count = 0
for i in range(1,n):
  count = 0
  h = list(set(s[:i]))
  t = list(set(s[i:]))
  if len(h)>len(t):
    for j in range(len(h)):
      if h[j] in t:count+=1
  else:
    for j in range(len(t)):
      if t[j] in h:count+=1
  ans = max(ans,count)
print(ans)

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

long long GetDigit(ll num) {
	return floor(log10(num)+1);
}

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

	for(ll i=1; i<=floor(sqrt(N)); i++) {
		if(i==1) {
			minimum = GetDigit(N);
		}
		else {
			if(N%i == 0)
				minimum= min(minimum, max(GetDigit(i) , GetDigit(N/i)));
		}
	}
	cout << minimum << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  string s; cin >> s;
  int day = 0;
  if(s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR"){
    day = 1;
  }
  else if(s == "RRS" || s == "SRR"){
    day = 2;
  }
  else if(s == "RRR"){
    day = 3;
  }
  cout << day;
}

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

int main () {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if ((max(a-c, c-a) > d) && ((max(a-b, b-a) > d) || (max(c-b, b-c) > d))) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, m, a, b;
vector<vector<ll>> to(100005);
vector<ll> dist(100005),ans(100005);
queue<ll> q;
bool visited[100005] = {};

int main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> a >> b;
		a--;
		b--;
		to[a].pub(b);
		to[b].pub(a);
	}
	q.push(0);
	visited[0] = true;
	dist[0] = 0;
	while (q.size()) {
		ll cur = q.front();
		q.pop();
		rep(i, sz(to[cur])) {
			if (visited[to[cur][i]])continue;
			dist[to[cur][i]] = dist[cur] + 1;
			ans[to[cur][i]] = cur;
			visited[to[cur][i]] = true;
			q.push(to[cur][i]);
		}
	}
	cout << "Yes" << endl;
	rep(i, n - 1)cout << ans[i + 1] + 1 << endl;
	return 0;
}

Measured memory_bytes: 13892
// ABC067_A.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a * b < c * d) {
		cout << c * d << endl;
	}
	else if (a * b < c * d) {
		cout << a * b << endl;
	}
	else{
		cout << a * b << endl;
	}
	return 0;
}



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

struct UnionFind
{
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x)
  {
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y)
  {
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

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

  UnionFind uf(n);

  rep(i, m)
  {
    int a, b;
    cin >> a >> b;
    uf.unite(a - 1, b - 1);
  }

  int ans = 0;
  rep(i, n)
  {
    ans = max(ans, uf.size(i));
    // cout << "i: " << i << ", " << uf.size(i) << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4048
import java.io.*;
import java.util.*;

public class Main {
  private static long solve(int n, int[] as) {
    for (int i = 0; i < n; i++) {
      as[i] -= i + 1;
    }
    
    Arrays.sort(as);
    int b = as[n / 2];
    long answer = 0;
    for (int a : as) {
      answer += Math.abs(a - b);
    }
    return answer;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int[] as = reader.nextInt(n);
    out.println(solve(n, as));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


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

//ABC112D
int compare_int(const void *a, const void *b) { //sort
  return *(int*) a-*(int*) b;
}

int main(void) {
  int n, m, k=0, i, cou=0, tho=1000;
  int memo[tho];
  scanf(" %d %d", &n, &m);
  int sqm=sqrt(m);
  //printf("sqm=%d\n", sqm);

  for(i=0; i<tho; i++){
    memo[i]=1;
  }
  for(i=sqm; i>=1; i--){
    if(m%i==0) memo[k++ ]=i, memo[k++ ]=m/i;
  }
  qsort(memo, k, sizeof(int), compare_int); //sort

  for(i=0; i<k; i++){
    if(memo[i]>=n){
      printf("%d", m/memo[i]);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static class Team implements Comparable<Team>{
		int number;
		int time;

		Team (int number) {
			this.number = number;
			this.time = 0;
		}

		public int compareTo(Team o) {
			return this.time - o.time;
		}
	}

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		Team team[];

		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			team = new Team[n];
			for (int i = 0; i < n; i++) {
				int number = sc.nextInt();
				team[i] = new Team(number);
				for (int j = 0; j < 8; j++) {
					int k = sc.nextInt();
					if (j % 2 == 0) {
						team[i].time += k * 60;
					} else {
						team[i].time += k;
					}
				}
			}
			Arrays.sort(team);
			System.out.println(team[0].number);
			System.out.println(team[1].number);
			System.out.println(team[team.length - 2].number);
		}
	}
}

Measured memory_bytes: 13000
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<sstream>

using namespace std;
#define ll 		long long
#define int     long long
#define ld 		long double
#define vll 	vector<ll>
#define pll 	pair<ll,ll>
#define map1 	map<ll,ll>
#define pqb 	priority_queue<ll>
#define pqs 	priority_queue<ll, vll,greater<ll> >
#define push_back emplace_back
#define N 		100009
#define mod 	1e9+9
#define MAX 	1e9
#define test(tt123) ll Tt123,tt123; cin>>Tt123; for(tt123=1 ; t<=Tt123 ; t++)    
#define one(x)	__builtin_popcountll(x)
#define zero(x) __builtin_ctzll(x)
#define precision(x) cout<<fixed<<setprecision(x);
#define debug(x)   cout<<"HELLO "<<x<<endl
const double pi = 3.14159265358979323846;
//vector<pll> p;
void fast(){
	//p.push_back({1,0}); p.push_back({0,1}); p.push_back({-1,0});p.push_back({0,-1});
	//p.push_back({-1,-1}); p.push_back({-1,1}); p.push_back({1,-1});p.push_back({1,1});
	ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	//#endif
}

int32_t main(){
	fast();
	int n ;cin>>n;
	int a[n];
	for(int i=0 ;i<n;i++)cin>>a[i];
	
	int mx=a[0],ans=0;
	for(int i=1 ; i<n ;i++){
		if(a[i]<mx){
			ans += mx-a[i];
		}
		mx = max(mx,a[i]);
	}	  
	cout<<ans;
}


Measured memory_bytes: 5216