akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define forn(i,a,n) for(int i =a; i < n; i++)
#define fi first
#define se second
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef long long int lli;

int main(){__
    string s;
    cin >> s;
    int n =(int)s.size();
    int ans = 1e9;
    int mov =0;
    //primero 0
    forn(i,0,n){
        if(i&1){
            if(s[i] != '1') mov++;
        }
        else{
            if(s[i] != '0') mov++;
        }
    }
    ans = min(ans,mov);
    mov =0;
    //primero 1
    forn(i,0,n){
        if(i&1){
            if(s[i] != '0') mov++;
        }
        else{
            if(s[i] != '1')mov++;
        }
    }
    ans = min(ans,mov);
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
import sys

def intstr(lis):
    a = ''
    for v in lis:
        a += chr(v+97)
    return a

s = list(input())
numS = []
for v in s:
    numS.append(ord(v)-97)#0-25

if len(numS)<26:
    for i in range(0,26):
        if numS.count(i)==0:
            numS.append(i)
            ans = intstr(numS)
            print(ans)
            sys.exit()
else:
    while numS:
        cur = numS.pop()
        for i in range(cur+1,26):
            if numS.count(i)==0:
                numS.append(i)
                ans = intstr(numS)
                print(ans)
                sys.exit()
    print(-1)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void){

  int so, st, co;
  int total[5];
  int max = 0;
  int i, j;

  for(i = 0; i < 1; i--){
    for(j = 0; j < 5; j++){
      scanf("%d%d", &so, &st);
      if((so == 0) && (st == 0)) return 0;
      total[j] = so + st;
      if(max < total[j]){
	max = total[j];
	co = j;
      }
    }
    printf("%c %d\n", 65+co, max);
    max = 0;
    co = 0;
  }
  return 0;
}

Measured memory_bytes: 600
/*
ID: tohoast1
TASK: gymnastics
LANG: C++
*/
#include <bits/stdc++.h>
#define speedup ios_base::sync_with_stdio(NULL)
#define fin freopen("allcodefs.in", "r", stdin)
#define fout freopen("allcodefs.out", "w", stdout)
#define FILENAME
#define PUBG push_back
#define p_b pop_back
#define mp make_pair
#define fi first
#define se second
#define cls clear
#define INF const int ci = 1e6 + 100
#define K_INF 1e9 + 7
#define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define MIN_INT -999999999
#define MOD 1000000007
#define d109 1000000000
#define basay break
#define bmbr exit(0)

using namespace std;
typedef long long LL;
typedef long L;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef string STR;
STR s;

