akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

vector<pair<char, ll>> runlength(string s) {
    vector<pair<char, ll>> ret;
    ll cnt = 1;
    Rep (i, (ll)s.size()-1) {
        if (s[i] == s[i+1]) cnt++;
        else {
            ret.push_back({s[i], cnt});
            cnt = 1;
        }
    }
    ret.push_back({s[s.size()-1], cnt});
    return ret;
}

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

    ll N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    ll ans = 0;
    Rep (i, K) {
        string s;
        for (ll j = i; j < N; j += K) {
            s += T[j];
        }

        auto a = runlength(s);

        Rep (j, (ll)a.size()) {
            char c = a[j].first;
            ll e = a[j].second;
            // cout << run[j] << " " << length[j] << endl;
            if (c == 'r') {
                ans += (e+1)/2 * P;
            } else if (c == 's') {
                ans += (e+1)/2 * R;
            } else {
                ans += (e+1)/2 * S;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 2756
#include <stdio.h>
#include <string.h>

int main()
{
        int kaisuu = 0, point_tarou = 0, point_hanako = 0;
        char string_tarou[100], string_hanako[100];

        scanf("%d", &kaisuu);
        while ( kaisuu > 0 )
        {
                scanf("%s %s", string_tarou, string_hanako);
                if ( strcmp(string_tarou, string_hanako) == 0 )
                {
                        point_tarou = point_tarou + 1;
                        point_hanako = point_hanako + 1;
                }
                else if ( strcmp(string_tarou, string_hanako) < 0 )
                {
                        point_hanako = point_hanako + 3;
                }
                else if ( strcmp(string_tarou, string_hanako) > 0 )
                {
                        point_tarou = point_tarou + 3;
                }

                kaisuu = kaisuu - 1;
        }

        printf("%d %d\n", point_tarou, point_hanako);
        return 0;

}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

int pr[16],ex[16][16],mi=0x3f3f3f3f,sum,now[16];
int n,m,x;
void solve(int u)
{
	int flag=1;
	for(int i=1;i<=m;++i)
	{
		if(now[i]<x)flag=0;
	}
	if(flag){if(sum<mi)mi=sum;return;}
	for(int i=u;i<=n;++i)
	{
		for(int j=1;j<=m;++j)now[j]+=ex[i][j];
		sum+=pr[i];
		solve(i+1);
		for(int j=1;j<=m;++j)now[j]-=ex[i][j];
		sum-=pr[i];
	}
	//cout<<1;
}
int main()
{
	ios;
	cin>>n>>m>>x;
	for(int i=1;i<=n;++i)
	{
		cin>>pr[i];
		for(int j=1;j<=m;++j)cin>>ex[i][j];
	}
	//cout<<1;
	solve(1);
	if(mi!=0x3f3f3f3f)cout<<mi<<'\n';
	else cout<<-1<<'\n';
}

Measured memory_bytes: 3660
#include <stdio.h>

int main(void)
{
	int n,i,debt;
	int t;
	
	debt = 100000;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		debt += debt/100*5;
		debt = (debt + 999) /1000 * 1000;
	}
	
	printf("%d\n", debt);
	
	return (0);
}

Measured memory_bytes: 592
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;
const int INF = 10000000; // INT_MAXにするとワーシャルフロイドでオーバーフロー
const int SIZE = 21;
vector<vector<int> > d(SIZE * SIZE, vector<int>(SIZE * SIZE, INF));

int h, w;
int sx, sy;
int gx, gy;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int V;
vector<string> maze(SIZE);

void warshall_floyd(int V){

  for(int k = 0; k < V; ++k)
    for(int i = 0; i < V; ++i)
      for(int j = 0; j < V; ++j) 
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main(){
  
  cin >> h >> w;
  
  int count = 0;

  rep(i, h){
    cin >> maze[i];
    
  }

  rep(i, h * w){
    d[i][i] = 0;
  }

  rep(i, h){
    rep(j, w){
      if(maze[i][j] == '#') continue;

      rep(k, 4){
        int nx = i + dx[k];
        int ny = j + dy[k];
        if(0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] == '.'){
          d[i*w + j][nx*w + ny] = 1;
          d[nx*w + ny][i*w + j] = 1;
        }
      }
    }
  }

  V = h * w;

  warshall_floyd(V);

  int ans = 0;
  rep(i, h * w){
    rep(j, h * w) {
      if(d[i][j] == INF)  continue;
      ans = max(d[i][j], ans);
    }
  }


  cout << ans <<endl;
}

Measured memory_bytes: 1024
import math

n = int(input())
ans = 0
a = {}
for i in range(1,n+1):
    for j in range(1,n+1):
        tmp = math.gcd(i,j)
        a[tmp] = a.get(tmp, 0)
        a[tmp] += 1

for key, val in a.items():
    for j in range(1, n+1):
        ans += math.gcd(key,j) * val

print(ans)



Measured memory_bytes: 9184
#include<stdio.h>

int main(){
    int i,j,I[3],O[3],A[3];
    for(i=0;i<3;i++){
        for(j=0;j<3;j++)scanf("%d",&I[j]);
        for(j=0;j<3;j++)scanf("%d",&O[j]);
        if(O[2]<I[2]){
            O[1]--;
            O[2]+=60;
        }
        A[2]=O[2]-I[2];
        if(O[1]<I[1]){
            O[0]--;
            O[1]+=60;
        }
        A[1]=O[1]-I[1];
        A[0]=O[0]-I[0];
        printf("%d %d %d\n",A[0],A[1],A[2]);
    }
}


Measured memory_bytes: 2100
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
P = list(map(int, input().split()))

miss_count = 0

for i, p in enumerate(P, start=1):
    if not i == p:
        miss_count += 1

    if miss_count > 2:
        print('NO')
        sys.exit()
print('YES')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	int m, n, x, y;
	int a, b;
	int mx=-100005, mn=100005;
	cin >> n >> m >> x >> y;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		mx = max(mx, a);
	}
	for (int i = 0; i < m; i++)
	{
		cin >> b;
		mn = min(b, mn);
	}
	if (mn <= y && mn > x&&mx > x&&mx <= y && mx < mn)
	{
		cout << "No War" << endl;
	}
	else
		cout << "War" << endl;
	return 0;
}

