akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>

using namespace std;
const int INF = 9999999 ;


int main(void){
    int N,M,a[1000],b[1000],c[1000] ;
    cin >> N >> M ;
    
    int t[101][101],dist[101][101] ;
    
    
    for(int i=1;i<=N;i++){
         for(int j=1;j<=N;j++){
              if(i==j){
                   t[i][j] = 0 ; dist[i][j] = 0 ;
              }else{
                   t[i][j] = INF ; dist[i][j] = INF ;
              }
         }
    }
    
    for(int i=1;i<=M;i++){
         
         cin >> a[i] >> b[i] >> c[i] ;
         
         t[a[i]][b[i]] = c[i] ; dist[a[i]][b[i]] = c[i] ;
         
         t[b[i]][a[i]] = c[i] ; dist[b[i]][a[i]] = c[i] ;
    }
    
    for(int k=1;k<=N;k++){
         
         for(int i=1;i<=N;i++){
              
              for(int j=1;j<=N;j++){
                   
                   dist[i][j] = min(dist[i][j] , dist[i][k] + dist[k][j]) ;
                   
              }
         }
    }
    
    int ans = 0 ;
    
    for(int i=1;i<=M;i++){
              
              if(dist[a[i]][b[i]] < t[a[i]][b[i]]){
                   ans++ ;
              }
    }
    
    cout << ans << endl ;
    

    
}


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    long long ans = 0;
    vector<int> A(N);

    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    for (int i = 1; i < N; i++){
        if(A[i-1] > A[i]){
            ans += A[i-1] - A[i];
            A[i] += A[i-1] - A[i];
        }
    }
    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3916
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>
#include <cassert>

using ll = long long;
using ull = unsigned long long;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

constexpr ll NOT_SPECIFIED_VALUE_MIN = INT64_MIN;
constexpr ll NOT_SPECIFIED_VALUE_MAX = INT64_MAX;

int main() {
	ll x;
	cin >> x;
	if (x < 600)
		cout << 8 << endl;
	else if (x < 800)
		cout << 7 << endl;
	else if (x < 1000)
		cout << 6 << endl;
	else if (x < 1200)
		cout << 5 << endl;
	else if (x < 1400)
		cout << 4 << endl;
	else if (x < 1600)
		cout << 3 << endl;
	else if (x < 1800)
		cout << 2 << endl;
	else
		cout << 1 << endl;
}


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

