akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)

int cx[210],cy[210];
int sx[1010],sy[1010];
set<pair<int,int>> s;

int main(void){
	int m,n;
	while(cin >> m,m){
		s.clear();
		rep(i,m) cin >> cx[i] >> cy[i];
		cin >> n;
		rep(i,n) cin >> sx[i] >> sy[i];
		rep(i,n) s.insert(make_pair(sx[i],sy[i]));

		int ax=-1,ay=-1;
		rep(i,m)rep(j,n){
			int dx=sx[j]-cx[i],dy=sy[j]-cy[i];
			bool ok=true;
			rep(k,m){
				if(s.find(make_pair(cx[k]+dx,cy[k]+dy))==s.end()){
					ok=false;
					break;
				}
			}
			if(ok) ax=dx,ay=dy;
		}
		cout << ax << " " << ay <<  endl;
	}
}

Measured memory_bytes: 1248
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int d, g; cin >> d >> g;
	VE p(d), c(d); rep(i, d)cin >> p[i] >> c[i];
	int ans = INF;
	rep(bit, 1 << d) {
		int now = 0;
		int cnt = 0;
		rep(i, d) {
			if (bit & (1 << i)) {
				now += p[i] * 100 * (i + 1) + c[i];
				cnt += p[i];
			}
		}
		
		if (now >= g) {
			chmin(ans, cnt); continue;
		}
		for (int j = d - 1; j >= 0; j--) {
			int tmp = g - now;
			if (!(bit & (1<<j))&&(tmp + (100 * (j + 1)) - 1) / (100 * (j + 1)) <= p[j] - 1) {
				cnt += (tmp + (100 * (j + 1)) - 1) / (100 * (j + 1));
				chmin(ans, cnt);
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

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

const int N = 200001;
int A[N];

int main() {
  int n;
  S(n);
  rep(i,1,n+1) {
    S(A[i]);
  }
  if(A[1]) {
    P(-1);
    return 0;
  }
  LL ans = 0;
  rep(i,2,n+1) {
    if(A[i] > A[i - 1] + 1) {
      P(-1);
      return 0;
    }
  }
  ans += A[n];
  for(int i = n - 1; i >= 1; i--) if(A[i] != A[i + 1] - 1) {
    ans += A[i];
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll; const int INF=1e9;
typedef pair<int,int> P;

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

  ll an=0;
  ll i=0,j=1,nw=a[0];
  while(i<n) {
    //cout<<i<<" "<<j<<" "<<nw<<" "<<an<<endl;
    if ((nw & a[j]) > 0 || j==n) {
      an+=j-i; if (i!=n-1) nw^=a[i]; i++;
    } else {
      if (j<n) nw^=a[j]; j++;
    }
    //cout<<i<<" "<<j<<" "<<nw<<" "<<an<<endl;
  }
  cout<<an<<endl;
}

Measured memory_bytes: 1024
x, y = [int(i) for i in input().split()]
if (x + y) % 3 != 0:
    print(0)
    exit()
z = (x + y) // 3
x -= z
y -= z

p = 10**9+7


def kai(x, p):
    a = 1
    for i in range(1, x + 1):
        a *= i
        a %= p
    return a


def comb(a, b, p):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai(a, p)
    c *= pow(kai(b, p), p - 2, p)
    c *= pow(kai(a - b, p), p - 2, p)
    return c % p


print(comb(x+y, x, p))


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

struct Problem {
	int num_wrong;

	Problem() : num_wrong(0) {}
};

struct Team {
	int team;
	std::vector<Problem> problems;
	int num_correct;
	int penalty;

	Team(int team, int num_problems)
		: team(team),
		problems(num_problems),
		num_correct(0),
		penalty(0)
	{}
};

int main()
{
	std::vector<Team> teams;
	std::string message;
	message.reserve(8);

	while (true) {
		int num_teams, num_problems, num_records;
		std::cin >> num_teams >> num_problems >> num_records;

		if (num_teams == 0) return 0;

		teams.clear();
		teams.reserve(num_teams);
		for (int i = 1; i <= num_teams; i++)
			teams.push_back(Team(i, num_problems));

		for (int i = 0; i < num_records; i++) {
			int tid, pid, time;
			std::cin >> tid >> pid >> time >> message;

			Team& t = teams[tid - 1];
			Problem& p = t.problems[pid - 1];

			switch (message[0])
			{
			case 'C':
				t.penalty += p.num_wrong * 1200 + time;
				t.num_correct++;
				break;
			case 'W':
				p.num_wrong++;
				break;
			default:
				return 1;
			}
		}

		std::sort(teams.begin(), teams.end(), [](Team& x, Team& y) {
			if (x.num_correct > y.num_correct) return true;
			if (x.num_correct < y.num_correct) return false;
			if (x.penalty < y.penalty) return true;
			if (x.penalty > y.penalty) return false;
			return x.team < y.team;
		});

		for (Team& t : teams) {
			std::cout << t.team << " " << t.num_correct << " " << t.penalty << std::endl;
		}
	}
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl


namespace atcoder {
	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	int N;
	cin >> N;
	double total = 0, x;
	double btc = 380000.0;
	string u;
	for (int i = 0; i < N; i++) {
		cin >> x >> u;
		if (u == "JPY") {
			total += x;
		}
		else {
			total += (x*btc);
		}
	}
	printf("%f\n", total);
	return 0;
}


Measured memory_bytes: 256
class Monster():
    def __init__(self, health, attack):
        self.hlt = health
        self.atk = attack

    def attack(self, opponent):
        opponent.hlt -= self.atk


a, b, c, d = map(int, input().split())

takahashi = Monster(a, b)
aoki = Monster(c, d)
players = [takahashi, aoki]
while True:
    attacker, attackee = players
    attacker.attack(attackee)
    if attackee.hlt <= 0:
        break
    players.reverse()

print('Yes' if takahashi.hlt > 0 else 'No')


Measured memory_bytes: 9140
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(void)
{
	while(1)
	{
	int a,b;
	scanf("%d",&b);
	if(b==0){break;}
	for(int i=0;i<9;i++){
		scanf("%d",&a);
		b-=a;
	}
	printf("%d\n",b);
	}
	return 0; 
}
//3:25.212クリア


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
using namespace std;

#define rep(i,N) for(int (i)=0; (i)<(N); (i)++)
#define revrep(i,N) for(int (i)=(N)-1; (i)>=0; (i)--)
#define dump(vec) for(int i = 0; i < (vec).size(); i++){cout << vec.at(i) << ",";}cout << endl

typedef long long ll;

int main(void)
{
    int N;
    cin >> N;
    vector<pair<double,double>> p(N);
    rep(i,N){
        double x,y;
        cin >> x >> y;
        p.at(i).first = x;
        p.at(i).second = y;
    }

    double sum = 0;
    rep(i,N){
        for(int j = i+1; j < N; j++){
            sum += sqrt(
                pow((p.at(i).first - p.at(j).first), 2) +
                pow((p.at(i).second - p.at(j).second), 2)
            );

        }

    }
    cout << std::setprecision(14) << sum * 2 / N << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
	    int cnt=0;
		Scanner sc = new Scanner(System.in);
        
		int N = sc.nextInt();
		int[][] A = new int[N][2];
		for(int i = 0;i<N;i++){
		    A[i][0] = sc.nextInt();
		    A[i][1] = sc.nextInt();
		}
		int tmp = 0;
		int tmp2 = 0;
		for(int j = 0;j<N;j++){
		    if(A[j][0]>tmp){
		        tmp=A[j][0];
		        tmp2 = j;
		    }
		}
		int ans = A[tmp2][1];
		while(ans!=0){
		    ans--;
		    cnt++;
		}

		System.out.println(cnt+A[tmp2][0]);
		
	}
}

Measured memory_bytes: 94860
import java.util.*;
public class Main {


	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int nos = scan.nextInt();
		int sum = 0;
		for( int i=0 ; i<nos; i++)
		{
			int input = scan.nextInt();
			sum+=input-1;
		}
		System.out.println(sum);
		scan.close();
	}

}


Measured memory_bytes: 27752
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define mod 1000000007
int32_t main()
{
    int n,i,br=0,x=1;
  	cin>>n;
  	int a[n];
  	for(i=0;i<n;i++)
    {
      	cin>>a[i];
      	if(a[i]==x)
        {
          	x++;
        }
     	 else
         {
           	br++;
         }
    }
  if(br==n)
    cout<<-1<<endl;
  else
    cout<<br<<endl;
}

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

 int main() {
   int n; cin >> n;
   string s; cin >> s;

  int res = 1;
  char prv = s[0];
  for (int i = 0; i < s.length(); ++i) {
    if (prv != s[i]) res += 1;
    prv = s[i]; 
  }

  cout << res << endl;
 }

Measured memory_bytes: 3780
h,w = map(int, input().split())
l = [None]*h
for i in range(h):
    l[i] = list(input())

dd=[[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
def check(i,j):
    ret=0
    for d in dd:
        x,y=d
        if 0<=i+x<h and 0<=j+y<w:
            if l[i+x][j+y]=="#":
                ret+=1
    return ret

for i in range(h):
    row=[]
    for j in range(w):
        if l[i][j]=="#":
            row.append("#")
        else:
            ret = check(i,j)
            row.append(ret)
    print(*row,sep="")

Measured memory_bytes: 45552
#include <iostream>

typedef unsigned long long ll;

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

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

int main(){
	int n;
	while (std::cin >> n, n){
		ll d[11], v[11];
		for (int i = 0; i < n; ++i){
			std::cin >> d[i] >> v[i];
			ll g = gcd(d[i], v[i]);
			d[i] /= g, v[i] /= g;
		}
		ll s = lcm(d[0], d[1]);
		for (int i = 2; i < n; ++i)s = lcm(s, d[i]);
		for (int i = 0; i < n; ++i)v[i] *= (s / d[i]);
		ll t = gcd(v[0], v[1]);
		for (int i = 2; i < n; ++i)t = gcd(t, v[i]);
		for (int i = 0; i < n; ++i)std::cout << v[i] / t << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

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

    vector<vector<int>> ls(m);
    vector<vector<int>> rs(m);
    for(int i=0;i+1<n;i++){
        ls[a[i]].push_back(i);
        rs[a[i+1]].push_back(i);
    }

    int mid = 0;
    ll sc = 0;
    for(int i=0;i+1<n;i++){
        if(a[i]<a[i+1]){
            sc += a[i+1]-a[i];
        }
        else{
            if(a[i]!=0) mid++;
            sc += a[i+1]+1;
        }
    }
    ll res = sc;

    auto dist=[&](int l,int r){
        if(l<r) return r-l;
        else return m-l+r;
    };
    
    for(auto p:rs[0]){
        sc += dist(a[p],a[p+1])-1;
        mid--;
    }
    for(auto v:ls[0]){
        mid++;
        sc++;
    }
    
    for(int i=1;i<m;i++){
        sc -= mid;
        res = min(res,sc);
        
        for(auto p:rs[i]){
            sc += dist(a[p],a[p+1])-1;
            mid--;
        }
        for(auto v:ls[i]){
            mid++;
            sc++;
        }
    }

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<62;
const ll MOD=1000000007;



signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    vector<ll> h(N,0);
    for(ll i=0;i<N;++i)cin>>h[i];
    ll C=A-B;
    ll L=0,R=powl(10LL,9LL)+100;
    while(L+1<R){
        ll M=(L+R)/2;
        vl D=h;
        for(ll i=0;i<N;++i){D[i]-=B*M;chmax(D[i],0LL);}
        ll sum=0;
        for(ll i=0;i<N;++i)sum+=(D[i]+C-1)/C;
        if(sum>M)L=M;
        else R=M;
    }
    prt(R)
    
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <queue>


using namespace std;

typedef long long ll;
int c[505];
int s[505];
int f[505];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<n; i++)
        scanf("%d%d%d",&c[i],&s[i],&f[i]);
    for(int i=1; i<n; i++)
    {
        int ans=0;
        for(int j=i; j<n; j++)
        {
            if(ans<s[j])
                ans=s[j];
            if(ans%f[j]!=0)
                ans=ans+f[j]-ans%f[j];
            ans+=c[j];
        }
        printf("%d\n",ans);
    }
    cout<< 0 <<endl;
    return 0;
}



Measured memory_bytes: 256
n, x, m = gets.split.map(&:to_i)
ary = [x]
v = Array.new(m)
v[x] = 0

a = x * x % m
i = 0
while !v[a]
    v[a] = (i += 1)
    ary << a
    a = a * a % m
end

if i + 1 >= n
    ans = ary[0, n].sum
else
    j = v[a]
    ans = ary[0, j].sum
    n -= j

    s, t = n.divmod(i - j + 1)
    ans += ary[j .. i].sum * s
    ans += ary[j, t].sum
end

p ans

Measured memory_bytes: 15768
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define NO NULL
struct node{
  int key;
  struct node *p,*l,*r;
};
typedef struct node *Node;
Node root;

void insert(int k){
  Node y=NO;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->l=NO;
  z->r=NO;
  while(x!=NO){
    y=x;
    if(z->key < x->key)x=x->l;
    else x=x->r;
  }
  z->p=y;
  if(y==NO)root=z;
  else if(z->key<y->key)y->l=z;
  else y->r=z;
}
Node find(Node k,int x){
  while(k!=NO && x != k->key){
    if(x < k->key)k=k->l;
    else k=k->r;
  }
  return k;
}
void inorder(Node u){
  if(u==NO)return;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}
void preorder(Node u){
  if(u==NO)return;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}
int main(){
  int n,i,j,h;
  char c[20];
  Node s;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c);
    if(c[0]=='i'){
      scanf("%d",&j);
      insert(j);
    }
    else if(c[0]=='f'){
      scanf("%d",&j);
      s=find(root,j);
      if(s==NO)printf("no\n");
      else printf("yes\n");
    }
    else{
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 20608
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <queue>
#include <numeric>
#include <stack>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int x;
  cin >> x;
  cout << (x/2) * ((x+1)/2) << endl;

  return 0;
}








Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, K;
  cin >> N >> K;
  cout << N-K+1 << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var h, w, k int
	fmt.Scan(&h, &w, &k)

	var patterns = [][]int{{0}}
	for i := 1; i < w; i++ {
		var patternsNext = [][]int{}
		for _, pattern := range patterns {
			patternN := make([]int, i+1)
			copy(patternN, pattern)
			patternN[i] = i
			patternsNext = append(patternsNext, patternN)
			if pattern[i-1] == i-1 {
				patternR := make([]int, i+1)
				copy(patternR, pattern)
				patternR[i-1] = i
				patternR[i] = i - 1
				patternsNext = append(patternsNext, patternR)
			}
		}
		patterns = patternsNext
	}

	nums := make([]int, w)
	nums[0] = 1
	for i := 0; i < h; i++ {
		numsNext := make([]int, w)
		for _, pattern := range patterns {
			for i, n := range pattern {
				numsNext[i] = (numsNext[i] + nums[n]) % 1000000007
			}
		}
		nums = numsNext
	}
	fmt.Println(nums[k-1])

}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#define	MOD = 1000000007;
using namespace std;

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

	int a[51], b[51];
	int c[51], d[51];

	for (int i = 1; i <= N; i++)
	{
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= M; i++)
	{
		cin >> c[i] >> d[i];
	}

	int S[51];
	for (int i = 1; i <= N; i++)
	{
		S[i] = 0;
	}

	for (int i = 1; i <= N; i++)
	{
		int man = 1000000000;
		for (int j = 1; j <= M; j++)
		{
			int X = a[i] - c[j];
			int Y = b[i] - d[j];
			if (X < 0)
			{
				X = -X;
			}
			if (Y < 0)
			{
				Y = -Y;
			}
			if (man > X + Y)
			{
				man = X + Y;
				S[i] = j;
			}
		}
	}

	for (int i = 1; i <= N; i++)
	{
		cout << S[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
inf = 2 ** 50
vn, en = gets.split.map(&:to_i)
adj = Array.new(vn) { Array.new(vn, inf) }

vn.times do |i|
  adj[i][i] = 0
end

en.times do
  s, t, d = gets.split.map(&:to_i)
  adj[s][t] = d
end

vn.times do |k|
  vn.times do |i|
    vn.times do |j|
      if (adj[i][k] != inf && adj[k][j] != inf)
        adj[i][j] = [adj[i][j], adj[i][k] + adj[k][j]].min
      end
    end
  end
end

has_negative = false

vn.times do |i|
  has_negative = true if adj[i][i] < 0
end

if has_negative
  puts "NEGATIVE CYCLE"
else
  vn.times do |i|
    vn.times do |j|
      print(" ") if j != 0
      print(adj[i][j] >= inf ? "INF" : adj[i][j])
    end
    puts()
  end
end



Measured memory_bytes: 7776
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0)
using namespace std;
typedef long long LL;

int main(){
    IOS;
#ifdef Local
    freopen("data.txt","r",stdin);
#endif//Local
    LL x,y;
    cin>>x>>y;
    if(x<2&&y<2){
        cout<<"Brown\n";
    }
    else if(abs(x-y)>1){
        cout<<"Alice\n";
    }
    else{
        cout<<"Brown\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <queue>

using namespace std;

const int maxn = 2*1e5+5;
int n;
struct Node {
	int a,b;
	bool operator<(const Node &other) const {
        return b > other.b;
    }
}arr[maxn],mis;

priority_queue<Node> pq;

int main () {
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d",&arr[i].a,&arr[i].b);
		pq.push(arr[i]);
	}
	//i:当前时刻
	int i = 0;
	while(!pq.empty()) {
		mis = pq.top();
		pq.pop();
		//________________
		//cout << i << endl;
		//cout << mis.a << ' ' << mis.b << endl;
		//________________
		i += mis.a;
		if (i > mis.b) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
}

Measured memory_bytes: 3444
#include <iostream>

int main() {
	int a, b;
	std::cin >> a >> b;
	int diff = b - a;
	int c = 0;
	for (int i = 1; i < diff; i++) {
		c += i;
	}
	std::cout << c - a << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
  /* your code */
  for ( j=2; j<=n; j++ ){
    int key = A[j];
    int i = j-1;
    while( i>0 && A[i]>key ){
      A[i+1] = A[i];
      i--;
    }
    A[i+1]=key;
    trace(A,n);
  }

  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	ll n, k;
	ll h[100005];
	ll dp[100005];
	memset(h, 0, sizeof(h));
	memset(dp, 100000, sizeof(dp));

	cin >> n >> k;
	rep(i, n)
		cin >> h[i];

	rep(i, 100005)
		dp[i] = INF;

	dp[0] = 0;
	for(ll i = 1; i <= n; i++)
	{
		for (ll j = 1; j <= k && i - j >= 0; j++)
		{
			dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}

	cout << dp[n - 1] << endl;
	

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
int main(){
    int n,ans=0;
    cin>>n;
    string s="E869120",t;
    rep(i,n){
        cin>>t;
        if(s==t) ans++;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3196
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        String s = in.next();
        char[] ch = s.toCharArray();

        int length = s.length();
        int[][] dp = new int[length+1][13];
        dp[0][0] = 1;

        for (int i=0; i < length; i++) {
            int c = ch[i] == '?' ? -1 : Integer.valueOf(String.valueOf(ch[i]));
            for (int next=0; next < 10; next++) {
                if (c == -1 || c == next) {
                    for (int j=0; j < 13; j++) {
                        dp[i + 1][(j * 10 + next) % 13] += dp[i][j];
                        dp[i + 1][(j * 10 + next) % 13] %= MOD;
                    }
                }
            }
        }

        out.println(dp[length][5]);
    }


}


Measured memory_bytes: 36644
#include <bits/stdc++.h>
using namespace std;
int main()
{
    while(1)
    {
        int m,f,mu,sum;
        cin>>m>>f>>mu;
        if(m==-1 && f==-1 && mu==-1)
            break;
        if(m==-1 || f==-1)
            cout<<"F"<<endl;
        else
        {
            sum=m+f;
            if(sum>=80)
                cout<<"A"<<endl;
            else if(sum>=65)
                cout<<"B"<<endl;
            else if(sum>=50)
                cout<<"C"<<endl;
            else if(sum>=30)
            {
                if(mu>=50)
                    cout<<"C"<<endl;
                else
                    cout<<"D"<<endl;
            }
            else
                cout<<"F"<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3100
import math
a,b,agree=map(float,input().split())
agree=math.radians(agree)

c=(a**2+b**2-2*a*b*math.cos(agree))**0.5
s=0.5*a*b*math.sin(agree)
l=a+b+c
h=b*math.sin(agree)

print("{0:.5f}".format(s))
print("{0:.5f}".format(l))
print("{0:.5f}".format(h))


Measured memory_bytes: 5700
#include<stdio.h>
int main() {
	char s[4] = { 0 }, i;
	scanf("%s", &s);
	for (i = 0; i < 4; i++)
	{
		if (s[i] == '1')
			s[i] = '9';
		else if(s[i] == '9')
			s[i] = '1';
	}
	printf("%s\n",s);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  double N, K, a;
  cin >> N >> K;
  if(N >= K){
    a = (N - K + 1.0) / N;
  }
  else a = 0;
  for(int i=1;i<=N && i<K;i++){
    // N <= Kなら１～Nで i*2^c >=Kを満たす最小のcを見つけ、b = 2^cとする
    // N > Kなら初期値が	K以上ならすぬけ君の勝ちなので1~K-1で同様の操作を行う
    int b = 1;
    while(K > b*i) b *= 2;
    a += 1.0 / b / N;
  }
  cout << fixed << setprecision(10);
  cout << a <<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // String n = sc.next();
        int x = Integer.parseInt(sc.next());
        // int[] a = new int[n];

        // for (int i = 0; i < n; i++) {
        // a[i] = Integer.parseInt(sc.next());
        //
        // }

        int ans = 0;
        int num = x;
        ans += (x / 500) * 1000;
        num -= (x / 500) * 500;
        ans += (num / 5) * 5;

        System.out.println(ans);

    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n,k;
    cin >> n >> k;
    int num[n];
    rep(i,n){
        cin >> num[i];
    }
    sort(num,num+n);
    int sum = 0;
    rep(i,k){
        sum += num[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3616
N, M, *AB = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
deg = [1] + [0] * N
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    deg[b] += 1

ans = [0] * (N + 1)
stack = [deg.index(0)]
while stack:
    cur = stack.pop()
    for nxt in E[cur]:
        deg[nxt] -= 1
        if deg[nxt] == 0:
            ans[nxt] = cur
            stack.append(nxt)

for a in ans[1:]:
    print(a)

Measured memory_bytes: 31716
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    double avr = 0.0;
    ll cost = 10000000523;
    ll pre = 0;
    for (int i = 0; i < N;i++)
    {
        cin >> A[i];
    }
    for (int i = -100; i < 101; i++)
    {
        pre = 0;
        for (int j = 0; j < N; j++)
        {
            pre += pow(abs(A[j] - i), 2);
        }
        cost = min(cost, pre);
    }
    cout << cost << endl;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        String s = sc.next();
        int ans=s.length();
        for (char i = 'a'; i <= 'z'; i++) {
            ans = min(ans, solve(s,i,0));
        }
        out.println(ans);
    }
    static boolean d(String s){
        int c=0;
        for (int i = 0; i < s.length()-1; i++) {
            if(s.charAt(i)!=s.charAt(i+1)){
                c++;
                break;
            }
        }
        return c==0;
    }
    static int solve(String s,char c,int ans){
        if(d(s))return ans;
        else {
            String temp="";
            for (int i = 0; i < s.length() - 1; i++) {
                if(s.charAt(i+1)==c){
                    temp+=c;
                }else {
                    temp+=s.charAt(i);
                }
            }
            return solve(temp,c,ans+1);
        }
    }
}

Measured memory_bytes: 42964
import java.util.*;

public class Main {


    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax = -1;
        int rmin = Integer.MAX_VALUE;

        for(int i = 0;i < m;i++){
            lmax = Math.max(lmax, sc.nextInt());
            rmin = Math.min(rmin, sc.nextInt());
        }

        if(lmax > rmin) {
            System.out.println("0");
        } else {
            System.out.println(rmin-lmax+1);
        }
    }
}

Measured memory_bytes: 63288
#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}

int main()
{
    fast_cin;
    int t;
    t=1;
    //int tc=0;
    while(t--)
    {
      int x,y;
      cin>>x>>y;
      vector<string> v;
      vector<vector<ll> > dp(x);
      int m=1e9+7;
      for(int i=0;i<x;i++)
      {
          dp[i].assign(y,0);
      }
      for(int i=0;i<x;i++)
      {
          string s;
          cin>>s;
          v.pb(s);
      }
      for(int j=1;j<y;j++)
      {
          if(v[0][j]=='#')
            break;
          dp[0][j]=1;
      }
      for(int i=1;i<x;i++)
      {
          if(v[i][0]=='#')
            break;
          dp[i][0]=1;
      }
      if(v[0][0]=='#')
        cout<<0;
      else
      {
           for(int i=1;i<x;i++)
          {
              for(int j=1;j<y;j++)
              {
                  if(v[i][j]=='#')
                    continue;
                  dp[i][j]=(dp[i-1][j]+dp[i][j-1])%m;
              }
          }
          cout<<dp[x-1][y-1];
      }
    }
    return 0;
}
/*#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}
void binary(int n)
{
    // array to store binary number
    int binaryNum[32];

    // counter for binary array
    int i = 0;
    while (n > 0) {

        // storing remainder in binary array
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }

    // printing binary array in reverse order
    for (int j = i - 1; j >= 0; j--)
        cout << binaryNum[j];
}
int main()
{
    fast_cin;
    int t;
    cin>>t;
    int tc=0;
    ll x=10000009;
    while(t--)
    {
       ll p,f,cnts,cntw,s,w;
       cin>>p>>f>>cnts>>cntw>>s>>w;
       ll ans=0;
       ll x1,y1,x2,y2;
       if(s>w)
       {
           swap(s,w);
           swap(cnts,cntw);
       }
       for(ll i=0;i<=cnts;i++)
       {
           x1=min(i,p/s);
           y1=min((p-(x1*s))/w,cntw);
           x2=min((cnts-x1),(f/s));
           y2=min((f-(x2*s))/w,cntw-y1);
           ans=max(ans,x1+y1+x2+y2);
       }
       cout<<ans<<endl;
    }
    return 0;
}*/


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

int main(void){

    int  i, len;
    int  sum =0,x;
    char str[1000],c;
    

    while(1){
        scanf("%s",str);
        len = strlen(str);
        x = atoi(str);
        if(x == 0){break;}
        
        for(i = 0; i < len; i++){
            sum += str[i] - '0';
        }

        printf("%d\n",sum);
        sum = 0;
    }

    return 0;
}

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

#define int long long

main()
{
	int n, m; cin >> n >> m;
	int mn = m / n;
	
	if(n == 1) return cout << m << endl, 0;
	if(m % n == 0) return cout << m / n << endl, 0;
	
	for(int i = mn; i > 1; i--)
	{
		if((m - i * n) % i == 0) return cout << i << endl, 0;
	}
	cout << 1 << endl;
}


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

int main() {
	int N,K;
	string S;
	cin >> N >> K;
	cin >> S;

	// 連続する数字の個数の列data
	// 最初あるいは最後が'0'ならば長さ0の'1'を付け加えることで奇数番目が'1', 偶数番目を'0'にする.
	vector<int> data;
	if(S[0] == '0'){
        data.push_back(0);
	}
	int LastBoundary = 0; // 始点
    for (int i = 0; i < N-1; ++i) {
        if(S[i] != S[i+1]){
            // 終点を見つけたらdataに投げて始点を更新
            data.push_back(i - LastBoundary + 1);
            LastBoundary = i+1;
        }
    }
    data.push_back(N-1 - LastBoundary + 1);
    if(S[N-1] == '0'){
        data.push_back(0);
    }

	
	// しゃくとり法
	int ans = 0, sum = 0;
	int b = 0, t = 2 * K;
	// data.size()は奇数
	if(t > data.size()){
	    ans = N;
	}else{
        for (int i = 0; i < t+1; ++i) {
            sum += data[i];
        }
        ans = sum;
        while(t != data.size()-1){
            sum = sum + data[t+1] + data[t+2] - data[b] - data[b+1];
            ans = max(ans,sum);
            t = t + 2;
            b = b + 2;
        }
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 1020
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int A = sc.nextInt();
            int B = sc.nextInt();

            System.out.println(lcm(A, B));
        }
    }

    static long gcd(long M, long N) {
        if (M < N) {
            return gcd(N, M);
        }
        return N > 0 ? gcd(N, M % N) : M;
    }

    static long lcm(long M, long N) {
        return M * N / gcd(M, N);
    }

}


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

int main() {
  int X,Y;
  cin >>X>>Y;
  int Z;
  Z=(Y-X*2)/2;
  if(0<=Z && Z<=X && Y%2==0){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
}


Measured memory_bytes: 3620
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val s = br.readLine()!!
    var ans = Int.MAX_VALUE

    for (curC in s) {
        var willChangeIndexFrom = 0
        var maxChangeCount = 0
        for ((i, c) in (s + curC).withIndex()) {
            if (c == curC) {
                maxChangeCount = max(maxChangeCount, i - willChangeIndexFrom)
                willChangeIndexFrom = i + 1
            }
        }
        ans = min(ans, maxChangeCount)
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 34236
import sys
stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces


S1, S2, S3 = list(input().split())
answer = (S1[0]+S2[0]+S3[0]).upper()
print(answer)

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

using namespace std;

typedef long long LL;

const int N = 1010;

int n;

int main()
{
    cin >> n;
    int t = n, s = 0;
    while(t)
    {
        s += t % 10;
        t /= 10;
    }

    if(n % s == 0) puts("Yes");
    else puts("No");
    return 0;
}


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

int main(){
    int A[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << A[K-1] << endl;
    return 0;
}

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

int memo[M];

int main(){
	int n,ans;
	
	memo[0]=1;
	memo[1]=1;
	memo[2]=2;
	
	for(int i=3;i<M;i++){
		memo[i]=memo[i-1]+memo[i-2]+memo[i-3];
	}
	
	while(cin>>n){
		if(n==0)break;
		cout<<memo[n]/(365*10)+1<<endl;
	}
	
	return 0;
}

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

int main() {
  int n;
  cin >>n;
  int shou=INT_MAX;
  int dai=0;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    shou=min(shou,x);
    dai=max(dai,x);
  }
  cout<<dai-shou<<endl;
  return 0;
}

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

int main(){
    queue<char> A,B,C;
    string s1,s2,s3; cin >> s1 >> s2 >> s3;
    rep(i,s1.size()) A.push(s1[i]);
    rep(i,s2.size()) B.push(s2[i]);
    rep(i,s3.size()) C.push(s3[i]);

    char ch = A.front();
    A.pop();
    while(true){
        
        if(ch == 'a'){
            if(A.empty()) {
                cout << "A" << endl;
                return 0;
            }
            ch = A.front();
            A.pop();
            
        }else if (ch == 'b'){
            if(B.empty()) {
                cout << "B" << endl;
                return 0;
            } 
            ch = B.front();
            B.pop();
            
        }else{
            if(C.empty()) {
                cout << "C" << endl;
                return 0;
            }
            ch = C.front();
            C.pop();
            
        }
          
    }
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <climits>
#include <queue>
#include <utility>
#include <iomanip>
#include <sstream> 
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template<typename T1, typename T2>
inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
const ll MOD = 1000000007;
const ll INF = 1LL << 60;


vector<string> s(100100);


int main()
{
    ll n;
    cin >> n;

    
    rep(i, n) {
        cin >> s[i];
    }
    
    ll ac = 0, wa= 0, tle=0, re=0;
    rep(i, n) {
        if (s[i] == "AC")
            ac++;
        else if (s[i] == "WA")
            wa++;
        else if (s[i] == "TLE")
            tle++;
        else
            re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;


}




Measured memory_bytes: 6276
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

const int N = 2030;

ll ans;
ll D[N][N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            D[i][j] = ((j ? D[i][j - 1] : 0) + cnk(i, j)) % MOD;
        }
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            D[i][j] = (D[i][j] + (j ? D[i][j - 1] : 0)) % MOD;
        }
    }
    for (int p = 0; p <= a; p++)
    {
        for (int q = 1; q - 1 <= b && p + q <= a; q++)
        {
            ll c = cnk(b - 1, q);
            ll d = D[q - 1][p];
            ans = (ans + c * d) % MOD;
        }
        ans = (ans + cnk(b - 1, 0)) % MOD;
    }
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 41856
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
           
#define rep(i, n) for (int i = 0; i < n; ++i)

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

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;

#include <cassert>
struct Dice
{
    int bottom, east, south;
    Dice(int bottom, int east, int south)
	: bottom(bottom), east(east), south(south)
    {
	int t[3] = { bottom, east, south };
	for (int i = 0; i < 3; ++i)
	    if (t[i] < 0 || t[i] > 6)
		cout << t[i] << endl;

    }
    Dice roll(int dx, int dy)
    {
	if (dy == 0)
	{
	    if (dx == 1)
		return Dice(east, 7 - bottom, south);
	    else if (dx == -1)
		return Dice(7 - east, bottom, south);
	    else
		exit(1);
	}
	else if (dx == 0)
	{
	    if (dy == 1)
		return Dice(7 - south, east, bottom);
	    else if (dy == -1)
		return Dice(south, east, 7 - bottom);
	    else
		exit(1);
	}
	else
	    exit(1);
    }
    int hash() const
    {
	return bottom*100 + east*10 + south;
    }
};
bool operator<(const Dice& a, const Dice& b)
{
    return a.hash() < b.hash();
}
struct Node
{
    int pena, x, y;
    Dice dice;
};
bool operator<(const Node& a, const Node& b)
{
    return a.pena > b.pena;
}
int main()
{
    int h, w, sx, sy, gx, gy;
    while (cin >> h >> w, h | w)
    {
	int cell[16][16];
	rep (y, h)
	    rep (x, w)
	    cin >> cell[h-1 - y][x];
	cin >> sy >> sx >> gy >> gx;
	sy = h-1 - sy;
	gy = h-1 - gy;

	map<Dice, int> dp[16][16];
	priority_queue<Node> q;
	q.push((Node){ 0, sx, sy, Dice(6, 3, 2) });
	dp[sy][sx][q.top().dice] = 0;
	while (!q.empty())
	{
	    Node cur = q.top(); q.pop();
	    if (cur.pena > dp[cur.y][cur.x][cur.dice])
		continue;

	    static const int dx[] = { 0, 1, 0, -1 };
	    static const int dy[] = { 1, 0, -1, 0 };
	    for (int i = 0; i < 4; ++i)
	    {
		int tx = cur.x + dx[i], ty = cur.y + dy[i];
		if (tx < 0 || ty < 0 || tx >= w || ty >= h)
		    continue;

		Dice d = cur.dice.roll(dx[i], dy[i]);
		int pena = cur.pena + d.bottom * cell[ty][tx];
		if (!dp[ty][tx].count(d) || pena < dp[ty][tx][d])
		{
		    dp[ty][tx][d] = pena;
		    q.push((Node){ pena, tx, ty, d });
		}
	    }
	}
	int res = 1e9;
	foreach (it, dp[gy][gx])
	    min_swap(res, it->second);
	cout << res << endl;
    }
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

int main() {
    int n, k; cin >> n >> k;
    long h[n];
    rep(i, n) cin >> h[i];
    sort(h, h + n);

    long ans = 0;
    rep(i, n - k){
        ans += h[i];
    }
    OP(ans);
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>

int main()
{
  int n, l;
  std::cin >> n >> l;
  std::vector<std::string> s(n);
  for (auto& string : s)
  {
    std::cin >> string;
  }
  std::sort(s.begin(), s.end());
  for (const auto& string : s)
  {
    std::cout << string;
  }
  std::cout << std::endl;
  
  return 0;
}

Measured memory_bytes: 256