akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

using ld= long double;

struct dice {
	vector<pair<int,ld>>mp;
	ld score() {
		ld sum=0;
		ld per=0;
		for (auto m : mp) {
			sum+=m.first*m.second;
			per+=m.second;
		}
		return sum/per;
	}
};

int main() {
	int T;cin>>T;
	vector<dice>my_dices;
	for (int i = 0; i < T; ++i) {
		dice di;
		int N,M;cin>>N>>M;
		for (int i = 0; i < M; ++i) {
			int v;ld r;cin>>v>>r;
			di.mp.emplace_back(v,r);
		}
		my_dices.push_back(di);
	}
	dice op_dice;
	{
		dice di;
		int N, M; cin >> N >> M;
		for (int i = 0; i < M; ++i) {
			int v; ld r; cin >> v >> r;
			di.mp.emplace_back(v, r);
		}
		op_dice=di;
	}
	bool ok=false;
	for (auto md : my_dices) {
		if (md.score() > op_dice.score() + 0.0000001) {
			ok=true;
		}
	}
	if (ok) {
		cout<<"YES"<<endl;
	}
	else {
		cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3260
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs             v.size()
#define ss             s.size()
#define sot(v)       sort(v.begin(),v.end())
#define rev(v)       reverse(v.begin(),v.end())
#define pii             pair<int,int>
#define ll               long long
#define ull             unsigned long long
#define pb             push_back
#define mpp          make_pair
#define Okay         0


static ll int inf = 1e18;
using namespace std;
void solve(){
    int n;
    cin>>n;
   ll int ar[n+5];
    for(int i = 0; i<n; i++){
        cin>>ar[i];
    }
    ll int ans = 1000;
    for(int i=1; i<n; i++){
        if(ar[i-1] < ar[i]){
            ans = (ans/ar[i-1])*ar[i] + (ans%ar[i-1]);
        }
    }
    cout<<ans<<endl;
}


int main(){

    Fast;
    solve();

    return Okay ;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>

using namespace std;

int binary_search_left(vector<int> &vec, long long left, long long right){
    if(right-left<2){
        return right;
    }
    long long mid=(left+right)/2;
    for(int i=0; i<vec.size(); i++){
        mid-=mid%vec[i];
    }
    if(mid==2){
        return binary_search_left(vec, left, mid);
    }else{
        return binary_search_left(vec, mid, right);
    }
}

int binary_search_right(vector<int> &vec, long long left, long long right){
    if(right-left<2){
        return left;
    }
    long long mid=(left+right)/2;
    for(int i=0; i<vec.size(); i++){
        mid-=mid%vec[i];
    }
    if(mid==2){
        return binary_search_right(vec, mid, right);
    }else{
        return binary_search_right(vec, left, mid);
    }
}

int main(){
    int K;
    cin >> K;
    vector<int> A(K);
    for(int i=0; i<K; i++){
        cin >> A[i];
    }

    long long max_=3;
    long long min_=2;
    if(A[K-1]!=2){
        max_=0;
    }
    for(int i=K-2; i>=0; i--){
        min_=(min_/A[i]+(min_%A[i]>0))*A[i];
        max_=(max_/A[i]+1)*A[i]-1;
    }
    if(min_>max_){
        cout << -1 << endl;
    }else{
        cout << min_ << ' ' << max_ << endl;
    }

}

Measured memory_bytes: 640
program main
    implicit none
    integer(8) N, M, i, sum
    integer(8), allocatable :: A(:)
    read *, N, M
    sum = 0
    allocate(A(M))
    read *, A
    do i = 1, M
        sum = sum + A(i)
    end do
    if (sum > N) then
        print *, -1
    else
        print '(I0)', N - sum
    end if
    deallocate(A)
    stop
contains

end program main

Measured memory_bytes: 2928
N,D = map(int,input().split())

from itertools import combinations
from fractions import math

points=[]
for i in range(N):
    points.append([list(map(int,input().split()))])

c = list(combinations(points,2))

cnt = 0

for combi in c:
    distance = 0

    for j in range(D):
        X=combi[0][0]
        Y=combi[1][0]
        distance += ( X[j] - Y[j])**2

    distance = math.sqrt(distance)

    if distance.is_integer():
        cnt+=1

print(cnt)

Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
#define MP make_pair
#define pb push_back
#define read2(a, b) (read(a), read(b))
#define read3(a, b, c) (read(a), read(b), read(c))
#define lop(i,a,b) for(register int i = (a); i <= (b); ++i)
#define dlop(i,a,b) for(register int i = (a); i >= (b); --i)
#define eps (1e-7)
#define fir first
#define sec second

const int inf = 0x3f3f3f3f-1;
const int MAXN = 1e6+7;
typedef long long LL;
typedef long double LF;
typedef pair<int,int> pii;
typedef unsigned long long ULL;
typedef unsigned int uint;
template<class T> void read(T & x) {
  register int c = getchar(), f = 1; x = 0;
  while(!isdigit(c)) {if (c == '-') f = -f; c = getchar();}
  while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= f;
}
LL n, m, a, b, c, d, l, o;

int main(void) {
  #ifdef LOCAL_DEBUG
  freopen("data.in", "r", stdin);
  #endif
  read3(a, b, c); read2(n, m);
  if (c*2 > a+b) {
  	cout << a*n+b*m;
  }
  else {
  	int cn1 = min(n, m);
  	int nn = n, mm = m;
  	n -= cn1, m -= cn1;
  	LL ans = cn1*2*c+n*a+m*b;
  	ans = min(ans, max(nn, mm)*2*c);
  	cout << ans;
  }
  return 0;
}

Measured memory_bytes: 256
(defun solve (n ma mb a b c)
  (let ((dp (make-array '(41 405 405) :initial-element 5000)) ans)
    (setf (aref dp 0 0 0) 0)
    (dotimes (i n) (dotimes (x 401) (dotimes (y 401)
       (when (< (aref dp i x y) 5000)
         (setf (aref dp (1+ i) x y)
               (min (aref dp i x y) (aref dp (1+ i) x y)))
         (setf (aref dp (1+ i) (+ x (aref a i)) (+ y (aref b i)))
               (min (aref dp (1+ i) (+ x (aref a i)) (+ y (aref b i)))
                    (+ (aref dp i x y) (aref c i))))))))
    (setf ans 5000)
    (loop for x from 1 to 400
          do (loop for y from 1 to 400
                       when (= (* x mb) (* y ma))
                       do (setq ans (min ans (aref dp n x y)))))
    ans))

(let* ((n (read)) (ma (read)) (mb (read))
      (a (make-array n))
      (b (make-array n))
      (c (make-array n))
      e)
  (loop for i below n 
        do (progn (setf (aref a i) (read))
                  (setf (aref b i) (read))
                  (setf (aref c i) (read))))
  (setq e (solve n ma mb a b c))
  (if (= e 5000)
    (princ "-1")
    (princ e)))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))
template<typename T> inline bool __max__(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool __min__(T &x, const T &y) { return x > y ? x = y, 1 : 0; }

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

bool comp(const pair<long, long> &a, const pair<long, long> &b) {
    return a.second < b.second;
}

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    long n, k;

    cin >> n >> k;

    map<long, long> table;
    vector<pair<long, long> > v;
    long a;
    long ans = 0;

    long i, len;

    for (i = 0; i < n; i++) {
        cin >> a;

        table[a]++;
    }

    for (auto t : table) v.pb(t);

    sort(v.begin(), v.end(), comp);

    if (k < v.size()) {
        len = v.size();
        i = 0;

        while (k < len) {
            ans += v[i++].second;

            len--;
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 18800
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let A: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    const L: usize = 60;
    let mut B = (0..L).rev().map(
        |i| A.iter().map(|&a| (a >> i) & 1).collect::<Vec<_>>()
    ).collect::<Vec<_>>();
    let mut C = vec![1; L];
    let one_cnts = B.iter().map(|b| b.iter().filter(|&&x| x == 1).count()).collect::<Vec<_>>();

    let mut res = 0;
    for i in 0..L {
        if one_cnts[i] > 0 {
            if one_cnts[i] % 2 == 1 { res += 1i64 << (L - 1 - i); }
            else {
                if B[i].iter().any(|&b| b == 1) || C[i] == 0 { res += 1i64 << (L - i); }
                if let Some(k) = (0..N).find(|&k| B[i][k] == 1) {
                    for j in (i + 1)..L {
                        if B[j][k] == 1 {
                            for l in 0..N { B[j][l] ^= B[i][l]; }
                            C[j] ^= C[i];
                        }
                    }
                }
            }
        }
    }
    let ans = res;

    println!("{}", ans);
}



Measured memory_bytes: 67060
n, k = map(int, input().split())
p = list(map(int, input().split(" ")))
for i in range(n):
    p[i] -= 1
c = list(map(int, input().split(" ")))
ans = -10000000000
for start in range(n):
    now = start
    pt = 0
    cycle = 0
    looplen = 0

    while 1:
        now = p[now]
        pt += c[now]
        looplen += 1
        if now == start:
            break

    cycle = pt
    pt = 0
    for i in range(looplen):
        now = p[now]
        pt += c[now]
        aftermove = k - i-1
        if aftermove < 0:
            continue

        loop = aftermove//looplen
        ans = max(ans, pt)
        ans = max(ans, pt+loop*cycle)
print(ans)


Measured memory_bytes: 74228
#include <stdio.h>
void sort(int data[],int n);
int main(void){
    
    int i,n,k,l[50],s=0;

    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&l[i]);
    }
    
    sort(l,n);
    for(i=0;i<k;i++){
        s=s+l[i];
    }
    
    printf("%d\n",s);
    
}
void sort(int data[],int n){
        
    int i,j,tmp;
        
    for(i=1;i<n;i++){
    for(j=n-1;j>=1;j--){
        if(data[j]>data[j-1]){
            tmp=data[j-1];
            data[j-1]=data[j];
            data[j]=tmp;
            }
        }
    }
    
}

Measured memory_bytes: 1704
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
  string S1, S2, S3;
  cin >> S1 >> S2 >> S3;
  cout << (char)(S1[0] - 'a' + 'A') << (char)(S2[0] - 'a' + 'A') << (char)(S3[0] - 'a' + 'A') << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int N, K;
int gcd(int a, int b) {
  while(b) {
    int tmp = a % b;
    a = b;
    b = tmp;
  }
  return a;
}
int main () {
  ios::sync_with_stdio(false);
  cin >> N >> K;
  for(int i = 0; i < N; ++i) cin >> a[i];
  sort(a, a + N);
 
  int com = a[0];
  for(int i = 0; i < N - 1; ++i) {
    int cc = gcd(a[i], a[i + 1]);
    com = gcd(cc, com);
    if (com == 1) break;
  }
 
  if (com == 1 && a[N - 1] >= K) {
    cout << "POSSIBLE" << endl;
    return 0;
  }
 
  for(int i = 0; i < N; ++i) {
    if (a[i] >= K && ((a[i] - K) % com) == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
 
  cout << "IMPOSSIBLE" << endl;
 
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		List<Long> list = new ArrayList<>();
		for(long i=1; i<=9; i++) list.add(i);
		List<Long> tmp = new ArrayList<>(list);
		while(true){
			if(k <= list.size()){
				System.out.println(list.get(k-1));
				break;
			}
			k -= list.size();
			list.clear();
			for(Long i: tmp){
				for(int j= -1; j<=1; j++){
					long d = i%10 + j;
					if(d<0 || d>9) continue;
					list.add(i*10+d);
				}
			}
			tmp = new ArrayList<>(list);

		}
	}
}


Measured memory_bytes: 30804
import numpy as np
import heapq

n, m = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

x = sorted(x)
x = np.diff(x)
#print(x)

if n >= m:
    print(0)

elif n == 1:
    print(sum(x))

else:
    print(sum(heapq.nsmallest(len(x)-n+1, x)))


Measured memory_bytes: 23972
#include<bits/stdc++.h>
using namespace std;
#define int long long 

main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int k,x;
    cin>>k>>x;

    for(int i=max(-1000000ll,x-k+1);i<=min(x+k-1,1000000ll);i++){
        cout<<i<<" ";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vvi g(n, vi());
    int a, b;
    vector<pair<int, int>> v(n - 1);
    map<pair<int, int>, int> m;
    REP(i, n - 1) {
        cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);
        g[a].emplace_back(b);
        g[b].emplace_back(a);
        v[i] = make_pair(a, b);
    }

    function<void(int, int)> dfs = [&](int c, int p) {
        if (p != -1 and sz(g[c]) == 1) return;
        int x = c;
        int y = p;
        if (x > y) swap(x, y);
        int used = (p != -1 ? m[make_pair(x, y)] : 0);
        int z = 1;
        for (auto q : g[c]) {
            if (q == p) continue;
            int u = c;
            int v = q;
            if (u > v) swap(u, v);
            if (z == used) z++;
            m[make_pair(u, v)] = z;
            z++;
            dfs(q, c);
        }

    };

    dfs(0, -1);
    int ans = 0;
    for (auto q : m) chmax(ans, q.second);
    cout << ans << endl;
    REP(i, n - 1) {
        cout << m[v[i]] << endl;
    }
}


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

long long mod = 1000000007LL;

int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	long long a, b;
	cin >> a >> b;
	long long x = a/b;
	if(a % b != 0) x++;
	cout << x;
}


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

void listen(char str[],int size);
void listenSize(int *X,int *Y);
void listenCourse(int **course,int X,int Y);
void analyzeCourse(int **course,int X,int Y);

int SkiResort();

int main()
{
	while(SkiResort());
	return 0;
}

int SkiResort()
{
	int X,Y;
	listenSize(&X,&Y);
	if(X==0 && Y==0)
	{
		return 0;
	}
	int course[X][Y];
	int *pCourse[X];
	int i;
	for(i=0;i<X;i++)
	{
		pCourse[i]=course[i];
	}
	listenCourse(pCourse,X,Y);
	analyzeCourse(pCourse,X,Y);
	
	return 1;
}

void listen(char str[],int size)
{
	for(;1;)
	{
		fgets(str,size,stdin);
		if(strcmp(str,"\n")!=0)
		{
			break;
		}
	}
}

void listenSize(int *X,int *Y)
{
	char str[64];
	listen(str,sizeof(str));
	
	*X=atoi(strtok(str," "));
	*Y=atoi(strtok(NULL," "));
}
	

void listenCourse(int **course,int X,int Y)
{
	char str[1024];
	int i,j;
	for(j=0;j<Y;j++)
	{
		listen(str,sizeof(str));
		course[0][j]=atoi(strtok(str," "));
		for(i=1;i<X;i++)
		{
			course[i][j]=atoi(strtok(NULL," "));
		}
	}
}

void analyzeCourse(int **course,int X,int Y)
{
	int i,j,k,m;
	int pattern[X][Y+2];
	for(i=0;i<X;i++)
	{
		for(j=0;j<Y+2;j++)
		{
			pattern[i][j]=0;
		}
	}
	
	for(i=0;i<X;i++)
	{
		if(course[i][0]==0)
		{
			pattern[i][0]=1;
		}
	}
	for(j=0;j<Y-1;j++)
	{
		for(i=0;i<X;i++)
		{
			for(k=i-1;k<=i+1;k++)
			{
				if(k<0 || X<=k)
				{
					continue;
				}
				switch(course[k][j+1])
				{
				  case 0:
					pattern[k][j+1]+=pattern[i][j];
					break;
				  case 1:
					pattern[k][j+1]=0;
					break;
				  default:
					if(k==i)
					{
						m=0;
						while(j+3+m<Y)
						{
							if(course[k][j+3+m]==2)
							{
								m+=2;
							}
							else
							{
								break;
							}
						}
						pattern[k][j+3+m]+=pattern[i][j];
					}
				}
			}
		}
	}
	int sum=0;
	for(i=0;i<X;i++)
	{
		for(k=Y-1;k<=Y+1;k++)
		{
			sum+=pattern[i][k];
		}
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 532
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define tc(t)  int t; cin>>t; while(t--)
#define f(n)    for(int i=1;i<=n;i++)
#define endl   "\n"







int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
    cin>>a>>b;
    int count=0;
    for(int i=0;i<3;i++)
    {
        if(a[i]==b[i]) count++;
        
    }
    cout<<count<<endl;



}

Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n;
int matrix[10][10];

int main() {
  while (scanf("%d", &n) > 0) {
    REP(y, n) {
      REP(x, n) {
        scanf("%d", &matrix[y][x]);
      }
    }
    set<vector<int> > visit;
    map<vector<int>, int> dist;
    priority_queue<pair<ll, vector<int> > > que;
    {
      vector<int> ini;
      REP(i, n) { ini.push_back(i); }
      que.push(make_pair(0, ini));
    }
    ll ans = 0;
    while (!que.empty()) {
      vector<int> perm = que.top().second;
      ll cost = -que.top().first;
      que.pop();
      if (visit.count(perm)) { continue; }
      visit.insert(perm);
      ans = max(ans, cost);
      REP(i, n) REP(j, i) {
        vector<int> nperm = perm;
        swap(nperm[i], nperm[j]);
        int ncost = cost + matrix[i][j];
        if (dist.count(nperm) && ncost >= dist[nperm]) { continue; }
        dist[nperm] = ncost;
        que.push(make_pair(-ncost, nperm));
      }
    }
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 9288
#include<iostream>

using namespace std;

int S[4010];
int T[4010];
int dp[4010][4010];
const int MOD = 1000000007;

int main()
{
    int n, m;

    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>S[i];
    for(int i=1;i<=m;i++)
        cin>>T[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1])%MOD;
            if(S[i] == T[j])
                dp[i][j] = (dp[i][j] + dp[i-1][j-1] + 1)%MOD;
            if(dp[i][j] < 0)
                dp[i][j] = dp[i][j] + MOD;
        }
    }
    int ans = (dp[n][m] + 1)%MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 32512
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> d(n, 0);
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        d[a]++; d[b]++;
    }
    rep(i, 0, n){
        cout << d[i] << endl;
    }
}

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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	ll n, k, r, s, p;
	string t;
	cin >> n >> k >> r >> s >> p >> t;
	ll ans = 0;
	vi v;
	REP(i, 0, k){
		if(t[i] == 's') v.PB(r);
		else if(t[i] == 'r') v.PB(p);
		else v.PB(s);
	}
	REP(i, k, n){
		if(t[i] == t[i-k] && v[i-k] > 0) v.PB(0);
		else{
			if(t[i] == 's') v.PB(r);
			else if(t[i] == 'r') v.PB(p);
			else v.PB(s);
		}
	}
	
	REP(i, 0, n) ans += v[i];
	cout<< ans;

}


Measured memory_bytes: 1020
//package com.zhangyong.algorithm;

import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {

    FastScanner in;
    PrintWriter out;

    class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        private FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        private FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

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

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

    }

    class cmp implements Comparator<String> {

        @Override
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    }

    private void solve() {

        int n, l;
        n = in.nextInt();
        l = in.nextInt();
        String[] str = new String[n];
        for (int i = 0; i < str.length; i++) {
            str[i] = in.next();
        }
        Arrays.sort(str, new cmp());
        for (int i = 0; i < str.length; i++) {
            out.print(str[i]);
        }
    }

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

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


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

vector<long long> runrun;

void search(long long x, long long d){
    if(d > 10) return ;
    long long a = x/pow(10,d-1);
    if(a == 9){
        search(x+(a-1)*pow(10,d),d+1);
        runrun.push_back(x+(a-1)*pow(10,d));
        search(x+a*pow(10,d),d+1);
        runrun.push_back(x+a*pow(10,d));
    }
    else if(a >= 2){
        search(x+(a-1)*pow(10,d),d+1);
        runrun.push_back(x+(a-1)*pow(10,d));
        search(x+a*pow(10,d),d+1);
        runrun.push_back(x+a*pow(10,d));
        search(x+(a+1)*pow(10,d),d+1);
        runrun.push_back(x+(a+1)*pow(10,d));
    }
    else if(a==1){
        search(x+(a-1)*pow(10,d),d+1);
        search(x+a*pow(10,d),d+1);
        runrun.push_back(x+a*pow(10,d));
        search(x+(a+1)*pow(10,d),d+1);
        runrun.push_back(x+(a+1)*pow(10,d));
    }
    else{
        search(x+a*pow(10,d),d+1);
        search(x+(a+1)*pow(10,d),d+1);
        runrun.push_back(x+(a+1)*pow(10,d));
    }
}

int main(){
    int k;
    cin >> k;
    for(long long i=0ll; i<=9ll; i++){
        search(i,1ll);
        if(i!=0)runrun.push_back(i);
    }
    sort(runrun.begin(),runrun.end());
    cout << runrun[k-1] << endl;;
    return 0;
}


Measured memory_bytes: 10604
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define boost ios_base::sync_with_stdio(0);cin.tie(0)
const int inf=1e18;

int mod(int n,int k)
{
    n%=k;
    n+=k;
    return n%k;
}


int32_t main()
{
    boost;
    
    int n,k,ans=0;
    cin>>n>>k;
    int a[n+1],pre[n+1]={0};
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]=mod(a[i],k);
        pre[i]=mod(pre[i-1]+a[i],k);
    }

    for(int i=1;i<=n;i++){
        pre[i]=mod(pre[i]-i,k);
        //cout<<pre[i]<<" ";
    }
    //cout<<endl;
    map<int,int>mp;
    mp[0]=1;
    for(int i=1;i<=n;i++)
    {
        if(i>=k)
            mp[pre[i-k]]--;
        ans+=mp[pre[i]];
        mp[pre[i]]++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 15872
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();

    int n;
    cin >> n;
    
    for (int i = 1; i <= 9; ++ i) {
    	for (int j = 1; j <= 9; ++ j) {
    		if (i * j == n) {
    			return cout << "Yes\n", 0;
    		}
    	}
    }
    
    cout << "No\n";
    
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;

const ll INF = numeric_limits<ll>::max(),
         MOD = 1e9 + 7;

const int INF_i = numeric_limits<int>::max(),
          MAX = 1e6;

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);

    int n;
    cin >> n;

    vii dp(3);
    for (int i = 0; i < n; i++) {
        vii dp_(3);
        cin >> dp_[0] >> dp_[1] >> dp_[2];
        dp_[0] += max(dp[1], dp[2]);
        dp_[1] += max(dp[0], dp[2]);
        dp_[2] += max(dp[1], dp[0]);
        swap(dp, dp_);
    }
    cout << *max_element(dp.begin(), dp.end());
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N;
  cin >> N;

  vvi G(N);
  i64 a, b;
  map<pair<i64,i64>,i64> mp;
  rep(i, N-1){
    cin >> a >> b;
    a--;
    b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    mp[make_pair(a,b)] = i;
  }

  vi c(N,-1);
  c[0] = 0;

  i64 K = 0;
  vi ans(N-1,-1);

  queue<i64> que;
  que.push(0);
  while(!que.empty()){
    i64 cur = que.front();
    que.pop();
    i64 i = 1;
    for(auto &p : G[cur]){
      if(c[p]!=-1) continue;
      if(c[cur] ==i) i++;
      c[p] = i;
      ans[mp[make_pair(cur,p)]] = i;
      chmax(K,i);
      que.push(p);
      i++;
    }
  }

  cout << K << "\n";
  for(auto &p : ans) cout << p << "\n";



}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 14464
#include<stdio.h>
#include<string.h>

