akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int a = readln.split.to!(int[]).reduce!"a + b";
    writeln(a < 10 ? a.to!string : "error");
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    cout << (C <= A + B ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
	int m, d, h[11], i;
	h[0] = h[2] = h[4] = h[6] = h[7] = h[9] = 31;
	h[3] = h[5] = h[8] = h[10] = 30;
	h[1] = 29;
	while(scanf("%d %d", &m, &d) != 0){
		if(m == 0 || d == 0) break;
		for(i = 0; i < m - 1; i++) d += h[i];
		if(d % 7 == 1) printf("Thursday\n");
		else if(d % 7 == 2) printf("Friday\n");
		else if(d % 7 == 3) printf("Saturday\n");
		else if(d % 7 == 4) printf("Sunday\n");
		else if(d % 7 == 5) printf("Monday\n");
		else if(d % 7 == 6) printf("Tuesday\n");
		else if(d % 7 == 0) printf("Wednesday\n");
	}
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;

  if ( L > R ) {
    cout << "Left" << endl;
  }
  else if ( L < R ) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

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

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

    // vector<int> A(N);
    // for(int n = 0; n < N; ++n) cin >> A[n];

    multiset<int> maxes;
    for(int n = 0; n < N; ++n) {
        int a;
        cin >> a;

        auto it = maxes.lower_bound(a);

        if (it == maxes.begin()) {
            maxes.insert(a);
        }
        else {
            --it;
            maxes.erase(it);
            maxes.insert(a);
        }
        // for(auto a: maxes) cout << a << ","; cout << endl;
    }
    cout << maxes.size() << endl;
}


Measured memory_bytes: 4992
N = int(input())
A = [int(input()) for _ in range(N)]
if A[0]:
    print(-1)
    exit()
ans = 0
dp = A[-1]
for a, b in zip(A[-2::-1], A[-1::-1]):
    if a == b - 1:
        continue
    elif a >= b:
        ans += dp
        dp = a
    else:
        print(-1)
        exit()
print(ans + dp)


Measured memory_bytes: 14156
import sys
input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15


def main():
    n = getN()
    # n, m = getlist()
    # nums = getlist()
    d = defaultdict(int)
    for i in range(n):
        s = input().strip()
        d[s] += 1
    # print(d)
    mx = max(d.values())
    ans = [k for (k, v) in d.items() if v == mx]

    ans.sort()
    for an in ans:
        print(str(an)[2:-1])

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Measured memory_bytes: 80600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

const double EPS = 1E-8;
typedef vector<double> vd;
typedef vector<vd> mat;

// 拡大係数行列で一次方程式系を解く
vector<double> GaussJordan(const mat& A, const vd b) {
  int n = A.size();
  mat B(n, vd(n+1));
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) B[i][j] = A[i][j];
  }
  for(int i=0; i<n; i++) {
    B[i][n] = b[i];
  }

  for(int i=0; i<n; i++) {
    int pivot = i;
    for(int j=i; j<n; j++) {
      if(abs(B[j][i]) > abs(B[pivot][i])) pivot = j;
    }
    swap(B[i], B[pivot]);

    if(abs(B[i][i]) < EPS) return vd();
    
    for(int j=i+1; j<=n; j++) B[i][j] /=B[i][i];
    for(int j=0; j<n; j++) {
      if(i != j) {
	for(int k=i+1; k<=n; k++) B[j][k] -= B[j][i] * B[i][k];
      }
    }
  }
  vd x(n);
  for(int i=0; i<n; i++) x[i] = B[i][n];
  return x;
}

int main() {
  int tcase;
  cin >> tcase;
  while(tcase--) {
    double x[3], y[3];
    cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];
    
    mat A(3, vd(3, 0));
    for(int i=0; i<3; i++) {
      for(int j=0; j<3; j++) {
	if(j == 2) A[i][j] = 1;
	else A[i][j] = (j % 2 ? y[i] : x[i]);
      }
    }
    
    vd b(3);
    for(int i=0; i<3; i++) b[i] = -(x[i]*x[i] + y[i]*y[i]);

    vd v = GaussJordan(A, b);
    
    double cX = -v[0]/2, cY = -v[1]/2;
    double r = sqrt(pow(x[0]-cX, 2) + pow(y[0]-cY, 2));
    printf("%.3f %.3f %.3f\n", cX, cY, r);
  }
  
  return 0;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define For(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Foz(i, a) For(i, 0, a)
#define Doz(i, a) Dor(i, 0, a)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n;
	cin >> n;
	vi a(n);
	Foz(i, n) cin >> a[i];
	sort(all(a));
	bool good = true;
	For(i, 1, n) if (a[i] == a[i - 1]) { good = false; break; }
	cout << (good ? "YES" : "NO") << '\n';
}



