akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
typedef long long ll;
#define mod 1000000007

int main() {
  string S; cin >> S;
  cout << S[0] << S.size() - 2 << S.back() << endl;
  return 0;
}


Measured memory_bytes: 256
S=input()
s=len(S)
T=""
i=0
while True:
    if S[i:i+5]=="dream":
        if i+5==s or S[i+5:i+7]!="er":
            T+="dream"
            i+=5
        elif S[i+5:i+7]=="er":
            if i+7==s or S[i+7]!="a":
                T+="dreamer"
                i+=7
            else:
                T+="dream"
                i+=5
    elif S[i:i+6]=="eraser":
        T+="eraser"
        i+=6
    elif S[i:i+5]=="erase":
        T+="erase"
        i+=5
    else:
        print("NO")
        exit()
    #print(T)
    if len(T)>=len(S):
        break
print("YES")

Measured memory_bytes: 9252
import numpy as np
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d,e=0,0
for i in range(n):
  c=a[i]-b[i]
  if c>0:
    d+=c
  elif c%2==0:
    e+=-c
  else:
    e+=-c-1
print('Yes' if 2*d<=e else 'No')


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

int main() {

    long N, A, B;

    cin >> N >> A >> B;

    long answer;

  	if (A==0){
      cout<<0<<endl;
      return 0;
    }
    answer = N/(A+B)*A;
    N %=A+B;
  	if (N>=A){
        answer += A;
    } else {
        answer += N%A;
    }
    cout << answer << endl;
    return 0;
}


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


int main(){
    
    ll N;
    cin >> N;
    set<ll>S;
    for(ll i = 0; i < N; i++){
        ll x;
        cin >> x;
        S.insert(x);
    }
    cout << S.size() << endl;
    
    return 0;
}


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

import heapq

def main2():
    n,m=map(int,input().split())
    jobs_list=[list(map(int,input().split())) for _ in range(n)]
    #breakするタイミングを作るため、Mより大きい値の仕事を作成
    banpei_list=[[i,0] for i in range(1,m+2)]
    #リストの統合
    jobs_list.extend(banpei_list)
    jobs_list=sorted(jobs_list)
    ans=0
    index=0
    que=[]
    while 1:
        day,pay=jobs_list[index]
        #dayがMを超えていればbreak
        if day>m:
            break
        #同じdayのデータが次にもあれば-1倍してheapにpush
        if day==jobs_list[index+1][0]: 
            heapq.heappush(que,-pay)
        #仕事の報酬の最大値を答えに加える
        #前の日のデータからも報酬が良い仕事は選べるようにqueにデータは貯めておく
        else:
            heapq.heappush(que,-pay)
            ans-=heapq.heappop(que)
        index+=1
    print(ans)

if __name__ == "__main__":
    main2()

Measured memory_bytes: 42620
from collections import deque
n=int(input())
g=[[] for _ in range(n+1)]
e=[]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    e.append(b-1)

q=deque([0])

color=[0 for _ in range(n)]
while(len(q)>0):
    ei=q.popleft()
    c=1
    for x in g[ei]:
        if c == color[ei]:
            c+=1

        color[x]=c
        c+=1
        q.append(x)

print(max(color))
for i in e:
    print(color[i])

Measured memory_bytes: 26272
n,k = (int(x) for x in input().split())
s = str(input())
slist = sorted(list(s))
if len(slist)-1<k:
  ans = ""
  for t in slist:
    ans += slist[0]
  print(ans)
else:
  ss = s + s[::-1]
  #print(ss)
  lens = len(s)
  rev = []
  for i in range(k-1):
    for x in range(lens+1):
      r = ss[x:lens+x]
      rev.append(r[::-1])
    sortrev = sorted(rev)
    tmp = sortrev[0]
    ss = tmp[::-1]+tmp
    #print(tmp[::-1])
    #print(ss)
    rev = []
  for x in range(lens+1):
    r = ss[x:lens+x]
    rev.append(r)
  sortrev = sorted(rev)
  print(sortrev[0])




Measured memory_bytes: 52596
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();

const intt max1 = 11;
const intt max2 = 102;
const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;
const intt lg2 = 7;
const intt lg3 = 10;
const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;
const intt lg7 = 24;
const intt lg8 = 27;
const intt lg9 = 30;
const intt lg18 = 60;
const intt INF = 2LL * 1000000000;
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a, intt b) { while(b) b ^= a ^= b ^= a %= b; return a;}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}
/**************************/

