akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int n;

int main()
{
  cin >> n;

  if(n >= 3) puts("0");
  else if(!(n & 1)) puts("1");
  else puts("2");

  return 0;
}

Measured memory_bytes: 1120
MAX_NUM = 10**6 + 1
MOD = 10**9+7

fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]

fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def combinations(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
N, K = map(int, input().split())
A = list(map(int, input().split()))
A=sorted(A)
ANSWER = 0
# Sの最大値をイテレート
for i in range(K-1, N):
    ANSWER += A[i]*combinations(i, K-1)
    # print(ANSWER)
for i in range(N-K+1):
    ANSWER -= A[i]*combinations(N-i-1, K-1)
    # print(ANSWER)

ANSWER %= MOD
print(ANSWER)


Measured memory_bytes: 133012
import math

a,b,h,m = map(int,input().split())

hour_deg = (h + m / 60) / 12 * 360
min_deg = (m / 60) * 360

deg_diff = abs(min_deg - hour_deg)
ans = a**2 + b**2 - (2 * a * b * math.cos(math.radians(deg_diff)))
print(math.sqrt(ans))

Measured memory_bytes: 9512
# C - GeT AC
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = map(int, raw_input().split())
S = raw_input()

cnt = [0] * (len(S) + 1)

for s_id in range(len(S)):
    cnt[s_id + 1] = cnt[s_id]
    if S[s_id] == 'C' and S[s_id - 1] == 'A':
        cnt[s_id + 1] += 1

for _ in range(Q):
    l, r = map(int, raw_input().split())
    print '{}'.format(cnt[r] - cnt[l])


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

struct Card {
  char suit;
  int number;
};

int selectionSort(Card cards[], int n) {
  int switch_count = 0;
  for (int i = 0; i < n; i++) {
    int minj = i;
    for (int j = i; j < n; j++) {
      if (cards[j].number < cards[minj].number) {
        minj = j;
      }
    }
    if (i != minj) {
      swap(cards[i], cards[minj]);
      switch_count++;
    }
  }
  return switch_count;
}

int bubbleSort(Card cards[], int n) {
  bool flag = true;
  int switch_count = 0;
  while(flag) {
    flag = false;
    for (int j = n - 1; j > 0; j--) {
      if (cards[j].number < cards[j - 1].number) {
        swap(cards[j], cards[j -1]);
        flag = true;
        switch_count++;
      }
    }
  }
  return switch_count;
}

void print(Card cards[], int n) {
  for (int i = 0; i < n; i++) {
    cout << cards[i].suit << cards[i].number;
    if (i != n - 1) {
      cout << " ";
    }
  }
  cout << endl;
}

void copy(Card cards[], Card copy_cards[], int n) {
  for (int i = 0; i < n; i++) {
    copy_cards[i] = cards[i];
  }
}

bool isStable(Card stable_cards[], Card sample_cards[], int n) {
  for (int i = 0; i < n; i++) {
    if (stable_cards[i].suit != sample_cards[i].suit) return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  Card cards[n];

  for (int i = 0; i < n; i++) {
    cin >> cards[i].suit >> cards[i].number;
  }

  Card bubble_sort_cards[n];
  copy(cards, bubble_sort_cards, n);
  Card seliction_sort_cards[n];
  copy(cards, seliction_sort_cards, n);
  bubbleSort(bubble_sort_cards, n);
  print(bubble_sort_cards, n);
  cout << "Stable" << endl;
  selectionSort(seliction_sort_cards, n);
  print(seliction_sort_cards, n);
  bool is_stable = isStable(bubble_sort_cards, seliction_sort_cards, n);
  if (is_stable) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B && A!=C){
    cout<<"Yes"<<endl;
  }
  else if(A==C && A!=B){
    cout<<"Yes"<<endl;
  }
  else if(B==C && B!=A){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*
ID: lyr14721
PROG: 
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int a,b;
	cin>>a>>b;
	if(a==1) {
		if(b==2) cout<<3;
		else cout<<2;
	}
	else if(a==2) {
		if(b==1) cout<<3;
		else cout<<1;
	}
	else {
		if(b==1) cout<<2;
		else cout<<1;
	}
	return 0;
}


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

int main(void){
    char s[11], t[11], u[11];
    int a = 0, b = 0; 

    scanf("%s%s%d%d%s", s, t, &a, &b, u);

    if(strcmp(s, u) == 0){
        a--;
    }else{
        b--;
    }

    printf("%d %d\n", a, b);
    return 0;

} 



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

using namespace std;

int main(void){

	double xa,ya,xb,yb,xc,yc,xd,yd;
	double sikaku;

	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF){
		sikaku=abs(((xa*yb+xb*yc+xc*yd+xd*ya)-(xb*ya+xc*yb+xd*yc+xa*yd))/2);
		xb-=xa,xc-=xa,xd-=xa,xa=0;
		yb-=ya,yc-=ya,yd-=ya,ya=0;
		if(sikaku==(abs((xb*yc-yb*xc)/2)+abs((xc*yd-yc*xd)/2))){
			xa-=xd,xb-=xd,xc-=xd,xd=0;
			ya-=yd,yb-=yd,yc-=yd,yd=0;
			if(sikaku==(abs((xb*ya-yb*xa)/2)+abs((xc*yb-yc*xb)/2))) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		else cout<<"NO"<<endl;

	}

	return 0;
}

Measured memory_bytes: 1224
n = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
i = 1
count = 0
while i < n - 1
  if (arr[i + 1] - arr[i]) * (arr[i] - arr[i - 1]) > 0
    count += 1
  end
  i += 1
end
puts count

Measured memory_bytes: 14332
#include <stdio.h>

int main()
{
  int i,b,k[100],n,a=0,o=0,v,j;
  scanf("%d",&a);
  for(b=0;b<a;b++)
    {
      scanf("%d",&n);
      k[b]= n;
      
    }

   for(b=0;b<a-1;b++)
	{
	  printf("%d ",k[b]);
	}
      printf("%d",k[b]);
      printf("\n");
  for(i=1;i<a;i++)
    {
      v = k[i];
      j = i-1;
      
      while(j>=0 && k[j]>v)
	{
	  k[j+1] = k[j];
	    j--;
	  
	}
      k[j+1] = v;
      for(b=0;b<a-1;b++)
	{
	  printf("%d ",k[b]);
	}
      printf("%d",k[b]);
      printf("\n");
    }
  
  return 0;
}



Measured memory_bytes: 2128
h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in [0]*h ]

res = []
for i in range(h):
    for j in range(w-1):
        if a[i][j] % 2 == 1:
            res.append((i+1,j+1,i+1,j+2))
            a[i][j+1] += 1

for i in range(h-1):
    if a[i][-1] % 2 == 1:
        res.append((i+1,w,i+2,w))
        a[i+1][-1] += 1

print(len(res))
for r1,r2,r3,r4 in res:
    print(r1,r2,r3,r4)

Measured memory_bytes: 72924
#include<iostream>
#include<cstdio>
#include<cctype>
#define N 1200
using namespace std;

int main() {
	char ch;

	while (1) {
		scanf("%c", &ch);
		if (islower(ch)) printf("%c", toupper(ch));
		else if (isupper(ch)) printf("%c", tolower(ch));
		else if (ch == ' ') cout << " ";
		else cout << ch;
		if (ch == '\n') {
		    //cout << endl;
		    break;
		}
	}
	return 0;
}


Measured memory_bytes: 3148
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/


/*実行開始からの経過時間を表すよ。

while (clock() < 1900000) {  }

*/


/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/

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

	if (b < c) {
		int tmp = b;
		b = c;
		c = tmp;
	}
	if (a < b) {
		int tmp = a;
		a = b;
		b = tmp;
	}

	int sum = a - b + a - c;

	if (sum & 1) {
		sum += 2;
	}

	cout << ceil(sum / 2.0);



	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //PrintWriter out = new PrintWriter(System.out);
        long N = sc.nextLong();
        long[] a = new long[5];
        for(int i=0;i<5;i++) a[i]=sc.nextLong();
        // {arrive at current stop, num of people transport per minute
        long v = N;
        for(long w:a) v = Math.min(v,w);
        long ans = N%v==0?N/v:(N/v+1);
        ans += 4;
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll H, W, D;
    cin >> H >> W >> D;

    map<ll, pi> mp;

    for(ll row = 1; row <= H; row++){
        for(ll col = 1; col <= W; col++){
            ll t; cin >> t;
            mp[t] = make_pair(row, col);
        }
    }

    //配るDP的な発想
    vector<ll > dp(H * W + 19, 0);

    //準備
    for(ll i = 1; i <= H * W; i++){
        ll next = i + D;
        if(i + D > H * W) continue;
        dp[i + D] = dp[i] + abs(mp[i].first-mp[i+D].first) + abs(mp[i].second-mp[i+D].second);
    }

    ll Q; cin >> Q;

    vector<ll > ans;
    for(ll i = 0; i < Q; i++){
        ll a, b; cin >> a >> b;
        ans.push_back(dp[b]-dp[a]);
    }

    for(ll i = 0; i < Q; i++){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 8308
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int N=2e5+2;
int num[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l;
	long long ans=0;
	string s;
	cin>>n>>s;
	for(i=1;i<=n;i++){
		if((n%i)||!(n%(2*i))){
			continue;
		}
		string t="",rev="",t1="";
		k=0;
		for(j=0;j<i;j++){
			t+=s[j];
			rev+=(s[j]^('1'^'0'));
			k=(k*2+(int)(s[j]-'0'));
			if(k>=mod){
				k-=mod;
			}
		}
		//cout<<i<<' '<<k<<endl;
		num[i]+=k;
		for(j=0;j<n/i;j++){
			if(!(j&1)){
				t1+=t;
			}
			else{
				t1+=rev;
			}
		}
		if(t1<=s){
			num[i]++;
		}
		if(num[i]>=mod){
			num[i]-=mod;
		}
		ans+=2ll*num[i]*i;
	//	cout<<i<<' '<<num[i]<<endl;
		ans%=mod;
		for(j=3*i;j<=n;j+=2*i){
			num[j]-=num[i];
			if(num[j]<0){
				num[j]+=mod;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 2000
a,b,m= [int(x) for x in input().split()]
alist = [int(x) for x in input().split()]
blist = [int(x) for x in input().split()]
w = []
for i in range(m):
  w.append([int(x) for x in input().split()])
kane = min(alist) + min(blist)
for i in range(m):
  money = alist[w[i][0]-1] + blist[w[i][1]-1]-w[i][2]
  if money < kane:
    kane = money
print(kane)

Measured memory_bytes: 32492
#include <iostream>

using namespace std;

int main(){
    string s;
    cin >> s;
    int n=s.length();
    bool ok=0;
    for(int i=0; i<n; i++){
        if(s[i]=='7'){
            ok=1;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        String n = in.nextLine();
        int sn = 0;
        for (char c : n.toCharArray()) {
            sn += c - '0';
        }

        System.out.println(Integer.parseInt(n)%sn == 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main(void)
{
    int n,q;
    string s;
    int l, r;

    cin >> n >> q;
    cin >> s;

    int count[n] = {0};
    int res[q] = {0};
    count[0] = 0;

    for (int i = 0; i < n; i++) {
        count[i+1] += count[i];

        if (s[i] == 'A' && s[i+1] == 'C') {
            count[i+1]++;
        }
    }

    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        res[i] = count[r-1]-count[l-1];
    }

    for (int i = 0; i < q; i++) {
        cout << res[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n ; i++) {
            a[i] = sc.nextInt();
        }
        boolean ans = false;
        for (int i = 0 ; i < n ; i++) {
            if (a[i] % 2 == 1) {
                ans = true;
            }
        }
        if (ans) {
            System.out.println("first");
        } else {
            System.out.println("second");
        }


    }

}


Measured memory_bytes: 50988
package main

import "fmt"

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n int
	fmt.Scan(&n)

	t, x, y := 0, 0, 0
	ok := true
	for i := 0; i < n; i++ {
		var nt, nx, ny int
		fmt.Scan(&nt, &nx, &ny)
		time := nt - t
		dist := abs(nx-x) + abs(ny-y)
		rest := time - dist
		if !(rest >= 0 && rest%2 == 0) {
			ok = false
			break
		}
	}

	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 7552
#include <iostream>

using namespace std;
int main()
{
    int n[1000];
    for(int i=0;i<5;i++)
    {
        cin>>n[i];
    }
    for(int i=0;i<5;i++)
    {
        if(n[i]==0)
            cout<<i+1<<endl;
    }

    return 0;
}

Measured memory_bytes: 3188
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	fmt.Fprintln(wr, 111+999-n)
}


Measured memory_bytes: 1772
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for(int i=0; i<h; i++)
		cin >> s[i];
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(s[i][j] != '#'){
				int n=0;
				if(i!=0){
					if(j!=0 && s[i-1][j-1]=='#')
						n++;
					if(s[i-1][j]=='#')
						n++;
					if(j!=w-1 && s[i-1][j+1]=='#')
						n++;
				}
				if(j!=0 && s[i][j-1]=='#')
					n++;
				if(j!=w-1 && s[i][j+1]=='#')
					n++;
				if(i!=h-1){
					if(j!=0 && s[i+1][j-1]=='#')
						n++;
					if(s[i+1][j]=='#')
						n++;
					if(j!=w-1 && s[i+1][j+1]=='#')
						n++;
				}
				s[i][j] = char('0'+n);
			}
		}
	}
	for(int i=0; i<h; i++)
		cout << s[i] << endl;
	return 0;
}


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

int main(){
  long long n, k, a; cin >> n >> k;
  map<long long, long long> m;
  rep(i, n){
    long long c, d; cin >> c >> d;
    m[c] += d;
  }
  for(auto p: m){
    k -= p.second;
    if(k <= 0){
      a = p.first;
      break;
    }
  }
  cout << a << "\n";
  return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll ans,pre[500005],suf[500005];
int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = s.size();
    pre[0] = 0;
    for(int i=0; i<n; i++)
        if(s[i] == '<')pre[i + 1] = pre[i] + 1;
    
    suf[n] = 0;
    
    for(int i=n-1; i>=0; i--)
        if(s[i] == '>')suf[i] = suf[i + 1] + 1;
    
    for(int i=0; i<=n; i++){
        ans += max(pre[i] , suf[i]);
    }
    
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 8732
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl;
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	int y, m, d;
	VS gengo = { "pre-meiji","meiji","taisho","showa","heisei" };
	VI gday = { 0,1867,1911,1925,1988 };

	while (cin >> y >> m >> d) {
		int ty, day = y * 10000 + m * 100 + d;

		if (day < 18680908)ty = 0;
		else if (day <= 19120729)ty = 1;
		else if (day <= 19261224)ty = 2;
		else if (day <= 19890107)ty = 3;
		else ty = 4;

		if (ty == 0)Cout(gengo[0])
		else {
			cout << gengo[ty] << " " << y - gday[ty] << " " << m << " " << d << endl;
		}
	}

}


Measured memory_bytes: 3208
import std.stdio, std.conv, std.string, std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.math, std.random, std.range;

void main()
{
    const MOD = 1000000007;
    int[] input = readln().split.to!(int[]);
    int H = input[0];
    int W = input[1];
    int K = input[2];

    int[][] dp;
    dp.length = W;
    dp.each!((ref a)=>a.length=H+1);
    dp[0][0] = 1;

    foreach(h; 0..H)
    {
        foreach(w; 0..W)
        {
            for(int i = 0;i < 1 << (W-1);i++)
            {
                bool ok = true;
                for(int k = 0;k < W-2;k++)
                {
                    if((i >> k & 1) && (i >> k+1 & 1))
                    {
                        ok = false;
                    }
                }
                if(ok == false)
                {
                    continue;
                }
                //左側
                if(w >= 1 && i >> w-1 & 1)
                {
                    dp[w-1][h+1] += dp[w][h];
                    dp[w-1][h+1] %= MOD;
                } //右側
                else if(w <= W-2 && i >> w & 1)
                {
                    dp[w+1][h+1] += dp[w][h];
                    dp[w+1][h+1] %= MOD;
                } //移動しない
                else
                {
                    dp[w][h+1] += dp[w][h];
                    dp[w][h+1] %= MOD;
                }
            }
        }
    }
    writeln(dp[K-1][$-1]);
}


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

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(v) v.begin(),v.end()

using int64 = long long;

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

int main(void){
	int H, W;
	while(cin >> W >> H && H && W){
		vector<string> f(H+2, string(W+2, '#'));
		int sy, sx;
		REP(i, H){
			cin >> f[i+1];
			REP(j, W)
				if(f[i+1][j] == '@'){
					sy = i+1;
					sx = j+1;
				}
			f[i+1] = '#'+f[i+1]+'#';
		}
		bool visited[30][30] = {};
		int cnt = 0;
		
		function<void(int, int)> dfs = [&](int y, int x){
			visited[y][x] = 1;
			cnt++;
			REP(i, 4){
				int yy = y+dy[i], xx = x+dx[i];
				if(f[yy][xx] != '#' && !visited[yy][xx]){
					dfs(yy, xx);
				}
			}
		};
		dfs(sy, sx);
		cout << cnt << endl;
	}
}


Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<int>S(N);
    cin >> S;

    int ans = accumulate(ALL(S), 0);
    if (ans % 10 == 0) {
        SORT(S);
        int i = 0;
        int m = S[0];
        while (m % 10 == 0) {
            m = S[i];
            i++;
            if (i == N) {
                m = -1;
                break;
            }
        }
        if (m == -1)ans = 0;
        else ans -= m;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> v(n);
    for (int i = 0; i < m; i++)
    {
        int x,y;
        cin >> x >> y;
        x--, y--;
        v[x].push_back(y);
    }
    vector<pair<int, int>> p;
    for (int i = 0; i < n; i++)
    {   if(v[i].size()!=0){
        sort(v[i].begin(), v[i].end());
        p.push_back(make_pair(i, v[i][0]));
    }
    }
    sort(p.begin(), p.end());
  /*   for (int i = 0; i < p.size(); i++)
    {
        cerr << p[i].first << " " << p[i].second << endl;
    }*/

    int cnt = 1;
    pair<int,int> line = p[p.size()-1];
    for (int i = p.size() - 2; i >= 0; i--)
    {
        if(p[i].second<=line.first){
            cnt++;
            line = p[i];
        }
    }
    cout << cnt << endl;
    


    return 0;
}

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

int main(){
	int n;
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		int b[10];
		for(int j=0; j<10; ++j) scanf(" %d", &b[j]);
		
		bool ans=false;
		//bitloopで全探索
		for(long j=(1<<10)-1; j>=0; --j){
			int left[11], right[11];
			int x=1, y=1;
			left[0]=right[0]=0;
			//printf("%ld\n", j);
			
			bool flag=true;
			
			for(int k=0; k<10; ++k){
				if( (j>>k)&1 ){ //右に入れる
					if(left[x-1] < b[k]) left[x++]=b[k];
					else flag=false;
				}
				else{
					if(right[y-1] < b[k]) right[y++]=b[k];
					else flag=false;
				}
				if(!flag) break;			
			}
			
			if(flag){
				ans=true;
				break;
			}
		}
		
	if(ans) printf("YES\n");
	else printf("NO\n");
	}
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int ALP = 26;
const int INF = 1e6 + 239;

set<int> s[ALP];

void init() {
	for (int i = 0; i < ALP; i++) {
		s[i].insert(INF);
	}
}

int get(int l, int r) {
	int ans = 0;
	for (int i = 0; i < ALP; i++) {
		ans += (*s[i].lower_bound(l) <= r);
	}
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	init();

	int n;
	string x;
	cin >> n >> x; 
	for (int i = 0; i < n; i++) {
		s[x[i] - 'a'].insert(i);
	}
	int q;
	cin >> q;
	while (q--) {
		int tp;
		cin >> tp;
		if (tp == 1) {
			int pos;
			char c;
			cin >> pos >> c;
			pos--;
			s[x[pos] - 'a'].erase(pos);
			x[pos] = c;
			s[x[pos] - 'a'].insert(pos);
		} else {
			int l, r;
			cin >> l >> r;
			l--;
			r--;
			cout << get(l, r) << '\n';
		}
	}
}


Measured memory_bytes: 24220
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int d_min = INT32_MAX;
    auto l_itr = lower_bound(x.begin(), x.end(), 0);
    int l;
    if(l_itr == x.end()) {
        cout << -x[n-k] << endl; return 0;
    }
    else {l = l_itr - x.begin();}
    if(l+k-1 <= n-1) chmin(d_min, x[l+k-1]);
    if (l-k+1 >= 0 && x[l] == 0) chmin(d_min, -x[l-k+1]);
    if (l-k >= 0 && x[l] != 0) chmin(d_min, -x[l-k]);
    rep(i,n) {
        int upper = i;
        int lower = upper-k+1;
        if(upper >= n || lower < 0) continue;
        if(upper < l || lower >= l) continue;
        chmin(d_min, 2*x[upper]-x[lower]);
        chmin(d_min, x[upper]-2*x[lower]);
    }
    cout << d_min << endl;
}

Measured memory_bytes: 640
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    R, G, B, N = map(int, readline().split())
    ans = 0
    for r in range(3001):
        if R*r>N:
            break
        for g in range(3001):
            b = N - R*r - G*g
            if b<0:
                break
            if b%B==0:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>

int main(int argc, char **argv){

    int N, Q;
    std::cin >> N;
    std::cin >> Q;

    std::queue<std::pair<std::string,int>> tasks;
    for(int i = 0; i < N; i++){
	std::string name;
	int time;
	std::cin >> name >> time;
	tasks.emplace(name, time);
    }

    int totaltime = 0;
    
    while(!tasks.empty()){
	auto task = tasks.front(); tasks.pop();
	int t = task.second;
	if(t > Q){
	    totaltime += Q;
	    task.second -= Q;
	    tasks.push(std::move(task));
	}else{
	    totaltime += t;
	    std::cout << task.first << " " << totaltime << std::endl;
	}
    }
    
}



Measured memory_bytes: 6220
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  int ku = 0;
  int ma = 0;
  for (int i = 0; i < N; i ++) {
    int a;
    cin >> a;
    ku += a;
    ma += a * a;
  }
  cout << (ku * ku - ma) / 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<int>v[N];
bool vstd[N];
vector<pair<int,int> > e;
map<pair<int,int>,int> mp;
int col[N];
int main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  int n;cin>>n;
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    v[a].push_back(b);
    v[b].push_back(a);
    e.push_back({a,b});
  }
  queue<int> q;
  int hnhn=0;
  q.push(1);vstd[1]=true;
  while(q.size()){
    int node=q.front();
    //cout<<node<<endl;
    q.pop();
    if(hnhn<v[node].size()){
       hnhn=v[node].size();
    }
    int now=1;
    for(auto u:v[node]){
      if(vstd[u]) continue;
      if(now==col[node]){
        now++;
      }
      col[u]=now;
      mp.insert({{u,node},now});
      mp.insert({{node,u},now});
      now++;
      vstd[u]=1;
      q.push(u);
    }
  }
  cout<<hnhn<<endl;
  for(auto u:e) cout<<mp[u]<<endl;
  return 0;
}

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

int main(){
    int n,t,a;
    cin >> n >> t >> a;
    vector<int> v(n);
    vector<double> h(n);
    for(int i=0;i<n;i++){
        cin >> v[i];
        h[i] = (double)t - (double)v[i] * 0.006;
    }
    int ansa = 1;
    double ans = abs(a-h[0]);
    for(int i=1;i<n;i++){
        if(ans > abs(a-h[i])){
            ansa = i+1;
            ans = abs(a-h[i]);
        }
    }
    cout << ansa << endl;
}

Measured memory_bytes: 256
N=int(input())
h=list(map(int,input().split()))
t=[0]*N
a=0
for i in range(N):
        while t[i]<h[i]:
                for j in range(i,N):
                        if t[j]<h[j]:
                                t[j]+=1
                        else:
                                break
                a+=1
print(a)

Measured memory_bytes: 39280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int x = scan.nextInt();
		scan.close();
		int ans = 0;
		
		for(int i=0; i<=a; i++) {
			for(int j=0; j<=b; j++) {
				for(int k=0; k<=c; k++) {
					if(50*k + 100*j + 500*i == x) {
						ans++;
					}
				}
			}
		}
		
		System.out.println(ans);
	}

}

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