int main() {
    #ifdef FILENAMEs
        fin;
        fout;
    #endif // FILENAME
    getline(cin, s);
    for (int i = 0 ; i < s.size() ; ++ i) {
        if (s[i] == ',') cout << ' ';
        else cout << s[i];
    }
    ///time;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <cctype>
#include <algorithm>
using namespace std;
int main(void){
    int a , b , c ;
    cin >> a >> b >> c;
    if(b - a == c - b){
        cout << "YES" << endl;
    }else{
        cout <<"NO" << endl;
    }
  
    return 0;
}

Measured memory_bytes: 256
import math
from collections import Counter


def num_nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
A_list = list(map(int, input().split()))

cum_sum = [0]
for i in range(N):
    cum_sum.append(cum_sum[i] + A_list[i])
cum_sum = cum_sum[1:]

d = Counter(cum_sum)

ans = 0
for key, val in d.items():
    if key == 0:
        if val == 1:
            ans += val
        else:
            ans += val + num_nCr(val, 2)
    else:
        if val > 1:
            ans += num_nCr(val, 2)

print(ans)


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

bool BUBBLE(int* number, char* mark, int n) {
	int copy_n;
	char copy_m;
	bool flag = true;
	for(int i = 0; i < n; ++i) {
		for(int j = n - 1; j > i; --j) {
			if(number[j] < number[j - 1]) {
				copy_n = number[j];
				number[j] = number[j - 1];
				number[j - 1] = copy_n;
				copy_m = mark[j];
				mark[j] = mark[j - 1];
				mark[j - 1] = copy_m;
			}
		}
	}
	cout << mark[0] << number[0];
	for(int i = 1; i < n; ++i) {
		cout << ' ' << mark[i] << number[i];
	}
	cout << endl;
	return flag;
}

void SELECT(int* number, char* mark, int n) {
	int min;
	int copy_n;
	char copy_m;
	for(int i = 0; i < n; ++i) {
		min = i;
		for(int j = i; j < n; ++j) {
			if(number[j] < number[min]) {
				min = j;
			}
		}
		copy_n = number[i];
		number[i] = number[min];
		number[min] = copy_n;
		copy_m = mark[i];
		mark[i] = mark[min];
		mark[min] = copy_m;
	}
	cout << mark[0] << number[0];
	for(int i = 1; i < n; ++i) {
		cout << ' ' << mark[i] << number[i];
	}
	cout << endl;
}

int main(void) {
	int numberB[36];
	int numberS[36];
	char markB[36];
	char markS[36];
	int n;
	
	cin >> n;
	
	for(int i = 0; i < n; ++i) {
		cin >> markB[i] >> numberB[i];
		markS[i] = markB[i];
		numberS[i] = numberB[i];
	}
	
	if(BUBBLE(numberB, markB, n)) {
		cout << "Stable" << endl;
	} else {
		cout << "Not stable" << endl;
	}
	
	SELECT(numberS, markS, n);
	bool flag = true;
	for(int i = 0; i < n; ++i) {
		if(markS[i] != markB[i]) {
			flag = false;
		}
	}
	if(flag)   cout << "Stable" << endl;
	else       cout << "Not stable" << endl;
	return 0;
}



Measured memory_bytes: 3108
f=lambda:[*map(int,input().split())]
n,k=f()
a=f()
def ok(x):
  c=0
  for i in a:
    c+=0--i//x
  return c<=n+k
l,r=0,10**9
while r-l>1:
  m=l+r>>1
  if ok(m): r=m
  else: l=m
print(r)

Measured memory_bytes: 30656
mod = 1000000007
n = int(input())
A = [int(x) for x in input().split()]
cum = [0]
for a in A:
    cum.append((cum[-1] + a)%mod)

# sum(sum(A[i]*A[j] for j in range(i+1, n)) for i in range(n))%mod =
print(sum(A[i]*(cum[n] - cum[i+1])%mod for i in range(n))%mod)


Measured memory_bytes: 31308
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,ans,a[200001];
int main()
{
	scanf("%lld",&n);
	for (int i=1;i<=2*n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+2*n+1);
	for (int i=1;i<=2*n;i+=2)ans+=min(a[i],a[i+1]);
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
typedef    long long          ll;
typedef    vector<long long>    vi; 
typedef    vector<vi>         vvi; 
typedef    pair<long,long>      ii; 
#define    sz(a)              long((a).size()) 
#define    pb                 push_back 
#define    mp                   make_pair
#define    all(c)             (c).begin(),(c).end() 
#define    tr(c,i)            for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define    present(c,x)       ((c).find(x) != (c).end()) 
#define    cpresent(c,x)      (find(all(c),x) != (c).end())  
#define    input(v,n)           for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define    output(v,n)          for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "



void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 

double pro[302][302][302];
double ex[302][302][302];

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

  ll one=0,two=0,three=0;

  ll n,i,j,k;
  cin>>n;
  for(i=0;i<n;i++)
  {
    ll x;
    cin>>x;
    if(x == 1)one++;
    if(x == 2)two++;
    if(x == 3)three++;

  }

  pro[three][two][one]=1;

  for(i=n;i>=0;i--)
  {
    for(j=n;j>=0;j--)
    {
      for(k=n;k>=0;k--)
      {
        if(i == 0 && k == 0 && j == 0)continue;
        if(pro[i][j][k] == 0)continue;
       // debug(i,j,k,ex[i][j][k],pro[i][j][k]);

        double pw = 1.0*(n-i-j-k)/n;
        pw = pw/(1-pw);

        ex[i][j][k]/=pro[i][j][k];
        ex[i][j][k]+=pw;
        if(i){
        pro[i-1][j+1][k]+=pro[i][j][k]*(i)/(i+j+k);
        ex[i-1][j+1][k]+=(ex[i][j][k]+1)*(pro[i][j][k]*(i)/(i+j+k));
        }

        if(j){
        pro[i][j-1][k+1]+=pro[i][j][k]*(j)/(i+j+k);
        ex[i][j-1][k+1]+=(ex[i][j][k]+1)*(pro[i][j][k]*(j)/(i+j+k));
        }

         if(k){
        pro[i][j][k-1]+=pro[i][j][k]*(k)/(i+j+k);
        ex[i][j][k-1]+=(ex[i][j][k]+1)*(pro[i][j][k]*(k)/(i+j+k));
        }
        //  debug(i,j,k,ex[i][j][k],pro[i][j][k]);
      }
    }
  }

 cout<<fixed<<setprecision(10)<<ex[0][0][0];





  return 0;
}


Measured memory_bytes: 418048
def gcd(a,b):
    if b:
        return gcd(b,a%b)
    else:
        return a

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

def f(x):
    res = 0
    while x%2==0:
        x //= 2
        res += 1
    return res

def main():
    import sys
    readline = sys.stdin.buffer.readline
    N, M = map(int, readline().split())
    a = list(map(int, readline().split()))
    for i in range(N):
        a[i] //= 2

    t = f(a[0])
    for i in range(N):
        if f(a[i]) == t:
            a[i] >>= t
        else:
            print(0)
            return
    M >>= t

    l = 1
    for i in range(N):
        l = lcm(l, a[i])
        if l > M:
            print(0)
            return

    M //= l
    ans = (M + 1) // 2
    print(ans)

main()

Measured memory_bytes: 12528
def gcd(a,b):
  while b:a,b=b,a%b
  return a
def lcm(a,b):return a*b//gcd(a,b)
mod=10**9+7

n=int(input())
a=list(map(int,input().split()))
l=a[0]
for i in range(1,n):
  l=lcm(l,a[i])
l%=mod

ans=0
for i in range(n):
  ans+=l*pow(a[i],mod-2,mod)
  ans%=mod
print(ans)

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

const int MAXN = 200 * 1000 + 20;
int n, q, a, b, num[MAXN], ans[MAXN];
vector <int> adj[MAXN];
bool vis[MAXN];

void dfs(int v, int sm) {
	vis[v] = true;
	sm += num[v];
	ans[v] = sm;
	for (int u: adj[v])
		if (!vis[u])
			dfs(u, sm);
}

int main() {
	ios:: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin >> n >> q;
	for (int i = 1; i < n; i++)
		cin >> a >> b, adj[a].push_back(b), adj[b].push_back(a);
	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		num[a] += b;
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++)
		cout << ans[i] << ' ';
	cout << '\n';
	return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int dp[n + 1];
    dp[1] = 0;
    dp[2] = abs(a[2] - a[1]);
    for (int i = 3; i <= n; i++) {
        dp[i] = std::min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    //for (int i = 1; i <= n; i++) {
     //   std::cout << dp[i] << " ";
   // }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int partition(int *A,int p,int r){

  int x,i,j,tmp;
  
  x=A[r];
  i=p-1;
  
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;

  return i+1;
}


int main(){

  int n,i,k;

  scanf("%d",&n);

  int A[n];
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  k=partition(&A[0],0,n-1);

  for(i=0;i<n;i++){
    if(i==k)printf("[");
    printf("%d",A[i]);
    if(i==k)printf("]");
    if(i!=n-1)printf(" ");
  }
  
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 2112
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]

arr=[str(i) for i in range(10**(n-1) if n>1 else 0,10**n)]

for x in arr:
  for i,tmp in enumerate(l):
    s,c=tmp
    if x[s-1]!=str(c):
      break
  else:
    print(x)
    exit()

print(-1)


Measured memory_bytes: 38256
n = int(input())
b = list(map(int,input().split()))
pops = []


ans = 0

mnd = True
first = True
for i in range(1,len(b)):
    if b[i-1] == b[i]:
        continue
    if first and b[i] != b[i-1]:
        mnd = b[i-1] < b[i]
        first = False
    if mnd and b[i-1] > b[i]:
        ans += 1
        first = True
    elif (not mnd) and b[i-1]<b[i]:
        ans += 1
        first = True
print(ans+1)


Measured memory_bytes: 14224
from collections import defaultdict
while 1:
    n = int(raw_input())
    if n == 0: break
    L = [0]*n
    T = [0]*n
    for man in xrange(n):
        m,l = map(int,raw_input().split())
        L[man] = l
        t = 0
        for date in xrange(m):
            s,e = map(int,raw_input().split())
            t |= 2**(e-6)-2**(s-6)
        T[man] = t

    dp = defaultdict(int)
    for l,t in zip(L,T):
        for bit in dp.keys():
            if bit&t == 0:
                dp[bit|t] = max(dp[bit|t], dp[bit]+l)
        dp[t] = max(dp[t], l)
        
    print max(dp.values())

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

char buf[1 << 20], *p1, *p2;
#define getchar() ((p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++)

template<typename T>
void read(T &x) 
{
	x = 0;
	int f = 1; char c = getchar();
	while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); }
	while (isdigit(c)) { x = x * 10 + c - 48; c = getchar(); }
	x *= f;
}