int main()
{
  int X, N;
  cin >> X >> N;
  vector<int> p(N);
  
  bool low = false;
  int D = X;
  int dif = 1;
  
  for(int i = 0; i < N; i++){cin >> p.at(i);}
  for(int i = 0; i < N; i++)
  {
    for(int j = 0; j < N; j++)
    {
      if(p.at(j) == D && low == false)
      {
        D -= dif;
        dif++;
        low = true;
        break;
      }
      else if(p.at(j) == D && low)
      {
        D += dif;
        dif++;
        low = false;
        break;
      }
    }
  }
  
  cout << D << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end());
    ll p=a.back();
    ll l=*(lower_bound(a.begin(),a.end(),p/2)-1);
    ll r=*lower_bound(a.begin(),a.end(),p/2);
    //cout<<l<<" "<<r<<endl;
    //cout<<(ld)p/2.0-(ld)l<<" "<<(ld)r-(ld)p/2.0<<endl;
    if((ld)p/2.0-(ld)l>(ld)r-(ld)p/2.0){
        cout<<p<<" "<<r<<endl;
    }else{
        cout<<p<<" "<<l<<endl;
    }
}

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

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

	for (int i = 0; i <= N; i++) {
		for (int j = 0; i+j <= N; j++) {
			int total = 10000 * i + 5000 * j + 1000 * (N-i-j);
			if (total == Y) {
				cout << i << " " << j << " " << N-i-j << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 083 B / Link: http://abc083.contest.atcoder.jp/tasks/abc083_b  ----- */


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

	LL N, A, B; cin >> N >> A >> B;
	LL ans = 0LL;
	auto f = [&](LL x) {
		LL ret = 0;
		while (x) {
			ret += x % 10;
			x /= 10;
		}

		return A<=ret && ret<=B;
	};
	FOR(i, 1, N + 1) {
		if (f(i))ans += i;
	}
	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
	string s; cin >> s;
	if(s=="SUN") cout << 7 << endl;
	if(s=="MON") cout << 6 << endl;
	if(s=="TUE") cout << 5 << endl;
	if(s=="WED") cout << 4 << endl;
	if(s=="THU") cout << 3 << endl;
	if(s=="FRI") cout << 2 << endl;
	if(s=="SAT") cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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;
}

ll gcd(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

void PrimeFact(ll x) { // 素因数分解 出力部を適切に書き換え
	int i=2;
	while(x%2&&i*i<=x) {
		cout<<2<<endl;
		x/=2;
	}
	i++;
	while(i*i<=x) {
		if(x%i) {
			i+=2;
			continue;
		}
		cout<<i<<endl;
		x/=i;
	}
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}

struct Node{
	int number;
	vector<int> under;
	int lv;
	int salary;
};

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

	int i=0;
	while(i<S.length()) {
		if(i+6<=S.length()&&S.substr(i,6)=="eraser") {
			i+=6;
			continue;
		}
		if(i+5<=S.length()&&S.substr(i,5)=="erase") {
			i+=5;
			continue;
		}
		if(i+7<=S.length()&&S.substr(i,7)=="dreamer") {
			if(i+7==S.length()||S.at(i+7)=='d'||S.at(i+7)=='e') {
				i+=7;
				continue;
			}
		}
		if(i+5<=S.length()&&S.substr(i,5)=="dream") {
			i+=5;
			continue;
		}
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
}


Measured memory_bytes: 512
//#include<i_am_noob_orz>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define int ll
#define ull unsigned long long
#define pii pair<int,int>
#define X first
#define Y second
#define mod ((ll)1e9+7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define bit_count(x) __builtin_popcount((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define LOCAL
#ifdef LOCAL
#define debug(a) cerr<<#a<<" "<<a<<endl;
#else
#define debug(a)
#endif
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int col[500010],cnt=0,ar[500010],o[500010];
struct NODE{
	int l,r,lbl,ind;
}qry[500010];
bool cmp(NODE a,NODE b){
	if(a.lbl==b.lbl)return(a.r<b.r);
	return a.lbl<b.lbl;
}
inline void add(int x){
	if(!col[x])cnt++;
	col[x]++;
}
inline void sub(int x){
	col[x]--;
	if(!col[x])cnt--;
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,q;
	cin>>n>>q;
	memres(col);
	F(n)cin>>ar[i];
	int m=sqrt(n);
	F(q){
		int l,r,bl;
		cin>>l>>r;
		--l,--r;
		bl=l/m;
		qry[i]={l,r,bl,i};
	}
	sort(qry,qry+q,cmp);
	int l=0,r=0;
	add(ar[0]);
	F(q){
		while(l<qry[i].l)sub(ar[l++]);
		while(l>qry[i].l)add(ar[--l]);
		while(r>qry[i].r)sub(ar[r--]);
		while(r<qry[i].r)add(ar[++r]);
		o[qry[i].ind]=cnt;
	}
	F(q)cout<<o[i]<<endl;
return 0;
}


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

int main() {
	std::string s, t;
	std::cin >> s;
	for (char &c : s) c = tolower(c);
	
	int ans = 0;
	
	while (true) {
		std::cin >> t;
		if (t == "END_OF_TEXT") break;
		for (char &c : t) c = tolower(c);
		ans += (s == t);
	}
	
	std::cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define FOR(i,a,b) for(register int i=a;i<=b;i++)

using namespace std;

inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

int main(){
  	
  	int n=read(); int m=read();
  	
  	char str[n+10]; cin>>str;
  	
  	str[m-1]=(str[m-1]-'A')+'a';
  
  	cout<<str;
  
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen("firesafe.in", "r", stdin);
//	freopen("firesafe.out", "w", stdout);
	string s;
	cin >> s;
	cout << string(s.size(), 'x');
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int r[16][16];
int a,b;
int n;
int i,j;
int x,y;

int solve(int p,int q){
	if(p==0&&q==0)return 1;
	else if(r[p][q]==1)return 0;
	else if(p==0)return solve(p,q-1);
	else if(q==0)return solve(p-1,q);
	else return solve(p-1,q)+solve(p,q-1);
}

int main(){
	while(1){
		scanf("%d %d",&a,&b);
		if(a==0&&b==0)return 0;
		for(i=0;i<a;i++)for(j=0;j<b;j++)r[i][j]=0;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d %d",&x,&y);
			r[x-1][y-1]=1;
		}
		printf("%d\n",solve(a-1,b-1));
	}
}

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

using namespace std;

int n, k, h[100000], dp[100000];

int main()
{
  memset(dp,0x3f3f3f3f,sizeof(dp));
  dp[0] = 0;
  cin >> n >> k;
  for(int i = 0; i<n; i++)
    cin >> h[i];
  for(int i = 1; i<n; i++)
    for(int j = 1; j<=min(i,k); j++)
      dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile

INF = float("inf")


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_A
    n, m = readi(2)
    coins = readi(m)
    dp = arr(n + 1, fill_value=INF)
    dp[0] = 0
    for i in range(n):
        for c in coins:
            if i + 1 - c >= 0:
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - c] + 1)
    print(dp[n])


if __name__ == "__main__":
    main()



Measured memory_bytes: 8492
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;
//for debugging 
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14 
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void solve(){
	string n;
	int k;
	cin >> n >> k;
	int len = n.length();
	int dp[len+1][5];
	memset(dp,0LL,sizeof(dp));
	int cur = 0;
	for(int i =1;i<=len;i++){
		for(int j = 0;j<n[i-1]-'0';j++)
			dp[i][min(cur+(j!=0),4)]+=1;

		for(int j =0;j<=k;j++)
		{
			dp[i][j]+=dp[i-1][j];
			dp[i][j+1] +=dp[i-1][j]*9;
		}
		cur+=(n[i-1]!='0');
	}
	if(cur==k)
		dp[len][k]++;
	cout << dp[len][k] << endl;
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 3624
X,Y,Z,K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)


ans = []
for i in range(X):
    if (i+1) > K: break
    for j in range(Y):
        if (i+1)*(j+1) > K: break
        for k in range(Z):
            if (i+1)*(j+1)*(k+1) > K: break
            ans.append(A[i]+B[j]+C[k])

ans.sort(reverse=True)

for i in range(K):
    print(ans[i])
            


Measured memory_bytes: 8708
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
   int n;
   cin>>n;
   vector<int> v(n);
   for(auto &it:v)cin>>it;
   int cnt=0,mx=0;
   for(int i=0;i<n;i++){
	    if(mx<=v[i]){
		  mx=v[i],cnt++;	
		}
	  }
	  cout<<cnt<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}

Measured memory_bytes: 256
N = int(input())
def n_ary(l,d): # リストl中の文字でd桁までを全列挙(sorted)
    if d == 1:
        return(l)
    n = len(l)
    ll = n_ary(l,d-1)
    lll = []
    for i in l:
        for j in ll[n*(n**(d-2)-1)//(n-1):]:
            lll.append(i+j)
    return(ll+lll)
possible = [i.replace('0','3').replace('1', '5').replace('2','7') for i in n_ary(['0','1','2'],9)] # 制約が10^9なので9
print(len([int(i) for i in possible if ('3' in i and '5' in i and '7' in i and int(i) <= N)]))


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

struct Node { int p, l, r; };
Node T[100005];
int n, D[100005];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    if(T[u].p==-1) cout << "root, ";
    else if(T[u].l==-1) cout << "leaf, ";
    else cout << "internal node, ";
    cout << "[";
    for(int i=0, c=T[u].l; c !=  -1; i++, c=T[c].r) {
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(int u, int p) {
    D[u]=p;
    if(T[u].r != -1) rec(T[u].r, p);
    if(T[u].l != -1) rec(T[u].l, p+1);
}

int main() {
    int i, j, d, v, c, l, r;
    cin >> n;
    for(int i=0; i<n; i++) T[i].p = T[i].l = T[i].r = -1;
    for(int i=0; i<n; i++) {
        cin >> v >> d;
        for(int j=0; j<d; j++) {
            cin >> c;
            if(j==0) T[v].l=c;
            else T[l].r=c;
            l=c;
            T[c].p=v;
        }
    }
    for(int i=0; i<n; i++) {
        if(T[i].p==-1) r=i;
    }

    rec(r,0);

    for(int i=0; i<n; i++) print(i);
    
    return 0;
}


Measured memory_bytes: 7680
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt();
		sc.close();
		while(true) {
			c-=b;
			if(c<=0) {
				System.out.println("Yes");
				break;
			}
			a-=d;
			if(a<=0) {
				System.out.println("No");
				break;
			}
		}
	}
}

Measured memory_bytes: 35788
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
#include <deque>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;

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

	long long n, a, b;
	cin >> n >> a >> b;
	long long c = a + b;
	long long res = n / c, remain = n % c;
	long long ans = res * a;
	ans += min(remain, a);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : frog2.cpp
// Author      : omar
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
int n,k,h[100009],dp[100009];

int solve(int idx){
	if(idx>=n)return 1000000009;
	if(idx==n-1)return 0;

	if(dp[idx]!=-1)return dp[idx];
	dp[idx]=1000000009;
	for(int i = 1 ; i  <= k ;i++){
		dp[idx]=min(abs(h[idx]-h[idx+i])+solve(idx+i),
				dp[idx]);
	}
	return dp[idx];

}

int main() {
	memset(dp,-1,sizeof(dp));
	cin>>n>>k;
	for(int i = 0 ; i < n ; i++)cin>>h[i];
	cout<<solve(0);

}


Measured memory_bytes: 5760
#include <stdio.h>          // printf(), scanf()
#include <string.h>         // strlen()
#define MAX_N 100

int dice[6];

void
east()
{
	int t = dice[2];
	dice[2] = dice[0];
	dice[0] = dice[3];
	dice[3] = dice[5];
	dice[5] = t;
}

void
south()
{
	int t = dice[1];
	dice[1] = dice[0];
	dice[0] = dice[4];
	dice[4] = dice[5];
	dice[5] = t;
}

void
west()
{
	int t = dice[3];
	dice[3] = dice[0];
	dice[0] = dice[2];
	dice[2] = dice[5];
	dice[5] = t;
}

void
north()
{
	int t = dice[4];
	dice[4] = dice[0];
	dice[0] = dice[1];
	dice[1] = dice[5];
	dice[5] = t;
}

int
main(int argc, char** argv)
{
	char cmd[MAX_N + 1];
	int l;
	int i;

	for (i = 0; i < 6; ++i)
		scanf("%d", &dice[i]);

	scanf("%s", cmd);
	l = strlen(cmd);
	for (i = 0; i < l; ++i)
	{
		switch (cmd[i])
		{
		case 'E':
			east();
			break;

		case 'S':
			south();
			break;

		case 'W':
			west();
			break;

		case 'N':
		default:
			north();
		}
	}

	printf("%d\n", dice[0]);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

int main() {
    ll n;
    cin >> n;
    ll sN = sqrt(n) + 1;

    ll target = n;

    bool isNotFind = true;
    while (isNotFind) {
        bool isPrime = true;

        for (ll j = 2; j < sN; j++) {
            if (target % j == 0) {
                isPrime = false;
                break;
            }
        }

        if (isPrime) {
            isNotFind = false;
        } else {
            target = target + 1;
        }
    }

    cout << target << endl;
}

Measured memory_bytes: 3648
import math
A,B,H,M = map(int, input().split())

#時針がなす角度をa、分針がなす角度をbとする
a = (H * 30) + (M * 0.5)
b = M * 6
c = math.radians(abs(a-b))

C = (A**2 + B**2 - 2*A*B*math.cos(c))**0.5

print(C)

Measured memory_bytes: 9496
#include<bits/stdc++.h>
using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-3
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
const ll mod = 1e9 + 9;
const db pi = acos(-1.0);
const ll maxn = 5e5+10;
vector<int > a;
signed main(){
    int  n, k;
    cin >> n >> k;
    a.resize(n);
    for(auto &i : a){
        cin >> i;
    }
    sort(all(a));
    ll res = 0;
    for(int i = 0; i < k;i++){
        res += a[i];
    }
    cout << res << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long Q, std::vector<long long> A, std::vector<long long> B) {
    rep(i, Q) {
        ll a = A[i], b = B[i];

        auto check = [&](ll d) {
            ll m;
            if (d % 2 == 0) {
                ll a1 = d / 2, b1 = d / 2;
                if (a1 >= a) a1++;
                if (b1 >= b) b1++;
                m = max((a1 + 1) * b1, a1 * (b1 + 1));
            } else {
                ll a1 = d / 2 + 1, b1 = d / 2 + 1;
                if (a1 >= a) a1++;
                if (b1 >= b) b1++;
                m = a1 * b1;
            }
            if (m < a * b)
                return true;
            else
                return false;
        };

        // 二分探索
        ll left = 0, right = 2000000005;
        while (right - left > 1) {
            ll mid = (left + right) >> 1LL;
            if (check(mid))
                left = mid;
            else
                right = mid;
        }
        cout << left << endl;
    }
}

int main() {
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> A(Q);
    std::vector<long long> B(Q);
    for (int i = 0; i < Q; i++) {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
    }
    solve(Q, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define ll long long int

using namespace std;

int main(void) {
    int q,c,a,n;
    cin >> q;
    REP(i,q){
        cin >> c >> a >> n;
        int ans=min({c,a,n});
        c-=ans;
        a-=ans;
        int s=min(c/2,a);
        c-=2*s;
        ans+=s+c/3;
        cout<< ans<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3080
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,A,B,C,D = inpl()
N -= 1
dist = abs(B-A)

if dist > D*(N-1):
    print('NO')
else:
    if N%2 == 0:
        for i in range(N//2+1):
            mid = i*(C+D)
            if abs(dist-mid) <= N*(D-C)/2:
                print('YES')
                sys.exit()
        print('NO')
    else:
        for i in range(N//2+1):
            mid = (i+1/2)*(C+D)
            if abs(dist-mid) <= N*(D-C)/2:
                print('YES')
                sys.exit()
        print('NO')


Measured memory_bytes: 4212
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
ll n,m;cin>>n>>m;
int p;
string s;
int t[n]={0};
int ok[n]={0};
int cor=0;
int dif=0;
int wa[n]={0};
rep(i,m){
 cin>>p>>s;
 p--;
 if(ok[p])continue;
 if(s=="AC"){
     ok[p]=1;
     cor++;
     dif+=wa[p];
 }
 if(s=="WA")wa[p]++;
}
cout<<cor<<" "<<dif<<endl;

}

Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	N := ReadInt()
	m := make([]map[byte]int, N)
	for i := 0; i < N; i++ {
		m[i] = make(map[byte]int)
		s := ReadString()
		for _, c := range []byte(s) {
			m[i][c]++
		}
	}
	v := ""
	for c := byte('a'); c <= 'z'; c++ {
		min := 1 << 62
		for i := 0; i < N; i++ {
			if min > m[i][c] {
				min = m[i][c]
			}
		}
		v += strings.Repeat(string(c), min)
	}
	fmt.Println(v)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1880
#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 tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;
 
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator
 
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
const int N=1e5+5;
vi adj[N];
int n,k;
int fact[N];
int ans;

void precompute()
{
    fact[0]=1;
    for(int i=1;i<N;i++)
        fact[i]=fact[i-1]*i,fact[i]%=mod;
}

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

int modinv(int x)
{
    return powermod(x, mod - 2, mod);
}

void dfs(int node,int pt)
{
    int rem=k-1-(pt!=-1);
    //trace2(node,rem);
    int child=adj[node].size()-1;
    if(child>rem)
    {
        cout<<0;
        exit(0);
    }

    ans*=fact[rem],ans%=mod;
    ans*=modinv(fact[rem-child]),ans%=mod;

    //trace3(node,ans,child);
    for(int i=0;i<adj[node].size();i++)
    {
        int el=adj[node][i];
        if(el!=pt)
            dfs(el,node);
    }

}

int32_t main()
{
    fast;
    cin>>n>>k;
    precompute();
    for(int i=2;i<=n;i++)
    {
        int x,y;cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    adj[1].pb(-1);

    if(n==1)
    {
        cout<<k;
        return 0;
    }
    ans=k;
    dfs(1,-1);
    cout<<ans;
}

Measured memory_bytes: 9984
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
S = list(input())[:-1]
T = list(input())[:-1]
N = len(S)
ans = N
for i in range(N):
    if S[i] == T[i]:
        ans -= 1
print(ans)

Measured memory_bytes: 15288
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <set>
#include <cmath>
#include <algorithm>
#include <locale>

//pair sort firstに揃う

#define int long long
#define pb(n) push_back(n)
#define For(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define F first
#define S second
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ELM 100001 //問題によっては1000000001に変更
using namespace std;

int F(int x){
    int ans=0;
    while (x%2==0) {
        ans++;
        x/=2;
    }
    return ans;
}
signed  main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n);
    For(n, i){
        cin >> a.at(i);
    }
    int ans=0;
    For(n, i){
        ans+=F(a[i]);
    }
    Pr(ans);
    return 0;
}



Measured memory_bytes: 384
<?php
fscanf(STDIN, "%d", $n);
$line = explode(" ",trim(fgets(STDIN)));

if(in_array('0', $line)){
    echo "0";
    exit;
}

$sum = 1;
foreach($line as $val){
    $sum *= $val; 
    if($sum > 10**18){
        echo "-1";
        exit;
    }
}
echo $sum;


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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}


int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<long long> a(7);
    for(int i = 0; i < 7; i++) {
        cin >> a[i];
    }
    long long ans = 0;
    long long t = min({a[0], a[3], a[4]});
    for(long long i = 0; i <= min(t, 1ll); i++) {
        long long x = a[0]-i, y = a[3]-i, z = a[4]-i;
        long long cur = a[1] + i*3 + (x/2)*2 + (y/2)*2 + (z/2)*2;
        ans = max(ans, cur);
    }
    cout << ans << endl;
}





Measured memory_bytes: 3588
#include <iostream>
#include <cstdlib>

using namespace std;

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

    cin >> a >> b >> c >> d;
    if (((abs(a - b) <= d) && (abs(b - c) <= d)) || (abs(a - c) <= d)){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[51] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, K, V[51];
	scanf("%d %d", &N, &K);
	for (i = 1; i <= N; i++) scanf("%d", &(V[i]));
	
	data d[51];
	for (i = 0; i < N; i++) {
		d[i].key = V[i+1];
		d[i].id = i + 1;
	}
	merge_sort(d, N);
	
	int l, r, sum[51][51] = {};
	for (r = 1; r <= K && r <= N; r++) sum[0][r] = sum[0][r-1] + V[N-r+1];
	for (l = 1; l <= K && l <= N; l++) {
		sum[l][0] = sum[l-1][0] + V[l];
		for (r = 1; r <= K - l && r <= N - l; r++) sum[l][r] = sum[l][r-1] + V[N-r+1];
	}
	
	int j, max = 0;
	for (l = 0; l <= K && l <= N; l++) {
		for (r = 0; r <= K - l && r <= N - l; r++) {
			for (i = 0, j = 0; i < K - l - r && i <= l + r; i++) {
				for (; j < N && d[j].key < 0 && d[j].id > l && d[j].id < N - r + 1; j++);
				if (j == N || d[j].key >= 0) break;
				sum[l][r] -= d[j++].key;
			}
			if (sum[l][r] > max) max = sum[l][r];
		}
	}
	
	printf("%d\n", max);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1744
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int x = sc.NextInt();

        int lcm = Lcm(x, 360);

        int answer = lcm / x;

        Console.WriteLine(answer);
    }

    // 最大公約数
    private static int Gcd(int a, int b)
    {
        if (a < b)
        {
            return Gcd(b, a);
        }
        while (b != 0)
        {
            int r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    // 最小公倍数
    private static int Lcm(int a, int b)
    {
        return a / Gcd(a, b) * b;
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27416
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int k, t;
    cin >> k >> t;
    vint a(t);
    rep(i, t) cin >> a[i];
    sort(rall(a));
    int x = 0, y = 0;
    rep(i, t) {
        if (x <= y) x += a[i];
        else y += a[i];
    }

    int d = abs(x - y);

    int ans = max(0, d-1);

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  string a,b;cin>>a>>b;
  int A=a.size(),B=b.size();
  if(A>B){
    cout<<"GREATER"<<endl;
    return 0;
  }
  else if(A<B){
    cout<<"LESS"<<endl;
    return 0;
  }
  else {
    rep(i,A){
      if(a[i]>b[i]){
        cout<<"GREATER"<<endl;
        return 0;
      }
      else if(a[i]<b[i]){
        cout<<"LESS"<<endl;
        return 0;
        }
    }
  }
  cout<<"EQUAL"<<endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> a(n),f(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>f[i];
	
	sort(a.begin(),a.end());
	sort(f.rbegin(),f.rend());
	// for(auto t: a)
	// 	cout<<t<<" ";
	// cout<<endl;
	// for(auto t:f)
	// 	cout<<t<<" ";
	// cout<<endl;
	ll low=0,high=1e12;
	while(low<high)
	{
		ll mid=(low+high)>>1;
		ll cnt=0;
		for(int i=0;i<n;i++)
		{
			if(mid<a[i]*f[i])
				cnt+=a[i]-mid/f[i];
		}
		// cout<<mid<<" "<<cnt<<endl;
		if(cnt<=k)
			high=mid;
		else
			low=mid+1;
	}
	cout<<low<<endl;
}

Measured memory_bytes: 3456
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100000

int main(){
  int a,b,c;

  scanf("%d%d%d",&a,&b,&c);

  int t = 0;
  
  for(int i=0;i<60;i++){
    if(t<=c && c<=t+a){
      printf("%d\n",c);
      return 0;
    }
    t += a + b;
    while(t>c) c+=60;
  }
    
  puts("-1");
  
  return 0;
}

Measured memory_bytes: 3220
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


from operator import itemgetter

N = read_a_int()
contents = []
for i in range(N):
    contents.append(list(input().split())+[i+1])

contents = [[a, -int(b), c] for a, b, c in contents]

contents.sort(key=itemgetter(0, 1))
ans = [a[2] for a in contents]
print(*ans, sep='\n')


Measured memory_bytes: 3064
import sys
import math
input = sys.stdin.readline

a, b, x = map(int, input().split())

if a*a*b/2 <= x:
    temp = 2*(b - x/(a**2))
    theta = math.atan2(temp, a)
    ans = math.degrees(theta)
else:
    temp = 2*x/(a*b)
    theta = math.atan2(temp, b)
    ans = 90 - math.degrees(theta)
print(ans)

Measured memory_bytes: 3060
# include <iostream>
# include <vector>


using namespace std;


int main() {
    int n; cin >> n;
    vector<int> scores(n); for (int i=0; i<n; ++i) cin >> scores[i];
    sort(scores.begin(), scores.end());

    int sum = 0; for (int score: scores) sum += score;
    if (sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }

    vector<bool> dp(sum+1); fill(dp.begin(), dp.end(), false);
    dp[sum] = true; dp[0] = true;
    for (int target_score=sum; target_score>=0; --target_score) {
        for (int score: scores) {
            dp[sum-score] = dp[sum];
        }
    }

    for (int score=sum; score>=0; --score) {
        if (dp[score] and score % 10 != 0) {
            cout << score << endl;
            return 0;
        }
    }

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



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

int main (void){
    int a, b;
    cin >> a >> b;
    if(a < 10 && b < 10){
        cout << a * b << endl;
    } else {
        cout << "-1" << endl;
    }
    return 0;
}



Measured memory_bytes: 3676
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#include <numeric>

#define ll long long
#define int long long
#define ld long double
#define endl "\n"
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
const ll MOD = 1e9 + 7;
const int N = 1e7+5;
const int demo = 10;
using namespace std;
const ll cfmod=998244353;
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int arr[N];
signed main(){
    int q=1;
    //cin>>q;
    while(q--) {
        memset(arr,0,sizeof(arr));
        for(int i=1;i<=N;i++){
            for(int j=i;j<N;j+=i){
                arr[j]++;
            }
        }
        int n;
        cin>>n;
        int ans=0;
        for(int i=1;i<=n;i++){
            ans+=i*arr[i];
        }
        cout<<ans;
    }
}

Measured memory_bytes: 81312
#include <stdio.h>
#include <string.h>
int main(){
    int a,b,c,i;
    scanf("%d %d %d",&a,&b,&c);
    for(i=0;i<b;i++){
        if((b*i+c)%a==0){
            printf("YES");
            return 0;
        }
    }
    printf("NO");
    return 0;
}

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

using namespace std;

using ll = long long;

const long long MOD_NUMBER = 1000000007;
const int MAX = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  ll n, a, q, b, c, sum = 0;
  vector<ll> cnt(100000, 0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    sum += a;
    cnt[a-1]++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    sum += (c-b)*cnt[b-1];
    cnt[c-1] += cnt[b-1];
    cnt[b-1] = 0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 3872
import kotlin.math.sqrt

fun main() {
    val N = readLine()!!.toInt()

    var fMap = HashMap<Int, Int>()
    for (i in 1..N) {
        fMap[i] = 0
    }

    val max = sqrt(N.toDouble()).toInt()
    for (x in (1..max)) {
        for (y in (1..max)) {
            for (z in (1..max)) {
                val n = x * x + y * y + z * z + x * y + y * z + z * x
                fMap[n] = (fMap[n] ?: 0) + 1
            }
        }
    }

    for (i in 1..N) {
        println(fMap[i])
    }
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    ll a, b, k;
    cin >> a >> b >> k;

    if (b - a >= 2 * k)
    {
        for (int i = a; i < a + k; i++)
        {
            cout << i << endl;
        }
        for (int i = b - k + 1; i <= b; i++)
        {
            cout << i << endl;
        }
    }
    else
    {
        for (int i = a; i <= b; i++)
            cout << i << endl;
    }
}


Measured memory_bytes: 256
N = input()

a = int(N[-1])

if a == 2 or a == 4 or a == 5 or a == 7 or a == 9:
    print('hon')
elif a == 0 or a == 1 or a == 6 or a == 8:
    print('pon')
elif a == 3:
    print('bon')


Measured memory_bytes: 61832
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<char> a;
	int i, j;
	char x[10] = {0};
	cin >> x;
	i = 0;
	while (x[i])
	{
		a.push_back(x[i]);
		i++;
	}
	j = 0;
	for (i = 0; i < a.size()-1; i++)
	{
		if (a[i] == 'A'&&a[i + 1] == 'C')
		{
			cout << "Yes" << endl;
			j++;
			break;
		}
	}
	if (!j)cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256