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

/*
操作 A: Dに詰められた宝石のうち、左端の宝石を取り出して手に入れる。
操作 B: Dに詰められた宝石のうち、右端の宝石を取り出して手に入れる。
操作 C: 持っている宝石を1つ選んでDの左端に詰める。
操作 D: 持っている宝石を1つ選んでDの右端に詰める。

操作AをA回、操作BをB回行うとする。捨てる操作はK-(A+B)回行える。
A,Bが決まると最適な捨てる回数は一意に定まる。
A+B<=min(N,K)=Rであるから、
・A+BがR通り
・AはさらにR通り
・それらをソートして最適解を導出するのにRlogR
R^3logRは間に合う。
*/

void solve(){
    int n,k;
    cin >> n >> k;
    vector<int> v;
    rep(i,n){
        int tmp;
        cin >> tmp;
        v.emplace_back(tmp);
    }
    int r=min(n,k);
    int ans = 0;
    for(int i=1; i<=r; i++){
        for(int a=0; a<=i; a++){
            int b=i-a;
            priority_queue<int, vector<int>, greater<int>> get;
            rep(left,a){
                get.push(v[left]);
            }
            rep(right,b){
                get.push(v[n-1-right]);
            }
            //cout << "a:" << a << ", b:" << b;
            
            //sort(get.begin(),get.end());
            int sum = 0;
            /*
            rep(t,get.size()){
                sum+=get.top();
                cout << " " << get.top();
                get.pop();
            }
            */
            /*
            rep(t,get.size()){
                sum+=get[t];
                cout << " " << get[t];
            }
            */
            for(int x=0; x<k-a-b; x++){
                if(get.size()==0 || get.top()>=0 ) {
                    //cout << " Yeah "; 
                    break;
                }
                //cout << " top:" << get.top();
                get.pop();
            }

            int siz = get.size();
            rep(t,siz){
                //cout << "+++t+++ " << t << " +++size+++ " << get.size() << " +++top+++ " << get.top();
                sum+=get.top();
                //cout <<  " " << get.top();
                get.pop();
            }

            //cout << ", sum:" << sum << endl;
            ans = max(sum, ans);
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 256
n,m,x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))

# print(n,m,x)
# print(a)

c0 = 0
c1 = 0

for i in range(n):
    if i < x:
        if i in a:
            c0 += 1
    if i > x:
        if i in a:
            c1 += 1

result = min(c0, c1)
print(result)

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

int main () {
  int N;
  cin >> N;
  bool finished = false;
  for(int i = N; i > 0; i--) {
    for(int j = 0; j*j <= N; j++) {
      if (i == j*j) {
        cout << i << endl;
        finished = true;
        break;
      }
    }
    if (finished) break;
  }
}

Measured memory_bytes: 256
n,m = map(int, input().split())

prob = {}


for i in range(m):
  x,y = input().split()
  if x not in prob:
    if y == 'AC':
      prob[x] = [1, 0]
    else:
      prob[x] = [0, 1]
  else:
    if prob[x][0] == 0:
      if y == 'AC':
        prob[x][0] += 1
        answered = True
      else:
        prob[x][1] += 1

ac = 0
wa = 0

for i in prob:
  if prob[i][0] == 1:
    ac += 1
    wa += prob[i][1]

print(ac, wa)

Measured memory_bytes: 29180
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0;i < n;i++)
#define all(n)	n.begin(),n.end()
#define each(i,n) for(auto &i : n)

const int INF = 1e9;