intt arr[150];
int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    intt a, b, c, d;
    cin >> a >> b >> c >> d;
    for (intt i = a; i < b; i++)
        arr[i] ++;
    for (intt i = c; i < d; i++)
        arr[i] ++;
    intt res = 0;
    for (intt i = 0; i <= 100; i++)
        res += arr[i] == 2;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct UnionFind {
    vector<int> par, size;
    UnionFind(int x) {
        par.resize(x);
        size.resize(x, 1);
        for(int i = 0; i < x; i++) {
            par[i] = i;
        }
    }
    int find(int x) {
        if (par[x] == x)
            return x;
        return par[x] = find(par[x]);
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int consize(int x) {
        return size[find(x)];
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (size[x] < size[y]) {
            par[x] = y;
            size[y] += size[x];
        }
         else {
            par[y] = x;
            size[x] += size[y];
        }
    }
};
signed main() {
    int N,M;
    cin >> N >> M;
    UnionFind uf(N);
    for(int i = 0; i < M; i++) {
        int A,B;
        cin >> A >> B;
        A--;B--;
        uf.unite(A,B);
    }
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        cnt = max(cnt,uf.consize(i));
    }
    cout << cnt << endl;
}


Measured memory_bytes: 6416
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int64_t K;
  cin >> K;

  int N = 50;
  int64_t def = 49 + K / 50;
  vector<int64_t> answer(N, def);
  rep(i, K % 50) {
    answer[i] += N + 1;
    rep(j, N) answer[j]--;
  }

  cout << N << endl;
  rep(i, N) {
    if (i != 0) cout << " ";
    cout << answer[i];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>

using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,N) for(long long int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, m;
set<int> si;

int main(){
	while (cin >> n >> m){
		if (n + m == 0)break;
		int a = 0;
		while (si.size() <= n){
			REP(i, m){
				a++;
				if (a > n){
					a = 1;
				}
				while (si.find(a) != si.end()){
					a++;
					if (a > n){
						a = 1;
					}
				}
			}
			si.insert(a);
			if (si.size() == n){
				cout << a << endl;
				break;
			}
		}
		si.clear();
	}
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int n;
int arr[(int)1e5 + 4];
long long dp[int(1e5) + 4];

long long solve(int index)
{
    if(index == n - 1)
        return 0;
    long long &ret = dp[index];
    if(~ret)
        return ret;
    ret =  1e9 + 7;
    if(index + 1 < n)
        ret = min(ret, solve(index + 1) + abs(arr[index] - arr[index + 1]));
    if(index + 2 < n)
        ret = min(ret, solve(index + 2) + abs(arr[index] - arr[index + 2]));
    return ret;
}

int main()
{
    IO;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0);
    return 0;
}


Measured memory_bytes: 4608
import math
import sys
# N, K = [int(_) for _ in input().split()]
N = int(input()) - 1
m = 0
i = 1
while True:
  m += 26 ** i
  if N < m:
    break
  i += 1
digit = i
N = N - (m - 26 ** i)

name = ''
for i in range(digit):
  c = chr(97+(26 + N) % 26)
  name += c
  N //= 26
print(name[::-1])


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	int k, a, b;
	cin >> k >> a >> b;

	for(int i = a; i <= b; i++){
		if(i % k == 0){
			cout << "OK";
			return 0;
		}
	}

	cout << "NG";

	return 0;
}

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  int xmin = 0;
  int xmax = W;
  int ymin = 0;
  int ymax = H;
  for (int i = 0; i < N; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1 && xmin < x) xmin = x;
    if (a == 2 && xmax > x) xmax = x;
    if (a == 3 && ymin < y) ymin = y;
    if (a == 4 && ymax > y) ymax = y;
  }
  if (xmin > xmax || ymin > ymin) {
    cout << 0 << endl;
    return 0;
  }
  int sum = (xmax - xmin) * (ymax - ymin);
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
field = []
for _i in range(h):
  field.append(list(input()))

def find_mines(x, y):
  if field[x][y] == '#':
    return '#'
  else:
    cnt = 0
    for i in range(x - 1, x + 2):
      for j in range(y - 1, y + 2):
        if i < 0 or i > h - 1 or j < 0 or j > w -1 or (i == x and j == y):
          continue
        else:
          if field[i][j] == '#':
            cnt += 1
    return str(cnt)

ans = field[::]
for idx1, i in enumerate(ans):
  for idx2, _j in enumerate(i):
    ans[idx1][idx2] = find_mines(idx1, idx2)

for i in ans:
  print("".join(i))





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

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

int main() {
    int a,b;
    cin >> a >> b;
    cout << max({a+b,a-b,a*b});
    return 0;
}



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

namespace AtTest.ABC_139
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] ab = ReadInts();
            int a = ab[0];
            int b = ab[1];
            int res = (b - 1) / (a - 1);
            if ((b - 1) % (a - 1) > 0) res++;
            WriteLine(res);
        }

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