const int Mod = 1e9 + 7;

inline int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; }
inline int mul(int a, int b) { return 1LL * a * b % Mod; }
inline void updateA(int &a, int b) { a = add(a, b); }
inline void updateM(int &a, int b) { a = mul(a, b); }

const int MAXN = 2e5 + 9;

int fac[MAXN], inv[MAXN], ifac[MAXN];

void Call(int n) 
{
	fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = mul(fac[i - 1], i);
	inv[1] = 1; for (int i = 2; i <= n; ++i) inv[i] = mul(sub(Mod, Mod / i), inv[Mod % i]);
	ifac[0] = 1; for (int i = 1; i <= n; ++i) ifac[i] = mul(ifac[i - 1], inv[i]);
}

int n;

struct Edge { int ver, nxt; } e[MAXN << 2];
int head[MAXN], tot = 0, Head[MAXN];

inline void Add(int x, int y) { e[++tot].ver = y, e[tot].nxt = head[x], head[x] = tot; }
inline void Add_(int x, int y) { e[++tot].ver = y, e[tot].nxt = Head[x], Head[x] = tot; }

int ans = 0;

std::vector<int> G;
bool vis[MAXN];
int edge = 0, s, t;
void GetLoop(int x, int Fa) 
{
	G.push_back(x);
	vis[x] = true;
	for (int i = head[x]; i; ++edge, i = e[i].nxt)
	{
		int y = e[i].ver;
		if (!vis[y]) GetLoop(y, x);
		else if (y != Fa)
			s = x, t = y;
	}
}

int pr[MAXN];
void GetPr(int x) 
{
	for (int i = head[x]; i; i = e[i].nxt) 
	{
		int y = e[i].ver;
		if (y == pr[x] || y == s) continue;
		pr[y] = x;
		GetPr(y);
	}
}

int deg[MAXN];
void Build()
{
	for (auto x : G)
		for (int i = head[x]; i; i = e[i].nxt) 	
		{
			int y = e[i].ver;
			if (y < pr[x]) Add_(x, y), ++deg[y];
			// 令每个点认领它的入边
			// 按照限制关系建边 
		}
}

