akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin>>n>>k;
    int mod = 1e9 + 7;
    vector<int> candies(n+1);
    for (int i = 1; i <= n; i++)
        cin>>candies[i];
    vector<vector<int> > ways(n+1, vector<int>(k+1));
    vector<int> sum(k+1);
    sum[0] = 1;
    for (int child = 0; child <= n; child++)
        ways[child][0] = 1;
    for (int candy = 1; candy <= k; candy++) {
        ways[0][candy] = 0;
        sum[candy] = 1;
    }
    for (int child = 1; child <= n; child++) {
        for (int candy = 1; candy <= k; candy++) {
            if (candies[child] < candy) {
                ways[child][candy] = (sum[candy] - sum[candy - candies[child] -1] + mod)%mod;
            }
            else {
                ways[child][candy] = sum[candy];
            }
        }
        for (int candy = 1; candy <= k; candy++) 
            sum[candy] = (sum[candy-1] + ways[child][candy])%mod;
    }
    cout<<ways[n][k]<<"\n";
    return 0;
}


Measured memory_bytes: 43184
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    X = in_nl()
    X = [(num, i) for i, num in enumerate(X)]

    ans = [0] * N
    X.sort()
    for i in range(N):
        _, j = X[i]
        if i < N // 2:
            ans[j] = X[N // 2][0]
        else:
            ans[j] = X[N // 2 - 1][0]

    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 54784
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,m;
  cin>>n>>m;
  vector<int> pe(n,0);
  for(int i=0;i<m;++i){
    int p;
    string s;
    cin>>p>>s;
    --p;
    if(pe[p]<=0){
      --pe[p];
      if(s=="AC")pe[p]*=-1;
    }
  }
  int r=0,pen=0;
  for(int i=0;i<n;++i){
    if(pe[i]>0){
      ++r;
      pen+=pe[i]-1;
    }
  }
  cout<<r<<" "<<pen;
}

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

enum { U, B, L, F, R, D };
struct Dice {               // . . U .
    int face[6];            // B L F R
    Dice() {                // . . D .
        face[F] = 1; face[R] = 2; face[U] = 3;
        face[B] = 6; face[L] = 5; face[D] = 4;
    }
    int find_face(int f) {
        for (int i = 0; i < 6; i++) if (face[i] == f) return i;
        return -1;
    }
    void turn(int dir) {
        switch (dir) {
            case R: rotate(U, R, D, L); break;
            case B: rotate(U, B, D, F); break;
            case L: rotate(U, L, D, R); break;
            case F: rotate(U, F, D, B); break;
            case U: rotate(F, R, B, L); break;  // 上から見て反時計回り
            case D: rotate(F, L, B, R); break;  // 下から見て反時計回り
        }
    }
    int& operator[](int n) { return face[n]; }
    const int& operator[](int n) const { return face[n]; }
    vector<Dice> all_rolls() {
        vector<Dice> res;
        for (int k = 0; k < 6; k++) {
            for (int i = 0; i < 4; i++) {
                res.push_back(*this);
                turn(R);
            }
            turn(k % 2 == 1 ? U : F);
        }
        return res;
    }
    void rotate(int a, int b, int c, int d) {
        int t = face[d]; face[d] = face[c]; face[c] = face[b];
        face[b] = face[a]; face[a] = t;
    }
    friend ostream& operator<< (ostream& os, const Dice d) {
        os << "[";                          // U, B, L, F, R, D
        for (int i = 0; i < 6; i++) os << d[i] << " ]"[i == 5];
        return os;
    }
};

int main() {
    Dice dice = Dice();
    map<int, map<int, Dice>> UFdices;
    for (auto d : dice.all_rolls()) {
        UFdices[d[U]][d[F]] = d;
    }
    int n;
    while (cin >> n, n) {
        // (x, y): (f, lv)
        map<pair<int, int>, pair<int, int>> gridU;
        while (n--) {
            int u, f; cin >> u >> f;
            Dice dice = UFdices[u][f];
            int x = 0, y = 0;
            while (true) {
                auto& now = gridU[{x, y}];
                int lv = now.second;
                int dx[] = {0, 0, -1, 0, 1, 0};
                int dy[] = {0, -1, 0, 1, 0, 0};
                vector<int> dirs = {B, L, F, R};
                sort(dirs.begin(), dirs.end(), [&dice](int a, int b) {
                    return dice[a] > dice[b];
                });
                bool can_fall = false;
                for (int k : dirs) if (dice[k] > 3) {
                    int nx = x + dx[k], ny = y + dy[k];
                    if (gridU[{nx, ny}].second < lv) {
                        dice.turn(k);
                        x = nx;
                        y = ny;
                        can_fall = true;
                        break;
                    }
                }
                if (!can_fall) {
                    now = {dice[U], lv + 1};
                    break;
                }
            }
        }
        vector<int> cnt(7, 0);
        for (auto p: gridU) cnt[p.second.first]++;
        for (int i = 1; i <= 6; i++) {
            cout << cnt[i] << " \n"[i == 6];
        }
    }
    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using P = pair<int, int>;

int main() {
    int w, h;
    while(cin >> w >> h, w) {
        vector<vector<int>> W(2*h-1);
        vector<vector<int>> ret(w, vector<int>(h, 0));
        for(int i=0; i<2*h-1; ++i) {
            int j_range = i%2 == 0 ? w-1 : w;
            for(int j=0; j<j_range; ++j) {
                int tmp; cin >> tmp;
                W[i].push_back(tmp);
            }
        }

        queue<P> que;
        ret[0][0] = 1;
        que.push(make_pair(0, 0));
        while(!que.empty()) {
            P p = que.front();
            que.pop();
            int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; // down, right, up, left
            int wy[4] = {p.second*2+1, p.second*2, p.second*2-1, p.second*2},
                wx[4] = {p.first, p.first, p.first, p.first-1};
            for(int i=0; i<4; ++i) {
                int nx = p.first + dx[i], ny = p.second + dy[i];
                if(0 <= nx && nx < w && 0 <= ny && ny < h && ret[nx][ny] == 0) {
                    if(W[wy[i]][wx[i]] != 1) {
                        que.push(make_pair(nx, ny));
                        ret[nx][ny] = ret[p.first][p.second] + 1;
                    }
                }
            }
        }
        cout << ret[w-1][h-1] << endl;
    }
}


Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
template <typename Container> void P(const Container &c) {
    for (const auto& x : c) cout << x << ' '; cout << '\n';
}
int main()
{
    int N; cin >> N;
    int T, A; cin >> T >> A;
    vector<int> H(N); REP(i, N) cin >> H[i];
    double t = T - H[0] * 0.006;
    int k = 0;
    FOR(i, 1, N) {
        double u = T - H[i] * 0.006;
        if (abs(t - A) > abs(u - A)) {
            k = i;
            t = u;
        }
    }
    cout << k + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
n= int(input())

std = int(input())
val = []
alldiff = []
for i in range(n-1):
    a = int(input())
    alldiff.append(a-std)
    if i == n-2:
        val.append(a-std)
    else:
        if std > a:
            std = a
        else:
            val.append(a-std)

print(max(max(val),max(alldiff)))

Measured memory_bytes: 23560
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int,string> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
int arr[N],A[N],ARR[N]  ;
bool visited[N]={};
int cnt[N]={};
bool f;
int per(vector<int>ve)
{
    int count(0);
    while(prev_permutation(ve.begin(),ve.end()))
    {
        count++;
    }
    return count;
}
int main()
{
    int n;
    cin>>n;
    vi v1(n),v2(n);
    rep(i,n)
    {
        cin>>v1[i];
    }
    rep(i,n)
    {
        cin>>v2[i];
    }
   int ans1=per(v1) , ans2=per(v2);
   cout<<abs(ans1-ans2);
go;
}


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

int f(char a,char b){
	if( a == 'r' && b == 'g' ) return 'b';
	if( a == 'b' && b == 'r' ) return 'g';
	if( a == 'b' && b == 'g' ) return 'r';
	swap(a,b);
	if( a == 'r' && b == 'g' ) return 'b';
	if( a == 'b' && b == 'r' ) return 'g';
	if( a == 'b' && b == 'g' ) return 'r';
	return 0;
}

int main(){
	string s;
	while(cin >> s && s != "0" ){
		map<string,int> done;
		queue< pair<string,int> > Q;
		Q.push(make_pair(s,0));
		while(Q.size()){
			pair<string,int> q = Q.front(); Q.pop();
			if( done[q.first]++) continue;
			if( count(q.first.begin(),q.first.end(),q.first[0]) == q.first.size() ) {
				cout << q.second << endl;
				goto exit;
			}
			for(int i = 0 ; i < q.first.size() - 1 ; i++){
				if( f(q.first[i],q.first[i+1]) ){
					char c = f(q.first[i],q.first[i+1]);
					string next = q.first;
					next[i] = next[i+1] = c;
					Q.push(make_pair(next,q.second+1));
				}
			}
		}
		cout << "NA" << endl;
		exit:;
	}
}

Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    string s;
    cin >> s;
    bool f = 1;

        if(s.at(0) > '2')f = 0;
        else{
            for(int i = 1; i < 10; ++i){
                
                if(i == 1){
                    if(s.at(i) >= '1')break;
                }
                if(i == 2){
                    if(s.at(i) >= '2')break;
                }
                if(i == 3){
                    if(s.at(i) < '9')f = 0;
                }
                if(i == 5){
                    if(s.at(i) == '1')break;
                }
                if(i == 6){
                    if(s.at(i) < '5')f = 0;
                }
            }
        }

    if(f)cout << "TBD" << endl;
    else cout << "Heisei" << endl;

}

Measured memory_bytes: 256
/*	Author
@ Pranjal Walia
IIIT Bangalore
*/
#include<bits/stdc++.h>
using namespace std;

void fastscan(int &x){
bool neg = false;register int c;
x = 0;c = getchar();
if(c=='-'){neg = true;c = getchar();}
for(; (c>47 && c<58); c=getchar()){x = x *10 + c - 48;}
if(neg){x *= -1;}}

#define ff              				first
#define ss              				second
#define int             				long long
#define pb              				push_back
#define mp              				make_pair
#define pii             				pair<int,int>
#define vi              				vector<int>
#define mii             				map<int,int>
#define pqb             				priority_queue<int>
#define pqs             				priority_queue<int,vi,greater<int> >
#define setbits(x)      				__builtin_popcountll(x)
#define zrobits(x)      				__builtin_ctzll(x)
#define mod             				1000000007
#define inf             				1e18
#define mem(a,x,n)					memset(a,x,sizeof(a))		//initialise only 0 ans -1 with memset
#define ps(x,y)         				fixed<<setprecision(y)<<x
#define mk(arr,n,type)  				type *arr=new type[n];
#define w(x)            				int x; cin>>x; while(x--)
#define sortv(v)        				sort(v.begin() , v.end())
#define rsortv(v)       				sort(v.rbegin() , v.rend())
#define pw(b,p)         				pow(b,p) + 0.1
#define __          	   				ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,a,b)	   					for(int i=a;i<b;i++)
#define repb(i,a,b) 	   				for(int i=a;i>=b;i--)
#define endl			   				"\n"    

#define tr(x) cout<<x<<endl;
#define tr2(x,y) cout<<x<<" "<<y<<endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(w,x,y,z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define tr5(v,w,x,y,z) cout<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define tr6(u,v,w,x,y,z) cout<<u<<" "<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;

#define sd(x) cin >> x;
#define sd2(x,y) cin >> x >> y;
#define sd3(x,y,z) cin >> x >> y >> z;
#define sd4(w,x,y,z) cin >> w >> x >> y >> z;

int mypow(int a, int b){	//(logn) --> faster than recursive --> binary expo
    int res = 1;            // call int x = mypow(2,5);
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
}

void file(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif
}

void CF_321_D2_A(){
    int n; sd(n);
    int a[n];
    rep(i , 0 , n)sd(a[i]);
    int c=1;
    int ans=0;

    rep(i  , 1 , n){
        if(a[i] >= a[i-1]){
            c++;
        }
        else{
            ans = max(ans,c);
            c=1;
        }
    }
    ans = max(ans , c);
    tr(ans);
}

int a[100005];


int32_t main(){
    __;	
    int d,n; sd2(d,n);
    int s=0;
    rep(i ,0, n){
        sd(a[i]);
        s+=a[i];
    }
    if(d < s){
        tr(-1);
    }
    else tr(d-s);
}

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

using namespace std;

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

#define int long long
#define tie() ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f(i,from,to) for(int i = from ; i <to ; i++)
#define mem(a , v) memset(a , v , sizeof a)
#define all(v) v.begin() , v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair


const int INF = 1e9 + 7;
const int sz = 1e5 + 20;
/***************************************************************/

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

int32_t main()
{
    clock_t st = clock();
    tie();
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    clog<<(long double)((clock() - st)/CLOCKS_PER_SEC)<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();
		int K=sc.nextInt();
		int ichikan=0;
		int kaisu=1;
		int[] waku=new int[N];
		for(int i=0; i<N; i++) {
			waku[i]=sc.nextInt();
			if(waku[i]==0) {
				ichikan=i;
			}
		}
		kaisu=(N-1)/(K-1);

		if(N==K) {kaisu=1;}
		if((N-1)%(K-1)!=0 && N!=K) {
			kaisu++;
		}
		System.out.println(kaisu);

		//そもそもこの問題(K+1)番目以降に1があると、少なくとも1番目の数字が1にならないので、実際に計算しなくても分かる、
	}
}

Measured memory_bytes: 50568
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main() {
    ll a,b,n;
    ll ans = 0;
    cin >> n >> a >> b;
    if (n > a+b) {
        ans += n/(a+b) * a;
        n %= (a+b);
    }
    ans += min(n,a);
    cout << ans << endl;
}



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

int main(){
	int N,ans=0;
	cin >> N;
	vector<long long> a(N);
	vector<bool> used(N,false);
	for(auto &i:a)cin >> i;
	
	long long X=0;
	for(auto i:a)X^=i;
	
	for(int k=30;k>=0;k--){
		long long t=(1LL<<(k+1))-1LL;
		long long m=(1<<k);
		if((X&m)==m){
			for(int i=0;i<N;i++){
				if(!used[i] && ((a[i]^(a[i]-1))==t)){
					X^=t;
					ans++;
					used[i]=true;
					break;
				}
			}
		}
		//cout << X << endl;
	}
	if(X==0)cout << ans << endl;
	else cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define N 2000
int solve(int,int,int);
int A[N],B[N];

int main(){
  int i,m,n;
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d",&B[i]);
  }
  for(i = 0;i < m;i++){
    if(solve(0,B[i],n)==1){
      printf("yes\n");
      }
    else{
      printf("no\n");
	}
    }
  return 0;
}

int solve(int i,int m,int n){
  int r;
  if(m==0) return 1;
  if(i >= n) return 0;
  r = (solve(i+1,m,n)||solve(i+1,m-A[i],n));
  return r;
}

Measured memory_bytes: 584
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

value = 0
before = 0
for i in range(N):
    value += B[A[i]-1]
    if before != 0 and A[i] - before == 1:
        value += C[before-1]
    before = A[i]
print(value)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
 
typedef long long ll;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
//const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
int main(){
    int n;
    std::cin >> n;
    VEC(dou,a,n);
    dou ans=0;
    rep(i,n)ans+=1/a[i];
    std::cout <<keta(10)<< 1/ans << std::endl;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [x, y, a, b, c] <- getIntList
    ps <- take x . reverse . sort <$> getIntList
    qs <- take y . reverse . sort <$> getIntList
    rs <- reverse . sort <$> getIntList
    let xs = sort (ps ++ qs)
    let s = sum $ zipWith max xs rs
    let t = sum $ drop (min c (a + b)) xs
    print $ s + t

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

#define ll long long int

	
	
int main(){
	stack<char> st;
	
	string s;
	cin>>s;
	
	for(int i=0;i<s.length();i++){
				if(s[i] == 'B'){
						if(!st.empty())
							st.pop();
						continue;
					}
					st.push(s[i]);
	}
	
	string ans;
	
	while(!st.empty()){
			ans += st.top();
			st.pop();
	}
	
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}




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

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

	return gcd(b, a % b);
}

int main(){
	int k;
	long long ans = 0;

	cin >> k;
	for(int a=1; a<=k; a++){
		for(int b=1; b<=k; b++){
			for(int c=1; c<=k; c++){
				ans += gcd(gcd(b, a), c);
			}
		}
	}

	cout << ans << endl;
}



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

int bubbleSort(int A[], int N);

int main() {
	int A[100]; //??°?????????
	int N; //????´???°
	int sw; //?????????????????°???????????±????????????

	//??\???
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	//?¨????
	sw = bubbleSort(A, N);

	//??????
	for (int i = 0; i < N; i++) {
		if (i) { cout << " "; }
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;

	return 0;
}

//flag?????¨????????????????????????
int bubbleSort(int A[], int N) {
	int sw = 0;
	bool flag = true;
	for (int i = 0; flag; i++) {
		flag = false;
		for (int j = N - 1; j > i; j--) {
			if (A[j] < A[j - 1]) {
				swap(A[j], A[j-1]);
				flag = true;
				sw++;
			}
		}
	}
	return sw;
}

Measured memory_bytes: 3104
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

//#define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\n";

ostream& operator<<(ostream& cerr, vector<ll> aux) {
    cerr << "[";
    for (auto e : aux) cerr << e << ' ';
    cerr << "]";
    return cerr;
}

const int maxN = 100011;

int n, m, x, y;
vector<int> adj[maxN];
int gr[maxN], dad[maxN], down[maxN], pr[maxN];
int lvl[maxN];
bool any = false;
bool can = false;
int len;

void ret(bool yes) {
    if (yes) 
        cout << "Yes";
    else
        cout << "No";
    exit(0);
}

void dfs(int node) {
    pr[node] = down[node];
    if (gr[node] > 2) down[node]++;

    for (auto to : adj[node]) {
        if (lvl[to] == 0) {
            lvl[to] = lvl[node] + 1;
            down[to] = down[node];
            dad[to] = node;
            dfs(to);
        } else {
            if (lvl[to] >= lvl[node] - 1) continue;
            if (down[node] - pr[to] < len)
                len = down[node] - pr[to];
        }
    }
}

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        scanf("%d%d", &x, &y);
        adj[x].pb(y);
        adj[y].pb(x);
        gr[x]++; gr[y]++;
    }

    for (int i = 1; i <= n; i++) {
        if (gr[i] & 1) ret(0);
        if (gr[i] == 4) any = true;
        if (gr[i] >= 6) can = true; 
    }

    if (can) ret(1);
    if (!any) ret(0);

    len = n + 13;
    lvl[1] = 1;
    dfs(1);

    for (int i = 1; i <= n; i++)
        if (gr[i] > 2)
            len--;

    if (len < 0) ret(1);
    ret(0);


    return 0;
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> num(n, 0);
    for (size_t i = 0; i < n-1; i++)
    {
        int a;
        cin >> a;
        a--;
        num[a]++;
    }
    
    for (auto &&n : num)
    {
        cout << n << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3976
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        double a = sc.nextInt();
        double b = sc.nextInt();
        double x = sc.nextInt();
        double res;
        
        if(x>a*a*b/2){
            res = Math.toDegrees(Math.atan(a*a*a/(2*a*a*b-2*x)));
        }else{
            res = Math.toDegrees(Math.atan(2*x/(a*b*b)));
        }
        System.out.println(90-res);
	}
}