Measured memory_bytes: 11220
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 100100

ll n,u,v;
vector<ll> adj[MAX];
ll dist_u[MAX],dist_v[MAX];

void fill_u(ll s,ll p,ll d){
	dist_u[s] = d;
	for(ll x:adj[s]) if(x!=p){
		fill_u(x,s,d+1);
	}
	return;
}
ll parent[MAX];
void fill_v(ll s,ll p,ll d){
	dist_v[s] = d;
	parent[s] = p;
	for(ll x:adj[s]) if(x!=p){
		fill_v(x,s,d+1);
	}
	return;
}

ll depth[MAX];
ll dfs(ll s,ll p){
	depth[s] = 0;
	for(ll x:adj[s]) if(x!=p){
		depth[s] = max(dfs(x,s)+1,depth[s]);
	}
	return depth[s];
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin>>n>>u>>v;u--;v--;
	For(i,0,n-1){
		ll x,y;cin>>x>>y;x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	fill_u(u,-1,0);
	fill_v(v,-1,v);
	dfs(v,-1);

	ll d = dist_u[v]-1;

	ll ans = depth[u]+d , count = 0;
	ll p = parent[u];
	ll c = 1;
	while(count<d/2){
		ans = max(ans,c+depth[p]+(d-2*c));
		p = parent[p];
		count++;
		c++;
	}
	cout<<ans<<endl;































	
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;


int main(){
	fast;
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({a * c, b * d, a * d, b * c});
	return 0;
}


Measured memory_bytes: 3680
import java.util.*;


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

	class Pair{
		int a;
		int b;
		Pair(int a,int b){
			this.a=a;
			this.b=b;
		}
	}


	public void run() {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();

		long ans = calc(b) ^ calc(a-1);
		System.out.println(ans);
		sc.close();
	}

	private long calc(long x) {

		x++;

		long ans = 0;

		for(int i=0; i<50; i++) {
			long loop = 1L<<(i+1);

			long cnt = (x/loop) * (loop/2);
			cnt += Math.max(0L,  (x%loop) - (loop/2));
			if(cnt % 2 != 0) {
				ans += (1L<<i);
			}
		}

		return ans;
	}


}


Measured memory_bytes: 22996
# AOJ 0008 Sum of 4 Integers

while line = gets
  n = line.to_i
  combinations = 0

  10.times do |a|
    10.times do |b|
      10.times do |c|
        10.times do |d|
          combinations += 1 if (a + b + c + d == n)
        end
      end
    end
  end

  puts combinations
end

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

int h, w, b = 0;
char m[51][51];
int d[50][50];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
typedef pair<int, int> P;

int main()
{
	cin >> h >> w;
	
	for (int i = 0; i < h; i++)
		cin >> m[i];

	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			d[i][j] = 0;
			if(m[i][j] == '#')
				b++;
		}

	queue <P> que;

	que.push(P(0, 0));

	while (que.size()) {
		P p = que.front();
		que.pop();

		if (p.first == h - 1 && p.second == w - 1)
			break;

		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i],
				ny = p.second + dy[i];

			if (nx > -1 && ny > -1 && nx < h && ny < w 
				&& d[nx][ny] == 0 && m[nx][ny] == '.') {
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}

	if (d[h - 1][w - 1] == 0)
		cout << -1 << endl;
	else
		cout << h * w - b - d[h - 1][w - 1]  - 1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
A=list(str(input()))
B=list(str(input()))
C=list(str(input()))
x="A"
while True:
    if x=="A":
        l=A
        pass
    elif x=="B":
        l=B
        pass
    elif x=="C":
        l=C
        pass
    if len(l)==0:
        print(x)
        break
    else:
        x=str.upper(l[0])
        l.remove(l[0])



Measured memory_bytes: 3060
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(long long N, long long K, std::vector<long long> V) {
  ll ans = -INF;
  rep(i, 0, min(K + 1, N + 1)) {
    rep(j, 0, min(K, N) - i + 1) {
      ll k = K - i - j;
      ascendingQueue que;
      rep(t, 0, i) { que.push(V[t]); }
      rep(t, 0, j) { que.push(V[N - t - 1]); }

      while (k > 0 && !que.empty() && que.top() < 0) {
        que.pop();
        k--;
      }

      ll sum = 0;
      while (!que.empty()) {
        sum += que.top();
        que.pop();
      }
      ans = max(sum, ans);
    }
  }
  print(ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> V(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &V[i]);
  }
  solve(N, K, std::move(V));
  return 0;
}


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

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = findSumOfDigits(i); // i の各桁の和
    if (sum >= A && sum <= B) { //  i の各桁の和が A 以上 B 以下かどうか
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
using bll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll N_MAX = 100;
constexpr ll B_I_MAX = 100000;

ll N;
ll B[N_MAX];

void input() {
	scanf("%lld", &N);
	rep(i, N-1) scanf("%lld", B + i);

	ll ans = 0;
	vector<ll> a(N,0);
	a[0]=B[0];
	a[1]=B[0];
	repeq(i,N-2){
		if(a[i]>B[i]){
			a[i]=B[i];
		}
		a[i+1]=B[i];
	}
	debug(a);
	rep(i,N)ans+=a[i];
	printf("%lld\n", ans);
}

signed main() {
	input();

	return 0;
}


Measured memory_bytes: 256
//
//  abc167_SkillUp.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll INF = 1000000007;
#define PI 3.14159265

std::map<int, int> factorization (int n) {
  std::map<int, int> f;
  for (int i = 2; i*i <= n; i++) {
    while (n%i == 0) {
      f[i] += 1;
      n /= i;
    }
  }
  if (n > 1) {
    f[n] += 1;
  }
  return f;
}

ll modpow (int x, int n) {
  if (n==0) return 1%mod;
  ll u = modpow(x, n/2);
  u = (u*u)%mod;
  if (n%2==1) u = (u*x)%mod;
  return u;
}

void dfs(vector<int> A, int n, int m)  {
  if  (A.size() > n) {
    for (int i = 1; i <= n; i++) {
      std::cout << A[i];
    }
    std::cout << std::endl;
    return;
  }
  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A, n, m);
    A.back()++;
  }
}

