akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9)+1;
const ll mod = ll(1e9)+7;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans %= mod;
        ans *= power(i + 1, mod - 2);
        ans %= mod;
    }
    return ans;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> ans(n,0);
    vector<pair<int, int>> sc(m);
    ans[0] = 0;
    rep0(i, m){
        int s,c;
        cin >> s >> c;
        sc[i] = make_pair(s, c);
    }
    sort(all(sc));
    rep0(i, m)if((sc[i].first == sc[i + 1].first &&sc[i].second != sc[i + 1].second) || (sc[i].first == 1 && sc[i].second == 0 && n != 1)){
        pf(-1);
        return 0;
    }
    rep0(i, m){
        ans[sc[i].first - 1] = sc[i].second;
    }
    if(n != 1 && ans[0] == 0)ans[0] = 1;
    rep0(i, n)cout << ans[i];
    cout << endl;
    return 0;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int A, B;
    cin >> A >> B;
    if (A < B) swap(A, B);
    int N = 16 - 2 * B;
    cout << ((2 * (A - B) <= N) ? "Yay!" : ":(") << endl;
    return 0;
}


Measured memory_bytes: 256
n,*t=map(int,open(0).read().split())
*z,=sorted(zip(*[iter(t)]*2))
s=set()
for i in range(n-1):
    if i in s:
        continue
    x,l=z[i]
    j=i+1
    while 1:
        y,r=z[j]
        if x+l>y-r:
            if y+r<x+l:
                s|={i}
                break
            else:
                s|={j}
        else:
            break
        j+=1
        if j==n:break
print(n-len(s))

Measured memory_bytes: 98916
import sys
from io import StringIO
import unittest
import os
from operator import ixor
from functools import reduce

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


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

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

    aaa = x[0]
    for cnt, i in enumerate(x):
        if cnt == 0:
            continue
        aaa = ixor(aaa, i)

    ans = []
    for cnt, i in enumerate(x):
        ans.append(ixor(aaa, i))

    print(*ans)

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

    def test_input_1(self):
        test_input = """4
20 11 9 24"""
        output = """26 5 7 22"""
        self.assertIO(test_input, output)

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


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

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


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