Measured memory_bytes: 35848
require 'set'
S = gets.chomp.chars
K = gets.to_i

set = Set.new
(0...(S.size)).each do |i|
  (0...K).each do |j|
    next if i + j >= S.size
    s = S[i..(i + j)].join('')
    set.add(s)
  end
end
ans = set.to_a.sort[K - 1]
puts ans


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

int main(){
  int a, b;
  cin >> a >> b;
  if(1 != a && 1 != b){
    cout << 1 << endl;
  }
  else if(2 != a && 2 != b){
    cout << 2 << endl;
  }
  else{
    cout << 3 << endl;
  }
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <queue>

using namespace std;

const char *X, *Y;
int X_length, Y_length;

int table_lcs[1001][1001];

int lcs(int x_begin, int y_begin) {
	int i, j, to;
	int max = 0;
	int v_lcs;
	bool alreadySeenTable[256];
	if (table_lcs[x_begin][y_begin] != -1) {
		return table_lcs[x_begin][y_begin];
	}
	
	for (i = 0; i < 256; i++) {
		alreadySeenTable[i] = false;
	}
	i = x_begin;
	to = Y_length-1;
	while(i <= X_length-1) {
		j = y_begin;
		if (alreadySeenTable[X[i]] == true) {
			i++;
			continue;
		}
		bool found = false;
		while (j <= to) {
			if (X[i] == Y[j]) {
				v_lcs = lcs(i + 1, j + 1) + 1;
				if (v_lcs > max) {
					max = v_lcs;
				}
				found = true;
				break;
			}
			else {
				j++;
			}
		}
		if (found == false) {
			alreadySeenTable[X[i]] = true;
			i++;
		}
		else {
			alreadySeenTable[X[i]] = true;
			i++;
			to = j - 1;
		}
	}
	return table_lcs[x_begin][y_begin] = max;
}

int lcs2(int x_begin, int y_begin) {
	int i, j, to;
	int max = 0;
	int v_lcs;
	if (table_lcs[x_begin][y_begin] != -1) {
		return table_lcs[x_begin][y_begin];
	}

	i = x_begin;
	to = Y_length - 1;
	while (i <= X_length - 1) {
		j = y_begin;
		bool found = false;
		while (j <= to) {
			if (X[i] == Y[j]) {
				v_lcs = lcs(i + 1, j + 1) + 1;
				if (v_lcs > max) {
					max = v_lcs;
				}
				found = true;
				break;
			}
			else {
				j++;
			}
		}
		if (found == false) {
			i++;
		}
		else {
			i++;
			to = j - 1;
		}
	}
	return table_lcs[x_begin][y_begin] = max;
}

int main() {

	int N;
	cin >> N;
	string stringX, stringY;

	for (int i = 1; i <= N; i++) {
		for (int i = 0; i < 1001; i++) {
			for (int j = 0; j < 1001; j++) {
				table_lcs[i][j] = -1;
			}
		}
		cin >> stringX >> stringY;
		X = stringX.c_str();
		X_length = stringX.size();
		Y = stringY.c_str();
		Y_length = stringY.size();
		printf("%d\n", lcs2(0, 0));
	}
	return 0;
}

Measured memory_bytes: 5436
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
//auto start=high_resolution_clock::now();
//auto end=high_resolution_clock::now();
// cout<<duration_cast<milliseconds>(end-start).count()<<endl;
// variable type var=numeric_limits<variable type>::max()/min();
#define _GLIBCXX_DEBUG//only for debugging
/*BISMILLAH UR RAHMAN*/ 
/* AUTHOR -CARLOSRAMIREZ *///Perfection is achieved only on the point of collapse
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) int(x.size())
#define INF INT_MAX;
using namespace std;
typedef long long int ll;
vector<tuple<int,int,int>> v(int(1e5+10));
int store[4][int(1e5+10)];
int dp(int n,int pre)
{
  if(n<=0)return 0;
  if(store[pre][n])return store[pre][n];
  int ans=0,a,b,c;
  tie(a,b,c)=v[n];
  if(pre==1)
    ans=max(b+dp(n-1,2),c+dp(n-1,3));
  else if(pre==2)
    ans=max(a+dp(n-1,1),c+dp(n-1,3));
  else
    ans=max(a+dp(n-1,1),b+dp(n-1,2));
   return store[pre][n]=ans;
}
int main()
{ 
  fast
  int n;cin>>n;
  for(int i=1,x,y,z;i<=n;++i)
  {
    cin>>x>>y>>z;v[i]=make_tuple(x,y,z);
  }
  int ans=INT_MIN;
  for(int i=1;i<=3;++i)
  ans=max(ans,dp(n,i));
  cout<<ans<<endl;
}
   