int main() {
  ll n, m, x;
  std::cin >> n >> m >> x;

  std::vector<int> a[n];
  int prices[n];

  for (int i = 0; i < n; i++) {
    std::cin >> prices[i];
    for (int j = 0; j < m; j++) {
      int level;
      std::cin >> level;
      a[i].push_back(level);
    }
  }

  std::priority_queue<int> q;

  for (int b = 1; b < (int)pow(2, n); b++) {
    int total_level[m];
    for (int j = 0; j < m; j++) {
      total_level[j] = 0;
    }
    int total_price = 0;

    for (int i = 0; i < n; i++) {
      int chosen = (b >> i) & 0x1;
      if (chosen == 0) continue;
      total_price += prices[i];
      for (int j = 0; j < m; j++) {
        total_level[j] += a[i][j];
      }
    }
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (total_level[j] < x) {
        ok = false;
        break;
      }
    }
    if (!ok) continue;
    q.push(-total_price);
  }

  int min = 0;
  if (q.empty()) {
    min = -1;
  }
  else {
    min  = -q.top();
  }
  std::cout << min << std::endl;
  return 0;
}

Measured memory_bytes: 4056
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;
const int MAXM=100000;

int n,m;
int p[MAXN];
int a[MAXM],b[MAXM];

int par[MAXN],sz[MAXN];

int find(int x) { if(par[x]==x) return x; return par[x]=find(par[x]); }
void unite(int a,int b) { a=find(a),b=find(b); if(a==b) return; if(sz[a]<sz[b]) swap(a,b); par[b]=a,sz[a]+=sz[b]; }



void run() {
	scanf("%d%d",&n,&m); REP(i,n) scanf("%d",&p[i]),--p[i]; REP(i,m) scanf("%d%d",&a[i],&b[i]),--a[i],--b[i];

	REP(i,n) par[i]=i,sz[i]=1;
	REP(i,m) unite(a[i],b[i]);

	int ret=0;
	REP(i,n) if(find(i)==find(p[i])) ++ret;
	printf("%d\n",ret);
}

int main() {
	run();
	return 0;
}


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

int n, x;
int a[30];
int dp[1000001];
int prime[1000001];

int main(){
	for(int i=0; i<1000001; i++){
		prime[i] = 1;
	}
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	for(int i=0; i<1000001; i++){
		if(prime[i]==1){
			for(int j=i+i; j<1000001; j+=i){
				prime[j] = 0;
			}
		}
	}


	for(;;){
		cin >> n >> x;
		if(n==0&&x==0) break;
		for(int i=0; i<n; i++){
			cin >> a[i];
		}

		for(int i=0; i<=x; i++){
			dp[i] = 0;
		}
		dp[0] = 1;

		for(int i=0; i<=x; i++){
			for(int j=0; j<n; j++){
				if(i-a[j]>=0){
					if(dp[i-a[j]]==1){
						dp[i] = 1;
					}
				}
			}
		}
		int mx = 0;
		for(int i=0; i<=x; i++){
			if(dp[i]==1 && prime[i]==1) mx = i;
		}

		if(mx==0) cout << "NA" << endl;
		else cout << mx << endl;
	}

	return 0;
}

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

