akhauriyash/Code-Regression huggingface dataset:
/*
    二分探索
    https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/4/ALDS1_4_B
*/
#include <bits/stdc++.h>
using namespace std;

bool binarySearch(int *array, int size, int key) {
    int low = 0;
    int high = size;

    while (low < high) {
        int middle = (low + high) / 2;
        if (array[middle] == key) {
            return true;
        } else if (array[middle] < key) {
            low = middle + 1;
        } else if (key < array[middle]) {
            high = middle;
        }
    }
    return false;
}

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

    int n;
    cin >> n;
    int s[100001];
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }

    int q;
    cin >> q;
    int t[50000];
    for (int i = 0; i < q; i++) {
        cin >> t[i];
    }

    int count = 0;
    for (int i = 0; i < q; i++) {
        if (binarySearch(s, n, t[i])) {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3752
import sys

s = input()
if s == "zyxwvutsrqponmlkjihgfedcba":
	print(-1)
	sys.exit()
if len(s) < 26:
	flg = [0] * 26
	for i in range(len(s)):
		flg[ord(s[i])-97] = 1
	ans = s + chr(flg.index(0)+97)
	print(ans)

else:
	candidate = []
	for i in range(25,0,-1):
		candidate.append(s[i])
		if s[i-1] < s[i]:
			obj = s[i-1]
			ind = i-1
			break

	candidate.append(obj)
	candidate.sort()
	switch = candidate[candidate.index(obj)+1]
	ans = s[:ind] + switch
	print(ans)

Measured memory_bytes: 3064
from itertools import product
h,w,k=map(int,input().split())
l=list()
for i in range(h):
    l.append(input())
ans=0
"""
sh=[]
sw=[0 for i in range(w)]
for i in range(h):
    sh.append(l[i].count('#'))
for i in range(w):
    for j in range(h):
        sw[i]+=l[j][i]=='#'
print(sh,sw)
"""
for i in product((0,1),repeat=h+w):
    p=0
    #print(i,type(i))
    for j in range(h):
        for m in range(w):
            if i[j]==0 and i[m+h]==0 and l[j][m]=='#':
                p+=1
    #print(p,i)
    if p==k:
        ans+=1
        #print(ans)
print(ans)

Measured memory_bytes: 9148
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = [list(map(int, input().split()))]
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())

    n = int(input())
    print(num2alpha(n).lower())


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2"""
        output = """b"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """27"""
        output = """aa"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """123456789"""
        output = """jjddja"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


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

#define MAX 1000000001

struct Card{
    char suit;
    int value;
};

int partition(struct Card A[], int p, int r){
    int x = A[r].value;
    int i = p-1;
    for(int j = i+1; j < r; j++){
        if(A[j].value <= x){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

void quickSort(struct Card A[], int p, int r){
    if(p < r){
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q+1, r);
    }
}

void merge(struct Card A[], int left, int mid, int right){
    int n1 = mid-left;
    int n2 = right-mid;
    struct Card L[n1+1];
    struct Card R[n2+1];
    for(int i = 0; i < n1; i++) L[i] = A[left+i];
    for(int i = 0; i < n2; i++) R[i] = A[mid+i];
    L[n1].value = MAX;
    R[n2].value = MAX;

    int li = 0;
    int ri = 0;

    for(int i = left; i < right; i++){
        if(L[li].value <= R[ri].value){
            A[i] = L[li];
            li++;
        }else{
            A[i] = R[ri];
            ri++;
        }
    }
}

void mergeSort(struct Card A[], int left, int right){
    if(left+1 < right){
        int mid = (left+right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(){
    int n;
    cin >> n;
    struct Card A[n], B[n];
    for(int i = 0; i < n; i++){
        char s;
        int val;
        cin >> s >> val;
        A[i].suit = B[i].suit = s;
        A[i].value = B[i].value = val;
    }

    mergeSort(A, 0, n);
    quickSort(B, 0, n-1);

    bool isStable = true;
    for(int i = 0; i < n; i++){
        if(A[i].suit != B[i].suit){
            isStable = false;
            break;
        }
    }

    if(isStable)    cout << "Stable" << endl;
    else            cout << "Not stable" << endl;

    for(int i = 0; i < n; i++){
        cout << B[i].suit << " " << B[i].value << endl;
    }

    return 0;
}


Measured memory_bytes: 5344
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define all(c) begin(c),end(c)
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
using ll = long long;
using vi = vector<int>; using vs = vector<string>;
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

void solve()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << (min(A, B) + min(C, D)) << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, char* argv[])
{
    int a, b, c, tmp1, tmp2;
    cin >> a >> b >> c ;
    if (a < 1 || a > 10000)
        return 0;
    if (b < 1 || b > 10000)
        return 0;
    if (c < 1 || c > 10000)
        return 0;       
    if ( a > b && a > c) {
        if (b > c) {
            cout << c << " " << b  << " " << a << endl;
            return 0;
        } else {
            cout << b << " " << c << " " << a << endl;
            return 0;
        }
    } else if ( b > a && b > c) {
        if (a > c) {
            cout << c << " " << a  << " " << b << endl;
            return 0;
        } else {
            cout << a << " " << c << " " << b << endl;
            return 0;
        }
    } else if ( a > b) {
        cout << b << " " << a << " " << c << endl;
    } else {
        cout << a << " " << b << " " << c << endl;
    }
}


Measured memory_bytes: 3088
#include<stdio.h>
#include<iostream>

#define MOD 1000000007

using namespace std;

long long x[100010];
long long y[100010];

	
int main(void) {
	long long  n, m;
	long long sumx = 0;
	long long sumy = 0;
	long long ans = 0;
	
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
	}

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

	//calculate sum of input x
	for (int i = 1; i <= n; i++) {
		sumx += ( ( (i-1) * x[i] ) % MOD - ( (n-i) * x[i] ) % MOD) ;
		sumx %= MOD;
	}

	for (int i = 1; i <= m; i++) {
		sumy += ( ( (i-1) * y[i] ) % MOD - ( (m-i) * y[i] ) % MOD);
		sumy %= MOD;
	}

	ans = ((sumx * sumy) % MOD +MOD)%MOD;

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

Measured memory_bytes: 1792
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>
#define MOD (ll)(1e9 + 7)

vvi g;
vi dpw, dpb;

void dfs(ll u, ll p) {
    ll white = 1, black = 1;
    for (auto it : g[u]) {
        if (it == p) {
            continue;
        }

        dfs(it, u);
        white *= (dpb[it] + dpw[it]);
        black *= dpw[it];

        white %= MOD;
        black %= MOD;
    }

    dpw[u] = white;
    dpb[u] = black;
}

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

    ll n;
    cin >> n;

    g.resize(n);
    dpw.resize(n), dpb.resize(n);

    for (int i = 0; i < n - 1; i++) {
        ll x, y;
        cin >> x >> y;
        x--, y--;

        g[x].pb(y);
        g[y].pb(x);
    }

    dfs(0, 0);
    cout << (dpw[0] + dpb[0]) % MOD << "\n";
}

Measured memory_bytes: 14208
N,M,C=map(int,input().split())
Blist=list(map(int,input().split()))
Alist=[list(map(int,input().split())) for i in range(N)]
count=0
for i in range(N):
    j=0
    kari=C
    for j in range(M):
        kari+=Alist[i][j]*Blist[j]
    if kari>0:
        count+=1
print(count)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if(discrete) else 10**-8
    if((not left)^f(r)): return r if(left) else r+1
    elif(left^f(l)): return l-1 if(left) else l
    while(r-l>eps):
        h=(l+r)//2 if(discrete) else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if(not discrete) else l if(left) else r

def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))
    A.sort()
    F.sort(reverse=1)

    def check(m):
        cost=0
        for a,f in zip(A,F):
            if(a*f<=m): continue
            cost+=a-(m//f)
        return cost<=k

    print(bisection(0,10**12,check,left=False))
resolve()

Measured memory_bytes: 113280
#include <iostream>
#include<string>
#include<vector>

using namespace std;
int main()
{
  
	string str;
	cin >> str;
	for (int i = 0; i < str.length() - 1; i++) {
		if (str[i] != str[i + 1]) {
			cout << "Yes";
			return 0;
		}

	}

	cout << "No";
	return 0;




}



Measured memory_bytes: 384
A,B,C = map(int,input().split())
ans = 0
lst = [A,B,C]
lst.sort()
import numpy as np
import sys
num1 = lst[1]-lst[0]
num2 = lst[2]-lst[1]
cnt = 0
while True:
    if num1 == 0 and num2 == 0:
        if A%2 == 1:
            print(0)
        else:
            print(-1)
        sys.exit()
    if num1 % 2 != 0 or num2 % 2 != 0:
        break
    cnt += 1
    num1 //= 2
    num2 //= 2
print(cnt)

Measured memory_bytes: 14452
#include<vector>
#include<iostream>
using namespace std;
typedef long long llong;
int check(llong P, vector<int>w, int k, int n) {
	int i = 0;
	for (int j = 0; j < k; j++) {
		llong s = 0;
		while (s + w[i] <= P) {
			s += w[i];
			i++;
			if (i == n)return n;
		}
	}
	return i;
}
llong solve(vector<int>w,int k,int n) {
	llong left = 0;
	llong right = 100000 * 10000;
	llong mid;
	while (left + 1 < right) {
		mid = (left + right) / 2;
		int x = check(mid,w,k,n);
		if (x >= n)right = mid;
		else left = mid ;
	}
	return right;
}
int main() {
	int n, k;
	cin >> n >> k;
	vector<int>w(n);
	for (int i = 0; i < n; i++)cin >> w[i];
	cout << solve(w, k, n) << endl;
	return 0;
}               

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

const int maxn=1e5+10;

int a[maxn],n,m;
vector <pair<int,int> > v;

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		v.push_back(make_pair(y,x));
	}
	int pos=0;
	sort(a,a+n);
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	int now=-1,has=0,x;
	for(int i=0;i<n;i++){
		if(has==0){
			now++;
			x=v[now].first;
			has=v[now].second;
		}
		if(a[i]>x) break;
		else{
			a[i]=x;
			has--;
		}
	}
	long long ans=0;
	for(int i=0;i<n;i++){
	//	cout<<a[i]<<endl;
		ans+=a[i];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1784
def fact(n):
    res = 1
    for i in range(2,n+1):
        res = (res*i)%1000000007
    return res

N,M = map(int,input().split())

if abs(N-M) >= 2:
    print(0)
elif N == M:
    print(2*fact(N)*fact(M)%1000000007)
else:
    print(fact(N)*fact(M)%1000000007)

Measured memory_bytes: 3064
from sys import stdin

class Node():
    NIL = -1

    def __init__(self, p=NIL, l=NIL, r=NIL, d=-1, h=-1):
        self.p = p
        self.l = l
        self.r = r
        self.d = d
        self.h = h

    def __repr__(self):
        return "Node({}, {}, {}, {})".format(self.p, self.l, self.r, self.d)

def root_of(T):
    return [u.p for u in T].index(Node.NIL)

def sibling_of(T, id):
    p = T[T[id].p]
    return p.r if p.l == id else p.l

def degree_of(T, id):
    l = 0 if T[id].l == Node.NIL else 1
    r = 0 if T[id].r == Node.NIL else 1
    return l + r

def calc_depth(T):

    def rec(id, depth):
        nonlocal T

        T[id].d = depth
        if T[id].l != Node.NIL:
            rec(T[id].l, depth + 1)
        if T[id].r != Node.NIL:
            rec(T[id].r, depth + 1)

    rec(root_of(T), 0)

def calc_height(T):

    def rec(id):
        nonlocal T

        l = 0 if T[id].l == Node.NIL else rec(T[id].l) + 1
        r = 0 if T[id].r == Node.NIL else rec(T[id].r) + 1
        T[id].h = max(l, r)
        return T[id].h

    rec(root_of(T))

def type_of(T, id):
    if T[id].p == Node.NIL:
        return "root"
    elif T[id].l == Node.NIL and T[id].r == Node.NIL:
        return "leaf"
    else:
        return "internal node"

def read_nodes(T):
    for line in stdin:
        id, l, r = [int(x) for x in line.split()]
        T[id].l = l
        if l != Node.NIL:
            T[l].p = id
        T[id].r = r
        if r != Node.NIL:
            T[r].p = id

def print_nodes(T):
    for id in range(len(T)):
        print("node {}: ".format(id), end="")
        print("parent = {}, ".format(T[id].p), end="")
        print("sibling = {}, ".format(sibling_of(T, id)), end="")
        print("degree = {}, ".format(degree_of(T, id)), end="")
        print("depth = {}, ".format(T[id].d), end="")
        print("height = {}, ".format(T[id].h), end="")
        print(type_of(T, id))

def main():
    n = int(stdin.readline())
    T = [Node() for _ in range(n)]

    read_nodes(T)
    calc_depth(T)
    calc_height(T)
    print_nodes(T)

main()



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

int bus[]{ 0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0 };
int main() {
	int n; scanf("%d", &n);
	rep(t, n) {
		int s, g; scanf("%d%d", &s, &g);
		int x = 0, y = 31;
		for (int i = 0; i < 31; i++) {
			for (int j = i + 1; j < 31; j++) {
				if (bus[i] == s&&bus[j] == g&&j - i < y - x) {
					x = i; y = j;
				}
			}
		}
		for (int i = x; i <= y; i++) {
			printf("%d", bus[i]);
			if (i == y)printf("\n");
			else printf(" ");
		}
	}
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    IO
    int n,m;
    ll k,x;
    cin>>n>>m>>k;

    vll A(n+1),B(m+1);
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        A[i]=A[i-1]+x;
    }

    for(int i=1;i<=m;i++)
    {
        cin>>x;
        B[i]=B[i-1]+x;
    }

    int ans=0;
    for(int i=0;i<=n;i++)
    {
        if(A[i]>k) break;
        if(A[i]==k) {ans=max(ans,i);continue;}

        ll t=k-A[i];
        int j=lower_bound(B.begin(),B.end(),t)-B.begin();
        if(j==m+1) {ans=max(ans,i+m);continue;}
        if(B[j]>t) ans=max(ans,i+j-1);
        else ans=max(ans,i+j);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6356
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int r,c,mat[100][100];
    int rowplus[100]={0},columnplus[100]={0}; //列、行それぞれの和
    int sum = 0; //行,列の和の合計(表右下)
    cin >> r >> c;
    for (int i=0; i<r; i++) {
        for (int j=0; j<c; j++) {
            cin >> mat[i][j];
            rowplus[i] += mat[i][j];  //行の和を格納
        }
    }
    for(int i=0; i<c; ++i){
        for(int j=0; j<r; ++j){
            columnplus[i] += mat[j][i]; //列の和を格納 jループ
        }
        sum+=columnplus[i];  //和の合計を格納
    }
    for(int i=0; i<r; ++i){
        for(int j=0; j<c; ++j){
                cout << mat[i][j] <<" ";
        }
        cout << rowplus[i] << endl;  //1行ごとに和を出力
    }
    
    for(int i=0; i<c; ++i){
        cout << columnplus[i] << " "; //列の和を一行で出力
    }
    cout << sum << endl;  //和の合計
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::string str;
	std::cin >> n >> str;
	char last = '-';
	int ans = 0;
	for(auto c : str) {
		if(c != last) {
			last = c;
			ans++;
		}
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 512
#include <cstdio>
#include <cmath>

using namespace std;

static const double EPS=1e-8;

int main() {
    while (true) {
        double a, b, c, d, e, f;
        if (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) == EOF)
            break;

        double x=(c*e-f*b)/(a*e-b*d);
        double y=(c*d-f*a)/(b*d-a*e);

        if (abs(x) < EPS) x = 0;
        if (abs(y) < EPS) y = 0;

        printf("%.3f %.3f\n", x, y);
    }

    return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> c(n);
    for(auto& i : v) cin >> i;
    for(auto& i : c) cin >> i;
    int value = 0;
    for(int i = 0; i < n; i++){
        if(v.at(i) > c.at(i)) value += v.at(i) - c.at(i);
    }
    cout << value << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int f[1000001], g[1000001];

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i,n){
        cin >> a[i];
        f[a[i]]++;
    }
    int ans = 0;

    rep(i,1000001){
        g[i] = 1;
        if(f[i] != 1) g[i] = 0;
    }

    srep(i,1,1000001){
        if(f[i] == 0) continue;
        int ii = i * 2;
        while(ii <= 1000000){
            g[ii] = 0;
            ii += i;
        }
    }

    rep(i,1000001)ans += f[i] * g[i];

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




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

int solve(int N, int M, int S, int G1, int G2) {
    const int INF = 10000000;
    vector<vector<int>> d(N+1, vector<int>(N+1, INF));
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;   
        d[a][b] = c;
    }
    for (int k = 1; k <= N; k++) {
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                d[i][i] = d[j][j] = d[k][k] = 0;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    
    int ret = INF;
    for (int mid = 1; mid <= N; mid++) {
        ret = min(ret, d[S][mid] + d[mid][G1] + d[mid][G2]);
    }
    return ret;
}

int main(void){
    int n, m, s, g1, g2;
    vector<int> ans;
    while (1) {
        cin >> n >> m >> s >> g1 >> g2;
        if (n == 0) break;
        ans.push_back(solve(n, m, s, g1, g2));
    }
    for (auto &i : ans) {
        cout << i << endl;
    }
    return 0;
}



Measured memory_bytes: 3208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0;i<n;i++) {
			Vector2 a = new Vector2(sc.nextDouble(),sc.nextDouble());
			Vector2 b = new Vector2(sc.nextDouble(),sc.nextDouble());
			Vector2 c = new Vector2(sc.nextDouble(),sc.nextDouble());
			Vector2 d = new Vector2(sc.nextDouble(),sc.nextDouble());
			boolean parallel = Math.abs(a.subtract(b).cross(c.subtract(d))) < 1E-10;
			System.out.println(parallel ? "YES" : "NO");
		}
	}

}
class Vector2 {
	public double x;
	public double y;
	public Vector2(double x,double y) {
		this.x = x;
		this.y = y;
	}
	public double dot(Vector2 v) {
		return this.x*v.x+this.y*v.y;
	}
	public double cross(Vector2 v) {
		return this.x*v.y-this.y*v.x;
	}
	public double norm() {
		return Math.sqrt(this.x*this.x+this.y*this.y);
	}
	public Vector2 normalize() {
		return divide(norm());
	}
	public Vector2 add(Vector2 v) {
		return new Vector2(x+v.x,y+v.y);
	}
	public Vector2 subtract(Vector2 v) {
		return new Vector2(x-v.x,y-v.y);
	}
	public Vector2 multiply(double k) {
		return new Vector2(x*k,y*k);
	}
	public Vector2 divide(double k) {
		return new Vector2(x/k,y/k);
	}
	public String toString() {
		return "(" + this.x + "," + this.y + ")";
	}
}

Measured memory_bytes: 23252
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;

int main()
{
    // 整数の入力
    long long N,i,k;
    deque<long long>data;
    string s;
    cin >> N;
    for (i= 0;i< N ;i++){
        cin >> k;
        if (N%2==0 ^ i%2!=0){
            data.push_back(k);
        }else{
            data.push_front(k);
        }
    }
    cout << data[0];
    for (i=1;i<N;i++){
        cout << " "<< data[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3840
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

void solve() {
  ll a, b, c; cin >> a >> b >> c;
  ll k; cin >> k;
  ll ans = min(a, k);
  k -= min(a, k);
  k -= min(b, k);
  ans -= min(c, k);
  print(ans);
}

int main() {
  int t; t = 1;
  while(t--) solve();
}


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

int main()
{
    std::size_t H, W, K;
    std::cin >> H >> W >> K;
    std::vector<std::vector<char>> HW(H, std::vector<char>(W, '\0'));
    for(auto& line : HW)
    {
        for(auto& c : line)
        {
            std::cin >> c;
        }
    }

//     for(const auto& l : HW)
//     {
//         for(const auto& d : l)
//         {
//             std::cerr << d;
//         }
//         std::cerr << std::endl;
//     }

    std::size_t answer = 0;

    std::bitset<7> h(0u);
    while(h.to_ulong() < 0b100'0000)
    {
        std::bitset<7> w(0u);
        while(w.to_ulong() < 0b100'0000)
        {
            std::size_t black = 0;
            for(std::size_t i=0; i<H; ++i)
            {
                for(std::size_t j=0; j<W; ++j)
                {
                    if(h[i] == 0 && w[j] == 0 && HW[i][j] == '#')
                    {
                        black += 1;
                    }
                }
            }
            if(black == K)
            {
//                 std::cerr << h << std::endl;
//                 std::cerr << w << std::endl;
                answer += 1;
            }
            w = w.to_ulong() + 1;
            if(std::pow(2, W) <= w.to_ulong())
            {
                break;
            }
        }
        h = h.to_ulong() + 1;
        if(std::pow(2, H) <= h.to_ulong())
        {
            break;
        }
    }
    std::cout << answer << std::endl;



    return 0;
}


Measured memory_bytes: 4088
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Int32.Parse(Console.ReadLine());
            var inputArray = Console.ReadLine().Split(' ');
            var aArr = new int[n];
            var alice = 0;
            var bob = 0;
            for (int i = 0; i < n; i++)
            {
                aArr[i] = Int32.Parse(inputArray[i]);
            }
            Array.Sort(aArr);
            Array.Reverse(aArr);
            for (int i = 0; i < n; i++)
            {
                if (i % 2 == 0)
                {
                    alice += aArr[i];
                }
                else
                {
                    bob += aArr[i];   
                }
            }
            Console.WriteLine(alice - bob);
            
        }
    }
}


Measured memory_bytes: 27516
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    struct Zahyo {
        public int i;
        public int j;
    }

    public void Solve() {
        var H = sc.nextInt();
        var W = sc.nextInt();
        var D = sc.nextInt();
        var A = new int[H, W];
        var dic = new Dictionary<int, Zahyo>();
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                A[i, j] = sc.nextInt();
                dic.Add(A[i, j], new Zahyo { i = i, j = j });
            }
        }
        var Q = sc.nextInt();

        var cost = new int[H * W + 1];
        for (int i = 1 + D; i <= H * W; i++) {
            cost[i] = cost[i - D] + Math.Abs(dic[i - D].i - dic[i].i) + Math.Abs(dic[i - D].j - dic[i].j);
        }

        for (int i = 0; i < Q; i++) {
            var l = sc.nextInt();
            var r = sc.nextInt();
            WriteLine(cost[r] - cost[l]);
        }
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}

Measured memory_bytes: 26052
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

divisors_lst = make_divisors(n)

mins = 10**100
for i in divisors_lst:
    j = n // i
    if i + j < mins:
        ans = i + j
        mins = i * j

print(ans-2)

Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int N,Q;
    cin >> N >> Q;
    map<int,vector<int>> mp;
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        mp[a-1].push_back(b-1);
        mp[b-1].push_back(a-1);
    }
    ll sum[N]={};
    rep(i,Q){
        int z,x;
        cin >> z >> x;
        sum[z-1]+=x;
    }
    stack<int> s;
    bool visi[N]={};
    s.push(0);
    visi[0]=true;
    while(true){
        if(s.empty())break;
        else{
            int now=s.top();
          	s.pop();
            visi[now]=true;
            for(auto x:mp[now]){
                if(!visi[x]){
                    sum[x]+=sum[now];
                    s.push(x);
                }
            }
        }
    }
    rep(i,N){
        cout << sum[i] << ' ';
    }

}

