akhauriyash/Code-Regression huggingface dataset:
N,M,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
a, b =[0],[0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
 
ans, j =0,M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K-a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Measured memory_bytes: 47368
s = input()
l = len(s)

prev = 0
ans1 = 0
for i in s:
    if prev != int(i):
        ans1 += 1
    if prev == 1:
        prev = 0
    else:
        prev = 1


prev = 1
ans2 = 0
for i in s:
    if prev != int(i):
        ans2 += 1
    if prev == 1:
        prev = 0
    else:
        prev = 1

print(min(ans1, ans2))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n;
    cin >> n;
    vi a(n*2+1);
    vi x(n+1, 0);
    repf(i, n){
        cin >> a[i];
        a[i+n] = a[i];
    }

    bool op = true;
    repf(i, n){
        if(op){ x[1] += a[i]; op = false; }
        else{ x[1] -= a[i]; op = true; }
    }
    cout << x[1] << " ";

    for(lli i=2; i<=n; i++){
        x[i] = 2*a[i-1]-x[i-1];
        cout << x[i] << ((i == n) ? endl : " "); 
    }
}

Measured memory_bytes: 3712
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	long long int n, a, b;
	cin >> n >> a >> b;
	cout << max((long long int)0, b * (n - 1) + a - (a * (n - 1) + b) + 1) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit =
  {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val h, w = sc.nextInt()
    val map = Vector.fill(h)(sc.next().toCharArray.toVector)

    def f[T](a: Vector[Vector[T]]): Vector[Vector[T]] =
    {
      if (a.head.length == 1)
      {
        Vector(a.map(_.head))
      }
      else
      {
          a.map(_.head) +: f(a.map(_.tail))
      }
    }

    val ans =
      f(
        f(map.filter(vec => vec.contains('#')))
          .filter(vec => vec.contains('#'))
      )

    ans.foreach(i => println(i.mkString("")))
  }

  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }

  def printExecTime(process: => Unit): Unit = {
    val start = System.currentTimeMillis
    process
    debug("処理時間： " + (System.currentTimeMillis - start) + " ミリ秒")
  }

  def bitSearch[T](n: Int, choice: Vector[T]): Vector[Vector[T]] = {
    @tailrec
    def bitSearchLogic(n: Int,
                       choice: Vector[T],
                       acc: Vector[Vector[T]]): Vector[Vector[T]] = {
      if (n == 0) acc
      else {
        val newAcc =
          acc.flatMap(vec => {
            choice.map(c => vec :+ c)
          })
        bitSearchLogic(n - 1, choice, newAcc)
      }
    }

    val firstAcc = choice.map(i => Vector(i))
    bitSearchLogic(n - 1, choice, firstAcc)
  }
}


