akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
long long mod=924844033;
long long I=44009197;
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		b/=2;
		a=a*a%mod;
	}
	return ret;
}
void fft(int n, int p, long long a[]) {
	long long et=I;
	if(p==-1)et=pw(I,mod-2);
  for (int m = n; m >= 2; m >>= 1) {
    int mh = m >> 1;
	long long w=1;
    for (int i = 0; i < mh; i++) {
      for (int j = i; j < n; j += m) {
        int k = j + mh;
        long long x = mod+a[j] - a[k];
        a[j] += a[k]; a[j]%=mod;
        a[k] = w * x; a[k]%=mod;
		
      }
	  w*=et;w%=mod;
    }
    et=et*et%mod;
  }
  int i = 0;
  for (int j = 1; j < n - 1; j++) {
    for (int k = n >> 1; k > (i ^= k); k >>= 1);
    if (j < i) swap(a[i], a[j]);
  }
}
vector<int>g[210000];
long long inv[210000];
long long fact[210000];
long long factinv[210000];
int oc[210000];
int N;
int dfs(int a,int b){
	int sz=1;
	for(int i=0;i<g[a].size();i++){
		if(g[a][i]==b)continue;
		sz+=dfs(g[a][i],a);
	}
	oc[sz]++;
	if(b!=-1)oc[N-sz]++;
	return sz;
}
long long x[1<<21];
long long y[1<<21];
int main(){
	int a;scanf("%d",&a);
	N=a;
	for(int i=0;i<a-1;i++){
		int p,q;
		scanf("%d%d",&p,&q);
		p--;q--;g[p].push_back(q);g[q].push_back(p);
	}
	inv[1]=fact[0]=factinv[0]=1;
	for(int i=2;i<210000;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<210000;i++)fact[i]=fact[i-1]*i%mod;
	for(int i=1;i<210000;i++)factinv[i]=factinv[i-1]*inv[i]%mod;
	int n=1<<21;
	long long ni=pw(n,mod-2);
	dfs(0,-1);
	for(int i=0;i<a;i++){
		x[i]=oc[i]*fact[i]%mod;
	}
	for(int i=0;i<a;i++){
		y[(1<<20)-i]=pw(fact[i],mod-2);
	}
	fft(1<<21,1,x);
	fft(1<<21,1,y);
	for(int i=0;i<(1<<21);i++)x[i]=x[i]*y[i]%mod;//for(int i=0;i<(1<<21);i++)if(x[i]<0)printf("%d: %lld\n",i,x[i]);
	fft(1<<21,-1,x);
	for(int i=0;i<(1<<21);i++)x[i]=x[i]*ni%mod;
	
	for(int i=1;i<=a;i++){
		long long ks=pw(fact[i],mod-2);
		ks=ks*x[i+(1<<20)]%mod;
		long long ret=(a*fact[a]%mod*factinv[a-i]%mod*factinv[i]%mod+mod-ks)%mod;
		printf("%lld\n",ret);
	}
}
/*
sum(j) a[j]*jCi
= 1/(i!) sum(j) a[j]*(j!)/((j-i)!)
= 1/(i!) sum(j) oc[j]*inv[(j-i)!]
*/


Measured memory_bytes: 62464
# coding: utf-8
# Your code here!

num_str = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
num_str = num_str.split(", ")
input_str = input()

print(num_str[int(input_str)-1])

Measured memory_bytes: 2940
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def make_divisors(n): # nの約数を列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

N = ir()
D = make_divisors(N)
answer = 10 ** 12
for d in D:
    e = N // d
    if e < d:
        break
    result = (d - 1) + (e - 1)
    if result < answer:
        answer = result

print(answer)


Measured memory_bytes: 3272
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		//System.out.println("c");
		
		Scanner sc = new Scanner( System.in );
		int N = sc.nextInt();
		int time = sc.nextInt();
		
		int[] oyu = new int[N];
		
		int oyu_time = 0;
		
		for( int i = 0;i < N;i++ ){
			oyu[i] = sc.nextInt();
			
			if( i == 0 ){
				oyu_time += time;
			}else{
				
				if( oyu[i] - oyu[i - 1 ] > time ){
					oyu_time += time;
				}else{
					oyu_time += time - ( time - ( oyu[i] - oyu[i - 1]) );
				}
				
			}
		}//forここまで
		
		System.out.println(oyu_time);

	}

}


Measured memory_bytes: 89380
n,m=map(int,input().split())
ab=[list(map(int, input().split())) for _ in range(n)]
ab=list(sorted(ab, key=lambda x: x[0]))

import heapq
hq=[]
ans=0
j=0
for i in range(1, m+1):  # m-i日後を考える
    while (j<n) and (ab[j][0]<=i):
        heapq.heappush(hq, -ab[j][1])
        j+=1
    if len(hq):
        ans+=-heapq.heappop(hq)

