akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
long long n;
vector<bool> honest(15, true);
vector<vector<pair<long long, bool> > > a(15);
long long maxv = 0;

int main(){
    cin >> n;

    for(long long i = 0; i < n; i++){
        long long A;
        cin >> A;
        for(long long j = 0; j < A; j++){
            long long x, y;
            cin >> x >> y;
            x--;
            if(y == 1){
                a[i].push_back(make_pair(x, true));
            }
            else{
                a[i].push_back(make_pair(x, false));
            }
        }
    }

    long long maxv = 0;

    for(long long bit = 0; bit < (1 << n); bit++){
        for(long long mask = 0; mask < n; mask++){
            if(bit & (1 << mask)){
                honest[mask] = true;
            }
            else{
                honest[mask] = false;
            }
        }
        long long count = 0;
        bool flag = true;
        for(long long i = 0; i < n; i++){
            if(honest[i] == true){
                count++;
                for(long long j = 0; j < a[i].size(); j++){
                    if(a[i][j].second != honest[a[i][j].first]){
                        flag = false;
                        break;
                    }
                }
            }
        }
        if(flag == true){
            maxv = max(maxv, count);
        }
    }

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

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(int i = (int)k; i < (int)n; i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, k, n) for(int i = (int)n-1; i > (int)k-1; i--)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl;
#define pb push_back

typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    while(cin>>n>>m,n){
        int h[1510]={};
        int w[1510]={};
        map<int,int> h2;
        map<int,int> w2;

        rep(i,n) cin >> h[i+1];
        rep(i,m) cin >> w[i+1];
        REP(i,1,n+1) h[i] += h[i-1];
        REP(i,1,m+1) w[i] += w[i-1];
        REP(i,1,n+1){
            rep(j,i){
                h2[h[i]-h[j]]++;
            }
        }
        REP(i,1,m+1){
            rep(j,i){
                w2[w[i]-w[j]]++;
            }
        }
        ll ans = 0;
        for(pair<int,int> o : h2){
            ans += w2[o.first]*o.second;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 34384
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 105;
const ll mm = 1e+18;
void solve()
{
    int d,t,s;
    cin>>d>>t>>s;
    if(s*t>=d) cout<<"Yes";
    else cout<<"No";
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 3648
#include "iostream"
#include "algorithm"
#include "cmath"

using namespace std;

int main()
{	
	int H, W;
	cin >> H >> W;
	char s[50][50];

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> s[i][j];
		}
	}

	//上下左右を同時に黒く塗るしか出来ないので
	//上下左右が全て白の黒点（画面端・角含む）は描画出来ない。

	bool flg = true;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '#') {
				//上下左右がいずれも白だった場合、不可
				if((i==0) || s[i-1][j] != '#'){ //上
					if ((i == H) || s[i + 1][j] != '#'){ //下
						if (j == 0 || s[i][j - 1] != '#') { //左
							if (j == W || s[i][j + 1] != '#') {
								flg = false;
								break;
							}

						}
					}
				}
			}
		}
		if (!flg) {
			break;
		}
	}

	if (flg)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  Test
//
//  Created by Nag on 2017/08/18.
//  Copyright ?? 2017??´ Nag. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>

using namespace std;

int main(void) {
    int n;
    int b, f, r, v;
    int i, j, k;
    
    int room[4][3][10];

    for(i=0; i<4; i++) {
        for(j=0; j<3; j++) {
            for(k=0; k<10; k++) {
                room[i][j][k] = 0;
            }
        }
    }

    cin >> n;
    for(i=0; i<n; i++) {
        cin >> b >> f >> r >> v;
        room[b-1][f-1][r-1] += v;
    }

    for(i=0; i<4; i++) {
        for(j=0; j<3; j++) {
            for(k=0; k<10; k++) {
                cout << " " << room[i][j][k];
            }
            cout << endl;
        }
        if(i<3) cout << "####################" << endl;
    }

    return 0;
}

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

using namespace std;

int n, a[100005], f, ans;
int ok;

int main() {

cin >> n;

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

ok = 3;
f = a[1];
ans++;

for(int i = 2; i <= n; ++i){
    if(ok == 3){
        if(a[i] > f) {ok = 2; f = a[i];}
        else if (a[i] < f) {ok = 1; f = a[i];}
    }
    else if(ok == 2){
        if(a[i] < f) ok = 0;
        else f = a[i];
    }
    else {
        if(a[i] > f) ok = 0;
        else f = a[i];
    }
    if(!ok) {ok = 3; f = a[i]; ans++;}
}

cout << ans;

return 0;

}


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

