akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
  long long n;
  cin>>n;
  if(n%2==1)
  cout<<0;
  else
  {
  	n=n/2;
  	long long answer=0;
  	long long factor=5;
  	while(factor<=n)
  	{
  		answer+=n/factor;
  		factor*=5;
  	}
  	cout<<answer;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read()
{
	char s;
	int k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(s>='0'&&s<='9'));
	if(s==EOF)exit(0);
	if(s=='-')base=-1,s=getchar();
	while(s>='0'&&s<='9')
	{
		k=k*10+(s-'0');
		s=getchar();
	}
	return k*base;
}
void write(int x)
{
	if(x<0)
	{
		putchar('-');
		write(-x);
	}
	else
	{
		if(x/10)write(x/10);
		putchar(x%10+'0');
	}
}
int n,m;
int a[201000];
int b[201000];
map<int,int> M;
int main()
{
	n=read();
	for (int i=1;i<=n;i++) 
	{
		a[i]=read();
		M[a[i]]++;
	}
	m=read();
	for (int i=1;i<=m;i++) 
	{
		b[i]=read();
		if (M[b[i]]>0) M[b[i]]--; else
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define bg begin()
#define ed end()
#define fi first()
#define se second()
using namespace std;
using ll = long long;
using vint = vector<int>;
using pint = pair<int,int>;
using vpint = vector<pint>;
template <typename T>
T sq(T x){
  return x * x;
}
ll mod = 1e9 + 7;

signed main (){
  int A,B;
  cin >> A >> B;
  if(A % 3 ==0 || B % 3 == 0|| (A + B) % 3 == 0){
cout << "Possible" << endl;
  }else{
cout << "Impossible" << endl;
  }
    return 0;
}


Measured memory_bytes: 256
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	a := stdin.ReadInt()
	b := stdin.ReadInt()
	c := stdin.ReadInt()

	ok1 := a == b && a != c // cが仲間はずれ
	ok2 := a == c && a != b // bが仲間はずれ
	ok3 := b == c && a != b // aが仲間はずれ

	if ok1 || ok2 || ok3 {
		stdout.Println("Yes")
	} else {
		stdout.Println("No")
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    char suit;
    bool cards[4][14];
    int a,b;
    
    for(int i=0;i<4;i++)
        for(int j=1;j<=13;j++)
            cards[i][j]=0;
            
    cin>>a;
    for(int x=0;x<a;x++){
    cin>>suit>>b;
    if(suit=='S')cards[0][b]=1;
    if(suit=='H')cards[1][b]=1;
    if(suit=='C')cards[2][b]=1;
    if(suit=='D')cards[3][b]=1;}
    
    for(int i=0;i<4;i++){
        for(int j=1;j<=13;j++){
            if(cards[i][j])continue;
            if(i==0)suit='S';
            if(i==1)suit='H';
            if(i==2)suit='C';
            if(i==3)suit='D';
            cout<<suit<<" "<<j<<endl;}
    }
            
            return 0;}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string a,b;
  cin>>a>>b;
for(int i=0;i<a.size();++i){
  if(a[i]==b[i])
    continue;
  else {
    cout<<"No";
    return 0;
  }
}
  cout<<"Yes";
  
  
  
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	string S;
	cin >> S;

	string T;
	cin >> T;

	int result = 0;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == T[i]) result++;
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);


// UnionFindTree
const int MAX_N = 200010;

struct UnionFind {
    
    vector<int> par;

    // n要素で初期化
    UnionFind(int n) {
        par.assign(n, -1);
    }

    // 木の根を求める
    int find_root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = find_root(par[x]);
    }

    // xとyの属する集合を併合
    bool merge(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    // xとyが同じ集合に属するか判定
    bool is_same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    int size(int x) {
        return -par[find_root(x)];
    }
};

int main() {

    int n, m, k;
    cin >> n >> m >> k;

    vector<set<int>> dame(n);
    UnionFind uf(n);

    for(int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--, b--;
        dame[a].insert(b);
        dame[b].insert(a);
        uf.merge(a, b);
    }

    for (int i = 0; i < k; i++) {
        int c, d; cin >> c >> d; c--, d--;
        if (!uf.is_same(c, d)) continue;
        dame[c].insert(d);
        dame[d].insert(c);
    }
    
    for(int i = 0; i < n; i++) {
        int mem = uf.size(i) - 1;
        mem -= dame[i].size();
        cout << mem << " ";
    }
    cout << endl;
    

    return 0;
}

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