Measured memory_bytes: 1024
#include<set>
#include<string>
#include<iostream>

#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

set<int> operator+(const set<int> &S,const set<int> &T){
	set<int> U;
	set<int>::iterator it1,it2;
	for(it1=S.begin();it1!=S.end();++it1) for(it2=T.begin();it2!=T.end();++it2)
		U.insert(*it1 + *it2);
	return U;
}

set<int> operator-(const set<int> &S,const set<int> &T){
	set<int> U;
	set<int>::iterator it1,it2;
	for(it1=S.begin();it1!=S.end();++it1) for(it2=T.begin();it2!=T.end();++it2)
		U.insert(*it1 - *it2);
	return U;
}

set<int> operator*(const set<int> &S,const set<int> &T){
	set<int> U;
	set<int>::iterator it1,it2;
	for(it1=S.begin();it1!=S.end();++it1) for(it2=T.begin();it2!=T.end();++it2)
		U.insert(*it1 * *it2);
	return U;
}

set<int> operator/(const set<int> &S,const set<int> &T){
	set<int> U;
	set<int>::iterator it1,it2;
	for(it1=S.begin();it1!=S.end();++it1) for(it2=T.begin();it2!=T.end();++it2)
		if(*it2!=0) U.insert(*it1 / *it2);
	return U;
}

string expr;

set<int> solve(int il,int ir){
	set<int> ans;

	// ツつキツづ猟づ青板篠堋づ個湘ェツ債、ツつサツづ個青板篠堋つセツつッツつゥツづァツづ按づゥツ集ツ債づーツ陛板つキ
	bool alldgt=true;
	for(int i=il;i<ir;i++) if(!isdigit(expr[i])) { alldgt=false; break; }
	if(alldgt){
		int num=0;
		for(int i=il;i<ir;i++) num=10*num+(expr[i]-'0');
		ans.insert(num);
		return ans;
	}

	// (expression) ツづつ「ツつ、ツ形ツづ個湘ェツ債、( ) ツづーツづ債つクツつキ
	if(expr[il]=='('){
		bool allprn=true;
		for(int i=il,depth=0;i<ir;i++){
			if     (expr[i]=='(') depth++;
			else if(expr[i]==')') depth--;
			if(i<ir-1 && depth==0){ allprn=false; break; }
		}
		if(allprn) return solve(il+1,ir-1);
	}
	
	int depth=0;
	for(int i=il;i<ir;i++){
		if     (expr[i]=='(') depth++;
		else if(expr[i]==')') depth--;
		if(depth!=0) continue;

		set<int> tmp;
		switch(expr[i]){
			case '+': tmp=solve(il,i)+solve(i+1,ir); break;
			case '-': tmp=solve(il,i)-solve(i+1,ir); break;
			case '*': tmp=solve(il,i)*solve(i+1,ir); break;
			case '/': tmp=solve(il,i)/solve(i+1,ir); break;
		}
		if(tmp.size()>0) ans.insert(all(tmp));
	}
	return ans;
}

int main(){
	for(;cin>>expr,expr!="#";) cout<<solve(0,expr.length()).size()<<endl;
	return 0;
}

Measured memory_bytes: 960
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int endAOnly = 0;
int startBOnly = 0;
int both = 0;

void solve() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ret = 0;
  for(int i = 0; i*r <= n; i++) {
    for(int j = 0; i*r + j*g <= n; j++) {
      int k = n-i*r-j*g;
      if(k >= 0 && k%b==0) ret++;
    }
  }
  cout << ret << endl;
}

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


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(void){
	string a,b;
	cin>>a>>b;
	if(a==b) puts("H");
	else puts("D");
	return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
         
        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = stdIn.nextInt();
        }
         
        Arrays.sort(a);
         
        long s = 0;
         
        for(int i = 0; i < n; i++) {
            s += a[i];
        }
         
        System.out.println(a[0] + " " + a [n-1] + " " +  s );
    }
}