int sz[MAXN];
void Dfs(int x) 
{
	sz[x] = 1;
	for (int i = Head[x]; i; i = e[i].nxt)
	{
		int y = e[i].ver;
		if (y == pr[x]) continue;
		Dfs(y);
		sz[x] += sz[y];
	}
}

int Calc() 
{
	for (auto i : G)
		Head[i] = deg[i] = 0;
	
	int res = fac[G.size()];
	
	pr[s] = t;
	GetPr(s);
	Build();

	for (auto i : G)
		if (!deg[i])
			Dfs(i);
	for (auto i : G) 
		updateM(res, inv[sz[i]]);
		
	return res;
}

int main() 
{
	read(n);
	for (int i = 1; i <= n << 1; ++i)
	{
		int x, y;
		read(x), read(y);
		y += n;
		Add(x, y), Add(y, x); 
	}

	n <<= 1; 
	Call(n);

	ans = fac[n];

	for (int i = 1; i <= n; ++i) 
		if (!vis[i])
		{
			GetLoop(i, 0);
			if (G.size() << 1 != edge) { ans = 0; break; } // 是否是基环树 
			updateM(ans, ifac[G.size()]);
			int res = 0;
			updateA(res, Calc());
			std::swap(s, t); // 换个方向 
			updateA(res, Calc());
			updateM(ans, res);
	
			G.clear();
			edge = 0;
		}

	printf("%d\n", ans);	

	return 0;
}

Measured memory_bytes: 17396
import collections

n = int(input())
v = list(map(int, input().split()))
a = v[::2]
b = v[1::2]
ac = collections.Counter(a).most_common(2)
bc = collections.Counter(b).most_common(2)
if ac[0][0] != bc[0][0]:
    print(n - ac[0][1] - bc[0][1])
else:
    if len(ac) == 1:
        print(n // 2)
    else:
        print(n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1]))

Measured memory_bytes: 15972
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use proconio::fastout;
use proconio::input;
//use proconio::marker::*;
//use std::collections::HashSet;
// use std::cmp::*;
//use std::collections::VecDeque;

fn main() {
    input! {
       A:i32,B:i32
    }

    println!(
        "{}",
        if A <= 5 {
            0
        } else if A <= 12 {
            B / 2
        } else {
            B
        }
    );
}


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

int main()
{
  string s;
  cin >> s;
  for (size_t i = 0; i < s.length(); i++)
  {
    if (s[i] == '?')
    {
      s[i] = 'D';
    }
  }
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 3748
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a ,b;
    b="yes";
    cin>>a;
    for (int i=0;i<a.size();i++){
        for (int j=i+1;j<a.size();j++){
            if(a.at(i)==a.at(j)){
                b="no";
                break;
            }
        }
    }
    cout<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
# int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字

def nC2(n):
    return n * (n - 1) // 2
s = input()
n = len(s)
dp = [0] * 2020
mod = 2019
temp = 0
dp[0] = 1
for i in range(n):
    m = (int(s[i]) * pow(10, n - i - 1, mod) + temp)% mod
    dp[m] += 1
    temp = m
ans = 0
for i in range(2020):
    if dp[i]:
        ans += nC2(dp[i])
print(ans)

Measured memory_bytes: 68332
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define out(a) printf("%d",a);
char str[1][10];
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	scanf("%s",str);
	str[0][3]='8';
	printf("%s",str);
	return 0;
}

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