int main() {
    int N; 
    cin >> N;
    vector<int> H(N+1);
    for(int i=1; i<=N; i++){
        cin >> H.at(i);
    }
    int dp[N+1];
    dp[1]=0;
    dp[2]=abs(H[2]-H[1]);

    for(int i=3; i<=N; i++){
        dp[i] = min(dp[i-1] + abs(H[i]-H[i-1]), dp[i-2] + abs(H[i]-H[i-2]));
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main() {
    while (true) {
        int n, p, bowl, player;
        int stone[50] = {};
        cin >> n >> p;
        if (n == 0 && p == 0) {
            break;
        }
        bowl = p;
        for (player = 0; stone[player] < p; player = (player + 1) % n) {
            if (bowl > 0) {
                ++stone[player];
                --bowl;
            }
            else {
                bowl = stone[player];
                stone[player] = 0;
            }
        }
        cout << player << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FASTIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N = 200005, M = 1000000007, BIG = 0x3f3f3f3f;

int ct = 0;

struct Mint {
  int value;
  Mint(int _value = 0) : value(_value) {}
  operator int() { return value; }
  Mint operator - (const Mint& _a) { int ans = value - _a.value; return ans < 0 ? M + ans : ans; }
  Mint operator + (const Mint& _a) { int ans = value + _a.value; return ans - (ans >= M) * M; }
  Mint operator * (const Mint& _a) { return (ll)value * _a.value % M; }
  bool operator == (const Mint& _a) { return value == _a.value; }
  bool operator != (const Mint& _a) { return value != _a.value; }
};
Mint& operator += (Mint& _a, const Mint& _b) { return _a = _a + _b; }
Mint& operator -= (Mint& _a, const Mint& _b) { return _a = _a - _b; }
Mint& operator *= (Mint& _a, const Mint& _b) { return _a = _a * _b; }
istream& operator >> (istream& is, Mint& _a) { is >> _a.value; return is; }
ostream& operator << (ostream& os, Mint& _a) { os << _a.value; return os; }

Mint ModPow(Mint _a, ll _b) {
  Mint ans = 1;
  while (_b > 0) {
    if (_b & 1)
      ans *= _a;
    _a = _a * _a;
    _b >>= 1;
  }
  return ans;
}

Mint MMI(Mint _a) {
  int ax = _a, bx = M, sx = 1, tx = 0;
  while (bx) {
    int qx = ax / bx;
    ax -= qx * bx;
    sx -= qx * tx;
    swap(ax, bx);
    swap(sx, tx);
  }
  return sx >= 0 ? sx : sx + M;
}

Mint C(int _a, int _b) {
  Mint ans = 1;
  for (int i = 0; i < _b; i++) {
    ans *= _a - i;
    ans *= MMI(i + 1);
  }
  return ans;
}

Mint n, a, b;

bool Read() {
  cin >> n;
  if (cin.eof())
    return 0;
  cin >> a >> b;

  return 1;
}

void Process() {
  cout << ModPow(2, n) - Mint(1) - C(n, a) - C(n, b) << "\n";
}

int main() {
  FASTIO();

  while (Read())
    Process();

  return 0;
}

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
//#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define ff first
#define tcase int _; cin>> _; for( ; _; --_)
#define ss second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	for(;exp; exp>>=1){
		if(exp % 2 == 1) total = mod(((mod(total, m)) * (mod(base, m))), m);
		base= mod((mod(base, m) * mod(base, m)), m);
	}
	return total;
}

int n;

vi prime;

vi freq(MAX, 0);
    
void solve(){
    cin >> n;
    
    vi a(n);
    
    for(int i = 0; i < n; ++i){
        cin>> a[i];
        freq[a[i]]++;    
    }

    bool pw = true;

    for(int i = 2; i < MAX; ++i){
        int c = 0;
        for(int j = i; j <= MAX; j += i) c += freq[j];
        if(c >= 2){
            pw = false;
            break;
        }
    }

    int sw = a[0];
    for(int i = 1; i < n; ++i) sw = gcd(a[i], sw);
    
    if(pw) cout<< "pairwise coprime\n";
    else if(sw == 1) cout<< "setwise coprime\n";
    else cout<< "not coprime\n";
}

int32_t main(){
	fastio;
	solve();
	return 0;
}



Measured memory_bytes: 11040
a,b=gets.split.map &:to_i
g=b-a

if b-a==1
  p 1
elsif a.abs==b.abs
  p 1
elsif a>=0 && b>=0
  if b>=a
    p b-a
  else
    if b==0
      p a+1
    else
      p a-b+2
    end
  end
elsif a>=0
  p (a.abs-b.abs).abs+1
elsif b>=0
  if b==0
    p (a.abs-b.abs).abs
  else
    p (a.abs-b.abs).abs+1
  end
else
  if b>=a
    p (a.abs-b.abs).abs
  else
    p (a.abs-b.abs).abs+2
  end
end

Measured memory_bytes: 1916
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collections;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] dp = new int[n+1];
        dp[0] = 0;
        dp[1] = 1;
        
        for (int i = 2; i <= n; i++) {
            dp[i] = dp[i-1] + 1;
            
            for (int j = 1; Math.pow(6, j) <= i; j++) {
                dp[i] = Math.min(dp[i], dp[i-(int)Math.pow(6, j)]+1);
            }
            
            for (int j = 1; Math.pow(9, j) <= i; j++) {
                dp[i] = Math.min(dp[i], dp[i-(int)Math.pow(9, j)]+1);
            }
        }
        
        System.out.println(dp[n]);
    }
}