Measured memory_bytes: 8832
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
num=[[0]*n for _ in range(3)]
from bisect import bisect_right as bl

for i in range(n):
    t=bl(b,a[i])
    if t==n:
        continue
    num[0][t]+=1
#print(num)
for i in range(1,n):
    num[0][i]+=num[0][i-1]
#print(num[0])
for i in range(n):
    t=bl(c,b[i])
    if t==n:
        continue
    num[1][t]+=num[0][i]

#print(num)
for i in range(1,n):
    num[1][i]+=num[1][i-1]
#print(num)
"""
for i in range(1,n):
    num[1][i]+=num[1][i-1]"""
#print(num[1])
print(sum(num[1]))


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

int main() {
  int tax1, tax2;
  cin >> tax1 >> tax2;
  int price = 0;
  bool flag = false;
  while (true) {
    price++;
    if ((int)((double)price * 0.08) == tax1 && (int)((double)price * 0.1) == tax2) {
      flag = true;
      break;
    }
    if ((int)((double)price * 0.08) > tax1)
      break;
    if ((int)((double)price * 0.1) > tax2)
      break;
  }
  if (flag)
    cout << price << endl;
  else
    cout << -1 << endl;
}

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

using namespace std;

int main()
{
	int n;
	long long t;
	cin >> n >> t;
	long long array[n];
	int i;
	for (i=0;i<n;i++)
	{
		cin >> array[i];
	}
	long long answer=0;
	for (i=0;i<n-1;i++)
	{
		if (array[i]+t<=array[i+1])
			answer += t;
		else
			answer += array[i+1]-array[i];
	}
	cout << answer+t;	

	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, uint>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 4;

void solve(){
    static int d[303][303];
    static bool d_n[303][303]; // 道路で結ばれていない場合true
    memset(d, 0, sizeof(d));
    memset(d_n, 0, sizeof(d_n));

    int n; cin >> n;
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            cin >> d[i][j];
        }
    }

    for(int k = 0; k < n; ++k){
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                if(d[i][j] > d[i][k] + d[k][j]){
                    cout << "-1" << endl;
                    return;
                }

                if(d[i][j] == d[i][k] + d[k][j] && d[i][k] > 0 && d[k][j] > 0){
                    d_n[i][j] = true;
                }

            }
        }
    }

    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= i; ++j){
            if(d_n[i][j] == false){
                ans += d[i][j];
            }

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



int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static long rec(long n, long x) {
		if (n%x == 0) {
			return n*2-x;
		}

		long m = n%x;

		return n/x*2*x + rec(Math.max(m, x), Math.min(x,m));
	}

	static void solve() {
		long n = in.nextLong();
	 	long x = in.nextLong();
	 	out.println((rec(Math.max(x, n-x), Math.min(n-x,x))+n));
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 9556
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

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

    vector<vector<pair<int, long long>>> graph(n, vector<pair<int, long long>>(0));
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        graph[a - 1].push_back(make_pair(b - 1, c));
        graph[b - 1].push_back(make_pair(a - 1, c));
    }

    vector<vector<bool>> reachable_tmp(n, vector<bool>(n, false));
    vector<vector<long long>> reachable_rem(n, vector<long long>(n, 0));
    for (int i = 0; i < n; i++) {
        reachable_tmp[i][i] = true;
        reachable_rem[i][i] = l;

        priority_queue<pair<long long, int>> que;
        que.push(make_pair(l, i));
        while (!que.empty()) {
            pair<long long, int> q = que.top();
            que.pop();

            for (int j = 0; j < static_cast<int>(graph[q.second].size()); j++) {
                if (q.first - graph[q.second][j].second >= reachable_rem[i][graph[q.second][j].first]) {
                    reachable_tmp[i][graph[q.second][j].first] = true;
                    reachable_rem[i][graph[q.second][j].first] = q.first - graph[q.second][j].second;
                    que.push(make_pair(q.first - graph[q.second][j].second, graph[q.second][j].first));
                }
            }
        }
    }

    vector<vector<int>> reachable(n, vector<int>(0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i != j && reachable_tmp[i][j]) {
                reachable[i].push_back(j);
            }
        }
    }

    int inf = 1000000000;
    vector<vector<int>> res(n, vector<int>(n, inf));
    for (int i = 0; i < n; i++) {
        res[i][i] = 0;

        queue<int> que;
        for (int j = 0; j < static_cast<int>(reachable[i].size()); j++) {
            res[i][reachable[i][j]] = 0;
            que.push(reachable[i][j]);
        }

        while (!que.empty()) {
            queue<int> que_next;
            while (!que.empty()) {
                int q = que.front();
                que.pop();

                for (int j = 0; j < static_cast<int>(reachable[q].size()); j++) {
                    if (res[i][reachable[q][j]] > res[i][q] + 1) {
                        res[i][reachable[q][j]] = res[i][q] + 1;
                        que_next.push(reachable[q][j]);
                    }
                }
            }

            que = que_next;
        }
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int s, t;
        cin >> s >> t;
        cout << (res[s - 1][t - 1] < inf ? res[s - 1][t - 1] : -1) << endl;
    }
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int ans = 1;
    for(int i = 1; i < s.size() / 2; i++){
        bool flag = true;
        for(int j = 0; j < i; j++){
            if(s.at(j) != s.at(j + i))
                flag = false;
        }
        if(flag) ans = i;
    }
    cout << ans * 2;
}


Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class AC>void r(AC &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
ll x,y;
int main(){
	r(x);r(y);
	if(y>x*2)printf("%lld\n",x+(y-x*2)/4);
	else printf("%lld\n",y/2);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,k,ans;
vector<int> x;
int main(){
  cin >> n >> k;
  x.resize(n);
  for (size_t i = 0; i < n; i++) {
    cin >> x[i];
    ans += min(x[i]*2,(k-x[i])*2);
  }
  cout << ans; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll cc=b/c-a/c+((a%c==0)?1:0);
    ll cd=b/d-a/d+((a%d==0)?1:0);
    ll g=c*d/(__gcd(c,d));
    ll cg=b/g-a/g+((a%g==0)?1:0);
    cout<<(b-a+1)-(cc+cd-cg)<<endl;
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val s = scala.io.StdIn.readLine()
  val t = scala.io.StdIn.readLine()
  var result = 0
  s.zipWithIndex.foreach { c =>
    if(c._1 != t(c._2)) {
      result = result + 1
    }
  }
  println(result)
}

Measured memory_bytes: 58124
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n + 1);
	for (ll i = 1; i <= n; i++) {
		for (ll j = i; j <= n; j += i) a[j]++;
	}
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		ans += i * a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 81380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}