char a[4][100005];
char s[100005];

    bool check(int x, int y, int z, int j){
        bool flag = false;
            if(s[y] == 'o'){
                if(a[j][y] == 'S'){
                    if(a[j][x] == 'S' && a[j][z] == 'S'){
                        flag = true;
                    }else if(a[j][x] == 'W' && a[j][z] == 'W'){
                        flag = true;
                    }
                }else if(a[j][y] == 'W'){
                    if(a[j][x] == 'S' && a[j][z] == 'W'){
                        flag = true;
                    }else if(a[j][x] == 'W' && a[j][z] == 'S'){
                        flag = true;
                    }
                }
            }else if(s[y] == 'x'){
                if(a[j][y] == 'S'){
                    if(a[j][x] == 'S' && a[j][z] == 'W'){
                        flag = true;
                    }else if(a[j][x] == 'W' && a[j][z] == 'S'){
                        flag = true;
                    }
                }else if(a[j][y] == 'W'){
                    if(a[j][x] == 'S' && a[j][z] == 'S'){
                        flag = true;
                    }else if(a[j][x] == 'W' && a[j][z] == 'W'){
                        flag = true;
                    }
                }
            }
            return flag;
    }
    
int main(void){
    long n;
    int cnt = 0;
    bool flag2 = false;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s[i];
    }

    a[0][0] = 'S';
    a[0][1] = 'S';
    
    a[1][0] = 'S';
    a[1][1] = 'W';
    
    a[2][0] = 'W';
    a[2][1] = 'S';
    
    a[3][0] = 'W';
    a[3][1] = 'W';

    for(int j=0;j<4;j++){
        for(int i=2;i<n;i++){
            if(a[j][i-2] == 'S'){
                if(a[j][i-1] == 'S'){
                    if(s[i-1] == 'o'){
                        a[j][i] = 'S';
                    }else if(s[i-1] == 'x'){
                        a[j][i] = 'W';
                    }
                }else if(a[j][i-1] == 'W'){
                    if(s[i-1] == 'o'){
                        a[j][i] = 'W';
                    }else if(s[i-1] == 'x'){
                        a[j][i] = 'S';
                    }
                }
            }else if(a[j][i-2] == 'W'){
                if(a[j][i-1] == 'S'){
                    if(s[i-1] == 'o'){
                        a[j][i] = 'W';
                    }else if(s[i-1] == 'x'){
                        a[j][i] = 'S';
                    }
                }else if(a[j][i-1] == 'W'){
                    if(s[i-1] == 'o'){
                        a[j][i] = 'S';
                    }else if(s[i-1] == 'x'){
                        a[j][i] = 'W';
                    }
                }
            }
        }
            if(check(n-3,n-2,n-1,j) == true && check(n-2,n-1,0,j) == true && check(n-1,0,1,j) == true){
                for(int i=0;i<n;i++){
                    cout << a[j][i];
                }
                cout << endl;
                return 0;
            }
    }
    
    cout << "-1" << endl;
    
    return 0;
}


Measured memory_bytes: 768
var
	n:Smallint;
begin
    read(n);
    if n=0 then begin
        write(0)
    end
    else if n<=1000 then begin
        write(1000-n)
    end
    else if n<=2000 then begin
        write(2000-n)
    end
    else if n<=3000 then begin
        write(3000-n)
    end
    else if n<=4000 then begin
        write(4000-n)
    end
    else if n<=5000 then begin
        write(5000-n)
    end
    else if n<=6000 then begin
        write(6000-n)
    end
    else if n<=7000 then begin
        write(7000-n)
    end
    else if n<=8000 then begin
        write(8000-n)
    end
    else if n<=9000 then begin
        write(9000-n)
    end
    else begin
        write(10000-n)
    end;
end.

Measured memory_bytes: 1324
n = int(input())
sp = [input().split() for i in range(n)]

for i in range(n) :
    sp[i][1] = int(sp[i][1])
    sp[i].append(i+1)

sp.sort()

for i in range(100):
    for j in range(1,n) :
        if sp[j][0] == sp[j-1][0] :
            if sp[j][1] > sp[j-1][1] :
                sp[j-1],sp[j] = sp[j],sp[j-1]

for i in range(n):
    print(sp[i][2])