Measured memory_bytes: 41912
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll sums[4000];
bool used[4000];
int main()
{
	int n;
	while(cin>>n,n) 
	{
		vector<int> order;
		bool f=false;
		int num;
		int a,b;
		fill(sums,sums+4000,0);
		fill(used,used+4000,0);
		for(int i = 0; i < n; ++i)
		{
			cin>>num>>a>>b;
			sums[num-1]+=(ll)a*b;
			order.push_back(num-1);
		}
		for(int i = 0; i < order.size(); ++i)
		{
			if(!used[order[i]]&&sums[order[i]]>=1000000)
			{
				cout<<order[i]+1<<endl;
				f=true;
				used[order[i]]=true;
			}
		}
		if(!f) cout<<"NA"<<endl;
	}
  return 0;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, x, t;
	cin >> n >> x >> t;
	cout << (n + x - 1) / x * t << endl;
	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int t[] = new int[12];
        for (int i = 0; i < 12; i++) {
            t[i] = scan.nextInt();
        }
        for (int i = 0; i < 11; i++) {
            for (int j = 0; j < 11 - i; j++) {
                if (t[j] < t[j + 1]) {
                    int temp = t[j];
                    t[j] = t[j + 1];
                    t[j + 1] = temp;
                }
            }
        }
        if (t[0] == t[1] && t[1] == t[2] && t[2] == t[3] && t[4] == t[5] && t[5] == t[6] && t[6] == t[7]
                && t[8] == t[9] && t[9] == t[10] && t[10] == t[11]) {
            System.out.println("yes");
        } else {
            System.out.println("no");
        }
    }
}



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

#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("READ.txt", "r", stdin)
#define Write          freopen("OUTPUT.txt", "w", stdout)
#define INF            -9999999
#define Co(x)          cout<<x<<endl;
#define Cos(x)         cout<<x<<" ";

/*typedef vector<long long>vii;
typedef pair<long long,long long>Pair;
typedef map<long long,long long>Map;

int dr[]={1,0,-1, 0 };
int dc[]={0,1, 0,-1 };

//int dr[]={1,1,0,-1,-1,-1, 0, 1};
//int dc[]={0,1,1, 1, 0,-1,-1,-1};

while(1) {
    if(!getline(cin,s)||s.empty()) break;
}

const int RT = 10000000;
vector<int>prime;
bitset<10000003> status;

void sieve()
{
    int rt = sqrt(RT);
    //for(int i = 4; i <= rt; i+=2) status[i]=true;
    for(int i = 3; i <= rt; i+=2)
        if(!status[i])
            for(int j = i*i; j < RT; j+=(i<<1))
                status[j] = true;
    prime.push_back(2);
    for(int i = 3; i <= RT; i+=2)
        if(!status[i])
            prime.push_back(i);
}

void Binary_Con(int n)
{
    int binaryNum[70];
    int i = 0;
    while (n > 0) {
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }
    // printing binary array in reverse order
    for (int j = i - 1; j >= 0; j--)
        cout << binaryNum[j];
}*/


void solve()
{
   long long a,b,c,d;
   cin>>a>>b>>c>>d;
   long long x=a*c;
   long long y=a*d;
   long long z=b*c;
   long long q=b*d;
   cout<<max(x,max(y,max(z,q)))<<endl;

}

void kick_ass()
{
    fast
    #ifndef ONLINE_JUDGE
    //Read;
    //Write;
    #endif
    //int t; cin>>t; while(t--) solve();
    solve();
}

int main()
{
   kick_ass();
}


Measured memory_bytes: 3648
import numpy as np
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
B = np.zeros([H,W], np.int64)
ind = 0
for i in range(H):
    for j in range(W):
        if A[ind] == 0:
            ind += 1
        B[i,j] = ind+1
        A[ind] -= 1

for i in range(H):
    if i % 2 == 0:
        print(*B[i])
    else:
        print(*B[i][::-1])
        

Measured memory_bytes: 21544
#include <iostream>

#define MAX 100001

using namespace std;

