akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

void chmin(int &a, int b) {
	a = min(a, b);
}
void chmax(int &a, int b) {
	a = max(a, b);
}
ll mod_pow(ll a, ll n, ll m = mod) {
	a %= m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };


void solve() {
	ll n; cin >> n;
	int ans = 0;
	Rep1(i, 2, 1000000) {
		if (n%i == 0) {
			int tmp = 0;
			while (n%i == 0) {
				tmp++; n /= i;
			}
			rep1(j, 9) {
				if (j*(j + 1) / 2 <= tmp)ans++;
			}
		}
	}
	if (n > 1)ans++;
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init_f();
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 7760
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  string O, E;
  cin >> O >> E;

  string pass = "";
  for(int i = 0; i < max(O.size(), E.size()); i++){
    pass += O[i];
    pass += E[i];
  }
  if(O.size() < E.size()){
    pass.erase(O.size() + E.size() - 1, 1);
    cout << pass << endl;
  }else{
    pass.erase(O.size() + E.size(), 1);
    cout << pass << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int H,W,K,dp[110][110],i,j,k,m,M=1e9+7;
int main(){
  cin>>H>>W>>K;
  dp[0][1]=1;
  for(i=1;i<=H;++i)
    for(k=0;k<1<<(W-1);++k)//kは各縦棒に対して横棒があるかどうかのビット列
      if(!(k&k/2))//連続二箇所で横棒がなければ(/2によってkのビット列を右に1ずらすことができる,>>1と同じ)
        for(m=k<<1,j=1;j<=W;++j)
          (dp[i][j]+=dp[i-1][m>>j&1?j+1:m>>(j-1)&1?j-1:j])%=M;//m>>j&1は現在位置から右方向に横棒があるかどうか、m>>(j-1)&1は現在位置から左方向に横棒があるかどうか
  cout<<dp[H][K]<<endl;
  return 0;
}

/*
dp[i-1][j-1] -(左方向の横棒)- dp[i-1][j] -(右方向の横棒)- dp[i-1][j+1]
                             dp[i][j]

移動元は(i-1,j-1),(i-1,j),(i-1,j+1)
移動先は(i,j)
(i-1,j-1)から右->下と移動して(i,j)
(i-1,j+1)から左->下と移動して(i,j)
(i-1,j)から真下と移動して(i,j)
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 ios_base::sync_with_stdio(0); cin.tie(0);
  int r,g,b,n; cin >> r >> g >> b >> n; int ans=0;
  for(int i=0;i<=n;i++){
  	if(i*r <= n){
  		for(int j=0;j<=n;j++){
  			if((n - (i*r + j*g))%b == 0 && (n - (i*r + j*g)) >= 0) ans++;
  		}
  	}
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;
const int N = 2e5 + 5;

string s;
ll ans;
int a[N], ps[N];

void solve() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') a[i+1] = 1;
    else a[i+1] = 0;
  }
  for (int i = 1; i <= s.size(); i++) {
    ps[i] = ps[i-1] + a[i];
  }
  ans = 0;
  for (int i = 1; i <= s.size(); i++) {
    if (!a[i]) ans += ps[i];
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 5252
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <functional>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

const int maxn = 10;

int main()
{
	string s;
	int flag = 0;
	cin >> s;
	int len = s.length();
	for (int i = 0; i < len; i++) {
		if (s[i] == 'C' && flag == 0) {
			flag = 1;
		} else if (s[i] == 'F' && flag == 1) {
			flag = 2;
			break;
		}
	}
	if (flag == 2) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    map<int, int> mp;
    for(int n=0; n<N; n++) {
        int A;
        cin >> A;
        mp[A]++;
    }
    vector<int> vec;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        vec.push_back(itr->second);
    }
    
    sort(vec.begin(), vec.end());
    int ans=0;
    for(int i=0; i<(int)vec.size()-K; i++) {
        ans += vec[i];
    }
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 10748
#include <stdio.h>
#include <algorithm>
using namespace std;
int arr[200001];
int main(){
	int N;scanf("%d",&N);
	for(int i=0;i<N;i++) scanf("%d",arr+i);
	sort(arr,arr+N);
	printf("%s",unique(arr,arr+N)==arr+N?"YES":"NO");
}

Measured memory_bytes: 896
import java.util.*;

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

        int h = sc.nextInt();
        int a = sc.nextInt();
        int ans = 0;
        while(h > 0){
            h -= a;
            ans++;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
N = int(input())
S = input()
cnt = 0
for i in range(1, N):
    # スライスで部分文字列をつくって、set型に変換し、積集合で共通する英小文字を取得
    dup_cnt = set(S[:i]) & set(S[i:])
    # 共通する英小文字の数が現時点での最大値より大きいなら最大値を更新
    if cnt < len(dup_cnt):
        cnt = len(dup_cnt)
print(cnt)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
	ll H, W;
	cin >> H >> W;
	if(H==1 || W==1) cout << 1 << endl;
	else cout << (H*W+1)/2 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <array>
#include <set>
#include <climits>
#include <cassert>
#include <bitset>
#include <numeric>
using namespace std;
#define mod 1000000007



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

#ifdef HELL_JUDGE
    freopen("input","r",stdin);
    freopen("output","w",stdout);
    freopen("error","w",stderr);
#endif 
    int n; cin>>n;
    int mx = 0;
    map<string , int>mp;
    for(int i=0;i<n;++i){
        string s; cin>>s;
        mp[s]++;
        mx = max(mx , mp[s]);
    }
    for(auto&itr:mp){
        if(itr.second==mx){
            cout<<itr.first<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 23808
#入力
N = int(input())
A = list(map(int, input().split()))



#初期値
jud = 0

#処理
for i in range(N):
    if A[i]%2 == 0: #偶数判定
        if A[i]%3 == 0 or A[i]%5 == 0: #3または5で割りきれる
            pass
        else:
            jud += 1

#表示
if jud == 0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,a,b;
int main(){
	cin>>n>>a>>b;
	ll c=n/(a+b);
	ll rem=min(a,n-c*(a+b));
	cout<<c*a+rem<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d int

	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	fmt.Println(max(a*b, c*d))
}

func max(a int, b int) int {
	if a > b {
		return a
	}

	return b
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <numeric>

using namespace std;

int main(){
    int n, mil = 196471;
    cin >> n;
    for(int i=0; i<n; i++){
        int y, m, d;
        int yy, mm, dd;
        cin >> y >> m >> d;

        yy = (y-1)/3 * 590 + (y-1)%3 * 195;

        if(y%3 == 0){
            mm = (m-1)*20;
        }else{
            if((m-1)%2 == 0){
                mm = (m-1)/2*39;
            }else{
                mm = (m-1)/2*39+20;
            }
        }
        dd = d;

        cout << mil - (yy+mm+dd) << endl;
    }
    return 0;
}



Measured memory_bytes: 3116
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int A, B, C, K;

int main(){
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    cin >> A >> B >> C >> K;
    for(int a = 0; a <= K; a++){
        for(int b = 0; b <= K-a; b++){
            int c = K-a-b;
            int aa = A, bb = B, cc = C;
            for(int i = 0; i < a; i++) aa *= 2;
            for(int i = 0; i < b; i++) bb *= 2;
            for(int i = 0; i < c; i++) cc *= 2;
            if(aa < bb && bb < cc){
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

Measured memory_bytes: 3660
/*_BELIEVE_*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;

void solve()
{
 int n,d;
 cin>>n>>d;

 int a[n][d];

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

 int dt,x,cnt=0;
 for(int i=0;i<n;++i)
 {
  for(int k=i+1;k<n;++k)
  {
   dt=0ll;
   for(int j=0;j<d;++j)
   dt+=(a[i][j]-a[k][j])*(a[i][j]-a[k][j]);

   x=sqrt(dt);

   if(x*x==dt)
   ++cnt;
  }
 }

 cout<<cnt;
}

int32_t main()
{
 fast();

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

 return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;
int A[112345];

int main() {
	cin >> N;
	REP(i, N) scanf("%d", A + i);
	
	sort(A, A + N);
	
	int ans = 0;
	vector<pii> ansv;
	
	int sum1 = A[N - 1], sum2 = A[0];
	int p = 1;
	while (p < N - 1) {
		ansv.push_back(pii(A[p] < 0 ? sum1 : sum2, A[p]));
		if (A[p] < 0) sum1 = sum1 - A[p];
		else sum2 = sum2 - A[p];
		p++;
	}
	ansv.push_back(pii(sum1, sum2));
	ans = sum1 - sum2;
	
	cout << ans << endl;
	REP(i, N - 1) printf("%d %d\n", ansv[i].fi, ansv[i].se);
	return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0; ll max = a[0];
    rep(i, n-1) {
        if (max > a[i+1]) {
            ans += max - a[i+1];
        }
        else if (max < a[i+1]) {
            max = a[i+1];
        }
    }
    cout << ans << endl;
}


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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	while (cin >> N, N) {
		vector<int> x(N);
		for (int i = 0; i < N; i++) {
			cin >> x[i];
		}
		int res = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 1; j <= 3; j++) {
				int lb = i - 1, ub = i + 1, cnt = 1;
				while (0 <= lb && x[lb] == j) {
					cnt++;
					lb--;
				}
				while (ub < N && x[ub] == j) {
					cnt++;
					ub++;
				}
				if (cnt >= 4) {
					while (0 <= lb && ub < N && x[lb] == x[ub]) {
						int v = x[lb], add = 0;
						while (0 <= lb && x[lb] == v) {
							add++;
							lb--;
						}
						while (ub < N && x[ub] == v) {
							add++;
							ub++;
						}
						if (add <= 3) break;
						cnt += add;
					}
					res = max(res, cnt);
				}
			}
		}
		cout << N - res << endl;
	}
	return 0;
}



Measured memory_bytes: 3208
def lucas(n)
    a, b = 2, 1 
    if n == 0
        return 2
    elsif n == 1
        return 1
    else
        (n-1).times do
            a, b = b, (a + b)
        end
        return b
    end
end

n = gets.to_i

puts lucas(n)

Measured memory_bytes: 1788
#include<iostream>

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;

	if (A == B && B == C) {
		cout << "No" << endl;
	}
	else if (A != B && B != C && C != A) {
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;

	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
const int mod = 1e9 + 7;

int main(){
    ll n;
    cin >> n;
    string res = "";

    while(n > 0){
        if (n % 26 == 0){
            res += 'z';
            n /= 26;
            n -= 1;
        }
        else{
            res += (n % 26 - 1) + 'a';
            n /= 26;
        }
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}

Measured memory_bytes: 3628
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort()
# N, T = 3000, 14
# AB = [(i**2, i) for i in range(N)]

# dp[i+1][j] = i番目までの料理で、j分経った時の、最高満足度
# jがT以上のときはj == T とする(T以上における差はないので)

dp = [[0 for _ in range(6010)] for _ in range(3010)]

max_num = 0
for i, (a, b) in enumerate(AB):
    # print(a, b)
    for j in range(T):
        if j == T-1:
            max_num = max(
                max_num,
                dp[i][j] + b
            )
        dp[i+1][j] = max(
            dp[i+1][j],
            dp[i][j]
        )
        dp[i+1][j+a] = max(
            dp[i+1][j+a],
            dp[i][j] + b
        )

# for dp_i in dp:
#     print(dp_i)

print(max_num)


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

int main(void){
  int n;
  long long power=1;
  cin>>n;
  r(i,n){power*=(i+1);
    power%=(1000000000+7);
    }

  cout<<power<<endl;






  return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {
    var line = input[0].split(' ');
    var x = parseInt(line[0]);
    var a = parseInt(line[1]);
    var b = parseInt(line[2]);

    if (Math.abs(x - a) <= Math.abs(x - b)) {
        console.log('A');
    }
    else {
        console.log('B');
    }
}



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

int main() {
  int N, count;
  count=0;
  cin >> N;
  vector<int> vec(N);
  
  for (int i=0; i<N; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());

  for (int i=0; i<N; i++) {
    
    if (i==0) {
      count++;
      continue;
    }
    
    if (i>0 && vec.at(i)>vec.at(i-1)) {
      count++;
      continue;
    }
  }

  cout << count << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int n;
ll a[200001];
ll b[200001];

ll sadv(ll c) {
	ll res = 0;
	for (int i = 0; i < n; i++) {
		res += abs(b[i] - c);
	}
	return res;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		 cin >> a[i];
		 b[i] = a[i] - i - 1;
	}
	sort(b, b + n);
	// for (int i = 0; i < n; i++) {
	// 	 cout << b[i] << " ";
	// }
	int m = n / 2;
	ll minv = sadv(b[m]);
	if (m - 1 >= 0) minv = min(minv, sadv(b[m - 1]));
	if (m + 1 < n) minv = min(minv, sadv(b[m + 1]));
	cout << minv;
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <algorithm>
#include <utility>
using namespace std;
int t, ii, jj, kk, x, y;
long long p;
long long n, a, b, c, d;
long long l;
pair<long long, long long> r[20000];
int table[64][50][30];
long long ansl[20000];
long long ansr[20000];
long long two;
long long lc, rc;
double ac, bc;
int main() {
	l = 1000000000;
	l *= 1500000000;
	l += 6;
	p = 1;
	while (p < l) {
		while (p < l) {
			while (p < l) {
				r[x].first = p;
				r[x].second = ii * 10000 + jj * 100 + kk;
				x++;
				p *= 5;
				kk++;
			}
			for (int e = 0; e < kk; e++) {
				p /= 5;
			}
			kk = 0;
			p *= 3;
			jj++;
		}
		for (int e = 0; e < jj; e++) {
			p /= 3;
		}
		jj = 0;
		p *= 2;
		ii++;
	}
	std::sort(r, r + x);
	for (int i = 0; i < x; i++) {
		ii = r[i].second / 10000;
		jj = r[i].second / 100 % 100;
		kk = r[i].second % 100;
		table[ii][jj][kk] = i;
	}
	scanf("%d", &t);
	for (int q = 0; q < t; q++) {
		scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
		for (int i = 0; i < x; i++) {
			ansl[i] = l;
			ansr[i] = l;
			ac = n / r[i].first;
			ac *= d;
			bc = l;
			bc *= 2;
			if (ac < bc) {
				if (n / r[i].first * d < l)ansl[i] = n / r[i].first * d;
			}
		}
		two = d + d;
		if (a + d < two)two = a + d;
		for (int i = x - 1; i >= 0; i--) {
			if (n / r[i].first < 1) {
				ansl[i] = 0;
				ansr[i] = d;
			}
			else if (n / r[i].first < 2) {
				ansl[i] = d;
				ansr[i] = two;
			}
			if (ansl[i] + d < ansr[i])ansr[i] = ansl[i] + d;
			if (ansr[i] + d < ansl[i])ansl[i] = ansr[i] + d;
			ii = r[i].second / 10000;
			jj = r[i].second / 100 % 100;
			kk = r[i].second % 100;
			if (ii) {
				y = table[ii - 1][jj][kk];
				lc = ansl[i] + a;
				lc += d * (n / r[y].first - n / r[i].first * 2);
				if (ansl[y] > lc)ansl[y] = lc;
				rc = ansr[i] + a;
				rc += d * ((n / r[i].first + 1) * 2 - (n / r[y].first + 1));
				if (ansr[y] > rc)ansr[y] = rc;
			}
			if (jj) {
				y = table[ii][jj - 1][kk];
				lc = ansl[i] + b;
				lc += d * (n / r[y].first - n / r[i].first * 3);
				if (ansl[y] > lc)ansl[y] = lc;
				rc = ansr[i] + b;
				rc += d * ((n / r[i].first + 1) * 3 - (n / r[y].first + 1));
				if (ansr[y] > rc)ansr[y] = rc;
			}
			if (kk) {
				y = table[ii][jj][kk - 1];
				lc = ansl[i] + c;
				lc += d * (n / r[y].first - n / r[i].first * 5);
				if (ansl[y] > lc)ansl[y] = lc;
				rc = ansr[i] + c;
				rc += d * ((n / r[i].first + 1) * 5 - (n / r[y].first + 1));
				if (ansr[y] > rc)ansr[y] = rc;
			}
		}
		printf("%lld\n", ansl[0]);
	}
}

Measured memory_bytes: 2432
#include <stdio.h>

int main(){

  char n;

  for(;;){

    scanf("%c",&n);
    
    if(n=='\n'){break;
    }
    
    if(n<97&&n>=65){
      n+=32;
    }

    else if(n>=97&&n<123){
      n-=32;
    }

    printf("%c",n);

      }

  printf("\n");

  return 0;
}

Measured memory_bytes: 932
#include<bits/stdc++.h>
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define YES cout<<"YES"<<endl
#define all(v) v.begin(),v.end()
#define NO cout<<"NO"<<endl
#define pb(x) emplace_back(x)
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define mi map<ll,ll>
#define pi pair<ll,ll>
#define what(x) cout<<#x<<" ="<<x<<endl;
using namespace std;
using ll =long long;

ll dp[1005][1005];
string a[1000+5];
ll mod=1e9+7,n,m;
ll solve(ll i,ll j)
{
    if(i==n-1 && j==m-1)return 1;
    if(i>=n ||i<0 || j>=m || j<0) return 0;
    if(dp[i][j]!=-1)return dp[i][j]%mod;
    dp[i][j]=0;
    if(i+1<n)if(a[i+1][j]!='#')dp[i][j]=(solve(i+1,j))%mod;
    if(j+1<m)if(a[i][j+1]!='#')dp[i][j]=(dp[i][j]%mod+solve(i,j+1)%mod)%mod;

    return dp[i][j]%mod;

}



int main()
{

    memset(dp,-1,sizeof dp);
    cin>>n>>m;



    fr(i,0,n)cin>>a[i];

    cout<<solve(0,0)<<endl;










}




























Measured memory_bytes: 13440
#include <stdio.h>

int combination(int n,int x){
	int i,j,k;
	int cnt = 0;
	/*
	static int cnt = 0;

	cnt++;
	printf("cnt:%d\n", cnt);

	if(cnt < a){
		for(i = b;i <= n;i++){
			printf("%d", i);
			combination(n,3,i+1);
		}
	}
	*/

	for(i = 1;i <= n;i++){
		for(j = i+1;j <= n;j++){
			for(k = j+1;k <= n;k++){
				if(i + j + k == x){
					//printf("%d %d %d\n", i, j, k);
					cnt++;
				}
			}
		}
	}

	return cnt;
}

int main(void){
	int n,x,i,j,k;
	int cnt = 0;

	while(1){
		scanf("%d %d", &n, &x);

		if((n == 0 && x == 0) || (n < 3 || n > 100)){
			return 0;
		}

		printf("%d\n", combination(n,x));
	}
	return 0;
}

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


int main() {
    long long A, B, C, K;
    cin >> A >> B >> C >> K;

    if (K % 2 == 0) {
        cout << A - B << endl;
    } else if (K % 2 != 0) {
        cout << B - A << endl;
    }
}

Measured memory_bytes: 256
L, R = map(int, input().split())
L_mod = L % 2019
R_mod = R % 2019

if R - L >= 2019:
    Ans = 0
elif R_mod < L_mod:
    Ans = 0
elif R_mod > L_mod:
    Ans = 2019
    for i in range(L_mod, R_mod):
        for k in range(L_mod+1,R_mod+1):
            Ans = min(Ans,i*k % 2019)
        
print(Ans)

Measured memory_bytes: 40428
#include<iostream>
using namespace std;
int n,k,a,i;
long dp[2<<17],mod=1e9+7;
main()
{
	cin>>n>>k;
	dp[k]=1;
	for(;cin>>a;i++)
	{
		for(int j=k;j--;)dp[j]+=dp[j+1];
		for(int j=0;j<k;j++)(dp[j]-=dp[j+a+1])%=mod;
	}
	cout<<dp[0]<<endl;
}

Measured memory_bytes: 1024
n = int(input())
b = list(map(int, input().split()))
ans = []
while(b != []):
    for i in range(len(b), 0, -1):
        if i not in b:
            continue
        if b[i - 1] == i:
            ans.append(i)
            del b[i - 1]
            break
    else:
        print(-1)
        exit()
for i in ans[::-1]:
    print(i)

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

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if ((a * b) % 2)
		cout << "Odd" << "\n";
	else
		cout << "Even" << "\n";
}

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