Measured memory_bytes: 9192
#include<iostream>
#include<cstring>
#define DN 605
#define M1 66013
#define M2 55817
#define pr 173
using namespace std;
int n,s1[DN][DN],s2[DN][DN],p1[DN],p2[DN],r1,r2,t1,t2,rez;
int s3[DN][DN],s4[DN][DN];
char a[DN][DN];
void f1(int &a,int b,int c,int M)
{
    a=(1LL*b*pr+c)%M;
}
int main()
{
    cin>>n;
    for(int i=0;i<=n;i++)
        cin.getline(a[i]+1,DN);
    for(int i=n+1;i<2*n;i++)
        for(int j=1;j<=n;j++)
            a[i][j]=a[i-n][j];
    for(int i=1;i<2*n;i++)
        for(int j=n+1;j<2*n;j++)
            a[i][j]=a[i][j-n];
    for(int i=1;i<2*n;i++)
        for(int j=1;j<2*n;j++)
        {
            f1(s1[i][j],s1[i][j-1],a[i][j]-'a',M1);
            f1(s2[i][j],s2[i][j-1],a[i][j]-'a',M2);
            f1(s3[i][j],s3[i-1][j],a[i][j]-'a',M1);
            f1(s4[i][j],s4[i-1][j],a[i][j]-'a',M2);
        }
    p1[0]=p2[0]=1;
    for(int i=1;i<DN;i++)
    {
        p1[i]=(1LL*p1[i-1]*pr)%M1;
        p2[i]=(1LL*p2[i-1]*pr)%M2;
    }
    for(int i=n;i<2*n;i++)
        for(int j=n;j<2*n;j++)
        {
            r1=r2=0;
            t1=t2=0;
            for(int h=i-n+1;h<=i;h++)
            {
                r1=(1LL*r1*p1[n]+s1[h][j]+M1-(1LL*p1[n]*s1[h][j-n])%M1)%M1;
                r2=(1LL*r2*p2[n]+s2[h][j]+M2-(1LL*p2[n]*s2[h][j-n])%M2)%M2;
            }
            for(int h=j-n+1;h<=j;h++)
            {
                t1=(1LL*t1*p1[n]+s3[i][h]+M1-(1LL*p1[n]*s3[i-n][h])%M1)%M1;
                t2=(1LL*t2*p2[n]+s4[i][h]+M2-(1LL*p2[n]*s4[i-n][h])%M2)%M2;
            }
            if(t1==r1&&t2==r2)
                rez++;
        }
    cout<<rez;
}


Measured memory_bytes: 6272
//OM
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define  x first
#define  y second
#define  pb push_back
#define  mp make_pair
#define  PI (acos(-1.0))
#define  mem(a,b) memset(a,b,sizeof(a))
#define  Sort(x) sort(x.begin(),x.end())
#define  FOR(i, b, e) for(int i = b; i <= (int)(e); i++)
#define  FORR(i, b, e) for(int i = b; i >=(int)(e); i--)
#define  FORI(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define  pr(x) cout<<x<<"\n"
#define  prs(x) cout<<x<<" "
#define  pr2(x,y) cout<<x<<" "<<y<<"\n"
#define  pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define  ppr(a) cout<<a.x<<" "<<a.y<<"\n"

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

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction

#define  EPS 1e-9
#define  MAX 100007

