akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int in[N],n,ans,is,msk,to = 1<<26,from,lol = 1;
vector<int>v;
short dp[1<<26];
void val(int msk){
	v.clear();
	while(msk)
		v.push_back(msk%3),
		msk/=3;
	while(v.size() < 16)v.push_back(0);
	reverse(v.begin(),v.end());
}
int main(){
	//freopen("input.txt","r",stdin);
	scanf("%d",&n);
	for(int i = 1,a,b,c;i < n;i++){
		scanf("%d%d%d",&a,&b,&c);
		in[a]^=c;
		in[b]^=c;
	}
	for(int i = 0;i < n;i++)
		ans+=!!(is&(1<<in[i])) && in[i],
		is^=1<<in[i];
	is&=(~0) - 1;
	for(int i = 0;i < to;i++)dp[i] = 17;
 	for(int i = 15;i + 1;i--)msk = msk*3 + (!(is&(1<<i)) ? 2 : 0),lol*=3;
 		lol/=3;
	dp[msk] = 0;
	for(int i = 0;i < to;i++)
		if(dp[i] < 17){
			val(i);
			int three = lol, freq = 0,temp = 0;
			from = 0;
			for(int j = 0;j < 16;j++,three/=3){
				if(!v[j])dp[i + three] = min(dp[i + three],dp[i]);
				if(v[j] == 1)temp^=(15 - j),freq++;
				from = from*3 + (v[j] ? 2 : 0);
			}
			short lol = dp[i] + freq - (freq > 1);
			if(!temp)dp[from] = min(dp[from],lol);
		}
	from = 0;
	for(int i = 0;i < 16;i++)from = from*3 + 2;
	cout << ans + dp[from] << endl;
}

Measured memory_bytes: 131712
# -*- coding: utf-8 -*-

N = int(input())

# 約数の個数
def divisor_num(n):
    res = 0
    for i in range(1, n+1):
        if n % i == 0:
            res += 1
    return res

ans = 0
for i in range(N, -1, -1):
    if i % 2 != 0:
        if divisor_num(i) == 8:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int n;