int main() {
    int m, f, r, sum;
    char grade;

    for ( ; ; ) {
        cin >> m >> f >> r;
        sum = m + f;

        if ( m == -1 && f == -1 && r == -1 ) break;
        if ( m == -1 || f == -1 ) grade = 'F';
        else if ( sum >= 80 ) grade = 'A';
        else if ( sum >= 65 && sum < 80 ) grade = 'B';
        else if ( sum >= 50 && sum < 65 ) grade = 'C';
        else if ( sum >= 30 && sum < 50 ) {
            if ( r >= 50 ) grade = 'C';
            else grade = 'D';
        }
        else if ( sum < 30 ) grade = 'F';

        cout << grade << endl;
    }

    return 0;
}

Measured memory_bytes: 3060
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np




def main():
	n,m,v,p=map(int,input().split())
	A=list(map(int,input().split()))
	A.sort(reverse=True)
	teki=A[p-1]
	
	ans=0
	cnt=1
	d=0
	
	for i in range(p,n):
		if A[i]+m<teki:break
		d+=cnt*(A[i-1]-A[i])
		if d>m*(n-v):break
		cnt+=1
		ans+=1
	print(p+ans)
	
if __name__ == "__main__":
	main()


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

int main(){
  int64_t n,sum=0,pre=0,pos=0;
  cin >> n;
  vector<int64_t> a(n);
  for(int64_t i=0; i<n; i++){
    cin >> a[i];
    sum += a[i];
  }
  for(int64_t i=0; i<n; i++){
    pre += a[i];
    if(pre>(double)sum/(double)2){
      pos = sum - pre + a[i];
      break;
    }
  }
  if(abs(2*pre-sum)>abs(2*pos-sum)) cout << abs(2*pos-sum) << endl;
  else cout << abs(2*pre-sum) << endl;
}