signed main() {

	int n, m;
	cin >> n >> m;

	vector<int> s(n), t(n);
	rep(i, n) {
		cin >> s[i] >> t[i];
	}
	vector<int> p(m);
	rep(i, m) {
		cin >> p[i];
	}
	rep(i, 4){
		p.push_back(+INF + i); m++;
		p.push_back(-INF - i); m++;
	}

	sort(all(p));
	vector<int> sum(m, 0), resum(m, 0);
	for (int i = 2; i < m;i++) {
		sum[i] = sum[i - 2] + p[i] - p[i - 1];
	}
	for (int i = m - 3; i >= 0; i--) {
		resum[i] = resum[i + 2] + p[i + 1] - p[i];
	}

	int ans = 0;
	rep(i, n) {
		if (s[i] < t[i]) {
			int si = upper_bound(p.begin(), p.end(), s[i]) - p.begin();
			int ti = upper_bound(p.begin(), p.end(), t[i]) - p.begin();
			int add = 0;
			if ((si % 2 && ti % 2 == 0) || (si % 2 == 0 && ti % 2)) {
				ti--;
			}
			add += sum[ti] - sum[si] + (p[si] - s[i]) - max(0ll, p[ti] - t[i]);
			ans += add;
		}
		else {
			int si = prev(lower_bound(p.begin(), p.end(), s[i])) - p.begin();
			int ti = prev(lower_bound(p.begin(), p.end(), t[i])) - p.begin();
			int add = 0;
			if ((si % 2 && ti % 2 == 0) || (si % 2 == 0 && ti % 2)) {
				ti++;
			}
			add += resum[ti] - resum[si] + (s[i] - p[si]) - max(0ll, t[i] - p[ti]);
			ans += add;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6668
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string>
#include<string.h>
using namespace std;

int main(){
	int n, r;
	cin >> n >> r;
	if (n >= 10){
		cout << r << endl;
		return 0;
	}
	else{
		cout << r + (100 * (10 - n)) << endl;
	}
	return 0;
}

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

int main() {
  int a, b;
  string op;
  cin >> a >> op >> b;
  int ans;
  if (op == "+") {
    ans = a + b;
  }
  else if (op == "-") {
    ans = a - b;
  }
  else {
    ans = 0;
  }
  cout << ans << endl;

  return 0;
}


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

int n, m, cnt = 0;
const int MAX = 30;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
bool seen[MAX][MAX];
char C[MAX][MAX];

void dfs(int x, int y){
    seen[x][y] = true;
    for(int i = 0; i < 4; i++){
        int nx, ny;
        nx = dx[i] + x;
        ny = dy[i] + y;
        if(nx < 0 or ny < 0 or nx >= n or ny >= m){
            continue;
        }
        if(seen[nx][ny] or C[nx][ny] == '#'){
            continue;
        }
        cnt++;
        dfs(nx, ny);
    }
}

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

    while(cin >> m >> n){
        if(n == 0 and m == 0) return 0;
        
        int sx, sy;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                seen[i][j] = false;
                cin >> C[i][j];
                if(C[i][j] == '@'){
                    sx = i;
                    sy = j;
                }
            }
        }

        cnt = 1;
        dfs(sx, sy);
        cout << cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <queue>
#include <map>
using namespace std;

void chmin(int &a, int b) { if (a > b) a = b; }

int N, M;
int A[310][310];

int main() {
	while (cin >> N >> M) {
		for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) cin >> A[i][j];

		int res = N;
		for (int iter = 0; iter < M; ++iter) {
			map<int, int> ma;
			for (int i = 0; i < N; ++i) {
				int num = 0;
				for (int j = 0; j < M; ++j) {
					if (A[i][j] != 0) {
						num = A[i][j];
						break;
					}
				}
				ma[num]++;
			}
			int tmp = 0;
			int maxv = -1;
			for (map<int, int>::iterator it = ma.begin(); it != ma.end(); ++it) {
				if (tmp < it->second) {
					maxv = it->first;
					tmp = it->second;
				}
			}
			chmin(res, tmp);
			for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) if (A[i][j] == maxv) A[i][j] = 0;

			/*
			cout << endl << iter << ": " << endl;
			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < M; ++j) {
					cout << A[i][j] << " ";
				}
				cout << endl;
			}
			cout << tmp << ", " << maxv << endl;
			*/
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
    long long int a;
    double b;
    scanf("%lld %lf",&a,&b);
    long long int ans = a*(int)b;
    long long int ans2 = a*((int)(b*1000)%1000);
    long long int ans3 = ans + ans2/1000;
    printf("%lld\n",ans3);

    return 0;
}


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

using namespace std;

//#define TEST

signed main(){
    int n;
    cin >> n;
    if (n <= 9){ // nが一桁ならnが答え
        cout << n << endl;
        return 0;
    }
    if (n <= 99){ // nが2桁なら9が答え
        cout << 9 << endl;
        return 0;
    }
    /* nの桁数digを求める */
    int dig = 0;
    int n_copy = n;    
    while (n_copy > 0){
        ++dig;
        n_copy /= 10;
    }
    /* digの確認 */
#ifdef TEST
    cout << "----dig----" << endl;
    cout << dig << endl;
#endif
    /*
        digが偶数だと、
            1桁,3桁,5桁,...,dig - 1桁
        の数の個数が答えなので、
            9 + (999 - 99) + (99999 - 9999) + ...
        を計算する.
        digが奇数だと、
            1桁,3桁,5桁,...,dig - 2桁
        の数とn以下のdig桁の個数が答えなので、
            9 + (999 - 99) + (99999 - 9999) + ...
                + (999...9 - 99...9) + (n - 9999...9)
        を計算する.
     */
    int ans = 9;
#ifdef TEST
    cout << "-----------" << endl;
    cout << "1 : 9" << endl;
#endif
    for (int i = 3;i <= ((dig & 1) ? (dig - 2) : (dig - 1));i += 2){
        int add = ((int)pow(10,i) - 1) - ((int)pow(10,i - 1) - 1);
        ans += add;
#ifdef TEST
        cout << i << " : " << add << endl;
#endif
    }
    if (dig & 1){
        int add = n - ((int)pow(10,dig - 1) - 1);
        ans += add;
#ifdef TEST
        cout << dig << " : " << add << endl;
#endif
    }
#ifdef TEST
    cout << "----ans----" << endl;
#endif
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val xList = readLine()?.split(" ")?.map { it.toInt() } ?: return

    val middleIndex = n / 2
    val sortedX = xList.sorted()

    val middleValue = sortedX[middleIndex] // 真っ二つにしたときに、大きい方の1番目に該当する値
    val lessMiddleValue = sortedX[middleIndex - 1] // 真っ二つにしたときに、小さい方のlastに該当する値

    for (x in xList) {
        if (x >= middleValue) {
            println(lessMiddleValue)
        } else {
            println(middleValue)
        }
    }
}

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

const int MAX_N = 110000;

int dp[MAX_N]; // dp[i] が i についての答え

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

    // 初期化
    for (int i = 0; i < MAX_N; ++i) dp[i] = N; // INF の気持ち
    dp[0] = 0;

    // 配る DP --- dp[n] から遷移を出して行く
    for (int n = 0; n < N; ++n) {
        for (int pow6 = 1; n + pow6 <= N; pow6 *= 6) {
            dp[n + pow6] = min(dp[n + pow6], dp[n] + 1);
        }
        for (int pow9 = 1; n + pow9 <= N; pow9 *= 9) {
            dp[n + pow9] = min(dp[n + pow9], dp[n] + 1);
        }
    }

    cout << dp[N] << endl;
}


Measured memory_bytes: 4028
#include<bits/stdc++.h>
#define ll long long
#define iof ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pi 3.1415926535897
#define mod 1000000007
#define inf (1ll<<60)
using namespace std;
ll arr[405];
ll pre(ll x,ll y)
{
    ll sum=0;
    for(ll i=x;i<=y;i++)
        sum+=arr[i];
    return sum;
}
int main()
{
    iof;
    ll n; cin>>n;
    for(ll i=0;i<n;i++)
      cin>>arr[i];
    ll dp[n+1][n+1];
    for(ll i=0;i<=n;i++)
        for(ll j=0;j<=n;j++)
          dp[i][j]=0;
    ll k=1;

    while(k<n)
    {
        ll i=0,j=k;
        while(j<n)
        {
            dp[i][j]=inf;
            ll s=pre(i,j);
            for(ll a=i;a<j;a++)
            {
                dp[i][j]=min(dp[i][j],dp[i][a]+dp[a+1][j]+s);
            }
            i++;
            j++;
        }
        k++;
    }
    cout<<dp[0][n-1];
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
typedef long long ll;

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<double> v(n);

	for (size_t i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());

	double ave = 0;
	ave = (v[0] + v[1]) / 2;
	for (size_t i = 2; i < n; i++) {
		ave = (ave + v[i]) / 2; 
	}
	cout << setprecision(15) << ave;
	return 0;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int s,w;
	cin>>s>>w;
	if(w >= s){printf("unsafe\n");}
	else{printf("safe\n");}
	
	return 0;
};

Measured memory_bytes: 3632
from math import factorial
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def MS(): return map(str, input().split())

YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = False
show_flg = True

p = None
XY = None
N = None


def main():
    N, M = MI()
    ans = 0
    p = [0] * M
    S = [0] * M
    dic = {}
    # x = LI()

    for i in range(M):
        p[i], S[i] = MS()
        dic[p[i]] = {'AC': False, 'WA': 0}

    for i in range(M):
        if S[i] == 'WA' and dic[p[i]]['AC'] is False:
            dic[p[i]]['WA'] += 1
        elif S[i] == 'AC':
            dic[p[i]]['AC'] = True

    AC = 0
    WA = 0
    for key in dic.keys():
        if dic[key]['AC']:
            AC += 1
            WA += dic[key]['WA']

    print(AC, WA)


if __name__ == '__main__':
    main()


Measured memory_bytes: 97080
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define F first
#define s second
#define int long long		
int x[214514];
string y[214514];
char z[214514];
int sum[214514];
signed main(){
	sc(s)
	if(s=="Sunny")c("Cloudy")
	else if(s=="Cloudy")c("Rainy")
	else c("Sunny")
}				

Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int C = Integer.parseInt(sc.next());
		int X = Integer.parseInt(sc.next());
		int Y = Integer.parseInt(sc.next());
		sc.close();

		int cost = 0;
		if(A + B < 2 * C) {
			if(X > Y) {
				cost = (A + B) * Y + A * (X - Y);
			}else if(X < Y) {
				cost = (A + B) * X+ B * (Y - X);
			}else {
				cost = (A + B) * X;
			}
		}else if(A + B > 2 * C){
			if(X > Y) {
				if(A <= 2 * C) {
					cost = 2 * C * Y + A * (X - Y);
				}else {
					cost = 2 * C * Y + 2 * C * (X - Y);
				}
			}else if(X < Y) {
				if(B <= 2 * C) {
					cost = 2 * C * X + B * (Y - X);
				}else {
					cost = 2 * C * X + 2 * C * (Y - X);
				}
			}else {
				cost = 2 * C * X;
			}
		}else {
			if(X > Y) {
				if(A <= 2 * C) {
					cost = 2 * C * Y + A * (X - Y);
				}else {
					cost = 2 * C * Y + 2 * C * (X - Y);
				}
			}else if(X < Y) {
				if(B <= 2 * C) {
					cost = 2 * C * X + B * (Y - X);
				}else {
					cost = 2 * C * X + 2 * C * (Y - X);
				}
			}else {
				cost = 2 * C * X;
			}
		}
		System.out.println(cost);
	}

}