int main()
{
	unsigned long long W = 0, H = 0, X = 0, Y= 0;

	std::cin >> W >> H >> X >> Y;

	double ans_a = (double)W *  (double)H / 2.0;
	int ans_s = (X + X == W) && (Y + Y == H);

	std::cout << ans_a << " "<< ans_s << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;

map<string, int> m;
int ppow10[7];
bool ok;

void Pow10(){
	int p = 1;
	rep(i,7){
		ppow10[i] = p;
		p *= 10;
	}
}

int f(string str){
	if(!ok) return 0;
	int ret = 0;
	rep(i,str.size()){
		if(str[i] == '('){
			string tmp;
			int cnt = 0;
			int p;
			for(int j = i+1; j < str.size(); j++){
				if(str[j] == '(') cnt++;
				if(str[j] == ')') cnt--;
				if(cnt == -1){
					p = j;
					break;
				}
				tmp.push_back(str[j]);
			}
			int len = 0, num = 0;
			for(int j = p+1; j < str.size(); j++){
				if('0' <= str[j] && str[j] <= '9') len++;
				else{
					break;
				}
			}
			for(int j = p+1; j < str.size(); j++){
				if('0' <= str[j] && str[j] <= '9') num += ppow10[len-j+p]*(str[j]-'0');
				else break;
			}
			if(num!= 0) ret += f(tmp)*num;
			else ret += f(tmp);
			i = p+len;
			if(!ok) break;
		} else{
			string tmp;
			tmp.push_back(str[i]);
			if(i == str.size()-1){
				ret += m[tmp];
				if(m[tmp] == 0){
					puts("UNKNOWN");
					ok = false;
					break;
				}
				continue;
			}
			if('a' <= str[i+1] && str[i+1] <= 'z'){
				i++;
				tmp.push_back(str[i]);
			}
			int len = 0, num = 0;
			for(int j = i+1; j < str.size(); j++){
				if('0' <= str[j] && str[j] <= '9') len++;
				else{
					break;
				}
			}
			for(int j = i+1; j < str.size(); j++){
				if('0' <= str[j] && str[j] <= '9') num += ppow10[len-j+i]*(str[j]-'0');
				else break;
			}
			if(m[tmp] == 0){
				puts("UNKNOWN");
				ok = false;
				break;
			}
			if(num != 0) ret += m[tmp]*num;
			else ret += m[tmp];
			i += len;
		}
	}
	return ret;
}

int main(){
	Pow10();
	while(true){
		string str;
		int x;
		cin >> str;
		if(str == "END_OF_FIRST_PART") break;
		cin >> x;
		m[str] = x;
	}
	while(true){
		string str;
		cin >> str;
		ok = true;
		if(str == "0") break;
		int F = f(str);
		if(ok) cout << F << endl;
	}
}

Measured memory_bytes: 1236
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;


int MOD=1000000007;

int main(void){
    int a;
    string s;
    cin >> a >> s;
    if(a>=3200) cout << s << endl;
    else cout << "red" << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(a);
    cii(b);
    cii(c);
    int ans = c - a + b;
    co(max(ans, 0));
    return 0;
}

Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc134/tasks/abc134_c
// greedy
import std.algorithm;
import std.stdio;
import std.conv;
import std.string;

void main() {
    const long n =  readln.chomp.to!long;
    long[] as = new long[n];
    foreach(i; 0..n) {
        as[i] = readln.chomp.to!long;
    }

    const long maxima = as.maxCount[0];
    const long count = as.maxCount[1];

    long second = -1;
    for(long i = 0; i < n; i++) {
        if(as[i] > second && as[i] != maxima) {
            second = as[i];
        }
    }

    foreach(item; as) {
        if(item == maxima && count == 1) {
            second.writeln;
            continue;
        }
        maxima.writeln;
    }
}


Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t;
    cin >> t;
    vector<lli> v;
    map<lli, lli> m;
    lli s = 0;
    for1(i, 0, t)
    {
        lli a;
        cin >> a;
        v.pb(a);
        m[a] += 1;
        s += a;
    }
    lli q;
    cin >> q;
    while (q--)
    {
        lli b, c;
        cin >> b >> c;
        lli x = m[b];
        m[b] = 0;
        m[c] += x;
        lli u = (c - b) * x;
        s += u;
        cout << s << endl;
    }
}

Measured memory_bytes: 9936
#include<iostream>
#include<vector>
#include<map>
#define ll long long
using namespace std;

int main(){
  ll N; cin >> N;
  vector<ll> L(N), R(N);
  map<ll,ll> m;
  for (int i = 0; i < N; i++){
    ll a; cin >> a;
    L[i] = a + i;
    R[i] = i - a;
    m[R[i]]++;
  }
  ll ans = 0;
  for (int i = 0; i < N; i++){
    ans += m[L[i]];
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 28952
from collections import deque


n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

graph = [[] for i in range(n)]
for a, b in info:
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)


visited = [False] * n
ans = [0] * n
s = 0
visited[s] = True
q = deque([s])
while q:
    v = q.popleft()
    for nxt_v in graph[v]:
        if visited[nxt_v]:
            continue
        else:
            visited[nxt_v] = True
            ans[nxt_v] = v + 1
            q.append(nxt_v)
print("Yes")
for i in range(1, n):
    print(ans[i])


Measured memory_bytes: 120812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

ll factorial(ll a) {
  if(!a) return 1;
  return a*factorial(a-1)%INF;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  vpii dp(2*N);
  dp[0]=make_pair(1,1);
  bool flag=true;
  rep(i,2*N-1) {
    if(dp[i].second) {
      if(S[i]==S[i+1]) dp[i+1]=make_pair(dp[i].first,0);
      else dp[i+1]=make_pair(dp[i].first+1,1);
    }
    else {
      if(S[i]==S[i+1]) dp[i+1]=make_pair(dp[i].first,1);
      else {
        if(dp[i].first<2) {
          flag=false;
          break;
        }
        dp[i+1]=make_pair(dp[i].first-1,0);
      }
    }
  }
  
  flag=S[0]=='B'&&dp[2*N-1].first==1;
  if(flag) {
    vi pointR, countL(2*N+1);
    rep(i,2*N) {
      countL[i+1]=countL[i];
      if(dp[i].second) pointR.push_back(i);
      else countL[i+1]++;
    }
    ll ans=factorial(N);
    rep(i,N) ans=ans*(N-countL[pointR[N-i-1]]-i)%INF;
    
    cout << ans << endl;
  }
  else cout << 0 << endl;
}

Measured memory_bytes: 4860
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;
typedef pair<int, int> pii;

int n, m, r;
vector<int> trg;

vector<vector<int>> dis;
int cost(int isVisited , int pos) {
	if (isVisited == ((1 << r)-1)) {
		return 0;
	}
	int c = BIG_INT;
	for (int i = 0; i < r;i++) {
		if (((isVisited >> i) & 1) == 0) {
			c = min(c, cost(isVisited + (1 << i),i)+dis[pos][i]);
		}
	}
	return c;
}


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

	trg = vector<int>(r);
	for (int i = 0; i < r;i++) {
		cin >> trg[i];
		trg[i]--;
	}

	vector<vector<int>> g(n, vector<int>(n,BIG_INT));
	for (int i = 0; i < m;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;

		g[a][b] = c;
		g[b][a] = c;
	}


	dis = vector < vector<int>>(r, vector<int>(r));
	for (int i = 0; i < r;i++) {
		vector<int>  d(n, BIG_INT);
		d[trg[i]] = 0;
		priority_queue<pii,vector<pii>,greater<pii>> pq;
		pq.push(make_pair(0, trg[i]));
		vector<bool> isChecked(n, false);
		while (!pq.empty()) {
			int v = pq.top().second;
			pq.pop();
			if (!isChecked[v]) {
				for (int j = 0; j < n;j++) {
					if (d[j] > d[v] + g[v][j]) {
						d[j] = d[v] + g[v][j];
						//cout << i << " " <<j << " " <<d[j]<< endl;
						pq.push(make_pair(d[j], j));
					}
				}
			}

		}
		for (int j = 0; j < r;j++) {
			dis[i][j] = d[trg[j]];
			
		}

	}

	int ans = BIG_INT;
	for (int i = 0; i < r;i++) {
		ans = min(ans, cost(1 <<i, i));
	}
	cout << ans << endl;

	
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N int(2e3+100)
#define pb push_back
#define ll long long int
#define pp pair<int,int>
#define pl pair<ll,ll>
#define fi first
#define si second
using namespace std;
int main() {
	int n,x,y;
	cin>>n>>x>>y;
	int a[n+1];
	for(int i=1;i<n;i++){
		a[i]=0;
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			a[min(j-i,abs(x-i)+abs(y-j)+1)]++;
		}
	}
	for(int i=1;i<n;i++){
		cout<<a[i]<<'\n';
	}
    return 0;
}




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