Measured memory_bytes: 24660
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <limits>
#include <type_traits>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;


// Connected component(DFS)
void dfs(int n, int comp[], vector<int> G[]) {
  int i, j, vertex, neighbor, color[100000];
  REP(i, 100000) color[i] = 0;
  stack<int> S;

  for (i = 0; i < n; i++) color[i] = 0;

  for (i = 0; i < n; i++) {
    if (color[i] == 0) {

      S.push(i);
      while (!S.empty()) {
        vertex = S.top();
        S.pop();
        color[vertex] = 1;
        comp[vertex] = i;
        for (j = 0; j < (int) G[vertex].size(); j++) {
          neighbor = G[vertex][j];
          if (color[neighbor] == 0) S.push(neighbor);
        }
      }
    }
  }
}


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> siz;

    UnionFind(int N) : par(N), siz(N, 1) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
          par[i] = i;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        siz[ry] += siz[rx];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x){
      return siz[root(x)];
    }
};

int main(){
    string s;
    int t, f, q, rev = 1;
    char c;

    cin >> s >> q;
    REP(i, q){
      cin >> t;
      if(t == 1){
        rev *= -1;
      } else {
        cin >> f >> c;
        if(rev < 0){
          if(f == 1){
            f = 2;
          } else {
            f = 1;
          }
        }

        if(f == 1){
          s.insert(s.begin(), c);
        } else {
          s.insert(s.end(), c);
        }
      }
    }

    if(rev < 0) reverse(s.begin(), s.end());

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	int n,i,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
		ans+=(i+n-n%i)*((n-n%i-i)/i+1)/2;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            solve(in);
        }
    }

    private static void solve(BufferedReader in) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        int N = Integer.parseInt(st.nextToken()), M = Integer.parseInt(st.nextToken());

        int[] l = new int[N + 1], r = new int[N + 1];
        @SuppressWarnings("unchecked")
        List<Integer>[] nByLen = new List[M + 1];

        for (int n = 1; n < N + 1; n++) {
            st = new StringTokenizer(in.readLine());
            l[n] = Integer.parseInt(st.nextToken());// 1 <= l <= r <= M
            r[n] = Integer.parseInt(st.nextToken());
            int len = r[n] - l[n] + 1;
            if (nByLen[len] == null) {
                nByLen[len] = new ArrayList<>();
            }
            nByLen[len].add(n);
        }

        int accum = N;

        fenwick = new int[M + 1];
        for (int d = 1; d < M + 1; d++) {
            int sum = accum;
            for (int e = d; e < M + 1; e += d) {
                sum += faccum(e);
            }
            System.out.println(sum);
            if (nByLen[d] != null) {
                accum -= nByLen[d].size();
                for (int i : nByLen[d]) {
                    fadd(l[i], 1);
                    fadd(r[i] + 1, -1);
                }
            }
        }
    }

    private static int[] fenwick;

    private static int faccum(int i) {
        int sum = 0;
        for (; i > 0; i -= i & -i) {
            sum += fenwick[i];
        }
        return sum;
    }

    private static void fadd(int i, int a) {
        for (; i < fenwick.length; i += i & -i) {
            fenwick[i] += a;
        }
    }
}

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