print(ans)


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> V(9, vector<int>(9));
  for (int i = 0, a, b; i < M && cin >> a >> b; i++)
    V.at(a).at(b)++, V.at(b).at(a)++;

  vector<int> P(N);
  for (int i = 0; i < N; i++) P.at(i) = i + 1;
  int ans = 0;
  do {
    int b = 1;
    for (int i = 0; i + 1 < N; i++)
      if (!V.at(P.at(i)). at(P.at(i + 1))) b = 0;
    ans += b;
  } while (next_permutation(P.begin(), P.end()) && P.at(0) == 1);

  cout << ans << endl;  
}

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

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

int main(){
    ll a,b;
    scanf("%lld %lld",&a,&b);
    ll x1 = floor(a/0.08);
    ll x2 = ceil(a/0.08);
    ll x3 = floor(b/0.1);
    ll x4 = ceil(b/0.1);

    if(floor(x1*0.08)==a and floor(x1*0.1)==b) printf("%lld\n",x1);
    else if(floor(x2*0.08)==a and floor(x2*0.1)==b) printf("%lld\n",x2);
    else if(floor(x3*0.08)==a and floor(x3*0.1)==b) printf("%lld\n",x3);
    else if(floor(x4*0.08)==a and floor(x4*0.1)==b) printf("%lld\n",x4);
    else printf("-1\n");
    return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)

using namespace std;


int main(){
    ll n, k;
    cin >> n >> k;
    
    ll t = 0;
    rep(b, n+1){
        if(b <= k)  continue;

        ll r = n/b;
        ll d = b-k;

        t += r*d;

        t += max(0ll, (n%b)+1 - k);

        if(k == 0)  t--;
    }

    cout << t << endl;


    return 0;
}


Measured memory_bytes: 256
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,a,b,c,x;
	int y[10000];
	while(cin>>n>>a>>b>>c>>x,n){
		rep(i,n)cin>>y[i];
		int f,r=0;
		for(f=0;f<=10000;f++){
			if(x==y[r]){
				r++;
				if(r==n)break;
			}
			x=(a*x+b)%c;
		}
		cout<<(f<=10000?f:-1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

#define fst first
#define snd second

typedef long long llint;
typedef pair<int, int> pii;

const int B = 27397, MOD = 1e9 + 7;
const int B1 = 33941, MOD1 = 1e9 + 9;

const int MAXN = 1e5+10;

int n;

vector<int> v[MAXN];

int get_sum(int node, int p) {
  int ret = 0;
  for (int nxt : v[node]) {
    if (nxt == p) continue;
    ret ^= 1 + get_sum(nxt, node);
  }
  return ret;
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b); --a; --b;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  if (get_sum(0, -1) == 0)
    printf("Bob\n");
  else
    printf("Alice\n");
  return 0;
}



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

using namespace std;

const int MAXN = 2200;
int a[MAXN], n;
int dp[MAXN][2];
int go(int pos, int turn){
	int lst = pos - 1;
	if(dp[pos][turn] != -1) return dp[pos][turn];
	int ans = turn == 0 ? -1e9 : 1e9;
	for(int i = pos; i < n + 1; i++){
		int val = go(i+1, 1 - turn);
		if(!turn) ans = max(ans, val);
		else ans = min(ans, val);
	}
	
	if(!turn) ans = max(ans, abs(a[n+1] - a[lst]));
	else ans = min(ans, abs(a[n+1] - a[lst]));
	return dp[pos][turn] = ans;
}

int main(){
	cin >> n >> a[0] >> a[1];
	for(int i = 0; i < n; i++) cin >> a[i+2];
	for(int i = 0; i < MAXN; i++) dp[i][0] = dp[i][1] = -1;
	cout<<go(2,0)<<endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=305;

int n,m;
int a[N][N],aa[N][N],pos[N][N],idx[N];
int cnt[N];

int check(int x) {
    memset(cnt,0,sizeof(cnt));
    for (int i=0;i<n;i++) {
        cnt[a[i][idx[i]]]++;
    }
    int mx=0,num=0;
    for (int i=1;i<=m;i++) {
        if (cnt[i]>mx) {
            mx=cnt[i];
            num=i;
        }
    }
    if (mx>x) return -num;
    else return num;
}

bool ok(int x) {
    memset(idx,0,sizeof(idx));
    for (int i=0;i<n;i++) {
        for (int j=0;j<m;j++) {
            aa[i][j]=a[i][j];
        }
    }
    for (int i=0;i<m-1;i++) {
        int res=check(x);
        if (res>0) return true;
        for (int j=0;j<n;j++) {
            aa[j][pos[-res][j]]=0;
        }
        for (int j=0;j<n;j++) {
            while (aa[j][idx[j]]==0&&idx[j]<m) idx[j]++; 
        }
    }
    return false;
}

int main() {
    scanf("%d%d",&n,&m);
    for (int i=0;i<n;i++) {
        for (int j=0;j<m;j++) {
            scanf("%d",&a[i][j]);
            pos[a[i][j]][i]=j;
        }
    }
    int lo=1,hi=n;
    while (lo<hi) {
        int mid=(lo+hi)>>1;
        if (!ok(mid)) lo=mid+1;
        else hi=mid;
    }
    printf("%d\n",lo);
}


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

using namespace std;

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

  int max_cnt = -1;
  int cur_cnt = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      cur_cnt++;
    } else {
      cur_cnt = 0;
    }

    max_cnt = max(cur_cnt, max_cnt);
  }

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


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

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