int main()
{
    int T;
    ll n,x;
    scanf("%lld%lld",&n,&x);
    x=max(x,n-x);
    ll sum=0;
    ll node=n-x;
    bool bb=false;
    while(1)
    {
        sum+=x;
       // pr3(x,node,sum);
        if(x%node==0)
        {
            sum+=x*2;
            if(bb)sum-=node;
            break;
        }
        else
        {
            ll path=x-x%node;
            if(bb)sum-=node;
            sum+=path*2;
            ll temp=x%node;
            x=node;
            node=temp;
        }
        bb=true;
      //  pr(sum);
    }
pr(sum);

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll              long long int
#define int             ll
#define ff              first
#define ss              second
#define pb              emplace_back
#define mpair           make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define sbits(x)      __builtin_popcountll(x)
#define zbits(x)      __builtin_popcountlliltin_ctzll(x)
#define w(t)            int t;cin>>t;while(t--)
#define uset            unordered_set
#define forr(i, a, b)   for(int i =int(a);i<=int(b);i++)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
    template <typename Arg1>
     void __f(const char* name,Arg1&& arg1){
        cout<<name<<" : "<<arg1<<std::endl;
     }
     template <typename Arg1, typename... Args>
     void __f(const char* names,Arg1&& arg1,Args&&... args){
        const char* comma = strchr(names+1 ,',');
        cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
     }
#else
#define trace(...)
#endif
/*     
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
double pi = 2.0*acos(0);
void fast(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed<<setprecision(10);}
int max2(int a,int b){ if(a>b) return a;return b;}
int min2(int a,int b){ if(a<b)return a;return b;}
int max3(int a,int b,int c){ return max2(a,max2(b,c));}
int min3(int a,int b,int c){ return min2(a,min2(b,c));}

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


void solve(){
    int n,m,x;
    cin>>n>>m>>x;
	int cost[n];
	int v[n][m];
	for(int  i =0;i<n;i++)
	{
		cin>>cost[i];
		for(int  j =0;j<m;j++)
		cin>>v[i][j];
	}
	
	int lim =(1<<n) -1;
	int min_cost = 1e18;
	for(int  i =0;i<=lim;i++)
	{
		bitset<13>b(i);
		int cum[m]={0};int tot = 0;
		for(int  j= 0;j<n;j++)
		{
			if(b[n-1-j]){
				tot+=cost[j];
			for(int k =0;k<m;k++)
			 cum[k]+=v[j][k];
			}
		}
		bool chk = true;
		
		for(int  j =0;j<m;j++)
		{
			 if(cum[j]<x){
			 chk = false;break;
			 }
		}
		
		if(chk && tot< min_cost)
		 min_cost = tot;
		
	}
	
	if(min_cost== 1e18)
	cout<<-1<<endl;
	else
	cout<<min_cost<<endl;
	
	
 }


signed main(void)
{
      fast();
     // w(t)
      solve();

}


Measured memory_bytes: 3660
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<ctype.h>
#include<math.h>
#include<map>
using namespace std;
int main() 
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int count=0;
		int i,j,k,l;
		for(i=0;i<=9;i++)
			for(j=0;j<=9;j++)
				for(k=0;k<=9;k++)
					for(l=0;l<=9;l++)
						if(i+j+k+l==n)
							count++;
		printf("%d\n",count);
	}
	return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>
 
int main(){
  int H,W,i,j;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0){
      break;
    }
    for(i=0; i<H; i++){
      for(j=0; j<W; j++){
        if((i%2==0&&j%2==0)||(i%2==1&&j%2==1))
        printf("#");
        else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	string a,b,c; cin >> a >> b >> c;
	const int X = 4010;
	V<bool> ab,bc,ac;
	auto Get = [&](string a,string b){
		V<bool> ab(X+X+1);
		for(int i=-X;i<=X;i++){
			ab[i+X] = true;
			rep(j,a.size()){
				int k = j+i;
				if(0<=k&&k<si(b)&&a[j]!='?'&&b[k]!='?'&&a[j]!=b[k]) ab[i+X] = false;
			}
		}
		return ab;
	};

	ab = Get(b,a);
	bc = Get(c,b);
	ac = Get(c,a);
	int ans = 1e9;
	for(int i=-X;i<=X;i++) if(ab[i+X]){
		for(int j=-X;j<=X;j++) if(bc[j+X]){
			int k = i+j;
			if(-X<=k&&k<=X&&ac[k+X]){
				int mn = min({0,i,k}), mx = max({si(a),i+si(b),k+si(c)});
				chmin(ans,mx-mn);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]

s1 = list(set(s))
a = [0 for i in range(101)]
for i in range (len(s1)):
    for j in range (N):
        if s1[i] == s[j]:
            a[i]+=1
for i in range (len(s1)):
    for j in range (M):
        if s1[i] == t[j]:
            a[i]-=1
print(max(a))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 1e4;
const ll inf = 1e9+7;


int main() {
	fastio;
	ll x;
	cin>>x;
	if(x>=30) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

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

int main()
{
    ll a, b, m;
    ll min = 100000000, remin = 10000000, mamin = 10000000;
    cin >> a >> b >> m;
    vector<ll> re(a), ma(b);
    ll l, c, n;
    for (ll i = 0; i < a; i++)
    {
        cin >> re[i];
        if (re[i] < remin)
        {
            remin = re[i];
        }
    }
    for (ll i = 0; i < b; i++)
    {
        cin >> ma[i];
        if (ma[i] < mamin)
        {
            mamin = ma[i];
        }
    }
    min = mamin + remin;
    for (ll i = 0; i < m; i++)
    {
        cin >> l >> c >> n;
        ll temp;
        temp = re[l - 1] + ma[c - 1] - n;
        if (min > temp)
        {
            min = temp;
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 1792
N,K=map(int,input().split())

import string
numbers = "0123456789"
alphabets = string.ascii_letters # a-z+A-Zをロード
characters = numbers + alphabets
 
def base_cvt(value, n=2):
    try:
        tmp = int(value)
    except:
        raise ValueError('Invalid value:', value)
 
    if n < 2 or n > len(characters):
        raise ValueError('Invalid n:', value)
 
    result = ''
    tmp = int(value)
    while tmp >= n:
        idx = tmp%n
        result = characters[idx] + result
        tmp = int(tmp / n)
    idx = tmp%n
    result = characters[idx] + result
    return result

print(len(base_cvt(N,K)))

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

int n;
int MAXIMUM=10000;
int INF = 123456789;
// W:未訪問
// G:訪問する候補
// B:訪問済み
int W=0,G=1,B=2;
vector<pair<int,int>> adj[10000];

int dijkstra(){
  priority_queue<pair<int,int>> PQ;
  int u,minv;
  int d[MAXIMUM],color[MAXIMUM];
  // d[n]:Tに属する頂点と V - T に属する頂点をつなぐ辺の中で重みが最小の辺の重みを記録

  //初期化
  for(int i=0;i<n;i++){
    d[i]=INF;
    color[i]=W;
  }

  d[0]=0;
  PQ.push(make_pair(0,0));
  color[0] = G;

  while (!PQ.empty()) {
    pair<int,int> f = PQ.top();
    PQ.pop();
    u = f.second;
    // 頂点を訪問済に
    color[u] = B;
    //最小値を取り出し、それが最短でなければ無視
    if( d[u]<f.first*(-1)) continue;

    //訪問済みでないかつ辺がつながっている頂点の中でコストが最小の辺を選択
    for(int j=0;j<adj[u].size();j++){
      int v = adj[u][j].first;
      if(color[v]== B) continue;
      if(d[v]>d[u]+adj[u][j].second){
        d[v]=d[u]+adj[u][j].second;
        PQ.push(make_pair(d[v]*(-1),v));
        color[v]=G;
      }
    }
  }

  for(int i=0;i<n;i++){
    if(d[i]!=INF) cout<<i<<" "<<d[i]<<endl;
    else cout<<i<<" "<<-1<<endl;
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      adj[u].push_back(make_pair(v,c));
    }
  }

  dijkstra();

}



Measured memory_bytes: 8088
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
int main() {
    string s;
    cin >> s;
    size_t n = s.size();
    int make = 0;
    for (int i = 0; i < n; i++) {
        if (s.at(i) == 'x') {
            make++;
        }
    }

    if (make < 8) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }


}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <string.h>
using namespace std;
// std::ios::sync_with_stdio(false);
typedef long long LL;
const int N = 150000;
const int M = 12;
const int INF = 0x3f3f3f3f;
const LL MOD = 1e9+7;
const double Pi = acos(-1);
int n,m;
int s[N];
int x;
int main()
{
    while (~scanf("%d",&n))
    {
        int a=0,b=0;//O,E
        int tmp = 1;
        for (int i=0;i<n;i++)
        {
            scanf("%d",&x);
            if (x%2)
                tmp *= 1;
            else
                tmp *= 2;
        }
        int ans = 1;
        for (int i=0;i<n;i++)
            ans *= 3;
        ans -= tmp;
        printf("%d\n", ans);
    }
    return 0;
}

/*


*/

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{

  int x, y;
  cin >> x >> y;

  int n, m;

  if (y % 2 != 0)
  {
    cout << "No" << endl;
  }
  else
  {
    n = -y / 2 + 2 * x;
    m = y / 2 - x;
    if (m < 0 || n < 0)
    {
      cout << "No" << endl;
    }
    else
    {
      cout << "Yes" << endl;
    }
  }

  return 0;
}

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

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

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

    int res = min(min(a, n - a + 1), min(b, n - b + 1));
    if (res % 3 == 0) res = 3;
    else res %= 3;

    cout << res << endl;
  }
}

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


int main() {
   long long int X;
   cin>>X;
   long long int count=0;
   while(X!=0){
   	X=X/2;
   	count++;
   }
   long long int ans=1;
   for(int i=0;i<count;i++)ans=ans*2;
   
   cout<<ans-1<<endl;
   
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using std::cin;
using std::cout ;
int main()
{
	int n,temp,min,moto,i;
	cin>>n>>moto;
	min=moto;
	for(i=0;i<n;i++)
	{
		cin>>temp;
		moto-=temp;
		if(temp<min)
			min=temp;
	}
	cout<<moto/min+n;
	return 0;
}	


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

int main() {
	for(int i = 1; i <= 10000; ++i) {
		int x;
		cin >> x;
		if(x == 0) {
			break;
		} else if((1 <= x) && (x <= 10000)) {
			cout << "Case " << i << ": " << x << endl;
		}
	}
}

Measured memory_bytes: 3028
N = int(input())
H = list(map(int,input().split()))

ans = 0

cnt = 0

for i in range(N-1) :
    if H[i] >= H[i+1] :
        cnt += 1
    else :
        ans = max(ans, cnt)
        cnt = 0

ans = max(ans,cnt)

print(ans)


Measured memory_bytes: 63984