int main()
{
	int N;
	long long K;
	int ans = 0;

	cin >> N >> K;

	long long table[MAX];
	for (int i = 0; i < MAX; i++)
		table[i] = 0;

	int a, b;
	for (int i = 0; i < N; i++)
	{
		cin >> a >> b;

		table[a] += b;
	}

	for (int i = 0; i < MAX; i++)
	{
		K -= table[i];
		if (K <= 0)
		{
			ans = i;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
  ll n, d;
  cin >> n >> d;
  ll ans = 0;
  for(int i=0;i<n;i++){
    ll a, b;
    cin >> a >> b;
    if (a * a + b * b <= d * d) ans ++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3476
#include<bits/stdc++.h>
using namespace std;
int main()
{ 
   int m,d,ans=0;
   scanf("%d%d",&m,&d);
   for(int i=1;i<=m;i++)
   {
   	   for(int j=22;j<=d;j++)
	   {
	   	   int jj=j%10;
	   	   int jjj=j/10;
	   	   if(jj<2||jjj<2)
		{
			continue;
	    }
	   	   if(jj*jjj==i)
		   {
			  ans++;
			  //cout<<i<"   ";
			  //cout<<j<<endl;
		   }
	   }
	   
   }
   printf("%d\n",ans);

} 

Measured memory_bytes: 256
import java.lang.Math.floor

fun main() {
    val x = readLong()
    var i = 100.0
    var y = 0

    while (i < x) {
        i = floor(i * 1.01)
        y++
    }
    println(y)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

Measured memory_bytes: 34480
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A = list(map(int, rl().split()))
    Q = int(rl())
    B, C = [0] * Q, [0] * Q
    for i in range(Q):
        B[i], C[i] = map(int, rl().split())
    
    counter = Counter(A)
    sum_a = sum(A)
    ans = []
    for b, c in zip(B, C):
        sum_a -= counter[b] * b
        sum_a += counter[b] * c
        counter[c] += counter[b]
        counter[b] = 0
        ans.append(sum_a)
    print(*ans, sep='\n')


if __name__ == '__main__':
    solve()


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a = ri() - 1, b = ri() - 1, c = ri() - 1, d = ri() - 1;
	std::string s;
	std::cin >> s;
	
	if (c == d) {
		assert(0);
		std::cout << "No" << std::endl;
		return 0;
	} else if (c < d) {
		bool res = true;
		for (int i = a; i < d; i++) if (s[i] == '#' && s[i + 1] == '#') {
			res = false;
			break;
		}
		if (res) std::cout << "Yes" << std::endl;
		else std::cout << "No" << std::endl;
	} else {
		bool res = false;
		for (int i = b; i <= d; i++) {
			if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
				res = true;
				break;
			}
		}
		for (int i = a; i < c; i++) if (s[i] == '#' && s[i + 1] == '#') {
			res = false;
			break;
		}
		if (res) std::cout << "Yes" << std::endl;
		else std::cout << "No" << std::endl;
		
	}
	
	return 0;
}


Measured memory_bytes: 640
X, N = map(int, input().split())
P = list(map(int, input().split()))

P.sort()
ans = abs(10000000)
for i in range(-101, 102):
  if not i in P:
    ans = min(ans, abs(i-X))

if not X-ans in P:
  print(X-ans)
else:
  print(X+ans)


Measured memory_bytes: 9180
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
//      String[] nyu=sc.nextLine().split(" ");

     String nyu=sc.nextLine();
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
int C=Integer.parseInt(nyu);


//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

if(C%2==0){
System.out.println(C);
}else{
System.out.println(C*2);

}



	}
}

Measured memory_bytes: 22612
local mmi = math.min
local n = io.read("*n")
local c_term, c_thru = {}, {}
local edge = {}
local parent = {}
local childcnt = {}
for i = 1, n do
  c_term[i] = 0
  c_thru[i] = io.read("*n")
  edge[i] = {}
  parent[i] = -1
  childcnt[i] = 0
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  table.insert(edge[a], b)
  table.insert(edge[b], a)
end
parent[1] = 0
local tasks = {1}
for i = 1, n do
  local src = tasks[i]
  for j = 1, #edge[src] do
    local dst = edge[src][j]
    if parent[dst] == -1 then
      parent[dst] = src
      childcnt[src] = childcnt[src] + 1
      table.insert(tasks, dst)
    end
  end
end
tasks = {}

if childcnt[1] == 1 then
  c_term[1], c_thru[1] = c_thru[1], 0
end
for i = 2, n do
  if childcnt[i] == 0 then
    c_term[i], c_thru[i] = c_thru[i], 0
    table.insert(tasks, i)
  end
end
local valid = true
for i = 1, n - 1 do
  local c = tasks[i]
  local p = parent[c]
  if c_term[p] + c_thru[p] < c_term[c] then
    valid = false
    break
  end
  local sub = mmi(c_term[c], c_thru[p])
  c_term[c] = c_term[c] - sub
  c_thru[p] = c_thru[p] - sub
  c_term[p] = c_term[p] + sub - c_term[c]
  c_term[c] = 0
  childcnt[p] = childcnt[p] - 1
  if 0 == childcnt[p] then
    if 0 < c_thru[p] then
      valid = false
      break
    end
    table.insert(tasks, p)
  end
end
if c_term[1] + c_thru[1] ~= 0 then valid = false end
print(valid and "YES" or "NO")


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

int main() {
  string s;
  cin >> s;
  int count = 0;
  
  for (int i; i < 3; i++) {
    if (s.at(i) == '1') {
	  count += 1;
    }
  }
  
  cout << count << endl;
}
   

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    long S = Long.parseLong(sc.next());
    
    long x1 = S;
    long y1 = 0;
    long x2 = 1;
    long y2 = 1;
    long x3 = 0;
    long y3 = 0;

    long g = (long)Math.sqrt(x1);
    if(g*g != x1){
      g++;
    }

    x1 = g;
    y2 = g;
    y1 = g*g-S;
    
    System.out.println(x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+y3);
  }
}

