akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scanner()
	x := make([]int, len(s))
	for i, r := range s {
		x[i] = int(r) - 97
	}
	k := intScanner()
	for i := 0; i < len(s); i++ {
		if k+x[i] >= 26 && x[i] != 0 {
			k -= 26 - x[i]
			x[i] = 0
		}
	}
	x[len(x)-1] = (x[len(x)-1] + k) % 26
	for _, r := range x {
		fmt.Print(string(rune(r + 97)))
	}
	fmt.Println("")
}


Measured memory_bytes: 3968
# -*- coding: utf-8 -*-
import collections
import math

N, P = map(int, input().split())

insuList=[]
warukazu = 2
while (warukazu <= math.sqrt(P) +1):
  if P % warukazu == 0:
    P = P / warukazu
    insuList.append(warukazu)
  else:
    warukazu+=1
insuList.append(P)

ans=1
c=collections.Counter(insuList)
for key in c.keys():
  while c[key] >= N:
    ans=ans*key
    c[key] -= N

print(int(ans))

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;

int n,p[51];
bool swapped=false, ans=true;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>p[i];
	}
	for(int i=1;i<=n;i++){
		if(p[i] == i)
			continue;
		if(!swapped){
			int temp = p[p[i]];
			p[p[i]] = p[i];
			p[i] = temp;
			swapped = true;
			if(p[i] == i)
				continue;
			else{
				ans = false;
				break;
			}
		}
		else{
			ans = false;
			break;
		}
	}
	if(ans)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

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

