akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define  rep(i,a,b) for(i=a;i<b;i++)
#define endl "\n"
#define ll long long int
#define ld long double
using namespace std;
int main()
{
IOS;
ld a,b;
cin>>a>>b;
ld c=(b-1)/(a-1);
cout<<ceil(c);
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
using namespace std;

int main(){
    unsigned int N;

    cin >> N;

    vector<int> A(N),X(N);
    int sA=0,s = 1;;
    for (size_t i = 0; i < N; i++)
    {
        cin >> A[i];
        X[i]=0;
        sA += s*A[i];
        s = -s;
    }

    if(s==-1){
        X[0]=sA;
        for (size_t i = 1; i < N-1; i++)
        {
            X[i] = 2*A[i-1]-X[i-1];
        }
        X[N-1]=2*A[N-1]-X[0];        
    }else{
        X[N-1]=-sA;
        for (size_t i = N-2; i >= 0; i--)
        {
            X[i] = 2*A[i]-X[i+1];
        }
    }
    for (size_t i = 0; i < N; i++)
    {
        cout << X[i] << " ";
    }

   cout << endl << flush;

    return 0;
}


Measured memory_bytes: 2048
def gcd(x, y):
    if x < y:
        x, y = y, x
    
    if(x == 0 or y == 0):
        if(x == 0):
            return y
        elif(y == 0):
            return x
    
    return gcd(y,x%y)
    
x,y = map(int, input().split())
print(gcd(x,y))


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

int main()
{
	int a = 0;
	int b = 0;
	int c = 0;

	cin >> a >> b >> c;
	if(a < b && b < c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 1156
import java.util.Scanner;

public class Main {

	/*
	 * 余りの最大値を求める。
	 */
	public static void main(String[] args) {

		/*
		 * Scannerで値取得。
		 */
		Scanner s = new Scanner(System.in);
		long number = s.nextInt();
		s.close();

		/*
		 * 少し試行すると最大値が変わらないため、
		 * 割る数を1つずつ値をずらして求めてみる。
		 * i ％ (i + 1)
		 * →結局1からnumber-1までの和になるから計算する。
		 */

		long max = 0;
		//max:答え,intを越える可能性があるため。
		max = number * (number-1) /2;
//		for(int i = 1; i < number; i++) {
//			max += i % (i + 1);
//		}
		//念の為。

		System.out.println(max);

	}

}


Measured memory_bytes: 21716
n,m = map(int,input().split())
item = list(map(int,input().split()))

item.sort(reverse=True)
s = 0

while s == 0:
    for i in range(n):
        if i == 0:
            item[i] = int(item[i]/2)
            m -= 1
            temp = item[i]
            if m == 0:
                s = 1
                break
            continue
        if item[i] > temp:
            item[i] = int(item[i]/2)
            m -= 1
            if m == 0:
                s = 1
                break
            continue
        item.sort(reverse=True)
        break
        

print(sum(item))

Measured memory_bytes: 14224
# include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; 
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

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

const int MAX_N = 114514;

int A[MAX_N];

int main(void) {

    fill(A,A+MAX_N,0);
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        A[a]++;
    }

    for (int i = 0; i < MAX_N; i++) {
        while (A[i] >= 3) {
            A[i] = A[i]/3 + A[i]%3;
        }
    }

    int one_cnt = 0;
    int two_cnt = 0;
    for (int i = 0; i < MAX_N; i++) {
        if (A[i] == 1) one_cnt++;
        if (A[i] == 2) two_cnt++;
    }

    if (two_cnt%2 != 0) {
        two_cnt--;
    }

    cout << one_cnt+two_cnt << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val N = scn.nextInt()
    val M = scn.nextInt()

    var WA = 0
    var AC = 0
    //var answer = mutableListOf<Int>()
    var answer = Array<Int>(N,{0})
    var wrong = Array<Int>(N,{0})

    for(i in 1 .. M){
        var p = scn.nextInt()
        val S = scn.next()

        if(p>N) continue
        if(answer[p-1]==1) continue

        if(S=="AC"){
            AC++
            WA += wrong[p-1]
            answer[p-1] = 1
        }else if(S=="WA"){
            wrong[p-1]++
        }
    }

    println("$AC $WA")
}

Measured memory_bytes: 69876
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <set>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;


int main() {
    ll A, B;
    ll V, W;
    ll T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;

    if(A < B){
        if(W >= V){
            cout << "NO" << endl;
            return 0;
        }
        if((long double)(B-A)/(V-W) <= T){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    else if(A>B){
        if(V<=W){
            cout << "NO" << endl;
            return 0;
        }
        if((long double)(A-B)/(V-W) <= T){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    else{
        if(W == V){
            cout << "YES" << endl;
        }
        else if(V > W){
            cout << "YES" << endl;
        }
        else
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
	class ABC045B
	{
		static void Main()
		{
			List<Queue<int>> qs = new List<Queue<int>>();
			for(int i= 0; i < 3; i++)
			{
				List<int> buff = Console.ReadLine().Select(x => x - 'a').ToList();
				Queue<int> q = new Queue<int>();
				foreach (int n in buff)
				{
					q.Enqueue(n);
				}
				qs.Add(q);
			}

			int num = 0;
			while (qs[num].Count() != 0)
			{
				num = qs[num].Dequeue();
			}

			Console.WriteLine((char)(num + 'A'));
		}
	}
}


Measured memory_bytes: 2904
#include <stdio.h>

typedef long long ll;

ll max(ll a, ll b){
	if(a>=b){return a;}
	else{return b;}
}

ll x[100005];
ll v[100005];
ll f[100005];
ll g[100005];
ll f2[100005];
ll g2[100005];

int main() {

	int N;

	ll C;

	scanf("%d %lld",&N,&C);

	int i;
	for(i=0;i<N;i++){
		scanf("%lld %lld",&x[i+1],&v[i+1]);
	}
	ll sum=0ll;
	f[0]=0ll;
	for(i=1;i<=N;i++){
		sum+=v[i];
		f[i]=sum-x[i];
	}

	for(i=1;i<=N;i++){
		g[i]=max(g[i-1],f[i]);		
	}
	for(i=1;i<=N;i++){
		g2[i]=max(g2[i-1],f[i]-x[i]);
	}

	sum=0ll;
	for(i=N;i>=1;i--){
		sum+=v[i];
		f2[i]=sum-(C-x[i]);
	}

	ll ans=0ll;

	for(i=1;i<=N;i++){
	ans=max(ans,f[i]);
	}
	for(i=1;i<=N;i++){
	ans=max(ans,f2[i]);
	}

	for(i=1;i<=N;i++){
	ll OA=g[i-1];
	ll OB=f2[i];
	if(ans<OB-(C-x[i])+OA){ans=OB-(C-x[i])+OA;}
	}

	for(i=1;i<=N;i++){
	ll OA2=g2[i-1];
	ll OB=f2[i];
	if(ans<OA2+OB){ans=OA2+OB;}
	}

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 4864
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

#define fst first
#define snd second

typedef long long llint;
typedef pair<int, int> pii;

const int B = 27397, MOD = 1e9 + 7;
const int B1 = 33941, MOD1 = 1e9 + 9;

struct Point {
  int idx;
  int r, s;

  Point () {}
  Point (int _idx, int _r, int _s) {
    idx = _idx;
    r = _r;
    s = _s;
  }
};

int R, S, n;

vector <Point> left, right, up, down;
stack <int> stk;

inline bool on_border(int r, int s) {
  return r == 0 || r == R || s == 0 || s == S;
}

void insert(int i, int r, int s) {
  if (s == 0) {
    left.emplace_back(i, r, s);
    return;
  }
  if (r == 0) {
    up.emplace_back(i, r, s);
    return;
  }
  if (s == S) {
    right.emplace_back(i, r, s);
    return;
  }
  if (r == R) {
    down.emplace_back(i, r, s);
    return;
  }
  assert(false);
}

inline bool cmp_sup(const Point &A, const Point &B) {
  return A.s < B.s;
}

inline bool cmp_sdown(const Point &A, const Point &B) {
  return A.s > B.s;
}

inline bool cmp_rup(const Point &A, const Point &B) {
  return A.r < B.r;
}

inline bool cmp_rdown(const Point &A, const Point &B) {
  return A.r > B.r;
}

void traverse(vector<Point> &v) {
  for (auto &p : v) {
    if (!stk.empty() && stk.top() == p.idx)
      stk.pop();
    else
      stk.push(p.idx);
  }
}

int main(void) {
  scanf("%d%d%d", &R, &S, &n);
  for (int i = 0; i < n; ++i) {
    int r1, s1, r2, s2;
    scanf("%d%d%d%d", &r1, &s1, &r2, &s2);
    if (on_border(r1, s1) && on_border(r2, s2)) {
      insert(i, r1, s1);
      insert(i, r2, s2);
    }
  }

  sort(left.begin(), left.end(), cmp_rup);
  sort(down.begin(), down.end(), cmp_sup);
  sort(right.begin(), right.end(), cmp_rdown);
  sort(up.begin(), up.end(), cmp_sdown);

  traverse(left);
  traverse(down);
  traverse(right);
  traverse(up);

  if (!stk.empty())
    printf("NO\n");
  else
    printf("YES\n");

  return 0;
}



Measured memory_bytes: 3692
import sys 
import sys 

N,A,B = map(int,sys.stdin.readline().split())
S = sys.stdin.readline().strip()
passCount = 0 
overseasRank = 0 
i = 0 
while i < len(S):
    c = S[i]
    if c == 'a':
        if passCount < A+B:
            print 'Yes'
            passCount += 1
        else:
            print 'No'
    if c == 'b':
        overseasRank += 1
        if passCount < A+B:
            if overseasRank <= B:                                                                                                                                                                                                     
                print 'Yes'
                passCount += 1
            else:
                print 'No'
        else:
            print 'No'
    if c == 'c':
        print 'No'

    i += 1

Measured memory_bytes: 3204
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll r,D,x;
	scan(r>>D>>x);
	rep(i,10){
		x=r*x-D;
		prin(x);
	}
	return 0;
}


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

using namespace std;

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

    int ANS = 0;

    if (X >= 1800)
    {
        ANS = 1;
    }

    else if (X >= 1600)
    {
        ANS = 2;
    }

    else if (X >= 1400)
    {
        ANS = 3;
    }

    else if (X >= 1200)
    {
        ANS = 4;
    }

    else if (X >= 1000)
    {
        ANS = 5;
    }

    else if (X >= 800)
    {
        ANS = 6;
    }

    else if (X >= 600)
    {
        ANS = 7;
    }

    else if (X >= 400)
    {
        ANS = 8;
    }

    cout << ANS << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

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

    bool flg = a < b && b < c;

    cout << (flg ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3096
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		
		int W;
		int H;
		int x;
		int y;
		int r;
		
		boolean leftside = false;
		boolean rightside = false;
		boolean upside = false;
		boolean downside = false;

		Scanner scan = new Scanner(System.in);
		W = Integer.parseInt(scan.next());
		H = Integer.parseInt(scan.next());
		x = Integer.parseInt(scan.next());
		y = Integer.parseInt(scan.next());
		r = Integer.parseInt(scan.next());
		
		
		
		if((x-r)<0){
			leftside=true;
		}
		
		if(W<(x+r)){
			rightside=true;
		}
		
		if(H<(y+r)){
			upside=true;
		}
		
		if((y-r)<0){
			downside=true;
		}

		if(leftside||rightside||upside||downside){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
		
	}
}

Measured memory_bytes: 26248
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

string S[30][30];

int main() {

	int i, j;

	int H, W;

	int ans[2];

	scanf("%d %d", &H, &W);

	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			cin >> S[i][j];
			if (S[i][j] == "snuke") { 
				ans[0] = i;
				ans[1] = j; 
			}
		}
	}
	printf("%c%d\n",ans[1]+'A',ans[0]+1);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define db double
#define il inline
#define re register
#define mkpr make_pair

using namespace std;
const int N=3000+10,mod=1e9+7;
il LL rd()
{
    LL x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
int n,m,f[2][N][2];

int main()
{
	n=rd(),m=rd();
	int nw=1,la=0;
	for(int i=1;i<=n;++i) f[0][i][0]=1;
	f[0][0][1]=1;
	for(int i=1;i<=m;++i)
	{
		for(int j=0;j<=n;++j)
			for(int k=0;k<=1;++k)
			{
				if(!f[la][j][k]) continue;
				if(j>=1)
				{
					f[nw][j-1][k|(j==1)]=(f[nw][j-1][k|(j==1)]+f[la][j][k])%mod;
					f[nw][j][k|(j==1)]=(f[nw][j][k|(j==1)]+f[la][j][k])%mod;
				}
				if(j<n)
				{
					f[nw][j+1][k]=(f[nw][j+1][k]+f[la][j][k])%mod;
					f[nw][j][k]=(f[nw][j][k]+f[la][j][k])%mod;
				}
				f[la][j][k]=0;
			}
		nw^=1,la^=1;
	}
	int ans=0;
	for(int j=0;j<=n;++j) ans=(ans+f[la][j][1])%mod;
	printf("%d\n",ans);
    return 0;
}


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

b_low=-1*(10**10)
b_high=10**10
b_low_d=sum([abs(a[i]-(b_low+2+i)) for i in range(n)])-sum([abs(a[i]-(b_low+1+i)) for i in range(n)])
b_high_d=sum([abs(a[i]-(b_high+2+i)) for i in range(n)])-sum([abs(a[i]-(b_high+1+i)) for i in range(n)])

while b_high-b_low>10:
  b_tmp=(b_low+b_high)//2
  b_tmp_d=sum([abs(a[i]-(b_tmp+2+i)) for i in range(n)])-sum([abs(a[i]-(b_tmp+1+i)) for i in range(n)])
  if b_tmp_d>0:
    b_high=b_tmp
  else:
    b_low=b_tmp

ans=10**20
for j in range(b_low,b_high):
  ans=min(ans,sum([abs(a[i]-(j+2+i)) for i in range(n)]))

print(ans)

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

int main(){
  string S,T;cin >> S >> T;
  for(int i=0;i<S.size();i++){
    if(S[i]!=T[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3628
import sys

fin = sys.stdin.readline

N, M = map(int, fin().split())
As = list(map(int, fin().split()))
BC = [tuple(map(int, fin().split())) for _ in range(M)]

As = sorted(As)
# BC = sorted(BC, key=lambda x: x[1], reverse=True)

BC_ = {}
for num, val in BC:
    if val in BC_:
        BC_[val] += num
    else:
        BC_[val] = num

BC_ = sorted(BC_.items(), reverse=True)

#
# def f(a, n, v):
#     if a[min(n-1, len(a)-1)] < v:
#         return v * min(n, len(a)), a[n:]
#     count = 0
#     for i in range(min(n, len(a))):
#         if a[i] < v:
#             count += 1
#         else:
#             break
#     return v * count, a[count:]


sum__ = 0
now = 0
for val, num in BC_:
    if now >= len(As) or As[now] >= val:
        break

    if As[min(num - 1 + now, len(As) - 1)] < val:
        sum_ = val * min(num, len(As) - now)
        now += min(num, len(As) - now)
    else:
        count = 0
        for i in range(min(num, len(As)-now)):
            if As[i + now] < val:
                count += 1
            else:
                break
        sum_ = val * count
        now += count
    sum__ += sum_

print(sum__ + sum(As[now:]))


Measured memory_bytes: 34684
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int64_t t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    //for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<mint> > dp(w, vector<mint>(w));
    rep(i, 1<<w-1) {
        bool x = true;
        rep(j, w-2) {
            if((i>>j)&1 and (i>>(j+1))&1) x = false;
        }
        if(!x) continue;
        rep(j, w-1) {
            if((i>>j)&1) {
                dp[j][j+1] += 1;
                dp[j+1][j] += 1;
            } else {
                if(!j) dp[j][j] += 1;
                if(j and !((i>>j-1)&1)) dp[j][j] += 1;
                if(j == w-2) dp[j+1][j+1] += 1;
            }
        }
    }

    vector<vector<vector<mint> > > dpp(h+1, vector<vector<mint> >(w, vector<mint>(w)));
    rep(i, w) {
        dpp[0][i][i] = 1;
    }
    rep(j, h) {
        rep(l, w) {
            rep(u, w) {
                rep(x, w) {
                    dpp[j+1][l][u] += dpp[j][l][x] * dp[x][u];
                }
            }
        }
    }

    cout << (w == 1 ? 1:dpp[h][0][k-1]) << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int nax = 1e5+5;
vector<int>v[nax];
const int mod = 1e9+7;
using ll = long long;
// return a pair{black, white}
int mul(int a, int b){
  return (ll) a*b % mod;
}
pair<int, int> dfs(int a, int parent){
  int all_white = 1;// means the vertex can be painted black
  int black = 0;
  for(auto b: v[a]){
    if(b != parent){
      pair<int, int>p = dfs(b, a);
      int prev_white = all_white;
      all_white = mul(all_white, p.second);
      black = (mul(prev_white, p.first)+mul(black, p.first+p.second))%mod;
    }
  }
  return make_pair(all_white, (all_white+black)%mod);
}

int main(){
  int a, b;
  int n;
  cin >> n;
  for(int i=0; i<n-1; i++){
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  pair<int, int> p = dfs(1, -1);
  int ans = (p.first+p.second) % mod;
  cout << ans;
  return 0;
}


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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << endl;
    return 0;
}


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

double cross_product(complex<double>, complex<double>);
int main(void) {
	complex<double> p[30];
	int n;
	double x, y, s = 0;

	n = 0;
	while (scanf("%lf,%lf", &x, &y) == 2) {
		p[n++] = complex<double>(x, y);
	}
	for (int i = n - 1; i >= 0; i--) {
		p[i] -= p[0];
	}
	for (int i = 2; i < n; i++) {
		s += cross_product(p[i - 1], p[i]);
	}
	if (s < 0) s = -s;
	cout << s/2 << endl;
	return 0;
}

double cross_product(complex<double> a, complex<double> b) {
	return (conj(a)*b).imag();
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;

int main(){
    cin >> s;
    int ans = 0;
    rep(i,s.size()){
        ans += (s[i] == '2');
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;

int main()
{
     double r, h, S;
     while (cin >> r >> h && r && h) {
	  S = r * r + r * sqrt(r * r + h * h * 4);
	  printf("%f\n", S);
     }

     return 0;
}

Measured memory_bytes: 1228
#include <stdio.h>
 
int main(){
  char p[101],s[101];
  int i=0,j=0,k=0,l=0,m=0;
  int ans=0;
  for(i=0; i<101; i++){
    scanf("%c",&s[i]);
    if(s[i]=='\n')break;
  }
  for(j=0; j<101; j++){
    scanf("%c",&p[j]);
    if(p[j]=='\n')break;
  }
  for(k=0;k<i;k++){
    if(s[k]==p[0]){
      for(l=0; l<j; l++){
        m=k+l;
        if(m>=i)m-=i;
        if(s[m]!=p[l])break;
        if(l==j-1)ans=1;
      }
    }
  }
  if(ans)printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 2112
N, A, B, C = map(int, input().split())
llist = []
for _ in range(N):
    llist.append(int(input()))
INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + llist[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + llist[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + llist[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))


Measured memory_bytes: 43996
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int A[3][3],i,a0,b0,a1,b1,a2,b2,c;
  
  cin>>A[0][0]>>A[0][1]>>A[0][2]>>A[1][0]>>A[1][1]>>A[1][2]>>A[2][0]>>A[2][1]>>A[2][2];
    a0=A[0][0]-A[0][1];
    b0=A[0][1]-A[0][2];
 a1=A[1][0]-A[1][1];
    b1=A[1][1]-A[1][2];
a2=A[2][0]-A[2][1];
    b2=A[2][1]-A[2][2];
   if(a0==a1&&a1==a2&&b0==b1&&b1==b2){
   cout<<"Yes"<<endl;
   }else{
   cout<<"No"<<endl;
   }
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

int h, w, k;
vector<string> brd;

bool inRange(int y, int x) {
	return y >= 0 && y < h && x >= 0 && x < w;
}

int cal(int a) {
	int ret = (a%k ? 1 : 0);
	ret += a/k + 1;
	return ret;
}
int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> h >> w >> k;
	brd.resize(h);
	rep(i,0,h) {
		cin >> brd[i];
	}
	int y, x;
	rep(i,0,h) rep(j,0,w) {
		if(brd[i][j] == 'S') {
			y = i;
			x = j;
		}
	}
	vector<vi> dist(h, vi(w, -1));
	dist[y][x] = 0;
	queue<pii> q;
	q.push(mp(y,x));
	while(!q.empty()) {
		int yy = q.front().F;
		int xx = q.front().S;
		q.pop();
		rep(i,0,4) {
			int ny = yy + dy[i];
			int nx = xx + dx[i];
			if(!inRange(ny,nx) || brd[ny][nx] == '#') {
				continue;
			}
			if(dist[ny][nx] == -1) {
				dist[ny][nx] = dist[yy][xx]+1;
				q.push(mp(ny,nx));
			}
		}
	}
	rep(i,0,h) rep(j,0,w) {
		if(dist[i][j] >= 0 && dist[i][j] <= k) {
			dist[i][j] = 0;
			q.push(mp(i,j));
		} else {
			dist[i][j] = -1;
		}
	}
	while(!q.empty()) {
		int yy = q.front().F;
		int xx = q.front().S;
		q.pop();
		rep(i,0,4) {
			int ny = yy + dy[i];
			int nx = xx + dx[i];
			if(!inRange(ny,nx)) {
				continue;
			}
			if(dist[ny][nx] == -1) {
				dist[ny][nx] = dist[yy][xx]+1;
				q.push(mp(ny,nx));
			}
		}
	}
	int ret = 1e9;
	rep(i,0,h) {
		ret = min(cal(dist[i][0]), ret);
		ret = min(cal(dist[i][w-1]), ret);
	}
	rep(i,0,w) {
		ret = min(cal(dist[0][i]), ret);
		ret = min(cal(dist[h-1][i]), ret);
	}
	cout << ret << '\n';
	return 0;
}


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

using namespace std;
using ll = long long;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

int main(){
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
string a,b,c;
cin>>a;
cin>>b;
cin>>c;
cout<<a[0];
int l2=b.size();
cout<<b[l2/2];
int l=c.size();
cout<<c[l-1];


return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
typedef long long ll;
void sc(int& x){x=0;char c=getchar();while(c>'9' || c<'0')c=getchar();
for(;c>='0' && c<='9';c=getchar())x=x*10+c-'0';
}
const int N=2e5+7;
const int inf=0x3f3f3f3f;
struct E{
	int to,next;E(int to=0,int next=0):to(to),next(next){}
}edge[N<<1];
int head[N],tot;
void add(int x,int y){
	edge[++tot]=E(y,head[x]);head[x]=tot;
	edge[++tot]=E(x,head[y]);head[y]=tot;
}
int n,sg[N];
void dfs(int x,int f){
	for(int i=head[x];i;i=edge[i].next){
		int v=edge[i].to;
		if(v!=f){
			dfs(v,x);
			sg[x]^=sg[v]+1;
		}
	}
}
int main(){
	scanf("%d",&n);
	rep(i,1,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
	}
	dfs(1,0);
	if(sg[1])puts("Alice");
	else puts("Bob");
}

Measured memory_bytes: 8832
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
#define rep(i, n) for (int i = 0; i < (n); i++)
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	while (k--) {
		vector<ll> b(n + 1);
	    rep(i, n) b[max(0LL, i - a[i])]++, b[min(i + a[i] + 1, n)]--;
	    rep(i, n ) b[i + 1] += b[i];
	    b.pop_back();
	    if (a == b) break;
	    a = b;
	}
	rep(i,n) cout << a[i] << ' ';
	return 0;
}



Measured memory_bytes: 6344
n, k = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i)

ans = (n - k + 1).times.map do |i|
  xl = xs[i]
  xr = xs[i + k - 1]

  lr = xl.abs + (xr - xl).abs
  rl = xr.abs + (xl - xr).abs

  [lr, rl].min
end.min

puts ans


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

class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int weight = sc.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        int[] size = new int[4];
        long[][] count = new long[4][n+1];
        for(int i=0;i<n;i++){
        	w[i] = sc.nextInt();
        	v[i] = sc.nextInt();
        }
        ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
        for(int i=0;i<4;i++){
        	list.add(new ArrayList<Integer>());
        }
        for(int i=0;i<n;i++){
        	ArrayList<Integer> l = list.get(w[i] - w[0]);
        	l.add(v[i]);
        }
		for(int i=0;i<4;i++){
			ArrayList<Integer> l = list.get(i);
			Collections.sort(l);
			size[i] = l.size();
        }
        for(int i=0;i<4;i++){
        	ArrayList<Integer> l = list.get(i);
        	for(int j=0;j<=size[i];j++){
        		if(j==0){
        			count[i][j] = 0;
        		}
        		else{
        			count[i][j] = count[i][j-1] + (long)l.get(l.size()-j);
        		}
        	}
        }

        long ans = 0;
        for(int i=0;i<=size[0];i++){
        	if(i*w[0]>weight){
        		break;
        	}
        	for(int j=0;j<=size[1];j++){
        		if(i*w[0]+j*(w[0]+1)>weight){
        			break;
        		}
        		for(int k=0;k<=size[2];k++){
        			if(i*w[0]+j*(w[0]+1)+k*(w[0]+2)>weight){
        				break;
        			}
        			int l = (int)Math.min((weight-i*w[0]-j*(w[0]+1)-k*(w[0]+2))/(w[0]+3), size[3]);
        			ans = (long)Math.max(ans, count[0][i]+count[1][j]+count[2][k]+count[3][l]);
        		}
        	}
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct bian{
	int next,point;
}b[210000];
int p[110000],len;
void ade(int k1,int k2){
	b[++len]=(bian){p[k1],k2}; p[k1]=len;
}
void add(int k1,int k2){
	ade(k1,k2); ade(k2,k1);
}
int sg[110000];
void dfs(int k1,int k2){
	sg[k1]=0;
	for (int i=p[k1];i;i=b[i].next){
		int j=b[i].point;
		if (j!=k2){
			dfs(j,k1); sg[k1]^=(sg[j]+1);
		}
	}
}
int main(){
	int n; scanf("%d",&n);
	for (int i=1;i<n;i++){
		int k1,k2; scanf("%d%d",&k1,&k2); add(k1,k2);
	}
	dfs(1,0);
	if (sg[1]==0) printf("Bob\n"); else printf("Alice\n");
	return 0;
}

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

int main(){
  int n, k, q;
  cin >> n >> k >> q;
  int a[q], c[n];
  for(int i=0; i<n; i++) c[i] = k-q;
  for(int i=0; i<q; i++){
    cin >> a[i];
    c[a[i]-1]++;
  }
  for(int i=0; i<n; i++){
    if(c[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

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

int main() {
	int N, M, X;
	cin >> N >> M >> X;
	int sum_left = 0, sum_right = 0;
	for (int i = 1; i <= M; i++) {
		int a;
		cin >> a;
		if (a < X) sum_left += 1;
		else sum_right += 1;
	}
	cout << min(sum_left, sum_right) << endl;
}

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

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

int main(void) {
    ll K;cin>>K;
    ll sum = 0;
    for (ll i = 1; i <= K; i++) {
        for (ll j = 1; j <= K; j++) {
            for (ll k = 1; k <= K; k++) {
                sum += gcde(i, j, k);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

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

int main() {

  int N,K;
  cin >> N >> K;
  
  int tmp = N;
  int ans = 1;

  while(1){
    
    if(tmp<K){
      break;
    }
    tmp /= K;
    ans++;
    
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

ll N, X, M;

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

    // ループ判定用の連想配列
    map<ll, ll> m;

    // Anを試しに計算してみよう
    vector<ll> a(200000);
    a.at(0) = X;
    m[X]++;

    // ループ開始位置とループ終了の位置を保存
    ll loop_start = 0, loop_end = 0;
    // 1回目のループが終わる位置までの和
    ll sum1 = X;

    rep(1, i, 200000)
    {
        ll f = (a.at(i - 1) * a.at(i - 1)) % M;
        a.at(i) = f;
        m[f]++;
        // ループ箇所が見つかった
        if (m[f] > 1)
        {
            loop_end = i - 1;
            break;
        }
        sum1 += a.at(i);
    }

    // ループ開始までの和
    ll sum2 = 0;
    // ループ開始位置はどこですか
    rep(0, i, 200000)
    {
        if (a.at(i) == a.at(loop_end + 1))
        {
            loop_start = i;
            break;
        }
        sum2 += a.at(i);
    }

    // 答え
    ll ans = 0;

    // 残りの和をとる個数
    ll NN = N;

    // 1回目のループが終わる位a置(またはNがそれより小さい時はそこまで)の和を計算
    rep(0, i, min(N, loop_end + 1))
    {
        ans += a.at(i);
        NN--;
    }

    ans += (NN / (loop_end - loop_start + 1)) * (sum1 - sum2);

    rep(0, i, NN % (loop_end - loop_start + 1))
    {
        ll j = i + loop_start;
        ans += a.at(j);
    }

    cout << ans << endl;
}

Measured memory_bytes: 7920
from operator import itemgetter
n = int(input())
sp = []
for i in range(n):
    s_input, p_input = input().split()
    sp.append([s_input] + [int(p_input)] + [i])
sorted1 = sorted(sp, key=itemgetter(1), reverse=True)
sorted2 = sorted(sorted1, key=itemgetter(0))

for i in range(n):
    print(int(sorted2[i][2]) + 1)


Measured memory_bytes: 3060
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
m = [[None for _ in range(W)] for _ in range(H)]
x, y = 0, 0
for color in range(N):
    for _ in range(a[color]):
        m[x][y] = color + 1
        if x % 2 == 0:
            if y == W - 1:
                x += 1
            else:
                y += 1
        else:
            if y == 0:
                x += 1
            else:
                y -= 1
for i in range(H):
    for j in range(W):
        c = '\n' if j == W - 1 else ' '
        print(m[i][j], end=c)

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

int main() {
  string O, E;
  cin >> O >> E;
  
  if (O.size() == E.size()) {
    for (int i = 0; i < O.size(); i++) {
      cout << O[i] << E[i];
    }
    cout << endl;
  } else {
    for (int i = 0; i < O.size()-1; i++) {
      cout << O[i] << E[i];
    }
    cout << O[O.size()-1] << endl;
    
  }
  
}

Measured memory_bytes: 3608
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1005,M=5005,inf=1e8,lim=-1e7;
int n,i,lt[N],he[N],a[N];
int f[N],g[M];
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
void gmax(int &x,int k){if (k>x) x=k;}
void cal(int x){
	int i,m=a[x],sum=0;
	for (i=0;i<=m;i++) g[i]=0;
	for (int y=he[x];y;y=lt[y]){
		int v=a[y],vx=f[y],kx=v-vx;
		sum+=v;
		for (i=m;i>=0&&g[i]>lim;i--)
			g[i]=max(i>=v?g[i-v]+kx:-inf,i>=vx?g[i-vx]:-inf);
	}
	f[x]=sum-g[m];
}
int main(){
	for (n=read(),i=2;i<=n;i++){
		int x=read();lt[i]=he[x];he[x]=i;
	}
	for (i=1;i<=n;i++) a[i]=read();
	for (i=n;i;i--) cal(i);
	puts(f[1]<inf?"POSSIBLE":"IMPOSSIBLE");
}

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

int main(){
    int m, f, r;
    
    while(true){
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;
        else if (m == -1 or f == -1) cout << "F" << endl;
        else if(m + f >= 80) cout << "A" << endl;
        else if(m + f < 80 && m + f >= 65) cout << "B" << endl;
        else if(m + f < 65 && m + f >= 50) cout << "C" << endl;
        else if(m + f < 50 && m + f >= 30){
            if (r >= 50) cout << "C" << endl;
            else cout << "D" << endl;
        }
        else if(m + f < 30) cout << "F" << endl;
    }
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define all(a) a.begin(), a.end()
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

void solve(){
    map<lli, vi> mpp;
    lli n,ans=0; cin>>n;
    vi a(n), p(n+1,0), neg(n+1,0);
    NA(I,0,n) cin>>a[I]; 
    for(lli i=n-1; i>=0; --i){
        if(a[i]+i<=n)
            ans += (neg[a[i]+i]);
        if(i-a[i]>0) 
            neg[i-a[i]]++;
    }
    cout<<ans;
    return;
}

int main(){
    fastIO;
    lli t = 1; 
    // cin>>t;
    NA(i,0,t) solve();
    return 0;
}

Measured memory_bytes: 7916
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  int max=a;
  if(b>max){
    max=b;
    b=0;
  }
  else if(c>max){
    max=c;
    c=0;
  }
  else
    a=0;
  cout << 10*max+a+b+c << endl;
}

  

Measured memory_bytes: 256
n,m=map(int,input().split())
a,b=[],[]
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
c=0
for i in range(n-m+1):
    for j in range(n-m+1):
        p = [l[j:j+m] for l in a[i:i+m]]
        if b == p and c==0:
            print('Yes')
            c=1
            break
if c==0:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long n;
    cin >> n;
    long long b;
    for(long long i = 1; i * i <= n; i++) {
        if(n % i == 0)
            b = n / i;
    }
    int ans = 0;
    while(b > 0) {
        b /= 10;
        ans++;
        //cout << num << endl;
    }
    //cout << m << endl;
    //cout << a << " " << b << endl;
    cout << ans;
}

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

int main()
{
	int a, b, c, d, e, k;

	cin >> a >> b >> c >> d >> e >> k;

	if (b - a > k || c - a > k || d - a > k || e - a > k || c - b > k || d - b > k || e - b > k || d - c > k || e - c > k || e - d > k)
		cout << ":(";
	else if(b - a <= k || c - a <= k || d - a <= k || e - a <= k || c - b <= k || d - b <= k || e - b <= k || d - c <= k || e - c <= k || e - d <= k)
		cout << "Yay!";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
using namespace std;main(){int n,c,m;for(;cin>>n,n;){
string s,t;map<string,int>M;
for(;n;n--)cin>>s>>c,M[s]=c;
for(cin>>n;n;M[s]=min(M[s],c),n--)for(c=0,cin>>s>>m;m;m--)cin>>t,c+=M[t];
cin>>s,cout<<M[s]<<endl;
}}

Measured memory_bytes: 1224
n = int(input())
a = list(map(int, input().split()))

ans = []
if max(a) >= -min(a):
    ans.append([a.index(max(a))+1, 1])
    ans.append([a.index(max(a))+1, 1])
    for i in range(n-1):
        ans.append([i+1, i+2])
        ans.append([i+1, i+2])

else:
    ans.append([a.index(min(a))+1, n])
    ans.append([a.index(min(a))+1, n])
    for i in range(n-1):
        ans.append([n-i, n-i-1])
        ans.append([n-i, n-i-1])

print(len(ans))
for i in range(len(ans)):
    print(" ".join(map(str, ans[i])))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 

  int64_t r,g,b;
  cin>>r>>g>>b;

  int64_t k;
  cin>>k;

  // blue>green>red

  bool flg = false;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if(b*pow(2,j)>g*pow(2,i) && g*pow(2,i)>r && i+j==k){
        flg=true;
        break;
      }
    }
  }

  if(flg)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll nC2(ll n)
{
  return n * (n - 1) * 0.5;
}

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

  vector<ll> a(n);
  vector<ll> an(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    an[a[i] - 1]++;
  }

  ll sum = 0;

  for(int i = 0; i < n; i++){
    if(an[i] > 1)
      sum += nC2(an[i]);
  }

  for(int i = 0; i < n; i++){
    cout << sum - (an[a[i] - 1] - 1) << endl;
  }

  return 0; 
}


Measured memory_bytes: 5760
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int h,w,dp[55][55];
char c;

int main(){
	cin>>h>>w;
	rep(i,55)dp[0][i]=dp[i][0]=INF;
	dp[0][1]=0;
	rep2(i,1,h+1)rep2(j,1,w+1){
		cin>>c;
		dp[i][j]=min(dp[i-1][j],dp[i][j-1])+c-'0';
	}
	cout<<dp[h][w]<<endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

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



Measured memory_bytes: 256
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

min_i = 0
max_i = 100000

for m in range(M):
    min_i = max(min_i, LR[m][0])
    max_i = min(max_i, LR[m][1])

print(max_i - min_i + 1 if (max_i >= min_i) else 0)


Measured memory_bytes: 27332
object Main extends App {

  import scala.io.StdIn._
  f
  def f: Unit = {
    val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0 && m == 0) return
    val taro = Array.tabulate(n) { _ ⇒ readLine.trim.toInt }.sorted
    val hanako = Array.tabulate(m) { _ ⇒ readLine.trim.toInt }.sorted
    val taroSum = taro.sum
    val hanakoSum = hanako.sum
    val sum = taroSum + hanakoSum
    if (sum % 2 == 1) println(-1)
    else {
      taro.find(t ⇒ hanako.find(h ⇒ taroSum - t + h == hanakoSum + t - h).isDefined) match {
        case Some(t) ⇒
          println(s"$t ${hanako.find(h ⇒ taroSum - t + h == hanakoSum + t - h).get}")
        case None ⇒ println(-1)
      }
    }
    f
  }
}



Measured memory_bytes: 44308
def Binary_Serch():
    n = int(input())
    t = list(map(int,input().split()))
    q = int(input())
    o = list(map(int,input().split()))

    cnt = 0

    for i in range(len(o)):
        left = 0
        right = n
        while left < right:
            mid = int((left + right) / 2)
            if t[mid] == o[i]:
                cnt +=1
                break
            elif o[i] < t[mid]:
                right = mid
            else:
                left = mid + 1
    
    return cnt

if __name__ == '__main__':
    print(Binary_Serch())


Measured memory_bytes: 16708
#include <iostream>

using namespace std;

int main(){

	ios::sync_with_stdio(false);

	int qtd_inns, altura_inn, maior_altura = 0, visao_oceano = 0;

	cin >> qtd_inns;

	for(int i=1; i<=qtd_inns; i++){
		cin >> altura_inn;

		if(altura_inn >= maior_altura){
			maior_altura = altura_inn;
			visao_oceano++;
		} 
	}

	cout << visao_oceano << endl;

	return 0;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String firstLine = br.readLine();
        String[] firstLineArray = firstLine.split(" ");
        int K = Integer.parseInt(firstLineArray[1]);

        String secondLine = br.readLine();
        String[] secondLineArray = secondLine.split(" ");

        int result = 0;
        for (String hStr : secondLineArray) {
            int h = Integer.parseInt(hStr);
            if (h >= K) {
                result++;
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 30364
# Title: Shichi-Go-San
# Link: https://abc114.contest.atcoder.jp/tasks/abc114_a

import sys


sys.setrecursionlimit(10 ** 6)

read_single_int = lambda: int(sys.stdin.readline().strip())


def solution(x: int):
    if x == 3 or x == 5 or x == 7:
        return 'YES'
    return 'NO'


def main():
    x = read_single_int()
    print(solution(x))


if __name__ == '__main__':
    main()

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

#define MAX 100000
int N, M;
map<int, pair<int, int>> C;	 // Year, pair<ID, refecture>
string ID[MAX + 1];
int prefCities[MAX + 1];

string fillZero(string s) {
	while (s.size() < 6) {
		s = "0" + s;
	}
	return s;
}

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		int p, y;
		cin >> p >> y;
		ID[i] = fillZero(to_string(p));
		C[y] = make_pair(i, p);
	}
	for (int i = 1; i <= N; i++) {
        prefCities[i] = 0;
	}
	for (auto it = C.begin(); it != C.end(); it++) {
		ID[(*it).second.first] +=
			fillZero(to_string(++prefCities[(*it).second.second]));
	}
	for (int i = 1; i <= M; i++) {
		cout << ID[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 13568