Measured memory_bytes: 256
//#include "pch.h"
//#include "stdafx.h"
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define MIN(a, b)		((a) < (b) ? a : b)
#define MAX(a, b)		((a) > (b) ? a : b)
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)		/* 奇数 */
#define IsEven(x)		(!IsOdd((x)))					/* 偶数 */
#define ArrayLength(x)	(sizeof(x) / sizeof(x[0]))
#define DWORD_MAX		(0xFFFFFFFF)

typedef short SWORD;
typedef unsigned short WORD;
typedef long SDWORD;
typedef unsigned long DWORD;
typedef long long int QWORD;
#define N_MAX	(1000 * 100 + 1)
#define M_MAX	(1000 * 100 + 1)

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int N;
int dist[2][100000], id;
vector<int> g[100000];

void dfs(int id ,int nowTo, int nowFrom)
{
	if (0 <= nowFrom) {
		dist[id][nowTo] = dist[id][nowFrom] + 1;
	}

	for (auto &nextTo : g[nowTo]) {
		// 来た道は省く
		if (nextTo != nowFrom) {
			dfs(id, nextTo, nowTo);
		}
	}
}

int main()
{
	cin >> N;

	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	// 各頂点への距離を算出
	dfs(0, 0, -1);
	dfs(1, (N - 1), -1);

	// 各頂点の距離が相手より近いかどうか
	int retFennce = 0;
	int retSnuke = 0;
	for (int i = 0; i < N; i++) {
		if (dist[0][i] <= dist[1][i]) {
			retFennce++;
		} else {
			retSnuke++;
		}
	}

	if (retSnuke < retFennce) {
		cout << "Fennec" << endl;
	} else {
		cout << "Snuke" << endl;
	}
}


Measured memory_bytes: 11136
w,h,n=map(int,input().split())
l=[[0]*w for i in range(h)]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        for i in range(h):
            l[i][:x]=[1]*x
    elif a==2:
        for i in range(h):
            l[i][x:]=[1]*(w-x)
    elif a==3:
        for i in range(h-1,h-y-1,-1):
            l[i]=[1]*w
    else:
        for i in range(h-y):
            l[i]=[1]*w
    #print(l)
ans=0
for i in l:
    ans+=i.count(0)
print(ans)

Measured memory_bytes: 3064
a,b,c,x,y = map(int, input().split())

answer = a * x + b * y

while (2*c) < (a+b):
    if x >= 1 and y >= 1:
        answer = answer +  (2*c) - (a+b)
        x -= 1
        y -= 1
    else:
        break

while (2*c) < a:
    if x >= 1:
        answer = answer + (2*c) -a
        x -= 1
    else:
        break

while (2*c) < b:
    if y >= 1:
        answer = answer + (2*c) -b
        y -= 1
    else:
        break
print(answer)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  int n,k;
  cin>>n>>k;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  ll ans=INF;
  rep(bit,1<<n){
    auto b=a;
    int cnt=0;
    ll sum=0;
    ll maxv=0;
    rep(i,n){
      if(b[i]>maxv){
        ++cnt;
        chmax(maxv,b[i]);
        continue;
      }
      if(bit&(1<<i)){
        sum+=maxv-a[i]+1;
        b[i]+=maxv-a[i]+1;
        //cerr<<b[i]<<"\n";
      }
      if(b[i]>maxv)++cnt;
      chmax(maxv,b[i]);
    }
    //cerr<<cnt<<"\n";
    if(cnt>=k)chmin(ans,sum);
  }
  cout<<ans<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


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