Measured memory_bytes: 23764
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var ab = new int[N][];
        var G = new Graph<int>(N);
        var degrees = new int[N];
        
        for (int i = 0; i < N-1; i++)
        {
            ab[i] = ReadLine().Split().Select(_=>int.Parse(_)-1).ToArray();
            int a = ab[i][0];
            int b = ab[i][1];
            G.Add(a, b);
            G.Add(b, a);
            degrees[a]++;
            degrees[b]++;
        }
        var c = ReadLine().Split().Select(long.Parse).ToArray();
        
        Array.Sort(c,(x,y)=>-x.CompareTo(y));

        int index = 0;
        int count = degrees[0];
        for (int i = 1; i < N; i++)
        {
            if (count > degrees[i])
            {
                count = degrees[i];
                index = i;
            }
        }

        var que = new Queue<int>();
        que.Enqueue(index);
        var d = Enumerable.Repeat(-1L, N).ToArray();
        d[index] = c[0];
        int num = 1;
        while (que.Count > 0)
        {
            var p = que.Dequeue();
            foreach (var i in G[p])
            {
                if (d[i] != -1) continue;
                d[i] = c[num++];
                que.Enqueue(i);
            }
        }

        WriteLine(c.Sum()-c[0]);
        WriteLine(string.Join(" ",d));
    }
}
class Graph<T>
{
    private List<T>[] G;
    public Graph(int size)
    {
        G = new List<T>[size];
        for (int i = 0; i < size; i++)
        {
            G[i] = new List<T>();
        }
    }

    public List<T> this[int i] => G[i];
    public void Add(int from, T to) => G[from].Add(to);
    public List<T>[] ToListArray() => G;
    public int Length => G.Length;
}



Measured memory_bytes: 33096
#include <stdio.h>
int main()
{
	int X, flag = 0;
	scanf("%d", &X);
	for(int n=1;n<10000;n++)
	{
		if(100*n<=X && X<=105*n)
		{
			printf("1\n");
			return 0;
		}
		if(100*n>X)
		{
			printf("0\n");
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
/*string s;
int main(){
    cin>>s;
    if (s[0]==s[1] && s[1]==s[2]) return puts("Yes");
    if (s[1]==s[2] && s[2]==s[3]) return puts("Yes");
    puts("No");
    return 0;
}*/
ll a[87];
int main(){
    int n;
    a[0]=2,a[1]=1;
    for (int i=2;i<=86;i++) a[i]=a[i-1]+a[i-2];
    read(n);
    cout<<a[n]<<endl;
    return 0;
}


Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define maxn 100010
#define LL long long
using namespace std;
LL n,a[maxn],y,id[maxn],vis[maxn],stk[maxn],top,k,m,ans[maxn];
int main(){
	scanf("%lld",&n);
	for(LL i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		id[i]=i;
	}
	for(LL i=n;i>=1;i--){//做差分 
		a[i]-=a[i-1];
	}
	scanf("%lld%lld",&m,&k);
	for(LL i=1;i<=m;i++){
		scanf("%lld",&y);
		swap(id[y],id[y+1]);//（难点）归纳出来的规律 
	}
	for(LL i=1;i<=n;i++){
		if(vis[i]==0){
			top=0;
			for(LL j=i;!vis[j];j=id[j]){
				stk[++top]=j;
				vis[j]=1;
			}
			for(LL j=1;j<=top;j++){
				ans[stk[j]]=a[stk[(k+j-1)%top+1]];
			}
		}
	}
	for(LL i=1;i<=n;i++){
		ans[i]+=ans[i-1];//期望值的可加性 
		printf("%lld\n",ans[i]);
	}
	return 0;
}//a b c d e f

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

int main()
{
    ll k, x;
    cin >> k >> x;
    for (int i = x - k + 1; i < k + x; i++)
    {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
D = []
count, temp = 0, 0

for n in range(N):
    input_line = input().split()
    if (int(input_line[0]) == int(input_line[1])):
        count += 1
        if count == 3:
            temp = 1
    elif(temp ==1):
        break
    else:
        count = 0

if count >= 3:
        print('Yes')

else:
        print('No')

Measured memory_bytes: 62424
#include <cstddef>
#include <vector>
#include <iostream>

using std::vector;
using std::cout;
using std::cin;

class UnionFind {
  vector<int> par;
public:
  UnionFind(size_t N) : par(N) {
    for (size_t i = 0; i < N; i++) {
      par[i] = i;
    }
  };

  int root(int x) {
    if (par[x] == x) {
      return x;
    }

    par[x] = root(par[x]);
    return par[x];
  }

  void unite(int x, int y) {
    int rx = root(x);  
    int ry = root(y);
    if (rx == ry) {
      return;
    }

    par[rx] = ry;
  }

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

int main(int argc, const char *argv[])
{
  int n, m;
  cin >> n >> m;
  vector<int> nums(n);
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }

  UnionFind tree(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    tree.unite(x - 1, y - 1);
  }

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (tree.same(nums[i] - 1, i)) {
      cnt++;
    }
  }

  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 1024
import string
n = int(input())
l = []
l = list(map(int, input().split()))
for i in range(n):
    key = l[i]
    j = i -1
    while j >= 0 and l[j] > key:
        l[j + 1] = l[j]
        j -= 1
    l[j + 1] = key
    print(' '.join(map(str, l)))

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

int main ()
{
    long long N;
    std::cin >> N;
    std::vector<long long> H(N);
    for (int i = 0; i < N; i++) std::cin >> H[i];

    bool ans = true;
    for (int i = 1; i < N; i++)
    {
        int diff = H[i] - H [i-1];

        if (diff == 0)
        {
            continue;
        }
        else if (diff >= 1)
        {
            H[i]--;
        }
        else if (diff < 0)
        {
            ans = false;
            break;
        }
    }

    if (ans == true) std::cout << "Yes" << std::endl;
    else if (ans == false) std::cout << "No" << std::endl;

    return 0;
}

Measured memory_bytes: 1024
import math

prime = [2]
for i in range(3, int(math.sqrt(200000)), 2):
  for j in prime:
    if i % j == 0:
      break
    elif math.sqrt(i) < j:
      prime.append(i)
      break

X = int(input())
if X % 2 == 0 and X != 2:
  X += 1

cand = 0
while not cand:
  for p in prime:
    if X != 2 and X % p == 0:
      break
    elif math.sqrt(X) < p:
      cand = X
      break
  X += 2

print(cand)

Measured memory_bytes: 9096
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )

char A;
int main() {
    int cnt = 0;
    rep(i, 0, 3) {
        cin >> A;
        if (A == 'o') {
            cnt++;
        }
    }
    cout << 700 + 100 * cnt << endl;
}

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

int main() {
  char a,b;
  cin >> a >> b;
  if(a == 'H') {
    if(b == 'H') cout << 'H' << endl;
    else cout << 'D' << endl;
  }else {
    if(b == 'H') cout << 'D' << endl;
    else cout << 'H' << endl;
  }
}

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

const int MAX_N = 2000;
int n, x, y;

void solve() {
    int d[n][n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i <= j) {
                d[i][j] = min(abs(i - j), abs(i - (x - 1)) + abs(j - (y - 1)) + 1);
            } else {
                d[i][j] = d[j][i];
            }
        }
    }

    int ans[n - 1];
    for (int i = 1; i <= n - 1; i++) {
        ans[i - 1] = 0;
    }
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            ans[d[i][j] - 1]++;    
        }
    }
    

    for (int i = 0; i < n - 1; i++) {
        cout << ans[i] << endl;
    }
}