int h,w,k;
char grid[10][10];

int solve(int a,int b){
    int cntb=0;
    for(int i = 0; i < h; i++){
        if(a&(1<<i)){
            continue;
        }
        for(int j = 0; j < w; j++){
            if(b&(1<<j)){
                continue;
            }
            cntb+=(grid[i][j]=='#');
        }
    }

    return cntb;
}



int main()
{
    cin >> h >> w >> k;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin>>grid[i][j];
        }
    }
    int cnt=0;
    for(int i = 0; i < (1<<h); i++){
        for(int j = 0; j < (1<<w); j++){
            if(solve(i,j)==k){
                cnt++;
            }
        }
    }
    cout<<cnt<<"\n";
    return 0;
}

Measured memory_bytes: 3608
# -*- coding: utf-8 -*-


def main():
    from collections import defaultdict
    from collections import deque
    import sys

    n = int(input())
    graph = [defaultdict(int) for _ in range(n)]
    visited = [False for _ in range(n)]
    dist = [float('inf') for _ in range(n)]
    lines = sys.stdin.readlines()

    for i in range(n - 1):
        ai, bi, ci = map(int, lines[i].split())
        ai -= 1
        bi -= 1
        graph[ai][bi] = ci
        graph[bi][ai] = ci

    q, k = map(int, lines[n - 1].split())
    k -= 1
    dist[k] = 0
    d = deque()
    d.append(k)

    while d:
        di = d.popleft()
        visited[di] = True

        for bi, ci in graph[di].items():
            if visited[bi]:
                continue

            dist[bi] = dist[di] + ci
            d.append(bi)

    ans = [0 for _ in range(q)]

    for j in range(q):
        xi, yi = map(int, lines[n + j].split())
        xi -= 1
        yi -= 1
        ans[j] = dist[xi] + dist[yi]

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