int main(){
    int h,w;
    cin>>h>>w;
    vector<string>s(h);
    string x;
    getline(cin,x);
    rep(i,h){
        getline(cin,s[i]);
        s[i]+=" ";
    }
    rep(i,h){
        for(int j=0; j<s[0].size()-5; j+=6){
            if(s[i].substr(j,5)=="snuke"){
                cout<<char('A'+j/6)<<i+1<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
int a, b, c, d ,e ,f ,g ,h , i;
int rep, elem;
set<int>sete;
int main()
{
    //cout<<"Hello World";
	cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
	cin>>rep;
	for(int i = 0; i<rep;i++){
	    cin>>elem;
	    sete.insert(elem);
	}
	if(
	(sete.count(a) && sete.count(b) && sete.count(c)) ||
	(sete.count(d) && sete.count(e) && sete.count(f)) ||
	(sete.count(g) && sete.count(h) && sete.count(i)) || //linhas
	
	(sete.count(a) && sete.count(d) && sete.count(g)) ||
	(sete.count(b) && sete.count(e) && sete.count(h)) ||
	(sete.count(c) && sete.count(f) && sete.count(i)) || //colunas
	
	(sete.count(a) && sete.count(e) && sete.count(i)) ||
	(sete.count(c) && sete.count(e) && sete.count(g))
	){
	    cout<<"Yes\n";
	}else{
	    cout<<"No\n";
	}
    return 0;
}
/*
a b c
d e f
g h i
/**/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  int a ;
  for(int i=0;i<=2*sqrt(n);i++){
    if(i*i+i>2*n){
      a = i-1 ;
      break ;
    }
  }
  int b = n- a*(a+1)/2 ;
  for(int i=1;i<=a;i++){
    if(i<=a-b){
      cout << i <<endl ;
    }
    else{
      cout << i+1 <<endl ;
    }
  }
 
  
  return 0 ;
}

Measured memory_bytes: 256
# coding = SJIS
n, x = map(int, input().split())
lis = list(map(int, input().split()))
ans = 0

bou = [0]
for i in range(n):
    bou.append(bou[i] + lis[i])

for i in range(n + 1):
    if bou[i] <= x:
        ans += 1

print(ans)

Measured memory_bytes: 9192
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<numeric>
#include<map>
#include<limits>
using namespace std;

#define R(i,s,n) for(int i=s;i<n;i++)
#define D(i,n,s) for(int i=n-1;i>=s;i--)
typedef pair<int,int> P;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int m,nmin,nmax;
  while (cin >> m >> nmin >> nmax && m) {
    int sco[m];
    R(i,0,m) {
      cin >> sco[i];
    }
    int tmp = 0;
    int ans;
    R(i,nmin-1,nmax) {
      if (tmp <= sco[i]-sco[i+1]) {
        tmp = sco[i]-sco[i+1];
        ans = i+1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}



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

int main(){
   int n;
   string s;
   int count=0;
   cin >> n >> s;
   rep(i,n){
      string m = s.substr(i,3);
      if(m=="ABC") count += 1;
   }
   cout << count << endl;
   return 0;  
}

Measured memory_bytes: 256
/*
2020-05-05
atcoder ABC
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int N, ref, cnt, loopCnt;
    ull K;
    cin >> N >> K;
    vector<int> towns(N);
    vector<int> saw(N);
    rep(i, N){
        int a;
        cin >> a;
        towns.at(i) = a - 1;
    }
    ref = 0;
    cnt = 0;
    while(1){
        if(cnt == K){
            cout << ref + 1 << endl;
            return 0;
        }
        if(saw.at(ref) == 1){
            break;
        }
        saw.at(ref) = 1;
        ref = towns.at(ref);
        cnt++;
    }
    int refmemo = ref;
    loopCnt = 0;
    while(1){
        
        if(cnt == K){
            cout << ref + 1 << endl;
            return 0;
        }
        if(towns.at(ref) == refmemo){
            loopCnt++;
            break;
        }
        ref = towns.at(ref);
        loopCnt++;
        cnt++;
    }
    K = (K - cnt) % loopCnt;
    cnt = 0;
    while(1){
        if(cnt == K){
            cout << ref + 1 << endl;
            return 0;
        }
        ref = towns.at(ref);
        cnt++;
    }
    
    return 0;
}


Measured memory_bytes: 4820
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;

int a[1000];
int b[1000];


int main() {
    int n;cin>>n;
    for(int i = 2;i<=n;i++) cin >>b[i];
    for(int i = 1;i<=n;i++){
      if(i == 1) a[i] = b[i+1];
      else if(i == n) a[i] = b[i];
      else a[i] = min(b[i],b[i+1]);
    }
    int g;
    for(int i = 1;i<=n;i++) g+=a[i];
    cout<<g;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)
def main():
    N = int(input())
    edge = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edge[a].append([b,i])
        edge[b].append([a,i])
    color = [0] * (N-1)
    def dfs(s,p,c):
        tmp_c = 1
        for v, num in edge[s]:
            if v == p:
                continue
            if tmp_c == c:
                tmp_c += 1
            color[num] = tmp_c
            dfs(v,s,tmp_c)
            tmp_c += 1
    dfs(0,-1,0)
    print(max(color))
    for c in color:
        print(c)


if __name__ == "__main__":
    main()

Measured memory_bytes: 148876
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

char buf[16];
int a[10];

int main() {
    while (scanf("%s", buf) != EOF) {
        rep (i, 10) a[i] = buf[i] - '0';
        rep (k, 9) rep (i, 9-k) a[i] = (a[i]+a[i+1]) % 10;
        printf("%d\n", a[0]);
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

	int a,b;
	cin >> a >> b;

	if (a < b) {
		cout << "a < b" << endl;
	} else if (a > b) {
		cout << "a > b" << endl;
	} else if (a == b) {
		cout << "a == b" << endl;
	}
	return 0;
}



Measured memory_bytes: 3148
n, c, k = map(int, input().split())
t = [0 for i in range(n)]
for i in range(n):
    t[i] = int(input())
t.sort()

time_of_bus = 0
num_of_people = 0
num_of_bus = 0
for i in range(n):
    if time_of_bus == 0:
        time_of_bus = t[i] + k
        num_of_people = 1
        num_of_bus += 1
    elif t[i] <= time_of_bus and num_of_people < c:
        num_of_people += 1
    else:
        time_of_bus = t[i] + k
        num_of_people = 1
        num_of_bus += 1
print(num_of_bus)


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

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

    vector<ll> dp(n+1);
    dp[0] = 1000;
    for (int k = 1; k <= n; k++) {
        dp[k] = 0;
        for(int i = 0; i < k-1; i++) {
            int m = 99999;
            for(int j = i+1; j < k; j++) {
                m = min(m, a[j]);
            }
            dp[k] = max(dp[k], dp[i]/m*a[k] + dp[i]%m);           
        }
    }
    ll ans = 0;
    rep(i, n+1) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0; 
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  vector<int> T(N);
  for(int i = 0; i < N; i++) cin >> T[i];

  int sumT = 0;
  for(int i = 0; i < N; i++){
    sumT += T[i];
  }

  int M;
  cin >> M;
  int decr = 0;
  int P, X;
  vector<int> ans(M);
  for(int i = 0; i < M; i++){
    cin >> P >> X;
    P--;
    ans[i] = sumT - (T[P] - X);
  }

  for(int i = 0; i < M; i++){
    cout << ans[i] << endl;
  }




  return 0;
}


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

int main() {
   int n,m,x;
   cin >> n >> m >> x;
   int r=0;
   rep(i,m){
      int a; cin >> a;
      if(x<a) 
      r++;
   }
   cout << min(r,m-r) << endl;
}

Measured memory_bytes: 256
"""
一回の移動で移動する人間は一人なのか？＝＞質問みたらYESだった。

n=2の場合を除いて、
人がいる部屋の数はmax(n-k,1)以上となる。
人がいる部屋の数が1つの場合、2つの場合、、、と順番に場合の数を数えていく。
人がいる部屋の数がxの場合の場合の数の求め方：まず、n部屋の中から、x部屋を選ぶ場合の数でnCx。各部屋に一人は人がいるので、nからxを控除する。残りのn-xをx部屋でどう分けるかを考えればよい。
これは、重複組み合わせの公式で(n-x+x-1)C(x-1)。上記の二つをかけ合わせればよい。
あと、制約から考えて、combination関数は高速化が必要。
"""
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)




mod = 10**9 +7
n,k = map(int,input().split())
ans = 0
for i in range(n,max(n-k,1)-1,-1):
    ans += cmb(n,i,p)*cmb(n-i+i-1,i-1,p)
ans %= mod
print(ans)

Measured memory_bytes: 213092
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();
    sc.close();

    long diff = Math.abs(a - b);
    if (diff % 2 == 0) {
      System.out.println(diff / 2);
    } else {
      long max = Math.max(a, b);
      long min = Math.min(a, b);
      long ans = 0;
      if (n - max <= min - 1) {
        ans = Math.min((n + n - max + 1 - min) / 2, n - min);
      } else {
        ans = Math.min((min - 1 + max) / 2, max - 1);
      }
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 23764
# ABC067D - Fennec VS. Snuke (ARC078D)
from collections import deque


def bfs(s: int, d: "List[int]") -> None:
    q = deque([s])
    while q:
        v = q.popleft()
        for u in G[v]:
            if not d[u]:
                q.append(u)
                d[u] = d[v] + 1


def main():
    global G, DB, DW
    N, *E = map(int, open(0).read().split())
    G = [[] for _ in range(N + 1)]
    for i in range(0, (N - 1) * 2, 2):
        v, u = E[i : i + 2]
        G[v] += [u]
        G[u] += [v]
    DB, DW = [0] * (N + 1), [0] * (N + 1)
    bfs(1, DB), bfs(N, DW)
    b, w = 0, 0
    for i, j in zip(DB[1:], DW[1:]):
        if i <= j:
            b += 1
        else:
            w += 1
    flg = b > w
    print("Fennec" if flg else "Snuke")


if __name__ == "__main__":
    main()

Measured memory_bytes: 32492
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

// ret[i][j] = sum of all field in [0,i) x [0,j).
template<typename T>
vector<vector<T>> calc_sum(const vector<vector<T>>& field){
    int h = field.size();
    int w = field[0].size();
    vector<vector<T>> ret(h+1,vector<T>(w+1));
    for(int y=1;y<=h;y++){
        for(int x=1;x<=w;x++){
            ret[y][x] = ret[y][x-1] + field[y-1][x-1];
        }
    }
    for(int x=0;x<=w;x++){
        for(int y=1;y<=h;y++){
            ret[y][x] = ret[y][x] + ret[y-1][x];
        }
    }
    return ret;
}

#define all(vec) vec.begin(),vec.end()
int main(){
    int n,m;cin >> n >> m;

    vector<int> index_of_x(n),index_of_y(n);
    for(int i=0;i<n;i++){
        cin >> index_of_x[i] >> index_of_y[i];
    }
    vector<int> value_of_x = index_of_x,
                value_of_y = index_of_y;

    sort(all(value_of_x));
    sort(all(value_of_y));
    value_of_x.erase(unique(all(value_of_x)),value_of_x.end());
    value_of_y.erase(unique(all(value_of_y)),value_of_y.end());
    for(int i=0;i<n;i++){
        index_of_x[i] = lower_bound(all(value_of_x),index_of_x[i]) - value_of_x.begin();
        index_of_y[i] = lower_bound(all(value_of_y),index_of_y[i]) - value_of_y.begin();
    }
    vector<vector<int>> p(value_of_y.size(),vector<int>(value_of_x.size()));
    for(int i=0;i<n;i++){
        p[index_of_y[i]][index_of_x[i]] += 1;
    }
    auto v = calc_sum(p);

    for(int i=0;i<m;i++){
        int x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;

        int sx = lower_bound(all(value_of_x),x1) - value_of_x.begin();
        int gx = upper_bound(all(value_of_x),x2) - value_of_x.begin();
        int sy = lower_bound(all(value_of_y),y1) - value_of_y.begin();
        int gy = upper_bound(all(value_of_y),y2) - value_of_y.begin();

        int ans = v[gy][gx] - v[sy][gx] - v[gy][sx] + v[sy][sx];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 196884
//============================================================================
// Name        : AOJCpp.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
//#include <stack>
using namespace std;
static const int MAX = 200;

class stack{
private:
	int top;
	int s[MAX];
public:
	void initialize();
	bool isEmpty();
	bool isFull();
	void push(int x);
	int pop();
};

void stack::initialize() {
	top = 0;
}
bool stack::isEmpty() {
	if (top == 0) return true;
	return false;
}
bool stack::isFull() {
	if(top==MAX-1) return true;
	return false;
}
void stack::push(int x) {
	top++;
	s[top] = x;
}
int stack::pop() {
	top--;
	return s[top+1];
}
int main() {

	string str;
//	stack<int> st;
	stack st;
	st.initialize();


	while(cin >> str) {
		int l, r;
		if (str == "*") {
			r = st.pop();
			l = st.pop();
			st.push(l*r);
		} else if (str == "/") {
			r = st.pop();
			l = st.pop();
			st.push(l/r);
		} else if (str == "-") {
			r = st.pop();
			l = st.pop();
			st.push(l-r);
		} else if (str == "+") {
			r = st.pop();
			l = st.pop();
			st.push(l+r);
		} else {
			st.push(stoi(str));
		}
	}
	cout << st.pop() << endl;
}




Measured memory_bytes: 3224
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
data = [input().split()+[i+1] for i in range(n)]
data.sort(key = lambda tup: (tup[0],-int(tup[1])))
for city , k,number in data:
  print(number)

Measured memory_bytes: 3316
#import numpy as np
def main():
    N = int(input()) #count of numbers
    A = list(map(int,input().split())) # array of imput numbers

    countor = 0
    while True:
        if (1 in list(map(lambda x: x%2, A))) == True: break
        A = list(map(lambda x: x/2, A))
        countor += 1
    print(countor)

if __name__ == "__main__":
    main()

Measured memory_bytes: 38896
import java.util.*;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int x, i = 1;
	while (true) {
	    x = sc.nextInt();
	    if (x == 0) {
		break;
	    }
	    System.out.println("Case " + i + ": " + x);
	    i++;
	}
    }
}

Measured memory_bytes: 33040
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    int n; cin >> n;
    vector<ll> a(n);
    ll MIN = INFINITY; //minimum
    for(int i=0;i<n;i++) {
        cin >> a[i];
        if(a[i]<MIN && a[i] != 0) MIN = a[i];
    }
    int st = 0;//when st == 1, roop stops
    while(st == 0){
        ll exMIN = MIN;//remember present minimum
        for(int i=0;i<n;i++){
            ll tmp = a[i]%MIN;
            if(tmp != 0) {
                MIN = min(MIN,tmp);
                a[i] = tmp;
            }
        }
        if(exMIN == MIN) st = 1;//when roop finished, if minimum equals to privious one, while-roop stops
    }
    cout << MIN << endl;
    return 0;
}

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

int main()
{
  int n;
  cin>>n;
  int a[n+1];
  ll dp[n+1];
  for(int i=0;i<=n;i++) dp[i] = 0;
  for(int i=1;i<=n;i++) cin>>a[i];
  for(int i=n;i>=1;i--)
  {
    for(int j=i;j<=n;j++)
    {
      if(i == j)
      {
        dp[i] =  a[i];
      }
      else
      {
        dp[j] = max(a[i]-dp[j],a[j]-dp[j-1]);
      }
    }
  }
  cout<<dp[n]<<endl;
  return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (int argc, char const *argv[])
{
    int64_t N, Q;
    char S[(int)1e5 + 1];
    int64_t m[(int)1e5] = {0}, ans = 0;

    scanf("%"PRId64"%"PRId64, &N, &Q);
    scanf("%s", S);

    for (int i = 1; i < N; i++) {
        if ((S[i - 1] == 'A') && (S[i] == 'C')) {
            m[i] = m[i - 1] + 1;
        } else {
            m[i] = m[i - 1];
        }
    }

    for (int i = 0; i < Q; i++) {
        int64_t l, r;
        scanf("%"PRId64"%"PRId64, &l, &r);
        printf("%"PRId64"\n", m[r - 1] - m[l - 1]);
    }

    return 0;
}


Measured memory_bytes: 1664
using System;

namespace ABC114_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            if((a == 3) || (a == 5) || (a == 7))
            {
                Console.WriteLine("YES");
            }else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001

int main() {
    int n,h;cin >> n >> h;
    vector<int> b(n);
    int m=0;
    for(int i = 0; i < n; i++) {
        int x,y;cin >> x >> y;
        m=max(m,x);
        b[i]=y;
    }
    vector<int> c;
    for(int i = 0; i < n; i++) {
        if(b[i]>m) c.push_back(b[i]);
    }
    sort(c.begin(),c.end());
    reverse(c.begin(),c.end());
    int ans=0;

    for(int i = 0; i < c.size(); i++) {
        h -= c[i];
        ans++;
        if(h<=0) break;
    }
    if(h>0){
        h--;
        h /= m;
        ans += h;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4292
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	map<int,int> cnt;
	int n, k, q; cin >> n >> k >> q;
	rep(i, q){
		int a; cin >> a;
		cnt[a - 1]++;
	}
	rep(i, n){
		cout << (k + cnt[i] - q > 0 ? "Yes" : "No") << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5376
#include<stdio.h>

int search(int *,int,int);

int main(){
  int S[1000000],k,n,q,C = 0;
  int i,j;
  
  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&S[i]);
  
  scanf("%d",&q);
  for(j = 0; j < q; j++) {
    scanf("%d",&k);
    if(search(S,n,k)) C++;
  }

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

int search(int *S,int n,int k){
  int i = 0;
  S[n] = k;
  while(S[i] != k) i++;
  return i != n;
}
  



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << endl;}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int v[510][510];
int ans[100000][4];
void solve() {
	var(int, h, w);
	rep(i, 1, h + 1) {
		rep(j, 1, w + 1) {
			cin >> v[i][j];
		}
	}
	int c = 0;
	rep(i, 1, h) {
		rep(j, 1, w + 1) {
			if (v[i][j] & 1) {
				ans[c][0] = i;
				ans[c][1] = j;
				ans[c][2] = i + 1;
				ans[c][3] = j;
				++c;
				++v[i + 1][j];
			}
		}
	}
	rep(j, 1, w) {
		if (v[h][j] & 1) {
			ans[c][0] = h;
			ans[c][1] = j;
			ans[c][2] = h;
			ans[c][3] = j + 1;
			++c;
			++v[h][j + 1];
		}
	}
	print(c);
	rep(i, 0, c) {
		print(ans[i][0], ans[i][1], ans[i][2], ans[i][3]);
	}
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
using namespace std;
int main(){
	int n,k,u,v;
	bool G[100][100] = {};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>v;
			G[u-1][v-1]=1;
		}
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cout<<G[i][j];
			if(j<n-1)cout<<" ";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3132
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	int n;cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	multiset<int> s;
	s.insert(a[0]);
	for(int i=1;i<n;i++){
		auto it=s.lower_bound(a[i]);
		if(it==s.begin()){
			s.insert(a[i]);
			//cout<<a[i]<<endl;
		}
		else{
		    it--;
			s.erase(it);
			s.insert(a[i]);	
		}
	}
	cout<<s.size()<<endl;
}

Measured memory_bytes: 5376
#include<iostream>
#include<map>
#include<vector>

using namespace std;

const int maxN=2*100000+10;
int N;
vector<int> A(maxN), B(maxN);

int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        B[i] = i-A[i];
        A[i] += i;
    }
    map<int,int> mp;
    long long ans=0;
    for(int i=0;i<N;i++){
        ans += mp[B[i]];
        mp[A[i]]++;
    }
    cout << ans << endl;

}



Measured memory_bytes: 21548
#include <bits/stdc++.h>
using namespace std;
vector<long long> A;
vector<vector<int>> G;
long long f(int p, int q) {
	if (G[p].size() == 1) return A[p];
	vector<long long> a;
	long long m = 0, s = 0;
	for (int x : G[p]) if (x != q) {
		long long y = f(x, p);
		if (y < 0) return -1;
		a.push_back(y);
		m = max(m, y);
		s += y;
	}
	if (A[p] > s) return -1;
	long long n = s - A[p];
	if (n > s - m) return -1;
	long long r = 2*A[p] - s;
	return r;
}
bool func() {
	int N;
	cin >> N;
	A.resize(N);
	for (auto& x : A) cin >> x;
	G.resize(N);
	for (int i = 0; i < N-1; ++ i) {
		int a, b;
		cin >> a >> b;
		-- a; -- b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	if (N == 2) return A[0] == A[1];
	for (int i = 0; i < N; ++ i) if (G[i].size() >= 2) {
		int x = f(i, -1);
		return x == 0;
	}
	throw 1;
}
int main() {
	cout << (func() ? "YES" : "NO") << endl;
}


Measured memory_bytes: 17152
N,W=map(int,input().split(' '))
w,v=[0]*N,[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split(' '))
dp=[[0]+[W+1]*(sum(v)+1) for _ in range(N+1)]
for i in range(N):
    for nv in range(sum(v),0,-1):
        if nv<v[i]:
            dp[i+1][nv]=min(dp[i][nv],dp[i+1][nv+1])
        else:
            dp[i+1][nv]=min(dp[i][nv],dp[i][nv-v[i]]+w[i])

print(dp[N].index(W+1)-1)

Measured memory_bytes: 138952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string s; cin >>s;

    ll sum = 0;
    for(int i = 0; s[i]; i++){
        sum += (s[i]-'0');
    }

    cout <<(sum%9 == 0? "Yes" : "No") <<endl;

    return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define EPS 1e-8
#define test cout<<"test"<<endl;
using namespace std;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const double pi = acos(-1.0);
int read()
{
	int ret=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret;
}
const int MAX_N=2e5+5;
ll a[MAX_N],sum[MAX_N],k,n,ans;
vector <ll> s;
ll BIT[MAX_N];
ll lowbit(ll x)
{
	return x&(-x);
}
void add(ll x,ll val)
{
	while(x<MAX_N)
	{
		BIT[x]+=val;
		x+=lowbit(x);
	}
}
ll Qsum(ll x)
{
	ll res=0;
	while(x)
	{
		res+=BIT[x];
		x-=lowbit(x);
	}
	return res;
}
int main()
{
 	#ifdef TEST
	 	freopen("input.txt","r",stdin);
	#endif
	mem(BIT,0);
	scanf("%lld%lld",&n,&k);
	sum[0]=0;
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",a+i);
		a[i]-=k;
		sum[i]=sum[i-1]+a[i];
	}
	for(int i=0;i<=n;i++)
	{
		s.push_back(sum[i]);
	}
	sort(s.begin(),s.end());
	s.erase(unique(s.begin(),s.end()),s.end());
	for(int i=0;i<=n;i++)
	{
		sum[i]=lower_bound(s.begin(),s.end(),sum[i])-s.begin()+1;
	}
	ans=0;
	for(int i=0;i<=n;i++)
	{
		ans+=Qsum(sum[i]);
		add(sum[i],1);
	}
	printf("%lld\n",ans);
	return 0;
}
//求顺序对 



Measured memory_bytes: 7156
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <utility>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <set> 
#include <vector>
#include <limits.h>
#include <math.h>

#define ll long long 

using namespace std; 
int n, m;
vector<int> v[200001];
bool check[200001];
int main(void)
{
	check[1] = true;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for (int i = 0; i < v[1].size(); i++)
	{
		int next= v[1][i];
		
		check[next] = true;
		for (int j = 0; j < v[next].size(); j++)
		{
			check[v[next][j]] = true;
			
		}
	}
	
	if (check[n]) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");

	return false;
}

Measured memory_bytes: 12144
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
using namespace std;
 

int main(){
    int a,b; cin >> a >> b;
    if(a<=5) b=0;
    else if(a>=6 && a<=12) b/=2;
    cout << b << endl; 
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int N, M, L, e, f, lx, ly, x, y, i;
char A[51][51], B[51][51];
int main(void){
	scanf("%d %d\n", &N, &M);
	for(i=0; i<N; i++){
		scanf("%s\n", A[i]);
	}
	for(i=0; i<M; i++){
		scanf("%s\n", B[i]);
	}
	e=0;
	for(ly=0; ly<N; ly++){
		for(lx=0; lx<N; lx++){
			if(ly+M-1>=N || lx+M-1>=N){continue;}
			f=1;
			for(int y=0;y<M;++y){
				for(int x=0;x<M;++x){
					if(A[ly+y][lx+x]!=B[y][x]){f=0;}
				}
			}
			if(f){e=1;}
		}
	}
	if(e){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e14+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
string s;int bas;
class bun{
public:
	char c;//文字
	int kuri;//繰り返し回数
	llint len;//文字列長
	vector<bun> ko;//中身
	void make(void){
		if('A'<=s[bas]&&s[bas]<='Z'){
			c=s[bas];bas++;
			kuri=1;len=1;
			return;
		}
		//そうでなければ数字のはず
		kuri=0;
		while('0'<=s[bas]&&s[bas]<='9'){kuri*=10;kuri+=s[bas]-'0';bas++;}
		if(kuri==0){cerr<<"bag"<<__LINE__<<endl;}
		if(s[bas]=='('){
			bas++;len=0;c='#';
			while(s[bas]!=')'){
				ko.emplace_back();
				ko.back().make();
				len+=ko.back().len;
			}
			mineq(len,big);len*=kuri;mineq(len,big);
			bas++;
		}
		else{c=s[bas];bas++;len=kuri;}
		return;
	}
	char putc(llint index){
		if(len<=index){return '0';}
		if(c!='#'){return c;}
		index%=(len/kuri);//一回当たりの回数
		for(auto it:ko){
			if(index<it.len){return it.putc(index);}
			else{index-=it.len;}
		}
	}
};
bool solve(void){
	bun aa;
	string ss;cin>>ss;
	if(ss=="0"){return false;}
	s="1("+ss+")";bas=0;
	aa.make();
	int ind;cin>>ind;
	cout<<aa.putc(ind)<<endl;
	return true;
}
int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);ios::sync_with_stdio(false);
	while(solve()){}
	return 0;
}



Measured memory_bytes: 3236
// abc176_e
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#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 ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int H, W, M;
    cin >> H >> W >> M;

    vector<int> col(W, 0), row(H, 0);
    map<P, int> mp;
    REP(i, M){
        int h, w;
        cin >> h >> w;
        h--; w--;
        row[h]++;
        col[w]++;
        mp[P(h, w)]++;
    }

    vector<int> row_idx(H);
    iota(ALL(row_idx), 0);
    sort(ALL(row_idx), [&](int i, int j){ return row[i] > row[j]; });

    vector<int> col_idx(W);
    iota(ALL(col_idx), 0);
    sort(ALL(col_idx), [&](int i, int j){ return col[i] > col[j]; });

    int rmax = row[row_idx[0]];
    int cmax = col[col_idx[0]];

    int ans = 0;
    REP(i, H) {

        if (row[row_idx[i]] < rmax) break;

        REP(j, W){

            if (col[col_idx[j]] < cmax) break;

            int tmp = row[row_idx[i]] + col[col_idx[j]];
            if (mp[P(row_idx[i], col_idx[j])] > 0){
                tmp -= 1;
                ans = max(ans, tmp);
            }  else{
                print(tmp);
                return 0;
            }
        }
    }

    print(ans);






    return 0;
}


Measured memory_bytes: 26668
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);



int main()
{
    fastInp;
    
    ll n, k;
    cin >> n >> k;
    vector<ll> vec(n);
    for (int i = 0; i < n; i++) cin >> vec[i];

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

    ll s = 0;
    for (int i = 0; i < k; i++) s += vec[i];

    cout << s;

    return 0;
}

Measured memory_bytes: 3648
N = int(input())
S = input()
CNTR = 0
CNTG = 0
CNTB = 0
for i in range(N):
    if S[i] == 'R':
        CNTR += 1
    if S[i] == 'G':
        CNTG += 1
    if S[i] == 'B':
        CNTB += 1
CONB = CNTR * CNTG * CNTB
CNT = 0
for i in range(N):
    for j in range(i,N):
        if S[j] != S[i]:
            k = j + (j-i)
            if k > N-1:
                continue
            if S[k] != S[i] and S[k] != S[j]:
                CNT += 1
print(CONB - CNT)

Measured memory_bytes: 73408
def countingSort(A,k):
    C = {}
    for ai in A:
        C[ai] = C.get(ai,0) + 1
    for i in range(1,k+1):
        C[i] = C.get(i,0) + C.get(i-1,0)
    B = A[:]
    for ai in A[::-1]:
        B[C[ai]-1] = ai
        C[ai] -= 1
    return B

if __name__=='__main__':
    n=int(input())
    print(*countingSort(list(map(int,input().split())),10000))

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

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

    //1の桁の数
    int count = N % 10;

    if (count == 3) {
        cout << "bon";
    } else if (count == 0 or count == 1 or count == 6 or count == 8) {
        cout << "pon";
    } else {
        cout << "hon";
    }

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

signed main()
{
	int N, K; cin >> N >> K;
	int ans = K;
	rep(i, N - 1) ans *= K - 1;
	cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    D = inputList()
    
    if D[0] != 0:
        print(0)
        sys.exit()
        
    if N == 1:
        print(1)
        sys.exit()
        
    D.sort()
    
    if D[1] != 1:
        print(0)
        sys.exit()
        
    ck = 0
    dict_tmp = {}
    for i,val in enumerate(D):
        if ck == val:
            pass
        elif ck+1 == val:
            ck += 1
        else:
            print(0)
            sys.exit()
            
        if val in dict_tmp:
            dict_tmp[val] += 1
        else:
            dict_tmp[val] = 1
            
    ans = 1
    for k,v in dict_tmp.items():
        if k == 0 or k == 1:
            pass
        else:
            tmp = dict_tmp[k-1]
            for i in range(v):
                ans *= tmp
                ans = ans % 998244353
                
    print(ans)
            
    
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 61488
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>

using namespace std;
typedef long long ll;

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> b(M);
  for (int i = 0; i < M; i++) {
    cin >> b[i];
  }
  
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = 0; j < M; j++) {
      int a;
      cin >> a;
      sum += b[j] * a;
    }
    sum += C;
    if (sum > 0) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256