int main() {
    cin >> n >> x >> y;
    solve();
}

Measured memory_bytes: 15872
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N, T, A;
	std::vector<int> H;
	std::cin >> N >> T >> A;
	H.resize(N);
	for (auto& h : H)
		std::cin >> h;
	
	T *= 1000;
	A *= 1000;
	int diff = 0x3fffffff;
	int idx = 0;
	for (int i = 0; i < N; ++i) {
		int cd = std::abs(A - (T - H[i]*6));
		if (cd < diff) {
			diff = cd;
			idx = i;
		}
	}
	std::cout << idx+1 << "\n";
}


Measured memory_bytes: 256
N,M=map(int,input().split())
H=[list(map(int,input().split()))for _ in range(M)]
H.sort()
a=H[-1][0]
s=1
for i in range(M-2,-1,-1):
 if H[i][1]<=a:
  s+=1
  a=H[i][0]
print(s)

Measured memory_bytes: 60744
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll

class BSumo {
public:
void solve(std::istream& cin, std::ostream& cout) {
    string s;
    cin >> s;
    int res = 0;
    for(auto c : s)res += c == 'x';
    if(res >= 8)cout << "NO" << endl;
    else cout <<"YES" << endl;
}
};


#undef int
int main() {
	BSumo solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
A  = 1
BC = 2
X  = 3

s = gets.chomp
a = []

i = 0
while i < s.size
  if s[i] == 'A'
    a << A
    i += 1
  elsif s[i] == 'B' && s[i+1] == 'C'
    a << BC
    i += 2
  else
    a << X
    i += 1
  end
end

b = []
tmp = []

a.each do |elm|
  if elm == X
    b << tmp
    tmp = []
  else
    tmp << elm
  end
end

b << tmp
b.reject!(&:empty?)

total = 0

b.each do |cs|
  num_a = 0
  point = 0
  cs.each do |c|
    if c == A
      num_a += 1
    elsif c == BC
      point += num_a
    end
  end

  total += point
end

p total


Measured memory_bytes: 14456
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100,mod=1e9+7;
ll power(ll n,ll k){
    if (k==0) return 1;
    if (k%2==1){
        ll x=power(n,k/2);
        return x*x%mod*n%mod;
    }
    ll x=power(n,k/2);
    return x*x%mod;
}
ll fen[N],fen1[N];
void add1(ll idx,ll val){
    for (;idx<N;idx+= idx & (-idx)){
        fen1[idx]+=val;
        fen1[idx]%=mod;
    }
}
ll get1(ll idx){
    ll s=0;
    for (;idx;idx-= idx & (-idx)) s+=fen1[idx],s%=mod;
    return s;
}
void add(ll idx,ll val){
    for (;idx<N;idx+= idx & (-idx)){
        fen[idx]+=val;
        fen[idx]%=mod;
    }
}
ll get(ll idx){
    ll s=0;
    for (;idx;idx-= idx & (-idx)) s+=fen[idx],s%=mod;
    return s;
}
ll a[N],t[N],b[N];
ll last[N],nxt[N];
int32_t main(){
    ll n;
    cin >> n;
    ll s=1;
    vector <int> ad;
    for (int i=1;i<=n;i++){
        cin >> a[i];
        ad.pb(a[i]);
    }
    sort(ad.begin(),ad.end());
    ll cnt=0;
    for (int i=n;i>0;i--){
        while(ad.size() && ad.back()==i){
            ad.pop_back();
            cnt++;
        }
        s*=cnt-(n-i);
        t[i]=cnt-(n-i);
        s%=mod;
    }
    b[0]=0;
    ll l=1;
    for (int i=1;i<=n;i++){
        b[i]=max((ll)1,b[i-1])*(t[i]-1)%mod*power(t[i],mod-2)%mod;
        if (b[i]==0){
            l=i;
        }
        last[i]=l;
    }
    l=n+1;
    for (int i=n;i;i--){
        if (b[i]==0) l=i;
        nxt[i]=l;
    }
    ll ans=0;
    ll ans1=0;
    for (int i=n;i;i--){
        ll z=get(nxt[a[i]]-1)-get(a[i]-1)+mod;
        z%=mod;
        ll y=power(b[a[i]],mod-2);
        ans+=z*y%mod*power(2,mod-2)%mod*s%mod;
        ans1+=s*(power(2,mod-2)*b[a[i]]%mod*(get1(a[i]-1)-get1(last[a[i]]-1)+mod)%mod)%mod;
        ans%=mod;
        add(a[i],b[a[i]]);
        add1(a[i],power(b[a[i]],mod-2));
        ans%=mod;
        ans1%=mod;
    }
    memset(fen,0,sizeof fen);
    ll ts=0;
    memset(fen1,0,sizeof fen1);
    for (int i=n;i;i--){
        ts+=get1(a[i]-1);
        ts%=mod;
        add1(a[i],1);
    }
    ans+=ts*s%mod-ans1;
    ans+=mod;
    ans%=mod;
    cout << ans%mod << endl;
}


Measured memory_bytes: 15984
from random import randint
import sys
input = sys.stdin.readline
INF = 9223372036854775808


def calc_score(D, C, S, T):
    """
    開催日程Tを受け取ってそこまでのスコアを返す
    コンテストi 0-indexed
    d 0-indexed
    """
    score = 0
    last = [0]*26  # コンテストiを前回開催した日
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]
    return score