int main(void){
	int w,h,n,i,j,k,f[128][128]={0},x,y,a,r=0;
	scanf("%d%d%d",&w,&h,&n);
	for(i = 1;i <= n;i++){
		scanf("%d%d%d",&x,&y,&a);
		if(a == 1){
			for(j = 0;j < w;j++){
				for(k = 0;k < h;k++){if(j < x){f[j][k]++;}}
			}
		}
		if(a == 2){
			for(j = 0;j < w;j++){
				for(k = 0;k < h;k++){if(x <= j){f[j][k]++;}}
			}
		}
		if(a == 3){
			for(j = 0;j < w;j++){
				for(k = 0;k < h;k++){if(k < y){f[j][k]++;}}
			}
		}
		if(a == 4){
			for(j = 0;j < w;j++){
				for(k = 0;k < h;k++){if(y <= k){f[j][k]++;}}
			}
		}
	}
	for(j = 0;j < w;j++){
		for(k = 0;k < h;k++){if(f[j][k] == 0){r++;}}
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 256
m=10**9+7
n=int(input())
f=1
i=s=r=0
d=[]
for i in range(n):
 f=f*(i+1)%m
 s=(s+pow(i+1,m-2,m))%m
 d.append(s)
a=input().split()
for i in range(n):
 r=(r+int(a[i])*f*(d[i]+d[~i]-1))%m
print(r)

Measured memory_bytes: 15472
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  
  ll ans = -1 * INF * INF * 2;
  ans = a*c > ans ? a*c : ans;
  ans = a*d > ans ? a*d : ans;
  ans = b*c > ans ? b*c : ans;
  ans = b*d > ans ? b*d : ans;
  
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 1002;
ll a[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	vector<int> v[2];
	ll s[2];
	s[0]=0,s[1]=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i] > 0)
		{
			v[i%2].pb(i);
			s[i%2] += a[i];
		}
	}
	if(sz(v[0])+sz(v[1])==0)
	{
		int id = 1;
		for(int i=1;i<=n;i++)
		{
			if(a[i]>a[id])
			{
				id = i;
			}
		}
		cout<<a[id]<<"\n";
		cout<<n-1<<"\n";
		for(int i=n;i>id;i--)
			cout<<i<<"\n";
		for(int i=1;i<id;i++)
			cout<<1<<"\n";
		return 0;
	}
	int id = 0;
	if(s[1] > s[0])
		id = 1;
	cout<<s[id]<<"\n";
	vector<int> res;
	for(int i=n;i>v[id][sz(v[id])-1];i--)
		res.pb(i);
	for(int i=1;i<v[id][0];i++)
		res.pb(1);
	for(int i=1;i<sz(v[id]);i++)
	{
		int d = v[id][i]-v[id][i-1]-1;
		while(d>1)
		{
			res.pb(3);
			d-=2;
		}
		res.pb(2);
	}
	cout<<sz(res)<<"\n";
	for(auto u:res)
		cout<<u<<"\n";
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define reps(i, s, n) for(int i = (int)s; i < (int)n; i++)
#define in(i) std::cin >> i;
#define print(i) std::cout << i;
#define println(i) std::cout << i << std::endl;