Measured memory_bytes: 21844
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf pop_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

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

bool comp(const pair < ll, ll >&a, const pair < ll, ll >&b){
    return ((a.ss < b.ss) || (a.ss == b.ss && a.ff < b.ff));
}

ll power(ll a, ll b){
    if(!b){
        return 1;
    }
    if(b&1){
        return (a * power(a*a , b/2));
    }
    return power(a*a , b/2);
}


signed main(){ 
    IOS
    //io_set();
    ll n, m, x, y, dx = INT_MIN, dy = INT_MAX;
    cin >> n >> m;
    rep(i, n){
        cin >> x >> y;
        dx = max(x, dx);
        dy = min(y, dy);
    }
    if(dy < dx){
        cout << 0 << endl;
    }
    else{
        cout << dy - dx + 1 << endl;
    }
    return 0;
}



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

int main() {
  string a,b,c;
  cin >> a >> b >> c;
  int dif = 'A' - 'a';
    cout << (char)(a.at(0)+dif) << (char)(b.at(0)+dif)<<(char)(c.at(0)+dif)<<endl;
}

Measured memory_bytes: 3584
n, m = map(int, input().split())
k = []
s = []
for i in range(m):
    l = list(map(int, input().split()))
    k.append(l[0])
    s.append(l[1:])