/*



 */



Measured memory_bytes: 27380
s = list(input())

op_cnt = len(s)-1
sum = 0
for i in range(2**op_cnt):
    op = ['+']*op_cnt
    for j in range(op_cnt):
        if (i>>j) & 1:
            op[j] = '-' 

    fomula = s[0]
    for j in range(op_cnt):
        fomula += op[j]
        fomula += s[j+1]
    
    if eval(fomula) == 7:
        print('{}=7'.format(fomula))
        break


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
 
int main() {
	
	int  a, b;
	
	cin >> a >> b;
	int c = a * b;
	if(c % 2 == 0) {
		cout << "Even" << endl;
	} else {
		cout << "Odd" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  string result = "No";
  vector<int> v_num;
  for(int i=0; i<4; i++){
    v_num.push_back(N%10);
    N /= 10;
  }
  if(v_num.at(0) == v_num.at(1) && v_num.at(1) == v_num.at(2)) result = "Yes";
  if(v_num.at(1) == v_num.at(2) && v_num.at(2) == v_num.at(3)) result = "Yes";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int pro,i;
scanf("%d",&pro);
for(i=9;i>0;i--){
    if(pro%i==0){
        pro /= i;
        i++;
        break;
    }
}
if(i&&pro<=9&&pro>=1)   printf("Yes");
else printf("No");
return 0;
}

Measured memory_bytes: 128
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
mi,mx=0,n
for item in l:
  mi1=item[0]
  mx1=item[1]
  if mi1>mi:
    mi=mi1
  if mx1<mx:
    mx=mx1
if mx<mi:
  print(0)
else:
  print(mx-mi+1)

Measured memory_bytes: 27336
function Main(input) {
	var sum = 0;
	input = input.split(" ").map(Number);
	for(var i=1;i<=input[0];i++){
		for(var j=22;j<=input[1];j++){
			if((i==Math.floor(j/10)*(j+'').slice(-1))&&((j+'').slice(-1)!=1)){sum++;}
         // console.log(i,j,Math.floor(j/10),(j-Math.floor(j/10)),(j+'').slice(-1))
		}
	}
	console.log(sum);
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7500
DP = [[0 for _ in range(2)] for _ in range(55)]
DP[0][0] = 1
N, P, *A = map(int, open(0).read().split())
for i in range(N):
  DP[i+1][0] += DP[i][0]
  DP[i+1][0] += DP[i][A[i]%2]
  DP[i+1][1] += DP[i][1]
  DP[i+1][1] += DP[i][(A[i]%2)^1]
print(DP[N][P])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
main()
{
    int n;
    cin>>n;
    for(int i=n;;i++)
    {
        if(i%2==0 && i%n==0)
        {
            cout<<i<<endl;
            break;
        }
    }
  	return 0;
}


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

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

    for(int i=0; i<n; ++i){
        string order;
        cin >> order;

        if( order == "print"){
            int a, b;
            cin >> a >> b;
            string sub = S.substr(a,b-a+1);
            cout << sub << endl;
        }else if( order == "reverse"){
            int a, b;
            cin >> a >> b;
            reverse(S.begin()+a, S.begin()+b+1);
        }if( order == "replace"){
            int a, b;
            string r;
            cin >> a >> b >> r;
            S.replace(a, b-a+1, r);
        }

    }
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
const int N=1e6+5;
int n,ans,jc[N],inv[N],size[N],f[N],Ans[N];
vector<int>g[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
int kuai(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2==1)res=res*a%mod;
        a=a*a%mod;
        b=b/2;
    }
    return res;
}
int C(int a,int b)
{
    if(b>a)return 0;
    return jc[a]*inv[b]%mod*inv[a-b]%mod;
}
void work(int u,int v)
{
    size[u]+=size[v];
    f[u]=f[u]*C(size[u]-1,size[v])%mod*f[v]%mod;
}
void rework(int u,int v)
{
    f[u]=f[u]*kuai(f[v]*C(size[u]-1,size[v])%mod,mod-2)%mod;
    size[u]-=size[v];
}
void dfs1(int u,int fa)
{
    size[u]=1;f[u]=1;
    for(int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        if(v==fa)continue;
        dfs1(v,u);
        work(u,v);
    }
}
void dfs2(int u,int fa)
{
    Ans[u]=f[u]%mod;
    for(int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        if(v==fa)continue;
        rework(u,v);work(v,u);
        dfs2(v,u);
        rework(v,u);work(u,v);
    }
}
signed main()
{
     
    jc[0]=jc[1]=inv[0]=inv[1]=1;
    for(int i=2;i<N;i++)jc[i]=jc[i-1]*i%mod;
    for(int i=2;i<N;i++)inv[i]=inv[mod%i]*(mod-mod/i)%mod;
    for(int i=2;i<N;i++)inv[i]=inv[i-1]*inv[i]%mod;
    n=read();
    for(int i=1;i<n;i++)
    {
        int x=read(),y=read();
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs1(1,0);
    dfs2(1,0);
    for(int i=1;i<=n;i++)printf("%lld\n",Ans[i]);
    return 0;
}

Measured memory_bytes: 60272
# -*- coding: utf-8 -*-
"""
B - 81
https://atcoder.jp/contests/abc144/tasks/abc144_b

"""
import sys


def solve(N):
    for i in range(1, 10):
        for j in range(1, 10):
            if i * j == N:
                return 'Yes'
    return 'No'


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a[575][575];

void solve(int l, int r, int k){
	int i,j,m;
	if(r-l<2){
		return;
	}
	m = (l+r)/2;
	for(i=l; i<m; ++i){
		for(j=m; j<r; ++j){
			a[i][j] = k;
		}
	}
	solve(l,m,k+1);
	solve(m,r,k+1);
}

int main(void){
	int n,i,j;
	cin >> n;
	solve(0,n,1);
	--n;
	for(i=0; i<n; ++i){
		for(j=(i+1); j<=n; ++j){
			cout << a[i][j] << ((j<n)?" ":"");
		}
		cout << endl;
	}
	return 0;
}


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

string solve(string s){
    if(s.size()<=3) return s;
    for(int i=0;i+2<s.size();i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            s[i]=s[i+1]=s[i+2]='X';
            i+=2;
        }
    }
    int cntA=0,cntB=0,cntC=0,cntX=0;
    for(auto c:s){
        cntA+=c=='A';
        cntB+=c=='B';
        cntC+=c=='C';
        cntX+=c=='X';
    }
    if(!cntX) return s;
    char x='K';
    if(!cntA) x='A';
    if(!cntB) x='B';
    if(!cntC) x='C';
    string s2;
    for(int i=0;i<s.size();i++){
        if(s[i]=='X'){
            s2.push_back(x);
            i+=2;
        }else{
            s2.push_back(s[i]);
        }
    }
    return solve(s2);
}

int main(){
    string S;
    cin>>S;
    if(solve(S)=="ABC"){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 21760
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int N, R;
	cin >> N >> R;
	if(N >= 10)cout << R << endl;
	else{
		cout << R + 100 * (10 - N) << endl;
	}

	return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    string s;cin >> s;
    deque<char> dq;
    int l = 0;
    for(int i=0;i<n;i++){
        if(s[i] == '('){
            dq.push_back('(');
            l++;
        }else{
            if(l > 0){
                dq.push_back(')');
                l--;
            }else{
                dq.push_front('(');
                dq.push_back(')');
            }
        }
    }
    while(l > 0){
        dq.push_back(')');
        l--;
    }
    for(auto c : dq){
        cout << c;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(Pii) jobs(N);
    FOR(i, 0, N) {
        cin >> jobs[i].second >> jobs[i].first;
    }
    sort(ALL(jobs));

    lint time = 0;
    bool good = true;
    for(auto& job : jobs) {
        int deadline = job.first, work = job.second;
        if (time + work > deadline) {
            good = false;
            break;
        }
        time += work;
    }

    cout << (good ? "Yes" : "No") << endl;
    return 0;
};


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}

int main() {
  ll N;
  ll X;
  ll T;
  cin >>N>>X>>T;
  cout<<((N+X-1)/X)*T<<endl;
}

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

const int N=100100;
typedef long long ll;
char s[N];
ll L,ans;
int n,d[N][2],cnt;

void dfs(int x,ll y){
	for(int i=0;i<2;++i)
		if(d[x][i])dfs(d[x][i],y-1);
		else if(y>0)ans^=y&-y;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>L;
	for(int i=1;i<=n;++i){
		cin>>s;
		for(int j=0,p=0;s[j];p=d[p][s[j]&1],++j)
			if(!d[p][s[j]&1])d[p][s[j]&1]=++cnt;
	}
	dfs(0,L);
	cout<<(ans?"Alice\n":"Bob\n");
	return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(),x.end()
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define PI 3.1415926535897932384626
#define mod 1000000007
#define modd 998244353
 
void io() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}
 
const int N = 2*1e5+1;
vector<int> adj[N];
bool vis[N];
 
void dfs(int s, int &cnt) {
	cnt++;
	vis[s] = true;
	for(auto x:adj[s]) {
		if(vis[x]) continue;
		dfs(x,cnt);
	}
}
 
int main() {
	io();
 
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++) {
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int ans=0;
	for(int i=1;i<=n;i++) {
		if(vis[i]) continue;
		int cnt = 0;
		dfs(i,cnt);
		ans = max(ans,cnt);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 24048
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
const int SIZE = 10005;

struct BSTNode
{
	int key;
	BSTNode *lchild, *rchild, *parent;
	BSTNode(int k = 0, BSTNode* p = nullptr, BSTNode* l = nullptr, BSTNode* r = nullptr)
		:key(k), parent(p), lchild(l), rchild(r){}
};
typedef BSTNode* BSTree;
BSTree insert(BSTree& Root, int key)
{
	BSTree parent = nullptr, child = Root;

	while (child != nullptr)
	{
		parent = child;
		if (key > child->key)
			child = child->rchild;
		else
			child = child->lchild;
	}
	child = new BSTNode(key, parent);
	if (parent == nullptr)
		Root = child;
	else if (key > parent->key)
		parent->rchild = child;
	else
		parent->lchild = child;
	return child;
}

void pre_order(const BSTree T)
{
	if (!T)
		return;
	cout << ' ' << T->key;
	pre_order(T->lchild);
	pre_order(T->rchild);
}

void in_order(const BSTree T)
{
	if (!T)
		return;
	
	in_order(T->lchild);
	cout << ' ' << T->key;
	in_order(T->rchild);
}
int main(void)
{
	ios::sync_with_stdio(false);
	int n, key;
	char str[10];
	cin >> n;
	BSTree T = nullptr;
	while (n--)
	{
		cin >> str;
		if (str[0] == 'i')
		{
			cin >> key;
			insert(T, key);
		}
		else
		{
			in_order(T);
			cout << endl;
			pre_order(T);
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 26540
using System;

class CF2016RC
{
	static int[] A;
	static public void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int len = 1;
		for(int i=0; i<N; i++)
			len *= 2;
		A = new int[len];
		for(int i=0; i<len; i++)
		{
			A[i] = int.Parse(Console.ReadLine());
		}

		Console.WriteLine(match(0, len/2));
	}

	static int match(int l, int r)
	{
		int w = r - l;
		int X, Y;
		if(w == 1)
		{
			X = A[l];
			Y = A[r];
		}
		else
		{
			X = match(l, l+w/2);
			Y = match(r, r+w/2);
		}

		if(X == Y)
		{
			return X;
		}
		else if(X > Y)
		{
			return X - Y;
		}
		else
		{
			return Y - X;
		}
	}
}


Measured memory_bytes: 16332
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s,t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t) {
  	cout << "Yes\n";
  }else {
  	cout << "No\n";
  }
}

Measured memory_bytes: 256
# include <iostream>
const int MAX = 1e5 + 2;
using namespace std;

long long N;
long long a[MAX];

int main() {
    cin >> N;
    for (long long i = 1; i <= N; i++) {
        cin >> a[i];
    }
    
    bool flag = false;
    for (long long i = 1; i <= N; i++) {
        if (a[i] % 2 == 1) {
            flag = true;
        }
    }

    if (flag) {
        cout << "first" << endl;
    } else {
        cout << "second" << endl;
    }
}

Measured memory_bytes: 1024
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()
S = input()

s = set([""])
for n in S:
	s |= set(x+n for x in s if len(x) != 3)

print(len([x for x in s if len(x) == 3]))


Measured memory_bytes: 65112
#include <iostream>
#include "string.h"
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,K;
	cin >> N >> K;
	vector<int> L(N);
	for(int i = 0;i < N;i++){
		cin >> L[i];
	}
	sort(L.begin(),L.end());
	reverse(L.begin(),L.end());
	int max = 0;
	for(int i = 0;i < K;i++){
		max += L[i];
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
S = input()
count = 0
for i in range(10):
    a = S.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = S.find(str(j),a + 1)
        if b == -1:
            continue
        for k in range(10):
            if str(k) in S[b+1::]:
                count += 1
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>

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

int cnt[212345];

int main() {
    int n;
    cin >> n;
    rep(i,n-1){
        int a;
        cin >> a;
        cnt[a-1]++;
    }
    rep(i,n) cout << cnt[i] << endl;
    return 0;
}

Measured memory_bytes: 4412