int main() {
    long X, amount;
    in(X);
    int cnt = 0;
    amount = 100;
    for(;;) {
        if(amount >= X)
            break;
        amount += (amount / 100);
        cnt++;
    }
    std::cout << cnt;
    return 0;
}

Measured memory_bytes: 3196
package main

import "fmt"

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)
	count := 0
	for i := 0; i < N; i++ {
		var h int
		fmt.Scanf("%d", &h)
		if h >= K {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, sum=0;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		sum+=v[i];
	}
	int res=sum, current=0;
	for(int i=0;i<n;i++){
		current+=v[i];
		sum-=v[i];
		res=min(res,abs(sum-current));
	}
	cout<<res;
}

Measured memory_bytes: 256
L = int(input())
N = L.bit_length()

node = [i for i in range(1, N + 1)]
edge = []

for x, y in zip(node[:-1], node[1:]):
    edge.append((x, y, 0))

x = 1
while L > 1:
    if L & 1:
        L -= 1
        edge.append((x, N, L))
    else:
        L //= 2
        edge.append((x, x + 1, L))
        x += 1

print(N, len(edge))
for e in edge:
    print(*e)

Measured memory_bytes: 3064
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int h, n, a;
	cin >> h >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		h -= a;
	}
	cout << (h <= 0 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int N, K;
	string S;
	cin >> N >> S >> K;
	for (int i = 0; i < S.size(); i++){
		if (S[i] != S[K-1]){
			S[i] = '*';
		}
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x;
    cin >> x;
    if(400<=x&&x<600) cout <<"8";
    else if (x<800) cout <<"7";
    else if (x<1000) cout <<"6";
    else if (x<1200) cout <<"5";
    else if (x<1400) cout <<"4";
    else if (x<1600) cout <<"3";
    else if (x<1800) cout <<"2";
    else if (x<2000) cout <<"1";
}


Measured memory_bytes: 3636
// while( !(succeed == try()) );

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


#define int long long int
#define loop(i,s,e) for(int i=s; i<e; i++)
#define endl '\n'
#define vii vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX

void INP();

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 


// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


void alpha()
{    
    int x, k, d;
    cin>>x>>k>>d;

    x = abs(x);

    int t = k;
    k = max(0LL, k-(x/d));

    if(k>0) x = x%d;
    else x -= t*d;

    // bug(x, k);

    int t1=x, t2=abs(x-d);

    if(t2 <= t1 and k>0)
    {
        if((k-1)%2==0)
        {
            cout<<t2<<endl;
            return;
        }
        else
        {
            cout<<t1<<endl;
            return;
        }
    }
    else
    {
        if(k%2==0)
        {
            cout<<t1<<endl;
            return;
        }
        else
        {
            cout<<t2<<endl;
            return;
        }
    }
}

int32_t main(){

    ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    // INP();
    int t=1;
    //cin>>t;
    
    while(t--) alpha();

    return 0;

}






















inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}
 
 

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

