akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<=(end);i++)
#define REP(i, n) FOR(i,1,n)
#define IFOR(i, begin, end) for(int i=(end);i>=(begin);i--)
#define IREP(i, n) IFOR(i,1,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

bool is_prime(int k)
{
    for(int j=2;j*j<=k;j++){
        if(k%j==0) {
            return false;
        }
    }
    return true;
}

int main()
{
	stringstream ss;
    // 入力
    int R;
    cin>>R;

    if(R<1200) cout<<"ABC"<<endl;
    else if(R<2800) cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> list = {111,222,333,444,555,666,777,888,999};
  for(int i=0; i<9; i++) {
    if(list.at(i) >= n) {
      cout << list.at(i) << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <typeinfo>
using namespace std;


// define list


namespace  math{
    const double PI = 3.14;
    const int INF = 1000000007;
    int GCM(int a,int b); //最大公約数
    int LCM(int a,int b); //最小公倍数
    int Pemu(int n,int r); //順列
    int Comb(int n,int m); //組み合わせ
    int Digit(int N); //桁和
    
    int GCM(int a,int b){
        if(a<b){
            swap(a,b);
        }
        int r = a%b;
        while (r!=0)
        {
            a=b;
            b=r;
            r=a%b;
        }
        return b;
    }

    int LCM(int a,int b){
        return a*(b/GCM(a,b));
    }

    int Pemu(int n,int r){
        int ans = n;
        for(int i=1;i<r;i++){
            ans*=(ans-i);
        }
        return ans;
    }

    int Comb(int n,int m){
        int a=n,b=m;
        for(int i=1;i<m;i++){
            a *= (a-i);
        }
        for(int i=1;i<m;i++){
            b *= (b-i);
        }
        
        return a/b;
    }

    int Digit(int N){
        if(N<10){
            return N;
        }
        int r = 0;
        while (N>=10)
        {
            r += (N%10);
            N /= 10;
        }
        r += N;
        return r;
    }
}

namespace SubLib{
    #define int long long
    #define double long double
    #define incin(n) int (n); cin >> (n);
    #define strcin(s) string (s); cin >> (s);
    #define incin2(a,b) int a,b; cin >> a >> b; 
    #define rap(n,i) for(int (i) = 0;i<(n);(i)++)
    #define input(n,v) (v) = SubLib::Input((n),(v))
    #define all(v) (v).begin(),(v).end()
    using intv = vector<int>;
    using strv = vector<string>;
    using charv = vector<char>;
    template <class T1>
    using pvec = vector<pair<T1,T1>>;
    template <typename T> vector<T> Input(int n,vector<T> v){
        for(int i=0;i<n;i++){
            cin >> v.at(i);
        }
        return v;
    }
}

using namespace math;
using namespace SubLib;

signed main(){
    strcin(w);
    int chars[200]={0};
    rap(w.size(),i){
        chars[w[i]]++;
    }
    rap(200,i){
        if(chars[i]%2==1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  ll ans = (n+k-3)/(k-1);
  cout << ans << endl;
  return 0;
}

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

using namespace std;
using LL = long long;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = (int)1e9 + 7;

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

    int n;
    cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    REP(i, n) cin >> x[i] >> u[i];

    double ans = 0;
    REP(i, n){
        ans += (u[i] == "JPY" ? x[i] : x[i] * 380000);
    }
    printf("%.9f\n", ans);
}

Measured memory_bytes: 256
import math, sys

a, b = map(int, input().split())
data = list(map(int, input().split()))
data.sort(reverse=True)

for i in range(b):
  if data[i] >= math.ceil(sum(data) / (4 * b)):
    pass
  else:
    print('No')
    sys.exit()
print('Yes')
            

Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;


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

  int N; cin >> N;
  rep(i, 100) {
    rep(j, 100) {
      if(4*i+7*j == N){
        cout << "Yes" << endl; return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
/*
 * Problem     : AOJ0010
 * Title       : A Point in a Triangle
 * Author      : mizo0203
 * Copyright   : Your copyright free
 * Description : 三角形による包含判定
 *               http://www5d.biglobe.ne.jp/~tomoya03/shtml/algorithm/Hougan.htm
 */

#include <stdio.h>
#include <math.h>
using namespace std;

typedef struct point {
  double x;
  double y;
} POINT;

POINT t[3], p;

bool input() {
  int i;

  for (i = 0; i < 3; i++) {
    if (scanf("%lf %lf", &t[i].x, &t[i].y) == EOF) return false;
  }
  scanf("%lf %lf", &p.x, &p.y);

  return true;
}

double intersectM(POINT p1, POINT p2, POINT p3, POINT p4) {
  return ((p1.x - p2.x) * (p3.y - p1.y) + (p1.y - p2.y) * (p1.x - p3.x))
      * ((p1.x - p2.x) * (p4.y - p1.y) + (p1.y - p2.y) * (p1.x - p4.x));
}

bool PosIncludeTriEx(POINT tp1, POINT tp2, POINT tp3, POINT xp) {

  if ((tp1.x - tp3.x) * (tp1.y - tp2.y) == (tp1.x - tp2.x) * (tp1.y - tp3.y))
    return false;

  if (intersectM(tp1, tp2, xp, tp3) < 0)
    return false;
  if (intersectM(tp1, tp3, xp, tp2) < 0)
    return false;
  if (intersectM(tp2, tp3, xp, tp1) < 0)
    return false;

  return true;
}

int main() {
  while (input()) {
    if (PosIncludeTriEx(t[0], t[1], t[2], p))
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 0
#-*-coding:utf-8-*-

def main():
    lines=[]
    rows,coloums = map(int,input().split())
    lines=[list(map(int,input().split())) for _ in range(rows)]
    colmus_total=[0]*coloums
    for line in lines:
        row_total=0
        row_output=" ".join(map(str,line))
        for col_index,data in enumerate(line):
            row_total+=data
            colmus_total[col_index]+=data
        print(row_output,row_total)
    col_output=" ".join(map(str,colmus_total))
    print(col_output,sum(colmus_total))

if __name__=="__main__":
    main()


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

int main(){
	int a, b, c;
	char op;
	while(1){
	cin >> a >> op >> b;
	if( op == '?' ) break;
	else if( op == '+' ) c = a + b; 
	else if( op == '-' ) c = a - b;
	else if( op == '*' ) c = a * b;
	else if( op == '/' ) c = a / b;
	cout << c << endl;	
}
return 0;
}

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

using namespace std;

int main() {
	int n, w, h, x, y, s, t;
	while (cin >> n && n) {
		cin >> w >> h;
		vector<vector<int> > grid(h + 1, vector<int>(w + 1, 0));
		for (int i = 0; i < n; ++i) {
			cin >> x >> y;
			grid[y][x]++;
		}
		cin >> s >> t;
		int ans = 0;
		for (int i = 1; i <= h - t + 1; ++i) {
			for (int j = 1; j <= w - s + 1; ++j) {
				int cnt = 0;
				for (int k = 0; k < t; ++k) {
					for (int l = 0; l < s; ++l) {
						if (grid[i + k][j + l]) cnt++;
					}
				}
				if (cnt > ans) ans = cnt;
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int n, ans = 0;
	vector<int> v;

	cin>> n;
	v.resize(n);
	for(int i=0;i<n;i++) cin>> v[i];

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

	for (int i = 0;i < v.size();i++) {
		for (int j = i + 1;j < v.size();j++) {
			auto tmp1 = lower_bound(v.begin() + j, v.end(), v[j] - v[i] + 1);
			auto tmp2 = lower_bound(v.begin() + j, v.end(), v[j] + v[i]);
			ans += distance(tmp1, tmp2) - 1;
			//cout << ans << " ";
		}
	}

	cout<< ans << endl;

}


Measured memory_bytes: 256
#ifdef DBG_MACRO_NO_WARNING
#include <dbg.h>
#endif
#include <bits/stdc++.h>
#define all(c) c.begin(), c.end()
#define isz(c) (int)c.size()

using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

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

    ll ans = max({a * c, a * d, b * c, b * d});
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
using namespace std;
int P[10010];
int N, M, A[10010], B[10010], COST[10010];
pair<int, int> bridge[10010];
void init(int n) {
 for (int i=0; i<n; ++i) { P[i] = i; }
}
int root(int a) {
 if (P[a] == a) return a;
 return (P[a] = root(P[a]));
}
bool is_same_set(int a, int b) {
 return root(a) == root(b);
}
void unite(int a, int b) {
 P[root(a)] = root(b);
}

int main() {
 while ((cin >> N >> M) && N>0) {
  for (int i=0; i<M; ++i) {
   cin >> A[i] >> B[i] >> COST[i];
   bridge[i].first = COST[i];
   bridge[i].second = i;
  }
  sort(bridge, bridge+M);
  init(N);
  int sum = 0;
  for (int i=0; i<M; ++i) {
   int cost = bridge[i].first;
   int a = A[bridge[i].second];
   int b = B[bridge[i].second];
   if (is_same_set(a,b)) { continue; }
   unite(a, b);
   sum += cost;
  }
  cout << sum << endl;
 }
}


Measured memory_bytes: 1256
MOD = 1000000007

N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))

H0 = [None for _ in range(N)]
H1 = [None for _ in range(N)]

incorrect = False

maxh = 0
for i in range(N):
    if maxh < T[i]:
        H0[i] = T[i]
        maxh = T[i]

maxh = 0
for i in reversed(range(N)):
    if H0[i] != None and H0[i] > A[i]:
        incorrect = True
    if maxh < A[i]:
        H1[i] = A[i]
        maxh = A[i]

ans = 1
for i in range(N):
    if H0[i]==None and H1[i]==None:
        ans *= min(A[i],T[i])
        ans %= MOD

print(ans if not incorrect else 0)

Measured memory_bytes: 19012
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N = int(input())
edge = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    edge[a].append((b,c))
    edge[b].append((a,c))
Q,K = map(int,input().split())
distance = [None] * (N+1)
def dfs(v1,d):
    distance[v1] = d
    for v2,dd in edge[v1]:
        if distance[v2] is not None:
            continue
        dfs(v2,d+dd)

dfs(K,0)

ans = [0] * Q
for i in range(Q):
    x,y = map(int,input().split())
    ans[i] = distance[x]+distance[y]
for a in ans:
    print(a)


Measured memory_bytes: 132712
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			if(sc.hasNextInt()){	//EOFについたらifが成り立たずbreakする
				int a = sc.nextInt();
				int b = sc.nextInt();
				System.out.println(GCD(a,b)+" "+LCM(a,b)); //公約数と公倍数を求めるメソッドは別に用意する
			} else { break; }
		}
	}
	static int GCD(int a, int b){
		int gcd =1;
		if(a==b){
			return a;
		}
		int gcdSup = Math.max(a, b)/2; //aとbの大きい方の半分
		for(int i=2; i<=gcdSup; i++){
			if(a%i==0){		//iがaの因数である場合
				if(b%i==0){  //iがbの因数である場合
					gcd = i; //iを新しい公約数として更新
				}
			}
		}
		return gcd;
	}
	static int LCM(int a, int b){
		int lcm = -1;
		int aTimes = a;
		int bTimes = b;
		while(true){
				while(aTimes < bTimes){
					aTimes = aTimes + a * ((bTimes - aTimes)/a) ;  //aの倍数がbの倍数に追い付くか抜くまで増やす
					if(aTimes==bTimes){
						return aTimes;
					} else { aTimes += a; }	//これをするとaの倍数がbの倍数を超える
				}
				while(bTimes < aTimes){
					bTimes = bTimes + b * ((aTimes - bTimes)/b);  //bの倍数がaの倍数に追い付くか抜くまで増やす
					if(aTimes==bTimes){
						return aTimes;
					} else { bTimes += b; }
				}
				if (aTimes == bTimes){ return aTimes;}
				if (aTimes > 2000000000){
					break;
				}
		}
		return lcm;
	}
}

Measured memory_bytes: 19016
n = int(input())
x = [float(x) for x in input().split()]
y = [float(x) for x in input().split()]
z = [0]*4

for _ in range(n):
    z[0] += abs(x[_] - y[_])
    z[1] += abs(x[_] - y[_])**2
    z[2] += abs(x[_] - y[_])**3
    if abs(x[_] - y[_]) > z[3]:
           z[3] = abs(x[_] - y[_])    

print(z[0])
print(z[1]**0.5)
print(z[2]**(1/3))
print(z[3])


Measured memory_bytes: 5664
N, X = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(N - 1) :
    if A[i] + A[i + 1] > X :
        if A[i] > X :
            ans += A[i] - X
            A[i] = X
        if A[i + 1] > X - A[i] :
            dis = A[i + 1] - (X - A[i])
            ans += dis
            A[i + 1] -= dis

print(ans)

Measured memory_bytes: 14252
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

int p[100002];

int main(){
  int N; cin >> N;
  for(int i=1; i<=N; ++i)
    cin >> p[i];
  int c = 0;
  for(int i=1; i<=N; ++i){
    if(p[i] == i){
      if(p[i+1] == i+1)
        swap(p[i], p[i+1]);
      ++c;
    }
  }
  cout << c << endl;
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<string> S(N);
	for (int i = 0; i < N; i++) cin >> S[i];

	bool flag = true;
	for (int i = 1; i < N; i++) {
		if (S[i - 1].back() != S[i][0]) {
			flag = false;
			break;
		}
		for (int j = i; j < N; j++){
			if (S[i - 1] == S[j]) {
				flag = false;
				break;
			}
		}
	}

	if (flag) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑




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

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

int main() {



	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll mon = lcm(c, d);
	ll cc = (b + c - 1) / c - (a + c) / c, dd = (b + d - 1) / d - (a + d) / d, cd = (b + mon - 1) / mon - (a + mon) / mon;
	if (a%c == 0) {
		++cc;
	}
	if (a%d == 0) { ++dd; }
	if (a%mon == 0) { ++cd; }

	if (b%c == 0) {
		++cc;
	}
	if (b%d == 0) { ++dd; }
	if (b%mon == 0) { ++cd; }
	//cout << cc << " " << dd << " " << cd << endl;
	cout << (b - a + 1) - (cc + dd - cd) << endl;

}

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 {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		int count = 0;

		for (int i = 0; i < line.length(); i++) {
			if (line.charAt(i) == 'o') {
				count++;

			}
		}

		System.out.println(700 + count * 100);

	}

}


Measured memory_bytes: 21204
#include <iostream>
#include <cstring>
#include <cctype>
#include <map>
using namespace std;

class Array
{
public:
	int size;
	map<int, int> val;
	
	Array() {}
	
	Array(int size)
	:size(size)
	{}
	
	bool Set(int pos, int v)
	{
		if(pos>=size) return false;
		val[pos]=v;
		
		return true;
	}
	
	bool At(int pos, int& v)
	{
		if(pos>=size) return false;
		map<int, int>::iterator it=val.find(pos);
		if(it == val.end()) return false;
		v=it->second;
		return true;
	}
	
	void Clear()
	{
		val.clear();
		size=-1;
	}
};

Array array[200];
bool bug, aid[200];
string expr;
int p;

int parseInt()
{
	int ret=0;
	while(p<expr.size())
	{
		if(!isdigit(expr[p])) break;
		ret*=10;
		ret+=expr[p]-'0';
		p++;
	}
	
	return ret;
}

char parseChr()
{
	char ret=expr[p];
	p++;
	
	return ret;
}

pair<char, int> parseArray()
{
	int v;
	char n=parseChr();
	p++;
	if(isalpha(expr[p]))
	{
		pair<char, int> pr=parseArray();
		if(!aid[pr.first]) bug=true;
		if(!array[pr.first].At(pr.second, v)) bug=true;
	}
	else v=parseInt();
	p++;
	
	return make_pair(n,v);
}

bool parse()
{
	p=0;
	pair<char, int> left=parseArray();
	if(bug) return false;
	if(expr[p]!='=') 
	{
		aid[left.first]=1;
		array[left.first] = Array(left.second);
	}
	else
	{
		p++;
		int v;
		if(!aid[left.first]) return false;
		if(isalpha(expr[p])) 
		{
			pair<char, int> right=parseArray();
			if(bug) return false;
			if(!aid[right.first]) return false;
			if(!array[right.first].At(right.second, v)) return false;
			if(!array[left.first].Set(left.second, v)) return false;
		}
		else
		{
			v=parseInt();
			if(!array[left.first].Set(left.second, v)) return false;
		}
	}
	
	return true;
}

int main()
{
	while(cin >> expr, expr!=".")
	{
		bug=false;
		int line=1;
		for(int i=0; i<200; i++)
		{
			array[i].Clear();
			aid[i]=0;
		}

		while(expr!=".")
		{
			if(!bug) if(!parse()) bug=true;
			cin >> expr;
			if(!bug) line++;
		}
		
		printf("%d\n", (bug?line:0));
	}
}

Measured memory_bytes: 0
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	N, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	scanner.Scan()

	S := scanner.Text()

	if N%2 != 0 {
		fmt.Println("No")
		os.Exit(0)
	}
	if S[:N/2] != S[N/2:] {
		fmt.Println("No")
		os.Exit(0)
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 1832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
using namespace std;

typedef long long llong;
// -2.1e-9 <= int <= 2.1e9

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

    int beki = 1;
    int C = K;
    while( (C - 1) < N ) {
        C *= K;
        ++beki;
    }
    cout << beki << endl;
}


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

using namespace std;
int main(void)
{
    int n, k;
    int l[50];

    cin >> n >> k;

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

    sort(l, l+n, greater<int>());

    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += l[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int kax = 1e5 + 10;

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n);
	vi cnts(kax);
	ll res = 0;
	rep(i,0,n) {
		cin >> a[i];
		++cnts[a[i]];
		res += a[i];
	}
	int q;
	cin >> q;
	rep(i,0,q) {
		ll b, c;
		cin >> b >> c;
		res = (res - cnts[b]*b + cnts[b]*c);
		cout << res << endl;
		cnts[c] += cnts[b];
		cnts[b] = 0;
	}
}

Measured memory_bytes: 4044
import Data.List
import Data.Char
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  [n, k] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  as <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  fs <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine 
  print $ binarySearch k (VU.fromList $ sort as) (VU.fromList $ reverse $ sort fs) (-1, 1100000000000000000)

binarySearch :: Int -> VU.Vector Int -> VU.Vector Int -> (Int, Int) -> Int
binarySearch k as fs (l, r)
  | r - l <= 1 = r
  | otherwise = if check mid
                  then binarySearch k as fs (l, mid)
                  else binarySearch k as fs (mid, r)
                where 
                  mid = (l + r) `div` 2
                  check :: Int -> Bool
                  check x = (VU.sum $ VU.filter (> 0) $ VU.zipWith (\a f -> a - x `div` f) as fs) <= k
                    

Measured memory_bytes: 38268
#include <iostream>
using namespace std;
using ll = long long;
int main() {
    ll n,m;
    cin >> n >> m;
    ll ans = 1;
    for (ll i = 0; i < n; ++i) {
        ans *= (m - i);
        ans %= 1000000007;
    }
    ll p = 1;
    ll q = 0;
    for (ll i = 0; i < n; ++i) {
        ll pp = p;
        ll qq = q;
        p *= (m - n);
        p += qq * (m - n + 1);
        q = (qq+pp) * (n - i - 1);
        p %= 1000000007;
        q %= 1000000007;
    }
    cout << ans*p%1000000007 << endl;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int n, m;
vector<int> k;
vector<int> p;
vector<vector<int>> s;
int answer = 0;
int light(vector<int>& ss, int num){
  int sum = 0;
  for(const auto & x : s[num]){
    if(ss[x-1] == 1){
      sum ++ ;
    }
  }
  int ans;
  if(sum % 2 == p[num]){
    ans = 1;
  }
  else{
    ans = 0;
  }
  return ans;
}

int subcomb(vector<int>& ss, int i, int nn, int mm){
  if(i == n){
    /*
    for(const auto & x : ss){
      cout << x;
    }
    */
    int sum = 0;
    for(int j = 0; j < m; j++){
      sum += light(ss, j);
    }
    if(sum == m){
      //cout << " o";
      answer ++;
    } else{
      //cout << " x";
    }
    //cout << endl;
    return 0;
  }
  for(int j = 1; j <= mm; j++){
    subcomb(ss, i + 1, nn, mm);
    ss[i] = j;
  }
  subcomb(ss, i + 1, nn, mm);
  ss[i] = 0;
  return 0;
}
void allcomb(int nn, int mm){
  vector<int>ss(nn,0);
  subcomb(ss, 0 , nn , mm);
}
int main()
{

  cin >> n >> m;
  s.resize(m);
  for(int i = 0; i < m; i++){
    int x;
    cin >> x;
    k.push_back(x);
    for(int j = 0; j < x; j++){
      int y;
      cin >> y;
      s[i].push_back(y);
    }
  }
  for(int i = 0; i < m; i++){
    int x;
    cin >> x;
    p.push_back(x);
  }  
  allcomb(n, 1);

  cout << answer;
  return 0;
}

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

using namespace std;

#define tie() ios_base :: sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long

const int N = 2e5 + 20;


bool vis[N];

int cnt = 0;

vector <int> g[N];
int last[N];


int dfs(int x , int k)
{
    if(k == 0 or g[x].empty())
        return x;
    cnt++;
    if(vis[x])
    {
        if(k > (cnt - last[x]))
            k %= (cnt - last[x]);
        if(k == 0 or g[x].empty())
            return x;
        return dfs(g[x][0] , k - 1);
    }
    vis[x] = true;
    last[x] = cnt;
    return dfs(g[x][0] , k - 1);
}

int32_t main()
{
    tie();
    int t = 1;
    //cin >> t;
    while(t--)
    {
    	int n , k;
        cin >> n >> k;

        int to;

        for(int i = 1 ; i <= n ; i++)
        {
            cin >> to;
            g[i].push_back(to);
        }

        memset(vis , false , sizeof vis);
        cout << dfs(1 , k) << endl;

    }
	return 0;
}


Measured memory_bytes: 16316
import sys,fractions
N,M=map(int,input().split())
S=input()
T=input()

x=1

gcd=fractions.gcd(M,N)

if gcd==0:
  print(-1)
  sys.exit()

if S[0]!=T[0]:
  print(-1)
  sys.exit()

lst=[S[0]]


lcm=(M*N)//gcd
dn=lcm//N
dm=lcm//M

dlcm=(dn*dm)//fractions.gcd(dn,dm)

for i in range(lcm//dlcm):
  if S[dlcm*i//dn] != T[dlcm*i//dm]:
    print(-1)
    sys.exit()
print(lcm)


Measured memory_bytes: 5344
#include <stdio.h>
#include <stdlib.h>

typedef int wint[2];

int compar(wint *a, wint *b)
{
  if ((double)((*a)[0])/(*a)[1] < (double)((*b)[0])/(*b)[1]) return 1;
  if ((double)((*a)[0])/(*a)[1] > (double)((*b)[0])/(*b)[1]) return -1;
  else return 0;
}

int main()
{
    int i, n, w;
    char buf[32];
    scanf("%d %d\n", &n, &w);

    int val[n][2];
    char *p;
    for (i=0; i<n; i++) {
      fgets(buf, 32, stdin);
      for (val[i][0]=0,p=buf; *p!=' ';  val[i][0] = val[i][0] * 10 + *(p++) - '0');
      for (val[i][1]=0,p++;   *p!='\n'; val[i][1] = val[i][1] * 10 + *(p++) - '0'); 
    }
    
    double total=0;
    qsort(val, n, sizeof(int)*2, (int(*)(const void*, const void*))compar);
    for (i=0; i<n; i++) {
       if (w>=val[i][1]) {
        w -= val[i][1];
        total += val[i][0];
      }	else {
	 total += (double)w*val[i][0]/val[i][1];
	 break;
      }
    }
    printf("%.12f\n", total);
    
    return 0;
}



Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<double,double>P;
int n,x[3001],y[3001];
set<P>st;
int main(){
	while(cin>>n,n){
		st.clear();
		r(i,n){
			cin>>x[i]>>y[i];
			st.insert(P(x[i],y[i]));
		}
		int ans=0;
		r(i,n)r(j,n)if(i!=j){
			int tx1=x[i]-x[j],ty1=y[i]-y[j];
			int tx2=x[i]+ty1,ty2=y[i]-tx1;
			int tx3=x[j]+ty1,ty3=y[j]-tx1;
			int tx4=x[i]-ty1,ty4=y[i]+tx1;
			int tx5=x[j]-ty1,ty5=y[j]+tx1;
			if(st.count(P(tx2,ty2))&&st.count(P(tx3,ty3))||
			   st.count(P(tx4,ty4))&&st.count(P(tx5,ty5))){
				ans=max(ans,tx1*tx1+ty1*ty1);
			}
		}
		cout<<ans<<endl;
	}
}

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

const int maxn = 1e5 + 5;
vector<int> edges[maxn];
int n, m, vis[maxn], dp[maxn];
int in[maxn];

void dfs(int x){
	vis[x] = 1;
	for(auto i : edges[x]){
		dp[i] = max(dp[i], dp[x] + 1);
		in[i] -= 1;
		if(in[i] == 0){
			dfs(i);
		}
	}
}

int main(int argc, char const *argv[])
{
//	freopen("in.txt", "r", stdin);
	scanf("%d %d", &n, &m);
	for(int i=0; i<m; i++){
		int x, y; 
		scanf("%d %d", &x, &y);
		edges[x].push_back(y);
		in[y] += 1;
	}
	for(int i=1; i<=n; i++){
		if(!vis[i] && in[i] == 0){
			dfs(i);
		}
	}
	int ans = 0;
	for(int i=1; i<=n; i++){
		ans = max(ans, dp[i]);
	}cout << ans <<endl;

	return 0;
}

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

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

    int res = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        while (a % 2 == 0) {
            res++;
            a /= 2;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

long long digitsum(long long n) {
	long long ans = 0;
	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

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

	long long n, i, j, k, x, v, d, ans;
	string s;
	cin >> n;
	s = to_string(n);
	ans = digitsum(n);
	d = 1;
	for (i = 1; i < s.length(); i++) {
		n /= 10;
		d *= 10;
		x = (n - 1) * d + (d - 1);
		ans = max(ans, digitsum(x));
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::unordered_map;
  using std::pair;
  using std::cin;
  using std::cout;
  ui N{}; std::cin >> N;
  ui K{N / 2};
  typedef pair<ui, ull> Pair;
  unordered_map<ui, ull> m1{}, m2{};
  rep(0, K)
  {
    ui a{}, b{}; cin >> a >> b;
    ++m1[a]; ++m2[b];
  }
  vector<Pair> vp1; vp1.reserve(m1.size());
  vector<Pair> vp2; vp2.reserve(m2.size());
  for(Pair p : m1) vp1.push_back(p);
  for(Pair p : m2) vp2.push_back(p);
  
  auto cmp = [](Pair p1, Pair p2){ return p1.second > p2.second; };
  boost::sort(vp1, cmp);
  boost::sort(vp2, cmp);
  if(vp1.size() == 1) vp1.push_back({0, 0});
  if(vp2.size() == 1) vp2.push_back({0, 0});

  ull ans{};
  if(vp1[0].first != vp2[0].first)
  {
    ans += K - vp1[0].second + K - vp2[0].second;
  }
  else
  {
    auto res0 = K - vp1[0].second + K - vp2[1].second;
    auto res1 = K - vp1[1].second + K - vp2[0].second;
    ans += std::min(res0, res1);
  }

  cout << ans << '\n';
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

void solve(long long a, long long b) {
  // solver code

  int tmp = a < b ? a : b;
  int len = a < b ? b : a;
  for (int i = 0; i < len; i++) cout << tmp;
  cout << endl;
}

int main() {
  long long a;
  scanf("%lld", &a);
  long long b;
  scanf("%lld", &b);
  solve(a, b);
  return 0;
}


Measured memory_bytes: 256
// In the name of Allah the Lord of the Worlds.

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

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

    ll a, b;
    cin >> a >> b;
    cout << max(a+b , max(a-b , a*b)) << endl;

    return 0;
}


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

#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define debg(a) cout<<#a<<":"<<a<<endl;
#define vint vector<signed>
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define yn(a) cout<<((a)?"Yes":"No")<<endl;
#define YN(a) cout<<((a)?"YES":"NO")<<endl;
int ans[31];
signed main(){
  int n,m;
  cin>>n>>m;
  int k[n],a[n][m];
  rep(i,n){
      cin>>k[i];
      rep(j,k[i]){
          cin>>a[i][j];
      }
  }
  //rep(i,n)rep(j,k[i])cout<<a[i][j]<<" ";cout<<endl;
  
  rep(i,n){
      rep(j,k[i]){
          ans[a[i][j]]++;
          
      }
  }
  int res=0;
  rep(i,m+1)if(ans[i]==n)res++;
  cout<<res;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

   cout << (a+b)%24 << endl;

   return 0;
}

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



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

int main(void) {
    string a, b, c;
    cin >> a >> b >> c;
    if (*(a.end() - 1) == *b.begin() && *(b.end() - 1) == *c.begin()) cout << "YES";
    else cout << "NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[7000];
int main()
{
int n;
int t;
cin>>n;
int si,maxi,wa;
si=0;
maxi=0;
wa=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
maxi+=a[i];
}
sort(a,a+n);
int s=0;
if(n%2==0)
for(int i=0;i<n;i+=2)
s=s+a[i];
else
for(int i=1;i<n;i+=2)
s=s+a[i];
cout<<maxi-s-s;
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        String s=in.nextLine();
        long sum=0;
        char ch[]=s.toCharArray();
        for (int i = 0; i <s.length(); i++) {
            sum+=(int)ch[i]-48;
        }
        if(sum%9==0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
}
}

Measured memory_bytes: 41820
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;


const long long MOD = 1000000007;

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

	int n;
	cin >> n;
	int* a;
	a = new int[n];
	rep(i, n) cin >> a[i];

	rep(i, n) {
		if ((a[i] & 1) == 0) {
			if (a[i] % 3 != 0 && a[i] % 5 != 0) {
				cout << "DENIED" << "\n";
				return 0;
			}
		}
	}

	cout << "APPROVED" << "\n";

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n,m,d;cin>>n>>m>>d;
    ld res=0;
    res += 1.0*(n-d)/(n*n);
    if(d!=0) res *= 2;
    res *= m-1;
    cout<<fixed<<setprecision(10)<<res<<endl;
}

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

using namespace std;

vector<long long> pbunkai(long long n){
    vector<long long> ret;
    for (long long i = 1; i*i <= n; ++i) {
        if(n%i==0){
            ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
        }
    }
    return ret;
};

int main(){
    long long n;
    cin>>n;
    auto pa=pbunkai(n);
    long long ans=0;
    for(auto i:pa){
        if(2<=(n/i-i))ans+=(n/i-1);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn=2009;
const int maxk=10009;
int n,K,len[maxn];
char s[maxn][maxk];
bitset<maxk> bit[maxn];
pii v[2][maxk];
int main()
{
    scanf("%d%d",&n,&K);
    for (int i=1;i<=n;++i) {
        scanf("%s",s[i]);
        len[i]=strlen(s[i]);
    }
    bit[n+1][0]=1;
    for (int i=n;i>=1;--i)
        bit[i]=bit[i+1]|(bit[i+1]<<len[i]);
    int c1=0;
    for (int i=1;i<=n;++i)
        if (bit[i+1][K-len[i]])
            v[1][++c1]=pii(i,0);
    for (int o=1;o<=K;++o) {
        char mmin='z';int c2=0;
        for (int i=1;i<=c1;++i)
            mmin=min(mmin,s[v[o&1][i].first][v[o&1][i].second]);
        putchar(mmin);
        int ID=n+1;
        for (int i=1;i<=c1;++i) {
            int id=v[o&1][i].first,pos=v[o&1][i].second;
            if (s[id][pos]!=mmin) continue;
            if (pos+1==len[id]) ID=min(ID,id);
            else v[(o+1)&1][++c2]=pii(id,pos+1);
        }
        for (int i=ID+1;i<=n;++i)
            if (K-o-len[i]>=0&&bit[i+1][K-o-len[i]])
                v[(o+1)&1][++c2]=pii(i,0);
        c1=c2;
    }
    return 0;
}


Measured memory_bytes: 15100
#include<cstdio>
#include<algorithm>
#include<bitset>
using namespace std;

int n;
char p[2100][2100];
int w[2100][2100], Right[2100], Left[2100], TLeft[2100];
bitset<2100>B[2100], U, RR[2100];
int main() {
	int i, j;
	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%s", p[i]);
		for (j = 0; j < i; j++) {
			if (p[i][j] == '1') {
				w[i][j] = 1;
			}
			else w[j][i] = 1;
		}
	}
	for (i = n - 1; i >= 0; i--) {
		RR[i][i] = 1;
		if (i == n - 1) {
			Right[i] = 1;
			Left[i] = 1;
			continue;
		}
		Left[i] = 1;
		for (j = i + 1; j < n; j++) {
			if (w[i][j] && Right[j] && Left[j]) {
				Right[i] = 1;
			}
			if (w[i][j] && Left[j]) {
				RR[i] |= RR[j];
			}
		}
		for (j = i + 1; j < n; j++) {
			if (RR[i][j - 1] && w[j][i]) B[j][i] = 1;
		}
		U.reset();
		U[i] = 1;
		for (j = i + 1; j < n; j++) {
			if ((U & B[j]).count()) {
				Left[j] = 1;
				U[j] = 1;
			}
			else {
				Left[j] = 0;
			}
		}
	}
	int res = 0;
	for (i = 0; i < n; i++) {
		if (Right[i] && Left[i])res++;
	}
	printf("%d\n", res);
}

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

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

    vector <int> a(n);
    
    for (int i = 0; i < n; i++) 
        cin >> a[i];
        
    int light = 1, ans = 1;
    for (int i = 0; i < n; i++) {
        if (a[light - 1] == 2)break;
        else light = a[light - 1], ans++;
    }
    if (ans <= n)cout << ans << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 768
#include<stdio.h>

int senkei();

int main(){
  int i = 0;
  int count2;
  int setdata[10000 + 1];
  int change;
  int key;
  int sum = 0;

  scanf("%d",&count2);

  for(i = 0;i < count2;i++){
    scanf("%d",&setdata[i]);
  }

  scanf("%d",&change);

  for(i = 0;i < change;i++){
    scanf("%d",&key);

    if(senkei(setdata,count2,key)){
      sum++;
    }
  }
  printf("%d",sum);
  printf("\n");
  return 0;
}


int senkei(int data[],int count,int key){
  int i = 0;
  
  data[count] = key;

  while(data[i] != key){
    i++;
  }
  return i != count;
}



Measured memory_bytes: 2128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!

    long long N,tmp,ans=0;
    vector<long long> v;
    
    cin >> N;
    
    for(int i=0;i<N;i++){
        cin >> tmp;
        v.push_back(tmp);
    }
    
    sort(v.begin(),v.end());

    for(int j=0;j<N;j++){
        for(int k=0;k<N;k++){
            for(int l=0;l<N;l++){
                if(v[l]<v[j]+v[k]&&v[j]!=v[k]&&v[l]!=v[k]&&v[j]!=v[l]&&v[l]>v[k]&&v[k]>v[j]){
                    ans++;
                    //cout << v[j] << ", " <<v[k] << ", "<<v[l]<<endl;
                } 
            }
        }
    }
    cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

	const int MOD = 100000;

    while (true) {
        int W, H;
        cin >> W >> H;
        if (W == 0 and H == 0) {
            break;
        }

        vector<vector<vector<vector<LL>>>> dp(H, vector<vector<vector<LL>>>(W, vector<vector<LL>>(3, vector<LL>(3, 0))));
        dp[0][0][0][0] = 1;

        FOR(y, 0, H) {
            FOR(x, 0, W) {
                FOR(i, 0, 3) {
                    FOR(j, 0, 3) {
                        if (y + 1 < H) {
                            if (j != 1 or i != 2) {
                                (dp[y + 1][x][1][i] += dp[y][x][i][j]) %= MOD;
                            }
                        }
                        if (x + 1 < W) {
                            if (j != 2 or i != 1) {
                                (dp[y][x + 1][2][i] += dp[y][x][i][j]) %= MOD;
                            }
                        }
                    }
                }
            }
        }

        LL ans = 0;
        FOR(i, 0, 3) {
            FOR(j, 0, 3) {
                (ans += dp[H - 1][W - 1][i][j]) %= MOD;
            }
        }
        print(ans);
    }
	return 0;
}


Measured memory_bytes: 5088
#include <bits/stdc++.h>
#define WHOLE(v) v.begin(), v.end()
using namespace std;
int main() {
    string S;
    cin >> S;
    int y, m, d;
    y = stoi(S.substr(0, 4));
    m = stoi(S.substr(5, 2));
    if(y < 2019 || y == 2019 && m < 5) {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
    return 0;
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	int s, w;
	cin >> s >> w;
	if (w >= s)
		cout << "unsafe" << endl;
	else
		cout << "safe" << endl;
	return 0;
}

//!

Measured memory_bytes: 3648
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int ans = (n % 2 == 0) ? n / 2 : n / 2 + 1;
        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
n = int(input())
a = list(map(int, input().split()))
odd, even, four = 0, 0, 0
for x in a:
    if x % 2:
        odd += 1
    else:
        if x % 4 == 0:
            four += 1
        else:
            even += 1
if even == 0:
    if four >= odd - 1:
        print('Yes')
    else: print('No')
else:
    if four >= odd:
        print('Yes')
    else: print('No')

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n+2);
  a.at(0) = 0;
  for(int i=1;i<n+1;i++){
    cin >> a.at(i);
  }
  a.at(n+1) = 0;
  
  ll dist = 0;
  for(int i=1;i<n+2;i++){
    dist += abs(a.at(i) - a.at(i-1));
  }
  
  //cout << dist << endl;
  for(int i=1;i<n+1;i++){
    cout << dist + abs(a.at(i+1) - a.at(i-1)) - (abs(a.at(i+1) - a.at(i)) + abs(a.at(i) - a.at(i-1))) << endl; 
  }
  
  return(0);
}

Measured memory_bytes: 3780
def Attention():
    N = int(input())
    S = input()
    ans = 300000

    Wcount = [0]
    Ecount = [0]
    cnt = 0
    for i in range(N):
        if S[i] == 'W':
            cnt += 1
        Wcount.append(cnt)
    cnt = 0
    for i in range(N):
        if S[(i + 1) * -1] == 'E':
            cnt += 1
        Ecount.append(cnt)

    for i in range(N):
        cnt = Wcount[i] + Ecount[(i + 2) * -1]
        ans = min(cnt, ans)
    print(ans)

Attention()


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

int main(){
  int A,B,k; cin >> A >> B;
  
  k=(A+B)/2;
  
  if((A+B)%2==0){
    cout << k << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
class Airplane:
    def __init__(self):
        self.P, self.Q, self.R = map(int, input().split())

    def calMineTime(self):
        lines = [self.P, self.Q, self.R]
        lines.sort()

        print(lines[0] + lines[1])


airPlane = Airplane()
airPlane.calMineTime()


Measured memory_bytes: 2940