akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

string replace_string(string S,string Q,string R){
	string::size_type pos(S.find(Q));

	while(pos!=string::npos){
		S.replace(pos,Q.length(),R);
		pos = S.find(Q,pos+R.length());
	}

	return S;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	string S=in<string>();
	S = replace_string(S,"BC","X");

	int N=S.size();
	ll AN=0;
	ll V=0;
	REP(i,N){
		if(S[i]=='A'){
			AN++;
		}
		else if(S[i]=='X'){
			V += AN;
		}
		else AN=0;
	}
	out(V);
	return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

	int N; cin >> N;
	vector<int> b(N);
	REP(i,N) cin >> b[i];
	vector<int> ans;

	REP(i,N){
		int idx = -1;
		REP(j,b.size()){
			if(j+1 == b[j]) idx = j;
		}
		if(idx == -1){
			cout << -1 << endl;
			return 0;
		}else{
			b.erase(b.begin() + idx);
			ans.insert(ans.begin(), idx+1);
		}
	}

	REP(i,ans.size()){
		cout << ans[i] << 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() {
    cin.tie(0)->sync_with_stdio(false);

    int n; cin >> n;

    multiset<int> d;
    REP(i, n) {
        int tmp; cin >> tmp;
        d.insert(tmp);
    }

    int m; cin >> m;

    multiset<int> t;
    REP(i, m) {
        int tmp; cin >> tmp;
        t.insert(tmp);
    }

    multiset<int> res;
    set_intersection(d.begin(), d.end(),
            t.begin(), t.end(),
            inserter(res, res.end()));

    if (t == res) cout << "YES" << '\n';
    else cout << "NO" << '\n';
    return 0;
}

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

int main()
{
	int t[100005]={},u[100005]={},l=0,r=0;
	string s;
	cin>>s;
	for(int i=0;i<s.length()-1;i++)
	{
		if(s.substr(i,2)=="RL")
		{
			r++;
			t[i]+=r/2+r%2;
			t[i+1]+=r/2;
			r=0;
		}
		else if(s[i]=='R')r++;
	}
	reverse(s.begin(),s.end());
	for(int i=0;i<s.length()-1;i++)
	{
		if(s.substr(i,2)=="LR")
		{
			l++;
			u[i]+=l/2+l%2;
			u[i+1]+=l/2;
			l=0;
		}
		else if(s[i]=='L')l++;
	}
	for(int i=0;i<s.length();i++)
	{
		t[i]+=u[s.length()-1-i];
		if(i)cout<<" "<<t[i];
		else cout<<t[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1408
import itertools

N, M, X = map(int, input().split())

C = []
A = []
for i in range(N):
    tmp = list(map(int, input().split()))
    C.append(tmp[0])
    A.append(tmp[1:])

C_total_min = -1
for ci in range(1, N+1):  # 組み合わせの数
    for seq in itertools.combinations(range(N), ci): # 組み合わせのリスト
        C_total = 0
        A_total = [0] * M
        for ni in seq:
            C_total += C[ni]
            A_total = [A_total[ai] + A[ni][ai] for ai in range(M)]

        # 判定
        flag = True
        for ai in range(M):
            if A_total[ai] < X:
                flag = False
        if flag: # Trueなら
            if C_total_min == -1:
                C_total_min = C_total
            elif C_total_min > C_total:
                C_total_min = C_total
            else:
                pass

print(C_total_min)

Measured memory_bytes: 9080
#include<iostream>

using namespace std;

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

	if (D == 25) {
		cout << "Christmas" << endl;
	}
	else if (D == 24) {
		cout << "Christmas Eve" << endl;
	}
	else if (D == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else if (D == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}

}

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

int main() {
  string s;
  cin >> s;
  bool flag=false;
  for (int i=0;i<s.size();i++) {
    for (int j=0;j<s.size()-i;j++) {
      string tmp=s;
      tmp.replace(i,j,"");
      if(tmp=="keyence") {
        flag=true;
        break;
      }
    }
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main() {
  
  int64_t N, M; cin >> N >> M;
  
  string S, T; cin >> S >> T;
  
  int64_t L = N / __gcd(N, M) * M;
  
  map<int64_t, char> memo;
  
  for (int i = 0; i < N; i++) {
    
    int64_t key = i * (L / N) + 1;
    
    memo[key] = S.at(i);
    
  }
  
  for (int i = 0; i < M; i++) {
    
    int64_t key = i * (L / M) + 1;
    
    if (memo.count(key)) {
      
      if (memo.at(key) != T.at(i)) { cout << -1 << endl; return 0; }
      
    }
    
  }
  
  cout << L << endl;
  
}

Measured memory_bytes: 9396
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;

struct UnionFind {
	vector<int> par;
	vector<ll> sizes;
	UnionFind(int n ):par(n), sizes(n){
		
		for (int i = 0; i < n;i++) {
			par[i] = i;
			sizes[i] = 1;
		}
		
	}

	int find(int x) {
		if (x == par[x]) {
			return x;
		}
		par[x] = find(par[x]);

		return par[x];
	}

	void unite(int x, int y) {
		int r_x = find(x);
		int r_y = find(y);

		if (r_x == r_y) {
			return;
		}

		if (sizes[r_x] < sizes[r_y]) {
			swap(r_x, r_y);
		}

		par[r_y] = r_x;
		sizes[r_x] += sizes[r_y];

	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	ll size(int x) {
		return sizes[find(x)];
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int,int>> adj(m);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		adj[i] = make_pair(a, b);
		
	}

	UnionFind uni(n);
	vector<ll> ans(m);
	ans[m - 1] = (1LL * n * (n - 1)) / 2;

	for (int i = m - 1; i > 0; i--) {
		
		int a = adj[i].first;
		int b = adj[i].second;
		
		if (!uni.same(a, b)) {
			ans[i-1] = ans[i] - uni.size(a) * uni.size(b);
			uni.unite(a, b);
		}
		else {
			ans[i - 1] = ans[i];
		}
		
	}
	
	for (int i=0; i < m;i++) {
		cout << ans[i] << endl;
	}


}


Measured memory_bytes: 4096
#include <iostream>

void rightTriangle(int, int, int);
int main()
{
    int N;
    std::cin >> N;
    for (int i = 0; i < N; ++i) {
        int a, b, c;
        std::cin >> a >> b >> c;
        rightTriangle(a, b, c);
    }
    return 0;
}
void rightTriangle(int a, int b, int c)
{
    if (a * a + b * b == c * c
        || b * b + c * c == a * a
        || c * c + a * a == b * b) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<stdlib.h>
int main ()
{
    long long int n,k,dif;
    scanf ("%lld%lld",&n,&k);
    long long int res;
        if (n>k)
            {
            n = n%k;
            dif = k - n;
            if (n>dif)
                res = dif;
            else res = n;
            }
        else {
        dif = k-n;
        if (dif >n)
        res = n;
        else res = dif;
        }
    printf ("%lld\n",res);
    return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	static long MOD = 1000000007;
	
	static long inv(long a) {
		return eleva(a, (int)MOD - 2);
	}
	
	static long eleva(long b, int e) {
		if (e == 0) return 1;
		long ret = eleva(b, e / 2);
		ret *= ret;
		ret %= MOD;
		if (e % 2 == 1) {
			ret *= b;
			ret %= MOD;
		}
		return ret;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int N = sc.nextInt();
		long[] fact = new long[N], invFact = new long[N];
		fact[0] = invFact[0] = 1;
		for (int i = 1; i < N; i++) {
			fact[i] = (fact[i-1] * i) % MOD;
			invFact[i] = inv(fact[i]);
		}
		long ans = fact[N-1] * (N-1) % MOD;
		
		for (int k = (N + 1)/2; k < N - 1; k++) {
			long tmp = (fact[k-1] * fact[k]) % MOD;
			tmp = (tmp * invFact[2*k - N]) % MOD;
			ans -= tmp;
		}
		ans %= MOD; ans += MOD; ans %= MOD;
		System.out.println(ans);
	}
}


Measured memory_bytes: 40276
/* ex5_4
   reo012 */

#include<stdio.h>

int main(void){
    char input_s[11], *s;   //変数宣言、入力される文字列のサイズは最大で10
    int count=0, max=0;     //変数宣言
    scanf("%s", input_s);   //文字列をinput_sに入力
    s = input_s;    //入力された文字列をsに格納

    //sについてACGT部分列の最大サイズを求める。文字列の前から順に見ていき、
    //ACGTのいずれかならcountを増やしてcountの最大値をmaxに記録、それらの文字でないならcountリセット
    while(*s){
        if(*s=='A' || *s=='C' || *s=='G' || *s=='T'){   //ACGTのいずれかの文字のとき
            count++;    //countを1増やす
            if(count>max){  //countがmaxより大きいならmaxに記録
                max=count;
            }
        }else{  //ACGTのどれでもないとき、countリセット
            count=0;
        }
        s++;    //次の文字に進む
    }
    printf("%d\n", max);    //最大値maxを出力
    return 0;
}

Measured memory_bytes: 1704
N = int(input())
S = input()


def check(ans):
    for i in range(1, N - 1):
        if (ans[i] == 0) == (S[i] == 'o'):
            ans += [ans[i - 1]]
        else:
            ans += [1 - ans[i - 1]]
    if ((S[0] == 'o') == (ans[0] == 0)) != (ans[1] == ans[-1]):
        return
    if ((S[-1] == 'o') == (ans[-1] == 0)) != (ans[-2] == ans[0]):
        return
    print(*['W' if _ else 'S' for _ in ans], sep='')
    exit()


check([0, 0])
check([0, 1])
check([1, 0])
check([1, 1])
print(-1)


Measured memory_bytes: 7008
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a +1):
    for j in range(b + 1):
        for k in range(c +1):
            if 500 *i + 100 *j + 50 *k == x:
                cnt += 1

print(cnt)

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> vec(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
    int count = 0;
    for (int j = 0; j < W; j++) {
      cin >> vec.at(i).at(j);
      if (vec.at(i).at(j) == '.') {
        count++;
      }
    }
    if (count == W) {
      vec.at(i).at(0) = 'D';
    }
  }
  
  for (int i = 0; i < W; i++) {
    int count = 0;
    for (int j = 0; j < H; j++) {
      if (vec.at(j).at(i) == '.' || vec.at(j).at(i) == 'D') {
        count++;
      }
    }
    if (count == H) {
      for (int j = 0; j < H; j++) {
        if (vec.at(j).at(i) == '.') {
          vec.at(j).at(i) = 'N';
        }
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    if (vec.at(i).at(0) != 'D') {
      for (int j = 0; j < W; j++) {
        if (vec.at(i).at(j) != 'N') {
          cout << vec.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long;

ll m, n;
vector<ll>rx, ry, x, y;
const ll MOD = 1000000007;
vector<ll>mx, my;

int main(void)
{
	cin >> n >> m;
	for (ll i = 0; i < n; ++i)
	{
		ll xx; cin >> xx;
		rx.push_back(xx);
	}
	for (ll i = 1; i < n; ++i)
	{
		x.push_back(rx[i] - rx[i - 1]);
		mx.push_back((i) * (n - i));
	}
	for (ll j = 0; j < m; ++j)
	{
		ll yy; cin >> yy;
		ry.push_back(yy);
	}
	for (ll j = 1; j < m; ++j)
	{
		y.push_back(ry[j] - ry[j - 1]);
		my.push_back((j) * (m - j));
	}
	ll strip = 0;
	for (int i = 0; i < n - 1; ++i)
	{
		ll area = x[i] % MOD;
		area *= mx[i] % MOD;
		area %= MOD;
		strip += area;
		strip %= MOD;
	}
	ll ans = 0;
	for (int j = 0; j < m - 1; ++j)
	{
		ll star = strip * my[j] % MOD;
		star %= MOD;
		star *= y[j] % MOD;
		star %= MOD;
		ans += star;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5788
N, K, C = map(int,input().split())
S = list(input())

def solve(List):
    ans = []
    i = 0
    while i < N:
        if List[i] == 'o':
            ans.append(i+1)
            i += C
        i += 1
    return ans

n = solve(S)

if len(n) > K:
    pass
else:
    r = solve(S[::-1])
    r = list(map(lambda x: N+1-x, r[::-1]))
    ans = list(set(n) & set(r))
    ans.sort()
    for i in ans:
        print(i)

Measured memory_bytes: 52896
N, K = map(int, input().split())
heights = sorted([int(input()) for _ in range(N)])
ans = max(heights)
for i in range(N - K + 1):
    if abs(heights[i] - heights[i + K - 1]) < ans:
        ans = abs(heights[i] - heights[i + K - 1])
print(ans)

Measured memory_bytes: 8280
eval'N,K,*A='+`dd`.split*?,
l=f=0
42.times{|b|c=A.count{|a|a[b]==1}
l+=K[b]==0?c<<b:[(c<<b)+f-l,N-c<<b].max
f+=[c,N-c].max<<b}
p l

Measured memory_bytes: 21760
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
map<int,int> mp;
int main(){
	int n;
	cin>>n;
	while(n--){
		int x;
		cin>>x;
		if(mp[x])return puts("NO"),0;
		mp[x]=1;
	}
	puts("YES");
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;



int main() {
 int n;
  cin>>n;
  int one[n];
  int two[n];
  for(int i=0;i<n;i++){
    cin>>one[i];}
   for(int i=0;i<n;i++){
    cin>>two[i];}
  
  int max=0;
  for(int j=0;j<n;j++){
    int wa=0;
    for(int k=0;k<=j;k++){
      wa+=one[k];}
    for(int l=j;l<n;l++){
      wa+=two[l];}
    if(max<wa) max=wa;
  
}
  
  cout<<max<<"\n";
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    hlist = list(map(int, input().split()))
    tot = 0
    for i in range(N):
        if i==0:
            tot += hlist[i]
        else:
            if hlist[i]-hlist[i-1]>0:
                tot += hlist[i]-hlist[i-1]
    
    print(tot)
solve()

Measured memory_bytes: 2940
//https://atcoder.jp/contests/abc172/tasks/abc172_c
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,m,k;
    unsigned long int t=0;
    cin >> n >> m >> k;
    vector<int> a(n);
    vector<int> b(m);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<m;i++){
        cin >> b[i];
    }
    for(int i=0;i<m;i++){
        t = t + b[i];
    }
    int j = m;
    int ans = 0;
    for(int i=0;i<n+1;i++){
        while(j > 0 && t > k){
            --j;
            t -= b[j];
        }
        if(t > k){
            break;
        }
        ans = max(ans, i+j);
        if(i==n){
            break;
        }
        t += a[i];
    }
    cout << ans << endl;
}

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

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

    sort(a, a+n);

    cout << a[n-1] - a[0] << endl;
}

Measured memory_bytes: 256
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int Mod=1e9+7;
const int N=1e6+5;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
int n,m,a,b,Ans,fac[N],inv[N];
int mod(int x){return x>=Mod?x-Mod:x;}
void Prepare(){
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<N;i++)fac[i]=1ll*fac[i-1]*i%Mod;
	for(int i=2;i<N;i++)inv[i]=1ll*inv[Mod%i]*(Mod-Mod/i)%Mod;
	for(int i=2;i<N;i++)inv[i]=1ll*inv[i-1]*inv[i]%Mod;
}
int C(int n,int m){return n<m?0:1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;}
int F(int n,int m){return C(n+m-2,n-1);}
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();m=read();a=read();b=read();Prepare();
	for(int i=1;i<=n-a;i++)Ans=mod(Ans+1ll*F(i,b)*F(n-i+1,m-b)%Mod);
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 11564
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
  int n;
  double x,y;
  while(1){
    cin >> n;
    if(n == -1)break;
    x = 1;
    y = 1;
    for(int i = 2; i < n; i++){
      double ang = M_PI/2 - atan2(-y,x);
      //cout << ang/M_PI*360 <<endl;
      x += cos(ang);
      y += sin(ang);
    }
    cout << x << endl;
    cout << y << endl;
  }
}

Measured memory_bytes: 1316
#include <stdio.h>
int main(){
    int x, y, z;
    
    scanf ( "%d %d" ,&x ,&y ) ;
    
    if ( x > y ) {
        z = y;
        y = x;
        x = z;
    }
    
    while ( 1 ) {
        z = x;
        x = y % x;
        if ( x == 0 ) {
            printf("%d\n", z);
            break;
        }
        y = z;
    }
    return 0;
}


Measured memory_bytes: 2136
n = int(input())
data = list(map(int, input().split()))

# 100 90 80 70 60 200
current_assets = 1000
current_price = 0
min_price = 999
for i in range(n-1):
    if min_price > data[i]:
        min_price = data[i]

    if data[i] < data[i+1]:
        buy_counts = current_assets // min_price
        current_assets -= buy_counts * min_price

        current_assets += buy_counts * data[i+1]

        # print(data[i], data[i+1])
        # print("MIN", min_price)
        min_price = 999

print(current_assets)


Measured memory_bytes: 9016
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int ComputePrice(
  int old_film_num,
  int semi_new_film_num,
  int new_film_num,
  int num_threshold,
  int price_threshold,
  int old_film_price,
  int semi_new_film_price,
  int new_film_price){

  int total_price = old_film_num * old_film_price 
    + semi_new_film_num * semi_new_film_price
    + new_film_num * new_film_price;

  int res = total_price;

  if(num_threshold <= old_film_num + semi_new_film_num + new_film_num
     && total_price >= (old_film_num + semi_new_film_num + new_film_num) * price_threshold){
    res = (old_film_num + semi_new_film_num + new_film_num) * price_threshold;
  }
  else if(num_threshold > old_film_num + semi_new_film_num + new_film_num
	  && total_price >= num_threshold * price_threshold
  ){
    res = num_threshold * price_threshold;
  }
  else{
    //nothing to do
  }
  return res;
}

int main(){
  int old_film_price,semi_new_film_price,new_film_price;
  int num_threshold,price_threshold;
  int old_film_num,semi_new_film_num,new_film_num;
  
  while(~scanf("%d %d %d %d %d",
	       &old_film_price,&semi_new_film_price,&new_film_price,
	       &num_threshold,&price_threshold)){
    if(num_threshold == 0) break;
    scanf("%d %d %d",&old_film_num,&semi_new_film_num,&new_film_num);

    int res = old_film_num * old_film_price
      + semi_new_film_num * semi_new_film_price
      + new_film_num * new_film_price;

    for(int i=0;i<=old_film_num + semi_new_film_num;i++){
      int b = min(semi_new_film_num,i);
      int a = i - b;
      //      printf("a:%d b:%d\n",a,b);
      int p1 = (old_film_num - a) * old_film_price 
	+ (semi_new_film_num - b) * semi_new_film_price;

      int p2 = ComputePrice(
	a,
	b,
	new_film_num,
	num_threshold,
	price_threshold,
	old_film_price,
	semi_new_film_price,
	new_film_price);

      res = min(p1+p2,res);
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 1188
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
bool check(int n){
    vector<int> res;
    while(n > 0){
        res.PB(n % 10);
        n /= 10;
    }
    bool ok = true;
    for(int i = 0, j = SZ(res) - 1; i <= j; i++, j--){
        ok &= (res[i] == res[j]);
    }
    return ok;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i = a; i <= b; i++){
        ans += (check(i));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <iostream>
#include <cstdio>

using namespace std;

int sumup(stack<int> &stk) {
	int sum = 0;
	while (stk.size()) {
		sum += stk.top();
		stk.pop();
	}
	return sum / 2;
}

int main() {
	vector<char> vec;
	stack<int> stk;
	vector<int> result;

	int count = 0;	
	int depth = 0;
	char s;
	while (scanf("%c", &s) != EOF) {
		vec.push_back(s);
	}

	int i = 0;
	while (i < vec.size()) {
		if (vec[i] != '\\') {
			++i;
			continue;
		}
		depth = 0;
		for (int j = i; j < vec.size(); ++j) {
			s = vec[j];
			if (s == '\\') {
				stk.push(2 * depth + 1);
				++depth;
			} else if (s == '/') {
				stk.push(2 * depth - 1);
				--depth;
			} else if (s == '_') {
				stk.push(2 * depth);
			}
			if (depth == 0) {
				result.push_back(sumup(stk));
				i = j + 1;
				break;
			}
		}
		if (depth) {
			while(stk.size()) stk.pop();
			++i;
		}
	}

	int sum = 0;
	for (int i = 0; i < result.size(); ++i) {
		sum += result[i];
	}
	cout << sum << endl;
	cout << result.size();
	for (int i = 0; i < result.size(); ++i) {
		cout << " " << result[i];
	}
	cout << endl;

	return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  string s;cin>>s;
  if(s[2]==s[3]&&s[4]==s[5]){
    puts("Yes");
  }else{
    puts("No");

  }

 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define pb push_back
#define FORA(i,s,e) for(int i = s; i < e; i++)
#define FORB(i,s,e) for(int i = s; i <= e; i++)

using namespace std;

void dfs(vector <vector<int>>& adj, vector <bool>& vis, int src)
{
	vis[src - 1] = true;
	for (int i = 0; i < adj[src - 1].size(); i++)
	{
		if (!vis[adj[src - 1][i] - 1])
			dfs(adj, vis, adj[src - 1][i]);
	}
	return;
}

void bfs(vector <vector<int>>& adj, vector <bool>& vis, int src)
{
	queue <int> q;
	q.push(src);
	while (!q.empty())
	{
		int temp = q.front();
		for (int i = 0; i < adj[temp - 1].size(); i++)
		{
			if (!vis[temp - 1])
				q.push(adj[temp - 1][i]);
		}
	}
	return;
}
int main(void)
{
	lli d, t, s;
	cin >> d >> t >> s;
	if (s * t >= d)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

#define MAX_N 100001

signed main() {
	vector<ll> ans(MAX_N, 0);
	for (int i = 2; i < MAX_N; i++) {
		ll k = 0;
		for (int j = 2; j <= sqrt(i); j++) {
			if (i % j == 0)k++;
			if (k >= 2)break;
		}
		ans[i] = ans[i - 1];
		if (k >= 2) ans[i]++;
	}
	ll q; cin >> q;
	rep(i, q) {
		ll n; cin >> n;
		cout << ans[n] << endl;
	}
}


Measured memory_bytes: 3464
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sort(x) sort(x.begin(),x.end())
#define reverse(x) reverse(x.begin(),x.end())
#define zero0(x,n) fill(x.begin(),x.begin()+n,0)
#define zero1(x,n) fill(x.begin(),x.begin()+n,1)
#define zero(x) fill(x.begin(),x.end(),0)
#define pb push_back
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vpii vector<pair<ll,ll> >
#define vb vector<bool>
#define pii pair<ll,ll>
#define F first
#define S second
#define INF 1e9+7
typedef long long int ll;

const ll N=2e5+7;
ll cnt[N];

void solve(){
    ll n;cin>>n;
    set<ll> s;
    ll a[n+1]; rep1(i,n) {cin>>a[i];cnt[a[i]]++;s.insert(a[i]);}
    ll ans1=0;
    for(auto i:s) if(cnt[i]) ans1+=cnt[i]*(cnt[i]-1)/2;
    rep1(i,n) {
        ll tmp=cnt[a[i]];
        ll ans=ans1;
        if(tmp>=2){
            ans-=tmp*(tmp-1)/2;
            ans+=(tmp-1)*(tmp-2)/2;
        }
        cout<<ans<<"\n";
    } 
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
}

Measured memory_bytes: 10624
#include <cstdio>
#include <utility>
#include <cctype>
#include <cmath>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n'&&c!=EOF;)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

int main() {
	times(i, in) {
		int h {in}, m {in};
		double d {abs(h / 12. - m * 11 / 720.)};
		if (d > 0.5)
			d = 1. - d;
		outl(d < 1 / 12. ? "alert" : d < 0.25 ? "warning" : "safe");
	}
}


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

using namespace std;
int main()
{
int n,d;
cin>>n>>d;
int div=2*d+1;
int q=n/div;
int r=n%div;
if(r==0)
{
cout<<q;
}
else
{
cout<<q+1;
}
return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
using namespace std;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int mod2 = 998244353 ;
const int mod = 1e9 + 7;
void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("output.txt", "w", stderr);
    #endif
}
const int N = 1e6 + 5;

int main() {
	io();
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i + 1;

	}
	sort(a, a + n);
	ll sum = 0;
	if(n % 2) {
		for(int i = 0; i < n; i++) {
			sum += abs(a[i] - a[n / 2]);
		}
		cout << sum;
	}
	else {
		ll ans = 1e18;
		int x = a[n / 2] + a[(n / 2) - 1];
		x /= 2;
		for(int i = 0; i < n; i++) {
			sum += abs(a[i] - x);
		}	
		ans = min(ans, sum);
		sum = 0;
		x = a[n / 2];
		for(int i = 0; i < n; i++) {
			sum += abs(a[i] - x);
		}
		ans = min(ans, sum);
		sum = 0;
		x = a[(n / 2) - 1];
		for(int i = 0; i < n; i++) {
			sum += abs(a[i] - x);
		}
		ans - min(ans, sum);	
		cout << ans;
	}

}



Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	string s,t;cin>>s>>t;
	int a[1<<18],b[1<<18],l=s.size(),aa[30],bb[30],c=0,d=0;
	for(int i=0;i<28;i++)aa[i]=bb[i]=-1;
	for(int i=0;i<l;i++)
	{
		if(aa[s[i]-97]<0)a[i]=++c,aa[s[i]-97]=i;
		else a[i]=a[aa[s[i]-97]];
		if(bb[t[i]-97]<0)b[i]=++d,bb[t[i]-97]=i;
		else b[i]=b[bb[t[i]-97]];
	}
	for(int i=0;i<l;i++)
	{
		if(a[i]!=b[i])
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

int main(){
    int N,
        ac = 0,
        wa = 0,
        tle = 0,
        re = 0;
    std::string s[100000];
    std::cin >> N;
    for (int i = 0; i < N; i++){
        std::cin >> s[i];
        if (s[i] == "AC"){
            ac++;
        }else if(s[i] == "WA"){
            wa++;
        }else if(s[i] == "TLE"){
            tle++;
        }else if(s[i] == "RE"){
            re++;
        }
    }
    std::cout << "AC x " << ac << std::endl;
    std::cout << "WA x " << wa << std::endl;
    std::cout << "TLE x " << tle << std::endl;
    std::cout << "RE x " << re << std::endl;
}


Measured memory_bytes: 6756
//Bismillahir Rahmanir Rahim
//In the name of Allah the Most Merciful
//Astagfirullahil laji Rabbi Minkulli Jamio
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int   long long  int
#define double  long double
#define mod 1000000007
#define rp(i,a,b)  for (int i = a; i <= b; i++)
#define hi ios_base :: sync_with_stdio(false); cin.tie(0);cout.tie(0);
int i,j,k;
main()
{
    int a,b;cin>>a>>b;
    int ar[4]={0};
    ar[a]=1;ar[b]=1;
    for(i=1;i<=3;i++)
    {
        if(ar[i]==0)cout<<i<<endl;
    }
}


Measured memory_bytes: 3624
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL N,A,B;

int main(){

    cin>>N>>A>>B;

    if(A>B){
        cout<<0<<endl;
        exit(0);
    }
    if((B-A)>N){
        cout<<0<<endl;
        exit(0);
    }
    if(B==A){
        cout<<1<<endl;
        exit(0);
    }
    LL sum_base=A+B;

   

    LL summax=sum_base;
    LL summin=sum_base;


    //間の値を決める
    for(LL i=0;i<N-2;i++){
        summax+=B;
        summin+=A;
    }
    //cout<<summax<<" "<<summin<<endl;
    cout<<summax-summin+1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define ll long long
#define ld long double
#define fi first
#define se second
const ll mod = 1000000000+7;
const int N = 100000+50;

ll dp[N];
ll a[N];
int k;

ll go(int x){
	if(x==0||x==1)return 0;
	if(dp[x]!=-1)return dp[x];
	ll ans = 1000000000+5;
	for(int i = 1 ;i<=k && x-i>0; i++)
	{
		ans = min(ans,go(x-i)+abs(a[x] - a[x-i]));
	}
	return dp[x]  = ans;
}

main()
{ 
	SPEED;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n ;
	cin >> n >> k;
	memset(dp,-1,sizeof(dp));
	for(int i = 1; i<=n;  i++)
	{
		cin >> a[i];
	}
	a[0] = a[1];
	cout << go(n) << endl;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, A[int(1e5+5)], cnt[int(1e5+5)];

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

  int ans = 0;
  for (int i = 0; i <= 1e5; i++){
    ans = max(ans, cnt[i]);
  }
  cout << ans << endl;

  return 0;
}


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


template <typename T>
struct BIT{
    int n;
    vector<T> d;

    BIT(int sz){
        n = sz+10;
        d.resize(n);
    }

    void add(int i, T x){

        while(i<=n){
            d[i] += x;
            i += i&-i;
        }
    }

    T getSum(int i){
        T ret = 0;

        while(i>0){
            ret += d[i];
            i -= i&-i;
        }
        return ret;
    }
};


int main(){
    int n; cin >> n;
    int ma = 0;
    vector<int> a(n),sorted(n);
    rep(i,n){
        cin >> a[i];
        sorted[i] = a[i];
    }


    sort(sorted.begin(), sorted.end() );
    map<int,int> mp;
    rep(i,n){
        mp[sorted[i]] = i+1;
    }


    ll res = 0;
    BIT<int> bit(n);
    rep(i,n){
        res += i-bit.getSum(mp[a[i]]);
        bit.add(mp[a[i]],1);
    }

    cout << res << endl;
}


Measured memory_bytes: 14496
from sys import stdin
from decimal import Decimal

def main():

    input = stdin.readline

    A,B = map(str,input().split())

    num_A = Decimal(A)
    num_B = Decimal(B)
    
    ans = int(num_A * num_B)

    print(ans)

if __name__ == "__main__":
    main()

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

void roundoff(double* num, int n);

int main() {
	int n;
	double x1, y1, x2, y2, x3, y3;
	double a, b, c, d, e, f;
	double px, py, r;

	scanf("%d", &n);
	while (n--) {
		scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);

		a = 2*(x2 - x1);
		b = 2*(y2 - y1);
		c = x1*x1 - x2*x2 + y1*y1 - y2*y2;
		d = 2*(x3-x2);
		e = 2*(y3-y2);
		f = x2*x2 - x3*x3 + y2*y2 - y3*y3;
		px = (b*f - c*e) / (a*e - b*d);
		py = (a*f - c*d) / (b*d - a*e);
		r = sqrt((x1 - px)*(x1 - px) + (y1 - py)*(y1 - py));
		roundoff(&px, 4);
		roundoff(&py, 4);
		roundoff(&r, 4);
		printf("%.3f %.3f %.3f\n", px, py, r);
	}

	return 0;
}

void roundoff(double* num, int n) {
	*num *= pow(10, n+1);
	*num += (num >= 0)? 0.5 : -0.5;
	*num = (double)(int)*num * pow(10, -n-1);
}

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

int main(){
  int t[10];

  for(int i = 0; i < 10; i++){
    cin >> t[i];
  }
  sort(t, t + 10);

  for(int i = 9; i >= 7; i--){
    cout << t[i] << endl;
  }
}

Measured memory_bytes: 0
import java.math.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++)
      a[i] = sc.nextInt();
    sc.close();

    int mod = 1000000007;

    int[][] dp = new int[N + 1][K + 1];
    dp[0][0] = 1;
    int[] cusum = new int[dp[0].length + 1];

    for (int i = 1; i < N + 1; i++) {
      for (int j = 1; j < cusum.length; j++)
        cusum[j] = (cusum[j - 1] + dp[i - 1][j - 1]) % mod;
      for (int j = 0; j < K + 1; j++)
        dp[i][j] = (cusum[j + 1] - cusum[Math.max(0,  j - a[i - 1])] + mod) % mod;
    }

    int ans = dp[N][K];
    System.out.println(ans);
  }
}


Measured memory_bytes: 80724
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
  int a,b;
  cin >> a >> b;
  int ans = (b+a)/2;
  if((b+a)%2 == 1)cout << "IMPOSSIBLE" << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 256
n,m = gets.chomp.split.map(&:to_i)
s = gets.chomp
t = gets.chomp

l = n*m/(n.gcd(m))

i = 0
flag = true
while i*l*l/(n*m) < l
  if !(s[i*l/m] == nil or s[i*l/m] == t[i*l/n])
    flag = false
    break
  end
    i += 1
end


if flag
  puts(l)
else
  puts("-1")
end


Measured memory_bytes: 2044
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n,k;
    cin>>n>>k;
    V<int> a(n);
    set<int> s;
    for(int i=0;i<n;i++){scanf("%d",&a[i]);if(i<k)s.insert(a[i]);}
    int cnt=0,sorted=0;
    for(int i=0;i<n-1;i++){
        if(a[i]<a[i+1])cnt++;
        else cnt=0;
        if(cnt==k-1)sorted++;
    }
    int ans=1;
    for(int i=0;i<n-k;i++){
        int l=*s.begin(),r=*s.rbegin();
        ans++;
        if(l==a[i]&&a[i+k]>r)ans--;
        s.erase(a[i]);
        s.insert(a[i+k]);
    }
    if(sorted)ans-=sorted-1;
    cout<<ans<<"\n";
}

Measured memory_bytes: 10368
import sys

N, M, K = map(int, sys.stdin.readline().split())

# 組み合わせは関係ないため、全探索可能
for i in range(N+1):
    tmp = i * M
    for j in range(M+1):
        tmp += (N - 2 * i)
        if tmp == K:
            print("Yes")
            sys.exit()

print("No")

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

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<=b;++i)
#define fj(a,b) for(int j=a;j<=b;++j)
#define fo(a,b) for(int o=a;o<=b;++o)
#define fdi(a,b) for(int i=a;i>=b;--i)
#define fdj(a,b) for(int j=a;j>=b;--j)
#define fdo(a,b) for(int o=a;o>=b;--o)
#define pb push_back
#define mp make_pair
#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...)
#endif
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;
typedef vector<int> vi;

/////////////////////////////////

int const MAX = 1e5 + 41;
int const LOG = 18;
int const MOD = 1e9 + 7;

int n, m;
int a[MAX];

int add(int a, int b) {
	a += b;
	while (a < 0) a += MOD;
	while (a >= MOD) a -= MOD;
	return a;
}

int mult(int a, int b) {
	return (ll) a * b % MOD;
}

int f[MAX], invf[MAX];

int bp(int x, int d) {
	int res = 1;
	while (d) {
		if (d & 1) res = mult(res, x);
		x = mult(x, x);
		d >>= 1;
	}
	return res;
}

int inv(int x) {
	return bp(x, MOD - 2);
}

void init() {
	f[0] = 1;
	fi(1, MAX - 1) {
		f[i] = mult(f[i - 1], i);
	}
	fi(0, MAX - 1) {
		invf[i] = inv(f[i]);
	}
}

int getc(int n, int k) {
	if (k > n) return 0;
	int res = f[n];
	res = mult(res, invf[k]);
	res = mult(res, invf[n - k]);
	return res;
}

int d[LOG][(1 << LOG)];

bool bit(int m, int i) {
	return (m & (1 << i));
}

int qbit(int m) {
	int res = 0;
	while (m) {
		res += (m & 1);
		m >>= 1;
	}
	return res;
}

void solve() {
	sort(a + 1, a + m + 1);
	reverse(a + 1, a + m + 1);	
	d[1][0] = 1;	
	fi(1, m) {
		memcpy(d[i + 1], d[i], sizeof(d[i]));
		for (int mask = 0; mask < (1 << n); mask++) {
			if (!d[i][mask]) continue;
			fj(0, n - 1) {
				if (bit(mask, j)) continue;
				int rem = (1 << n) - a[i];
				rem -= mask;
				int v1 = getc(rem, (1 << j) - 1);
				int v2 = f[(1 << j)];
				int v3 = d[i][mask];
				int v = mult(v1, mult(v2, v3));
				d[i + 1][(mask ^ (1 << j))] = add(d[i + 1][(mask ^ (1 << j))], v);
			}
		}
	}
	/*
	for (int mask = 0; mask < (1 << n); mask++) {
		err("mask = %d ways = %d\n", mask, d[m + 1][mask]);
	}
	*/
	int bad = 0;
	for (int mask = 1; mask < (1 << n); mask++) {
		int s = (qbit(mask) % 2 == 1 ? 1 : -1);
		int v1 = d[m + 1][mask];
		int v2 = f[(1 << n) - 1 - mask];
		int v = mult(v1, v2);
		bad = add(bad, s * v);
//		err("mask = %d s = %d v1 = %d v2 = %d v = %d\n", mask, s, v1, v2, v);
	}
	bad = mult(bad, (1 << n));
//	err("bad = %d\n", bad);
	int ans = add(f[(1 << n)], -bad);
	printf("%d\n", ans);
}

int main(){
#ifdef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	init();

	scanf("%d %d", &n, &m);
	fi(1, m) {
		scanf("%d", &a[i]);
	}
	solve();		
	
#ifdef LOCAL
	fprintf(stderr, "ELAPSED TIME: %.3lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using usi = unordered_set<int>;

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

    int x, sz;
    cin >> x >> sz;
    vi ps(sz, 0);
    for (auto &p : ps) cin >> p;

    const usi ps_set(ps.cbegin(), ps.cend());

    for (int d = 0;; ++d) {
        if (!ps_set.count(x - d)) {
            cout << x - d << '\n';
            break;
        } else if (!ps_set.count(x + d)) {
            cout << x + d << '\n';
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
using namespace std;
typedef long long ll;
ll n, x, a[100100];

ll gcd(ll x, ll y){
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main(void){
    // Your code here!
    cin >> n >> x;
    for (ll i = 0; i < n; i++) cin >> a[i];
    for (ll i = 0; i < n; i++) a[i] -= x;
    for (ll i = 0; i < n; i++) a[i] = abs(a[i]);
    ll ans = a[0];
    for (ll i = 1; i < n; i++){
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
char c[1001];
int main()
{
    cin>>c[0]>>c[1]>>c[2];
    if(c[0]-'0'==c[2]-'0')
	{
		cout<<"Yes"<<endl;
	}
    else 
	{
		cout<<"No"<<endl;	
	}
	cout<<endl;
    return 0;
}

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

public class Main
{

	static class dsu
	{
		int [] par,size;
		dsu(int n)
		{
			par=new int[n];size=new int[n];
			for(int i=0;i<n;i++)
			{
				size[i]=1;par[i]=i;
			}
		}
		void merge(int x,int y)
		{
			int parx=find(x),pary=find(y);
			if(size[parx]>size[pary])
			{
				par[pary]=parx;size[parx]+=size[pary];
			}
			else
			{
				par[parx]=pary;size[pary]+=size[parx];
			}
		}
		int find(int x)
		{
			if(par[x]==x)
				return x;
			else
				return find(par[x]);
		}
	}

	
	
	
	public static void main(String[] Rohan)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		String[] s = br.readLine().split(" ");


		int n=Integer.parseInt(s[0]),m=Integer.parseInt(s[1]);

		String[] s1=new String[m];

		for(int i=0;i<m;i++) s1[i]=br.readLine();

		dsu dsu=new dsu(n);

		long pair=n;

		pair*=(n-1);

		pair/=2;

		ArrayList<Long> arr=new ArrayList<Long>();

		for(int i=m-1;i>=0;i--)
		{
			arr.add(pair);
			s=s1[i].split(" ");

			int j=Integer.parseInt(s[0])-1,k=Integer.parseInt(s[1])-1;

			if(dsu.find(j)!=dsu.find(k))
			{
				long pj=(long)dsu.size[dsu.find(j)],pk=(long)dsu.size[dsu.find(k)];
				pair-=(pj*pk);
				dsu.merge(j,k);
			}
		}
		for(int i=arr.size()-1;i>=0;i--) System.out.println(arr.get(i));

			
		

	}
}

Measured memory_bytes: 67544
#include<stdio.h>
#include <bits/stdc++.h>
using namespace std;
int cmpfunc (const void * p, const void * q)
{
   return ( *(int*)p - *(int*)q );
}
int main()
{
    int n,m,i,j=0,k=0,l,p=0;
    scanf("%d %d",&n,&m);
    int a[m],b[m],c[m],d[m];
    for(i=0;i<m;i++)
    {
        scanf("%d %d",&a[i],&b[i]);
        if(a[i]==1)
        {
            c[k]=b[i];
             k++;
        }
       if(b[i]==n)
       {
           d[j]=a[i];
           j++;
       }
    }
    set<int>s;
    for(int i=0;i<j;i++)
    {
        s.insert(d[i]);
    }
    set<int>::iterator it;
     //qsort(c, k, sizeof(int), cmpfunc);
     //qsort(d, j, sizeof(int), cmpfunc);
     for(i=0;i<k;i++)
     {
            it=s.find(c[i]);
            if(it!=s.end())
            {
                cout<<"POSSIBLE"<<endl;return 0;
            }
    }
    cout<<"IMPOSSIBLE";
 return 0;
}


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

#define int long long 
#define dou double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	char chr;
	cin >> chr;
	if(isupper(chr))
		cout <<"A\n";
	else
		cout <<"a\n";
}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	return 0;
}


Measured memory_bytes: 3616