if __name__ == '__main__':
    main()


Measured memory_bytes: 79848
#include <iostream>

using namespace std;
const int maxn = 200500;
int f[maxn];
int num[maxn];
// int x[maxn];
// int y[maxn];
int n,m,x,y;
int find_(int x){
    if(f[x]==x)return x;
    return f[x]=find_(f[x]);
}
void init() {
    for(int i = 0;i <= n;i++)
        f[i] = i;
}
void merge(int x,int y) {
    int fax = find_(x);
    int fay = find_(y);
    if(fax!=fay)
        f[fay] = fax;
}

int ans = 0;
int main()
{
    scanf("%d%d",&n,&m);    //n个点m组
    init();
    for(int i=0;i < m;i++) {
        scanf("%d%d",&x,&y);
        merge(x,y);
    }
    for(int i = 1;i <= n;i++) 
        num[find_(i)]++;
    for(int i = 1;i <= n;i++) {
        if(ans < num[i])
            ans = num[i];
    }
    printf("%d\n",ans);
    return 0;
}


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

#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<n;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define mod 10000000007
#define modpro 99824435

const int d4i[4]={-1,0,1,0},d4j[4]={0,1,0,-1};
const int d8i[8]={-1,-1,0,1,1,1,0,-1},d8j[8]={0,1,1,1,0,-1,-1,-1};