# define int(x) int x; scanf("%d",&x);
# define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
# define string(x) string x; cin >> x;

using namespace std;

namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    REP (i, mat.size()) {
      REP (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    REP (i, v.size())
      if (i >= v.size()-1)
	cout << v[i];
      else
	cout << v[i] << ' ';
    
    cout << endl;
  }

  template <typename T> pair<T, T> shape(vector<vector<T>> mat) {
    int d1, d2;

    d1 = mat.size();
    if (d1 > 0) d2 = mat[0].size();
    else int d2 = 0;
    cout << "(" << d1 << ", " << d2 << ")" << endl;
    return make_pair(0, 0);
  }

  template <typename T> vector<vector<T>> empty(int n, int m) {
    vector<vector<T>> mat(n, vector<T>(m));
    return mat;
  }
}
#define MOD 1000000007
long long fact(long long k){
  long long sum = 1;
  for (long long i = 1; i <=k;i++){
    sum *=i;
    sum = sum % MOD;
  }
  return (sum);
}

int main() {
  vint(A,2);

  if(abs(A[0]-A[1])<=1){
    long long ans = 1;
    for(int i=1;i<=A[0];i++) ans = (ans * i) % MOD;
    for(int i=1;i<=A[1];i++) ans = (ans * i) % MOD;
    if(A[0] == A[1])
      ans = (ans*2)%MOD;
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }

}


Measured memory_bytes: 256
fun main(args: Array<String>?): Unit {
    while(true) {
        val n = (readLine() ?: return).toInt()
        val times = readLine()!!.trim().split(' ').map(String::toLong).sorted().toLongArray()
        for (i in 1 until n) {
            times[i] += times[i - 1]
        }
        println(times.sum())
    }
}


Measured memory_bytes: 33224
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
ll A, B, X;
ll f(ll num) {
	if (num<0) {
		return 0;
	}
	else {
		return num / X+1;
	}
	
}
int main() {
	
	cin >> A >> B >> X;
	cout << (f(B)-f(A-1))<< endl;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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 gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vi a(n);
  rep(i, n){
    cin >> a[i];
    a[i] -= i+1;
  }

  sort(all(a));
  int m = a[n/2];
  ll ans = 0LL;
  rep(i, n) ans += abs(a[i]-m);

  std::cout << ans << '\n';
}


Measured memory_bytes: 1024
#include <atcoder/scc>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  scc_graph g(n);
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    g.add_edge(a, b);
  }
  vector<vector<int> > s = g.scc();
  cout << s.size() << "\n";
  for (int i = 0; i < s.size(); i++)
  {
    cout << s[i].size() << " ";
    for (int j = 0; j < s[i].size(); j++)
    {
      cout << s[i][j] << " ";
    }
    cout << "\n";
  }
}