p = list(map(int, input().split()))

ans = 0
for bit in range(2 ** n):
    q = 1
    for i in range(m):
        sum = 0
        for j in range(k[i]):
            if (bit >> (s[i][j] - 1)) & 1:
                sum += 1
        if sum % 2 != p[i]:
            q = 0
    if q == 1:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <numeric>
#include <map>
#include <vector>
#include <climits>
#include <cmath>

//using integer = unsigned long long;
using integer = signed long long;

int main(void) {
  integer n;
  std::cin >> n;

  std::vector<integer> a(n);
  std::vector<integer> mark(n, 0);
  for (integer i = 0; i < n; i++) {
    std::cin >> a[i];
    a[i] -= 1;
  }

  integer idx = a[0];
  integer count = 1;
  mark[0] = 1;
  while(idx != 1) {
    mark[idx] = 1;
    integer next = a[idx];
    if (next == idx || mark[next]) {
      count = -1;
      break;
    }
    idx = next;
    count++;
  }

  std::cout << count << std::endl;
  return 0;
}


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

using namespace std;

int main()
{
	int a;
	cin >> a;
	int h, ha, m, ma;
	h = a / 3600;
	ha = a % 3600;
	m = ha / 60;
	ma = ha % 60;
	cout << h << ":" << m << ":" << ma<<endl;
}

Measured memory_bytes: 1164
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	while (b > 0) {
		ll c = b;
		b = a % b;
		a = c;
	}
	return a;
}

int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	map < pair<ll, ll>, ll> m, used;
	cin >> n;
	ll ans = 1;
	ll add = 0;
	vector<ll> pw(200000 + 10);
	pw[0] = 1;
	for (ll i = 1; i < pw.size(); i++) {
		pw[i] = (pw[i - 1] * 1LL * 2) % MOD;
	}
	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		if (x == 0 && y == 0) {
			add++;
		}
		else if (x == 0) {
			m[{-INT64_MAX, 0}]++;
		}
		else if(y == 0){
			m[{0, INT64_MAX}]++;
		}
		else {
			ll g = gcd(abs(x), abs(y));
			bool ok1 = (x < 0), ok2 = (y < 0);
			if (ok1 ^ ok2) {
				m[{-abs(x) / g, abs(y) / g}]++;
			}
			else {
				m[{abs(x) / g, abs(y) / g}]++;
			}
		}
	}
	for (auto i : m) {
		if (!used[i.first]) {
			used[i.first] = 1;
			pair<ll, ll> op;
			if (i.first.first >= 0) {
				op = { -i.first.second, i.first.first };
			}
			else {
				op = { i.first.second, -i.first.first };
			}
			used[op] = 1;
			ans = (ans * ((pw[i.second] - 1 + pw[m[op]] + MOD)%MOD)) % MOD;
		}
	}
	cout << (add + ans - 1 + MOD) % MOD;
}