void solve(){
	int n,k;
	cin>>n>>k;
	inv(v,int,n);
	vector<int> dp(n);
	//F(0,k-1,i) dp[i] = 0;
	//dp[k-1] = abs(v[k-2]-v[k-1]);
	F(0,n,i) dp[i] = INT_MAX;
	dp[0] = 0;
	F(0,n,i){
		for(int j=1;j<=k;j++){
			if(i-j>=0) dp[i] = min(dp[i],dp[i-j]+abs(v[i-j]-v[i]));
		}
	}
	cout<<dp[n-1];
}

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
}



Measured memory_bytes: 3992
int main(){
  int i,x,y,swap,r;

  //input two numbers
  scanf("%d%d",&x,&y);

  //swapping
  if(x<y){
    swap = x;
    x = y;
    y = swap;
  }

  while(y>0){
    r = x % y;
    x = y;
    y = r;
  }

  printf("%d\n",x);

  return 0;
}

Measured memory_bytes: 592
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        if(b % a == 0) System.out.println(a+b);
        else System.out.println(b-a);
    }  
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int INV = 5e8 + 4;

template<int MOD>
struct ModInt {
    long long v;
    ModInt(long long _v = 0) {v = (-MOD < _v && _v < MOD) ? _v : _v % MOD; if (v < 0) v += MOD;}
    ModInt& operator += (const ModInt &other) {v += other.v; if (v >= MOD) v -= MOD; return *this;}
    ModInt& operator -= (const ModInt &other) {v -= other.v; if (v < 0) v += MOD; return *this;}
    ModInt& operator *= (const ModInt &other) {v = v * other.v % MOD; return *this;}
    ModInt& operator /= (const ModInt &other) {return *this *= inverse(other);}
    bool operator == (const ModInt &other) const {return v == other.v;}
    bool operator != (const ModInt &other) const {return v != other.v;}
    friend ModInt operator + (ModInt a, const ModInt &b) {return a += b;}
    friend ModInt operator - (ModInt a, const ModInt &b) {return a -= b;}
    friend ModInt operator * (ModInt a, const ModInt &b) {return a *= b;}
    friend ModInt operator / (ModInt a, const ModInt &b) {return a /= b;}
    friend ModInt operator - (const ModInt &a) {return 0 - a;}
    friend ModInt power(ModInt a, long long b) {ModInt ret(1); while (b > 0) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
    friend ModInt inverse(ModInt a) {return power(a, MOD - 2);}
    friend ostream& operator << (ostream &os, const ModInt &m) {return os << m.v;}
};
typedef ModInt<1000000007> M;

int n, sz[200005];
M pre[200005];
vector<int> adj[200005];

int dfs1(int u, int p) {
    sz[u] = 1;
    for (int v : adj[u])
        if (v != p)
            sz[u] += dfs1(v, u);
    return sz[u];
}

M dfs2(int u, int p) {
    M ret = 0;
    for (int v : adj[u])
        if (v != p)
            ret += (1 - pre[sz[v]]) * (1 - pre[n - sz[v]]) + dfs2(v, u);
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n;
    for (int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    pre[0] = 1;
    for (int i=1; i<=n; i++)
        pre[i] = pre[i-1] * INV;

    dfs1(0, -1);
    cout << dfs2(0, -1) + 1 - pre[n] - M((long long) n * INV) << "\n";

    return 0;
}


Measured memory_bytes: 27964
#pragma GCC optimize("O3")
 #pragma GCC optimize("unroll-loops")
 #pragma GCC optimize("fast-math")
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}
const int N = 2000;
int dp[N][N];
char c[N][N];
signed main() {
    accell();
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> c[i][j];
        }
    }
    dp[0][0] = c[0][0] == '#';
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (i && c[i][j] == '#' && c[i - 1][j] == '#') dp[i][j] = max(dp[i][j], (int)(dp[i - 1][j] + 1));
            if (j && c[i][j] == '#' && c[i][j - 1] == '#') dp[i][j] = max(dp[i][j], (int)(dp[i][j - 1] + 1));
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            ans = max(ans, dp[i][j]);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            ans -= c[i][j] == '#';
    if (ans == 0)
        cout << "Possible";
    else
        cout << "Impossible";
    return 0;
}


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

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