int main(){
	int ans=0;

	int n,d;
	cin >> n >> d;
	int x[n][d];
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin >> x[i][j];
		}
	}

	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){

			int kyori_2=0;
			for(int k=0;k<d;k++){
				kyori_2+=(x[j][k]-x[i][k])*(x[j][k]-x[i][k]);
			}
			for(int z=0;z<1000;z++){
				if(kyori_2==z*z){
					ans++;
					break;
				}
			}
		}
	}

	cout << ans <<endl;
	
}


Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	string s,t;
	cin>>s>>t;
	map<char,char>mp1,mp2;
	for(int i=0;i<s.size();i++){
		if(mp1.find(s[i])==mp1.end()){
			mp1[s[i]]=t[i];
		}
		if(mp2.find(t[i])==mp2.end()){
			mp2[t[i]]=s[i];
		}
		if(mp1[s[i]]!=t[i]||mp2[t[i]]!=s[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}	
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 776
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
int n;
double x[101],y[101];

int main(void){
	int cnt=1;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%lf %lf",&x[i],&y[i]);
		}
		double res=0.0;
		for(int i=0;i<n;i++){
			res+=y[i]*(x[(i+n-1)%n]-x[(i+1)%n])/2.0;
		}
		printf("%d %.1f\n",cnt++,fabs(res));
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	ll n, m;
	cin >> n >> m;
	if(n == 1 && m == 1){
		cout << 1 << endl;
	}else if(n == 1 || m == 1){
		ll answer = n*m -2;
		if(answer < 0) answer = 0;
		cout << answer << endl;
	}else{
		ll answer = n*m - (n+m)*2 + 4;
		cout << answer << endl;
	}

}


Measured memory_bytes: 3528
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    int p[n],q[n];
    for(int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> q[i];
    }
    int a[n];
    for(int i = 1; i <= n; i++) {
        a[i-1] = i;
    }
    int flag_a = 0,flag_b = 0;
    int s,t,count = 0;
    do {
        flag_a = 1;
        flag_b = 1;
        for(int i = 0; i < n; i++) {
            if(a[i] != p[i]) {
                flag_a = 0;
            }
            if(a[i] != q[i]) {
                flag_b = 0;
            }
        }
        count++;
        if(flag_a == 1) {
            s = count;
        }
        if(flag_b == 1) {
            t = count;
        }
    }while(next_permutation(a,a+n));
    cout << abs(s-t);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1LL<<57)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV], p[MV], q[MV];
ll factx[MV];
ll arr[MV];