Measured memory_bytes: 41768
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(input())
divisors = []
for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        divisors.append(i)
        if i != N // i:
            divisors.append(N//i)

divisors.sort()
m=len(divisors)

if m%2==0:
  print(divisors[m//2]+divisors[m//2-1]-2)
else:
  print(divisors[m//2]*2-2)

Measured memory_bytes: 9368
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = mutableMapOf<String, Int>()
    for (i in 1..n) {
        val tempS = readLine()!!
        if (s.containsKey(tempS)) {
            s[tempS] = s[tempS]!! + 1
        } else {
            s[tempS] = 1
        }
    }

    val m = readLine()!!.toInt()
    val t = mutableMapOf<String, Int>()
    for (i in 1..m) {
        val tempT = readLine()!!
        if (t.containsKey(tempT)) {
            t[tempT] = t[tempT]!! + 1
        } else {
            t[tempT] = 1
        }
    }

    var max = 0
    for(key in s.keys){
        val temp = if (t.containsKey(key)) t[key]!! else 0
        max = Math.max(max, s[key]!! - temp)
    }
    println(max)
}

Measured memory_bytes: 33532
s = gets.chomp
t = ""
ans = 0
["", "+"].repeated_permutation(s.length) do |plus|
  (s.length).times do |i|
    t << plus[i]
    t << s[i]
  end
  ans += t.split("+").map(&:to_i).inject(:+)
  t = ""
end
p ans / 2

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a, int b) {
    int c;
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int lcm(int a, int b) {
    int c = gcd(a, b);
    a /= c;
    return a * b;
}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI = acos(-1.0);


#define int long long

using namespace std;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};


signed main() {
    string s;
    cin >> s;

//    cout << s.size() <<endl;x
//    for (int i = 0; i < s.size(); i++) {
//        if (s[i] == 'k') {
//            if (s[i + 1] != 'e') {
//                for (int j = i + 2; j < s.size(); j++) {
//
//                }
//            }
//
//        }
//    }
    string tmp = "keyence";
//    cout << s.substr(0,7) << endl;
//    cout << s.substr(s.size()-7,s.size()) << endl;
    if (s.substr(0, 7) == "keyence") {
        cout << "YES" << endl;
        return 0;
    } else if (s.substr(s.size() - 7, s.size()) == "keyence") {
        cout << "YES" << endl;
        return 0;
    }

//    if(s[0] == 'k' && s.substr(s.size()-6,s.size()) == "eyence"){
//        cout << "YES" <<endl;
//    }
//
    for (int i = 1; i < 7; i++) {

//        cout << i << endl;
//        cout << s.substr(0, i) << " " << tmp.substr(0, i) << endl;
//        cout << s.substr(s.size() - 7 + i, s.size()) << " " << tmp.substr(tmp.size() - 7 + i, tmp.size()) << endl;

        if (s.substr(0, i) == tmp.substr(0, i) && (s.substr(s.size() - 7 + i, s.size()) ==
                                                   tmp.substr(tmp.size() - 7 + i, tmp.size()))) {

            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
}

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

#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long int lli;
#define rept(x, s, n) for (int x = s; x < n; x++)


int i_cins(int n, int* A);
int l_cins2(int n, long* A,long* B);
int s_dsort(const void* a, const void* b);

int main(void) {
	int   i,N,tmp=0;
	
	i_cin(N);

	rept(i, 1, N+1) 
		tmp += i;

    i_cout(tmp);
   
	return 0;
}

//降順
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
//
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	rept(i, 0, n) {
		i_cin(*(a + i));
	}
	return 0;
}




Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>
#define eps 1e-50
using namespace std;
int  inf=1000000002;
int main()
{
    string s;
    cin>>s;
    int t=0,ans=0;
    for(long i=0;i<s.size();i++)
    {
        if(s[i]=='T')
        {
            if(t!=0){t--;ans++;}

        }
        else
        {
            t++;
        }
    }
    cout<<s.size()-2*ans<<endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
long long int gcd(long long int x,long long int y)
{
    long long int r;
    while((r = x % y) != 0) 
    {
        x = y;
        y = r;
    }
    return y;
}
long long int lcm(long long int x,long long int y)
{

    return (y / gcd(x, y)*x);
}
int main(){
    long long int n;
    cin>>n;
    long long int t[n];
    rep(i,n){
        cin>>t[i];
    }
    long long int temp=t[0];
    rep(i,n){
        temp=max(temp,lcm(temp,t[i]));
    }
    cout<<temp<<endl;
    return 0;

}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,t=map(int, input().split())
    costmin=10000
    for i in range(n):
        c,tt=map(int, input().split())
        if tt<=t:
            costmin=min(c,costmin)
    if costmin==10000:
        print('TLE')
    else:
        print(costmin)
resolve()

Measured memory_bytes: 3060
import sys
# sys.setrecursionlimit(10**10)
N = int(sys.stdin.readline().rstrip())
# S = sys.stdin.readline().rstrip()
# N, K = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().split()))

if 0 in A:
    print(0)
    exit()

ans = 1
for a in A:
    ans *= a
    if ans > 10 **18:
        print(-1)
        exit()
else:
    print(ans)

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

int main(){
    int N,M;

    cin >> N >> M;

    int total = 0;

    for(int i=1; i<N; i++){
        for(int j=N-1; j>=0; j--){
            total = total + 1;
        }
    }

    for(int i=1; i<M; i++){
        for(int j=M-1; j>=0; j--){
            total = total + 1;
        }
    }

    cout << total/2 << endl;


    return 0;
}

Measured memory_bytes: 256
def abc167_c():
    import numpy as np
    N, M, X = map(int, input().split())
    Cost = [0] * N
    Query = np.zeros((N, M), dtype=int)
    for i in range(N):
        row = list(map(int, input().split()))
        Cost[i] = row[0]
        Query[i] = row[1:]
    ans = 10**9

    from itertools import product
    for v in product(range(2), repeat=N):
        score = np.zeros(M, dtype=int)
        co = 0
        for i in range(N):
            if v[i] == 0: continue
            score += Query[i]
            co += Cost[i]
        if X <= np.min(score):
            ans = min(co, ans)
    if ans < 10**9: print(ans)
    else: print(-1)

abc167_c()

Measured memory_bytes: 27272
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
int gcd(int a, int b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
int ans = 0;
int s[10][10];
int k[10];
int p[10];
void bit(int m, int n, int d) {
	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			bool w = true;
			rep(i, 0, d) {
				int x = 0;
				rep(j, 0, k[i])if (now[s[i][j] - 1] == '1')x++;
				if (x % 2 != p[i])w = false;
			}
			if (w)ans += 1;
		}
		else {
			for (int i = m - 1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}
;
int main() {
	int a, b;
	cin >> a >> b;
	if (a + b < 10)cout << a + b << endl;
	else cout << "error" << endl;
	return 0;
}


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

int main() {
  int n,x,sum=1;
  cin>>n>>x;
  vector<int>L(n);
  for(int i=0;i<n;i++){
    int l; cin>>l;
    L[i]=l;
  }
  int d=0;
  for(int i=0;i<n;i++){
    d+=L[i];
    if(d<=x) sum++;
  }
  cout<<sum<<endl;
}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,ans;
  cin >> s;
  ans = "";
  for(int i = 0; i < s.size(); i ++){
    if(s.at(i) == '0'){
      ans += s.at(i);
    }
    if(s.at(i) == '1'){
      ans += s.at(i);
    }
    if(s.at(i) == 'B'){
      ans = ans.substr(0,ans.size()-1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

int gcd(int a, int b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

//-----------------------ここから-----------


int main(void){
	int d, n;
	cin >> d >> n;

	if(n == 100){
		if(d == 0){
			cout << 100 + 1<< endl;
		} else if(d == 1){
			cout << 10000 + 100 << endl;
		} else {
			cout << 1000000 + 10000 << endl;
		}
		return 0;
	}

	if(d == 0){
		cout << n << endl;
	} else if(d == 1){
		cout << 100 * n << endl;
	} else {
		cout << 10000 * n << endl;
	}
}



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

int numofbits(long bits)
{
	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = ((bits >> 4) + bits) & 0x0f0f0f0f;
	bits += bits >> 8;
	return (bits + (bits >> 16)) & 0xff;
}

int main()
{
	int n, s;
	int count;
	int i, j;
	int sum;

	while (cin>>n>>s, n||s) {
		count = 0;
		for (i = 0; i < 1<<10; i++) {
			if ( numofbits(i) != n ) continue;
			sum = 0;
			for (j = 0; j < 10; j++) {
				if (i>>j & 1) sum += j;
			}
			if (sum == s) count++;
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;
int main() {
   int a,b;
   cin>>a>>b;
   if(a>0&&b>0)
   {
   	cout<<"Positive"<<endl;
   	 return 0;
   }
   if(a<=0&&b>=0)
   {
   	cout<<"Zero"<<endl;
   	 return 0;
   }
   if((-a+b+1)%2)
   cout<<"Negative"<<endl;
   else cout<<"Positive"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main  (){
    int a;
    int sum ;
    cin >> a ;
    for(int i=0; i < a; i++){
        int  b , c ,d;
        cin >> b >> c;
        d = c - b +1;
        sum += d;
    }
    cout << sum <<endl;
}
        

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

int main(){
  
  int N, max=0, sum=0;
  string S;
  cin >> N >> S;
  
  for (int i=0; i<N; i++){
    
    if (S.at(i)=='I'){
      sum++;
    }
    else if (S.at(i)=='D'){
      sum--;
    }
    
    if (sum>max){
      max = sum;
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int n, a[110], memo[100010];

int dp(int stone) {
	if (memo[stone] != -1)
		return memo[stone];
	memo[stone] = 0;
	for (int j = 0; j < n; j++) {
		if (stone < a[j])
			break;
		if (dp(stone - a[j]) == 0) {
			memo[stone] = 1;
			break;
		}
	}
	return memo[stone];
}

int main() {
	int k;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a, a + n);
	memset(memo, -1, sizeof memo);
	if (dp(k) == 1)
		printf("First\n");
	else
		printf("Second\n");
	return 0;
}

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

#define int long long

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

int N, A;
int x[50];
int dp[50][51][2501] = {};

signed main() {
    cin >> N >> A;
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    dp[0][0][0] = 1;
    dp[0][1][x[0]] = 1;
    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j <= i + 1; j++) {
            for (int k = 0; k <= 2500; k++) {
                dp[i + 1][j][k] += dp[i][j][k];
                dp[i + 1][j + 1][k + x[i + 1]] += dp[i][j][k];
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += dp[N - 1][i][i * A];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 48128
#include <bits/stdc++.h>
using namespace std;
using large = long long;
constexpr large fail = LLONG_MIN / 2;
// divide by 2 to make space for adding negative values

//       pos   skip  used
large dp[200'010][3][2];

template <class T, size_t N, class V> void fill_(T (&a)[N], V v) {
    for (auto &elem : a)
        elem = v;
}

template <class T, size_t N, size_t M, class V> void fill_(T (&md)[N][M], V val) {
    for (auto &row : md)
        fill_(row, val);
}

int main() {
    int n;
    cin >> n;
    auto a = vector<int>(n);
    for (auto &a_i : a)
        cin >> a_i;

    int cnt = n / 2;
    int max_skips = n - (2 * cnt - 1);
    // cerr << "n:" << n << " max_skips:" << max_skips << "\n";

    fill_(dp, fail);
    dp[0][0][0] = 0;
    dp[0][1][0] = 0;
    dp[0][2][0] = 0;

    for (int i = 0; i < n; ++i) {
        // use i'th
        dp[i + 1][0][1] = dp[i][0][0] + a[i];
        dp[i + 1][1][1] = dp[i][1][0] + a[i];
        dp[i + 1][2][1] = dp[i][2][0] + a[i];

        // don't use i'th
        dp[i + 1][0][0] = dp[i][0][1];
        dp[i + 1][1][0] = max(dp[i][1][1], dp[i][0][0]);
        dp[i + 1][2][0] = max(dp[i][2][1], dp[i][1][0]);
    }

    auto ans = max(dp[n][max_skips][0], dp[n][max_skips][1]);
#if 0
    for (int sk = 0; sk < max_skips; ++sk) {
        auto pos = n - (max_skips - sk);
        ans = max({ans, dp[pos][sk][0], dp[pos][sk][1]});
    }
#endif
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 13560
using System;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            string[] vs = a.Split(' ');

            int i2 = int.Parse(vs[1]);
            int i1 = int.Parse(vs[0]);

            int a1 = i2 + i1;
            int a2 = i2 * i1;

            if(a1 == 15)
            {
                Console.WriteLine("+");
            }
            else if(a2 == 15)
            {
                Console.WriteLine("*");
            }
            else
            {
                Console.WriteLine("x");
            }
            
        }

    }
}


Measured memory_bytes: 11092
#include <stdio.h>
typedef unsigned int uint32_t;
typedef int int32_t;
typedef long long int64_t;
#define NUM_CONTESTS (26)
#define MAX_DAY (365)


int main()
{
    int32_t D;
    int32_t c[NUM_CONTESTS];
    int32_t s[MAX_DAY][NUM_CONTESTS];
    int32_t t[MAX_DAY];
    int32_t score, last[NUM_CONTESTS]={0};
    
    // Read data
    scanf("%d", &D);
    for(int i =0; i<NUM_CONTESTS;i++){
        scanf("%d", &c[i]);
    }
    for(int i=0; i<D;i++){
        for(int j=0;j<NUM_CONTESTS;j++){
            scanf("%d", &s[i][j]);
        }
    }
    for(int i=0; i<D; i++){
        scanf("%d", t+i);
    }

    // Calc satisfaction score
    for(int i=0; i<D;i++){
        int num = t[i]-1;
        score += s[i][num];
        last[num] = i+1;
        for(int j=0; j<NUM_CONTESTS; j++){
            score -= c[j]*(i+1-last[j]);
        }
        printf("%d\n",score);
    }

    
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X,K,D; cin>>X>>K>>D;
    ll A = abs(X);
    ll t = A/D;
    if (K<=t){
        cout<<A-K*D<<endl;
    }else{
        K-=t;
        A-=t*D;
        ll B = abs(A-D);
        if (K%2==0){
            cout<<A<<endl;
        }else{
            cout<<B<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
int a,b,c,d,e;
void solve(){
	if (a+b+c+d==7) {cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<'='<<'7';return;}
	if (a+b+c-d==7) {cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<'='<<'7';return;}
	if (a+b-c+d==7) {cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<'='<<'7';return;}
	if (a+b-c-d==7) {cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<'='<<'7';return;}
	if (a-b+c+d==7) {cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<'='<<'7';return;}
	if (a-b+c-d==7) {cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<'='<<'7';return;}
	if (a-b-c+d==7) {cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<'='<<'7';return;}
	if (a-b-c-d==7) {cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<'='<<'7';return;}
	return;
}
int main(){
	cin>>e;
	d=e%10;e/=10;c=e%10;e/=10;b=e%10;e/=10;a=e%10;e/=10;
	
	solve();
	return 0;
	
}


Measured memory_bytes: 256
H, W = map(int, input().split())
s = []
nb = 0
for _ in range(H):
    s.append(list(input()))
    nb += s[-1].count("#")

nw = H * W - nb

sy, sx = 0, 0
gy, gx = H - 1, W - 1

q = [[sy, sx]]
visited = [[int(1e10)]*W for _ in range(H)]
visited[sy][sx] = 0
while q:
    ty, tx = q.pop(0)
    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ny, nx = ty + dy, tx + dx
        if 0 <= ny < H and 0 <= nx < W and s[ny][nx] != "#":
            if visited[ny][nx] > visited[ty][tx] + 1:
                visited[ny][nx] = visited[ty][tx] + 1
                q.append([ny, nx])
    if [gy, gx] in q:
        temp = visited[gy][gx]
        break
if visited[gy][gx] == int(1e10):
    print(-1)
else: print(nw - temp - 1)

Measured memory_bytes: 40432
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}


int main(void){

  ll k;
  cin>>k;
 
  string s;
  cin>>s;
 
  if(s.size()<=k){
    cout<<s<<endl;
  }else{
    REP(i, k){
      cout<<s[i];
    }
    cout<<"..."<<endl;
  }
  return 0;
 

}

Measured memory_bytes: 3724
#include<iostream>
#include<string>
#include<cstdlib>

#define N 100000
using namespace std;


typedef struct{
  int num[N];
  int head;
  int tail;
}Queque;


//grobal
Queque que;

//add to head position
void Enqueue(int);
//delete head position
void Dequeue(void);
//return now of stck
int front(void);


int main(){
  //format
  que.head=0;
  que.tail=0;

  int pasttime=0;
  int i,n,q,tim=0;
  string name[N];
  int finishcount=0;
  int flag[N];
  int st;

  //load n and q
  cin >>n>>q;

  //load name and time
  for(i=0;i<n;i++){
    cin >>name[i]>>tim;
    Enqueue(tim);
  }

  //format flag
  for(i=0;i<n;i++){
    flag[i]=0;
  }
  
  i=0;

  while(1){
    if(finishcount==n) break;
    //i->n i=0 continue
    else if(i==n){
      i=0;
      continue;
      }
    //flag=1 go next
      else if(flag[i]==1){
      i++;
      continue;
    }
    //load
    st=front();

    if(st>q){
      Enqueue(st-q);
      Dequeue();
      pasttime+=q;
    }

    else{
      Dequeue();
      pasttime+=st;
      flag[i]=1;
      finishcount++;
      //print
      cout <<name[i]<<" "<<pasttime<<endl;
    } 
    
    i++;
  }
    
  
  return 0;
  
}

//add to head position
void Enqueue(int x){
  que.num[que.tail]=x;
  que.tail++;
//if over N tail=0
  if(que.tail==N)que.tail=0; 
}
//delete head position
void Dequeue(void){
  que.head++;
}
//return now of stck
int front(void){
  return que.num[que.head];
}

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



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

	vector<ll> A(N);
	for (auto& e : A) {
		cin >> e;
	}

	int l = 0, r = N;
	while (r - l > 1) {
		int mid = (l + r) / 2;

		map<int, int> mp;
		mp[A[0]] = 0;
		bool ok = true;
		for (int i = 1; i<N; i++) {
			if (A[i - 1] < A[i]) {
				auto it = --mp.end();
				if (it->second == 0) {
					mp.erase(it);
				}
				mp[A[i]] = 0;
			} else {
				auto it = mp.lower_bound(A[i]);
				if (it->second == mid - 1) {
					while (it != mp.begin() && it->second == mid - 1) {
						--it;
					}
					if (it == mp.begin() && it->second == mid - 1) {
						ok = false;
						break;
					}
					if (it->first != 1 && mp.find(it->first - 1) == mp.end()) {
						mp[it->first - 1] = it->second;
					}
					it->second++;

					auto nit = --mp.end();
					while (it != nit) {
						mp.erase(nit);
						nit = --mp.end();
					}
					assert(it->first < A[i]);
					mp[A[i]] = 0;
				} else {
					if (A[i] != 1 && mp.lower_bound(A[i] - 1) == it) {
						mp[A[i] - 1] = it->second;
					}
					mp[A[i]] = it->second + 1;

					mp.erase(mp.upper_bound(A[i]), mp.end());
				}
			}
		}
		if (ok) {
			r = mid;
		} else {
			l = mid;
		}
	}
	cout << r << endl;

	return 0;
}

Measured memory_bytes: 1792
//Mir_123
//Credits:- Shashank Keshav
/*Life begins beyond your comfort zone*/
/*Either solve hard questions
  or else don't solve any question*/
#include<bits/stdc++.h>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<iterator>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define bin binary_search
#define vmin *min_element
#define vmax *max_element
bool cmp_sec(pair<ll,ll> &a,pair<ll,ll> &b)
{
  if(a.second!=b.second)
    return a.second<b.second;
  return a.first<b.first;
}
//Use set if your want your array to be auto sorted
//sort takes log(N) time
struct item
{
  ll w,v;
};
int main(void)
{
  ll n,mw,i,j;
  cin>>n>>mw;
  vector<item>vec(n);
  for(i=0;i<n;i++)  cin>>vec[i].w>>vec[i].v;
  vector<ll>dp(mw+1,0);
  for(i=0;i<n;i++)
  {
    for(j=mw-vec[i].w;j>=0;j--)
    {
      if(dp[j]==0&&j!=0)
        continue;
      dp[j+vec[i].w]=max(dp[j+vec[i].w],dp[j]+vec[i].v);
    }
  }
  cout<<vmax(dp.begin(),dp.end());
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  set<string> S;
  for(int i = 0;i < n;i++) {
    string s;
    cin >> s;
    S.insert(s);
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 19188
import std.algorithm, std.stdio, std.string, std.range, std.conv;

string longer(ref in string x, ref in string y) {
  if (x.length < y.length) return y;
  return x;
}

void main() {
  const s = readln.chomp;
  const t = readln.chomp;
  
  size_t[][] dp;
  dp.length = s.length+1;
  foreach (ref x; dp) x.length = t.length+1;
  
  foreach (si; 1..s.length+1) foreach (ti; 1..t.length+1) {
    if (s[si-1] == t[ti-1]) {
      dp[si][ti] = dp[si-1][ti-1] + 1;
    } else {
      dp[si][ti] = max(dp[si-1][ti], dp[si][ti-1]);
    }
  }
  
  string ans;
  
  size_t si = s.length, ti = t.length;
  while (si > 0 && ti > 0) {
    if (dp[si][ti] == dp[si][ti-1]) {
      --ti;
    } else if (dp[si][ti] == dp[si-1][ti]) {
      --si;
    } else {
      --si; --ti;
      ans ~= s[si];
    }
  }
  ans.retro.to!string.writeln;
}

Measured memory_bytes: 73724
#include<stdio.h>
 
#define MAX 100
#define NIL -1
 
struct node{
  int parent;
  int left;
  int right;
};
 
struct node T[MAX];
int n;
 
void PreOrder(int);
void InOrder(int);
void PostOrder(int);
 
int main(){
  int id, l, r;
  int root;
  int i;
 
  scanf("%d", &n);
 
  for(i=0; i<n; i++){
    T[i].parent = T[i].left = T[i].right = NIL;
  }
 
  for(i=0; i<n; i++){
    scanf("%d%d%d", &id, &l, &r);
 
    T[id].left = l;
    T[id].right = r;
     
    T[l].parent = id;
    T[r].parent = id;
  }
 
  for(i=0; i<n; i++){
    if(T[i].parent == NIL){
      root = i;
      break;
    }
  }
 
  printf("Preorder\n");
  PreOrder(root);
  printf("\n");
 
  printf("Inorder\n");
  InOrder(root);
  printf("\n");
 
  printf("Postorder\n");
  PostOrder(root);
  printf("\n");
   
  return 0;
}
 
void PreOrder(int u){
  if(u == NIL)
    return;
 
  printf(" %d",u);
  PreOrder(T[u].left);
  PreOrder(T[u].right);
}
 
void InOrder(int u){
  if(u == NIL)
    return;
   
  InOrder(T[u].left);
  printf(" %d",u);
  InOrder(T[u].right);
}
 
void PostOrder(int u){
  if(u == NIL)
    return;
   
  PostOrder(T[u].left);
  PostOrder(T[u].right);
  printf(" %d",u);
}



Measured memory_bytes: 2092
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 2e5 + 10;
int N;
int A[MAX];

int main(void) {
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }

    int cur = 1, b = 0;
    REP(i, N) {
        if (A[i] == cur) {
            cur++;
        } else {
            b++;
        }
    }

    if (b == N) cout << -1 << endl;
    else cout << b << endl;
}


Measured memory_bytes: 1024
#include <iostream>

int main()
{
  int N, A, B;
  std::cin >> N >> A >> B;
  
  if ( N == 2 || (B - A - 1) % 2 == 0 ) std::cout << "Borys\n";
  else std::cout << "Alice\n"; 

  return 0;
}


Measured memory_bytes: 256
A,B,C=map(int,input().split())
K=int(input())

for i in range(0,K+1):
    for j in range(0,K+1-i):
        for k in range(0,K+1-i-j):
            #print('{},{},{}'.format(i,j,k))
            if(A*(2**i) < B*(2**j) and B*(2**j) < C*(2**k)):

                print('Yes')
                exit()

print('No')


Measured memory_bytes: 61876
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <stack>
#include <cmath>
#include <string>
#define SIZE 100005
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int cnt[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int a;
		scanf("%d",&a);
		cnt[a]++;
	}
	ll ret=1;
	for(int l=0,r=n-1;l<=r;l++,r--)
	{
		if(l==r)
		{
			if(cnt[r-l]!=1)
			{
				puts("0");
				return 0;
			}
		}
		else
		{
			if(cnt[r-l]!=2)
			{
				puts("0");
				return 0;
			}
			ret*=2LL;
			if(ret>=MOD) ret-=MOD;
		}
	}
	printf("%lld\n",ret);
	return 0;
}


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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> data(n);
  for(int i=0; i<n; i++){
    cin >> data.at(i);
  }
  int sum=0,count=1;
  for(int i=0; i<n; i++){
    sum += data.at(i);
    if(sum <= x){
      count++;
    }else{
      break;
    }
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
n,k,q = list(map(int,input().split()))
data = [k] * n
for i in range(q):
  answer = int(input())
  data[answer-1] += 1

for i in range(n):
  data[i]  = data[i] - q

for i in range(n):
  if data[i] >= 1:
    print('Yes')
  else:
    print('No')


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  int n,x;
  cin>>n>>x;
  vector<int> a(n);
  cin>>a;

  rep(i,n-1){
    a[i+1]+=a[i];
  }
  auto itr = upper_bound(a.begin(),a.end(),x);
  itr--;
  int id = itr-a.begin();
  cout<<(id+2)<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    long long n; cin >> n;
    long long sum = 0;
    vector<long long> v;
    for(int i = 0; i < n; i++){
        long long a; cin >> a;
        sum += a;
        v.push_back(sum);
    }

    long long ans = 1e18;
    for(int i = 0; i < n - 1; i++){
        ans = min(ans, abs(2*v[i] - sum));
    }
    cout << ans << endl;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N, M;
bool p[100010];
int num[100010];

int main() {
    p[0] = 1;
    cin >> N >> M;
    rep(i, N) num[i] = 1;

    rep(i, M) {
	int x, y;
	cin >> x >> y;
	--x; --y;
	p[y] |= p[x];
	++num[y];

	if (--num[x] == 0) {
	    p[x] = 0;
	}
    }

    int ret = 0;
    rep(i, N) ret += p[i];
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 768
def main():
    N, M, X = [int(x) for x in input().split()]
    Cl, All = [], []
    for i in range(N):
        tmp = [int(x) for x in input().split()]
        Cl.append(tmp[0])
        All.append((tmp[1:]))
    # 参考書全て購入した金額+1円を最低金額の初期値に
    min_cost = sum(Cl) + 1
    # 0冊購入は考慮せず、1冊目からループ
    for bit in range(1, 1 << N):
        cost = 0
        # アルゴリズムM個の理解力を保持するリスト
        totalAl = [0]*M
        for i, al in enumerate(All):
            # 購入フラグが立っていればアルゴリズムの理解力と金額を更新
            if (1 << i) & bit:
                for j, a in enumerate(al):
                    totalAl[j] += a
                cost += Cl[i]
        # 全アルゴリズムの理解力が目標を満たしていれば最低金額を更新
        check = True
        for a in totalAl:
            if a < X:
                check = False
        if check:
            min_cost = min(min_cost, cost)
    # 購入金額が初期値のままならば-1を出力
    if min_cost > sum(Cl):
        print(-1)
    else:
        print(min_cost)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9248
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
const int inf = 1e9;

template<typename T>
struct MincostFlow{
    struct edge{
        int to, rev;
        int cap;
        T cost;
        edge(int to, int rev, int cap, T cost)
            :to(to),rev(rev),cap(cap),cost(cost){}
        edge(){}
    };
    
    int n;
    T zero;
    T inf;
    vector<vector<edge>> graph;

    MincostFlow(int n, T zero, T inf):n(n),zero(zero),inf(inf){
        graph.resize(n);
    }
    void add_edge(int from, int to, int cap, T cost){
        graph[from].emplace_back(to, graph[to].size(), cap, cost);
        graph[to].emplace_back(from, (int)graph[from].size()-1, 0, -cost);
    }
    T exec(int s, int g, int f){
        T res = zero;
        while(f > 0){
            vector<int> prevv(n), preve(n);
            vector<T> mincost(n, inf);
            mincost[s] = zero;
            while(1){
                bool update = false;
                for(int i=0; i<n; i++){
                    if(mincost[i] == inf) continue;
                    for(int j=0; j<(int)graph[i].size(); j++){
                        edge &e = graph[i][j];
                        if(e.cap>0 && mincost[i] +e.cost < mincost[e.to]){
                            mincost[e.to] = mincost[i] +e.cost;
                            prevv[e.to] = i;
                            preve[e.to] = j;
                            update = true;
                        }
                    }
                }
                if(!update) break;
            }
            if(mincost[g] == inf){
                return inf;
            }
         
            int d = f;
            for(int v=g; v!=s; v=prevv[v]){
                d = min(d, graph[prevv[v]][preve[v]].cap);
            }
            f -= d;
            res += d*mincost[g];
            for(int v=g; v!=s; v=prevv[v]){
                edge &e = graph[prevv[v]][preve[v]];
                e.cap -= d;
                graph[v][e.rev].cap += d;
            }
        }
        return res;
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }
    map<int, int> conv;
    for(int i=0; i<n; i++){
        conv[a[i]] = 0;
        conv[b[i]] = 0;
    }
    int idx = 0;
    for(auto &p: conv){
        p.second = idx;
        idx++;
    }

    int s=idx+n, g=idx+n+1;
    MincostFlow<int> flow(idx+n+2, 0, inf);
    for(int i=0; i<idx; i++){
        flow.add_edge(s, i, 1, 0);
    }
    for(int i=0; i<n; i++){
        flow.add_edge(conv[a[i]], idx+i, 1, -b[i]);
        flow.add_edge(conv[b[i]], idx+i, 1, -a[i]);
    }
    for(int i=0; i<n; i++){
        flow.add_edge(idx+i, g, 1, 0);
    }
    int ans = 0;
    int curr = 0;
    for(int i=0; i<n; i++){
        int ret = flow.exec(s, g, 1);
        if(ret != inf){
            curr += -ret;
        }
        ans = max(ans, curr);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3500
package main

import "fmt"

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func abs(i int) int {
	if i < 0 {
		return -1 * i
	}
	return i
}

func main() {
	var N, X int
	fmt.Scanf("%v", &N)
	fmt.Scanf("%v", &X)

	xs := make([]int, 0, N)

	for i := 0; i < N; i++ {
		var x int
		fmt.Scanf("%v", &x)
		xs = append(xs, abs(X-x))
	}

	var ans = xs[0]
	for _, x := range xs {
		ans = gcd(ans, x)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6312
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
using namespace std;


int main()
{
    int N;
    cin>>N;
    vector<int>B(N-1);
    for(int i=0;i<N-1;i++) cin>>B[i];
    int ans=B[N-2];//A[N-1]
    
    ans+=B[0];//A[0]
    for(int i=1;i<N-1;i++){
        ans+=min(B[i],B[i-1]);
    }
    cout<<ans<<endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
import sys
r=sys.stdin.readline
N=int(r())
F=[int(r().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,r().split()))for _ in[0]*N]
print(max(sum([p[bin(f&i).count('1')]for f,p in zip(F,P)])for i in range(1,2**10)))

Measured memory_bytes: 3064
n,k = map(int,input().split())
L = []
for i in range(n):
    a,b = map(int,input().split())
    L.append([(i+1)*100,a,b])
#print(L)
ans = 10**10
if k < L[-1][0]*L[-1][1]:
    if k%L[-1][0] != 0:
        ans = (k//L[-1][0]+1)
    else:
        ans = (k//L[-1][0])

for i in range(1<<n):
    li = []
    score,score_zan,cnt = 0,0,0
    for j in range(n):
        if i>>j&1:
            score +=(L[j][0]*L[j][1] + L[j][2])
            cnt +=L[j][1]
            score_zan = k-score
        else:
            li.append(L[j])
    if score > 0 and score_zan <= 0:
        ans = min(ans,cnt)
    li.sort(reverse = True)
    #print(score,li,cnt,score_zan)
    if li and score_zan > 0:
        if score_zan < li[0][0]*li[0][1]:
            ans = min(ans,cnt + score_zan//li[0][0])
print(ans)

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

action = [0] * N
money = 1000
kabu = []


def state(a, b):
    return 'up' if a - b >= 0 else 'down'


def buy(i):
    global money
    kabu.append([A[i], (money // A[i])])
    money = money - ((money // A[i]) * A[i])
    kabu.append([A[i], (money // A[i])])


def sell(i):
    global kabu
    global money
    if not kabu:
        buy(0)
    for value, count in kabu:
        money += A[i] * count
    kabu = []


st0 = state(A[1], A[0])
if st0 == 'up':
    buy(0)

for i in range(1, N - 1):
    st1 = state(A[i + 1], A[i])
    if st0 != st1:
        # action
        if st1 == 'up':
            buy(i)
        else:
            sell(i)
    st0 = st1

if kabu:
    sell(N - 1)


print(money)


Measured memory_bytes: 62092
S=input()
s=[]
for i in range(26):
  s=s+[chr(97+i)]
for i in range(len(S)):
  s.remove(S[i])
if len(s)==0:
  for i in range(25):
    if ord(S[24-i])<ord(S[25-i]):
      q=S[25-i:]
      q2=[]
      for j in q:
        if ord(j)<ord(S[24-i]):
          pass
        else:
          q2+=[ord(j)]
      q2.sort()
      
      S=S[:24-i]+chr(q2[0])
      print(S)
      break
    if i==24:
      print(-1)
    
else:
  print(S+s[0])


Measured memory_bytes: 3064
import numpy as np

c = np.array([list(map(int, input().split())) for i in range(3)])

x = [0] * 3
y = [0] * 3

for i in range(3):
    y[i] = c[0][i] - x[0]
for i in range(3):
    x[i] = c[i][0] - y[0]
flag = True

for i in range(3):
    for j in range(3):
        if x[i] + y[j] != c[i][j]:
            flag = False

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



Measured memory_bytes: 12500