Measured memory_bytes: 54560
n = int(input())
w = [input() for _ in range(n)]

words = set()
ok = True
for i in range(n):
    if w[i] in words:
        ok = False
        break
    elif i != 0 and w[i-1][-1] != w[i][0]:
        ok = False
        break
    words.add(w[i])
print('Yes' if ok else 'No')


Measured memory_bytes: 9096
#include<iostream>
#include<cmath>
#include<map>
#include<deque>
#include<string>
#include<algorithm>

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;
ll n,m;

ll a[100005];
ll p[100005];
ll cor,pen;
int main(){
    cin>>n>>m;
    rep(i,0,100005){
        a[i]=0;
        p[i]=0;
    }
    rep(i,0,m){
        ll x;
        string s;
        cin>>x>>s;
        if(a[x]==0){//まだACしていない
            if(s=="WA"){
                p[x]++;
            }else{
                a[x]=1;
                cor++;
                pen+=p[x];
            }
        }
    }
    cout<<cor<<" "<<pen<<endl;
}

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

int n;
bool use[10];
int w[10],s[10];
vector<int> tmp,ans;
int maximam,total;

void rec(int pos){
  if(pos==n){
    int g;
    g = 0;
    for(int i=0;i<n;i++)g+=(i+1)*w[tmp[i]];
    if(maximam<g){
      maximam = g;
      ans = tmp;
    }
    return;
  }

  for(int i=0;i<n;i++){
    if(!use[i]){
      if(s[i]>=total){
	use[i] = true;
	total += w[i];
	tmp.push_back(i);
	rec(pos+1);
	tmp.pop_back();
	use[i] = false;
	total -= w[i];
      }
    }
  }
}

int main(){
  string f[10];

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++){
      cin >> f[i] >> w[i] >> s[i];
      use[i] = false;
    }

    total = 0;
    ans.clear();
    tmp.clear();
    maximam = 0;

    rec(0);

    for(int i=ans.size()-1;i>=0;i--)cout << f[ans[i]] << endl;
  }
}
    

Measured memory_bytes: 912
// Aizu Vol-6 0632: 0632: Refreshment Area
// 2017.9.5 bal4u@uu

#include <stdio.h>

char map[102][102];

int main()
{
	int n, m, d, r, c, w, ans;

	scanf("%d%d%d", &m, &n, &d);
	for (r = 0; r < m; r++) scanf("%s", map[r]);
	for (ans = 0, r = 0; r < m; r++) {
		for (w = c = 0; c < n; c++) {
			if (map[r][c] == '.') w++;
			else if (w > 0) {
				if (w >= d) ans += w-d+1;
				w = 0;
			}
		}
		if (w >= d) ans += w-d+1;
	}
	for (c = 0; c < n; c++) {
		for (w = r = 0; r < m; r++) {
			if (map[r][c] == '.') w++;
			else if (w > 0) {
				if (w >= d) ans += w-d+1;
				w = 0;
			}
		}
		if (w >= d) ans += w-d+1;
	}
	printf("%d\n", ans);
	return 0;
}

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

int main()
{
    int v;
    vector<int> vec;
    while (cin >> v && v != 0)
    {
        vec.push_back(v);
    }
    for (int i = 0; i != vec.size(); ++i)
    {
        cout << "Case " << i+1 << ": " << vec[i] << endl;
    }

    return 0;
}



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

typedef long double ld;
#define vd vector<ld>
 
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
// #define mp make_pair
//#define endl '\n'

 
int main() {
    int n;
    cin >> n;
    vd a(n);
    rep(i,n){
        cin >> a[i];
    }
    double result = 0;
    rep(i,n){
        result += (1/a[i]);
    }
    result = 1 / result;
    cout << result << endl;
    return 0;
}

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

typedef long long  int   ll;

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,d=0;
    cin>>a>>b>>c;
    if(a==b&&a==c)cout<<"No";

  else  if(b==a&&b==c)cout<<"No";

 else if(c==b&&c==a)cout<<"No";
    else if(a!=b&&a!=c&&c!=b)cout<<"No";
      else cout<<"Yes";

    return 0;
}