double tab[3001];
double dp[3001][3001];
double solve(int idx,int k){
    if(idx==n&&k>(n/2))return 1.0;
    if(idx==n&&(k<=(n/2)))return 0.0;
    if(dp[idx][k]!=-1.0)
        return dp[idx][k];
    double ans=tab[idx]*solve(idx+1,(k+1));
    ans+=(1-tab[idx])*solve(idx+1,k);
    return dp[idx][k]=ans;
}
int main(){
    boost;
    cin>>n;
    for (int i = 0; i < 3001; ++i)
        for (int j = 0; j < 3001; ++j)
            dp[i][j]=-1.0;
    for (int i = 0; i < n; ++i)
        cin>>tab[i];
    cout<<fixed<<setprecision(9)<<solve(0,0);
    return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin n,m,xx,yy;
lin x[102], y[102];

int main(void)
{
    cin >> n >> m >> x[0] >> y[0];
    rep(i,n)
    {
        cin >> x[i+1];
    }
    rep(i,m)
    {
        cin >> y[i+1];
    }

    sort(x, x+n+1);
    sort(y, y+m+1);
    bool res = x[n] < y[0];
    if(res)
        cout << "No War" << endl;
    else
        cout << "War" << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;
int fa[100010];
int finds(int x){
    if(fa[x] == x) return x;
    fa[x] = finds(fa[x]);
    return fa[x];
}
void join(int x,int y){
    int fx = finds(x);
    int fy = finds(y);
    if(fx != fy) fa[fx] = fy;
}
int p[100005];
int a[100005],b[100005];
int main()
{
    int n,m;
    cin >> n >> m;
    for(int i = 1;i <= n;++i) scanf("%d",&p[i]);
    for(int i = 1;i <= n;++i) fa[i] = i;
    for(int i = 1;i <= m;++i){
        scanf("%d%d",&a[i],&b[i]);
        join(a[i],b[i]);
    }
    int cnt = 0;
    for(int i = 1;i <= n;++i){
        if(finds(p[i]) == finds(i)) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n,k;
  cin >> n >> k;
  cout << n-k+1 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	void solve() {
		int n = in.nextInt(), m = in.nextInt();
		char[][] a = new char[n][m];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextToken().toCharArray();
		}

		int[][][] cost = new int[m][n + 1][n + 1];
		for (int i = 0; i + 1 < m; i++) {
			for (int s1 = n; s1 >= 0; s1--) {
				for (int s2 = n; s2 >= 0; s2--) {
					int pos1 = n - s1 - 1;
					int pos2 = n - s2 - 1;
					if (pos1 >= 0 && pos2 >= 0 && a[pos1][i] == a[pos2][i + 1]) {
						cost[i][s1][s2]++;
					}
					if (s1 + 1 <= n && s2 + 1 <= n) {
						cost[i][s1][s2] += cost[i][s1 + 1][s2 + 1];
					}
				}
			}
		}

		int result = 0;
		for (int I = 0; I + 1 < m; I++) {
			int[][] cst = cost[I];
			int INF = Integer.MAX_VALUE / 4;
			int[][] dp = new int[n + 1][n + 1];
			for (int[] i : dp) {
				Arrays.fill(i, INF);
			}

			dp[n][n] = 0;
			for (int i = n; i >= 0; i--) {
				for (int j = n; j >= 0; j--) {
					if (i < n) {
						int val = dp[i + 1][j] + cst[i][j];
						dp[i][j] = Math.min(dp[i][j], val);
					}
					if (j < n) {
						int val = dp[i][j + 1] + cst[i][j];
						dp[i][j] = Math.min(dp[i][j], val);
					}
				}
			}
			result += dp[0][0];
		}
		out.println(result);
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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


Measured memory_bytes: 189036
import java.util.Scanner;

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

        int n = sc.nextInt();
        int b4 = 0;
        int b2 = 0;
        int b0 = 0;

        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            if (a % 2 == 0) {
                if (a % 4 == 0)
                    b4++;
                else
                    b2++;
            } else {
                b0++;
            }
        }

        String ans = "Yes";

        if (b0 > b4) {
            ans = "No";
        }
        if (b2 == 0 && b0 - b4 == 1)
            ans = "Yes";

        System.out.println(ans);
    }

}

Measured memory_bytes: 46088
import math
import string


def readints():
    return list(map(int, input().split()))


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


a, b = map(int, input().split())

print("Even" if (a*b) % 2 == 0 else "Odd")


Measured memory_bytes: 3828
from collections import*
(n,m),a,*q=[[*map(int,o.split())]for o in open(0)]
t=[-1]*n
def r(x):
 while t[x]>=0:x=t[x]
 return x
def u(L):
 x,y=map(r,L)
 if x!=y:
  if t[x]>t[y]:x,y=y,x
  t[x]+=t[y];t[y]=x
d=defaultdict(list)
for l in q:u(l)
i=c=0;b=[];k=(n+~m)*2
for v in a:d[r(i)]+=v,;i+=1
print(k<1and'0'or k>n and'Impossible'or exec("for r,p in d.items():p.sort();c+=p.pop(0);b+=p;k-=1")or c+sum(sorted(b)[:k]))

Measured memory_bytes: 35664
#include <stdio.h>
#include <limits.h>
 int main() { int t,x,y,z,p;
    scanf("%d%d%d%d",&x,&y,&z,&p);
    
    (x>y)? t=y*z+(x-y)*p:
    t=x*z;
    printf("%d",t);
    
    
 return 0; }

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=min((a), (b))

const int MOD=1000000007;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int a[364364], b[364364];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s;
	cin>>n>>s;
	REP(i, n){
		if(s[i]=='E'){
			a[i+1]=a[i]+1;
			b[i+1]=b[i];
		}
		else{
			a[i+1]=a[i];
			b[i+1]=b[i]+1;
		}
	}
	int ans=1<<30;
	REP(i, n){
		int e=a[n]-a[i+1];
		ans=min(ans, e+b[i]);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 2964
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import qualified Data.IntMap as I
import qualified Data.Map as M

main = do
    s <- getLine
    k <- readLn
    putStrLn $ solve s k

solve :: String -> Int -> String
solve s k = (sort (allsub k s)) !! (k-1)

allsub :: Int -> String -> [String]
allsub k str = concat $ map (subuniq str) [1..k]

subuniq :: String -> Int -> [String]
subuniq str w = nub $ subs str w

subs :: String -> Int -> [String]
subs str w | length str < w = []
           | otherwise = (take w str) : subs (tail str) w


Measured memory_bytes: 4348
from heapq import heappush,heappop
I=lambda:list(map(int,input().split()));n,a,b=int(input()),I(),I()
w=x=y=z=0
c,h=[],[]
for i in range(n):
  x+=a[i];y+=b[i]
  if a[i]<b[i]:c.append(b[i]-a[i]);z+=1
  else:heappush(h,b[i]-a[i])
if x<y:print(-1);exit()
for i in c:
  w-=i
  while w<0:w+=-heappop(h);z+=1
print(z)

Measured memory_bytes: 18484
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
int main() {
  int a, b;
  cin >> a >> b;
  cout << 6 / a / b << endl;
}

Measured memory_bytes: 3648
using System;

namespace ABC152
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			string[] ps = Console.ReadLine().Split(' ');
			int[] p = new int[n];

			for(int i = 0; i < n; i++)
			{
				p[i] = int.Parse(ps[i]);
			}

			int count = 0;
			int min = 2 * 100000 + 1;

			for (int i = 0; i < n; i++)
			{
				if(min > p[i])
				{
					min = p[i];
				}

				if(min >= p[i])
				{
					count++;
				}
			}

			Console.WriteLine(count);
		}
	}
}