int main(){
	int D,N;
	cin >> D >> N;
	if(N==100){
		cout << (int)((101)*pow(100,D)) << endl;
	}else{
		cout << (int)(N*pow(100,D)) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
s = input()

pre_char = 'R'
R_counter = 0
L_counter = 0
output_list = []
for index, char in enumerate(s):
    if (pre_char == 'L' and char == 'R') or index == len(s) - 1:
        if index == len(s) - 1:
            L_counter += 1
        output_list += [0] * (R_counter - 1)
        output_list.append(R_counter - R_counter // 2 + L_counter // 2)
        output_list.append(L_counter - L_counter // 2 + R_counter // 2)
        output_list += [0] * (L_counter - 1)
        R_counter = 0
        L_counter = 0
    if char == 'R':
        R_counter += 1
    else:
        L_counter += 1
    pre_char = char

str_output_list = [str(i) for i in output_list]
print(' '.join(str_output_list))

Measured memory_bytes: 10900
#include <iostream>
#include <map>
using namespace std;
int n,k,a[200001];
map<int,int> mp;
int main(){
    cin>>n>>k;
    long long ans=0;
    mp[0]=1;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[i]--;
        (a[i]+=a[i-1])%=k;
        if(i>=k)mp[a[i-k]%k]--;
        ans+=mp[a[i]%k];
        mp[a[i]%k]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10368
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (ll i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

const ll MOD = 1000000007LL;

string S;
ll dp[100010][4];

int main ()
{
    cin >> S;
    dp[0][0] = 1LL;

    for (int i = 0; i < S.size(); i++) {
        for (int j = 0; j < 4; j++) {
            if (S[i] == '?') {
                dp[i + 1][j] += dp[i][j] * 3LL;
            } else {
                dp[i + 1][j] += dp[i][j];
            }
        }
        if (S[i] == '?' || S[i] == 'A') {
            dp[i + 1][1] += dp[i][0];
        }
        if (S[i] == '?' || S[i] == 'B') {
            dp[i + 1][2] += dp[i][1];
        }
        if (S[i] == '?' || S[i] == 'C') {
            dp[i + 1][3] += dp[i][2];
        }
        for (int j = 0; j < 4; j++) {
            dp[i + 1][j] %= MOD;
        }
    }
    
    cout << dp[S.size()][3] << endl;

    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int n,a,b;
	int f=0;
	cin >> n >> a >> b;
	for(int i=a;i<=b;i++){
		if(i%n==0) f=1;
	}
	if(f==1) cout << "OK" << endl;
	else cout << "NG" << endl;
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
    string Sa,Sb,Sc;
    cin>>Sa>>Sb>>Sc;
    int lenSa=Sa.size();
    int lenSb=Sb.size();
    int lenSc=Sc.size();
    int a=0;
    int b=0;
    int c=0;
    int reacha=5;
    int reachb=5;
    int reachc=5;
    int turn=0;
    while(true){
        //cout<<a<<" "<<b<<" "<<c<<endl;
        if(reacha==0 && turn==0){
            cout<<"A"<<endl;
            return 0;
        }
        if(reachb==1 && turn==1){
            cout<<"B"<<endl;
            return 0;
        }
        if(reachc==2 && turn==2){
            cout<<"C"<<endl;
            return 0;
        }
        if(a==lenSa){
            reacha=0;
        }
        if(b==lenSb){
            reachb=1;
        }
        if(c==lenSc){
            reachc=2;
        }
        if(Sa[a]=='a' && turn==0){
            a++;
            continue;
        }
        if(Sb[b]=='a' && turn==1){
            b++;
            turn=0;
            continue;
        }
        if(Sc[c]=='a' && turn==2){
            c++;
            turn=0;
            continue;
        }
        if(Sa[a]=='b' && turn==0){
            a++;
            turn=1;
            continue;
        }
        if(Sb[b]=='b' && turn==1){
            b++;
            continue;
        }
        if(Sc[c]=='b' && turn==2){
            c++;
            turn=1;
            continue;
        }
        if(Sa[a]=='c' && turn==0){
            a++;
            turn=2;
            continue;
        }
        if(Sb[b]=='c' && turn==1){
            b++;
            turn=2;
            continue;
        }
        if(Sc[c]=='c' && turn==2){
            c++;
        }
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0; cin>>n;
	for(int i=1;i<=n;i++){
		int cnt=0;
		if(i%2==0) continue;
		for(int j=1;j<=i;j++){
			if(i%j==0) cnt++;
		}
		if(cnt==8) ans++;
	}
	cout<<ans;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define out(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    constexpr int T = 10;
    int n; cin >> n;
    vector<bitset<T>> f(n);
    REP(i,n) REP(j,T) {
        int b; cin >> b;
        if (b == 1) f[i].set(j,true);
    }
    vector<vector<int>> p(n,vector<int>(T+1));
    REP(i,n) REP(j,T+1) cin >> p[i][j];

    int ans = -(1 << 30);
    FOR(i,1,pow(2,T)) {
        int tmp = 0;
        bitset<T> jo(i);
        REP(j,n) {
            bitset<T> op = f[j] & jo;
            tmp += p[j][op.count()];
        }
        ans = max(ans,tmp);
    }

    cout << ans << endl;

    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll dp[3030][3030];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, 3030)REP(j, 3030) dp[i][j] = 0;

    ll N;
    cin >> N;
    string s;
    cin >> s;

    REP(i, N) dp[1][i] = 1;
    for(int i=1;i<N;i++){
    	REP(j, N){
    		if(s[i-1]=='>'){
    			dp[i+1][0] += dp[i][j];
    			dp[i+1][0] %= mod;

    			dp[i+1][j] -= dp[i][j];
    			dp[i+1][j] += mod;
    			dp[i+1][j] %= mod;
    		}else{
    			dp[i+1][j] += dp[i][j];
    			dp[i+1][j] %= mod;

    			dp[i+1][N-i] -= dp[i][j];
    			dp[i+1][N-i] += mod;
    			dp[i+1][N-i] %= mod;
    		}
    	}
    	REP(j, 3029){
    		dp[i+1][j+1] += dp[i+1][j];
    		dp[i+1][j+1] %= mod;
    	}
    }
    cout << dp[N][0] << endl;
    return 0;
}

Measured memory_bytes: 71936
#include <iostream>
using namespace std;
int main()
{
	int h, w;
	while(true)
	{
		cin >> h >> w;
		if(h==0&&w==0)
			break;
			
		for(int i =0; i < h; i++){
			for(int t=0; t < w; t++){
				if(i==0||i==h-1||t==0||t==w-1)
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}


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

#define ll  long long int
#define ld  long double
#define MAX 1000001
#define MOD 1000000007
#define pi  3.14159265358979323846264338
#define mp  make_pair
#define pb  push_back
#define pll pair<ll,ll>
#define vl  vector<ll>
#define vi  vector<int>
#define vs  vector<string>
#define vc  vector<char>
#define fst first
#define sec second
#define foi(i, a, b)   for(ll i = a; i<b;i++)
#define fod(i, a, b)   for(ll i = a;i>=b;i--)
#define all(v)         (v).begin(), (v).end()
#define max3(a, b, c)  max(max(a,b), c)
#define min3(a, b, c)  min(min(a,b), c)
#define ump  unordered_map<ll,ll>
#define us   unordered_set<ll>
#define nl  "\n"
#define INF  (ll)1e18
#define s(v) (ll)(v).size()
#define e(v) (v).empty

using namespace std;

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


void solve(){
    ll n,w;
    cin>>n>>w;
    // cout<<n<<" "<<w<<"\n";
    vector<ll> wt(n);
    vector<ll> val(n);
    ll sum_val = 0;
    foi(i,0,n){
        cin>>wt[i]>>val[i];
        sum_val += val[i];
    }
    //cout<<sum_val<<"\n";
    ll dp_next[sum_val+1];
    ll dp_prev[sum_val+1];
    for(int i=0;i<n+1;i++){
        for(int j=0;j<sum_val+1;j++){
            if(j==0){
                dp_next[j] = 0;
            }else if(i==0){
                dp_next[j] = INT_MAX;
            }else{
                if(val[i-1]<=j){
                    dp_next[j] = min(dp_prev[j],wt[i-1] + dp_prev[j-val[i-1]]);
                }else{
                    dp_next[j] = dp_prev[j];
                }
            }
        }
        foi(j,0,sum_val+1){
            dp_prev[j] = dp_next[j];
        }
    }
    // foi(i,0,sum_val+1){
    //     cout<<dp_prev[i]<<" ";
    // }
    //cout<<"\n";
    ll ans = 0;
    foi(i,0,sum_val+1){
        if(dp_prev[i]<=w){
            ans = max(ans,(ll)i);
        }
    }
    cout<<ans<<"\n";
}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
    }

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 5364