const ll MOD = 1000000007LL;

int main(){
    int n;
    cin >> n;
    ll ans = 1;
    for(int i = 1; i <= n; i++){
        ans = ans * i;
        if(ans >= MOD) ans %= MOD;
    }
    cout << ans << endl;
}


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

int n, y;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  cin >> n >> y;

  int j=0, k=0;
  for (int i=0; i<=n; i++) {
    j = max(0, ((n-i)*1000-(y-10000*i))/(-4000));
    k = max(0, ((y-10000*i)-(n-i)*5000)/(-4000));
    if (i+j+k == n && 10000*i + 5000*j + 1000*k == y) {
      cout << i << " " << j << " " << k << "\n";
      break;
    }
    if (i == n) {
      cout << "-1 -1 -1" << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
mod = 10 ** 9 + 7

S = [[0] * (K + 1) for i in range(N + 1)]
S[0][0] = 1
for n in range(1, N + 1):
	for k in range(1, K + 1):
		S[n][k] = (S[n - 1][k - 1] + k * S[n - 1][k]) % mod
print(sum(S[N][:K+1])%mod)


Measured memory_bytes: 29348
#include "bits/stdc++.h"
constexpr auto MAX = 10E9+1;
using namespace std;
using ll = long long;
using VI = vector<int>;

int main()
{
    int n;
    cin >> n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    for (int i = 0; i < n; i++) {
        string s = "";
        cin >> s;
        if (s == "AC") ac++;
        else if (s == "TLE") tle++;
        else if (s == "WA") wa++;
        else if (s == "RE") re++;
    }

    cout << "AC x " << ac << "\n";
    cout << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n";
    cout << "RE x " << re << "\n";
    

    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>

#define MOD 1000000007

using ll = long long;

int main() {
    char S[100005];
    scanf("%s\n", S);
    ll N = strlen(S);

    ll mod13[13];
    mod13[0] = 1;
    int exponent = 1;

    for (int i = 0; i < N; i++) {
        ll mod13_buf[13] = {0};
        int c = (S[N - i - 1] == '?') ? -1 : S[N - i - 1] - '0';
        for (int n = 0; n < 10; n++) {
            if (c != -1 && c != n) continue;
            int m = n * exponent % 13;
            for (int r = 0; r < 13; r++) {
                mod13_buf[(r + m) % 13] += mod13[r];
            }
        }
        exponent = exponent * 10 % 13;
        for (int j = 0; j < 13; j++) {
            mod13[j] = mod13_buf[j] % MOD;
        }
    }
    printf("%lld\n", mod13[5]);
}


Measured memory_bytes: 256
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/04/04.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC126
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

template<class T> inline bool chmin(T& a, T b){ if(a>b){a=b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b){ if(a<b){a=b; return 1;} return 0;}

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__

void solve(void){
  
  int N, K;
  string S;
  
  cin >> N >> K;
  cin >> S;
  
  S[K-1]=S[K-1]-('A'-'a');
      
  cout << S << endl;
  
  return;
   
}



#define TESTCASES 1

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}



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

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

    long long n;
    cin >> n;
    map<long long, long long> mp;
    for(long long i = 0; i < n; i++){
        long long a;
        cin >> a;
        mp[a]++;
    }

    if(mp.size() == 1){
        for(auto x : mp){
            if(x.first == 0){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
            break;
        }
        return 0;
    }

    if((n % 3 != 0) || (mp.size() > 3)){
        cout << "No" << endl;
        return 0;
    }

    if(mp.size() == 2){
        vector<long long> A, B;
        for(auto x : mp){
            A.push_back(x.first);
            B.push_back(x.second);
        }
        if(A[1] == 0){
            swap(A[0], A[1]);
            swap(B[0], B[1]);
        }
        if(A[0] != 0){
            cout << "No" << endl;
            return 0;
        }
        if(B[0] * 2 == B[1]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        return 0;
    }else if(mp.size() == 3){
        vector<long long> A, B;
        for(auto x : mp){
            A.push_back(x.first);
            B.push_back(x.second);
        }
        sort(B.begin(), B.end());
        if(B[0] == B[2] and (A[0] ^ A[1]) == A[2]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        return 0;
    }

    // cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=1e5+5;
//const int MOD=1e9+7;


int main(){
	int N;
	cin>>N;
	int amax,bthen;
	rep(i,N){
		int a,b;
		cin>>a>>b;
		if(a>amax){
			amax=a;
			bthen=b;
		}
	}
	cout<<amax+bthen;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  if (A + B < C + D) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
    string st;
    cin>>st;
    if(st.substr(0,3)!="2018")st.replace(0,4,"2018");
    cout<<st<<endl;
}

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

#define ll long long int

const ll mod=1e9+7;

int main()
{
    ll n,m;
    cin>>n;
    ll ara[n];
    ll sum[n];

    for(int i=0;i<n;i++) cin>>ara[i];
    for(int i=n-1;i>=0;i--){
        if(i==n-1) sum[i]=ara[i];
        else sum[i]=(sum[i+1]+ara[i])%mod;
    }

    ll ans=0;

    for(int i=0;i<n-1;i++){
        ll p=(sum[i+1]*ara[i])%mod;
        ans=(ans + p)%mod;
    }

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


Measured memory_bytes: 6760
#include<iostream>
using namespace std;
char mas[100][100];
int H ,W ,cnt=0;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,-1,0,1 };
char n;
void dfs(int x ,int y);

int main(){
  while(1){
    cnt = 0;
    cin >> H >> W;
    if ( H == 0 && W == 0 ){
      break;
    }
 
    for (int i=0 ; i<H ; i++ ){
      for ( int j=0 ; j<W ; j++ ){
	cin >> mas[i][j];
      }
    }
    for ( int i=0 ; i<H ; i++ ){
      for ( int j=0 ; j<W ; j++ ){
	if ( mas[i][j] == '#' || mas[i][j] == '@' || mas[i][j] == '*' ){
	  cnt++;
	  n = mas[i][j];
	  dfs (j , i );
	}
      }
    }
    cout << cnt << endl;
  }
}


void dfs (int x ,int y ){
  mas[y][x] = '.';
  for (int i=0 ; i<4 ; i++ ){
    int nx = x + dx[i];
    int ny = y + dy[i]; 
   if ( nx >= 0 && nx < W && ny >= 0 && ny < H && n == mas[ny][nx]){
      dfs ( nx ,ny );

    }
  }
  return ;  
}

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

int f(std::vector<int> p) {
    int largest = -1;

    for (int i = 0; i < p.size(); i++) {
        if (largest < p[i]) {
            largest = p[i];
        }
    }

    int result = 0;
    for (int i = 0; i < p.size(); i++) {
        if (largest == p[i]) {
            result += p[i] / 2;
            largest = -1;
        } else {
            result += p[i];
        }
    }

    return result;
}

int main() {

    int n;
    std::cin >> n;

    std::vector<int> p;
    for (int i = 0; i < n; i++) {
        int tmp;
        std::cin >> tmp;
        p.push_back(tmp);
    }

    int result = f(p);
    std::cout << result << std::endl;

    return 0;
}


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

using namespace std;

int main()
{
	int  n,i;
	double a;
	string str[8];
	str[0]="1:";
	str[1]="2:";
	str[2]="3:";
	str[3]="4:";
	str[4]="5:";
	str[5]="6:";
	
	cin >> n;
	
	for(i=0;i<n;i++)
	{
		cin >> a;
		if(a<165.0)
		{
			str[0]+="*";
		}
		else if(a>185.0)
		{
			str[5]+="*";
		}
		else
		{
			int aa;
			aa=(a-160.0)/5.0;
			str[aa]+="*";
		}
	}
	for(i=0;i<6;i++)
		cout << str[i] << endl;
}

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

int main() {
    int a, b, c; cin >> a >> b >> c;
    if (a == b && b == c) {
        cout << 1 << endl;
    }
    else if (a != b && b != c && c != a) {
        cout << 3 << endl;
    }
    else cout << 2 << endl;

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli	long long int
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
#define rep(i,l,r)	for(i=l;i<r;i++)
using namespace std;
int main()
{
	string s1,s2;
	cin >> s1 >> s2;
	s2=s2+s1;
	cout << s2 << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	ll a, b, n;
	cin >> a >> b >> n;
	
	ll x;
	
	if( n < b ) x = n;
	else if( n >= b ) x = b - 1;

	cout << (a * x / b) - a * (x / b) << endl;
	
	return 0;
}


Measured memory_bytes: 3652
import java.util.*;

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

    int count0 = 0;
    int count1 = 0;
    for (int i = 0; i < S.length(); i++) {
      if (S.charAt(i) == '0') {
        count0++;
      } else {
        count1++;
      }
    }
    
    System.out.println(Math.min(count0, count1) * 2);
  }
}

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

long parse_eq(string x) {
    string char_stack = "";
    long res = 0;
    for (int i = 0; i < x.length(); ++i)
    {
        if (x[i] != '+') {
            char_stack += x[i];
        }
        else
        {
            res += stol(char_stack);
            char_stack = "";
        }
    }
    res += stol(char_stack);
    return res;
}

long sum = 0;
string S;
void dfs(int pos, string x)
{
    if (pos == S.size()) {
        sum += parse_eq(x);
        return;
    }

    dfs(pos+1, x + S[pos]);
    dfs(pos+1, x + '+' + S[pos]);
}

int main() {
    cin >> S;

    if (S.length() == 1) {
        cout << S << endl;
    } else {
        string s = "";
        s += S[0];

        dfs(1, s);

        cout << sum << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();

        int sum = a + b + c;
        int max = Math.max(a, Math.max(b, c));
        int ans = max * 10 + (sum - max);

        System.out.println(ans);

    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 21076
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7


def main():
    n = int(input())
    k = int(input())
    x = int(input())
    y = int(input())
    r = x * min(n,k)
    r += y * max(0,n-k)
    return r



print(main())


Measured memory_bytes: 5672
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,x;
	cin>>k>>x;

	int mini = max(-1000000,(x-k+1));
	int maxi = min(1000000,(x+k-1));

	for(int i=mini; i<=maxi; i++)
	{
		cout<<i<<" ";
	}
	cout<<endl;
	
	return 0;
}


Measured memory_bytes: 256
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, k: usize, c: usize);
    let s: Vec<_> = it.next().unwrap().bytes().collect();
    let mut ls = vec![];
    let mut rs = vec![];
    let mut cur = s.iter().position(|&x| x == b'o').unwrap();
    ls.push(cur);
    for i in (cur + 1)..n {
        if ls.len() == k {
            break;
        }
        if i - cur <= c || s[i] == b'x' {
            continue;
        }
        ls.push(i);
        cur = i;
    }
    let mut cur = s.iter().rposition(|&x| x == b'o').unwrap();
    rs.push(cur);
    for i in (0..cur).rev() {
        if rs.len() == k {
            break;
        }
        if cur - i <= c || s[i] == b'x' {
            continue;
        }
        rs.push(i);
        cur = i;
    }
    rs.reverse();
    for i in 0..k {
        if ls[i] == rs[i] {
            println!("{}", ls[i] + 1);
        }
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 5596
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

char A[1001][1001];
int H, W;

bool f(int x, int y){
  if(x < 0) return 0;
  if(y < 0) return 0;
  if(x >= W) return 0;
  if(y >= H) return 0;
  return (A[y][x] == '.');
}

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

int main(){
  cin >> H >> W;

  rep(i, H){
    cin >> A[i];
  }

  int count = 0;
  stack<pair<int, int>> st;
  rep(h, H){
    rep(w, W){
      if(A[h][w] == '#'){
        st.push(make_pair(h, w));
        count++;
      }
    }
  }

  int ans = 0;
  while(count != H * W){
    ans++;
    stack<pair<int, int>> st2;
    while(st.size()){
      pair<int, int> p = st.top();
      st.pop();
      int y = p.first;
      int x = p.second;
      rep(i, 4){
        int xx = x + dx[i];
        int yy = y + dy[i];
        if(f(xx, yy)){
          A[yy][xx] = '#';
          count++;
          st2.push(make_pair(yy, xx));
        }
      }
    }
    st = st2;
  }

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


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> c(n), d(n);
    for(int i=0;i<n;i++){
    	cin >> c[i] >> d[i];
    }
    sort(be(c));
    sort(be(d));
    ll mi, ma;
    if(n&1){
    	mi = c[n/2];
    	ma = d[n/2];
    	cout << ma - mi + 1LL << endl;
    }else{
    	ll ans = 0;
    	if((c[n/2] - c[n/2 - 1]) % 2LL == 0LL){
    		mi = (c[n/2] + c[n/2 - 1]) / 2LL;
    	}else{
    		mi = (c[n/2] + c[n/2 - 1]) / 2LL + 1LL;
    		ans++;
    	}
    	if((d[n/2] - d[n/2 - 1]) % 2LL == 0LL){
    		ma = (d[n/2] + d[n/2 - 1]) / 2LL;
    	}else{
    		ma = (d[n/2] + d[n/2 - 1]) / 2LL;
    		ans++;
    	}
    	ans += (ma - mi) * 2LL + 1LL;
    	cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 6348
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

ll lcm(ll d1, ll d2){
    return d1 / __gcd(d1, d2) * d2;
}


int main(void){
	int n; cin >> n;
	ll nowt, nowa;
	rep(i, n){
		ll t, a; cin >> t >> a;
		if(i == 0){
			nowt = t, nowa = a;
		}else{
			// printf("sa %d %d\n", nowt, nowa);
			if(t >= nowt && a >= nowa){
				nowt = t; nowa = a;
				continue;
			}
			ll dt, da;
		
			if(nowt % t == 0) dt = nowt / t;
			else  dt = nowt / t + 1;
			if(nowa % a == 0) da = nowa / a;
			else da = nowa / a + 1;
			// printf("%d %d\n", dt, da);
			ll s;
			s = max(dt, da);
			// printf("%lld\n", s);
			nowt = t * s; nowa = a * s;
			while(nowt < t || nowa < a){
				nowt *= 2; nowa *= 2;
			}
			// printf("%d %d\n", nowt, nowa);
		}
	}
	printf("%lld\n", nowt + nowa);
	return 0;
}

Measured memory_bytes: 256
txt = input()
n = (int)(input())
count = 0
sentou = ""
saigo = ""
for i in range(n):
  temp = input()
  if temp[0] == '1':
    count += 1
  else:
    sec, moji = (int)(temp.split(" ")[1]), temp.split(" ")[2]
    if (sec + count) % 2 == 1:
      sentou = moji + sentou
    else:
      saigo += moji
if count % 2 == 1:
  txt = saigo[::-1] + txt[::-1] + sentou[::-1]
else:
  txt = sentou + txt + saigo
print(txt)    

Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define sp putchar(' ')
#define en putchar('\n')
const int MAXN = 1000005 ;
using namespace std ;
using VI = vector<int64_t> ;
int n, m, T, u, v, a, b ;

bool isP[MAXN] ;
vector<int> primes ;
void getP() {
    memset(isP, true, sizeof(isP)) ;
    isP[0] = isP[1] = false ;
    primes.clear() ;
    for(int i = 2; i < MAXN; ++ i) {
        if(!isP[i]) continue ;
        primes.push_back(i) ;
        for(int j = 2;1LL*j*i < MAXN; ++ j) {
            isP[j * i] = false ;
        }
    }
}

int factor[20][2] ;
int factCnt ;

int64_t getFactor(int x)
{
    int64_t sum = 1 ;
    factCnt = 0 ;
    for(int i = 0;primes[i] < x; ++ i) {
        if (isP[x]) break ;
        if (x % primes[i] == 0) {
            for (factor[factCnt][1] = 0;x % primes[i] == 0;x /= primes[i]) {
                ++ factor[factCnt][1] ;
            }
            sum *= (factor[factCnt][1] + 1) ;
            factor[factCnt ++ ][0] = primes[i] ;
        }
    }
    if (x != 1) {
        factor[factCnt][1] = 1 ;
        sum *= (factor[factCnt][1] + 1) ;
        factor[factCnt ++ ][0] = x ;
    }
    return sum ;
}


int main()
{
    getP() ;
    ios::sync_with_stdio(false) ;
    while(cin >> n) {
        int64_t ans = 0 ;
        for(int i = 1;i < n; ++ i) {
            ans += getFactor(i) ;
        }
        cout << ans << endl ;
    }
}


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

using namespace std;

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

    vector<int> a(n), b(n+1), c(n);
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=1; i<=n; i++) cin >> b[i];
    for (int i=1; i<n; i++) cin >> c[i];

    int ans = 0;

    for (int i=0; i<n; i++) {
        ans += b[a[i]];
        if (i < n-1 && a[i]+1 == a[i+1])
            ans += c[a[i]];
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
Z = 10**9+7

sum = 0

sum_A, sum_B = 0, 0
for i in range(1, K):
    sum_A += i-1
    sum_B += (N-i+1)

for i in range(K, N+2):
    sum_A += i-1
    sum_B += (N-i+1)
    sum += sum_B - sum_A + 1

print(sum % Z)

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

int main() {
    ll n;
    std::cin >> n;
    
    if(n%10==3){
        std::cout << "bon" << std::endl;
    }else if(n%10==0||n%10==1||n%10==6||n%10==8){
        std::cout << "pon" << std::endl;
    }else{
        std::cout << "hon" << std::endl;
    }
}


Measured memory_bytes: 3636
N = int(input())
L = [list(map(int, input().split())) for i in range(N)]

flag = False
ans = [0, 0, 0]
for i in range(101):
  for j in range(101):
    for k in range(N):
      Xt, Yt, Ht = L[k][0], L[k][1], L[k][2]
      if Ht > 0:
        break
    H = Ht + abs(Xt - i) + abs(Yt - j)
    result = []
    for k in range(N):
      l = L[k]
      if l[2] == max(H - abs(i - l[0]) - abs(j - l[1]), 0):
        result.append(True)
      else:
        result.append(False)
    if result.count(True) == N:
      ans[0], ans[1], ans[2] = i, j, H
      flag = True
      break
  if flag:
    break

print("{} {} {}".format(ans[0], ans[1], ans[2]))

Measured memory_bytes: 3064
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

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

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

int m, card[7], num[7];
int n;
int dp[7001][8];

int dfs(int sum, int kind)
{
  if (dp[sum][kind] != -1) return (dp[sum][kind]);
  if (sum == n) return (1); // ok
  if (sum != n && kind == m) return (0); // ng

  int cnt = 0;
  REP(i, num[kind] + 1){
    cnt += dfs(sum + i * card[kind], kind + 1);
    // maisu 0 ~ num[kind]
    // sum + card[kind] * maisu <- next_sum
  }
  return (dp[sum][kind] = cnt);
}

signed main()
{
  ios::sync_with_stdio(false);
  
  while (cin >> m, m){
    REP(i, m) cin >> card[i] >> num[i];
    int g;
    cin >> g;
    REP(i, g){
      memset(dp, -1, sizeof(dp));
      cin >> n;
      print(dfs(0, 0));
    }
  }
  
  return (0);
}

Measured memory_bytes: 1420
def main():

    m = int(input())

    m_list = list()
    flag  = 1
    state = 0

    for _ in range(m):
        inp = input().split()
        p = [int(a) for a in inp]

        s = 0
        for i in range(len(p)):
            if i == 0:
                continue
            s = s | (flag << p[i])

        m_list.append(s)

    q = int(input())

    for _ in range(q):

        param = input().split()
        c = int(param[0])
        if len(param) >= 2:
            param[1] = int(param[1])

        if c == 0:
            if state & (flag << (param[1])) :
                print("1")
            else:
                print("0")

        elif c == 1:
            state = state | m_list[param[1]]

        elif c == 2:
            state = state & (~m_list[param[1]] & 0xffffffffffffffff)
            
        elif c == 3:
            state = state ^ m_list[param[1]]

        elif c == 4:
            if state & m_list[param[1]] == m_list[param[1]]:
                print("1")
            else:
                print("0")
            
        elif c == 5:
            if (state & m_list[param[1]]) != 0:
                print("1")
            else:
                print("0")

        elif c == 6:
            if (state & m_list[param[1]]) == 0:
                print("1")
            else:
                print("0")

        elif c == 7:
            current = state & m_list[param[1]]
            print(format(current, "064b").count("1"))

        elif c == 8:
            current = state & m_list[param[1]]
            print(int(current))

main()


Measured memory_bytes: 5636
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt() - 1
	}
	ans := 0
	for i := 0; i < N; i++ {
		x := i
		y := a[i]
		if a[x] == y && a[y] == x {
			ans++
		}
	}
	out(ans / 2)
}


Measured memory_bytes: 3140
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+7;
typedef long long LL;
LL a[N];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++)
    {
        LL x;
        scanf("%lld", &x);
        a[i]=a[i-1]+x;
    }
    LL m=-1;
    for(int i=1;i<n;i++)
    {
        LL x=a[n]-a[i];
        LL y=abs(x-a[i]);
        if(m==-1||m>y) m=y;
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 1792