int main() {
  int N; cin >> N;
  vector<vector<pair<int, bool>>> data(N);
  rep(i,N) {
    int A; cin >> A;
    rep(j,A) {
      int x;
      bool y;
      cin >> x >> y;
      x--;
      data[i].push_back(make_pair(x,y));
    }
  }
  
  int ans = 0;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<15> s(tmp);
    bool flag = true;
    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        for (int j = 0; j < data[i].size(); j++) {
          int x; bool y;
          tie(x,y) = data[i][j];
          if (y != s.test(x)) flag = false; 
        }
      }
    }
    if (flag) {
      int k = s.count();
      ans = max(ans,k);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
s = input()

n = len(s)

index1 = (n-1)//2
index2 = (n+3)//2

flag = True

if s == s[::-1]:
    if s[:index1] == s[:index1][::-1]:
        if s[index2-1:] == s[index2-1:][::-1]:
            print('Yes')
            flag = False
        
if flag:
    print('No')

Measured memory_bytes: 3060
// Author -- Frame

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<iostream>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x7fffffffffffffff;
const double eps=1e-10;

template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline bool _cmp(const _Tp &a,const _Tp &b){return abs(a-b)<=eps;}
template <typename _Tp>Finline void read(_Tp &x)
{
	register char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
	read(t);read(args...);
}
Finline int read_str(char *s)
{
	register char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	register char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=100005;
int Query(int x,int y)
{
	printf("? %d %d\n",x-1,y-1);
	fflush(stdout);
	char ch=getchar();
	while(ch!='N'&&ch!='Y') ch=getchar();
	return ch=='Y';
}
int st[N],top;
int ans[N];
int main()
{
	int a,b;
	read(a,b);
	if(a<=b)
	{
		printf("Impossible\n");
		return 0;
	}
	for(int i=1;i<=a+b;++i)
	{
		if(!top) st[++top]=i;
		else
		{
			if(!Query(st[top],i)) --top;
			else st[++top]=i;
		}
	}
	int x=st[top];
	for(int i=1;i<=a+b;++i)
	{
		ans[i]=x!=i?Query(x,i):1;
	}
	printf("! ");
	for(int i=1;i<=a+b;++i) printf("%d",ans[i]);
	printf("\n");
	fflush(stdout);
	return 0;
}


Measured memory_bytes: 724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int a, b, c, d, e, f;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        d = sc.nextInt();
        e = sc.nextInt();
        f = sc.nextInt();
        solve();
    }

    void solve() {
        double concentration = -1.0;
        int mass = -1;
        int sugar = -1;
        for (int i = 0; i * 100 * a < f; i++) {
            for (int j = 0; j * 100 * b < f; j++) {
                for (int k = 0; k * c < f; k++) {
                    for (int l = 0; l * d < f; l++) {
                        if (i == 0 && j == 0 && k == 0 && l == 0) {
                            continue;
                        }
                        int tempMass = i * 100 * a + j * 100 * b + k * c + l * d;
                        if (tempMass > f) {
                            continue;
                        }
                        int tempSugar = k * c + l * d;
                        if (100 * tempSugar * (100 + e) > 100 * e * (tempMass)) {
                            continue;
                        }
                        double tempConcentration = 100.0 * tempSugar / tempMass;
                        if (tempConcentration > concentration) {
                            concentration = tempConcentration;
                            mass = tempMass;
                            sugar = tempSugar;
                        }
                    }
                }
            }
        }
        System.out.println(mass + " " + sugar);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

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

    int attack1;
    int attack2;


    if(a%d == 0) attack1 = a/d;
    else attack1 = a/d + 1;

    if(c%b == 0) attack2 = c/b;
    else attack2 = c/b + 1;

    if(attack1<attack2) cout << "No" << endl;
    else cout << "Yes" << endl; 
}

Measured memory_bytes: 3624
#include<stdio.h>

void spin_w(int x[]){
  int sai1[6],i;

  for(i=0;i<6;i++){
    sai1[i]=x[i];
  }

  sai1[0]=x[2];
  sai1[2]=x[5];
  sai1[3]=x[0];
  sai1[5]=x[3];

  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }

}