int main() {
  int  n,m;
  cin >> n >> m;
  if (n%2){
    for(int i = 1;i <= m;i++){
      cout << i << " " << m*2+1-i << endl;
    }
  }else{
    for(int i = 1,j=m*2+1;i <= m;i++,j--){
      if(m%2){
	if(j-i-1 == m){
	  j -= 1;
	  cout << i << " " << j << endl;
	}else{
	  cout << i << " " << j << endl;
	}
      }else{
	if(j-i == m){
	  j -= 1;
	  cout << i << " " << j << endl;
	}else{
	  cout << i << " " << j << endl;
	}
      }
    }
  }
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[100000];
  int sum = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    if(a[i] % 2 != 0 ) {
      sum ++;
    }
  }
  
  if(sum % 2 == 0) {
    cout <<"YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}
  

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

using namespace std;

int main() {
	int n, k, ans = 1e9;
	cin >> n >> k;
	vector <int> a, b;
	for (int i = 0; i < n; ++i) {
		int tr;
		cin >> tr;
		if (tr >= 0) {
			a.push_back(tr);
		}
		else
			b.push_back(-tr);
	}
	sort((a).begin(), (a).end());
	sort((b).begin(), (b).end());
	int P = a.size();
	int M = b.size();
	for (int i = 0; i < k + 1; ++i) {
		int j = k - i;
		if (i > P || j > M) {
			continue;
		}
		int pd = 0;
		if (i) {
			pd = a[i - 1];
		}
		int md = 0;
		if (j) {
			md = b[j - 1];
		}
		ans = min(ans, 2 * min(pd, md) + max(pd, md));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;

ll largestAreaHistogram(vi v){
  ll N=v.size();
  stack<pii> st; st.push({0,v[0]});
  ll ans=v[0];
  FOR(i,1,N) {
    ll tmp=i;
    while(st.size()&&st.top().second>v[i]) {
      ans=max(ans,st.top().second*(i-st.top().first));
      tmp=st.top().first;
      st.pop();
    }
    st.push({tmp,v[i]});
  }
  while(st.size()) {
    ans=max(ans,st.top().second*(N-st.top().first));
    st.pop();
  }
  return ans;
}

int main(){
  ll H,W; cin>>H>>W;
  vvi c(H,vi(W));
  REP(h,H) REP(w,W) cin>>c[h][w];
  vvi dp(H,vi(W));
  REP(w,W) if(c[0][w]==0) dp[0][w]=1; else dp[0][w]=0;
  FOR(h,1,H) REP(w,W) if(c[h][w]==0) dp[h][w]=dp[h-1][w]+1; else dp[h][w]=0;
  ll ans=0; REP(h,H) ans=max(ans,largestAreaHistogram(dp[h]));
  cout<<ans<<endl;
}

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

int main(){
    int X;
    cin >> X;
    if(X < 600) cout << 8 << endl;
    else if(X < 800) cout << 7 << endl;
    else if(X < 1000) cout << 6 << endl;
    else if(X < 1200) cout << 5 << endl;
    else if(X < 1400) cout << 4 << endl;
    else if(X < 1600) cout << 3 << endl;
    else if(X < 1800) cout << 2 << endl;
    else cout << 1 << endl;

}

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

int main() {
    int n, x[1000] = {}, y[1000] = {};
    double d[4] = {};

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> y[i];
    }

    double max_ = 0;
    for (int i = 0; i < n; i++) {
        double diff = abs(x[i] - y[i]);
        d[0] += diff;
        d[1] += pow(diff, 2);
        d[2] += pow(diff, 3);
        d[3] = max(d[3], diff);
    }
    d[1] = sqrt(d[1]);
    d[2] = cbrt(d[2]);

    cout << fixed << setprecision(5);
    for (int i = 0; i < 4; i++) {
        cout << d[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3412
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

struct Point{
	int x, y;
	int num;
};

struct Node{
	int l, r;
	int location;
};

bool sortByX(const Point &left, const Point &right){
	return left.x < right.x;
}

bool sortByY(const Point &left, const Point &right){
	return left.y < right.y;
}

#define MAX_N 510000
#define NIL (-1)

Point P[MAX_N];
Node T[MAX_N];
int np;

int make2DTree(int l, int r, int depth){
	if(l >= r){
		return NIL;
	}
	int mid = (l + r) / 2;
	int t = np++;
	
	if(depth % 2 == 0){
		sort(P + l, P + r, sortByX);
	}else {
		sort(P + l, P + r, sortByY);
	}
	
	T[t].location = mid;
	T[t].l = make2DTree(l, mid, depth + 1);
	T[t].r = make2DTree(mid + 1, r, depth + 1);
	
	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<int> &ans){
	Point p = P[T[v].location];
	int x = p.x;
	int y = p.y;
	int num = p.num;
	
	if(sx <= x && x <= tx && sy <= y && y <= ty){
		ans.push_back(num);
	}
	
	if(depth % 2 == 0){
		if(T[v].l != NIL && sx <= x){
			find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		}
		if(T[v].r != NIL && x <= tx){
			find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	}
	else {
		if(T[v].l != NIL && sy <= y){ 
			find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		}
		if(T[v].r != NIL && y <= ty){
			find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	}
}

int main(){
	
	int n, q;
	cin >> n;
	
	for(int i = 0; i < n; i++){
		scanf("%d %d", &P[i].x, &P[i].y);
		P[i].num = i;
		T[i].l = T[i].r = T[i].location = NIL;
	}
	
	np = 0;
	int root = make2DTree(0, n, 0);
	
	cin >> q;
	
	for(int i = 0; i < q; i++){
		int sx, tx, sy, ty;
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		
		vector<int> ans;
		find(root, sx, tx, sy, ty, 0, ans);
		
		sort(ans.begin(), ans.end());
		
		for(int j = 0; j < ans.size(); j++){
			printf("%d\n", ans[j]);
		}
		printf("\n");
	}
	
	return 0;
}



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

using Vec = vector<int>;

vector<Vec> transpose(vector<Vec>& mat) {
    int m = mat.size(),
        n = mat[0].size();
    vector<Vec> res(n, Vec(m));
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            res[r][c] = mat[c][r];
        }
    }
    return res;
}

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    if (H % h == 0 and W % w == 0) {
        cout << "No" << endl;
        return 0;
    }

    vector<Vec> a(H, Vec(W));

    bool trans = false;
    if (H % h != 0) {
        trans = true;
        swap(H, W);
        swap(h, w);
        a = transpose(a);
    }

    int x = (W / w) / (W % w) + 1;

    for (int r = 0; r < H; r++) {
        for (int c = 0; c < W; c++) {
            if ((r + 1) % h == 0 and (c + 1) % w == 0) a[r][c] = -(h * w - 1) * x - 1;
            else a[r][c] = x;
        }
    }
    
    if (trans) {
        swap(H, W);
        a = transpose(a);
    }

    cout << "Yes" << endl;
    for (int r = 0; r < H; r++) {
        for (int c = 0; c < W; c++) {
            cout << a[r][c] << " ";
        }
        cout << endl;
    }
    return 0;
}

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

int main(){
    
    int S, h, m, s;
    cin >> S;
    
    s = S % 60;
    m = (S - s) / 60 % 60;
    h = ((S - s) / 60 - m) / 60;
    
    cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,N,r,l,sum;
  cin >> N;
  
  for(i=0,sum=0;i<N;i++){
  	cin >> r >> l;
    sum += l - r + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
from collections import deque
import numpy as np
def main():
    hw = list(map(int, input().split()))
    s = np.zeros((hw[0],hw[1]), dtype=int)
    validpoints = []
    for i in range(hw[0]):
        tmp = input()
        tm = [None]*hw[1]
        for j in range(hw[1]):
            if tmp[j] == '.':
                tm[j] = 0
                validpoints.append((i,j))
            elif tmp[j] == '#':
                tm[j] = 1
        s[i] = np.array(tm)

    ma = 0

    for i in validpoints:
        cost = breadth(s,i)
        if cost > ma:
            ma = cost
    print(ma)

def breadth(ss, start):
    q = deque()
    visited = np.array(ss)
    visited[start] = 1
    q.append({start})
    c = 0

    while not len(q) == 0:
        c += 1
        v = q.pop()
        tmpl = []
        for i in v:
            visited[i] = 1
            child = get_child_quad(ss, visited, i)
            tmpl.extend(child)
        tmps = set(tmpl)
        if len(tmps) > 0:
            for i in tmps:
                visited[i] = 1
            q.append(set(tmpl))

    return c-1

def get_child_quad(ss, visited, p):
    down = (p[0]+1,p[1])
    up = (p[0]-1,p[1])
    right = (p[0],p[1]+1)
    left = (p[0],p[1]-1)
    child = [down,up,right,left]
    return list(filter(lambda pp: 0 <= pp[0] < len(ss) and 0 <= pp[1] < len(ss[0]) and visited[pp[0],pp[1]] == 0, child))

if __name__ == '__main__':
    main()

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/f.in", "r", stdin);
//  freopen("../IO/f.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

void solve(std::istream &in, std::ostream &out) {
  int n, ma, mb;
  in >> n >> ma >> mb;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; ++i) {
    in >> a[i] >> b[i] >> c[i];
  }
  vector<vector<int>> dp(401,vector<int>(401,numeric_limits<int>::max()/2));
  dp[0][0]=0;
  for (int i = 0; i < n; ++i) {
    for (int cost1 = 400 - a[i]; cost1 >= 0; --cost1) {
      for (int cost2 = 400 - b[i]; cost2 >= 0; --cost2) {
        dp[cost1 + a[i]][cost2 + b[i]] = min(dp[cost1 + a[i]][cost2 + b[i]], dp[cost1][cost2] + c[i]);
      }
    }
  }
  int ans = numeric_limits<int>::max() / 2;
  for (int mpl = 1; mpl * max(ma, mb) <= 400; ++mpl) {
    ans = min(ans, dp[mpl * ma][mpl * mb]);
  }
  if (ans == numeric_limits<int>::max() / 2)
    ans = -1;
  out << ans << '\n';
}


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

#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13

using namespace std;

int translateChar(char ch){

    switch(ch){
    case 'A':
        return  1;
    case 'C':
        return  2;
    case 'G':
        return  3;
    case 'T':
        return  4;
    }
}


int translateStr(char buf[]){
    int sum = 0,mult = 1;
    for(int i = 0; buf[i] != '\0'; i++){
        sum += translateChar(buf[i])*mult;
        mult *= 4;
    }
    return sum - 1;
}

int main(){

    int n;
    scanf("%d",&n);
    char order[ORDER_LENGTH],str[STR_LENGTH];

    char* check_table = new char[TABLE_SIZE];

    for(int i = 0; i < n; i++){
        scanf("%s %s",order,str);
        if(order[0] == 'i'){
            check_table[translateStr(str)] = 'Y';
        }else{
            if(check_table[translateStr(str)] == 'Y'){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
}

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

typedef long long ll;
typedef pair<int, int> pii; 
const int N = 1e5+5, mod = 1e9+7;

void solve() {
    int n; cin >> n;

    if (n >= 400 && n <= 599) {
        cout << 8 << endl;
    } else if (n >= 600 && n <= 799) {
        cout << 7 << endl;
    } else if (n >= 800 && n <= 999) {
        cout << 6 << endl;
    } else if (n >= 1000 && n <= 1199) {
        cout << 5 << endl;
    } else if (n >= 1200 && n <= 1399) {
        cout << 4 << endl;
    } else if (n >= 1400 && n <= 1599) {
        cout << 3 << endl;
    } else if (n >= 1600 && n <= 1799) {
        cout << 2 << endl;
    } else if (n >= 1800 && n <= 1999) {
        cout << 1 << endl;
    }

}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1; 
    while (t--) solve();
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>

using namespace std;

string divide[4] = { "dream", "dreamer", "erase", "eraser" };

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

	reverse(s.begin(), s.end());
	for (int i = 0; i < 4; i++) {
		reverse(divide[i].begin(), divide[i].end());
	}

	bool can = true;

	for (auto i = 0; i < s.size();) {
		bool can2 = false;
		for (int j = 0; j < 4; j++) {
			string d = divide[j];
			if (s.substr(i, d.size()) == d) {
				can2 = true;
				i += d.size();
				break;
			}
		}
		if (!can2) {
			can = false;
			break;
		}
	}

	if (can) cout << "YES";
	else cout << "NO";

	return 0;
}

Measured memory_bytes: 3236
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################
x = int(input())
arr = [i for i in range(8,-1,-1)]
ans = 0
if 400 <= x < 600:
	ans = arr[0]
elif 600 <= x < 800:
	ans = arr[1]
elif 800 <= x < 1000:
	ans = arr[2]
elif 1000 <= x < 1200:
	ans = arr[3]
elif 1200 <= x < 1400:
	ans = arr[4]
elif 1400 <= x < 1600:
	ans = arr[5]
elif 1600 <= x < 1800:
	ans = arr[6]
elif 1800 <= x < 2000:
	ans = arr[7]

print("{}".format(ans))








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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

int main() {
    int N;
    cin >> N;
    vector<lli> A(N), B(N);
    REP (i, 0, N) cin >> A[i];
    REP (i, 0, N) cin >> B[i];
    lli x = 0, y = 0;
    REP (i, 0, N) {
        if (A[i] >= B[i]) {
            y += (A[i] - B[i]);
        } else {
            x += ((B[i] - A[i] + 1) / 2);
            y += (B[i] - A[i]) % 2;
        }
    }
    /*
    if (y == 0) {
        cout << "Yes" << endl;
    } else if (x == 0 || x < y) {
        cout << "No" << endl;
    } else {
        cout << (x % y == 0 ? "Yes" : "No") << endl;
    }
    //*/
    cout << (x >= y ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;

// エラトステネスの篩
std::vector<int> Eratosthenes(int max){
	std::vector<int> list;
	// 2 ~ maxの配列 / 初期化
	std::vector<int> v;
	for (size_t i = 2; i < max; i++) {
		v.push_back(i);
	}
	while (v.size() > 0) {
		std::vector<int> temp;
		list.push_back(v[0]);
		for (size_t i = 0; i < v.size(); i++) {
			if (v[i] % v[0] != 0) {
				temp.push_back(v[i]);
			}
		}
		v = temp;
	}

	return list;
}

int main(int argc, char const *argv[]) {
	int Q;
	std::cin >> Q;
	std::vector<pair<int,int>> v;
	int maxr = -1;
	for (size_t i = 0; i < Q; i++) {
		int l,r;
		std::cin >> l >> r;
		v.push_back(make_pair(l,r));
		maxr = max(r,maxr);
	}
	maxr++;
	std::vector<int> sosuu(Eratosthenes(maxr));


	// 素数列があるので、1~iについて2017に似た数字がいくつあるかを保有する配列が作れる
	std::vector<int> like;
	// like_(i+1) = like(i) + 1 (if i+1が2017に似た数の時)
	// like_(i+1) = like(i) (otherware)
	//0,1,2は似ていないので0
	like.push_back(0);
	like.push_back(0);
	like.push_back(0);
	// 3~maxrについて2017に似ているか考える
	for (size_t i = 3; i < maxr; i++) {
		int x = 0;
		int last = like[like.size() - 1];
		for (size_t j = 0; j < sosuu.size(); j++) {
			if (i == sosuu[j]) {
				x++;
			}
			if ((i + 1) / 2 == sosuu[j]) {
				x++;
			}
		}
		// iが2017に似た数の時
		if (x == 2) {
			like.push_back(last + 1);
		}
		else {
			like.push_back(last);
		}
	}

	for (size_t i = 0; i < v.size(); i++) {
		std::cout << like[v[i].second] - like[v[i].first - 1] << '\n';
	}
	return 0;
}


Measured memory_bytes: 2336
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        int n = sc.nextInt();
        int w = sc.nextInt();
        int[][] item = new int[n][2];

        for (int i=0; i<n; i++) {
            item[i][0] = sc.nextInt();
            item[i][1] = sc.nextInt();
        }

        long[][] dp = new long[n+1][w+1];

        for (int i=1; i<=n; i++) {
            int weigh = item[i-1][0];
            int val = item[i-1][1];
            inner:
            for (int j=1; j<=w; j++) {
//                if (j < dp[i-1][j]+weigh) continue inner;
                if (0<=j-weigh && j-weigh<=w) {
                    dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-weigh]+val);
                } else {
                    dp[i][j] = dp[i-1][j];
                }
            }
        }

//        System.out.println(dp[1][3]);
//        System.out.println(dp[2][3]);
//        System.out.println(dp[n-2][w]);
//        System.out.println(dp[n-1][w]);
        System.out.println(dp[n][w]);

    }
}




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

int main(void) {
	int N; cin >> N;
	int a[N]; int x=0, y=0;
	int i;
	for (i = 0; i < N; i++) {
		cin >> a[i];
	}

	sort(a, a + N);

	for (i = N - 1; i >= 0; i -= 2) {
		x += a[i];
		if (i == 0) {
			break;
		}
		y += a[i - 1];
	}

	cout << x - y << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>
using namespace std;
#define INF 1 << 29

#define elif else if
#define read cin >>
#define echo cout <<
#define fin << '\n'
#define endl '\n'

int main(){
	int a;
	read a;
	if ( a < 1200 ) echo "ABC\n";
	elif ( a < 2800 ) echo "ARC\n";
	else echo "AGC\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

constexpr ll mod = 1e9 + 7;
const double PI = acos(-1.0);

vector<int> par;
vector<int> rak; // number of edges
vector<ll> sum; // sum of the weight of vertices
vector<int> ans; // number of edges satisfied

void init(const int& n) {
  par.resize(n+1);
  rak.resize(n+1, 0);
  sum.resize(n+1);
  ans.resize(n+1, 0);
  for(int i=1; i<=n; i++) {
    par.at(i) = i;
    cin >> sum[i];
  }
}

int find(int x) {
  if (par.at(x) == x) {
    return x;
  } else {
    return par.at(x) = find(par.at(x));
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x==y) return;
  if (rak.at(x) < rak.at(y)) {
    rak[y] += rak[x];
    sum[y] += sum[x];
    ans[y] += ans[x];
    par.at(x) = y;
  } else {
    rak[x] += rak[y];
    sum[x] += sum[y];
    ans[x] += ans[y];
    par.at(y) = x;
  }
}

void calc(int x, const ll& len) {
  x = find(x);
  rak[x]++;
  if (len <= sum[x]) {
    ans[x] = rak[x];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  init(n);
  vector<pair<int, P>> vec(m);
  rep(i, m) {
    int a, b, y; cin >> a >> b >> y;
    vec[i] = make_pair(y, P(a,b));
  }

  sort(vec.begin(), vec.end());

  for(auto e: vec) {
    auto a = e.second.first;
    auto b = e.second.second;
    auto len = e.first;
    unite(a,b);
    calc(a,len);
    //debug(x); debug(rak[x]); debugln(ans[x]);
  }
  cout << m - ans[find(1)] << endl;
}

Measured memory_bytes: 3456
//include
//--------------------------------------------------
#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<ctime>

using namespace std;

//conversion
//--------------------------------------------------
inline int toInt(const string &s){
    int v;istringstream sin(s);sin>>v;
    return v;
}
template<class T> inline string toString(T x){
    ostringstream sout;sout<<x;
    return sout.str();
}

//math
//--------------------------------------------------
template<class T> inline T sqr(T x){return x*x;}

//typedef
//--------------------------------------------------
typedef vector<int>VI;
typedef vector<VI>VVI;
typedef vector<string>VS;
typedef pair<int,int>PII;
typedef long long LL;

//container util
//--------------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//--------------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------------
const int INF=1e9+7;
const int dx[]={0,-1,0,1};
const int dy[]={-1,0,1,0};

//clear memory
#define CLR(a) memset((a),0,sizeof(a))

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

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

char cnv(char x,int t){
    int val=x-'a'+t;
    val%=26;
    return val+'a';
}

int abs(int x){
    if(x<0)x*=-1;
    return x;
}

int N;
string str;
int A[100],B[100];

string solve(){
    REP(i,N){
        int a=A[i],b=B[i];
        swap(str[a],str[b]);
        int t=abs(a-b);
        str[a]=cnv(str[a],t);
        str[b]=cnv(str[b],t);
    }
    return str;
}


int main(){
    while(cin>>N,N){
        cin>>str;
        REP(i,N){
            cin>>A[i]>>B[i];
            A[i]--;B[i]--;
        }
        reverse(A,A+N);
        reverse(B,B+N);
        cout<<solve()<<endl;
    }

    return 0;
}

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

int main(){
 
  int N, i, a;
  cin >> N;
  vector<int> p(N), _p(N);
  for (i = 0; i < N; i++) {
    cin >> p.at(i);
    _p.at(i) = p.at(i);
  }
  
  sort(_p.begin(), _p.end());
  
  int count = 0;
  for (i = 0; i < N; i++){
    if(_p.at(i) != p.at(i)) count++;
  }
  
  if (count == 2 || count == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = long.Parse(line[0]);
        var a = long.Parse(line[1]);
        var b = long.Parse(line[2]);
        if (a > b) { Console.WriteLine(0); goto end; }
        if (a != b && n == 1) { Console.WriteLine(0); goto end; }
        else if (a == b && n == 1) { Console.WriteLine(1); goto end; }
        var mmax = a + b + (n - 2) * b;
        var mmin = a + b + (n - 2) * a;
        var ret = mmax - mmin + 1;
        Console.WriteLine(ret);
        end:;
    }
}

Measured memory_bytes: 11092
#include<iostream>
   using namespace std;
int main()
{
  int n,m,l;
  cin>>n>>m>>l;
  int A[n][m],B[m][l];
  long long int C;
  for(int i=0;i<n;i++){
    for(int u=0;u<m;u++){
      cin>>A[i][u];
    }
  }
  for(int t=0;t<m;t++){
    for(int s=0;s<l;s++){
      cin>>B[t][s];
    }
  }
  for(int y=0;y<n;y++){
    for(int z=0;z<l;z++){
      C=0;
      for(int f=0;f<m;f++){
        C+=A[y][f]*B[f][z];
      }
      if(y==n-1 && z==l-1)cout<<C<<endl;
      else if(z==l-1)cout<<C<<endl;
      else cout<<C<<" ";
      
    }
  }
  return 0;
}


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

const int INF = 1 << 29;

struct position {
    int h, w;
    position() {}
    position(int a, int b): h(a), w(b) {}
};

struct state {
    position left, right;
    int cost;
    state() {}
    state(position l, position r, int c): left(l), right(r), cost(c) { }
};

const int dh[4] = {1, 0, -1, 0};
const int dw[4] = {0, 1, 0, -1};

int W, H;
string rooml[55], roomr[55];

int memo[55][55][55][55];

int get_memo(position left, position right) {
    return memo[left.h][left.w][right.h][right.w];
}

void update_memo(position left, position right, int value) {
    memo[left.h][left.w][right.h][right.w] = value;
}

position move(position p, int dir) {
    return position(p.h+dh[dir], p.w+dw[dir]);
}

bool solve() {
    cin >> W >> H;
    if (W+H==0) { return false; }
    for (int j = 0; j < H; ++j) {
        cin >> rooml[j] >> roomr[j];
    }

    position sl, sr, gl, gr;

    for (int j = 0; j < H; ++j) {
        for (int k = 0; k < W; ++k) {
            if (rooml[j][k] == 'L') { sl.h = j; sl.w = k; }
            if (roomr[j][k] == 'R') { sr.h = j; sr.w = k; }

            if (rooml[j][k] == '%') { gl.h = j; gl.w = k; }
            if (roomr[j][k] == '%') { gr.h = j; gr.w = k; }
        }
    }

    for (int j = 0; j < H; ++j) {
        for (int k = 0; k < W; ++k) {
            for (int l = 0; l < H; ++l) { fill(memo[j][k][l], memo[j][k][l]+W, INF); }
        }
    }

    queue<state> que;
    que.emplace(sl, sr, 0);
    update_memo(sl, sr, 0);

    int result = INF;
    while (!que.empty()) {
        state st = que.front(); que.pop();

        if (get_memo(st.left, st.right) < st.cost) { continue; }

        if ((rooml[st.left.h][st.left.w] == '%') != (roomr[st.right.h][st.right.w] == '%')) {
            continue;
        }

        if ((rooml[st.left.h][st.left.w] == '%') && (roomr[st.right.h][st.right.w] == '%')) {
            result = st.cost;
            break;
        }

        for (int d = 0; d < 4; ++d) {
            position nexl = move(st.left, d);
            position nexr = move(st.right, (4-d)%4);

            if (nexl.h < 0 || nexl.h >= H || nexl.w < 0 || nexl.w >= W) { nexl = st.left; }
            if (nexr.h < 0 || nexr.h >= H || nexr.w < 0 || nexr.w >= W) { nexr = st.right; }

            if (rooml[nexl.h][nexl.w] == '#') { nexl = st.left; }
            if (roomr[nexr.h][nexr.w] == '#') { nexr = st.right; }

            if (get_memo(nexl, nexr) > st.cost+1) {
                update_memo(nexl, nexr, st.cost+1);
                que.emplace(nexl, nexr, st.cost+1);
            }
        }
    }

    cout << (result == INF ? "No" : "Yes") << endl;

    return true;
}

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

Measured memory_bytes: 33744
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"

	"strconv"
)

func solve(in io.Reader, out io.Writer) error {
	sc := bufio.NewScanner(in)
	sc.Split(bufio.ScanWords)

	n, m := nextInt(sc), nextInt(sc)

	fmt.Fprintf(out, "%d\n", calc(n, m))
	return nil
}

func calc(n, m int) int {
	if n == 1 && m == 1 {
		return 1
	} else if n == 1 || m == 1 {
		if n > m {
			return n - 2
		} else {
			return m - 2
		}
	}
	return (n - 2) * (m - 2)
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	err := solve(os.Stdin, os.Stdout)
	if err != nil {
		log.Fatal(err)
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    using i64=int_fast64_t;
    i64 a;
    static constexpr i64 MOD=998244353;
    modint(){a=0;}
    modint(i64 a_){
        a=a_%MOD;
        if(a<0) a+=MOD;
    }
    modint inv()const{
        i64 n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y;
        y.a=n;
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y;
        y.a=a+x.a;
        if(y.a>=MOD) y.a-=MOD;
        return y;
    }
    modint operator-(const modint& x){
        modint y;
        y.a=a-x.a;
        if(y.a<0) y.a+=MOD;
        return y;
    }
    modint operator*(const modint& x){
        modint y;
        y.a=(a*x.a)%MOD;
        return y;
    }
    modint operator/(const modint& x){
        modint y;
        y.a=(a*x.inv().a)%MOD;
        return y;
    }
    modint& operator+=(const modint& x){
        a+=x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint& operator-=(const modint& x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint& operator*=(const modint& x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint& operator/=(const modint& x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    int_fast64_t a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(int_fast64_t a,int_fast64_t b){
    modint _;
    int_fast64_t n=1,A=a;
    while(b){
        if(b&1) (n*=A)%=modint::MOD;
        (A*=A)%=modint::MOD;
        b>>=1;
    }
    _.a=n;
    return _;
}

vector<modint> p;

vector<modint> solve(int n){
    int m,a,b;
    vector<vector<int>> e(n);
    cin>>m;
    fr(i,m){
        cin>>a>>b;
        if(a>b) swap(a,b);
        e[a-1].emplace_back(b-1);
    }
    vector<int> v(n);
    vector<modint> c;
    vector<bool> q(n+1);
    ifr(i,n){
        fr(j,e[i].size()+1) q[j]=false;
        for(auto&j:e[i]) q[v[j]]=true;
        fr(j,e[i].size()+1) if(!q[j]){
            if(c.size()==j) c.emplace_back();
            c[v[i]=j]+=p[i+1];
            break;
        }
    }
    return c;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;
    p.resize(n+1);
    modint e18=pwr(10,18);
    p[0]=1;
    fr(i,n) p[i+1]=p[i]*e18;
    auto c0=solve(n),c1=solve(n),c2=solve(n);
    modint ans;
    fr(i,c0.size()) fr(j,c1.size()) if((i^j)<c2.size()){
        ans+=c0[i]*c1[j]*c2[i^j];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5632
a, b = map(int, input().split())

fi = str(a)*b
se = str(b)*a

num = max(a, b)

for i in range(num):
    ff = int(fi[i])
    ss = int(se[i])
    if ff<ss:
        print(fi)
        break
    elif ss<ff:
        print(se)
        break
    else:
        pass

    if i==num-1:
        print(fi)

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

using namespace std;
vector<long long> factors;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);

int main()
{
	IOS
	int n, k;
	cin >> n >> k;
	vector<ll> a(n + 1);
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	vector<vector<ll>> dp(n + 1, vector<ll>(k + 1));
	for (int i = 0; i <= n; ++i)
	{
		dp[i][0] = 1;
	}
	for (int i = 1; i <= k; ++i)
	{
		dp[0][i] = 0;
	}
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= k; ++j)
		{
			dp[i][j] = ((dp[i-1][j] + dp[i][j-1]) - ((j > a[i])?dp[i-1][j-a[i] - 1]:0) + MOD) % MOD;
		}
	}
	cout << dp[n][k];

	return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lint;

int main(){
    int n;
    cin >> n;
    n--;
    int arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    int cntr = arr[0] + arr[n-1];
    for(int i=0; i<n-1; i++){
        cntr += min(arr[i],arr[i+1]);
    }
    cout << cntr;
    return 0;
}


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

int main() {
 int N;
  cin>>N;
  vector< pair< pair<string,int>,int> >a(N);
  for(int i=0;i<N;i++){
	cin>>a.at(i).first.first>>a.at(i).first.second;
    a.at(i).second=i+1;
    a.at(i).first.second *=-1;
  }
  sort(a.begin(),a.end());
  for(int i=0;i<N;i++){
  cout<<a.at(i).second<<endl;
  }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll a[60],b[60];
ll ans=0;

void dfs(int n,ll x){
	if(x<=0)return;
	if(a[n]<=x){
		ans+=b[n];
		return;
	}
	if(n==0)return;
	if(a[n-1]+2<=x)ans++;
	dfs(n-1,x-1);
	dfs(n-1,x-a[n-1]-2);
}
signed main(){
	int n;ll x;cin>>n>>x;
	a[0]=1;b[0]=1;
	for(int i=1;i<=n;i++)a[i]=a[i-1]*2+3;
	for(int i=1;i<=n;i++)b[i]=b[i-1]*2+1;
	dfs(n,x);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String line[] = br.readLine().split(" ");
        int intArray[] = new int[n];
        for (int i=0; i<n; i++){
            intArray[i] = Integer.parseInt(line[i]);
        }

        int mi = 1000000;
        for (int i=0; i<n; i++){
            mi = Math.min(mi,intArray[i]);
        }
        
        int ma = -1000000;
        for (int i=0; i<n; i++){
            ma = Math.max(ma,intArray[i]);
        }
        
        long sum = 0;
        for (int i=0; i<n; i++){
            sum += (long) intArray[i];
        }
        System.out.println(String.format("%s %s %s", mi , ma, sum));
    }
}

Measured memory_bytes: 25568
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ');
            // 商品の数
            var n = long.Parse(nm[0]);
            // 人気商品の数
            var m = long.Parse(nm[1]);
            // 得票数
            var a = (from x in Console.ReadLine().Split(' ') select long.Parse(x)).ToArray();
            // 得票数
            var sum = a.Sum() / (4m * m);

            var k = 0;

            foreach (var b in a)
            {
                if (b >= sum) k++;
            }

            Console.WriteLine(k >= m ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13396
#include<stdio.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    int a[m];
    for(int i = 0;i < m;i++){
        scanf("%d",&a[i]);
    }
    int dp[n + 1];
    for(int i = 0;i < (n + 1);i++){
        dp[i] = 0;
    }
    dp[0] = 1;
    int j = 0;
    for(int i = 1;i < (n + 1);i++){
        
        if(i == 1){
            dp[i] = 1;
            }else{
            dp[i] += dp[i - 1];
            dp[i] += dp[i - 2];
            }
        if(dp[i] > 1000000007){
            dp[i] %= 1000000007;
        }    


        for(int rj = j;rj < m;rj++){
            if(i == a[rj]){
                dp[i] = 0;
                ++j;
                break;
            }
        }
    }
    printf("%d",dp[n]);
    return 0;
}

Measured memory_bytes: 896
from collections import defaultdict
N = int(input())
MOD = 10**9 + 7


def f(v):
    a = 2
    dic = defaultdict(int)
    while v != 1:
        if v % a == 0:
            dic[a] += 1
            v //= a
        else:
            a += 1
    return dic


if N == 1:
    print(1)
    exit()

dic = defaultdict(int)
for i in range(2, N + 1):
    d = f(i)
    for key, value in d.items():
        dic[key] += value

# print('dic', dic)
ans = 1
for value in dic.values():
    ans *= value + 1
    ans %= MOD
print(ans)


Measured memory_bytes: 3316
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())

    mat = []
    a = []
    b = []

    for _ in range(N):
        x, y = map(int, readline().split())
        a.append(x + y)
        b.append(x - y)

    d1 = max(a) - min(a)
    d2 = max(b) - min(b)

    print(max(d1,d2))


if __name__ == '__main__':
    main()


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;

signed main() {
  IOS;
  int A,B;
  cin >> A >> B;

  if (A >= 6 and A <= 12) B /= 2;
  else if (A <= 5) B = 0;

  cout << B << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
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 print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 
 
int main() {
    int a, b;
    cin >> a >> b;
    string as = "", bs = "";
    rep(i, a) as += to_string(b);
    rep(i, b) bs += to_string(a);
    if (as <= bs) cout << as << endl;
    else cout << bs << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  string s;
  cin >> s;

  ll ans=inf;
  for(ll i=0;i<s.size()-2;i++){
    string t=s.substr(i,3);
    ans=min(ans,abs(753-stoll(t)));
  }
  cout << ans << endl;

}

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

int main(){
  string AU;
  int cnt=0,n;
  bool check=1;
  cin >> n;

  for(int i=0;i<n;i++){
    cin >> AU;
    if(AU[0]=='A')
      cnt++;
    if(AU[0]=='U')
      cnt--;
    if(cnt<0)
      check=0;
  }

  if(check==1 && cnt==0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
double dp[3001]={1};
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        double p;
        cin>>p;
        for(int j=i+1;j>0;j--)
        {
            dp[j]+=(dp[j-1]-dp[j])*p;
        }
    }
    cout<<fixed<<setprecision(10)<<dp[(n+1)/2]<<endl;
}


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



int main()
{
    int x;
    std::cin >> x;

    int i;
    long long res = 0;
    for(i = 0; res < 1000000000; i++){
        res += i;
        if(res >= x)break;
    }
    std::cout << i << std::endl;
}

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

typedef long long ll;
typedef tuple<ll, int, int> tlii;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define all(obj) (obj).begin(), (obj).end()
#define pb push_back
#define str to_string
#define mkp make_pair
#define mkt make_tuple
#define print(out) cout << (out) << endl
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
void chmax(ll &a, ll b) { a = max(a, b); }
void chmin(ll &a, ll b) { a = min(a, b); }

int N;
string S;

bool calc(ll m) {
    string a;
    string b;
    rep(i, 0, N-m*2+1) {
        a = S.substr(i, m);
        b = S.substr(i+m);
        if (b.find(a) != -1) return true;
    }
    return false;
}

ll bisearch_max(ll mn, ll mx) {
    ll ok = mn;
    ll ng = mx;
    ll mid;
    while (ok+1 < ng) {
        mid = (ok+ng) / 2;
        if (calc(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}

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

    cin >> N;
    cin >> S;
    print(bisearch_max(0, N));
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=[""]*n
    t=[0]*n
    for i in range(n):
        ss,tt=input().split()
        s.append(ss)
        t.append(int(tt))
    x=input()
    print(sum(t[s.index(x)+1:]))

if __name__=='__main__':
    main()

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


typedef long long ll;
#define CIN_I(a) ll a;cin>>a;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(s,i,n) for(ll i=s;i<(ll)(n);i++)

int main() {
  CIN_I(N);
  ll res = 0;
  FOR(1, k, N+1) {
    ll sigA = N / k;
    res += sigA*(sigA + 1)*k/2;
  }
  cout << res << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(x-a) > abs(x-b))
    {
        cout << "B" << endl;
    }
    else
    {
        cout << "A" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	string x;
	int t,s,ans;
	t=0;
	s=0;
	ans=0;
	cin >> x;
	for(int i=0;i<x.size();i++){
		if(x[i]=='S'){
			s+=1;
		}else{
			if(s==0){
				ans+=1;
			}else{
				s-=1;
			}
		}
	}
	cout << ans*2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 1000000000000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}

#define MAX 100005
int a[MAX];

signed main(){
	int n,k; cin>>n>>k;
	for(int i=0; i<n; i++) cin>>a[i];
	
	sort(a, a+n);
	int ans=INF;
	for(int i=0; i<n; i++){
		if(i+k-1<n) ans=min(ans, a[i+k-1]-a[i]);
	}
	cout<<ans<<en;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;


int main(){
  int n; cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  int cnt_BA = 0, cnt_A = 0, cnt_B = 0, ans = 0;
  rep(i,n) {
    rep(j,s[i].size()-1) {
      if(s[i][j] == 'A' && s[i][j+1] == 'B') ans++;
    }
    if(s[i][0] == 'B' && s[i].back() == 'A'){
      cnt_BA++;
      continue;
    }
    if(s[i][0] == 'B') cnt_B++;
    if(s[i].back() == 'A') cnt_A++;
  }
  
  int tmp = min(cnt_A, cnt_B);
  if(max(cnt_A,cnt_B) > 0) ans += tmp + cnt_BA;
  else ans += max(cnt_BA - 1, 0);
  cout << ans << endl;
}

Measured memory_bytes: 768
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    else:
        count = 0
        for i in range(1, n + 1):
            for j in range(i + 1, n + 1):
                for k in range(j + 1, n + 1):
                    if i + j + k == x:
                        count += 1
        print(count)



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

#define MIN(a, b) ((a) < (b) ? (a) : (b))

using namespace std;

int main(){
	int n;
	vector<unsigned long long> a(200001);
	unsigned long long baum, b[4][3], minb, ans = 0;
	cin >> n;
	a[0] = 0;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		a[i] += a[i - 1];
		a[i + n] = a[i];
	}
	baum = a[n];
	for (int i = 1; i <= n; i++){
		a[i + n] += baum;
	}
	for (int cut1 = 0; cut1 < n; cut1++){
		int cut2, cut3_1, cut3_2;
		for (cut2 = cut1 + 1; cut2 < cut1 + n; cut2++){
			if (a[cut2] - a[cut1] > baum / 3){
				break;
			}
		}
		for (cut3_1 = cut2; cut3_1 < cut1 - 1 + n; cut3_1++){
			if (a[cut3_1] - a[cut2 - 1] >(baum - (a[cut2 - 1] - a[cut1])) / 2){
				break;
			}
		}
		for (cut3_2 = cut2 + 1; cut3_2 < cut1 + n; cut3_2++){
			if (a[cut3_2] - a[cut2] >(baum - a[cut2] - a[cut1]) / 2){
				break;
			}
		}
		b[0][0] = a[cut2 - 1] - a[cut1];
		b[0][1] = a[cut3_1 - 1] - a[cut2 - 1];
		b[0][2] = baum - b[0][0] - b[0][1];
		b[1][0] = a[cut2 - 1] - a[cut1];
		b[1][1] = a[cut3_1] - a[cut2 - 1];
		b[1][2] = baum - b[1][0] - b[1][1];
		b[2][0] = a[cut2] - a[cut1];
		b[2][1] = a[cut3_2 - 1] - a[cut2];
		b[2][2] = baum - b[2][0] - b[2][1];
		b[3][0] = a[cut2] - a[cut1];
		b[3][1] = a[cut3_2] - a[cut2];
		b[3][2] = baum - b[3][0] - b[3][1];
		for (int i = 0; i < 4; i++){
			minb = MIN(MIN(b[i][0], b[i][1]), b[i][2]);
			if (ans < minb){
				ans = minb;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2596
#include<iostream>
#include <string>
#include <cstring>
using namespace std;
 
int main(){
    int N;
    cin>> N;
  	if(N%10 ==2||N%10 ==4||N%10 ==5||N%10 ==7||N%10 ==9) cout<<"hon"<<endl;
  	else if(N%10 ==0||N%10 ==1||N%10 ==6||N%10 ==8) cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
    return 0;
}

Measured memory_bytes: 3572