akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
    string S;
    long long K;
    cin >> S >> K;
    K--;

    long long index = 2e18;
    int ans;

    for (int i=0; i<S.size(); i++){
        //cout << "S[" << i << "]=" << S.at(i) << endl;
        if (S.at(i)!='1') {
            index = i;
            ans = S.at(i)-'0';
            break;
        }
    }

    if (K<index) ans = 1;

    cout << ans << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int N; cin >> N;
  vi h(N);
  rep(i, N) cin >> h[i];

  vi dp(N+2, INFL);
  dp[0] = 0;
  rep(i, N) {
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
  }
  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int N, K;
int B[200001];

int main () {
  cin >> N >> K;
  vector<int> B(N+1, 0);
  int A;
  rep(i,N) {
    cin >> A;
    B[A]++;
  }

  priority_queue<int, vector<int>, greater<int>> pq;
  rep(i,N+1) {
    if(B[i] != 0) pq.push(B[i]);
  }

  int ans = 0;
  while(pq.size() > K) {
    ans += pq.top();
    pq.pop();
  }

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


Measured memory_bytes: 2168
#include<stdio.h>
int main(){
int a,b,c,d,e=0;
scanf("%d %d %d",&a,&b,&c);
d=b-a+1;
while(1){
if(d == 0)break;
else if(c%a == 0){
e++;
}
d--;
a++;
}
printf("%d\n",e);
return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

int main () {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > node;
  node.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    node[a].push_back(b);    
    node[b].push_back(a);    
  }  
  vector<string> ans;
  ans.push_back("1");
  while (ans[0].size() < n) {
    int size = ans.size();
    for (int i = 0; i < size; i++) {
      int itr = ans[i][ans[i].size() - 1] - 48;
      string h = ans[i];
      for (int j = 0; j < node[itr].size(); j++) {
        if (j == 0) {
          ans[i] = ans[i] + to_string(node[itr][j]);  
        }    
        else {
          ans.push_back(h + to_string(node[itr][j]));  
        }
      }
    }  
  }
  int answer = 0;
  vector<int> init(n + 1, 0);
  for (int i = 0; i < ans.size(); i++) {
    for (int j = 0; j <= n; j++) {
      init[j] = 0;  
    }    
    for (int j = 0; j < ans[i].size(); j++) {
      int itr = ans[i][j] - 48;
      init[itr]++;  
    }
    for (int j = 1; j <= n; j++) {
      if (init[j] == 1) {
          
      } 
      else {
        break;  
      } 
      if (j == n) {
        answer++;  
      }
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 46824
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 10000000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M; cin >> N >> M;
	vector<VI>dp(1 << N, VI(N, INF));
	vector<VI>d(N, VI(N, INF));

	REP(i, M) {
		int a, b, c; cin >> a >> b >> c;
		d[a][b] = c;
	}

	dp[(1 << N) - 1][0] = 0;

	for (int S = (1 << N) - 2; S >= 0; S--) {
		//cout << S << endl;
		REP(v, N) {
			REP(u, N) {
				if (!(S >> u & 1)) {
					chmin(dp[S][v], dp[S | 1 << u][u] + d[v][u]);
				}
			}
		}
	}
	cout << (dp[0][0] != INF ? dp[0][0] : -1) << endl;
	return 0;
}




Measured memory_bytes: 7728
#include <stdio.h>
int main (void)
{
    int a[5];
    int i;
    int ans = 0,min=9,temp = 0;
    scanf("%d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4]);
    for (i = 0; i < 5; i ++)    {
        if(a[i] % 10 == 0)   ans += a[i];
        else    ans += a[i] + 10 - a[i]%10;
        if(min >= a[i] % 10 && a[i] %10 != 0) {
            min = a[i]%10;
            temp = i;
        }
    }
    if(a[0]%10 == 0 && a[1]%10 == 0 && a[2]%10 == 0 && a[3]%10 == 0 && a[4]%10 == 0)  printf("%d",ans);
    else printf("%d",ans - 10 + min);
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		char s[] = scanner.next().toCharArray();
		if (s.length == 1) {

			System.out.println("-1 -1");
			return;
		}
		if(s.length == 2){
			if(s[0]==s[1]){
				System.out.println("1 2");
				return;
			}else{
				System.out.println("-1 -1");
				return;
			}
		}
		for (int i = 1; i < s.length - 1; i++) {
			if (s[i - 1] == s[i] || s[i + 1] == s[i] || s[i - 1] == s[i + 1]) {
				System.out.println(i + " " + (i + 2));
				return;
			}
		}
		System.out.println("-1 -1");
	}
}

Measured memory_bytes: 13364
#include <cstdio>
#include <set>
#include <vector>

using namespace std;

const int N = 5e3;
char buf[N];

char other(char a, char b) {
    set<char> s;
    s.insert('R');
    s.insert('G');
    s.insert('B');
    s.erase(a);
    s.erase(b);
    return *s.begin();
}

int main() {
    int n;
    scanf("%d", &n);
    scanf("%s", buf);

    vector<int> r, g, b;

    for (int i = 0; i < n; i++) {
        if (buf[i] == 'B') {
            b.push_back(i);
        }
        if (buf[i] == 'R') {
            r.push_back(i);
        }
        if (buf[i] == 'G') {
            g.push_back(i);
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (buf[i] == buf[j]) continue;
            char o = other(buf[i], buf[j]);
            int c = 0;
            if (o == 'R') {
                c = end(r) - upper_bound(begin(r), end(r), j);
                int k = 2 * j - i;
                if (k < n && buf[k] == 'R') c--;
            }
            if (o == 'B') {
                c = end(b) - upper_bound(begin(b), end(b), j);
                int k = 2 * j - i;
                if (k < n && buf[k] == 'B') c--;
            }
            if (o == 'G') {
                c = end(g) - upper_bound(begin(g), end(g), j);
                int k = 2 * j - i;
                if (k < n && buf[k] == 'G') c--;
            }
            ans += c;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3264
n = int(input())
lattice_point = [[0,0,0]]
count = 0

for i in range(n):
    lattice_point.append(list(map(int, input().split())))

for i in range(n):
    min_distance = abs(lattice_point[i][1]-lattice_point[i+1][1]) + abs(lattice_point[i][2]-lattice_point[i+1][2])
    time_limit = lattice_point[i+1][0] - lattice_point[i][0]
    if  time_limit < min_distance or time_limit%2 != min_distance%2:
        print('No')
        break
    else:
        count += 1

if count == n:
    print('Yes')

Measured memory_bytes: 27300
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }

  int ans = -1;

  for (int i = 0; i <= 10000; i++) {
    string snum = to_string(i);
    if (snum.size() != n) continue;

    bool ok = true;
    for (int j = 0; j < m; j++) {
      if ((snum[s[j]] - '0') != c[j]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	s := next()
	n := len(s)

	g, p := 0, 0
	ans := 0
	for i := 0; i < n; i++ {
		if p == g {
			g++
			if s[i] == 'p' {
				ans--
			}
		} else if n-i <= g-p {
			p++
			if s[i] == 'g' {
				ans++
			}
		} else {
			g++
			if s[i] == 'p' {
				ans--
			}
		}
	}

	puts(ans)
}


Measured memory_bytes: 896
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n,k; cin >> n >> k;
  
  if(k != 1) cout << n-k << endl;
  else cout << 0 << endl;
  
  
}

Measured memory_bytes: 3604
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.length();
    vector<int> left, right;
    for(int i = n - 1; i >= 0; i--) {
        if(s[i] == 'L') {
            left.push_back(i);
        }
    }
    reverse(left.begin(), left.end());
    int cnt[n] = {};
    for(int i = 0; i < n; i++) {
        if(s[i] == 'R') {
            right.push_back(i);
            if(left.size() == 0) {
                cnt[n - 1]++;
            } else {
                if((left[0] - i) % 2 == 1) {
                    cnt[left[0] - 1]++;
                } else {
                    cnt[left[0]]++;
                }
            }
        } else {
            left.erase(left.begin(), left.begin() + 1);
            if(right.size() == 0) {
                cnt[0]++;
            } else {
                if((i - right[right.size() - 1]) % 2 == 1) {
                    cnt[right[right.size() - 1] + 1]++;
                } else {
                    cnt[right[right.size() - 1]]++;
                }
            }
        }
    }
    for(int i = 0; i < n; i++) {
        cout << cnt[i] << " ";
    }
}

Measured memory_bytes: 4452
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

a,b,c = inm()
k = inn()
x = 0
while b<=a:
  b *= 2
  x += 1
while c<=b:
  c *= 2
  x += 1
print('Yes' if x<=k else 'No')



Measured memory_bytes: 8988
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    double n,d;
    cin >> n >> d;
    int ans=0;
    double x, y, z;
    for(int i=0; i<n ; i++){
        cin >> x >> y;
        z = x*x + y*y;
        if(z<= d*d){
            ans++;
        }
    }
    
    cout << ans;
    
}


Measured memory_bytes: 3772
#include <stdio.h>
#include <vector>

int main() {
  int h[1501], w[1501];
  int n, m, i, j;
  
  while(scanf("%d%d", &n, &m) && (n|m)) {
    std::vector<int> dat(std::max(n, m)*1500+1, 0);
    n++, m++;
    h[0] = w[0] = 0;
    for(i=1; i<n; i++) { scanf("%d", &h[i]); h[i] += h[i-1]; }
    for(i=1; i<m; i++) { scanf("%d", &w[i]); w[i] += w[i-1]; }
    
    for(i=0; i<m-1; i++)
      for(j=i+1; j<m; j++)
	dat[w[j]-w[i]] ++;
    
    int cnt = 0;
    for(i=0; i<n-1; i++)
      for(j=i+1; j<n; j++)
	cnt += dat[h[j]-h[i]];
    
    printf("%d\n", cnt);
  }
  
  return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
    int x = 0;
    cin >> x;

    if(x <= 599)
    {
        cout << 8 << endl;
    }
    else if(x <= 799)
    {
        cout << 7 << endl;
    }
    else if(x <= 999)
    {
        cout << 6 << endl;
    }
    else if(x <= 1199)
    {
        cout << 5 << endl;
    }
    else if(x <= 1399)
    {
        cout << 4 << endl;
    }
    else if(x <= 1599)
    {
        cout << 3 << endl;
    }
    else if(x <= 1799)
    {
        cout << 2 << endl;
    }
    else if(x <= 1999)
    {
        cout << 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
n, m = map(int, input().split())

li_route = list()

for i in range(m):
    li_route.append(list(map(int, input().split())))

starts = set(l[1] for l in li_route if l[0] == 1)

ends = set(l[0] for l in li_route if l[1] == n)

if len(starts.intersection(ends)) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 59548
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using ULL = uint64_t;
using P = pair<LL, LL>;
#define rep(i, n) for (LL i = 0; i < (n); ++i)
//#define DEBUG

LL f(const vector<vector<LL>> &edges, vector<bool> &visited,
     const LL pos, const LL depth, const LL n) {
  #ifdef DEBUG
  string s = "";
  rep(i, depth) {
    s += "  ";
  }
  cout << s << pos << endl;
  #endif

  if (depth == n) {
    return (LL)1;
  }

  LL sum = (LL)0;
  for (const auto i: edges.at(pos)) {
    if (!visited.at(i)) {
      visited.at(i) = true;
      sum += f(edges, visited, i, depth + 1, n);
      visited.at(i) = false;
    }
  }
  return sum;
}

int main() {
  LL n, m;
  cin >> n >> m;

  vector<vector<LL>> edges(n, vector<LL>());

  for (LL i = 0; i < m; ++i) {
    LL a, b;
    cin >> a >> b;
    edges[a - 1].push_back(b - 1);
    edges[b - 1].push_back(a - 1);
  }

  vector<bool> visited(n, false);
  visited.at(0) = true;
  cout << f(edges, visited, 0, 1, n) << endl;
  #ifdef DEBUG
  #endif
}



Measured memory_bytes: 384
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


HH, WW, M = ints()
H, W = read_col(M)


def flatten(i, j): return i * WW + j


def reshape(x): return x // WW, x % WW


H = mina(*H)
W = mina(*W)
H_cnt = Counter(H)
W_cnt = Counter(W)
# 爆弾がある座標に関しては-1,それ以外はそのまま
# 爆弾のある座標の具体的な爆破数を持っていれば良い


n_bomb = defaultdict(lambda: 0)
ma = -1
for h, w in zip(H, W):
    n_bomb[flatten(h, w)] = H_cnt[h] + W_cnt[w] - 1
    ma = max(ma, H_cnt[h] + W_cnt[w] - 1)

# 縦横大きい方から見てく
H_rank = H_cnt.most_common()
W_rank = W_cnt.most_common()
# print(H_rank, W_rank)

for i, h_cnt in H_rank:
    for j, w_cnt in W_rank:
        if h_cnt + w_cnt <= ma:
            break  # どうあがいてもこれ以上大きくするのは無理
        n = n_bomb[flatten(i, j)]
        if n == 0:
            n = h_cnt + w_cnt
        ma = max(ma, n)

print(ma)


Measured memory_bytes: 231332
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        long answer = b/n-a/n;
        if(a%n == 0){
            answer++;
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;
// const double PI = M_PI;

int N;
vector<int> R, C;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  R.resize(N);
  C.resize(N);
  rep(i, N) { cin >> R[i] >> C[i]; }

  int dp[N][N + 1];
  rep(i, N) { fill(dp[i], dp[i] + N + 1, 0); }

  for (int i = 2; i <= N; i++) {
    for (int l = 0; l < N; l++) {
      int r = l + i;
      if (r > N) {
        continue;
      }
      dp[l][r] = INF;
      for (int k = l + 1; k < r; k++) {
        dp[l][r] = min(dp[l][r], dp[l][k] + dp[k][r] + R[l] * R[k] * C[r - 1]);
      }
    }
  }
  cout << dp[0][N] << endl;
  return 0;
}



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

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

    vector<vector<char>> a(H, vector<char>(W));
    vector<bool> row(H, false);
    vector<bool> col(W, false);
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin>>a[i][j];
            if(a[i][j]=='#'){
                row[i] = true;
                col[j] = true;
            }
        }
    }

    for(int i=0; i<H; i++){
        if(row[i]){
            for(int j=0; j<W; j++){
                if(col[j]){
                    cout<<a[i][j];
                }
            }
            cout<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(void)
{
    int n;
    int a, b, c;
    int i;

    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d %d %d", &a, &b, &c);
        if (a * a == b * b + c * c){
            printf("YES\n");
        }
        else if (b * b == c * c + a * a){
            printf("YES\n");
        }
        else if (c * c == a * a + b * b){
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }

    return (0);
}

Measured memory_bytes: 580
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = [1000000000]
e = []
flg = False
for i in range(len(a)-1):
  t = a[1+i] - a[i]
  e.append(t)
  if(t < d[0]):
    d.insert(0,t)
  if(t == 1):
    flg = True
    break
if(flg):
  print(1)
else:
  d.sort()
  l = len(d)
  ans = 1
  for i in range(l):
    u = list(map(lambda x: x% d[l - 1 - i],e))
    if(u.count(0) == n):
      ans = d[l-1-i]
      break
  if(ans == 1):
    k = d[0]
    f = []
    j = 2
    while True:
      s = int(k/j)
      if(k % j == 0):
        f.insert(0,s)
      if(s < 1):
        break
      j += 1
    q = len(f)
    for i in range(q):
      u = list(map(lambda x: x% f[q - 1 - i],e))
      if(u.count(0) == n):
        ans = f[q-1-i]
        break

  print(ans)

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

#define MIN(a,b) ((a)<(b)?(a):(b))


int main() {
	string a,s;
	cin >> a>>s>>a;
	cout << "A" << s[0] << "C";
	return 0;
}


Measured memory_bytes: 256
import sys
import math
import collections
from collections import deque
def main():
    #n = int(input())
    #a, b = map(int, input().split())
    s = input()
    #x = list(map(int, input().split()))
    q = int(input())
    d = deque([])
    for i in range(len(s)):
        d.append(s[i])

    rev = 1
    for i in range(q):
        que = sys.stdin.readline().split()
        if que[0] == "1":
            rev *= -1

        else:
            if rev == 1:
                if que[1] == "1":
                    d.appendleft(que[2])
                else:
                    d.append(que[2])

            else:
                if que[1] == "1":
                    d.append(que[2])
                else:
                    d.appendleft(que[2])


    if rev == 1:
        for i in range(len(d)):
            print(d.popleft(), end="")
    else:
        for i in range(len(d)):
            print(d.pop(), end="")

main()


Measured memory_bytes: 7780
/*
 * ALDS1_8_C.cpp
 *
 *  Created on: May 3, 2018
 *      Author: 13743
 */

#include<cstdio>
#include<cstdlib>

struct Node {
	int key;
	Node *pa, *lc, *rc;
};

Node* root = NULL;

void insert(int k) {
	Node* y = NULL;
	Node* x = root;
	Node* z = new Node;
	while(x != NULL) {
		y = x;
		if(k < y->key) x = y->lc;
		else x = y->rc;
	}
	z->pa = y;
	z->lc = NULL;
	z->rc = NULL;
	z->key = k;
	if(y == NULL) {
		root = z;
	}
	else if(k < y->key) {
		y->lc = z;
	}
	else {
		y->rc = z;
	}
}

void preorder(Node* u) {
	if(u == NULL) return;
	printf(" %d", u->key);
	preorder(u->lc);
	preorder(u->rc);
}

void inorder(Node* u) {
	if(u == NULL) return;
	inorder(u->lc);
	printf(" %d", u->key);
	inorder(u->rc);
}

void print() {
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
}

void find(int k) {
	Node* x = root;
	while(x != NULL) {
		if(x->key == k) {
			printf("yes\n");
			return;
		}
		if(k < x->key) x = x->lc;
		else x = x->rc;
	}
	printf("no\n");
}

void deleteNode(Node* u) {
	if(u->lc!=NULL && u->rc!=NULL) {
		Node* piv = u->rc;
		while(piv->lc != NULL) {
			piv = piv->lc;
		}
		u->key = piv->key;
		deleteNode(piv);
	}
	else if(u->lc==NULL && u->rc==NULL) {
		if(u->pa->lc == u) u->pa->lc = NULL;
		else u->pa->rc = NULL;
		delete u;
	}
	else {
		Node* ch;
		if(u->lc != NULL) ch = u->lc;
		else ch = u->rc;
		if(u->pa->lc == u) u->pa->lc = ch;
		else u->pa->rc = ch;
		ch->pa = u->pa;
		delete u;
	}
}

void remove(int k) {
	Node* x = root;
	while(x != NULL) {
		if(x->key == k) {
			break;
		}
		if(k < x->key) x = x->lc;
		else x = x->rc;
	}
	if(x == NULL) return;
	deleteNode(x);
}

int main() {
	int m;
	scanf("%d", &m);
	char s[100];
	int ke;
	for(int i=0; i<m; i++) {
		scanf("%s", s);
		if(s[0] == 'i') {
			scanf("%d", &ke);
			insert(ke);
		}
		else if(s[0] == 'f') {
			scanf("%d", &ke);
			find(ke);
		}
		else if(s[0] == 'd') {
			scanf("%d", &ke);
			remove(ke);
		}
		else {
			print();
		}
	}
}




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


#define ll long long
#define MOD 1000000007



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

    vector<int> c(n,-1);

    int x,v,j=0;
    for(int i=0;i<m;i++){
        cin>>x>>v;
        if(c.at(x-1) != -1){
            if(c.at(x-1)!=v){
                j = 1;
            }
        }else c.at(x-1) = v;
    }
    if(c.at(0)==0&&n!=1)j=1;

    for(int i=0;i<n;i++){
        if(c.at(i) == -1){
            if(i==0&&n!=1)c.at(i)=1;
            else c.at(i) = 0;
        }
    }

    int ans = 0;
    int t=1;
    for(int i=n-1;i>=0;i--){
        ans += c.at(i)*t;
        t *= 10;
    }

    if(j==1){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);

  cout << max(0LL, C - (A - B)) << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


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

#define ll long long
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll mod = 1000000007;
ll INF = 1e9 + 5;

int DFS(vector<ll> adj[],int u,vector<ll> &dp)
{
    if(dp[u] != -1) return dp[u];
    int res = 0;
    for(auto v : adj[u])
    {
        res = max(res,DFS(adj,v,dp)+1);
    }
    dp[u] = res;
    return res;
}

int main(){
    FAST;
    ll n,m;
    cin >> n >> m;
    vector<ll> adj[n+1];
    for(int i=0;i<m;i++)
    {
        ll x,y;
        cin >> x >> y;
        adj[x].push_back(y);
    }
    vector<ll> dp(n+1,-1);
    for(int i=1;i<=n;i++)
    {
        DFS(adj,i,dp);
    }
    ll ans = 0;
    for(int i=1;i<=n;i++)
    {
        ans = max(ans,dp[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9216
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
last = -1
for a_i in a:
    ans += b[a_i - 1]
    if last == a_i - 1:
        ans += c[a_i - 2]
    last = a_i

print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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



















int main(){
    ll n, c, k;
    cin >> n >> c >> k;
    vector<ll> t(n);
    REP(i, n){
        cin >> t[i];
    }
    sort(t.begin(), t.end());
    ll ans = 0, cnt = 0, time = 0;
    REP(i, n){
        if(cnt == c || time < t[i]){
            ans++;
            time = t[i] + k;
            cnt = 1;
        }
        else{
            cnt++;
        }
    }
    cout << ans << endl;
}

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

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

    long long int ans = 1;

    vector<long long int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }

    for (int i = 0; i < k; i++) {
        ans = ans * a.at(i);
    }

    for (int i = k; i < n; i++) {
        if (a.at(i) > a.at(i-k)) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }

    return 0;
}


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

int main () {
  int n;
  int aa;
  cin >> n >> aa;
  vector<int> a(n + 1);
  for (int i = 0; i <= n; i++) {
    a[i] = i;    
  }
  cout << a[n - (aa - 1)] << endl;
}

Measured memory_bytes: 256
int main(){
  int str[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k=0;
  scanf("%d",&k);
  printf("%d",str[k-1]);
  return 0;
}

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

const int Max = 100000;
const int NIL = -1;

int n;
vector<int> G[Max];
int color[Max];

void dfs(int r, int c){
    stack<int> S;
    S.push(r);
    color[r] = c;
    while(!S.empty()){
        int u = S.top();
        S.pop();
        for(int i=0; i<G[u].size(); i++){
            int v = G[u][i];
            if(color[v] == NIL){
                S.push(v);
                color[v] = c;
                // cout << color[v] << endl;
            }
        }
    }
}
void assignColor(){
    int id = 1;
    for(int i=0; i<n; i++){ color[i] = NIL; }
    for(int u=0; u<n; u++){
        if(color[u] == NIL) dfs(u, id++);
    }
}

int main(){
    int m, u, v, q;
    cin >> n >> m;
    for(int i=0; i<m; i++){
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    assignColor();
    
    cin >> q;
    for(int i=0; i<q; i++){
        cin >> u >> v;
        // cout << color[u] << color[v] << endl;
        if(color[u] == color[v]) cout << "yes\n";
        else cout << "no\n";
    }

    return 0;
}


Measured memory_bytes: 8996
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD!long - 1L;

	//foreach (N; 0..10L^^2)
	//{
	debug writeln("N:", N+1);
	long x = 26;
	long[] num;
	while (N >= 0)
	{
		num ~= N % 26;
		N -= x;
		if (N < 0) break;
		N /= 26;
	}
	debug writeln(num);

	char[] ans;
	foreach (i; 0..num.length)
	{
		ans ~= cast(char)('a'+num[i]);
	}
	ans.reverse();

	writeln(ans);
	stdout.flush;//}
	debug readln;
}


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


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

    vector<tuple<string, int, int>> v;
    for(int i=1; i<=n; i++){
        string s;
        int p;
        cin >> s >> p;
        v.emplace_back(s, -p, i);
    }
    sort(v.begin(), v.end());
    for(auto x : v){
        cout << get<2>(x) << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

int main(){

  long long n,i;
  cin>>n;
  cout<<n<<":";
  i=2;
  while(n>1 && i*i<=n){
    if(n%i==0){
      cout<<" "<<i;
      n/=i;
    }
    else i+=1;
  }
  if(n!=1)cout<<" "<<n;
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1164
s= input()
t= input()
count=0

lens =len(s)
lent= len(t)
ans =0

for i in range(0,lens-lent+1):
    count=0
    for j in range(0,lent):
        #print(j)
        if (s[i+j] == t[j]):
            count +=1 
            

    ans= max(count,ans )

print(lent-ans)

Measured memory_bytes: 9004
#include<bits/stdc++.h>
using namespace std;
#define maxn 110

int n,ans=0,k;
int a[maxn];

inline int read(){
  	int X=0,w=0; 
	char ch=0;
  	while (ch<'0' || ch>'9'){
		w|=ch=='-';
		ch=getchar();
	}
  	while (ch>='0' && ch<='9') 
	    X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
  	return w?-X:X;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++)
	  a[i]=read();
	k=1;
	for (int i=2;i<=n;i++)
	  if (a[i]!=a[i-1]){
	  	ans+=(k/2);
	  	k=1;
	  }
	  else k++;
	ans+=k/2;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
    int H, W, i, j, f;
    for (;;) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W ==0) exit(0);
        for (i=1; i<=H; i++) {
            f = i % 2;
            for (j=1; j<=W; j++) {
                if (f==1) printf("#");
                else printf(".");
                f ^= 1;
            }
            printf("\n");
        }
        printf("\n");
    }
}




Measured memory_bytes: 2028
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import itertools

for s in sys.stdin:
  d = map( int, s.split() )
  if d == [ 0,0 ]:
    break
  n, s = d[0], d[1]
  lis = list(itertools.combinations(range(10),d[0]))
  print sum( [ 1 for e in lis if sum(e) == d[1] ] )
  

Measured memory_bytes: 4388
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll N, K; cin >> N >> K;
    vll a(N);
    rep(i, 0, N){
        cin >> a[i];
    }
    bool t = true;
    ll c = 0;
    while(t&&c < K){
        vll imos(N+1, 0);
        rep(i, 0, N){
            ll l = i - a[i]; if(l < 0){l = 0;}
            ll r = i + a[i] + 1; if(N < r){r = N;}
            imos[l]++;
            imos[r]--;
        }
        ll sm = 0;
        bool f = true;
        rep(i, 0, N){
            sm += imos[i];
            a[i] = min(sm, N);
            if(a[i] != N){
                f = false;
            }
        }
        if(f){t = false;}
        c++;
    }
    if(!t){
        rep(i, 0, N){prt(N); prt(" ");}
    }else{
        rep(i, 0, N){
            prt(a[i]); prt(" ");
        }
    }
}

Measured memory_bytes: 6428
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll a,b;
    cin>>a>>b;
    cout<<(a-1)/b + 1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define all(v) (v).begin(),v.end()
#define fi first
#define se second
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
using Pc=pair<char,char>;
int main() {
    int n,q; string s; cin >> n >> q >> s;
    vector<Pc> td(q);
    for (int i = 0; i < q; ++i) cin >> td[i].fi>>td[i].se;
    //左端
    int low = -1, high = n;
    while (high - low > 1) {
        int mid = (low + high)/2;
        bool check=false;
        int pos=mid;
         for (auto c : td) {
        if (s[pos] != c.fi) continue;
        if (c.se== 'L') --pos;
        else ++pos;
        if (pos < 0){check=true;break;}
    }
        if (check) low = mid;
        else high = mid;
    }
    int left_fall = high;

    // 右側の境目
    low = -1, high = n;
    while (high - low > 1) {
        bool check=false;
        int mid = (low + high) / 2;
        int pos=mid;
         for (auto c : td) {
        if (s[pos] != c.fi) continue;
        if (c.se == 'L') --pos;
        else ++pos;
        if (pos >=(int)s.size()){check=true;break;}
    }
        if (check) high = mid;
        else low = mid;
    }
    int right_fall = n-1-low;

    cout<< n - (left_fall + right_fall)<<endl;;
}

Measured memory_bytes: 900
package main

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

func main() {
	scanInit()
	combinitMODD()

	n := nextInt()
	p := nextInt() // 0=even, 1=odd
	a := make([]int, n)

	oddnum := 0
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		if a[i]%2 == 1 {
			oddnum++
		}
	}
	evennum := n - oddnum
	cnt := 0

	eway := 1 << evennum
	osum := 0
	for i := 0; i <= oddnum; i += 2 {
		coi := combinationMODD(oddnum, i)
		osum += coi
	}
	cnt = eway * osum

	if p == 1 {
		cnt = 1<<n - cnt
	}
	fmt.Println(cnt)

}

const modd int = 1000000007
const combMax int = 510000 // combinit用
var combfac [combMax]int   // combinit用
var combfinv [combMax]int  // combinit用
var combinv [combMax]int   // combinit用
func combinitMODD() {
	combfac[0] = 1
	combfac[1] = 1
	combfinv[0] = 1
	combfinv[1] = 1
	combinv[1] = 1
	for i := 2; i < combMax; i++ {
		combfac[i] = combfac[i-1] * i % modd
		combinv[i] = modd - combinv[modd%i]*(modd/i)%modd
		combfinv[i] = combfinv[i-1] * combinv[i] % modd
	}
}

// 1<=k<=n<=10**7
func combinationMODD(n int, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return combfac[n] * (combfinv[k] * combfinv[n-k] % modd) % modd
}
func pow(a, b int) int {
	var ret int = 1
	for b > 0 {
		if (b & 1) == 1 {
			ret *= a
		}
		a *= a
		b >>= 1
	}
	return ret
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 13756
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    FAST_IO
    
    ll a,b;
    cin >> a >> b;

    cout << ((a * b) % 2 == 0 ? "Even" : "Odd") << endl;
    
    return 0;
}

Measured memory_bytes: 3004
#include <stdio.h>
int main() {
  int H,W,h,w;
  scanf("%d", &H);scanf("%d", &W);scanf("%d", &h);scanf("%d", &w);
  //printf("%d\n", H);printf("%d\n", W);printf("%d\n", h);printf("%d\n", w);
  
  int ans=0;
  
  ans=H*W-(h*W)-(w*(H-h));
  
  printf("%d\n",ans);
    
  return 0;
}

Measured memory_bytes: 128
H, W = map(int, raw_input().split())
field = []
for i in range(0, H):
	lst = []
	s = raw_input()
	for j in range(0, W):
		lst.append(s[j])
	field.append(lst)

for i in range(0, H):
	for j in range(0, W):
		if field[i][j] != '#':
			cnt = 0
			for p in range(-1, 2):
				if 0 <= i+p and i+p <= H-1:
					for q in range(-1, 2):
						if 0 <= j+q and j+q <= W-1:
							if field [i+p][j+q] == '#':
								cnt = cnt + 1
			field[i][j] = str(cnt)

for i in range(0, H):
	ans = ''
	for j in range(0, W):
		ans = ans + field[i][j]
	print ans

Measured memory_bytes: 2696
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
score = 0
for i in range(n):
	if B[i] >= A[i] + A[i+1]:
		score = score + A[i] + A[i+1]
		A[i+1] = 0
	elif B[i] <= A[i]:
		score = score + B[i]
	else:
		score = score + B[i]
		A[i+1] = A[i+1] + A[i] - B[i]
print(score)

Measured memory_bytes: 18624
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;



void solve() {
	int num, b;
	ll cnt = 0;
	cin >> num >> b;
	while(num) {
		cnt++;
		num /= b;
		
		}
		cout << cnt << endl;
}			


int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	int t;
	solve();
	return 0;
}
 
 
 


Measured memory_bytes: 3548
#include <iostream>

int main() {
    int A, B, C, D;
    std::string s;
    std::cin >> A >> B >> C >> D;
    if (A+B == C+D) {
        s = "Balanced";
    } else if (A+B > C+D) {
        s = "Left";
    } else {
        s = "Right";
    }
    std::cout << s << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}
int main()
{
        //input->compute->output//
        int K, S;
        cin >> K >> S;
        int ans = 0;
        for (int X = 0; X < K + 1; X++)
        {
                for (int Y = 0; Y < K + 1; Y++)
                {
                        if (S - X - Y >= 0 && K >= S - X - Y)
                        {
                                ans++;
                        }
                }
        }

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


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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  for(int i=0;i<n;i++){
    if(s[i]==',')cout<<" ";
    else cout<<s[i];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3572