int main(void){
	int n;

	while(cin>>n, n){
		int sum = 0;
		int maxS = 0, minS = 1000;
		for(int i=0;i<n;i++){
			int x;
			cin>>x;
			sum += x;
			maxS = max(maxS,x);
			minS = min(minS,x);
		}
		cout<<(sum - maxS - minS) / (n - 2)<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void){
    long long int n;
    scanf("%lld",&n);
    long long int num[n+1];
    long long int q;
    for(q=0;q<=n-1;q++) scanf("%lld",&num[q]);
    
    long long int maxv,min;
    maxv=num[1]-num[0];
    min=num[0];
    
    long long int i;
    for(i=1;i<=n-1;i++){
        if(maxv<num[i]-min){
            maxv=num[i]-min;
        }
        if(min>num[i]){
            min=num[i];
        }
    }
    printf("%lld\n",maxv);
    return 0;
}

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

int n, t, a;
long h;

int main(){
    scanf("%d", &n);
    scanf("%d%d", &t, &a);
    double close = 1e5;
    double tmp = 0;
    int cidx = 0;
    for(int i = 0; i< n; i++){
        scanf("%ld", &h);
        tmp = t - h * 0.006;
        if(abs(tmp-a) < close){
            cidx = i;
            close = abs(tmp-a);
        }
    }
    printf("%d", cidx+1);
    return 0;
}


Measured memory_bytes: 256
def solve(s):
    for i, c in enumerate(s):
        if i % 2 == 1:
            if not c in ["L", "U", "D"]:
                return "No"
        else:
            if not c in ["R", "U", "D"]:
                return "No"
    return "Yes"

s = input()
print(solve(s))

Measured memory_bytes: 2940
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;

const LL INF=1<<30;
const LL MOD=1000000007;






int main(){
    int n;
    cin>>n;
    VVEC abc(3,VEC(n));
    for(int i=0;i<3;++i){
        for(int j=0;j<n;++j){
            cin>>abc[i][j];
        }
        sort(abc[i].begin(),abc[i].end());
    }
        LL ans=0;
        LL ansa=0,ansc=0;
    for(int i=0;i<n;++i){
        auto it=lower_bound(abc[0].begin(),abc[0].end(),abc[1][i]);
        ansa=it-abc[0].begin();
        it=upper_bound(abc[2].begin(),abc[2].end(),abc[1][i]);
        ansc=n-(it-abc[2].begin());
        ans+=ansa*ansc;
    }

    cout<<ans<<endl;

}



Measured memory_bytes: 3328
n, k = gets.split.map(&:to_i)
arr = Array.new(n){0}
a = gets.split.map(&:to_i).map{|i| i-1}
if n < k then
  puts 0
  exit
end

# initial condition
k.times{|i|
  arr[a[i]] += 1
}
min = n+1

# extract unused number
rest = {}
k.times{|i|
  rest[i] = 1 if arr[i] == 0
}
if rest.size == 0 then
  puts k
  exit
end

r = k
l = 0
loop do
  break if l >= n - k

  # elongate window to include all numbers in the window
  while rest.size > 0 && r < n
    arr[a[r]] += 1
    rest.delete(a[r])
    r += 1
  end

  # no possibility to find minimum
  break if rest.size > 0

  # shrink the window while all numbers are included in the window
  while a[l] >= k || arr[a[l]] > 1
    arr[a[l]] -= 1
    l += 1
  end

  # update the minimum window size
  min = r - l if min > r - l

  # is minimum condition?
  break if min == k

  # slide window to left
  arr[a[l]] -= 1
  rest[a[l]] = 1 # drop out from the window
  l += 1

  #  p arr
end

if min > n
  puts 0
else
  puts min
end

Measured memory_bytes: 17904
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#define REP(i, n) for(int i=0;i<n;++i)
#define INF 100000000
#define ll long long

using namespace std;

typedef pair<int, int> P;

int main(){
  string s1, s2, s3;
  cin >> s1;
  cin >> s2;
  cin >> s3;
  char a = s1[0];
  char b = s2[1];
  char c = s3[2];

  cout << a << b << c << endl;
  

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
int n,k;
struct st{
    int a,b,c,d,e;
    bool operator <(const st &p)const{
        if(a!=p.a)return a<p.a;
        if(b!=p.b)return b<p.b;
        if(c!=p.c)return c<p.c;
        if(d!=p.d)return d<p.d;
        return e<p.e;
    }
};
char s[5005];
set<st>o;
vector<st>com;
int main(void){
    cin>>s>>k;
    k--;
    n=strlen(s);
    for(int i=0;i<n;i++){
        int u[5]={-1,-1,-1,-1,-1};
        for(int j=0;j<5&&i+j<n;j++){
            u[j]=s[i+j]-'a';
            st x=st{u[0],u[1],u[2],u[3],u[4]};
            if(o.find(x)==o.end()){
                com.push_back(x);
                o.insert(x);
            }
        }
    }
    sort(com.begin(),com.end());
    int u[5]={com[k].a,com[k].b,com[k].c,com[k].d,com[k].e};
    for(int i=0;i<5&&u[i]!=-1;i++)printf("%c",char(u[i]+'a'));
    printf("\n");
}

Measured memory_bytes: 1500
#include <iostream>
#include <cstring>
#include <algorithm>
#include <list>
#include <cmath>
#include <string>
#include <iterator>
#include <vector>
 
using namespace std;

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 2 * 1e5 + 5;

int largest(int a, int b){
	return (a<b)?b:a;
}

int main() {
	int n = 0, m = 0;
	cin >> n >> m;
	vector<pair<int,int> > ab(m);
	for(int i = 0; i < m; ++i){
		cin >> ab[i].first >> ab[i].second;
	}
	int k = 1;
	for(int i = 0; i < n; ++i){
		int ans = 0;
		for(int i = 0; i < m; ++i){
			if(ab[i].first == k){
				++ans;
			}
			else if(ab[i].second == k){
				++ans;
			}
		}
		++k;
		cout << ans << endl;
	}


    return 0;
}

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

const int MAX_N = (int)7368791;
int A[MAX_N+5];

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    for(int i=2;i<=MAX_N;i++){
        for(int j=2*i;j<=MAX_N;j+=i) A[j] = i;
    }
    while(true){
        int N, M, cnt = 0; cin >> M >> N;
        if(M==0) return 0;

        int cur = M;
        while(cnt<=N){
            if(M<=A[cur]) {
                cur++;
                continue;
            }
            else{
                if(cnt==N) {
                    printf("%d\n", cur);
                    break;
                }
                cnt++;
                cur++;
            }
        }
    }
}


Measured memory_bytes: 31948
#include<iostream>
#include<string>
#include<algorithm>
#include<bitset>
typedef unsigned long ulong;

using namespace std;

string Oct(ulong n){
	string s;
	bitset<32> b(n);

	while( b.any() ){
		int c = (b[2]?1:0) * 4 + (b[1]?1:0) * 2 + (b[0]?1:0);
		s += (c + '0');
		b >>= 3;
	}
	reverse( s.begin(), s.end() );
	return s;
}
int main(){
	while(true){
		string sNum;
		ulong n;

		cin >> n;
		
		if( n == 0 )
			break;

		sNum = Oct(n);

		for(unsigned int i = 0; i < sNum.length(); ++i){
			switch( sNum[i] ){
				case '4':
					sNum[i] = '5';
					break;
				case '5':
				case '6':
				case '7':
					sNum[i] += 2;
					break;
			}
		}

		cout << sNum << '\n';
	}
	return 0;
}

Measured memory_bytes: 904
from heapq import heappush, heappushpop

N = int(input())

A = list(map(int, input().split()))
lsum = [0] * (N + 1)
rsum = [0] * (N + 1)
lq = []
rq = []
ans = [0] * (N + 1)

for i in range(N):
    a = A[i]
    heappush(lq, a)
    lsum[0] += a

    b = A[3 * N - 1 - i]
    heappush(rq, -1 * b)
    rsum[N] += b

for k in range(1, N + 1):
    na = A[N - 1 + k]
    lsum[k] = lsum[k - 1] + na - heappushpop(lq, na)

    nb = A[2 * N - k]
    rsum[N - k] = rsum[N - k + 1] + nb - (-1) * heappushpop(rq, -1 * nb)

for i in range(N + 1):
    ans[i] = lsum[i] - rsum[i]

print(max(ans))


Measured memory_bytes: 38144
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n;

    string s;
    cin>>s;
    if(s[s.size()-1]== 's')
    {
        cout<<s.append("es");
    }
    else
    {
        cout<<s.append("s");
    }
    
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	vector<vector<int>> a(3, vector<int>(3));
	rep(i, 3) rep(j, 3) cin >> a[i][j];
	int n; cin >> n;
	vector<int> b(n);
	rep(i, n) cin >> b[i];
	vector<vector<int>> res(3, vector<int>(3));
	rep(k, n) rep(i, 3) rep(j, 3) if (a[i][j] == b[k]) res[i][j] = 1;

	rep(i, 3) {
		if (res[i][0] == 1 && res[i][1] == 1 && res[i][2] == 1) {
			puts("Yes");
			return 0;
		}
	}
	rep(j, 3) {
		if (res[0][j] == 1 && res[1][j] == 1 && res[2][j] == 1) {
			puts("Yes");
			return 0;
		}
	}
	if (res[0][0] == 1 && res[1][1] == 1 && res[2][2] == 1) {
		puts("Yes");
		return 0;
	}
	if (res[0][2] == 1 && res[1][1] == 1 && res[2][0] == 1) {
		puts("Yes");
		return 0;
	}

	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b,pos;
char ans[111][111];
int main()
{
	cin>>a>>b;
	a--;
	for (int i=1;i<=100;i+=2)
	{
		for (int j=1;j<=100;j++)
		{
			ans[i+1][j]='#';
		}
		for (int j=1;j<=100;j+=2)
		{
			if (!a)
			{
				for (int k=j;k<=100;k++) ans[i][k]='#';
				break;
			}
			ans[i][j]='.';ans[i][j+1]='#';
			a--;
		}
		if (!a)
		{
			pos=i+2;
			break;
		}
	}
	b--;
	for (int i=1;i<=100;i++) ans[pos][i]='.';
	for (int i=pos+1;i<=100;i+=2)
	{
		for (int j=1;j<=100;j++)
		{
			ans[i+1][j]='.';
		}
		for (int j=1;j<=100;j+=2)
		{
			if (!b)
			{
				for (int k=j;k<=100;k++) ans[i][k]='.';
				break;
			}
			ans[i][j]='#';ans[i][j+1]='.';
			b--;
		}
		if (!b)
		{
			pos=i+1;
			break;
		}
	}
	cout<<pos<<" "<<100<<endl;
	for (int i=1;i<=pos;i++)
	{
		for (int j=1;j<=100;j++)
		cout<<ans[i][j];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Input();
		var a = p[0].ToLong();
		var b = p[1].ToLong();
		
		var a1 = Primes(a);
		var b1 = Primes(b);
		var k = a1.Count > b1.Count ? b1 : a1;
		var s = a1.Count > b1.Count ? a1 : b1;
		long wa = 0;
		foreach(var key in k.Keys)
		{
			if(s.ContainsKey(key))
				wa++;
		}
		Console.WriteLine(wa+1);
	}
	
	static Dictionary<long, long> Primes(long a)
	{
		var d = new Dictionary<long,long>();
		for(long i = 2; i * i <= a; i++)
		{
			if(a % i != 0) continue;
			int num = 0;
			while(a % i == 0)
			{
				num++;
				a /= (int)i;
			}
			d.Add(i, num);
		}
		if(a != 1)
		{
			d.Add(a, 0);
		}
		return d;
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define gcda(x,y) gcd(abs(x),abs(y))

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main(){
    int x, y;
    cin >> x >> y;
    int t2,u2;
    //t+u=x
    //2t+4u=y

    t2 = 4*x - y;
    u2 = y - 2*x;
    if(t2>=0&&u2>=0&&t2%2==0&&u2%2==0) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
using namespace std; 
typedef long long ll; 
int n; 
ll arr[55]; 
inline bool chk(ll num)
{
	ll res = 0; 
	for (int i = 0; i < n; i++)
		res += (arr[i] + num) / (n + 1); 
	return res >= num; 
}
int main()
{
	// freopen("ARC079-E.in", "r", stdin); 
	scanf("%d", &n); 
	for (int i = 0; i < n; i++)
		scanf("%lld", arr + i); 
	ll ans = 1e18; 
	for (int i = 0; i <= n; i++)
	{
		ll l = 0, r = 1e16, res; 
		while (l <= r)
		{
			ll m = l + r >> 1; 
			if (chk(m * (n + 1) + i))
				l = m + 1; 
			else
			{
				res = m; 
				r = m - 1; 
			}
		}
		// cout << i << " " << res << endl; 
		ans = min(ans, res * (n + 1) + i); 
	}
	printf("%lld\n", ans - 1);
	return 0; 
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Calc();
        }
    }

    public class Solver
    {
        public struct AB
        {
            public int A;
            public int B;
        }
        public void Calc()
        {
            var p = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
            var A = p[0];
            var B = p[1];
            var C = p[2];
            var K = p[3];

            var remain = K;
            long sum = 0;
            if (A >= remain)
            {
                Console.WriteLine(remain);
                return;
            }
            else
            {
                remain = remain - A;
                sum = A;

                if (B >= remain)
                {
                    Console.WriteLine(sum);
                    return;
                }
                else
                {
                    remain = remain - B;
                    Console.WriteLine(sum - remain);
                    return;
                }

            }


        }


    }

}


Measured memory_bytes: 28240
import java.util.Scanner;
public class Main
{
  public static void main(String[] args)
  {
    Scanner scanner = new Scanner(System.in);
    while(true)
    {
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        if((x == 0) &&(y == 0)){
          break;
        }
        if(x<y)
        {
          System.out.println(x + " " + y);
        }
        if(x>y)
        {
          System.out.println(y + " " + x);
        }
        if(x == y)
        {
          System.out.println(x + " " + y);
        }
        }
    }
  }

Measured memory_bytes: 35724
from sys import stdin
from itertools import groupby

n,k = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()

kohuku = 0

for i in range(len(s)-1):
    if s[i] == "R" and s[i+1] == "R":
        kohuku += 1
    elif s[i] == "L" and s[i+1] == "L":
        kohuku += 1

if len(s) == 1:
    print(0)
    exit()

num_2 = s.count("RL")

num_1 = 0
if s[0] == "R":
    num_1 += 1
elif s[-1] == "R":
    num_1 += 1
if k <= num_2:
    print(min(n-1,2*k+kohuku))
    exit()

if num_1 == 0:
    print(min(n-1,2*k+kohuku))

elif num_1 == 1:
    print(min(n-1,2*num_2+1+kohuku))

else:
    if k == num_2 +1:
        print(min(n-1,2*num_2+1+kohuku))
    else:
        print(min(n-1,2*num_2+2+kohuku))

Measured memory_bytes: 3316
N = int(input())
A = [int(i) for i in input().split()]

cnt = 0
flg = True

while flg == True:
    for i in range(N):
        if A[i]%2 == 1:
            flg = False
            break
    if flg == True:
        cnt += 1
        A = [a/2 for a in A]

print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
const int N = 1e6+5;	
ll get(vector<ll>&v, ll idx)
{
	ll ans = 0;
	while(idx >= 0)
	{
		ans = max(ans, v[idx]);
		idx = (idx & (idx+1)) - 1;
	}
	return ans;
}
void upd(vector<ll>&v, ll idx, ll val)
{
	while(idx < v.size())
	{
		v[idx] = max(v[idx], val);
		idx |= (idx + 1);
	}
}
 
int main()
{
	sync;
	ll n;
	cin >> n;
	vector<ll> bit(n + 1);
	ll h[n], a[n];
	input(h, n);
	input(a, n);
	for(ll i = 0; i < n; i++)
	{
		ll maxm = get(bit, h[i]) + a[i];
		upd(bit, h[i], maxm);
	}
	cout << get(bit, n);
}


Measured memory_bytes: 7952
import numpy as np

a = [list(map(int, input().split())) for _ in range(3)]
a = np.array(a)
n = int(input())

for _ in range(n):
    b = int(input())
    
    for j in range(3):
        for i in range(3):
            if a[j][i] == b:
                a[j][i] = 0

at = a.transpose()
flag = False
for i in range(3):
    if sum(a[:][i]) == 0 or sum(at[:][i]) == 0:
        flag = True
        break
diag = a[0][0] + a[1][1] + a[2][2]
diag2 = a[2][0] + a[1][1] + a[0][2]
if diag == 0 or diag2 == 0:
    flag = True

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

Measured memory_bytes: 18000
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	if a%3 == 0 || b%3 == 0 || (a+b)%3 == 0 {
		fmt.Println("Possible")
	} else {
		fmt.Println("Impossible")
	}
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 7; i++)
            {
                var ab = ReadInts();
                WriteLine(Abs(ab[0] - ab[1]));
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



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

using namespace std;

int main(void) {
  int N, M; cin >> N >> M;
  int ans[N]; memset(ans, 0, sizeof(ans));
  bool z[N]; memset(z, false, sizeof(z));

  for (int i = 0; i < M; i++) {
    int s, c; cin >> s >> c;
    if (z[N-s] && ans[N-s] != c) {
      cout << -1 << endl;
      return 0;
    }
    ans[N-s] = c;
    z[N-s] = true;
  }
  
  if (N == 1) {
    cout << ans[0] << endl;
    return 0;
  }

  if (N == 2) {
    if (ans[1] != 0) {
      cout << ans[1];
    } else {
      if (z[1]) {
        cout << -1 << endl;
        return 0;
      }
      cout << 1;
    }
    cout << ans[0] << endl;
    return 0;
  }

  if (ans[2] != 0) {
    cout << ans[2] << ans[1] << ans[0] << endl;
    return 0;
  } else {
    if (z[2]) {
      cout << -1 << endl;
      return 0;
    } else {
      cout << 1 << ans[1] << ans[0] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
import functools
import math

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


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


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper

d=inp()
print('Christmas' +(' Eve' *( 25-d)))


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    HashMap<llong, char> x;

    signed call_of_Cthulhu( signed datum ) {

        llong n, m;
        read n >> m;
        String a, b;
        read a >> b;
        if ( a[0] != b[0] ) {
            echo -1 fin;
            return 0;
        }
        llong l = lcm(n, m);
        for ( int i = 1; i < n; i++ ) {
            x[i*l/n] = a[i];
        }
        for ( int i = 1; i < m; i++ ) {
            char c = x[i*l/m];
            if ( c != 0 && c != b[i] ) {
                echo -1 fin;
                return 0;
            }
            x[i*l/m] = b[i];
        }
        echo l fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


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

int main() {
  int64_t n,a,b,c,d,e,check;
  cin >> n >> a >> b >> c >> d >> e;
  check = min({a,b,c,d,e});
  
  if (check == a) {
    cout << (n+a-1) / a + 4;
  }
  else if (check == b) {
    cout << (n+b-1) / b + 4;
  }
  else if (check == c) {
    cout << (n+c-1) / c + 4;
  }
  else if (check == d) {
    cout << (n+d-1) / d + 4;
  }
  else if (check == e) {
    cout << (n+e-1) / e + 4;
  }
}

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

int main()
{
    int n, m, **A, *b, *c;

    cin >> n >> m;

    A = new int*[n];
    b = new int[m];
    c = new int[n];
    for (int i = 0; i < n; i++) {
        A[i] = new int[m];
        c[i] = 0;
        for (int j = 0; j < m; j++)
            cin >> A[i][j]; 
    }
    for (int j = 0; j < m; j++) 
        cin >> b[j];

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            c[i] += A[i][j] * b[j];

    for (int i = 0; i < n; i++)
        cout << c[i] << endl;

    for (int i = 0; i < n; i++)
        delete[] A[i];
    delete[] A;
    delete[] b;
    delete[] c;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
ll cnt = 0;

int main(){
   int n,m; cin >> n >> m;
   vector<int> l(m),r(m);
   rep(i,m){
       cin >> l[i] >> r[i];
   }

   sort(l.begin(),l.end());
   sort(r.begin(),r.end());

   int lmax,rmin;
   lmax = l[m-1];
   rmin = r[0];
   if(lmax>rmin){
       cout << 0 << endl;
       return 0;
   }else {
       cout << rmin - lmax+1 << endl;

   }
   return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
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;}

int main() {
    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];

    ll dp[110][100100] = {0};
    rep(i, N) {
        rep(j, W + 1) {
            if (j - w[i] >= 0) chmax(dp[i+1][j], dp[i][j - w[i]] + v[i]);
            chmax(dp[i+1][j], dp[i][j]);
        }
    }
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 86272
import bisect
n, m, k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
bc = [0]*(m+1)
for i in range(m):
    bc[i+1] = bc[i] + b[i]
bc = bc[1:]

ans = bisect.bisect_right(bc, k) # 0冊
totala = 0
na = 0
for i in range(n):
    totala += a[i]
    na += 1
    if totala == k:
        ans = max(ans, na)
        break
    elif totala > k:
        break
    ba = bisect.bisect_right(bc, k-totala)
    ans = max(ans, na+ba)
print(ans)

Measured memory_bytes: 40768
//                                                   ¯\_(ツ)_/¯
  //#pragma GCC optimize("Ofast")
 //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
#define pi pair<int,int>
const int N=100005,MOD=1e9+7;

using namespace std;

int n,k;
ll dp[105][N];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	scanf("%d %d",&n,&k);

	for(int i=0,x;i<n;i++){

		scanf("%d",&x);

		if(i==0){
			for(int j=0;j<=x;j++)dp[i][j]=1;
		}
		else{
			for(int j=0;j<=k;j++){
				if(j<=x)
					dp[i][j]=(dp[i-1][j])%MOD;
				else 
					dp[i][j]=(dp[i-1][j]-dp[i-1][j-x-1]+MOD)%MOD;
			}
		}

		for(int j=0;j<=k;j++){
			if(j)(dp[i][j]+=dp[i][j-1])%=MOD;
		}
	}

	printf("%lld\n",k?(dp[n-1][k]-dp[n-1][k-1]+MOD)%MOD:dp[n-1][k]);

}

Measured memory_bytes: 80128
S = str(input())
T = str(input())
alp = "abcdefghijklmnopqrstuvwxyz"
for i in range(0,min(len(S),len(alp)*2)):
  if S[i] != T[i]:
    S = S.translate(str.maketrans({S[i]:T[i], T[i]:S[i]}))
  else:
    pass
  if S == T:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 4400
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

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

	h.pb(0);

	ll ans = 0;
	while (*max_element(rng(h))) {
		bool start = false;
		rep (i, n + 1) {
			if (start && h[i] == 0) {
				ans++;
				break;
			}
			if (!start && h[i]) {
				start = true;
			}
			if (start) {
				h[i]--;
			}
		}
	}

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

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

int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long> A(X), B(Y), C(Z);
    for(int i = 0; i < X; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<long long>());

    for(int i = 0; i < Y; i++) {
        cin >> B[i];
    }
    sort(B.begin(), B.end(), greater<long long>());
    
    for(int i = 0; i < Z; i++) {
        cin >> C[i];
    }
    sort(C.begin(), C.end(), greater<long long>());
    

    int N_E = X * Y;
    vector<long long> E(N_E);
    int cnt = 0;
    for(int i = 0; i < X; i++) {
        for(int j = 0; j < Y; j++) {
            E[cnt] = A[i] + B[j];
            //cout << E[cnt] << endl;
            cnt++;
        }
    }
    
    sort(E.begin(), E.end(), greater<long long>());

    int N_E_lim = min(K, N_E);
    vector<long long> E_lim(N_E_lim);
    
    for (int i = 0; i < N_E_lim; i++) {
        E_lim[i] = E[i];
    }

    vector<long long> F(Z*N_E_lim);
    cnt = 0;
    for(int i = 0; i < N_E_lim; i++) {
        for(int j = 0; j < Z; j++) {
            F[cnt] = E_lim[i] + C[j];
            cnt++;
        }
    }
    
    sort(F.begin(), F.end(), greater<long long>());

    for(int i = 0; i < K; i++) {
        cout << F[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 31616
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = 1234567;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int a,b;
	cin>>a>>b;
	cout<<(a*b%2==0?"No":"Yes")<<endl;

	return 0;
}


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

typedef long long ll;
typedef std::pair< ll, ll > P;

int N, M;
std::vector< P > student, checkpoint;

ll manhattan(P a, P b) {
    return std::abs( a.first - b.first ) + std::abs( a.second - b.second );
}

int main() {
    std::cin >> N >> M;
    for (int i=0; i<N; ++i) {
        P st;
        std::cin >> st.first >> st.second;
        student.push_back( st );
    }
    for (int i=0; i<M; ++i) {
        P p;
        std::cin >> p.first >> p.second;
        checkpoint.push_back( p );
    }

    for (int i=0; i<N; ++i) {
        ll calc = LLONG_MAX;
        ll number = -1;
        for (int j=0; j<M; ++j) {
            if ( calc > manhattan( student[i], checkpoint[j] ) ) {
                calc = manhattan( student[i], checkpoint[j] );
                number = j+1;
            }
        }
        std::cout << number << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let k = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<i64>();
    }
    let mut ans = 0;
    for i in 0..(std::cmp::min(n, k) + 1) {
        for l in 0..(i + 1) {
            let mut items = vec![];
            let r = i - l;
            for j in 0..l {
                items.push(seq[j]);
            }
            for j in 0..r {
                items.push(seq[n - j - 1]);
            }
            assert!(items.len() <= seq.len());
            items.sort();
            items.reverse();
            let rest = k - i;
            for _j in 0..std::cmp::min(i, rest) {
                if *items.last().unwrap() < 0 {
                    items.pop();
                }
            }
            let mut sum = 0;
            for &v in items.iter() {
                sum += v;
            }
            ans = std::cmp::max(ans, sum);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

ll sum(ll n){
	ll ans=0;
	while(n!=0){
		ans+=n%10;
		n/=10;
	}
	return ans;
}
int main(){
	ll n;
	cin>>n;
	ll ans=sum(n);
	if(ans==1)cout<<10<<endl;
	else cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll ceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   ll k;
   cin >> k;
   cout << ceil(k,2)*(k/2) << endl;
}


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

int n;
bool used[200200];
vector<int> v[200200];
vector<int> color[2];

void dfs(int now, bool col){
	used[now] = 1;
	color[col].push_back(now);
	rep(i, v[now].size()){
		if(!used[v[now][i]]){
			dfs(v[now][i], col ^ 1);
		}
	}
}

int ans[200200];

int main(){
	scanf("%d", &n);
	rep(i, n-1){
		int a, b;
		scanf("%d%d", &a, &b);
		a--, b--;
		v[a].push_back(b);
		v[b].push_back(a);
	} 
	memset(used, 0, sizeof(used));
	dfs(0, 0);
	if(color[0].size() > color[1].size()) swap(color[0], color[1]);
	int num0 = n / 3, num1 = (n+2) / 3, num2 = (n+1) / 3;
	bool has1 = 0, has2 = 0;
	rep(i, 2){
		if(color[i].size() >= num1){
			for(int cnt = 0; cnt < num1; cnt++){
				ans[color[i][color[i].size() - 1]] = cnt*3 + 1;
				color[i].pop_back();
			} 
			has1 = 1;
			break;
		}
	}
	rep(i, 2){
		if(color[i].size() >= num2){
			for(int cnt = 0; cnt < num2; cnt++){
				ans[color[i][color[i].size() - 1]] = cnt*3 + 2;
				color[i].pop_back();
			} 
			has2 = 1;
			break;
		}
	}
	if(!(has1 && has2)){
		cout << "-1" << endl;
		return 0;
	}
	int cnt = 0;
	rep(i, n){
		if(ans[i] == 0){
			ans[i] = (cnt+1) * 3;
			cnt++;
		}
	}
	rep(i, n) cout << ans[i] << " ";
	cout << endl;
	return 0;
} 

Measured memory_bytes: 19444
import re

input_str=input()
N=int(input_str.split()[0])
K=int(input_str.split()[1])
str_teams = str(input())
sub_str_teams = str_teams

def next_check_val(check_val):
  if check_val == '1':
    return '0'
  else:
    return '1'

cur_check_val = str_teams[0]
teams_group = []
teams_state = ''

## 直立/逆立ちのグループに分ける処理
for i in range(N):
  person = str_teams[i]
  if str_teams[i] == cur_check_val:
    teams_state = teams_state + str_teams[i]
  else:
    teams_group.append(teams_state)
    teams_state = str_teams[i]
    cur_check_val = next_check_val(cur_check_val)

teams_group.append(teams_state)
#print(teams_group)

## 0グループの個数がK以下の場合
## 人数を回答にしてexitする
count_0 = 0
for i in range(len(teams_group)):
  if teams_group[i].startswith('0'):
    count_0 += 1
if count_0 <= K:
  print(N)
  exit()

sum_handstand = [] ## 累積和を格納するリスト
handstands = 0     ## 各累積和を一時的に格納する変数


## 最初の累積和を計算する処理
## 先頭が0か1かによって処理を分割している
if ('0' in teams_group[0]):
  for k in range(K*2):
    handstands += len(teams_group[k])
else:
  for k in range(K*2+1):
    handstands += len(teams_group[k])

sum_handstand.append(handstands)

## 途中の累積和を計算する処理
for i in range(1,len(teams_group)-(K*2)):
  ## 先頭が0か1かによって処理を分割している
  if ('0' in teams_group[i]):
    handstands = sum_handstand[i-1]
  else:
    if i == 1:
      handstands = sum_handstand[i-1] - len(teams_group[i-1]) + (len(teams_group[i+2*K-1])+len(teams_group[i+2*K]))
    else:
      handstands = sum_handstand[i-1] - (len(teams_group[i-1])+len(teams_group[i-2])) + (len(teams_group[i+2*K-1])+len(teams_group[i+2*K]))
  sum_handstand.append(handstands)

handstands = 0
## 最後の累積和を計算する処理
if ('0' in teams_group[-1]):
  for k in range(0,K*2):
    handstands += len(teams_group[len(teams_group)-2*K+k])
  sum_handstand.append(handstands)


#print(sum_handstand)
print(max(sum_handstand))

Measured memory_bytes: 6052
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  ll l = 2;
  ll r = 2;
  for (int i = n - 1; i >= 0; --i) {
    ll x = a[i];

    if (l % x != 0) {
      l += x - l % x;
    }

    if (r % x != 0) {
      r -= r % x;
    }

    if (l > r) {
      cout << -1 << endl;
      return 0;
    }

    r += x - 1;
  }

  cout << l << " " << r << endl;

  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
ld A,B,H,M;
inline void solve(void){
  in(A,B,H,M);
  out(sqrt(A*A+B*B-2*A*B*cos(2.0*abs((60*H+M)/720.0-M/60.0)*M_PI)));
}
int main(void){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 4176
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

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

    std::string s;
    std::cin >> s;

    std::vector<long long> pos;

    pos.push_back(0);
    for (int i = 0; i < n - 1; i++) {
        if (s[i] != s[i + 1]) {
            pos.push_back(i + 1);
        }
    }
    pos.push_back(n);

    long long ans = 0;
    for (int i = 0; i < pos.size() - 1; i++) {
        int end_pos_idx;
        if (s[pos[i]] == '1') {
            end_pos_idx = i + 2 * k + 1;
        } else {
            end_pos_idx = i + 2 * k;
        }

        if (end_pos_idx >= pos.size()) {
            end_pos_idx = pos.size() - 1;
        }

        ans = std::max(ans, pos[end_pos_idx] - pos[i]);
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 1528