void spin_side(int x[]){
int sai1[6],i;

for(i=0;i<6;i++){
  sai1[i]=x[i];
 }

sai1[1]=x[2];
sai1[2]=x[4];
sai1[3]=x[1];
sai1[4]=x[3];

for(i=0;i<6;i++){
  x[i]=sai1[i];
 }
}


void spin_s(int x[]){
	int sai1[6],i;
	
  for(i=0;i<6;i++){
    sai1[i]=x[i];
  }
  sai1[0]=x[4];
  sai1[1]=x[0];
  sai1[4]=x[5];
	sai1[5]=x[1];
	
  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }
}

int conf(int x[],int y[]){
	
	int i,count=0,count2=0,a=0,sai1[6],sai2[6];
	
	for(i=0;i<6;i++){
		sai1[i]=x[i];
		sai2[i]=y[i];
	}
	
	for(i=0;i<6;i++){
    if(sai1[i]==sai2[i]){
      count++;
    }
	}
	
  if(count!=6){
		for(i=0;i<=3;i++){
			spin_w(sai1);
			count2++;
		if(sai1[0]==sai2[0])break;
		}
		if(count2==4){
			for(i=0;i<=3;i++){
			spin_s(sai1);
		if(sai1[0]==sai2[0])break;
			}
		}
			
    for(i=0;i<=3;i++){
      spin_side(sai1);
      if(sai1[1]==sai2[1] && sai1[2]==sai2[2] && sai1[3]==sai2[3] && sai1[4]==sai2[4])break;
		}
  }

  count=0;


  for(i=0;i<6;i++){
    if(sai1[i]==sai2[i]){
      count++;
		}
	}
	if(count==6){
		return 1;
	}else{
		return 0;
	}
}