Measured memory_bytes: 1792
// type a
//a...いけそう
//b...自信がない
//c...お試し
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000
#define mod = (lint)1000000007;
#pragma endregion

string s;
void input() {
	cin >> s;
	return;
}
int solve() {
	int ans = 0;
	for (int i = 1; i < (int)s.size(); i++) {
		if (s[i] != s[i - 1])ans++;
	}
	return ans;
}


int main(void) {
	input();
	printf("%d\n", solve());
	
	return 0;
}

Measured memory_bytes: 3824
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
		AB = input[0].split(" ");

	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(AB[0], 10);
	var b = parseInt(AB[1], 10);
	
	var ans = 0;
	if (a ==b) {var ans = a + b;}
	    else if (a > b){var ans =a + a-1;}
	             else {var ans = b + b - 1;}
	
	         
	//出力
	console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int main() {
    int n;cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int count = 0;
    rep(i, 50) {
        rep(j, n) {
            if(a[j]%2==1) {
                cout << i << endl;
                return 0;
            }
            a[j]/=2;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
//	cut here before submit 
//	freopen ("testcase.Cup_Game", "r", stdin );

	bool CUP[3] = {false};
	CUP[0] = true;

	string str = "";
	while (getline (cin, str ) ){
		swap(CUP[str[0] - 'A'], CUP[str[2] - 'A'] );
	} // end while
	rep (i, 3 ) if (CUP[i] ) cout << (char)(i+'A') << endl;

	return 0;
}

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

#define intt long long
#define mod 1000000007

int main()
{
	intt n,k;
	cin>>n>>k;
	intt arr[n+1];
	for(intt i=0;i<=n;i++)
	arr[i]=i;
	
	intt prefix[n+1];
	intt suffix[n+1];
	prefix[0]=arr[0];
	suffix[n]=arr[n];
	for(intt i=1;i<=n;i++)prefix[i]=prefix[i-1]+arr[i];
	for(intt i=n-1;i>=0;i--)suffix[i]=suffix[i+1]+arr[i];
	
	intt sum=0;
	for(intt j=k;j<=n+1;j++)
	{
		intt diff=suffix[n-j+1]-prefix[j-1]+1;
		sum+=(diff%mod);sum=sum%mod;
	}
	
	cout<<sum<<endl;
}


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

int main(){
    int K,S;
    cin >> K >> S;
    int z,ans=0;
    for(int i=0;i < K+1;i++){
        for(int j=0;j < K+1;j++){
            if(i + j + K >= S && i + j <= S){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int N;
    cin>>N;
    vector<pair<int,int>>p;
    vector<int>time;
    time.push_back(0);
    p.push_back(make_pair(0,0));
    for(int i=0;i<N;i++){
        int t,x,y;
        cin>>t>>x>>y;
        time.push_back(t);
        p.push_back(make_pair(x,y));
    }
    vector<int>v;

    for (int i=0;i<=N;i++){
        v.push_back(p[i].first+p[i].second);
        //cout<<v[i]<<endl;

    }
    bool flag=true;
    
    for(int i=0;i<N;i++){
        if((time[i+1]-time[i])%2==0){

        
        if(abs(v[i+1]-v[i])-(time[i+1]-time[i])>0 || abs(v[i+1]-v[i])%2==1)
        {   flag=false;
            break;
        }
    }
        else{
            if(abs(v[i+1]-v[i])-(time[i+1]-time[i])>0 || abs(v[i+1]-v[i])%2==0){
                flag=false;
                break;
            }
            
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 2288
if __name__=="__main__":
    N, M, X = map(int, input().split(' '))
    book_list = [None]*N
    min_price = -1
    for i in range(N):
        book_list[i] = list(map(int, input().split(' ')))

    for i in range(2 ** N):
        comp_list = []
        for j in range(N):
            if ((i >> j) & 1):
                if comp_list == []:
                    comp_list = book_list[j]
                else:
                    comp_list = [a + b for a, b in zip(comp_list, book_list[j])]

                if all(comp >= X for comp in comp_list[1:]):
                    if min_price == -1:
                        min_price = comp_list[0]
                    elif comp_list[0] <= min_price:
                        min_price = comp_list[0]
    print(min_price)

Measured memory_bytes: 9236
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    grid = list(list(input()) for _ in range(H))

    res = [[0] * W for _ in range(H)]
    visited = [[False] * W for _ in range(H)]
    for y in range(H):
        for x in range(W):
            if grid[y][x] == "#":
                visited[y][x] = True
                que = deque([[y, x]])
                cnt = 1
                tmp = []
                while que:
                    h, w = que.popleft()
                    for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                        next_h, next_w = h + dh, w + dw
                        if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                            continue
                        if grid[h][w] == "#" and grid[next_h][next_w] == ".":
                            if not visited[next_h][next_w]:
                                que.append([next_h, next_w])
                                tmp.append([next_h, next_w])
                                visited[next_h][next_w] = True
                        elif grid[h][w] == "." and grid[next_h][next_w] == "#":
                            if not visited[next_h][next_w]:
                                cnt += 1
                                que.append([next_h, next_w])
                                visited[next_h][next_w] = True
                for h, w in tmp:
                    res[h][w] = cnt
    ans = 0
    for h in range(H):
        ans += sum(res[h])
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 21756
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();
        long r = sc.nextLong();
        long sum = b+r;

        long ans = 0;
        ans = (n/sum)*b;
        ans = ans+(Math.min(n%sum,b));

        
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
#include <stdio.h>

int main(void) {
	int X, A, B;
	int dounatu;
	if (scanf("%d", &X) != 1) return 1;
	if (scanf("%d", &A) != 1) return 1;
	if (scanf("%d", &B) != 1) return 1;
	dounatu = (X - A) / B;
	printf("%d\n", X - A - B * dounatu);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(void){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int res = 2000000000;
    for(int c=0;c <= max(X, Y); c++){
        int cost = 2*C*c;
        cost += A*max(X-c, 0);
        cost += B*max(Y-c, 0);
        res = min(res, cost);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

double p, e, t;

double dfs(int k, double r, double l){
    double h = (r + l) / 2;

    if(k == 0){
        if(abs(t - h) < e) return 1;
        else return 0;
    }

    if(t - e <= l && r <= t + e) return 1;
    else if(r < t - e || t + e < l) return 0;

    if(h >= t){
        return  p * dfs(k - 1, r, h) + (1 - p) * dfs(k - 1, h, l);
    }else{
        return  p * dfs(k - 1, h, l) + (1 - p) * dfs(k - 1, r, h);
    }
}

int main(){
    int k;
    double r,l;
    cin >> k >> l >> r >> p >> e >> t;
    cout <<fixed << setprecision(10)<< dfs(k, r, l) << endl;
}

Measured memory_bytes: 3280
#include <iostream>
#include <queue>

#define MAX_N 100

using namespace std;

int main(int argc, char const *argv[])
{
	int n,r;
	int p,c;
	int h[MAX_N];

	while(1){

		cin>>n>>r;
		if (n+r==0){
			break;
		}

		for(int i1=0;i1<n;i1++){
			h[i1]=n-i1;
		}

		for(int i1=0;i1<r;i1++){
			cin>>p>>c;
			queue<int> q1;
			queue<int> q2;

			for(int i2=0;i2<p-1;i2++){
				q1.push(h[i2]);
			}
			for(int i2=0;i2<c;i2++){
				q2.push(h[i2+p-1]);
			}
			for(int i2=0;i2<p-1+c;i2++){
				if(i2<c) {
					h[i2]=q2.front();
					q2.pop();
				}
				else {
					h[i2]=q1.front();
					q1.pop();
				}
			}
		}
		cout<<h[0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200