int main() {
  int n,m,x,y,flg = 0;
  cin >> n >> m >> x >> y;
  vector<int> X(n), Y(m);

  rep(i,n) cin >> X[i];
  rep(i,m) cin >> Y[i];

  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());

  for (int i = x+1; i <= y; i++) {
    if (X[n-1] < i && i <= Y[0]) {
      flg = 1;
      break;
    }
  }
  if (flg) cout << "No War" << endl;
  else cout << "War" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>

int main(){
  int a, b;
  std::cin >> a >> b;
  int ans = 0;
  if(a > b){
    ans += a;
    --a;
  }else{
    ans += b;
    --b;
  }
  if(a > b)
    ans += a;
  else
    ans += b;

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

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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

vector<int64_t> fact, fact_inv;

void create_mod_tables(int num){
    fact.assign(num+1, 1);
    fact_inv.assign(num+1, 1);
    for(int i=1; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
    fact_inv[num] = inv_mod(fact[num]);
    for(int i=num; i>0; i--) fact_inv[i-1] = fact_inv[i] * i % MOD;
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

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

    static int64_t dp[3002][3002][3][3];
    dp[A][B][0][0] = 1;
    for(int i=A; i<=C; i++) for(int j=B; j<=D; j++) for(int a=0; a<3; a++) for(int b=0; b<3; b++){
        // 上、隅以外
        {
            add(dp[i+1][j][1][b], dp[i][j][a][b] * (j-1));
        }
        // 上、隅
        {
            add(dp[i+1][j][1][min(2, 1+b)], dp[i][j][a][b]);
        }
        // 右、隅以外
        {
            if(a != 1 || i==A) add(dp[i][j+1][a][1], dp[i][j][a][b] * (i-1));
        }
        // 右、隅
        {
            add(dp[i][j+1][min(2, 1+a)][1], dp[i][j][a][b]);
        }
    }

    int64_t ans = 0;
    for(int a=0; a<3; a++) for(int b=0; b<3; b++) add(ans, dp[C][D][a][b]);
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N; cin >> N;
  vector<int> d(N); for (int i =0; i<N; i++) cin >> d.at(i);
  sort(d.begin(),d.end());
  int ans = d.at(N/2) - d.at(N/2 - 1);
  if (ans <= 0) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m; cin >> n >> m;
	map<int,int> o;
	for(int i = 0; i < m; i++){
		int a, b; cin >> a >> b;
		o[a] ^= 1;
		o[b] ^= 1;
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) ans += o[i];
	if(ans) printf("NO\n");
	else printf("YES\n");
	return 0;
}


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

ll calc(ll x){
  if(x==1){
    return 1;
  }else{
    return 2*calc(x/2)+1;
  }
}

int main(){
  ll H;
  cin >> H;
  cout << calc(H) << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include<atcoder/fenwicktree.hpp>
using namespace std;
using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;



int main() {
	int n, q;
	cin >> n >> q;
	fenwick_tree<ll> fw(n);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		fw.add(i, a);
	}

	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (t) {
			int l, r;
			cin >> l >> r;
			cout << fw.sum(l, r) << endl;
		}
		else {
			int p, x;
			cin >> p >> x;
			fw.add(p, x);
		}
	}
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < n; i++)

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

    ll X;
    cin >> X;

    ll ans = 0;
    ll cnt = 0;
    ll i = 0;
    while (cnt < X) {
        i++;
        cnt += i;
        ans++;
    }

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

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

int main()
{
   int n, count=0;
   cin>>n;
   string s;
cin>>s;
for(int j=0;j<n;j++){

    if(s[j]=='A' && s[j+1]=='B' && s[j+2]=='C'){
        count++;
    }

}
   cout<<count;
return 0;
}






Measured memory_bytes: 3604
import java.util.Scanner;

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

    char[] S = scanner.next().toCharArray();
    int[] cnt = new int[4];
    for (char ch : S) {
      switch (ch) {
        case 'N':
          cnt[0] = 1;
          break;
        case 'S':
          cnt[1] = 1;
          break;
        case 'E':
          cnt[2] = 1;
          break;
        case 'W':
          cnt[3] = 1;
          break;
      }
    }
    if ((cnt[0] ^ cnt[1]) == 0 && (cnt[2] ^ cnt[3]) == 0) System.out.println("Yes");
    else System.out.println("No");
  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){//a c g t
    string S;
    cin >> S;
    ll s = S.size();
    ll ans = 0;
    bool now = 0;
    ll cnt = 0;
    rep(i,s){
        if(now && (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')){
            cnt++;
        }
        else if(now == false && (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')){
            now = true;
            cnt++;
        }
        else if(now && S[i] != 'A' && S[i] != 'C' && S[i] != 'G' && S[i] != 'T'){
            ans = max(ans,cnt);
            now = false;
            cnt = 0;
        }
        //cout << cnt << endl;
    }
    cout << max(ans,cnt) << endl;
}

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

int main() {
  string s;
  bool found = false;
  cin >> s;
  for (char i : s) {
    if (found) break;
    if (i=='9') found = true;
  }
  if (found) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
lst = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1]

while True:
    try:
        s = []
        num = int(input())
        for i in lst:
            if num >= i:
                num = num - i
                s.append(i)
        
        s.sort()
        print(*s)

    except EOFError:
        break


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

int main(int argc, char const *argv[])
{
	int N;
	cin >> N;
	vector<int> arr(N);
	for(int i = 0; i < N; i++)
		cin>> arr[i];

	sort(arr.begin(), arr.end());
	cout << (arr[arr.size() - 1] - arr[0]) << '\n';
	return 0;
}

Measured memory_bytes: 632
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;


int main() {

	long N, L; cin >> N >> L;

	long A[100009];
	long key = 0;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	for (int i = 1; i <= N - 1; i++) {

		if (A[i] + A[i + 1] >= L) key = i;

	}


	if (key != 0) cout << "Possible" << endl; else cout << "Impossible" << endl;

	if (key != 0) {

		for (int i = 1; i < key; i++) cout << i << endl;
		for (int i = N - 1; i > key; i--) cout << i << endl;
		cout << key << endl;

	}
}

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

int main() {
  int a,b,m;
  int smallA = 100000;
  int smallB = 100000;
  int smallWariNasi = 0;
  int smallWari = 200000;
  
  cin >> a >> b >> m;
  vector<int> vecA(a);
  vector<int> vecB(b);
  
  for(int i = 0; i < a; i++){
    cin >> vecA.at(i);
    if(smallA > vecA.at(i)) smallA = vecA.at(i);
  }
  for(int i = 0; i < b; i++){
    cin >> vecB.at(i);
    if(smallB > vecB.at(i)) smallB = vecB.at(i);
  }
  
  smallWariNasi = smallA + smallB;
  
  int tmpA,tmpB,wariKin;
  for(int i = 0; i < m; i++){
    cin >> tmpA >> tmpB >> wariKin;
    tmpA--;
    tmpB--;
    if(smallWari > vecA.at(tmpA) + vecB.at(tmpB) - wariKin){
      smallWari = vecA.at(tmpA) + vecB.at(tmpB) - wariKin;
    }
  }
  
  if(smallWariNasi <= smallWari) cout << smallWariNasi;
  else cout << smallWari;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int a[] = new int[N];
		
		for(int i=0; i<N; i++) {
			a[i]  = keyboard.nextInt();
		}
		
		int ans = 0;
		
		for(int i = 0; i<N; i++) {
			while(a[i]%2 != 1) {
				ans++;
				a[i] /= 2;
			}
		}
		
		System.out.println(ans);
		keyboard.close();	
	}
}


Measured memory_bytes: 48528
#include<iostream>
#include<stack>
#include<queue>
#include<map>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int x; sc(x)
    int n = 1;
    while (x > n * (n + 1) / 2) n++;
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N, M, Q; 
vector<int> A(50), B(50), C(50), D(50);

int dfs(int n, vector<int> &v){
  int ret = 0;
  if(n == N){
    REP(i, Q){
      if(v[B[i]-1]-v[A[i]-1] == C[i]) ret += D[i];
    }
    return ret;
  }

  FOR(i, (n == 0? 1: v[n-1]), M+1){
    v[n] = i;
    chmax(ret, dfs(n+1, v));
  }
  return ret;
}


signed main() {
  cin >> N >> M >> Q;

  REP(i, Q) cin >> A[i] >> B[i] >> C[i] >> D[i];

  vector<int> v(N);

  cout << dfs(0, v) << "\n";

  return 0;
}

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

int A, B, N, H, W;
int main()
{
	cin >> N >> H >> W;
	int ans = 0;
	for (int i = 1; i <= N; i++)
	{
		cin >> A >> B;
		if (A >= H && B >= W)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main(int argc, char const *argv[])
{
    string str;
    getline(cin,str);
    for(int i=0;i<str.length()-1;i++){
        if(str.at(i)=='A'&&str.at(i+1)=='C'){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c, d, e, f int
	fmt.Scan(&a, &b, &c, &d, &e, &f)
	a *= 100
	b *= 100

	var mizu, sato int
	ansSato := 0
	ansMizu := 100
	for na := 0; a*na <= f; na++ {
		for nb := 0; a*na+b*nb <= f; nb++ {
			if na == 0 && nb == 0 {
				continue
			}
			mizu = a*na + b*nb
			for nc := 0; mizu+c*nc <= f; nc++ {
				for nd := 0; mizu+c*nc+d*nd <= f; nd++ {
					sato = c*nc + d*nd
					if sato > mizu/100*e {
						continue
					}
					if sato*(ansSato+ansMizu) >= ansSato*(sato+mizu) {
						ansSato = sato
						ansMizu = mizu
					}
				}
			}
		}
	}
	fmt.Println(ansSato+ansMizu, ansSato)
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<map>
#include<cstdlib>
#include<cctype>
#include<string>

using namespace std;

typedef long long ll;
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;

const int d[]={0,1,0,-1};

#define SQR(x) ((x)*(x))
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define reps(i,j,n) for(int i = (j) ; i < (n) ; ++i )
#define rep(i,j) reps(i,0,j)
#define INF (1 << 30)
#define dout(x,n) fixed << setprecision(n) << x

int getint(){ int x; cin >> x; return x;}
string itos(int v) {stringstream ss;ss<<v;return ss.str();}
int stoi(string s) {int v; stringstream ss(s);ss>>v;return v;}

int main(){
  int N,M,k[101];
  bool p[101][101];
  while(cin >> N , N){
    fill_n(p[0],101*101,false);
    fill_n(k,101,1);
    rep(i,N){
      cin >> M;
      rep(j,M){
        int a = getint() - 1;
        p[i][a] = true;
      }
    }
    cin >> M;
    rep(i,M){
      int a = getint() - 1;
      rep(j,N) if(!p[j][a]) k[j] = 0;
    }
    int sum = 0;
    rep(i,N) sum += k[i];
    if(sum != 1) cout << -1 << endl;
    else rep(i,N){
        if(k[i]){
          cout << i + 1 << endl;
          break;
      }
      }
  }
}

Measured memory_bytes: 1180
from collections import Counter

n, p = map(int, input().split(" "))
s = list(map(int, input()))

ans = 0
if 10 % p == 0: # p = 2, 5
    for i, num in enumerate(s, 1):
        if num % p == 0:
            ans += i
    print(ans)
    exit()

s = s[::-1]
power = 1
t = [0] * len(s)
t[0] = s[0] % p
for i in range(1, len(s)):
    power = power * 10 % p
    t[i] = (t[i-1] + s[i] * power) % p

# counter = Counter(t)
# for i in counter.values():
#     ans += i * (i-1) // 2
# ans += counter[0]
# print(ans)

count = [0] * p
count[0] = 1
for i in t:
    ans += count[i]
    count[i] += 1
print(ans)


Measured memory_bytes: 12668
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,p=0,q=0;
  cin>>n>>a>>b;
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='c')cout<<"No"<<endl;
    if(s[i]=='a'){
      if(p<a+b)p++,cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }
    if(s[i]=='b'){
      if(p<a+b&&q<b)q++,p++,cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
    
    public static void sort(int array[], int array2[], int left, int right){
        if(left <= right){
            int p = array[(left + right) >>> 1];
            int l = left;
            int r = right;
            while(l <= r){
                while (array[l] < p){
                    l++;
                }
                while (array[r] > p){
                    r--;
                }
                if (l <= r){
                    int tmp = array[l];
                    array[l] = array[r];
                    array[r] = tmp;
                    
                    int tmp2 = array2[l];
                    array2[l] = array2[r];
                    array2[r] = tmp2;
                    l++;
                    r--;
                }
            }
            Main.sort(array, array2, left, r);
            Main.sort(array, array2, l, right);
        }
    }
    
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        //int x = stdIn.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        //String s = stdIn.next();
        //String t = stdIn.next();
        //char c[] = s.toCharArray();
        //int sum = 0;
        //boolean flag = true;
        for(int i = 0; i < n; i++){
            a[i] = stdIn.nextInt();
            b[i] = stdIn.nextInt();
        }
        
        Main.sort(a, b, 0, n - 1);
        
        //int q = stdIn.nextInt();
        
        for(int i = 0; i < n; i++){
            int index = 0;
            for(int j = i; j < n; j++){
                if(j < n - 1){
                    if(a[j] != a[j + 1]){
                        index = j;
                        //System.out.println("a" + i + " " + j);
                        Main.sort(b, a, i, j);
                        i = j + 1;
                    }
                }else if(j == n - 1 && n != 1){
                    if(a[j] == a[j - 1]){
                        index = j;
                        //System.out.println("a" + i + " " + j);
                        Main.sort(b, a, i, j);
                        i = j + 1;
                    }
                }
            }
            
        }
        
        for(int i = 0; i < n; i++){
            System.out.println(a[i] + " " + b[i]);
        }
        

        //System.out.println();
        //System.out.print();

        stdIn.close();
    }
}





Measured memory_bytes: 102908
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)

int main() {
	int n; cin >> n;
	int ga, sa, ba, gb, sb, bb; cin >> ga >> sa >> ba >> gb >> sb >> bb;

	vector<ll> dp(n + 1);
	iota(dp.begin(), dp.end(), 0);
	int A[3] = { ga, sa, ba };
	int B[3] = { gb, sb, bb };
	rep(i, 0, 3)
		rep(j, A[i], n + 1)
		dp[j] = max(dp[j], dp[j - A[i]] + B[i]);

	n = dp[n];
	dp.assign(n + 1, 0);
	iota(dp.begin(), dp.end(), 0);
	rep(i, 0, 3)
		rep(j, B[i], n + 1)
		dp[j] = max(dp[j], dp[j - B[i]] + A[i]);

	cout << dp[n] << endl;

	return 0;
}

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

int a[15];

int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int len = s.size();
	int ans = 0;
	for (int i = 0; i < len; i++)
	{
		if (s[i] == '0')
		{
			ans++;
			a[ans] = 0;
		}
		else if (s[i] == '1')
		{
			ans++;
			a[ans] = 1;
		}
		else if (s[i] == 'B' && ans >= 1) ans--;
	}
	
	for (int i = 1; i <= ans; i++) cout << a[i];
	return 0;
}


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

int main() {
    long long int A, B, N;
    cin >> A >> B >> N;
    
    if (N < B-1) {
        cout << A*N/B << endl;
    }else{
        cout << A*(B-1)/B << endl;
    }
}

Measured memory_bytes: 3620
let n = int (stdin.ReadLine())
let a = stdin.ReadLine().Split() |> Array.map int
let b = stdin.ReadLine().Split() |> Array.map int
let c = stdin.ReadLine().Split() |> Array.map int
Array.fold (fun (value, back) z -> if z = back + 1 then (b.[z - 1] + c.[back - 1] + value, z) else (b.[z - 1]+ value, z)) (0, -1) a |> fst |> printfn "%d"

Measured memory_bytes: 14044
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
using namespace std;
#define I inline
#define R register
#define inf 1073742823
#define FOR(i,begin,end) for(R int i=begin;i<=end;++i)
#define ROF(i,begin,end) for(R int i=begin;i>=end;--i)
signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b&&b!=c)||(a==c&&c!=b)||(b==c&&a!=c))cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1,n;
    cin>>n;
    vector<ll> a(n+1,0),b(n+1,0),c(n+1,0);
    ll dp[n+1][3]={
        0
    };
    for(ll i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    /*
    State
    dp[i][char j]: Denotes the maximum happiness  unitl the ith day if he performs activity j
    Recurrence
    dp[i][j]=max(dp[i-1][k]+ points/happiness for j) for all k except j
    */
    dp[1][1]=b[1];dp[1][2]=c[1];dp[1][0]=a[1];
    for(ll i=2;i<=n;i++){
        for(ll j=0;j<3;j++){
            ll points=0;
            if(j==0)
                points=a[i];
            else if(j<2)
                points=b[i];
            else
                points=c[i];
            for(ll k=0;k<3;k++){
                if(k!=j)
                    dp[i][j]=max(dp[i-1][k]+points,dp[i][j]);
            }
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

// https://atcoder.jp/contests/abc075/tasks/abc075_b
// 200点

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    vector<string> a(h);
    for (int i = 0; i < h; i++)
    {
        cin >> s[i];
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] == '#')
                a[i] += '#';
            else
            {
                int c = 0;
                if (i + 1 < h && s[i + 1][j] == '#')
                    c += 1;
                if (i - 1 >= 0 && s[i - 1][j] == '#')
                    c += 1;
                if (j + 1 < w && s[i][j + 1] == '#')
                    c += 1;
                if (j - 1 >= 0 && s[i][j - 1] == '#')
                    c += 1;
                if (i + 1 < h && j + 1 < w && s[i + 1][j + 1] == '#')
                    c += 1;
                if (i - 1 >= 0 && j + 1 < w && s[i - 1][j + 1] == '#')
                    c += 1;
                if (i + 1 < h && j - 1 >= 0 && s[i + 1][j - 1] == '#')
                    c += 1;
                if (i - 1 >= 0 && j - 1 >= 0 && s[i - 1][j - 1] == '#')
                    c += 1;
                a[i] += to_string(c);
            }
        }
    }
    for (int i = 0; i < h; i++)
    {
        cout << a[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int h, w, a, b;
int main() {
	int a, b;
	cin >> a >> b;
	if (0 >= a && 0 <= b) cout << "Zero" << endl;
	else {
		if (a > 0) cout << "Positive" << endl;
		else {
			int nt = b - a + 1;
			if (nt & 1) cout << "Negative" << endl;
			else cout << "Positive" << endl;
		}
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

typedef pair<int, int> P;



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

    int now=0;
    int ans=0;
    rep(i, n) {
        if(now > x) {
            break;
        }else{
            ans++;
            now += l[i];
        }
    }

    if(now <= x) {
        ans++;
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pir;
const int N=100010;
ll a[N],b[N];
set <pir> P,Q;
priority_queue <ll> p,q;
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int A,B,C;
    ll ans=0;
    cin>>A>>B>>C;
    for(int i=1;i<=A+B+C;i++) {
	int x=gi(),y=gi(),z=gi();
	ans+=x,a[i]=y-x,b[i]=z-x;
	P.insert(pir(a[i],i)),Q.insert(pir(b[i],i));
    }
    while(B&&C) {
	int t;
	if(*P.rbegin()>*Q.rbegin()) {
	    t=P.rbegin()->second;
	    ans+=a[t],p.push(b[t]-a[t]),--B;
	}
	else {
	    t=Q.rbegin()->second;
	    ans+=b[t],q.push(a[t]-b[t]),--C;
	}
	P.erase(pir(a[t],t)),Q.erase(pir(b[t],t));
    }
    while(B--) {
	int x=P.rbegin()->second,y=Q.rbegin()->second;
	if(q.top()+b[y]>a[x]) {
	    ans+=q.top()+b[y],q.pop(),q.push(a[y]-b[y]);
	    P.erase(pir(a[y],y)),Q.erase(pir(b[y],y));
	}
	else {
	    ans+=a[x];
	    P.erase(pir(a[x],x)),Q.erase(pir(b[x],x));
	}
    }
    while(C--) {
	int x=P.rbegin()->second,y=Q.rbegin()->second;
	if(p.top()+a[x]>b[y]) {
	    ans+=p.top()+a[x],p.pop(),p.push(b[x]-a[x]);
	    P.erase(pir(a[x],x)),Q.erase(pir(b[x],x));
	}
	else {
	    ans+=b[y];
	    P.erase(pir(a[y],y)),Q.erase(pir(b[y],y));
	}
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 15736
#include <iostream>

using namespace std;

class B {
	int n, d, x;
public:
	void solve()
	{
		int a;
		int day;
		int ans{ x };

		for (int i{ 0 }; i < n; i++)
		{
			cin >> a;
			day = 1;

			while (day <= d)
			{
				ans++;
				day += a;
			}
		}

		cout << ans << endl;
	}

	B()
	{
		cin >> n >> d >> x;
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

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

using namespace std;

int main() {
    while (1) {
        int n, t, l, b;

        cin >> n >> t >> l >> b;
        if (n == 0) break;
        int pn = 2 * n + 2;
        vector<double> p (pn, 0);
        vector<int> map(pn, 0);

        for (int i = 0; i < l; ++i) {
            int li; cin >> li; map[li] = 1;
        }
        for (int i = 0; i < b; ++i) {
            int bi; cin >> bi; map[bi] = -1;
        }
        p[0] = 1;

        for (int ti = 0; ti < t; ++ ti) {
            vector<double> temp(pn, 0);
            for (int i = 0; i < pn; ++i) {
                if (map[i] == -1) continue;
                else if (map[i] == 1) temp[i + n + 1] += p[i];
                else if (i == n) temp[i] += p[i];
                else {
                    for (int d = 1; d <= 6; ++d) {
                        int to = i > n ? i - (n + 1) + d : i + d;
                        if (to > n) to = n - (to - n);
                        if (map[to] == -1) to = 0;
                        temp[to] += p[i] * 1. / 6;
                    }
                }
            }
            for (int i = 0; i < pn; ++i) {
                p[i] = temp[i];
                //printf("%.2f ", p[i]);
            }
            //cout << endl;
        }

        printf("%.6f\n", p[n]);
    }
}


Measured memory_bytes: 3152
gets; k = gets.strip
c = k.count('1')
ki = k.to_i(2)
kr = k.reverse
df1, df2 = ki % (c+1), (c == 1 ? 0 : ki % (c-1))
t1, t2 = 1, -1
def calc(x)
	ret = 1
	while x != 0
		ret += 1
		x %= x.to_s(2).count('1')
	end
	return ret
end

kr.chars.map{|i|
	ans = 0
	if i == '0'
		ans = calc((df1+t1+c+1) % (c+1))
	elsif c == 1
		ans = 0
	else
		ans = calc((df2+t2+c-1) % (c-1))
	end
	t1 = t1 * 2 % (c+1)
	t2 = t2 * 2 % (c-1) if c != 1
	ans
}.reverse.each{|x|p x}

Measured memory_bytes: 42040
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let h: usize = iter.next().unwrap().parse::<usize>().unwrap();
    let w: usize = iter.next().unwrap().parse::<usize>().unwrap();
    
    let mut c = vec![vec![0i64;10];10];
    for y in 0..10 {
        for x in 0..10 {
            let k: i64 = iter.next().unwrap().parse::<i64>().unwrap();
            c[y][x] = k;
        }
    }

    let mut a = vec![vec![0i32;w];h];
    for y in 0..h {
        for x in 0..w {
            let k: i32 = iter.next().unwrap().parse::<i32>().unwrap();
            a[y][x] = k;
        }
    }

    warshall_floyd(&mut c);

    let mut ret = 0i64;
    for y in 0..h {
        for x in 0..w {
            if a[y][x] != -1 {
                ret += c[a[y][x] as usize][1];
            }
        }
    }
    println!("{}", ret);
}

#[doc = " d[x][y] = cost or INF, d[i][i] = 0"]
pub fn warshall_floyd(d: &mut [Vec<i64>]) {
    let n = d.len();
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                d[i][j] = std::cmp::min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
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(b<a) { a=b; return 1; } return 0; }

int main(){
  int n; cin >> n;
  map<ll,int,greater<int>> mp;
  rep(i,n){
    int a; cin >> a;
    mp[a]++;
  }
  ll ans = 0;
  int ok = 0;
  for(auto x : mp){
    if(2 <= x.second){
      if(ans == 0 && 4 <= x.second){
        ans = x.first*x.first;
        break;
      }
      if(ok == 0) ans = x.first;
      else ans *= x.first;
      ok++;
    }
    if(ok == 2) break;
  }
  cout << ans;
  cout << "\n";
  return 0;
}


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

#define C



#ifdef A

int main(void) {
	int n;

	cin >> n;

	if (n % 10 == 9)
	{
		cout << "Yes" << endl;
		return 0;
	}
	n /= 10;
	if (n % 10 == 9)
	{
		cout << "Yes" << endl;
		return 0;
	}

	cout <<"No" <<endl;
	return 0;
}
#endif // A



#ifdef B
const int MAX = 100000;
int main(void) {

	int n;
	int cunt = 0;
	for (size_t i = 0; i < n; i++)
	{
		int s, e;
		cin >> s >> e;
		cunt += e - s + 1;
	}
	cout << cunt << endl;


	return 0;
}

#endif // B



#ifdef C
int main(void) {
	int n;
	cin >> n;
	map<int, int> arr;
	for (size_t i = 0; i < n; i++)
	{
		int n;
		cin >> n;
		if (arr[n] == 0)arr[n] = 1;
		else arr[n] = 0;
	}
	int cunt = 0;
	for (auto a : arr)
		if (a.second)cunt++;

	cout << cunt << endl;
	return 0;
}
#endif // C

Measured memory_bytes: 4864
T = []
for i in range(52):
    T.append(False)
for i in range(int(input())):
    #print(input())
    mark, num = input().split()
    num = int(num) - 1
    if mark == "S":
        num += 0
    elif mark == "H":
        num += 13
    elif mark == "C":
        num += 26
    elif mark == "D":
        num += 39
    T[num] = True
for idx, i in enumerate(T):
    if not i:
        mark = idx // 13
        if mark == 0:
            mark = "S"
        elif mark == 1:
            mark = "H"
        elif mark == 2:
            mark = "C"
        elif mark == 3:
            mark = "D"
        print(mark, (idx % 13) + 1)



Measured memory_bytes: 5604
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x = a + b;
  int y = b + c;
  int z = c + a;
  int min = x;
  if (min > y)
    min = y;
  if (min > z)
    min = z;
  cout << min;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 50;

ll a, b, d;

bool ok(ll ax, ll ay, ll x, ll y) {
	return ax + ay > x + y || ax + ay == x + y && a * ax + b * ay > a * x + b * y;
}

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


	while(cin >> a >> b >> d, a | b | d) {
		ll ax = INF, ay = INF;
		for(ll x = 0; x <= 50000; x++) {
			if((d + a * x) % b == 0) {
				ll y = (d + a * x) / b;
				if(ok(ax, ay, x, y)) {
					ax = x;
					ay = y;
				}
			}
			if(a * x - d >= 0 && (a * x - d) % b == 0) {
				ll y = (a * x - d) / b;
				if(ok(ax, ay, x, y)) {
					ax = x;
					ay = y;
				}
			}
			if(d - a * x >= 0 && (d - a * x) % b == 0) {
				ll y = (d - a * x) / b;
				if(ok(ax, ay, x, y)) {
					ax = x;
					ay = y;
				}
			}
		}
		cout << ax << " " << ay << endl;
	}
}

Measured memory_bytes: 3176
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let primes = get_primes(n);
    let mut dict = HashMap::new();
    for i in 1..n + 1 {
        let factors = factorize(i, &primes);
        for (&fact, &value) in factors.iter() {
            *dict.entry(fact).or_insert(1) += value;
        }
    }
    let mut over75 = 0;
    let mut over25 = 0;
    let mut over15 = 0;
    let mut over5 = 0;
    let mut over3 = 0;

    for &count in dict.values() {
        if count >= 3 {
            over3 += 1;
        }
        if count >= 5 {
            over5 += 1;
        }
        if count >= 15 {
            over15 += 1;
        }
        if count >= 25 {
            over25 += 1;
        }
        if count >= 75 {
            over75 += 1;
        }
    }
    debug!(over3);
    debug!(over5);
    debug!(dict);
    let mut ans = over75;
    ans += over25 * (over3 - 1);
    ans += over15 * (over5 - 1);
    ans += over5 * (over5 - 1) * max(over3 - 2, 0) / 2;
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn get_primes(n: usize) -> Vec<usize> {
    let mut is_prime = vec![true; n + 1];
    let mut primes = Vec::new();
    is_prime[0] = false;
    is_prime[1] = false;

    for i in 2..n + 1 {
        if is_prime[i] {
            primes.push(i);
            let mut j = 2 * i;
            while j < n {
                is_prime[j] = false;
                j += i;
            }
        }
    }
    primes
}

fn factorize(mut num: usize, primes: &Vec<usize>) -> std::collections::HashMap<usize, usize> {
    // max_primes >= (num)^(1/2)
    let mut dict = std::collections::HashMap::new();
    for &p in primes.iter() {
        while num % p == 0 {
            *dict.entry(p).or_insert(0) += 1usize;
            num /= p;
        }
        if num == 1 {
            break;
        }
    }
    if num != 1 {
        dict.insert(num, 1);
    }
    dict
}


Measured memory_bytes: 4352