Measured memory_bytes: 256
from functools import reduce
from operator import mul
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]
ss = [x[0] for x in s]

march = ['M', 'A', 'R', 'C', 'H']

c = [ss.count(x) for x in march]
combi = list(combinations(c, 3))

print(sum([reduce(mul, x) for x in combi]))


Measured memory_bytes: 11272
x, k, d = map(int, input().split())

if k*d < abs(x):
    ans = abs(x)-k*d
    print(ans)
    exit()
x = abs(x)
n = x//d
ans = x-n*d
nn = k-n
if nn % 2 == 0:
    print(ans)
else:
    print(abs(ans-d))


Measured memory_bytes: 9176
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

ll a,b,n;
ll h[100002];

inline bool cal(int mid) {
  ll cnt = 0, sub = a - b;
  rep (i,n) {
    ll tmp = h[i] - mid * b;
    if (tmp <= 0) continue;
    ll rem = ceil((double) tmp / sub);
    cnt += rem;
  }

  return (cnt <= mid) ? true : false;
}

int main() {
  cin >> n >> a >> b;

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

  ll left = 1, right = 1e9;
  while (left <= right) {
    ll mid = (left + right) / 2;
    if (cal(mid)) {
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }

  cout << right + 1 << endl;
}


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

int main() {
  int N;
  cin >> N;
  int W[105];
  int A, B;
  B = 0;
  for (int i = 0; i < N; i++) {
    cin >> W[i];
    B += W[i];
  }
  A = W[0];
  B -= A;
  int ans = abs(A-B);
  for (int i = 1; i < N; i++) {
    A += W[i];
    B -= W[i];
    ans = min(ans, abs(A-B));
  }
  cout << ans << endl;
  
  
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        String ans = "second";
        for (int i = 0; i < N; i++) {
            int a = in.i();
            if (a % 2 == 1) {
                ans = "first";
                break;
            }
        }
        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool t = true;
    if(s[a] != '-'){
        t = false;
    }
    FOR(i,0,a){
        if(s[i] < '0' || s[i] > '9'){
            t = false;
        }
    }
    FOR(i,a+1,a+b+1){
        if(s[i] < '0' || s[i] > '9'){
            t = false;
        }
    }
    if(t){
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
"""
~~ Author : Bhaskar
~~ Dated : 16~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    k = int(sys.stdin.readline())
    s = sys.stdin.readline().replace("\n", "")
    if len(s) <= k:
        print(s)
    else:
        print(s[:k]+"...")


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


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

int main(){
        int n,k,i,cnt=0,cnt_out=0,cnt_in=0,ans=0;
        char s_pre,s_now;
        cin >> n >> k;
        cin >> s_pre;
        if(s_pre=='L') ++cnt_out;
        else ++cnt_in;
        for(i=0;i<n-1;++i){
                cin >> s_now;
                if(i==n-2&&s_now=='R') ++cnt_out;
                if(i==n-2&&s_now=='L') ++cnt_in;
                if(s_pre=='R'&&s_now=='L') ++cnt;
                else if(s_pre==s_now) ++ans;
                s_pre = s_now;
        }
        if(cnt_in==2) --cnt;
        if(k<=cnt) ans += k*2;
        else if(cnt_out==1) ans += cnt*2;
        else ans += cnt*2 + 1;
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>
#include<cmath>
#include<queue>

typedef long long ll;
using namespace std;
#define mod 10007
#define rep(i,n) for(ll i=0;i<n;i++)

int main(void){
  string s,ans;
  cin >> s;
  if(s=="Sunny")ans="Cloudy";
  if(s=="Cloudy")ans="Rainy";
  if(s=="Rainy")ans="Sunny";

  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#define ll long long
using namespace std;
const int mod=2019;

int main() {
	int  l,r;
	scanf("%d %d",&l,&r);
	if(r-l+1>=2019) {
		puts("0");
		return 0;
	}
	l%=mod,r%=mod;
	int ans=2019;
	for(int i=l; i<r; i++)
		for(int j=i+1; j<=r; j++)
			ans=min(ans,i*j%mod);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  ll n;
  cin>>n;
  ll ans=1000000000000;
  ll a,b;
  for(int i=1;i<=sqrt(n);i++){
    if(n%i==0){
      a=n/i;
      b=i;
      ans=min(a+b,ans);
    }
  }
  cout<<a+b-2<<endl;
}


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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

long long func(ll a , ll x){
	return a/x;
}

int main(){
	ll a,b,x;
	cin >> a >>b >> x;
	ll ans = func(b,x)-func(a,x);
	if (a% x==0) cout << ans+1;
	else cout <<  ans;

	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val input1 = readInt
  val input2 = readLine.split(" ").take(input1).map(_.toInt)

  var result: Double = 0

  for(x <- 0 until input1)
    result += 1.0/input2(x).toDouble
 
  println(1.0/result)

}


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

using namespace std;

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

    sort(n.begin(), n.end(), greater<int>());
    cout << (n[0] * 10 + n[1]) + n[2] << '\n';
}


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


int main() {
    string s,t;
    cin >> s >> t;
    vector<int> a(26,-1);
    vector<int> b(26,-1);

    int n = s.size();
    rep(i,n){
        int p = s[i]- 'a';
        int q = t[i] - 'a';
        if(a[p] != -1 || b[q] != -1){
            if(a[p] != q || b[q] != p){
                cout << "No" << endl;
                return 0;
            }
        }else{
            a[p] = q;
            b[q] = p;
        }
    }
    cout << "Yes" << endl;
    return 0;  
}

Measured memory_bytes: 776
import Data.List

main = do
  n <- readLn
  putStrLn $ show n ++ ": " ++ unwords (fmap show $ solve n)

factors :: Int -> [Int]
factors n = [d | d <- [2,3]++[5,7..n `max` 7], n `mod` d == 0]

isPrime :: Int -> Bool
isPrime x = not $ any divisible $ takeWhile notTooBig [2..] where
     divisible y = x `mod`y == 0
     notTooBig y = y*y <= x

primeFactor :: Int -> [Int]
primeFactor 1 = []
primeFactor n = d : primeFactor (n `div` d)
  where d = factors n !! 1

solve :: Int -> [Int]
solve n
  | isPrime n = [n]
  | otherwise = reverse $ primeFactor2 [] n

primeFactor2 :: [Int] -> Int -> [Int]
primeFactor2 res 1 = res
primeFactor2 res n = primeFactor2 (d : res) (n `div` d)
    where d = head $ factors n

Measured memory_bytes: 4136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#include <set>
#include <climits>
#include <bitset>

#define mod 1e9+7
#define mp make_pair
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

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

int main(){
	ll N, a;
	cin >> N;
	ll ans = 0;
	ll x;
	if(N%2 == 0){
		x = 10;
		while(N >= x){
			ans += N/x;
			x*=5;
		}
		cout << ans;
	}
	else cout << ans;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int , input().split()))
t = [2,5,5,4,5,6,3,7,6]
cost = {ai: t[ai-1] for ai in a}

dp = [0] + [-1] * n

for i in range(1, n+1):
    dpi = -1
    for ai, ci in cost.items():
        if i - ci >= 0 and dp[i-ci] >= 0:
            dpi = max(dp[i-ci] * 10 + ai, dpi)
    dp[i] = dpi
print(dp[n])


Measured memory_bytes: 50908
#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 MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#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){
  return (b ? gcd(b,a%b) : a);
}

const ll INF = 1LL << 60;

struct Edge{
  int to,weight;
  Edge(int t, int w) : to(t),weight(w){}
};

using Graph = vector<vector<Edge>>;

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

  int ans = 0;
  int right = 0;
  int cnt = 0;
  rep(left, n){
    while (right < n) {
      if(s[right] == '1') right++;
      else if(cnt+1 <= k){
        cnt++;
        while(right < n && s[right] == '0') right++;
      }
      else break;
    }
    //std::cout << right << " " << left << '\n';
    chmax(ans, right - left);

    while(s[left] == '1') left++;
    while(s[left] == '0') left++;
    left--; cnt--;
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
	int a,b,i;
	int isFirst = 1;
	int flag;
	while(1){
		scanf("%d%d",&a,&b);
		if(a == 0 && b == 0){break;}
		if(!isFirst){putchar('\n');}
		isFirst = 0;
		flag = 0;
		for(i = a; i <= b; i++){
			if(!(i % 4)){
				if(!(i % 100)){
					if(!(i % 400)){
						printf("%d\n",i);
						flag = 1;
					}
				}else{
					printf("%d\n",i);
					flag = 1;
				}
			}
		}
		if(!flag){puts("NA");}
	}

	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>

int main()
{
    int x,a,b,D1=0,D2=0;
    scanf("%d%d%d",&x,&a,&b);
    if(1<=x && x<=1000 && 1<=a && a<=1000 && 1<=b && b<=1000)
    {
        D1 = abs(x-a);
        D2 = abs(x-b);
        if(D1<D2) printf("A");
        else printf("B");
    }

return 0;
}

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

template<unsigned mod=1000000007>struct fp {
   int v; static unsigned get_mod(){return mod;}
   int inv() const{
      int tmp,a=v,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0){x+=mod;} return x;
   }
   fp():v(0){}
   fp(ll x):v(x>=0?x%mod:mod+(x%mod)){}
   fp operator-()const{return fp(-v);}
   fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;}
   fp& operator+=(const fp& x){if((v+=x.v)>=(int)mod)v-=mod; return *this;}
   fp& operator-=(const fp& x){if((v+=mod-x.v)>=(int)mod)v-=mod; return *this;}
   fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;}
   fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;}
   fp operator+(const fp& x)const{return fp(*this)+=x;}
   fp operator-(const fp& x)const{return fp(*this)-=x;}
   fp operator*(const fp& x)const{return fp(*this)*=x;}
   fp operator/(const fp& x)const{return fp(*this)/=x;}
   bool operator==(const fp& x)const{return v==x.v;}
   bool operator!=(const fp& x)const{return v!=x.v;}
}; using Fp=fp<>;

int main(){
   int n; cin>>n;
   vector<int> a(n);
   Fp sum=0;
   rep(i,0,n)cin>>a[i],sum+=a[i];
   Fp res;
   rep(i,0,n)res+=(sum-a[i])*a[i],sum-=a[i];
   cout<<res.v<<endl;
   return 0;
}

Measured memory_bytes: 4040
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin() , v.end()
#define fast ios_base::sync_with_stdio(false) , cin.tie(0) ;
int main()
{
    fast ;
    int k, x ,n , i;
    vector<int>v ;
    cin >> n ;
    for(i = 0 ; i < n ; i++)
    {
        cin >> x ;
        v.pb(x) ;
    }
    sort(all(v)) ;
    n = n/2 ;
    cout << v[n] - v[n-1] << "\n" ;
    return 0;
}

Measured memory_bytes: 892
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional;
 
void main() {
    auto N = readln.chomp.to!int;
    N.iota.map!(i => readln.split.to!(ulong[]).pipe!(range => range[1] - range[0] + 1)).sum.writeln;
}

Measured memory_bytes: 508
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>


using namespace std;

int main() {
	int n;
	
	cin >> n;
	
	vector<int>a (n,0);
	vector<int>b (n,0);
	vector<int>c (n-1,0);
	
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	
	for (int i = 0; i < n; i++) {
		cin >> b.at(i);
	}
	
	for (int i = 0; i < n-1; i++) {
		cin >> c.at(i);
	}
	
	/*dbg
	for (int i = 0; i < n; i++) {
		cout << "a: " << a.at(i) << ",b:" << b.at(i) << endl;
		if( i != n -1) cout << "c:" << c.at(i) << endl;
	}
	*/
	
	int ans = 0;
	int prev = -2;
	
	for ( int i = 0; i < n; i++) {
		ans += b.at(a.at(i)-1);
		if(a.at(i) == prev+1){
			ans += c.at(prev-1);
		}
		prev = a.at(i);
		
	//	cout << "term:" << i << ", ans:" << ans << endl;
		
	}
	
	cout << ans << 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;
using ll = long long;
using P = pair<int, int>;



int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> S(h);
    rep(i, h) {
        cin >> S[i];
    }
    int ans = h + w;
    for (int i = 0; i < 1<<(h-1); i++) {
        int tmp = 0;
        vector<int> lines;
        lines.push_back(0);
        rep(j, h-1) {
            if (i>>j&1) {
                tmp++;
                lines.push_back(j+1);
            }
        }
        lines.push_back(h);
        vector<int> block_sum(lines.size()-1);
        vector<int> col_sum(lines.size()-1);
        rep(j, w) {
            bool flg = false;
            rep(l, lines.size()-1) {
                for (int m = lines[l]; m < lines[l+1]; ++m) {
                    col_sum[l] += (S[m][j]=='1');
                    if (col_sum[l] > k) {
                        flg = true;
                        break;
                    }
                }
            }
            if (flg) {
                tmp = h + w;
                break;
            }
            bool flg_2 = true;
            rep(l, lines.size()-1) {
                if (block_sum[l]+col_sum[l]>k) {
                    flg_2 = false;
                    break;
                }
            }
            if (flg_2) {
                rep(l, lines.size()-1) {
                    block_sum[l] += col_sum[l];
                    col_sum[l] = 0;
                }
            } else {
                tmp++;
                rep(l, lines.size()-1) {
                    block_sum[l] = col_sum[l];
                    col_sum[l] = 0;
                }
            }
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1000000000;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

using p = pair<int, int>;

bool cmp(p a, p b){
  return a.s < b.s;	
}

void solve(){
   int n;
   cin >> n;
   vector<p> v;
   
   for (int i = 0; i < n; i++){
	     int a, b;
	     cin >> a >> b;
	     v.push_back({-b, a});
	 }
   sort(all(v));
   cout << v[0].s <<  " " << -v[0].f << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3192