def update_score(D, C, S, T, score, ct, ci):
    """
    ct日目のコンテストをコンテストciに変更する
    スコアを差分更新する

    ct: change t 変更日 0-indexed
    ci: change i 変更コンテスト 0-indexed
    """
    last = [0]*26  # コンテストiを前回開催した日
    for d in range(ct):
        last[T[d]] = d + 1
    prei = T[ct]  # 変更前に開催する予定だったコンテストi
    score -= S[ct][prei]
    score += S[ct][ci]
    for d in range(ct, D):
        if d != ct and T[d] == prei:
            break
        score += C[prei]*(d + 1 - ct - 1)
        score -= C[prei]*(d + 1 - last[prei])
    for d in range(ct, D):
        if d != ct and T[d] == ci:
            break
        score += C[ci]*(d + 1 - last[ci])
        score -= C[ci]*(d + 1 - ct - 1)
    T[ct] = ci
    return score, T


def local_search(D, C, S, T, today_score, d):
    pass


def evaluate(D, C, S, T, k):
    """
    d日目終了時点での満足度を計算し，
    d + k日目終了時点での満足度の減少も考慮する
    """
    score = 0
    last = [0]*26
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]

    for d in range(len(T), min(len(T) + k, D)):
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
    return score


def greedy(D, C, S):
    Ts = []
    for k in range(5, 16):
        T = []  # 0-indexed
        for d in range(D):
            # d+k日目終了時点で満足度が一番高くなるようなコンテストiを開催する
            max_score = -INF
            best_i = 0
            for i in range(26):
                T.append(i)
                score = evaluate(D, C, S, T, k)
                if max_score < score:
                    max_score = score
                    best_i = i
                T.pop()
            T.append(best_i)
        Ts.append((max_score, T))
    return max(Ts, key=lambda pair: pair[0])[1]