Measured memory_bytes: 31068
n = int(input())
list02 = []
list01 = input().split()
#print(list01)
#print(list01[0])
#for a in range(0,n):
#  list02.append(list01[n-a-1])
for b in range(n-1,0,-1):
  print(list01[b],end=' ')
print(list01[0])


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
///////////////////////////
int main() {
  long long int n,m,count=1000000000,ans=0;
  cin>>n>>m;
  vector<long long int> a(n),b(n),c(m),d(m);
  for(long long int i=0;i<n;i++) cin>>a[i]>>b[i];
  for(long long int i=0;i<m;i++) cin>>c[i]>>d[i];
  
  
  
  for(long long int i=0;i<n;i++){
    count=1000000000;
    for(long long int j=0;j<m;j++){
      if(count>abs(a[i]-c[j])+abs(b[i]-d[j])){
        ans=j;
        count=abs(a[i]-c[j])+abs(b[i]-d[j]);
      }
    }
    cout<<ans+1<<endl;
  } 
}



///////////////////////////



Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip() 
def main():
    moji=input()
    cycle=int(input())
    flont_or_back=0
    flont=""
    back=""
    for i in range(cycle):
        line=input()
        if line[0]=="1":
            flont_or_back+=1
        else:
            fi=line[2]
            ci=line[4]
            if flont_or_back%2==0:
                if fi=="1":
                    flont=ci+flont
                else:
                    back+=ci
            else:
                if fi=="1":
                    back+=ci
                else:
                    flont=ci+flont
    moji=flont+moji+back
    if flont_or_back%2==0:
        print(moji)
    else:
        print(moji[::-1])
    

if __name__ == '__main__':
    main() 
  


Measured memory_bytes: 4520
#include <cstdio>
#include <utility>
#include <algorithm>
using namespace std;
pair<int, pair<int, int > > p[2010];
const int mod = 1000000007;
int add(int &v, int x) {
	v += x;
	if (v >= mod) v -= mod;
}
int par[1010];
int find(int x) {
	return par[x] == x ? x : (par[x] = find(par[x]));
}
int p2[2010];
int main() {
	int n, m;
	long long x;
	scanf("%d%d", &n, &m);
	scanf("%lld", &x);
	for (int i = 0; i < m; i++) {
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		--u; --v;
		p[i] = make_pair(w, make_pair(u, v));
	}
	sort(p, p + m);
	for (int i = 0; i < n; i++) {
		par[i] = i;
	}
	int nc = n;
	long long mw = 0;
	for (int i = 0; i < m; i++) {
		int u = p[i].second.first, v = p[i].second.second, w = p[i].first;
		if (find(u) == find(v)) {
			continue;
		}
		par[find(u)] = find(v);
		mw += w;
		nc--;
	}
	if (nc != 1 || mw > x) {
		puts("0");
		return 0;
	}
	p2[0] = 1;
	for (int i = 1; i < 2010; i++) {
		p2[i] = p2[i-1];
		add(p2[i], p2[i]);
	}
	long long mmw = mw;
	int ans = 0;
	nc = 1;
	int nb = 0;
	for (int i = 1; i < m; i++) {
		int u = p[i].second.first, v = p[i].second.second, w = p[i].first;
		for (int j = 0; j < n; j++) {
			par[j] = j;
		}
		par[find(u)] = find(v);
		mw = w;
		for (int j = 0; j < m; j++) {
			if (j == i) continue;
			u = p[j].second.first, v = p[j].second.second, w = p[j].first;
			if (find(u) == find(v)) {
				continue;
			}
			par[find(u)] = find(v);
			mw += w;
		}
		if (mw == x) {
			nc++;
		} else if (mw > x) {
			nb++;
		}
	}
	ans = p2[nc];
	add(ans, mod - 2);
	ans = (long long)ans * p2[nb] % mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
/*
 Sarthak Jain
*/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
  return (a<b)?a:b;
}
int max(int a,int b){
  return (a>b)?a:b;
}
int fp(int a,int b){
  if(b==0) return 1;
  int x=fp(a,b/2);
  x=(x*x)%mod;
  if(b&1) x=(x*a)%mod;
  return x;
}


signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 int n,x,ans=0;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  cin>>x;
  if((i&1)&&(x&1))
    ans++;
 }
 cout<<ans;

}

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

int main() {
	static long long N, A[200010], ANS = 0;
	static bool B[200010];
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = N; i > 0; i--) {
		int COUNT = 0;
		for (int j = 2; i * j <= N; j++) {
			if (B[i * j]) COUNT++;
		}
		if (COUNT % 2 != A[i] % 2) B[i] = true;
	}
	for (int i = 1; i <= N; i++) if (B[i]) ANS++;
	cout << ANS << endl;
	ANS = 0;
	for (int i = 1; i <= N; i++) {
		if (B[i]) {
			if (ANS != 0) cout << " ";
			cout << i;
			ANS++;
		}
	}
	cout << endl;
}

Measured memory_bytes: 2688
//This disgusting code is wriiten by Juruo D0zingbear
//Please don't hack me! 0v0 <3
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}

// cf IO: I64d
// atcoder IO: £ì£ì£ä
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int Maxn=200005;
const int Maxm=70000000;
map<int,vector<int> > v;
int sum[Maxn];
char c[Maxn];
int dp[Maxn];
int Mn
[Maxm];
int gs(int pos){
	if (pos==-1) return 0;
	return sum[pos];
}
int main(){
	//cout<<sizeof(pos)<<' '<<sizeof(sum);
	scanf("%s",c);
	int n=strlen(c);
	int full=0;
	for (int i=0;i<26;i++) full|=(1<<i);
	v[0].pb(-1);
	for (int i=0;i<n;i++){
		if (i) sum[i]=sum[i-1];
		sum[i]^=(1<<(c[i]-'a'));
		//cout<<sum[i]<<' ';
		v[sum[i]].pb(i);
	}
	for (int i=0;i<Maxm;i++) Mn[i]=1e9;
//	cout<<endl;
	dp[0]=0;
	Mn[0]=0;
	for (int i=1;i<=n;i++){
		dp[i]=1e9;
		int nv=gs(i-1);
		for (int j=0;j<27;j++){
			int wv=nv^(1<<j);
			if (j==26) wv=nv;
			if (v.count(wv)){
				dp[i]=min(dp[i],Mn[wv]+1);
			}
		}
		Mn[nv]=min(Mn[nv],dp[i]);
	//	cout<<"ff"<<dp[i]<<endl;
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 297344
N,M = map(int, input().split())
X = [x for x in map(int, input().split())]
sorted_x = sorted(X)
# print(sorted_x)
index = range(len(X)-1)
# print(index)
diff = [sorted_x[n+1] - sorted_x[n] for n in index]
sorted_diff = sorted(diff,reverse=True)
# print(sorted_diff)
sub_diff = sorted_diff[N-1:]
# print(sub_diff)
print(sum(sub_diff))


Measured memory_bytes: 13840
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    if(s[k-1]=='A') s[k-1]='a';
    else if(s[k-1]=='B') s[k-1]='b';
    else s[k-1]='c';
    cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define pb push_back
#define ALL(v) v.begin(),v.end()
const long long INF = 1LL << 60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] { -1, 0, 1, 0};
int dy[] {  0, -1, 0, 1};
int main()
{
    int H, W, K, si, sj, ti, tj;
    cin >> H >> W >> K >> si >> sj >> ti >> tj;
    --si;--sj;--ti;--tj;
    vector<string> G(H);
    rep(i, H) cin >> G[i];

    auto toId = [&](int i, int j, int v)
    {
        return (i*W+j)*4+v;
    };
    auto modCeilK = [&](ll x)
    {
        return (x+K-1)/K*K;
    };
    vector<ll> dist(H*W*4, INF);
    priority_queue<LP, vector<LP>, greater<LP>> q;
    auto push = [&](int i, int j, int v, ll x)
    {
        auto id = toId(i, j, v);
        if(dist[id] <= x) return;
        dist[id] = x;
        q.emplace(x, id);
    };
    rep(v, 4) push(si, sj, v, 0);
    while(!q.empty()){
        ll d = q.top().first;
        int id = q.top().second;
        q.pop();
        if(dist[id] != d) continue;
        int i = id/W/4;
        int j = id/4%W;
        int v = id%4;
        rep(nv, 4){
            push(i, j, nv, modCeilK(d));
        }
        int ni = i+dx[v], nj = j +dy[v];
        if(!(0<=ni && ni <H && 0<=nj && nj <W)) continue;
        if(G[ni][nj]== '@') continue;
        push(ni, nj, v, d+1);
    }
    ll ans = INF;
    rep(v, 4) chmin(ans, dist[toId(ti, tj, v)]);
    if(ans == INF) ans = -1;
    else ans = modCeilK(ans)/K;
    cout << ans << endl;
    return 0;
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

//グラフ関連
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

class UnionFind {
    vector<int> data;
    int num;

  public:
    UnionFind(int size) : data(size, -1), num(size) {}
    bool unionSet(int x, int y) {
        x = root(x);
        y = root(y);
        if(x != y) {
            if(data[y] < data[x])
                swap(x, y);
            data[x] += data[y];
            data[y] = x;
            num--;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
    int numSet() {
        return num;
    }
};

void solve() {
    ll n, m;
    cin >> n >> m;
    UnionFind uni(n);
    REP(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        uni.unionSet(a, b);
    }

    int ans = 0;
    REP(i, n) {
        chmax(ans, uni.size(i));
    }
    cout << ans << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 3988
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
int n,k;cin>>n>>k;int arr[n];
for(int i=0;i<n;i++)
    cin>>arr[i];
   sort(arr,arr+n);int sum=0;
   for(int i=0;i<k;i++)
   {
       sum+=arr[i];
   }
   cout<<sum<<"\n";

return 0;
}


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

int main() {

    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    if(s.size()<=2){
    	cout << 0 << endl;
    }else{
    	for(int i=0; i<n-2;i++){
    		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
    			ans += 1;
    		}
    	}
    	cout << ans << endl;
    }
} 

Measured memory_bytes: 256
const main = input => {
  let [a, b] = input.split('\n');
  let [n, k] = a.split(' ');
  let ans = b.split(' ').map(x => Number(x)).sort((a, b) => a - b).reduce((acc, current, index, array) => {
    if (index < k) {
      return acc + current;
    } else {
      return acc;
    }
  });
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29584
#include<iostream>
using namespace std;
int main()
{
    int n,i,x,k=0;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> x;
        while(x%2==0)
        {
            x/=2;
            k++;
        }
    }
    cout << k << endl;
    return 0;
}


Measured memory_bytes: 256
nums=input().split()
h=int(nums[0])
w=int(nums[1])

myfield=[]

for i in range(h):
    temp=input()
    myfield.append([])
    for j in range(len(temp)):
        myfield[i].append(temp[j])

myfield2=[]

myfield2.append([])
myfield2[0].append("-")
for i in range(w):
    myfield2[0].append("-")
myfield2[0].append("-")
for i in range(h):
    myfield2.append([])
    myfield2[i+1].append("-")
    for j in range(w):
        myfield2[i+1].append(myfield[i][j])
    myfield2[i+1].append("-")
myfield2.append([])
myfield2[h+1].append("-")
for i in range(w):
    myfield2[h+1].append("-")
myfield2[h+1].append("-")

for i in range(h):
    for j in range(w):
        if myfield[i][j]=="#":
            continue
        temp=0
        for k in range(3):
            for l in range(3):
                if myfield2[i+k][j+l]=="#":
                    temp+=1
        myfield[i][j]=str(temp)

for i in range(h):
    temp=""
    for j in range(w):
        temp+=myfield[i][j]
    print(temp)

Measured memory_bytes: 3192
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <assert.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
using namespace std;

// #define __DEBUG__

#ifdef __DEBUG__
bool debug_disabled = false;
#else
bool debug_disabled = true;
#endif

#define dbg if (debug_disabled) {} else cerr

void solve() {
    int K;
    string S;
    cin >> K >> S;
    if (S.size() <= K) cout << S << endl;
    else {
        for (int i = 0; i < K; ++i) cout << S[i];
        cout << "..." << endl;
    }
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3656
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<ctime>

using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;

int main(){
	int n;
	while(~scanf("%d", &n)){
		int a[105], i, j, m, ans = 1;
		for(i = 0; i < n; i++) scanf("%d", &a[i]);
		for(i = 1; i < n; i++){
			for(j = 0; j < i; j++){
				if(a[i] != a[j]){
					if(j + 1 == i) ans++;
				}
				else break;
			}
		}
	    printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}


int main() {
	int d;
	cin >> d;
	switch (d) {
	case 25:
		cout << "Christmas";
		break;
	case 24:
		cout << "Christmas Eve";
		break;
	case 23:
		cout << "Christmas Eve Eve";
		break;
	case 22:
		cout << "Christmas Eve Eve Eve";
		break;
	
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>
double PI = M_PI * 60 / 180;

using namespace std;

void solve(int deep, pair<double, double> begin, pair<double, double> end) {
  if(deep == 0) {
    return;
  }
  pair<double, double> s = make_pair((2 * begin.first + end.first) / 3, (2 * begin.second + end.second) / 3);
  pair<double, double> t = make_pair((begin.first + 2 * end.first) / 3, (begin.second + 2 * end.second) / 3);
  double uForx = (t.first - s.first) * cos(PI) - (t.second - s.second) * sin(PI) + s.first;
  double uFory = (t.first - s.first) * sin(PI) + (t.second - s.second) * cos(PI) + s.second;
  pair<double, double> u = make_pair(uForx, uFory);
  solve(deep - 1, begin, s);
  printf("%.8f %.8f\n", s.first, s.second);
  solve(deep - 1, s, u);
  
  printf("%.8f %.8f\n", u.first, u.second);
  solve(deep - 1, u, t);
  printf("%.8f %.8f\n", t.first, t.second);

  solve(deep - 1, t, end);
}


int main(void) {
  int n;

  cin >> n;
  pair<double, double> begin = make_pair(0, 0);
  printf("%.8f %.8f\n", begin.first, begin.second);
  pair<double, double> end = make_pair(100, 0);
  solve(n, begin, end);
  printf("%.8f %.8f\n", end.first, end.second);
  return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    char a,b;

    scanf("%c %c", &a, &b);

    if( a == b ) printf("H\n");
    else    printf ("D\n");

    return 0;
}



Measured memory_bytes: 256
n = list(map(int,input()))
a = n.pop()
if a == 2 or a == 4 or a == 5 or a == 7 or a == 9:
    print("hon")
if a == 0 or a == 1 or a == 6 or a == 8:
    print("pon")
if a == 3:
    print("bon")

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

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

    int m = n;
    int digit = 0;
    while(m > 0){
        m /= 10;
        digit += 1;
    }

    int count = 0;
    for(int i=1; i<digit; i += 2){
        count += (pow(10, i) - 1) - (pow(10, i-1) - 1);
    }
    if(digit % 2 == 1){
        count += n - pow(10, digit - 1) + 1;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner s = new Scanner(System.in);
	int a = s.nextInt();
	int b = s.nextInt();
	int c = s.nextInt();

	if(a < b && b < c) System.out.println("Yes");
	else System.out.println("No");
    }
}



Measured memory_bytes: 26148
i = int(input())

tarou = 0
hanako = 0

for x in range(i):
    a,b = input().split()
    if b > a:
        hanako += 3
    elif a > b:
        tarou += 3
    else:
        hanako += 1
        tarou += 1
print("{0} {1}".format(tarou, hanako))

Measured memory_bytes: 7652
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	string s;
	cin >> s;
	bool up = 0, down = 0, right = 0, left = 0;
	for (int i = 0; i < SZ(s); i++) {
		if (s[i] == 'N')
			up = 1;
		else if (s[i] == 'S')
			down = 1;
		else if (s[i] == 'E')
			right = 1;
		else
			left = 1;
	}
	if ((up ^ down) || (left ^ right))
		puts("No");
	else
		puts("Yes");
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000002486618624LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, a, x[111111] = {0};

  std::cin >> N;

  for (int i = 0; i < N; i ++) {
    std::cin >> a;

    if (a == 0) {
      x[0] ++;
      x[1] ++;
    }
    else {
      x[a - 1] ++;
      x[a    ] ++;
      x[a + 1] ++;
    }
  }

  int xp = 0;

  for (int i = 0; i < 111111; i ++)
    xp = std::max(x[i], xp);

  std::cout << xp << std::endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  int N, M;
  cin >> N >> M;
  vector<string> A(N), B(M), C(M);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  for(int i = 0; i < M; i++){
    cin >> B.at(i);
  }
  bool flag = false;
  for(int i = 0; i < N-M; i++){
    for(int j = 0; j < N-M; j++){
      for(int k = 0; k < M; k++){
        C.at(k) = A.at(i+k).substr(j, M);
      }
      if(C == B){
        flag = true;
        break;
      }
    }
  }
  if(flag || A == B) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int main() {
  int number_n, number_k, i, j, temp;
  scanf("%d %d", &number_n, &number_k);
  int height[number_n];
  int sum_cost[number_n];
  for(i = 0; i< number_n; i++) {
    scanf("%d", &height[i]);
    sum_cost[i] = INT_MAX;
  }
  sum_cost[0] = 0;
  sum_cost[1] = abs(height[0] - height[1]);
  for(i = 2; i < number_n; i++) {
    for(j = 0; j < number_k; j++) {
      temp = sum_cost[i-j-1] + abs(height[i] - height[i-j-1]);
      sum_cost[i] = (sum_cost[i] <= temp)? sum_cost[i] : temp;
      if(i == j + 1) {
        break;
      }
    }
  }
  printf("%d\n", sum_cost[number_n-1]);
  return 0;
}


Measured memory_bytes: 896
#include<iostream> 
main(){for(;;){int d[5]={},s=0,i=0;for(;i<5;i++){int h;std::cin>>h;if(!h)return 0;s|=d[i]=1<<(h-1);}for(i=0;i<5;i++){std::cout<<(s==7|s==d[i]?3:((s^d[i])==d[i]*2|(s^d[i])==d[i]/4?1:2))<<"\n";}}}

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

using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    bool flag=true;
    for(int i=0,j=s.length()-1;i<s.length();i++,j--) {
        if(s[i]!=s[j]) {
            cout<<"No\n";
            return 0;
        }
    }
    int c_1=(s.length()-1)/2-1;
    for(int i=0,j=c_1;i<=c_1;i++,j--) {
        if(s[i]!=s[j]) {
            cout<<"No\n";
            return 0;
        }
    }
    int c_2=(s.length()+3)/2-1;
     for(int i=c_2,j=s.length()-1;i<s.length();i++,j--) {
        if(s[i]!=s[j]) {
            cout<<"No\n";
            return 0;
        }
    }
     cout<<"Yes\n";
            return 0;

}


Measured memory_bytes: 256
//#pragma GCC optimize ("-O3","unroll-loops")
// #pragma GCC target("avx")
#include<bits/stdc++.h>
 
using namespace std;
 
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
 
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;

int good[20];
vector<P>A[20];
void solve() {
	int N;cin>>N;
	REP(i,N){
		int c;cin>>c;
		REP(_,c){
			int x,y;cin>>x>>y;
			x--;
			A[i].push_back({x,y});
		}
	}
	int mx=0;
	REP(bit,1<<N){
		int now=__builtin_popcount(bit);
		bool ok=true;
		REP(i,N)good[i]=-1;
		REP(i,N){
			if(bit&(1<<i))good[i]=1;
			else good[i]=0;
		}
		REP(i,N){
			if(!(bit&(1<<i)))continue;
			for(auto p:A[i]){
				int x=p.first,y=p.second;
				if(y==1){
					if(good[x]==0){
						ok=false;break;
					}
				}
				else if(y==0){
					if(good[x]==1){
						ok=false;break;
					}
				}
			}
		}
		if(ok){
			mx=max(mx,now);
		}
	}
	print(mx);
}
 
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}


Measured memory_bytes: 256
/*
[abc140] E - Second Sum
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 1e5;

int N;
int P[MAX_N];

ll solve() {
    vector<pii> ps;
    for (int i = 0; i < N; i++) {
        ps.push_back({P[i], i + 1});
    }
    sort(ALL(ps), greater<pii>());

    ll ans = 0;
    set<int> s;
    s.insert(0);
    s.insert(N + 1);
    for (int i = 0; i < N; i++) {
        auto iter = s.insert(ps[i].second).first;
        auto l = iter, r = iter;
        int a, b, c, d, e;
        b = *(--l);
        a = (l == s.begin()) ? b : *(--l);
        c = ps[i].second;
        d = *(++r);
        e = (++r == s.end()) ? d : *r;

        ans += 1LL * ((b - a) * (d - c) + (c - b) * (e - d)) * ps[i].first;
    }

    return ans;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }

    cout << solve() << endl;

    return 0;
}


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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int n, k;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);  freopen(Task".out", "w", stdout);
  cin >> n >> k;
  vector<ll> pre(n + 2, 0);
  ll L = 0, R = n, l = 0, r = n;
  for (int i = 1; i <= n + 1; ++i){
    pre[i] = pre[i-1] + (R - L + 1 + mod);
    pre[i] %= mod;
    ++l; --r;
    L += l; R += r;
    L %= mod; R %= mod;
  }
  cout << (pre[n + 1] - pre[k-1] + mod) % mod;
}




Measured memory_bytes: 4768
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int INF = 10000000;

int n;
VI e[100000];
bool did[100000];

int grundy(int p){
	did[p]=true;
	int res=0;
	EACH(i,e[p]){
		int q=*i;
		if(did[q])continue; // is parent;
		res = res ^ (grundy(q) + 1);
	}
	return res;
}

int main() {
	cin>>n;
	REP(i,n-1){
		int x,y;
		cin>>x>>y;
		--x;--y;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	cout << (grundy(0) ? "Alice" : "Bob") << endl;
	return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

struct UnionFind {
    vector<int> d;
    // コンストラクタ　親は-頂点数を保管
    UnionFind(int N) : d(N, -1) {}

    int find(int x) {
        if (d[x] < 0) {
            return x;
        }
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        }
        if (d[x] > d[y]) {
            swap(x, y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return -d[find(x)];
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    rep(i, n) p[i]--;

    UnionFind uf(n);
    rep(i, m){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x, y);
    }

    vector<int> q(n);
    rep(i, n){
        q[p[i]] = i;
    }

    int ans = 0;
    rep(i, n){
        if(uf.same(i, q[i])) ans++;
    }
    cout << ans << endl;
}

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

int main() {
	int N, K, out = 1;
	cin >> N >> K;
	for (int i = 0; i < N; ++i){
		if (2 * out < out + K) {
			out *= 2;
		}
		else {
			out += K;
		}
	}
	cout << out << endl;
}


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

int gcd(int a, int b) {
	if (!b)return a;
	return gcd(b, a%b);
}
int lcm(int a, int b) {
	int g = gcd(max(a, b), min(a, b));
	return (a / g)*(b / g)*g;
}
struct node {
	int p, q, left, right, parent;
};
int n;
node T[100];
int w[100];
vector<int>d[100];

void bfs(int u, int i) {
	if (!~u)return;
	d[i].push_back(u);
	bfs(T[u].left, i + 1);
	bfs(T[u].right, i + 1);
}
int main() {
	while (scanf("%d", &n), n) {
		rep(i, n)d[i].clear();
		rep(i, n) {
			int p, q, r, b; scanf("%d%d%d%d", &p, &q, &r, &b);
			int g = gcd(max(p, q), min(p, q));
			T[i] = { p / g,q / g,--r,--b,-1 };
		}
		rep(i, n) {
			if (~T[i].left)T[T[i].left].parent = i;
			if (~T[i].right)T[T[i].right].parent = i;
		}
		int root;
		rep(i, n) {
			if (!~T[i].parent)root = i;
		}
		bfs(root, 0);
		for (int i = n - 1; i >= 0; i--) {
			for (int u : d[i]) {
				if (!~T[u].left && !~T[u].right)w[u] = T[u].p + T[u].q;
				else if (!~T[u].left) {
					int e = lcm(T[u].p, w[T[u].right]);
					w[u] = (e / T[u].p)*(T[u].p + T[u].q);
				}
				else if (!~T[u].right) {
					int d = lcm(T[u].q, w[T[u].left]);
					w[u] = (d / T[u].q)*(T[u].p + T[u].q);
				}
				else {
					int e = lcm(T[u].q, w[T[u].left]);
					for (int i = e;; i += e) {
						if ((i / T[u].q*T[u].p) % w[T[u].right] == 0) {
							w[u] = i / T[u].q*(T[u].p + T[u].q);
							break;
						}
					}
				}
			}
		}
		printf("%d\n", w[root]);
	}
}

Measured memory_bytes: 3268
import sys
s = input()
ans = 0
while len(s)>= 2:
  if s[0] == s[-1]:
    s = s[1:-1]
  elif s[0] == 'x':
    ans += 1
    s = s[1:]
  elif s[-1] == 'x':
    ans += 1
    s = s[:-1]
  else:
    print(-1)
    sys.exit()
print(ans)

Measured memory_bytes: 3316
using System;
using System.Linq;

namespace ABC111B
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            for (var i = N; i <= 999; i++)
            {
                if (i.ToString().Distinct().Count() != 1) continue;
                Console.WriteLine(i);
                break;
            }
        }
    }
}

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

int main(){
  long int A,B;
  cin >> A >> B;
  long int ans=0;
  long int i=1;
  double tmp=0;
  
  while(true){
    tmp = (B*i) % A;
    if(tmp == 0.0){
      ans = B*i;
      break;
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n, i, c = 0, d = 0;
    cin >> n;
    int a[n];
    for(i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    for(i=0; i<n; i++){
        if(i%2 == 0){
            c += a[i];
        }else{
            d += a[i];
        }
    }
    cout << abs(c-d);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

    string T = "ATCG";

    int ans, now;
    ans = now = 0;
    rep(i, S.size()){
        bool isATCG = false;
        rep(j, T.size()) {
            if (S[i] == T[j]) isATCG = true;
        }
        if (!isATCG) 
            now = 0;
        else {
            now++;
            ans = max(ans, now);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3156