akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

int c[4000][26];

signed main(){
    IOS;
    int n;
    string s;
    cin >> n >> s;
    c[n-1][s[n-1]-'A']++;
    for (int i = 0; i < 26; i++) {
    	for (int j = n - 2; j >= 0; j--) {
    		c[j][i] = c[j+1][i] + (s[j]-'A' == i);
    	}
    }
    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
    	for (int j = i + 1; j < n; j++) {
    		if (s[i] == s[j]) continue;
    		int k = j + j - i;
    		for (int k = 0; k < 26; k++) {
    			if (k == s[i]-'A' || k == s[j]-'A') continue;
    			ans += c[j+1][k];
    		}
    		if (k < n && s[k] != s[i] && s[k] != s[j]) ans--;
    	}
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  int64_t a = 2, b = 1, r = 0;
  if(n == 0) {
    r = a;
  }
  else if(n == 1) {
    r = b;
  }
  else {
    for(int i = 2; i <= n; i++) {
      r = a + b;
      a = b;
      b = r;
    }
  }
  cout << r;
}


Measured memory_bytes: 3540
#include <stdio.h>

int main(void){
    //long long int num[6] = {};
    long long int ninzu,temp;
    long long int trans[5];
    long long int min = 0;
    int i,bneck;
    
    scanf("%lld", &ninzu);
    for(i = 0; i < 5; i++){
        scanf("%lld", &trans[i]);
    }
    
    
    temp = 10e14;
    for(i = 0; i < 5; i++){
        if(temp >= trans[i]){
            bneck = i;
            temp = trans[i];
        }
    }
    
    //printf("bneck:%d\n", bneck);
    
    min += (ninzu + trans[bneck] - 1)/trans[bneck];
    min += 4;
    
    printf("%lld\n", min);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rmin(r, x) r = min(r, x);
#define rmax(r, x) r = max(r, x);
#define ends ' '
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

string s, t;

int main(void) {
    fastio;
    cin >> s >> t;
    int ans = s.size();
    for(int i = 0; i + t.size() - 1 < s.size(); ++i) {
        int cnt = 0;
        for(int j = 0; j < t.size(); ++j)   cnt += (s[i + j] != t[j]);
        rmin(ans, cnt);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<math.h>
int main(void){
	int i, n, x[100], y[100];
	double D1 = 0, d2 = 0, Dm = 0, d3 = 0, ab[100];
	scanf("%d", &n);
	for (i = 0; i<n; i++){
		scanf("%d", &x[i]);
	}
	for (i = 0; i<n; i++){
		scanf("%d", &y[i]);
	}
	for (i = 0; i<n; i++){
		ab[i] = abs(x[i] - y[i]);
		if (i == 0){ Dm = ab[0]; }
		else if (ab[i]>Dm){ Dm = ab[i]; }
		D1 += ab[i];
		d2 += ab[i] * ab[i];
		d3 += pow(ab[i], 3.0);
	}

	printf("%f\n%f\n%f\n%f\n", D1, sqrt(d2), pow(d3, 1.0 / 3.0), Dm);
	return 0;
}


Measured memory_bytes: 2108
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    K = int(input())
    A, B = map(int, input().split())

    for i in range(0, 100):
        if A <= K * i <= B:
            print("OK")
            return
    print("NG")


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9984
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    int a, b, C;
    double S, L, h, d;
    cin >> a >> b >> C;

    d = (acos(-1)*C)/180.0;
    S = a*b*sin(d)/2.0;
    L = a + b + sqrt(a*a + b*b -2*a*b*cos(d));
    h = b*sin(d);

    printf("%lf\n%lf\n%lf\n", S, L, h);

    return 0;
}


Measured memory_bytes: 3352
#include <iostream>
using namespace std;
int main(void){
    int N, i, sum=0, x;
    cin >> N;
    for(i=0; i<N; i++){
        cin >> x;
        if(x % 2 == 0){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 3108
#include "bits/stdc++.h"
using namespace std;

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
ll INF = (1LL << 60);
int MOD = 1000000007;

ll d[210][210];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n, m; cin >> n >> m;
	ll R; cin >> R;
	vector<ll>r(R); rep(i, R)cin >> r[i];
	rep(i, R)r[i]--;
	sort(r.begin(), r.end());
	rep(i, n) {
		rep(j, n) {
			d[i][j] = INF;
		}d[i][i] = 0;
	}
	rep(i, m) {
		int a, b; ll c; cin >> a >> b >> c; a--; b--;
		d[a][b] = c; d[b][a] = c;
	}
	rep(k, n)rep(i, n)rep(j, n) {
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}
	ll ans = INF;
	do {
		ll now = 0;
		rep(i, R - 1) {
			now += d[r[i]][r[i + 1]];
		}
		ans = min(ans, now);
	} while (next_permutation(r.begin(), r.end()));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int h,w;
    cin >> h >> w;
    int count = 0;
    string s;
    while (cin >> s)
    {
        if (s=="snuke")
        {
            break;
        }
        count++;
    }
    int tate = count/w+1;
    char yoko = count%w+65;
  	cerr << count;
    cout << yoko << tate << endl;
}

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

const int N=100001;
const int M=101;
int dp[M][N]; int n; int arr[M]; int brr[M]; int crr[M]; 
int INF=10000000000000000;
int w;

int go(int index, int weight){
	if(index==n || weight==w)
	return 0;
	
	if(dp[index][weight]!=-1)
	return dp[index][weight];
	
	int ans=0;
	if(weight+arr[index]<=w)
	ans=brr[index]+go(index+1,weight+arr[index]);
	ans=max(ans,go(index+1,weight));
	return dp[index][weight]=ans;
}

#undef int
int main(){
	#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t=1;
	while(t--){
		cin >> n >> w;
		for(int i=0;i<n;i++){
			cin>>arr[i]>>brr[i];
		}
		memset(dp,-1,sizeof(dp));
		cout<<go(0,0);
	}
	return 0;
}


Measured memory_bytes: 79232
N = int(input())
a = [int(x) for x in input().split()]

sm = 0
for i in range(len(a)):
    sm += a[i]

ans = 0
for i in range(len(a)):
    ans += a[i]*(sm-a[i])

ans //= 2
print(ans%(10**9+7))

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N) {
  ll cnt = 0;
  FOR(A, 1, N) {
    FOR(B, 1, N) {
      ll C = N - A * B;
      if (C > 0)
        cnt++;
      else
        break;
    }
  }
  cout << cnt << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(true) {
			int h = scan.nextInt();
			int w = scan.nextInt();
			if(h == 0 && w == 0) {
				break;
			}

			for(int i = 0; i < h; i++) {
				for(int j = 0; j < w; j++) {
					if((i + j) % 2 == 0) {
						System.out.printf("#");
					}
					else {
						System.out.printf(".");
					}
				}
				System.out.println("");
			}
			System.out.println("");
		}

		scan.close();
	}
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int a, b, c; cin >> a >> b >> c;
        cout << max(0, c - (a - b));
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 3604
C = [list(map(int, input().split())) for _ in range(3)]

ans = True
row = C[0]
for i in range(1, 3):
    for j in range(3):
        C[i][j] -= C[0][j]

    if row != C[i] and len(set(C[i])) != 1:
        ans = False

print("Yes" if ans else "No")


Measured memory_bytes: 3060
#C - Welcome to AtCoder

N, M = map(int, input().split())
Score = [[]*i for i in range(N)]
Count_AC = 0
Count_WA = 0

#小問毎の正誤リスト作成
for i in range(M):
  p, S = input().split()
  Score[int(p)-1].append(S)

for i in range(N):
  for j in range(len(Score[i])):
    if Score[i][j] == "WA":
      continue
    else:
      Count_AC += 1
      Count_WA += j
      break

print(Count_AC, Count_WA)

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

int main(){
	long long n,a=1,b=1,c=1,m=1e9+7,ans=0;
	cin>>n;
	
	for(int i=0;i<n;i++)
		a=(a*10)%m;
		
	for(int i=0;i<n;i++)
		b=(b*8)%m;
		
	for(int i=0;i<n;i++)
		c=(c*9)%m;
		
	c=(2*c)%m;

	ans = (((a%m+b%m)%m)%m - (c)%m)%m;
	if(ans<0)
	ans+=m;
	cout<<ans;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

int main(){
    string s,t;cin >> s >> t;
    int ans = 0;
    rep(i,s.size()-t.size()+1){
        int cnt = 0;
        rep(j,t.size()){
            if(s[i+j] == t[j]) cnt++;
        }
        ans = max(ans,cnt);
    }
    cout << t.size() - ans << endl;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define LC(x) ((x)<<1)
#define RC(x) ((x)<<1|1)

int a[105];
int b[105];
int c[105];

int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++){
        scanf("%d",&a[i]);
    }
    a[0]=a[n]=1e9;
    int ans=0;
    for(int j=1;j<=n;j++){
        b[j]=min(a[j-1],a[j]);
        ans+=b[j];
    }
    printf("%d",ans);
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MODULO 1000000007
#define PI 3.14159265359
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
     ll n;
     cin>>n;
     stack<char> st;
     char x='a';
     while(n)
     {
     	int l=n%26;
     	if(l==0)
     	l=26;
     	st.push(char(x+l-1));
     	n=(n-l)/26;
	 }
	 while(!st.empty())
	 {
	 	cout<<st.top();
	 	st.pop();
	 }
	 cout<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
int a,b,c;
int ans =0;
cin >> a >> b >> c;
c--;
ans++;
int che = min(c,b);
while(che!=0){
   c--;
   b--;
   che--;
   ans++;
   ans++;
}
che = min(a,c);
while(che!=0){
   c--;
   a--;
   che--;
   ans++;
}
cout << ans+b << endl;
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pie 3.142857143
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)

void solve()
{
	ll n, w;
	cin >> n >> w;
	vlli dp(w + 1, 0);
	fr(i, 0, n)
	{
		ll wt, vl;
		cin >> wt >> vl;
		for (ll j = w - wt; j >= 0; j--)
		{
			dp[j + wt] = max(dp[j + wt], dp[j] + vl);
		}

	}
	ll ans = 0;
	fr(i, 0, w + 1)
	{
		ans = max(ans, dp[i]);

	}
	cout << ans << endl;

}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin>>t;
	t = 1;
	while (t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 3964
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = IR(5)
    k = II()
    if max(a) - min(a) > k:
        print(":(")
    else:
        print("Yay!")
    return

#B
def B():
    a = IR(5)
    b = a[0]
    ans = 0
    for a_ in a:
        if a_ % 10 != 0:
            if b % 10> a_ % 10:
                b = a_
    flg = 0
    for a_ in a:
        if a_ != b or flg:
            ans += math.ceil(a_ / 10) * 10
        else:
            ans += b
            flg = 1
    print(ans)
            
    
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 39408
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int MAX=200040;
const ll MOD=1000000007;
vector<int> conn[MAX],dir[MAX],tmp[MAX];
int a,b,com=0,par[MAX],n;
void dfs(int x,int p){
    par[x]=p;
    for(int i=0;i<conn[x].size();i++) if(conn[x][i]!=p) dfs(conn[x][i],x);
}
int simple(int v,int u){
    int p1=1,p2=tmp[v].size()-1,pos=1;
    while(p1<p2){
        if(tmp[v][p1]+tmp[v][p2]>u) pos=0;
        p1++,p2--;
    }
    return pos;
}
int div2(int v,int x,int y,int u){
    if(y-x==1) return x;
    int p=(x+y)/2,p1=0,p2=tmp[v].size()-1,pos=1;
    //for(int i=p1;i<=p2;i++) printf("%d ",tmp[v][i]);
    if(p1==p) p1++;
    if(p2==p) p2--;
    while(p1<p2){
        if(tmp[v][p1]+tmp[v][p2]>u) pos=0;
        p1++,p2--;
        if(p1==p) p1++;
        if(p2==p) p2--;
    }
    if(pos) return div2(v,x,p,u);
    return div2(v,p,y,u);
}
int f(int x,int u){
    tmp[x].clear();
    if(dir[x].size()==0) return 0;
    if(dir[x].size()==1){
        int t=f(dir[x][0],u)+1;
        if(t==0||t>u) return -1;
        return t;
    }
    for(int i=0;i<dir[x].size();i++){
        int t=f(dir[x][i],u)+1;
        if(t==0) return -1;
        tmp[x].push_back(t);
    }
    if(tmp[x].size()%2==0) tmp[x].push_back(0);
    sort(tmp[x].begin(),tmp[x].end());
    int t=div2(x,0,tmp[x].size(),u)+1;
    if(tmp[x].size()==t) return -1;
    if(tmp[x][t]>u) return -1;
    if(simple(x,u)) return tmp[x][0];
    return tmp[x][t];
}
int div22(int x,int y){
    if(y-x==1) return x;
    int p=(x+y)/2,u=f(com,p);
    if(u==-1) return div22(p,y);
    return div22(x,p);
}
int main(){
    scanf(" %d",&n);
    for(int i=0;i<n-1;i++){
        int t1,t2;
        scanf(" %d %d",&t1,&t2);
        conn[t1].push_back(t2);
        conn[t2].push_back(t1);
    }
    for(int i=1;i<=n;i++) if(conn[i].size()%2) com=max(i,com), a+=1;
    a/=2;
    dfs(com,0);
    for(int i=1;i<=n;i++){
        for(int j=0;j<conn[i].size();j++) if(conn[i][j]!=par[i]) dir[i].push_back(conn[i][j]);
    }
    b=div22(0,n+1)+1;
    printf("%d %d\n",a,b);
}


Measured memory_bytes: 31872
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N, K; cin >> N >> K;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	for (int i = K ; i < N; i++) {
		//cout << A[i - K] << " " << A[i] << endl;
		if(A[i-K]<A[i])cout << "Yes" << endl;
		else cout << "No" << endl;
	}

}


Measured memory_bytes: 4784
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.Map.Strict               as M
import           Data.Char


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> Int -> Int
solve n k =
    let 
        a = n `mod` k
    in
        min a (k - a)


main = do
    (n, k) <- readTuple2
    print $ solve n k





Measured memory_bytes: 380
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

bool dp[30009][4][1009];

int main () {
  int n;
  string s;
  cin >> n >> s;
  dp[0][0][0] = true;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= 3; ++j) {
      for (int k = 0; k < 1000; ++k) {
        if (dp[i][j][k] == false) continue;
        dp[i+1][j][k] = true;
        if (j <= 2) {
          dp[i+1][j+1][k*10+(s[i]-'0')] = true;
        }
      }
    }
  }
  int ans = 0;
  rep(i,1000) {
    if (dp[n][3][i] == true) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 118528
from fractions import gcd


def liner_search(n, l):
    for i in range(len(l)):
        if n < l[i]:
            return i
    return len(l)


N, X = map(int, input().split())
x = sorted(list(map(int, input().split())))
x.insert(liner_search(X, x), X)
sabun = [None] * N
for i in range(1, len(x)):
    sabun[i - 1] = x[i] - x[i - 1]
res = gcd(0, sabun[0])
for i in range(1, len(sabun)):
    res = gcd(res, sabun[i])
print(res)


Measured memory_bytes: 16280
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n, k;
ll a[15];
string d[10005];
bool v[10005];
ll b[15] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

bool f(string p, string q)
{
    if(p.size() != q.size()) return p.size() < q.size();
    else return p < q;
}

int main()
{
    scanf("%lld%lld", &n, &k);
    for(ll i = 0; i < k; i++)
    {
        scanf("%lld", &a[i]);
    }
    d[0] = "";
    v[0] = true;
    for(ll i = 1; i <= n; i++)
    {
        for(ll j = 0; j < k; j++)
        {
            ll t = b[a[j]];
            if(i < t) continue;
            if(!v[i - t]) continue;
            d[i - t].push_back(a[j] + '0');
            if(f(d[i], d[i - t])) d[i] = d[i - t];
            d[i - t].pop_back();
            v[i] = true;
        }
    }
    cout<<d[n]<<endl;
    return 0;
}


Measured memory_bytes: 54272
s = input()
t = input()
ls = len(s)
lt = len(t)
mi = 10**6
for i in range(ls-lt+1):
    s1 = s[i:i+lt]
    count = 0
    for j in range(lt):
        if s1[j]!=t[j]:
            count += 1
    mi = min(mi,count)
print(mi)

Measured memory_bytes: 9112
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

n = int(input())
s = input()

op, cl = 0 ,0
# sを右から調べていく
# s[i]が何なら何が必要になるのか
for c in s:
    if c == '(':
        op += 1
    else:
        if op > 0:
            op -= 1
        else:
            cl += 1
# 追加するのは左に'('いくつか右に')'いくつか
print(('(' * cl) + s + (')' * op))

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

int main(void){
  string s;
  cin >> s;
  
  string original = "";
  
  for (int i = 0; i < s.size(); i += 2){
    original += s.at(i);
  }
  
  cout << original << endl;
  
  
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <functional>

using namespace std;


int main()
{
	int K, N, d1 = 0, d2 = 0;
	vector<int> A, d;

	cin >> K >> N;

	A.resize(N);

	d.resize(N);

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



	d[0] = K - A[N - 1] + A[0];
	for (int i = 1; i < N; i++) 
		d[i] = A[i] - A[i-1];
	


	sort(d.begin(), d.end());
	for (int i = 0; i < N - 1; i++)
		d1 += d[i];


	cout << d1;

	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    int n;
    string s="No";
  	cin>>n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==n){
                s="Yes";
                break;
            }
        }
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
import java.util.List;
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();


		long ans=1L;
		for (int i = 0; i < N; i++) {
			long time=sc.nextLong();

			ans=lcm(ans, time);
		}

		System.out.println(ans);

	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}


	public static long gcd(long a, long b) {

		if (b == 0) {
			return a;
		}

		if (a < b) {
			long t = a;
			a = b;
			b = t;
		}

		return gcd(b, a%b);

	}

	public static long lcm(long a, long b) {

		long gcd=gcd(a,b);
		return a /gcd*b;
	}


	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 22996
n, x = list(map(int, input().split()))
al = list(map(int, input().split()))
ans = 0
for i in range(n):
    if i == 0:
        if al[i] > x:
            ans += al[i]-x
            al[i] = x
    else:
        if al[i] + al[i-1] > x:
            ans += al[i] + al[i-1] - x
            al[i] = x - al[i-1]
print(ans)


Measured memory_bytes: 63984
A,B,AB,X,Y = [int(x) for x in input().split()]
total = A*X+B*Y
for xy in range(0,max(X,Y)+1):
  x = X-xy
  y = Y-xy
  if x<0:
    x=0
  if y<0:
    y=0
  if x*A+y*B+xy*2*AB < total:
    total = x*A+y*B+xy*2*AB
    #print(x,y,xy)
print(total)

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

uint64_t nC2(uint64_t n) { return n * (n - 1) / 2; }

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

  map<string, uint> m;
  for(uint i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    m[s]++;
  }

  uint64_t ans = 0;
  for(const auto &e : m) ans += nC2(e.second);

  cout << ans << endl;
}


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

using namespace std;
using ll = long long;


int main()
{
    int R, G, B, n; cin >> R >> G >> B >> n;int cnt = 0;
    for(int i = 0; i <= 3500; i++) {
        for(int j = 0; j <= 3500; j++) {
            if(n - (i * R + j * G) < 0 || (n - (i * R + j * G)) % B)continue;
            cnt++;
        }
    
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int N, res = 0;
    cin >> N;
    rep(i, N) {
        int l, r;
        cin >> l >> r;
        res += r - l + 1;
    }
    cout << res << endl;
    return 0;
}

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

long int gcd(int a, int b);

int main(){
    long long int a, b;
    cin >> a >> b;
    cout << ( a * b ) / gcd(a,b) << endl;
    return 0;
}


long int gcd(int a, int b)
{
    while (b != 0 && a != 0)
    {
        if(b > a)
        {
        int tmp = b;
        b = a;
        a = tmp;
        }
        a = a % b;
        //cout << a << endl;
    }
    
    if (b == 0)
    {
        return a;
    }
    if (a == 0)
    {
        return b;
    }
}

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

int main()
{
  string s;
  cin >> s;
  string ans = "Good";

  for (int i = 1; i < 4; i++) {
    if (s[i - 1] == s[i]) {
      ans = "Bad";
      break;
    }
  }
  cout << ans << endl;
}


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

int main(){
    string s;
    cin>>s;
    int x,y;
    cin>>x>>y;
    int xs=0,ys=0;
    int state=-1;
    vector<int> xv,yv;
    for(auto c:s){
        if(c=='T'){
            if(xs) xv.push_back(xs);
            if(ys) yv.push_back(ys);
            xs=ys=0;
            state=(state+1)%2;
        }
        else{
            switch(state){
                case -1:{
                    x--; break;
                }
                case 0:{
                    ys++; break;
                }
                case 1:{
                    xs++; break;
                }
            }
        }
    }
    if(xs) xv.push_back(xs);
    if(ys) yv.push_back(ys);
    
    auto knapsack=[](vector<int> v,int tar){
        int n=v.size();
        const int OFFSET=8000+5;
        const int SIZE=OFFSET*2+5;;
        vector<vector<int>> dp(2,vector<int>(SIZE,0));
        dp[0][OFFSET]=true;
        for(int i=0;i<n;i++){
            fill(dp[(i+1)&1].begin(),dp[(i+1)&1].end(),0);
            for(int j=0;j<SIZE;j++){
                if(j+v[i]<SIZE) dp[(i+1)&1][j+v[i]]|=dp[i&1][j];
                if(j-v[i]>=0) dp[(i+1)&1][j-v[i]]|=dp[i&1][j];
            }
        }
        return dp[n&1][OFFSET+tar];
    };
    cout<<(knapsack(xv,x) && knapsack(yv,y) ? "Yes" : "No")<<endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
#define MAX 100
 
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
int w, h, xs, ys, xg, yg, G[MAX+2][MAX+2];
 
bool dfs(int x, int y, int color){
    if(color == 0 || G[x][y] != color) return false;
    if(x==xg&&y==yg) return true;
    G[x][y] = 0;
    for(int r=0; r<4; r++){
        if(dfs(x+dx[r], y+dy[r], color)) return true;
    }
    return false;
}
 
int main(void)
{
    int n, c, d, bx, by;
    while(cin>>w>>h, w&&h){
        for(int x=0; x<w+2; x++){
            for(int y=0; y<h+2; y++){
                G[x][y] = 0;
            }
        }
        cin >> xs >> ys >> xg >> yg >> n;
        for(int i=0; i<n; i++){
            cin >> c >> d >> bx >> by;
            for(int i=0; i<4; i++){
                for(int j=0; j<2; j++){
                    if(d==0) G[bx+i][by+j] = c; 
                    else G[bx+j][by+i] = c;
                }
            }
        }
        if(dfs(xs, ys, G[xs][ys])) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
    return 0;
}


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

int main(){

    int N, M;
    cin >> N >> M;
    vector<int> A(40, 0);
    for(int i = 0; i < N; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int a;
            cin >> a;
            A[a]++;
        }
    }

    int ans = 0;
    for(int i = 0; i < A.size(); i++){
        if(A[i] == N) ans++;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define INF (1 << 29)
#define MOD 10000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){

  int a,b,c;
  cin >> a >> b >> c;
  if(a + b + c >= 22)cout << "bust";
  else cout << "win";

  return 0;
}

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

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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);

    for (int i = 0; i < h; i++)
    {
        cin >> s.at(i);
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] == '.')
            {
                int cnt = 0;
                for (int k = 0; k < 8; k++)
                {
                    int x = i + dx[k];
                    int y = j + dy[k];
                    if (0 <= x && x < h && 0 <= y && y < w && s[x][y] == '#')
                    {
                        cnt++;
                    }
                }
                s[i][j] = '0' + cnt;
            }
        }
    }
    for (int i = 0; i < h; i++)
    {
        cout << s[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{	
	int i, N, Q;
	char s[200001], t[200001], d[200001];
	scanf("%d %d", &N, &Q);
	scanf("%s\n", s);
	for (i = 0; i < Q; i++) scanf("%c %c\n", &(t[i]), &(d[i]));
	
	int l = -1, r = N;
	for (i = Q - 1; i >= 0 && l < r - 1; i--) {
		if (d[i] == 'L') {
			if (s[l+1] == t[i]) l++;
			if (r < N && s[r] == t[i]) r++;
		} else {
			if (l >= 0 && s[l] == t[i]) l--;
			if (s[r-1] == t[i]) r--;
		}
	}
	
	printf("%d\n", r - l - 1);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2288
n = int(input())
time = []
for i in range(n):
    a1, b1 = [int(i) for i in input().split()]
    time.append({"need": a1, "timeup":b1})
time_sorted = sorted(time, key=lambda x:x["timeup"])
t = 0
cnt = 0
for line in time_sorted:
    t += line["need"]
    if t > line["timeup"]:
        print("No")
        break
    if cnt==len(time)-1:
        print("Yes")
    cnt += 1

Measured memory_bytes: 80276
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(a+b+c>=22) cout << "bust" << endl;
	else cout << "win" << endl;
	
	return 0;
}

Measured memory_bytes: 256
MOD=10**9+7
class Integer
  def mod_add(x)
    (self + x) % MOD
  end
  def mod_sub(x)
    (self - x) % MOD
  end
  def mod_mul(x)
    (self * x) % MOD
  end
  
  # a.mod_div(b) => a / b
  def mod_div(x)
    (self * x.mod_inv) % MOD
  end
  
  # a.mod_pow(b) => a ** b
  def mod_pow(x)
    a = self
    res = 1
    while x > 0
      res = res * a % MOD if x[0] == 1
      a = a * a % MOD
      x >>= 1
    end
    res
  end
  
  # for prime mod
  def mod_inv()
    self.mod_pow(MOD - 2)
  end
  
  def mod_comb(n, k)
    a = 1
    b = 1
    k.times do |i|
      b *= i + 1
      b %= MOD
    end
    k.times do |i|
      a *= n - i
      a %= MOD
    end
    a * b.mod_inv % MOD
  end
end

#初期値を配列に入れておく
class ModCombination
  attr_reader :fac, :finv
  
  def initialize(n)
    @fac = Array.new(n+1)
    @finv = Array.new(n+1)
    @fac[0] = 1
    1.upto(n) do |i|
      @fac[i] = (@fac[i-1] * i) % MOD
    end
    
    @finv[n] = @fac[n].mod_inv;
    n.downto(1) do |i|
      @finv[i-1] = (@finv[i] * i) % MOD
    end
  end
 
  def combination(n, k)
    return 0 if k < 0 || k > n
    return (@fac[n] * @finv[k] * @finv[n-k]) % MOD
  end
end

N,K=gets.split.map(&:to_i)

mc1 = ModCombination.new(K-1)
mc2 = ModCombination.new(N-K+1)

ans=Array.new(K,0)
(1..K).each do |m|
  if m > N-K+1
    ans[m-1] = 0
  else
    ans[m-1] = (mc1.combination(K-1, m-1) * mc2.combination(N-K+1, m)) % MOD
  end
end
puts ans

Measured memory_bytes: 1916
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string t;
    cin >> t;
    reverse(all(t));
    ll d;
    cin>>d;
    ll dp[t.size() + 1][d][2];
    rep(i,t.size()+1)rep(j,d)rep(k,2)dp[i][j][k]=0;
    dp[0][0][0] = 1;
    rep(i,t.size()){
        rep(j,d){
            rep(k,10){
                ll f = (j + k) % d;
                if(k>t[i]-'0'){
                    dp[i + 1][f][1] += dp[i][j][0] + dp[i][j][1];
                }else if(k==t[i]-'0'){
                    dp[i + 1][f][1] += dp[i][j][1];
                    dp[i + 1][f][0] += dp[i][j][0];
                }else{
                    dp[i + 1][f][0] += dp[i][j][1] +dp[i][j][0];
                }
                dp[i+1][f][0]%=MOD;
                dp[i+1][f][1]%=MOD;
            }
        }
    }
    cout << (dp[t.size()][0][0]+MOD-1)%MOD << endl;
}

Measured memory_bytes: 15872
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
vector<string> splitAll(string s, string t) {
  vector<string> v;
  for (int p = 0; (p = s.find(t)) != s.npos; ) {
    v.push_back(s.substr(0, p));
    s = s.substr(p + t.size());
  }
  v.push_back(s);
  return v;
}

int main(){
  int n, m;
  while(cin>>n>>m && n){
    int parent[1000];
    memset(parent, -1, sizeof(parent));
    int save[1000];
    map<string, int> id;
    cin.ignore();
    REP(i, n){
      string s; getline(cin, s);
      int lev = 0;
      while(s[lev] == ' ') lev++;
      string name = s.substr(lev);
      id[name] = i;
      save[lev] = i;
      if(lev != 0){
        parent[i] = save[lev-1];
      }
    }
    REP(i, m){
      string query; getline(cin, query);
      vector<string> words = splitAll(query, " ");
      string A = words[0];
      string B = words[5].substr(0, words[5].size()-1);
      bool ans = false;
      if(words[3] == "child"){
        ans = parent[id[A]] == id[B];
      }else if(words[3] == "parent"){
        ans = parent[id[B]] == id[A];
      }else if(words[3] == "sibling"){
        ans = parent[id[A]] == parent[id[B]];
      }else if(words[3] == "descendant"){
        int now = id[A];
        while(now != -1){
          if(now == id[B]) ans = true;
          now = parent[now];
        }
      }else if(words[3] == "ancestor"){
        int now = id[B];
        while(now != -1){
          if(now == id[A]) ans = true;
          now = parent[now];
        }
      }
      if(ans) cout<<"True"<<endl;
      else cout<<"False"<<endl;
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1000
//
//  test1_1.cpp
//  test
//
//  Created by Ryohei Nakamura on 2020/03/19.
//  Copyright © 2020 Ryohei Nakamura. All rights reserved.
//
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    int n;
    int b = 0;
    char a;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a == 'Y'){
            b = 1;
            break;
        }
    }
    if(b == 1){
        cout << "Four" << endl;
    }
    else cout << "Three" << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int h, w, cnt=0;
    cin >> h >> w;
    string s;
    for(int i=0; i<h; i++) {
        cin >> s;
        for(int j=0; j<w; j++) if(s[j]=='#') cnt++;
    }
    if(cnt==h+w-1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    rep(i, n) {
        int v = a[i];
        int j = i-1;
        while(j >= 0 and a[j] > v) {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        rep(i, n) {
            cout << a[i] << (i == n-1?'\n':' ');
        }
    }
}


Measured memory_bytes: 3168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp6
{
	class Program
	{
		static void Main(string[] args)
		{
			string abc = Console.ReadLine();
			string[] num = abc.Split(' ');

			int a = int.Parse(num[0]);
			int b = int.Parse(num[1]);
			int c = int.Parse(num[2]);

			if (a < b && b < c)
			{
				Console.WriteLine("Yes");
			}
			else
				Console.WriteLine("No");

		}
	}
}



Measured memory_bytes: 15944
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	ll n;
	cin>>n;
	if(n%2==0){
		cout<<n;
	}else{
		cout<<n*2;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

typedef long long ll;

using namespace std;


int main(){

    
    string s;
    cin >> s;

    rep(i, s.size()){
        cout << "x";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

/**
 * Taking a Seat
 */
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line;

		int M, N;
		M = sc.nextInt();
		N = sc.nextInt();

		boolean[][] seats = new boolean[M + 2][N + 2];

		for (int i = 0; i < M + 2; i++) {
			Arrays.fill(seats[i], true);
		}

		//
		Arrays.fill(seats[1], false);

		for (int i = 1; i <= M; i++) {
			String s = sc.next();
			for (int j = 1; j <= N; j++) {
				char c = s.charAt(j - 1);
				if (c == 'o') {
					for (int k = -1; k <= 1; k++) {
						seats[i][j + k] = false;
					}
				} else if (c == 'x') {
					for (int k = -1; k <= 1; k++) {
						for (int l = -1; l <= 1; l++) {
							seats[i + k][j + l] = false;
						}
					}
				}
			}
		}

		int ans = 0;

		for (int i = 1; i <= M; i++) {
			for (int j = 1; j <= N; j++) {
				if (seats[i][j]) ans++;
			}
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 27692
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()
A = getList()

lista = [[0, 0] for i in range(61)]
# bitの各桁が１か０かをlistaに収納
def splitbit(n):
    for i in range(61):
        if n & (1 << i):
            lista[i][0] += 1
        else:
            lista[i][1] += 1

for i in range(N):
    splitbit(A[i])

bi_int = 0
for i in range(61):
    if lista[i][0] % 2 == 1:
        bi_int += 2 ** i

ans = []
for i in range(N):
    ans.append(bi_int ^ A[i])
print(*ans)

Measured memory_bytes: 116356
n = int(input())
num = 1
list = []

while num <= n:
    list.append(int(input()))
    num += 1

m = max(list)
num2 = 0
aa = True
for i in list:
    if i == m and aa:
        list[num2] = int(m / 2)
        num2 += 1
        aa = False
    else:
       i
       num2 += 1

print(sum(list))

Measured memory_bytes: 3064