void solve(int T)
{
	int n;
	cin>>n;
	factx[0] = 1;
	for(int i=1;i<=n;i++)
	factx[i] = 1LL*i * factx[i-1];
	for(int i=0;i<n;i++)
	cin>>p[i];
	for(int i=0;i<n;i++)
	cin>>q[i];
	ll px = 0, qx = 0;
	for(int i=0;i<n;i++)
	{
		int z = 0;
		for(int j=i;j<n;j++)
		{
			if(p[j] < p[i])
			z++;	
		}	
		px += (1LL*z*factx[n-i-1]);
	}	
	for(int i=0;i<n;i++)
	{	
		int z = 0;
		for(int j=i;j<n;j++)
		{
			if(q[j] < q[i])
			z++;	
		}	
		qx += (1LL*z*factx[n-i-1]);
	}		
	cout<<abs(px-qx)<<"\n";
	return;
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

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

typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

#define fi first
#define se second
#define pb push_back

const ll MOD = 1e9+7;

inline void in() {}
template<class T, class... Ts>
inline void in(T& x, Ts&... xs) {
	int c, s=0; x=0;
	while (c=getchar(), c!='-'&&(c<'0'||c>'9'));
	if (c=='-') s=1, c=getchar();
	do x=x*10+(c-'0'); while (c=getchar(), c>='0'&&c<='9');
	if (s) x=-x;
	in(xs...);
}
inline void ins(char *s) {
    char c; while(c=getchar(), c<33); do *s++=c; while(c=getchar(), c>32); *s=0;
}

int main() {
	int h,w,n;
	in(h,w,n);
	map<pii,int> m;
	rep(i,0,n) {
		int a,b;
		in(a,b);
		rep(x,0,3) {
			rep(y,0,3) {
				int nx=a-x,ny=b-y;
				if(nx>=1&&nx<=h-2&&ny>=1&&ny<=w-2) {
					m[{nx,ny}]++;
				}
			}
		}
	}
	ll ans[10];
	rep(i,0,10)ans[i]=0;
	ans[0]=((ll)h-2)*(w-2)-m.size();
	for(auto p:m) {
		ans[p.se]++;
	}
	rep(i,0,10)printf("%lld\n",ans[i]);
}


Measured memory_bytes: 56448
def run(n, m, ab):
    ab = sorted(ab)
    cnt = 1
    b = ab[0][1]
    c = b
    for i in range(1, m):
        a = ab[i][0]
        b = ab[i][1]
        if a < c and c <= b:
            pass
        elif c <= a:
            cnt += 1
            c = b
        else:
            c = b
    return cnt


def read_line():
    n, m = list(map(int, input().split()))
    ab = []
    for i in range(m):
        a, b = list(map(int, input().split()))
        ab.append([a, b])
    return (n, m, ab)


def main():
    n, m, ab = read_line()
    print(run(n, m, ab))


if __name__ == '__main__':
    main()


Measured memory_bytes: 22956
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: usize,
    k: usize,
    s: chars,
  }
  let mut border = vec![];
  let mut current = 'x';
  for (i, &c) in s.iter().enumerate() {
    if c != current {
      current = c;
      border.push(i);
    }
  }
  border.push(n);
  let l = border.len();
  let mut ans = 0;
  for i in 0 .. l - 1 {
    if s[border[i]] == '0' {
      ans = cmp::max(ans, border[cmp::min(i + 2 * k, l - 1)] - border[i]);
    } else {
      ans = cmp::max(ans, border[cmp::min(i + 2 * k + 1, l - 1)] - border[i]);
    }
  }

  println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    bool ok = true;
    string s_rev = s;
    reverse(s_rev.begin(), s_rev.end());
    if(s != s_rev) ok = false;
    string s_part = s.substr(0,(n-1)/2);
    string s_part_rev = s_part;
    reverse(s_part_rev.begin(), s_part_rev.end());
    if(s_part != s_part_rev) ok = false;
    s_part = s.substr((n+1)/2);
    s_part_rev = s_part;
    reverse(s_part_rev.begin(), s_part_rev.end());
    if(s_part != s_part_rev) ok = false;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
// B

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  int N;
  string s;
  cin>>N>>s;
  int cnt(0);
  for (int i(0);i<s.size();i++){
    if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
      cnt ++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int tri[3],nazo,i,j,n,m;
	scanf("%d",&m);
	for(n=0;n<m;n++){
	scanf("%d %d %d",&tri[0],&tri[1],&tri[2]);
	for(i=0;i<3;i++)for(j=0;j<3;j++){
 	if(tri[j]>tri[i]){nazo=tri[i];tri[i]=tri[j];tri[j]=nazo;}
	}
	if(tri[2]*tri[2]==tri[1]*tri[1]+tri[0]*tri[0]) puts("YES");
	else puts("NO");
	} 
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
int main(){
    int w,h,n;
    cin>>h>>w;
    for(int i=0;i<h;i++){
        char s[100];
        cin>>s;
        n=0;
        for(int j=0;j<w;j++){
        if(j>0)cout<<" ";
        if(s[j]=='c'){
            n=1;
            cout<<"0";
        }else if(n>0){
            cout<<n;
            n++;
        }else{
            cout<<"-1";
        }

        }
        cout<<endl;
    }
    return 0;
}

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

using namespace std;

int main(){
     int n,k;
     cin >> n >> k;
     vector<int>a(n);
     for(int&i : a) cin >> i;
     sort(a.begin(),a.end());
     long long ans = 0;
     for(int i =0;i < k;i++){
          ans += a[i];
     }
     cout << ans;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const int Nmax=2e5+1;
const int Nd=61;
const int INF=1e5;


int main(){
  int h,w;cin>>h>>w;
  map<int,int> s;
  multiset<int> vals;
  rep(i,w) s[i]=i;
  rep(i,w) vals.insert(0);
  
  rep(i,h){
    int l,r;
    cin>>l>>r;
    l--;

    auto it=s.lower_bound(l);
    int mr =-1;
    while(it !=s.end() && it->first <= r){
      mr=max(mr,it->second);
      int x=it->first-it->second;
      vals.erase(vals.find(x));
      s.erase(it++);
    }
    if(mr!=-1 && r<w){
      vals.insert(r-mr);
      s[r]=mr;
    }
    
    int ans=-1;
    if(vals.size()>0){
      ans= *vals.begin()+ (i+1);
    }
    cout<<ans<<endl;
  }


}


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

int main(void) {
  int sx, sy, tx, ty;
  string ans;

  cin >> sx >> sy >> tx >> ty;

  for(int i = 0; i < abs(sy - ty); i++) ans = ans + "U";
  for(int i = 0; i < abs(sx - tx); i++) ans = ans + "R";
  for(int i = 0; i < abs(sy - ty); i++) ans = ans + "D";
  for(int i = 0; i < abs(sx - tx); i++) ans = ans + "L";

  ans = ans + "L";

  for(int i = 0; i < abs(sy - ty) + 1; i++) ans = ans + "U";
  for(int i = 0; i < abs(sx - tx) + 1; i++) ans = ans + "R";

  ans = ans + "DR";

  for(int i = 0; i < abs(sy - ty) + 1; i++) ans = ans + "D";
  for(int i = 0; i < abs(sx - tx) + 1; i++) ans = ans + "L";

  ans = ans + "U";

  cout << ans << endl;

  return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll h,w; cin>>h>>w;
    string s[h];
    rep(i,h) cin>>s[i];
    ll dy[8]={1,1,1,0,0,-1,-1,-1};
    ll dx[8]={1,0,-1,1,-1,1,0,-1};
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#') continue;

            ll num=0;
            rep(k,8){
                ll ni=i+dy[k];
                ll nj=j+dx[k];
                if(ni<0||h<=ni) continue;
                if(nj<0||w<=nj) continue;

                if(s[ni][nj]=='#') num++;
            }
            s[i][j]=num+'0';
        }
    }
    rep(i,h) cout<<s[i]<<endl;
    return 0;
}