int main(){
  int N;
  string S;
  cin >> N >> S;
  vector<int> V(2*N);
  for(int i = 0; i < 2*N; ++i){
    if(S[i] == 'B') V[i] = 1;
    else V[i] = 0;
  }
  using mint = modint<(int)1e9+7>;
  int t = 0, k = 0;
  mint ans = 1;
  for(int i = 0; i < 2*N; ++i){
    if(k) V[i] = 1 - V[i];
    if(V[i]){
      ++t;
      k = 1 - k;
    }else{
      ans *= t;
      --t;
      k = 1 - k;
    }
    //cerr << i << " " << ans << endl;
  }
  if(t) ans = 0;
  for(int i = 0; i < N; ++i)
    ans *= (i+1);
  cout << ans << endl;
}


Measured memory_bytes: 1412
z[2002],*a=z,*b=z+1001,m,i,j,t;
main(n){
	for(;scanf("%d",&n),n;printf("%d\n",m)){
		for(memset(a,m=i=0,4004);i<n;i++){
			scanf(" ");
			for(j=1;j<=n;j++)
				m=fmax(m,b[j]=getchar()-'*'?1+fmin(fmin(b[j-1],a[j-1]),a[j]):0);
			t=a;a=b;b=t;
		}
	}
	exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    string str1, str2;
    while (cin>>str1>>str2, str1.length() != 1) {
        int hit = 0;
        int blow = 0;
        for (int i = 0; i < 4; ++i) {
            if (str1[i] == str2[i]) hit++;
            for (int j = 0; j < 4; ++j) {
                if (i == j) continue;
                if (str1[i] == str2[j]) blow++;
            }
        }
        cout<<hit<<" "<<blow<<endl;
    }
    return 0;
}


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