int main(){
  int i,j,k,l,sai1[6],sai2[6],sai_c[105][6],n,a=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<6;j++){
			scanf("%d",&sai_c[i][j]);
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<6;j++){
			sai1[j]=sai_c[i][j];
		}
		for(k=i+1;k<n;k++){
			for(l=0;l<6;l++){
				sai2[l]=sai_c[k][l];
			}
				if(conf(sai1,sai2)==1){
			a++;
			}
		}
	}
  if(a==0){
	  printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 584
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = Integer.parseInt(scanner.next()); // HP
        int b = Integer.parseInt(scanner.next()); //こうげき
        int c = Integer.parseInt(scanner.next()); //HP
        int d = Integer.parseInt(scanner.next()); //こうげき
        while (a >= 0 || c >= 0) {
            c -= b;
            if (c <= 0) {
                break;
            }
            a -= d;
            if (a <= 0) {
                break;
            }
        }
        if (a <= 0) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 26928
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();

		int a[] = new int[n];

		int sum = 0;
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();

			sum += 1 + (d - 1)/a[i];
		}

		System.out.println(x + sum);

	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#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 INF=1e9+7;

ll power(ll a, int b) {
  if(!b) return 1;
  ll c = power(a, b/2);
  if(b%2) return c*c%INF*a%INF;
  return c*c%INF;
}

int main() {
  int N,K;
  cin >> N >> K;
  
  vl fact(N+1,1);
  rep(i,N) fact[i+1]=fact[i]*(i+1)%INF;
  
  rep2(i,1,K+1) {
    if(i==1)
      cout << N-K+1 << endl;
    else if(i<=N-K-1)
      cout << fact[N-K+1]*fact[K-1]%INF*power(fact[i]*fact[N-K-i+1]%INF*fact[i-1]%INF*fact[K-i]%INF,INF-2)%INF << endl;
    else if(i==N-K)
      cout << (N-K+1)*fact[K-1]%INF*power(fact[i-1]*fact[K-i]%INF,INF-2)%INF << endl;
    else if(i==N-K+1)
      cout << fact[K-1]*power(fact[i-1]*fact[K-i]%INF,INF-2)%INF << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 3612
/*input
3
1 3
2 3
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

const ll MX = 200005;

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	ll n; cin >> n;
	ll ans = 0;
	for(ll i = 1; i <= n; i++) {
		ans += (i * (n - i + 1));
	}
	for(ll i = 0; i < n - 1; i++) {
		ll u, v; cin >> u >> v;
		if(u > v) swap(u, v);
		ans -= (u * (n - v + 1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3676