Measured memory_bytes: 40620
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
llint solve(llint n,int ga,int sa,int ba,int gb,int sb,int bb){
	//効率を考える
	if(ga>=gb){ga=1;gb=1;}
	if(sa>=sb){sa=1;sb=1;}
	if(ba>=bb){ba=1;bb=1;}
	if(gb*sa<sb*ga){swap(ga,sa);swap(gb,sb);}
	if(sb*ba<bb*sa){swap(sa,ba);swap(sb,bb);}
	if(gb*sa<sb*ga){swap(ga,sa);swap(gb,sb);}
	//gaが最高効率
	llint ans=n;
	llint Mi=min(lcm(sa,ba),lcm(ga,ba))/ba;
	llint Mj=lcm(ga,sa)/sa;
	for(llint i=0;i<Mi;i++){
		//Bシリーズ
		for(llint j=0;j<Mj;j++){
			//Sシリーズ
			llint don=n-(i*ba+j*sa);
			if(don<0){break;}
			chmax(ans,don/ga*gb+don%ga+i*bb+j*sb);
		}
	}
	return ans;
}
int main(void){
	llint n;cin>>n;
	int ga,sa,ba,gb,sb,bb;cin>>ga>>sa>>ba>>gb>>sb>>bb;
	n=solve(n,ga,sa,ba,gb,sb,bb);
	n=solve(n,gb,sb,bb,ga,sa,ba);
	cout<<n<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;   
int main()
{
	int a,b,c,k,mx,sum=0;
	cin>>a>>b>>c>>k;
	sum=a+b+c-max(a,max(b,c));
	mx=a+b+c-sum;
	for (int i=1;i<=k;i++) mx*=2;
	cout<<sum+mx;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string.h>
#include <set>
#include <math.h>
#include <numeric>
#include <assert.h>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <queue>
#include <random>
#include <chrono>
#include <limits.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define endl "\n"
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> OST;
typedef tree<pair<int, int>, null_type, less_equal<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> OST_multiset;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const ll inf = 1e9 + 69;
const ld pi = 3.14159265358979323L;
const ld eps = 1e-15;

void setIn(string s){freopen(s.c_str(), "r", stdin);}
void setOut(string s){freopen(s.c_str(), "w", stdout);}
void unsyncIO(){cin.tie(0) -> sync_with_stdio(0);}
int setIO_count = 0;
void setIO(string s = ""){
	if(!setIO_count){
		unsyncIO();
		setIO_count = 1;
	}
	if(s.size()){ //output only
		setIn(s + ".in");
		setOut(s + ".out");
	}
}

#define gc getchar//_unlocked //can't for window server
#define pc putchar//_unlocked //can't for window server
ll inp(){
	char c = gc(); bool neg = false;
	for(; c < '0'||'9' < c; c = gc())
		if(c == '-') neg=true;
	ll rs = c - '0'; c = gc();
	for(; '0' <= c && c <= '9'; c = gc())
		rs = (rs << 1) + (rs << 3) + (c - '0');
	if(neg) rs = -rs;
	return rs;
}
void pri(ll _n){
	ll N = _n, rev, count = 0;
	bool neg = false;
	if(N < 0){
		N = -N; neg = true;
	}
	rev = N;
	if(N == 0) {pc('0'); return;}
	if(neg) pc('-');
	while(rev % 10 == 0) {count ++; rev /= 10;}
	rev = 0;
	while(N != 0) {rev = (rev << 3) + (rev << 1) + N % 10; N /= 10;}
	while(rev != 0) {pc(rev % 10 + '0'); rev /= 10;}
	while(count --) pc('0');
}

const ll mod = 998244353;
const int N = 2 * 100 * 1000 + 5;

ll st[N * 4];

void upd(int nd, int cl, int cr, int ps, ll v){
	if(ps < cl || cr < ps) return;
	if(cl == cr && cl == ps){
		st[nd] = v; return;
	}

	upd(nd * 2, cl, (cl + cr) / 2, ps, v);
	upd(nd * 2 + 1, (cl + cr) / 2 + 1, cr, ps, v);
	st[nd] = (st[nd * 2] + st[nd * 2 + 1]) % mod;
}

ll que(int nd, int cl, int cr, int l, int r){
	if(cr < l || r < cl) return 0ll;
	if(l <= cl && cr <= r) return st[nd];
	return que(nd * 2, cl, (cl + cr) / 2, l, r) + que(nd * 2 + 1, (cl + cr) / 2 + 1, cr, l, r);
}

int main(){
	setIO("");

	int n, k; cin >> n >> k;
	vector<pair<int, int> > v(k);
	for(int i = 0; i < k; i ++) cin >> v[i].first >> v[i].second;

	upd(1, 1, n, 1, 1);

	for(int i = 2; i <= n; i ++){
		ll gt = 0ll;
		for(int j = 0; j < k; j ++){
			int lf = max(1, i - v[j].second), rg = max(1, i - v[j].first);
			if(i - v[j].first < 1) continue;
			gt += que(1, 1, n, lf, rg);
		}
		gt %= mod;
		upd(1, 1, n, i, gt);
	//	return 0;
	}
	
	cout << que(1, 1, n, n, n) << endl;

	return 0;
}

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


int cnt[100001];


int main(){
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
    }

    bool ok = true;
    for(int i = 1; i <= N; i++){
        if(cnt[i] % 2 != 0){
            ok = false;
        }
    }
    if(ok){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long



using namespace std;

int main(){
    ll N;
    cin >> N;
    ll A[N],B[N],C[N];
    for(int i=1;i<=N;i++){
        cin >> A[i];
    }
    for(int i=1;i<=N;i++){
        cin >> B[i];
    }
    for(int i=1;i<=N-1;i++){
        cin >> C[i];
    }
    ll ans=0;
    ans += B[A[1]];
    for(int i=2;i<=N;i++){
        ans += B[A[i]];
        if(A[i-1]+1==A[i]){
            ans += C[A[i-1]];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
using vi = vector<int>;
using vll = vector<ll>;
const ll INF = 1LL<<60;

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

  vector<pll> d(n);
  rep(i,n){
    ll a,b; cin >> a >> b;
    d[i] = pll(a,b);
  }
  sort(d.begin(), d.end());

  ll ans = 0;
  for(int i = 0; i < n; i++){
    ll a = d[i].first;
    ll b = d[i].second;
    if(b < m){
      ans += a * b;
      m -= b;
    }else{
      ans += a * m;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    
    char c;
    cin >> c;
    c++;
    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int Map[52][52];
bool used[52][52];
const int dir[][2] = { {-1, 0 }, { -1, 1 }, { 0, 1 }, { 1, 1 }, { 1, 0 }, { 1, -1 }, {0, -1 }, {-1, -1 } };
int w, h;

void dfs (int row, int col )
{
	used[row][col] = true;
	rep (k, 8 ){
		int nr = row + dir[k][0];
		int nc = col + dir[k][1];
		if (nr < 0 || nc < 0 || nr >= h || nc >= w || Map[nr][nc] == 0 || used[nr][nc] ) continue;
		dfs (nr, nc );
	} // end rep
}

int main()
{
	while (scanf ("%d %d", &w, &h ) && w && h ){
		memset (used, false, sizeof (used ) );
		rep (i, h ){
			rep (j, w ){
				scanf (" %d", Map[i]+j );
			} // end rep
		} // end rep
		int cnt = 0;
		rep (i, h ){
			rep (j, w ){
				if (Map[i][j] == 1 && !used[i][j] ){
					dfs (i, j );
					cnt++;
				} // end if
			} // end rep
		} // end rep
		printf ("%d\n", cnt );
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(){
  int A,B,C,D,P,X,Y,i;
  scanf("%d%d%d%d%d",&A,&B,&C,&D,&P);
  X = A * P;
  if(0 <= P && P <= C){
    Y = B;
  }else if(C < P){
    i = P - C;
    Y = B + (i * D);
  }else{
    return 1;
  }

  if(X <= Y){
    printf("%d\n",X);
  }else{
    printf("%d\n",Y);
  }
  return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    int minn = n;
    rep(sixN, n+1){
        int cnt = 0;
        int t = sixN;
        while(0<t) cnt += t%6, t /= 6;
        t = n - sixN;
        while(0<t) cnt += t%9, t /= 9;
        minn = min(minn, cnt);
    }
    cout << minn << endl;

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int count = 1;
    bool ok=false;
    rep(i,n){
        if(a.at(i)==count){
            count ++;
            ok = true;
        }
    }
    if(ok){
        cout << n - count + 1 << endl;
    }
    else{
        cout << -1 << endl;
    }


}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAXN = 5000001;
const int mod=1000000007;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--)
    {
      string s,t;
      cin>>s>>t;

      int n=s.length();
      int m=t.length();
      int mn=1e7;
      for(int i=0;i<=n-m;i++)
      {
          int cnt=0;
          for(int j=0;j<m;j++)
          {
              if(s[i+j]!=t[j])cnt++;
          }
          mn=min(mn,cnt);
      }
  cout<<mn<<endl;

    }
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
vector<int> v[N];
int h[N];
int a[N];
int main(){
    fast;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        h[x]++;
        a[i] = x;
        if(!v[x].empty()) continue;
        for(int i = 1; i * i <= x; i++){
            if(x % i == 0){
                v[x].push_back(i);
                if(x / i != i) v[x].push_back(x / i);
            }
        }
        
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        h[a[i]]--;
        int fl = 1;
        for(auto j: v[a[i]]){
            if(h[j]) fl = 0;
        }
        ans += fl;
        h[a[i]]++;
    }
    cout << ans;
}

Measured memory_bytes: 46672
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
    int N[3], K;
    cin >> N[0] >> N[1] >> N[2] >> K;
    sort(N, N+3);
    cout << N[0] + N[1] + N[2] * pow(2, K) << endl;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

int a, b, c;

int read() {
  if (scanf("%d%d%d", &a, &b, &c) < 3) {
    return false;
  }
  return true;
}

void solve() {
  int res = 0;
  while (true) {
    if ((a & 1) || (b & 1) || (c & 1)) {
      break;
    }
    if (a == b && b == c) {
      res = -1;
      break;
    }
    int na = (b + c) / 2, nb = (a + c) / 2, nc = (a + b) / 2;
    a = na;
    b = nb;
    c = nc;
    res++;
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main()
{
    ll n, t, i =0, m ;
    string s ;
    cin >> s ;
    n = s.size()-1;
    ll sum = 0, tmp = 0 ;
    ll subset= pow(2,n);
    for(i=0; i<(1<<n); i++) // like a binary form of n and i ak akta r binary number r representative 
    {
        tmp = 0;
        for(ll j=0 ; j<n ; j++)
        {
            tmp = tmp*10 + s[j] - '0' ;
            if( i & (1<<j) )
            {
                sum+=tmp;
                tmp = 0 ;
            }
        }
        sum+=(tmp*10) + s[n]-'0';
    }
    cout << sum ;
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    int x; cin >> x;
    if(x == 7 || x == 5 || x == 3) cout << "YES" << endl;
    else cout << "NO" << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[4];
  REP(i,4){
    a[i] = n%10;
    n /= 10;
  }
  
  if((a[0]==a[1] && a[1]==a[2]) || (a[1]==a[2] && a[2]==a[3])){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

void solve(void){

  long long int N;
  cin >> N;
  
  int i=0;int A[N];
  for(i=0;i<N;i++){
  cin >>A[i];
  }
	
  for(i=0;i<N;i++){
  if(A[i]%2==0){
  if(A[i]%3!=0&&A[i]%5!=0){
  cout << "DENIED" <<endl;
    return;
  }
  }
  }
  
  cout << "APPROVED" <<endl;
  
return;
}

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

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = input()

head = int(s[:2])
tail = int(s[2:])

mmyy = 1 <= head <= 12
yymm = 1 <= tail <= 12

if mmyy and yymm:
    print('AMBIGUOUS')
elif mmyy:
    print('MMYY')
elif yymm:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int n;cin>>n;
  int cnt=0;
  rep(i,n){
    int x;cin>>x;
    if(x!=i+1)cnt++;
  }
  if(cnt<=2)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
//#include <set>

int n, m; //??????, ???

int main() {
    while(std::cin >> n >> m, n + m) {
        std::string str(n, '#');

        char q;
        for(int a = 0; a < m; ++a) {
            std::cin >> q;

            bool ok;
            switch(q) {
            case 'A':
                str[str.find("#")] = 'A';
                break;
            case 'B':
                ok = false;
                for(int i = n - 1; i >= 0; --i) {
                    if((i == 0 || str[i - 1] != 'A') && (i == n - 1 || str[i + 1] != 'A') && str[i] == '#') {
                        ok = true;
                        str[i] = 'B';
                        break;
                    }
                }
                if(!ok) {
                    str[str.find("#")] = 'B';
                }
                break;
            case 'C':
                ok = false;
                for(int i = 0; i < n; ++i) {
                    if(str[i] != '#') {
                        if(i != n - 1 && str[i + 1] == '#') {
                            str[i + 1] = 'C';
                            ok = true; break;
                        }
                        if(i != 0 && str[i - 1] == '#') {
                            str[i - 1] = 'C';
                            ok = true; break;
                        }
                    }
                }

                if(!ok) {
                    str[n / 2] = 'C';
                }
                break;
            case 'D':
                int dist[101];
                for(int i = 0; i < n; ++i) {
                    int d = 1e+9;
                    if(str[i] == '#') {
                        for(int j = 0; j < n; ++j) {
                            if(str[j] != '#') {
                                d = std::min(d, std::abs(i - j));
                            }
                        }
                    }else {
                        d = 0;
                    }
                    
                    dist[i] = d;
                }

                int maxIdx = 0;
                for(int i = 1; i < n; ++i) {
                    if(dist[i] > dist[maxIdx]) {
                        maxIdx = i;
                    }
                }

                str[maxIdx] = 'D';

                break;
            }
//            std::cout << str << std::endl;
        }

        std::cout << str << std::endl;
    }
}

Measured memory_bytes: 1204
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
using namespace std;
typedef long long ll;

class Edge
{
	public:
	int color;
	int ind;
	int from;
	int to;

	Edge(int n,int c,int i)
	{
		to=n;
		color=c;
		ind=i;
	}

	Edge(int f,int t,int c,int i)
	{
		from=f;
		to=t;
		color=c;
		ind=i;
	}
};

vector<Edge> g[100000];
int ans[100000];
bool used[100000];
int k;
void dfs(int now,int nc)
{
	int cnt=0;
	used[now]=true;
	for(int i=0;i<g[now].size();i++)
	{
		Edge e=g[now][i];
		if(!used[e.to])
		{
			if(cnt==nc)
				cnt++;
			ans[e.ind]=cnt;
			dfs(e.to,cnt);
			cnt++;
		}
	}
	return;
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(Edge(b,-1,i));
		g[b].push_back(Edge(a,-1,i));
	}
	int root=0;
	for(int i=0;i<n;i++)
	{
		if(g[root].size()<g[i].size())
			root=i;
	}
	k=g[root].size();
	cout<<g[root].size()<<endl;
	dfs(root,-1);
	for(int i=0;i<n-1;i++)
		cout<<ans[i]+1<<endl;
	return 0;
}

Measured memory_bytes: 9728
def cost(x,y):
    return (x-y)**2

def resolve():
    N=int(input())
    X=[int(i) for i in input().split()]
    mns=10**9
    for i in range(100):
        mns=min(mns,sum([cost(i,j) for j in X]))
    print(mns)






if __name__ == "__main__":
    resolve()

Measured memory_bytes: 39024
import math

n = int(input())
if n == 1:
    print(0)
    exit(0)
max = int(math.sqrt(n) + 0.1)
ans = 0
for i in range(2, max):
    count = 0
    while n % i == 0:
        count += 1
        n = n // i
    if count > 0:
        for j in range(1, 64):
            if count >= j:
                ans += 1
            else:
                break
            count -= j
    if n == 1:
        print(ans)
        exit(0)
print(ans + 1)

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

int main() {
  string S;cin>>S;
  cout << S.substr(0,5) << " " << S.substr(6,7) << " " << S.substr(14) << endl;
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------


int main(){
    int n=IN_int();
    int d=IN_int();
    int ans=(n+d*2)/(2*d+1);
    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a,b=[],[]
for _ in range(n):
    i,j=map(int,input().split())
    a+=[i]
    b+=[j]
a.sort()
b.sort()
c=n//2
if n%2==1:
    print(b[c]-a[c]+1)
else:
    print(b[c]-a[c]+b[c-1]-a[c-1]+1)

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

using namespace std;

int n, k, x, cx, i, Max, A;

int cmmdc(int a, int b) {
    int r = 0;
    while (b) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main ()
{
   // freopen("in", "r", stdin);
//freopen("out", "w", stdout);

    scanf("%d %d\n", &n, &k);
    Max = 0;
    for (i = 1; i <= n; ++i) {
        scanf("%d ", &x);
        Max = max(Max, x);
        if (i == 1) { A = x; continue; }
        A = cmmdc(A, x);
    }

    if (k <= Max && k % A == 0 && k >= A) printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
double ans = 0,ans2=0;


void comb(vector<vector<long long int>> &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int k = 1; k < v.size(); k++)
    {
        for (int j = 1; j < k; j++)
        {
            v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
        }
    }
}

int main()
{
ll n,a,b;
cin >> n>>a>>b;
ll v[n] = {};
rep(i, n)
{
    cin >> v[i];
}
sort(v, v+n);
rep(i,a){
    ans+=v[n-1-i];
}
ans/=a;


vector<vector<long long int> > vv(n+1,vector<long long int>(n+1,0));
comb(vv);
ll re=v[n-a];
auto itr1 = lower_bound(v,v+n, re);
auto itr2 = upper_bound(v,v+n, re);
ll aaa=itr2-itr1;
if(v[n-a]==v[n-1]){
    for(ll i=a;i<min(b+1,aaa+1);i++){
        ans2+=vv[itr2-itr1][i];
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
    cout <<fixed<<setprecision(0)<< ans2 << endl;
    return 0;
}



ll te=v+n-itr2;
//cout << a-te<<" "<<itr2-itr1 << endl;
ans2=vv[itr2-itr1][a-te];

cout<<fixed<<setprecision(10)<<ans<<endl;
cout <<fixed<<setprecision(0)<< ans2 << endl;
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();
        int S = scanner.nextInt();
        scanner.close();
        int combination = 0;
        int k;

        for(int i=0;i<=K;i++) {
            for(int j=0;j<=K;j++) {
                k = S-i-j;
                if(i+j+k==S && i>=0 && j>=0 && k>=0 && k <= K) {
                    combination++;
                }
            }
        }
        System.out.println(combination);
    }
}

Measured memory_bytes: 23252
#include<stdio.h>
int main(int argc, char* argv[])
{
  int a, b;
  scanf("%d %d", &a, &b);
  while((a != 0)||(b != 0)){
    if(a <= b){
      printf("%d %d\n", a, b);
    }else{
      printf("%d %d\n", b, a);
    }
    scanf("%d %d\n", &a, &b);
  }
  return(0);
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
  int r, d, x;
  cin >> r >> d >> x;
  for (int i = 0; i < 10; ++i) {
    x = r * x - d;
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int ss;
    
    scanf("%d",&ss);
    
    int h = ss / 60 / 60;

    ss -= h * 60 * 60;
    int m = ss / 60;

    int s = ss % 60;

    printf("%d:%d:%d\n",h,m,s);
    return 0;
}

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

typedef struct{
  string n;
  int t;
  int e;
} process;

int main() {
  int n,q;
  cin >> n >> q;
  process p[n];
  queue<process> r;
  for(int i=0;i<n;++i){
    cin >> p[i].n >> p[i].t;
    r.push(p[i]);
  }

  process tmp;
  int ct=0;
  queue<process> f;
  while(!r.empty()){
    tmp = r.front();
    r.pop();
    if(tmp.t>q){
      tmp.t-=q;
      ct+=q;
      r.push(tmp);
    }
    else{
      ct+=tmp.t;
      tmp.e=ct;
      f.push(tmp);
    }
  }
  
  while(n-->0){
    tmp=f.front();
    cout << tmp.n << " " << tmp.e << endl;
    f.pop();
  }

}

Measured memory_bytes: 5228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll N, T;
    cin >> N >> T;
    ll t[N];
    for(int i = 0; i < N; i++) cin >> t[i];

    ll ans = T;
    for(int i = 1; i < N; i++) {
        ans -= max(0LL, T - (t[i] - t[i - 1]));
        ans += T;
    }
    cout << ans << "\n";
    return 0;
}

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

int main () {
  ll X, Y;
  cin >> X >> Y;
  int ans = 0;
  
  while (X <= Y) {
    X *= 2;
    ans++;
  }
  
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
int main() {
  int64_t n;
  cin>>n;
  vector<int64_t> h(n);
  for(int i=0;i<n;i++){
    cin>>h.at(i);
  }
  int64_t count=0;
   priority_queue<int64_t> z;
  for(int i=0;i<n-1;i++){
    if(h.at(i)>=h.at(i+1)){
      count++;
    }
    else{
      z.push(count);
      count=0;
    }
  }
  z.push(count);
  cout<<z.top();
}

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

struct Node{
  ll key;
  Node *p;
  Node *left;
  Node *right;
  Node(ll k){
    key = k;
    p = left = right = NULL;
  }
};


void inorder(Node* n){
  if(n == NULL){
    return;
  }
  inorder(n->left);
  cout << " " << n->key;
  inorder(n->right);
  return;
}

void preorder(Node* n){
  if(n == NULL){
    return;
  }
  cout << " " << n->key;
  preorder(n->left);
  preorder(n->right);
  return;
}

void insert(Node* &T, Node* z){
  Node* y = NULL;
  Node* x = T;
  while(x != NULL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->p = y;

  if(y == NULL){
    T = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

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

  int m;
  Node* T = NULL;
  cin >> m;
  while(m--){
    string str; cin >> str;
    if(str == "print"){
      inorder(T);
      cout << endl;
      preorder(T);
      cout << endl;
    }else{
      ll k; cin >> k;
      Node* kn = new Node(k);
      insert(T, kn);
      /*
      if(kn->p != NULL) cout << kn->p->key << endl;
      else if(kn->left != NULL) cout << "LEFT " << kn->left->key << endl;
      else if(kn->right != NULL) cout << "RIGHT " << kn->right->key << endl;
      */
    }
  }

  return 0;
}

Measured memory_bytes: 24668
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (!isdigit(ch)){if (ch=='-')fh=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x=x*fh;
}
int n,q,k;
char ch[1000010];
int main(){
	read(n);
	for (int i=1;i<=n;i++){ch[i]=getchar();while (ch[i]<'A'||ch[i]>'Z')ch[i]=getchar();}
	read(q);
	while (q--){
		read(k);
		int nb=0,na=0;ll ans=0,nab=0;
		for (int i=1;i<=n;i++){
			if (i>k){
				if (ch[i-k]=='D'){na--;nab-=nb;}
				if (ch[i-k]=='M'){nb--;}
			}
			if (ch[i]=='D')na++;
			if (ch[i]=='M'){nab+=na;nb++;}
			if (ch[i]=='C')ans+=nab;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
import sys
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,m=mis()
    lis=[0]*(n+1)
    ww=[0]*(n+1)
    wa=0
    for _ in range(m):
        P,s=input().split()
        p=int(P)
        if lis[p]==0:
            if s=='WA': ww[p]+=1
            else:
                lis[p]+=1
                wa+=ww[p]
    print(sum(lis),wa)


if __name__ == "__main__":
    main()

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Repi(i, a, b) for(int i = int(a); i < (int)(b); i++)
#define Repl(i, list) for(int i : list)
#define Sort(v) sort(v.begin(), v.end())
template<typename _T> void Out(_T x) { cout << x << endl; }
template<typename _T> void PrintVec(vector<_T> vec) { Rep(i, vec.size()) { cout << vec.at(i) << " "; } cout << endl; }

int main()
{
    // input
    int A;
    cin >> A;
    int B;
    cin >> B;

    // output
    if (A == 1 && B == 2) {
        Out(3);
    } else if (A == 1 && B == 3) {
        Out(2);
    } else if (A == 2 && B == 3) {
        Out(1);
    } else if (A == 2 && B == 1) {
        Out(3);
    } else if (A == 3 && B == 1) {
        Out(2);
    } else if (A == 3 && B == 2) {
        Out(1);
    }

    return 0;
}

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
ps = [[] for _ in range(n)]

for i in range(m):
    p, y = list(map(int, input().split()))
    ps[p-1].append((y, i))

for i in range(n):
    ps[i] = sorted(ps[i])

    pstr = str(i+1).zfill(6)

    for j in range(len(ps[i])):
        ps[i][j] = (pstr + str(j+1).zfill(6), ps[i][j][1])

ps = [city for sub in ps for city in sub]
ps = sorted(ps, key = lambda x: x[1])

for city in ps:
    print(city[0])

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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9+100;

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

  int N; cin >> N;
  using MA = pair<PII,int>;
  vector<MA> xs(N*2);
  REP(i,N){
	cin >> xs[i].FF;
	xs[N+i] = MP(MP(xs[i].FF.SS, xs[i].FF.FF), 1);
  }
  sort(ALL(xs), [](const MA& l, const MA& r){
	  return
		l.FF.FF != r.FF.FF ?
		l.FF.FF < r.FF.FF :
		l.FF.SS > r.FF.SS;
	});

  VI dp(N*2, INF);
  REP(i,N*2){
	int ix = lower_bound(ALL(dp), xs[i].FF.SS) - begin(dp);
	if(xs[i].SS != ix%2){
	  if(ix == 0)
		continue;
	  --ix;
	}
	mini(dp[ix], xs[i].FF.SS);
  }

  cout << (lower_bound(ALL(dp), INF) - begin(dp)) << endl;

  return 0;
}

Measured memory_bytes: 5980
table = {"61"=>"z", "62"=>".", "63"=>"?", "64"=>"!", "65"=>" "}
25.times {|i| table["#{i / 5 + 1}#{i % 5 + 1}"] = (97 + i).chr}

$<.readlines.map(&:chomp).each do |cipher|
  catch :jump do
    text = ""
    i = 0
    while i < cipher.size
      a = table[cipher[i, 2]]
      unless a
        puts "NA"
        throw :jump
      end
      text += a
      i += 2
    end
    puts text
  end
end


Measured memory_bytes: 6868
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){
 int n,m;
  cin>>n>>m;
 	vector<int> A(n);
	  rep(i,n) cin>>A[i];
  int all=0;
  for(int i=0;i<n;i++){
    all+=A[i] ;
  }
  int ans=0;
  for(int i=0;i<n;i++){
if(A[i]*4*m >=all){
  ans++;
}
  }
  if(ans>=m){
cout<<"Yes"<<endl;
  }
else if(ans<m){
  cout<<"No"<<endl;
}
return 0;
}


Measured memory_bytes: 256
import * as fs from "fs";

const input = fs.readFileSync("/dev/stdin", "utf8").split("\n");

let s: string;
let t: string;

s = input[0];
t = input[1];

var ans = 100000;
for (let i = 0; i <= s.length - t.length; i++) {
    var count = 0;
    for (let j = i; j < i + t.length; j++) {
        if (s[j] != t[j - i]) count++;
    }
    if (count < ans) ans = count;
}
console.log(ans);


Measured memory_bytes: 32232