using namespace std;

int main(){
    int n, k; cin >> n >> k;
    vector<bool> ds(10);
    for(int i=0; i<k; ++i){
        int d; cin >> d;
        ds[d]=true;
    }
    int ans=n;
    while(true){
        int tmp=ans;
        bool found=true;
        while(tmp){
            if(ds[tmp%10]){
                found=false;
                break;
            }
            tmp/=10;
        }
        if(found) break;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int a;
    cin >> a;
    
    if(a < 1200) cout << "ABC" << endl;
    else if(a < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    
    return 0;

}

Measured memory_bytes: 256
from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys
#input = sys.stdin.readline

import copy

N,A,B=map(int,input().split())
H=[int(input()) for i in range(N)]
H.sort()
ng=0
ok=10**18
A-=B
while ok-ng>1:

    mid=(ok+ng)//2
    c=bisect_right(H,mid*B)

    _sum=0
    for i in range(c,N):
        Z=H[i]-mid*B
        _sum+=Z//A+bool(Z%A)
    #print(_sum)
    if mid>=_sum:
        ok=mid
    else:
        ng=mid
print(ok)


Measured memory_bytes: 76372
function main(){
	var n = scan();
	rep(n, function(i){
		var x = scan('string').split('');
		x.sort();
		var a = +x.join('');
		var b = +x.reverse().join('');
		print(b - a);
	});
}
 
function rep(a, b, c){
	if(c == null){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		c(i);
	}
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var input = '';
var input_index = 0;
 
function scan(type){
	if(type === 'string'){
		return input[input_index++];
	}
	else{
		return +input[input_index++];
	}
}
 
function print(val){
	console.log(val);
}
 
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.split(/\s+/);
	main();
});

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

int main()
{
  string s;
  while (cin >> s) {
    vector<int> cnt(9, 0), ans;
    for (unsigned int i = 0; i < s.size(); ++i)
      ++cnt[s[i]-'1'];

    for (int i = 0; i < 9; ++i) {
      if (cnt[i]+1 >= 5)
	continue;

      bool valid = false;
      for (int j = 0; j < 9; ++j) {
	vector<int> cp(cnt);
	++cp[i];
	 
	if (cp[j] < 2)
	  continue;
	cp[j] -= 2;

	for (int k = 0; k < 9; ++k) {
	  if (cp[k] >= 3)
	    cp[k] -= 3;
	}

	for (int k = 0; k < 7; ++k) {
	  while (cp[k] > 0 && cp[k+1] > 0 && cp[k+2] > 0) {
	    --cp[k];
	    --cp[k+1];
	    --cp[k+2];
	  }
	}

	bool ok = true;
	for (int k = 0; k < 9; ++k) {
	  if (cp[k] != 0)
	    ok = false;
	}

	if (ok) {
	  valid = true;
	  break;
	}
      }

      for (int j = 0; j < 9; ++j) {
	vector<int> cp(cnt);
	++cp[i];
	 
	if (cp[j] < 2)
	  continue;
	cp[j] -= 2;

	for (int k = 0; k < 7; ++k) {
	  while (cp[k] > 0 && cp[k+1] > 0 && cp[k+2] > 0) {
	    --cp[k];
	    --cp[k+1];
	    --cp[k+2];
	  }
	}

	for (int k = 0; k < 9; ++k) {
	  if (cp[k] >= 3)
	    cp[k] -= 3;
	}

	bool ok = true;
	for (int k = 0; k < 9; ++k) {
	  if (cp[k] != 0)
	    ok = false;
	}

	if (ok) {
	  valid = true;
	  break;
	}
      }

      if (valid)
	ans.push_back(i+1);
    }

    if (ans.empty()) {
      cout << "0" << endl;
    } else {
      for (unsigned int i = 0; i < ans.size()-1; ++i)
	cout << ans[i] << " ";
      cout << ans[ans.size()-1] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>

const int N = 1000000;
int prime[N] = {0},num_prime = 0;
int isNotPrime[N] = {1, 1};

int main()
{
    int n;
    for(long i=2; i<(2<<17); i++)
    {
        if(!isNotPrime[i])
            prime[num_prime++]=i;
        for(long j = 0 ; j < num_prime && i * prime[j] <  N ; j ++)
        {
            isNotPrime[i * prime[j]] = 1;
            if( !(i % prime[j] ) )
                break;
        }
    }
    while(~scanf("%d",&n),n)
    {
        int cnt = 0;
        for(int i=0; prime[i]<n; i++)
            for(int j=i; prime[j]<n; j++)
                if(prime[i] + prime[j] == n)
                    cnt++;
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 5024
// AOJ 2155: Infected Computer
// 2017.10.20 bal4u@uu
// 2018.2.4

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
typedef struct { int t, s, d; } T;
T tbl[20002], *end;
char f[20002];
 
int cmp(T *a, T *b) { return a->t - b->t; }
 
//#define getchar_unlocked()  getchar()
int in()
{
    int n = 0;
    int c = getchar_unlocked();
    do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
    while (c >= '0');
    return n;
}
 
int main()
{
    int n, m, ans;
    T *t;
 
    while (n = in()) {
        m = in();
        memset(f, 0, n+1);
        end = tbl + m; for (t = tbl; t < end; t++) t->t = in(), t->s = in(), t->d = in();
        qsort(tbl, m, sizeof(T), cmp);
        f[1] = 1, tbl[m].s = 1;
		t = tbl-1; while ((++t)->s != 1);
		ans = 1;
		for (; t < end; t++) {
			ans += f[t->s] & ~f[t->d];
			f[t->d] |= f[t->s];
		}
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2228
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
#include<math.h>
#define MAX_N 300000
using namespace std;

int sum (int n){
 int res=0;
 for (int i=0;i<=4;i++){
  res+=((int)(n/pow(10,i)))%10;
 }
 return res;
}

int main(){
 int a,b,n,x,ans=0;
 cin >>n>>a>>b;
 for (int i=1;i<=n;i++){
  x=sum(i);
  if (a<=x&&x<=b) ans+=i;
 }

 cout <<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int N;
  int i, j;

  scanf("%d%*c", &N);

  for(i = 1; i < 10; i++){
    for(j = 1; j < 10; j++){
      if(i * j == N){
        printf("Yes\n");
        return 0;
      }
    }
  }

  printf("No\n");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, k, q;
ll sum[101010];
int main() {
    cin>>n>>k>>q;
    REP(i, 0, q){
        ll a;
        cin>>a;
        a--;
        sum[a]++;
    }

    REP(i, 0, n){
        if(k-(q-sum[i])>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>

int n,fb,la,res;

bool flag,f2;

std::string s[10000];

int main(){

    std::cin>>n;

    for(int i=0;i<n;i++)
    std::cin>>s[i];

    for(int i=0;i<n;i++){
        for(int j=0;j<s[i].size()-1;j++){
            if(s[i][j]=='A'&&s[i][j+1]=='B')
            res++;
        }
        if(s[i][0]=='B')fb++;
        if(s[i][s[i].size()-1]=='A')la++;
        if(s[i][0]!='B'&&s[i][s[i].size()-1]=='A')flag=true;
        if(s[i][0]=='B'&&s[i][s[i].size()-1]!='A')flag=true;
        if(s[i][0]=='B'||s[i][s[i].size()-1]=='A')f2=true;
    }

    res+=std::min(fb,la);

    if(flag==false&&f2==true)
    res--;

    std::cout<<res<<std::endl;

    return 0;
}

Measured memory_bytes: 768
#include<stdio.h>

int search(int A[], int n, int key){
    int i = 0;
    A[n] = key;
    while(A[i] != key) i++;
    return i != n;
}

int main(){
    int i, n, A[10000 + 1], q, key, sum = 0;

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }

    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &key);
        if(search(A, n, key)){
            sum++;
        }
    }
    printf("%d\n",  sum);

    return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  int t = 0;
  for (int i=a;i<=b;i++){
    if (i/10000 == i%10 && (i%10000)/1000 == (i%100)/10){
      t++;
    }
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
    }
    let mut f = vec![0; n + 1];
    for x in 1..=n {
        if x * x > n {
            break;
        }
        for y in 1..=n {
            if x * x + y * y + x * y > n {
                break;
            }
            for z in 1..=n {
                let s = x * x + y * y + z * z + x * y + y * z + z * x;
                if s > n {
                    break;
                }
                f[s] += 1;
            }
        }
    }
    for i in 1..=n {
        println!("{}", f[i]);
    }
}


Measured memory_bytes: 2128
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

vector<vector<ll>> mul(vector<vector<ll>> &A, vector<vector<ll>> &B){
    vector<vector<ll>> C(A.size(), vector<ll>(B.size()));

    for(int i=0; i<A.size(); i++){
        for(int k=0; k<B.size(); k++){
            for(int j=0; j<B[0].size(); j++){
                (C[i][j] += (A[i][k] * B[k][j]) % MOD) %= MOD;
            }
        }
    }
    
    return C;
}

vector<vector<ll>> pow(vector<vector<ll>> A, ll n){
    vector<vector<ll>> B(A.size(), vector<ll>(A.size()));

    for(int i=0; i<A.size(); i++){
        B[i][i] = 1;
    }

    while(n > 0){
        if(n & 1LL) B = mul(B, A);
        A = mul(A, A);
        n >>= 1LL;
    }

    return B;
}

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

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

    a = pow(a, k);

    ll ans = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            ans += a[i][j];
            ans %= MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

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

    int N; cin >> N;
    vector<int64_t> A(N);
    rep(i, N) cin >> A[i];

    rep(i, N){
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }

    int64_t ans = 1;
    rep(i, N){
        int64_t x = 1000000000000000000LL/ans;
        if(A[i]>x){
            cout << "-1" << endl;
            return 0;
        }
        ans*=A[i];
    }

    cout << ans << endl;

}

Measured memory_bytes: 3996