if __name__ == '__main__':
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    T = greedy(D, C, S)
    for t in T:
        print(t+1)


Measured memory_bytes: 84640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    rep(a, A + 1) rep(b, B + 1) {
        int ab = a * 500 + b * 100;
        if(ab <= X && (X - ab) % 50 == 0 && (X - ab) / 50 <= C) {
            ans++;
        }
    }
    output(ans);
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
vector<vector<int>> graph;
map<char,ll> mp;
int main(){
int n;
cin>>n;
string s,t;
cin>>s>>t;
int cnt=0;
bool check=false;
while(1){
    if(cnt==n)break;
    check=true;
    int i=n-1;
    while(i-cnt>=0){
        if(s.at(i)!=t.at(i-cnt))check=false;
        i--;
    }
    if(check)break;
cnt++;
}
cout<<s.size()+cnt<<endl;
}


Measured memory_bytes: 256
from scipy.misc import comb
# > comb(n, k, exact = True)

nn, kk = map(int, input().split())
r = nn - kk
b = kk
p = 10 ** 9 + 7

# for nCk calculation -----------------------
'''
factorial = [0] * (nn + 1)
factorial[0] = 1
for i in range(nn):
    factorial[i + 1] = factorial[i] * (i + 1) % p
# 逆元


def cmb(n, k):
    # if (n == 1 or k == 1):
    if (n == 0 or k == 0):
        return 1
    if (n < 0 or k < 0):
        return 0

    return factorial[n] * pow(factorial[n - k], p - 2, p) * pow(factorial[k], p - 2, p) % p

'''
# ---------------------------------------
for i in range(1, kk + 1):
    ans = comb(r + 1, i, exact=True) * comb(b - 1, i - 1, exact=True) % p

    #ans = (cmb(r + 1, i) * cmb(b - 1, i - 1)) % p
    print(ans)


# https://img.atcoder.jp/abc132/editorial.pdf


Measured memory_bytes: 14752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define FOR(i, r, n) for (int i=(int)(r); i<=(int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 2147483647
#define INF64 9223372036854775807
#define MOD 1000000007

int main(){

    int D; cin>>D;
    vector<int> c(26);
    vector<vector<int>> s(D, vector<int>(26));
    rep(i, 26) cin>>c[i];
    rep(i, D) rep(j, 26) cin>>s[i][j];

    vector<int> fuman(26, 0);
    rep(i, D){
        rep(j, 26) fuman[j]+=c[j];
        int t, fuman_max=-100000000;
        rep(j, 26){
            if(fuman_max<fuman[j]-s[i][j]){
                t=j;
                fuman_max=fuman[j];
            }
        }
        
        cout<<t+1<<endl;
        fuman[t]=0;
    }

}

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

int main(void) {
	int n = 0;
	char a[4];

	for (int i = 0; i < 4; i++) cin >> a[i];

	for (int i = 0; i < 4; i++) {
		if (a[i] == '+') n++;
		else n--;
	}

	cout << n << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const int mod = 1e9 + 7;

int rk(const vi &a) {
	vi b(a);
	sort(b.begin(), b.end());
	int res = 0;
	do {
		++res;
		if (a == b) return res;
	}	while (next_permutation(b.begin(), b.end()));
	return res;
}

signed main() {
	int n; cin >> n;
	vi p(n), q(n);
	for (auto &x : p) cin >> x;
	for (auto &x : q) cin >> x;
	cout << abs(rk(p) - rk(q));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  int n;
  cin>>n;
  cout<<0<<endl;

  string sex;
  cin>>sex;
  if(sex == "Vacant") return 0;
  
  int L = 0,R = n;
  while(L+1<R){
    int M = (L+R)/2;
    cout<<M<<endl;
    string s;
    cin>>s;
    if(s == "Vacant") return 0;
    if(M%2) sex != s? L=M:R=M;
    else sex == s? L=M:R=M;
  }
  
  cout<<L<<endl;
  cout<<R<<endl;
  
  return 0;
}


Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
    string s; cin >> s;
    int ans = 0;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') ans = 3;
    else if (s[0] == 'R' && s[1] == 'R') ans = 2;
    else if (s[2] == 'R' && s[1] == 'R') ans = 2;
    else {
        if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') ans = 1;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3620