Measured memory_bytes: 3624
#include <cstdio>
#include <string>
#include <map>
#include <algorithm>
#include <utility>
#include <iostream>

using namespace std;

char s[49];

int main() {
    int n;
    scanf("%d %s", &n, s);
    map<pair<string, string>, int> cnt;
    for (int i = 0; i < (1 << (n - 1)); ++i) {
        string t = "", rt = "";
        for (int j = n - 1; j >= 0; --j) {
          if (i >> j & 1) {
            t += s[n + j];
          } else {
            rt += s[n + j];
          }
        }
        //cout << t << " " << rt << endl;
        ++cnt[{t, rt}];
        ++cnt[{t, rt}];
    }
    cout << endl;
    long long ans = 0;
    for (int i = 0; i < (1 << (n - 1)); ++i) {
        string t = "", rt = "";
        for (int j = 0; j < n; ++j) {
          if (i >> j & 1) {
            t += s[j];
          } else {
            rt += s[j];
          }
        }
        //cout << t << " " << rt << endl;
        if (cnt.count({t, rt}) != 0) {
          ans += cnt[{t, rt}];
        }
        if(cnt.count({rt, t}) != 0) {
            ans += cnt[{rt, t}];
        }
    }
    printf("%lld\n", ans);
}


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

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

	int S[100000], n, q, num, se;
	num = 0;

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

	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> se;
		if (*lower_bound(S, S + n -1, se) == se)
			num++;
	}

	cout << num << endl;
	return 0;
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;scanf("%d%d",&n,&k);
	priority_queue<int> pq;
	while(n--) {
		int x;scanf("%d",&x);pq.push(-x);
	}
	int ans=0;
	while(k--){
		ans-=pq.top();pq.pop();
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,M,K; cin>>N>>M>>K;

    string ans="No";
    rep(i,0,N+1)rep(j,0,M+1){
        if(M*i+N*j-2*i*j==K) ans="Yes";
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*Hey, What's up?*/

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<long long>v;
int main()
{
    fastio;
    long long a=0,b=0,c,d,e,f=0,l,g,m,n,k,i,j,t,p,q;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a;
        v.push_back(a);
    }
    q=0;
    p=1;
    for(i=0;i<n;i++){
        if(v[i]==p){
            p++;
        }
        else {
            q++;
        }
    }
    if(q==n){
        cout<<-1<<'\n';
    }
    else cout<<q<<'\n';
    return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>

int main(void)
{
    int d;
    scanf("%d", &d);
    switch(d) {
        case 25:
            printf("Christmas");
            break;
        case 24:
            printf("Christmas Eve");
            break;
        case 23:
            printf("Christmas Eve Eve");
            break;
        case 22:
            printf("Christmas Eve Eve Eve");
            break;
    }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int Alice = 0, Bob = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 == 0){
      Alice += a[i];
    }
    else{
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
  return 0;
}

Measured memory_bytes: 3608
import java.util.*;

class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int x = sc.nextInt();
   int y = 0;
   Gcd gcd = new Gcd();
   for(int i=1;i<=x;i++){
     for(int j=1;j<=x;j++){
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     }
   }
   System.out.println(y);
 }
}

class Gcd{
   int gcd(int a,int b,int c){
     int min = a;
     int num = 1;
     if(a>b&&b<=c)
       min = b;
     else if(a>b&&b>c)
       min = c;
     
     for(int i=1;i<=min;i++){
       if(a%i==0&&b%i==0&&c%i==0)
         num = i;
     }
     return num;
   }
}

Measured memory_bytes: 35876