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

using namespace std;

bool judge(string S) {
	string tmp = S;
	reverse(tmp.begin(), tmp.end());

	if (S == tmp)return true;
	else return false;
}

int main(void) {
	string S, substr1, substr2;

	cin >> S;

	substr1 = S.substr(0, (S.size() - 1) / 2);
	substr2 = S.substr((S.size() + 3) / 2 -1, (S.size() - 1) / 2);

	if (judge(S) && judge(substr1) && judge(substr2)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc081/tasks/abc081_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int cnt;
  string s;

  cin >> s;

  for (size_t i = 0; i < s.length(); i++)
  {
    if (s[i] == '1')
      cnt++;
  }

  cout << cnt;

  return 0;
}


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

int main() {
  int D, G; cin >> D >> G;
  int P[D], C[D]; for (int i = 0; i < D; i++) cin >> P[i] >> C[i];
  int min_p = 1e+9;
  for (int b = 0; b < (1<<D); b++) {
    int p = 0;
    int point = 0;
    for (int i = 0; i < D; i++) {
      if (b & (1<<i)) {
        point += 100*(i+1)*P[i]+C[i];
        p += P[i];
      }
    }
    for (int i = D-1; i >= 0; i--) {
      if (!(b & (1<<i)) && point < G) {
        if (point + 100*(i+1)*(P[i]-1) <= G) {
          point += 100*(i+1)*(P[i]-1);
          p += P[i]-1;
        } else {
          p += (G-point+100*i)/(100*(i+1));
          point = G;
        }
      }
    }
    if (point >= G) {
      min_p = min(min_p, p);
    }
  }
  cout << min_p << endl;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)
for i in range(n - 1):
    if (a[i + 1] - a[i]) == 1:
        ans += c[a[i] - 1]

print(ans)


Measured memory_bytes: 3060
H = int(input())
W = int(input())
N = int(input())
Hcount = 0
Wcount = 0


list = [[0 for i in range(W)] for j in range(H)]

#if (W < H):
for k in range(W):
    Hcount = H*(k+1)
    if(Hcount >= N):
        Hcount = k+1
        break
        #exit()
    else:
        continue

#elif (W > H):
for l in range(H):
    Wcount = W*(l+1)
    if(Wcount >= N):
        Wcount = l+1
        break
        #exit()
    else:
        continue

print(min(Hcount,Wcount))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 100000

using namespace std;

int v[maxn+5][5], d[maxn+5][5];
queue<pii> qu;///fi=zi se=cf

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n; cin >> n;
  int i, j, z;
  for (i = 1; i <= n; i++) cin >> v[i][1] >> v[i][2] >> v[i][3];
  for (j = 1; j <= 3; j++) {
    d[1][j] = v[1][j];
    qu.push({1, j});
  }
  while (!qu.empty()) {
    pii cur = qu.front(); qu.pop();
    for (j = 1; j <= 3; j++)
      if (cur.fi < n && j != cur.se && d[cur.fi+1][j] < d[cur.fi][cur.se]+v[cur.fi+1][j]) {
        d[cur.fi+1][j] = d[cur.fi][cur.se]+v[cur.fi+1][j];
        qu.push({cur.fi+1, j});
      }
  }
  cout << max({d[n][1], d[n][2], d[n][3]});
  return 0;
}


Measured memory_bytes: 4224
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=2000003;
int bit1[maxn];
ll a[maxn];
ll b[maxn],c[maxn];
int main(){
  int n;
  ll k;
  cin>>n>>k;
  fill(a,a+maxn,0LL);
  fill(b,b+maxn,0LL);
  fill(c,c+maxn,0LL);
  for(int i=0;i<n;i++){
    int ta;
    ll tb;
    cin>>ta>>tb;
    a[ta]+=tb;
  }
  int now=1;
  for(int i=0;i<maxn;i++){
    if(a[i]!=0LL){
      b[now]=a[i];
      b[now]+=(ll)b[now-1];
      c[now]=(ll)i;
      now++; 
    }
  }
  
  int l=-1,r=now,mid;
  while(r-l>1){
    mid=(l+r)/2;
    //cout<<l<<" "<<r<<" "<<mid<<" "<<b[mid]<<endl;
    if(b[mid]>=k)r=mid;
    else l=mid;
  }
  cout<<c[r]<<endl;


  return 0;
}


Measured memory_bytes: 47360
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10, mod = 1e9 + 7;
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 21
#endif // LOCAL
using ll = long long ;
void plusle(int &a, int b){
    if((a += b) >= mod) a -= mod;
}
void minun(int &a, int b){
    if((a -= b) < 0) a += mod;
}
int mul(int a, int b){
    return (1LL * a * b) % mod;
}
int power(int a, ll b){
    int res = 1;
    for(; b > 0 ; b >>= 1 , a = mul(a, a))
        if(b & 1)
            res = mul(res, a);
    return res;
}
ll h, w, t;


int main(){
    /// no static D R can be together at the same time
    /**
    3 Case S D -> 2 ^ C-group
    S R 2 ^ R-group
    D R 2 ^ gcd(R - group , C - group)
    and compute each group independently
    */
    scanf("%lld %lld %lld", &h, &w, &t);
    int res = 0;
    ll cshift = (t % w == 0)? w : t % w;
    ll rshift = (t % h == 0) ? h : t % h;

    ll rgroup = __gcd(h, rshift);
    ll cgroup = __gcd(w, cshift);

    ll row = h / rgroup;
    ll col = w / cgroup;

    plusle(res, power(2, row));
    plusle(res, power(2, col));
    plusle(res, power(2, __gcd(row, col)));
    minun(res, 3);
    res = power(res, rgroup);
    res = power(res, cgroup);
    printf("%d\n", res);

}

/*
    Long time no see!
    Atcoder...
*/


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

int main(void){
    int s,m,h,S;
    cin >> S;

    h=S/3600;
    m=(S-3600*h)/60;
    s=S%60;
    
    cout << h;
    cout << ":";
    cout << m;
    cout << ":";
    cout << s;
    cout << endl;
}


Measured memory_bytes: 3116
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

int to[200001], ne[200001];
int H[100001], PM[100001], Pm[100001];
bool OK = true;
pair<int, int> sagasu(int A, int pre) {
	bool OE[2] = {};
	if (PM[A] < 1e6) OE[PM[A] & 1] = 1;
	for (int i = H[A]; i; i = ne[i]) {
		if (to[i] != pre) {
			auto p = sagasu(to[i], A);
			if (p.first < 1e6) OE[p.first & 1] = 1;
			PM[A] = min(PM[A], p.first);
			Pm[A] = max(Pm[A], p.second);
		}
	}
	if (OE[0] && OE[1]) OK = false;
	if (PM[A] < Pm[A]) OK = false;
	return mp(PM[A] + 1, Pm[A] - 1);
}
void sagasu2(int A, int M, int prev) {
	if (M + 1 <= PM[A]) PM[A] = M + 1;
	else PM[A] = M - 1;
	for (int i = H[A]; i; i = ne[i]) {
		if (to[i] != prev) sagasu2(to[i], PM[A], A);
	}
}

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


	int N = getint();
	for (int i = 1; i < 2 * (N - 1); i += 2) {
		int a = getint(), b = getint();
		to[i] = a;
		ne[i] = H[b];
		H[b] = i;
		to[i + 1] = b;
		ne[i + 1] = H[a];
		H[a] = i + 1;
	}
	int K = getint();
	int v, p;
	rep1(i, N) {
		PM[i] = 5e6;
		Pm[i] = -5e6;
	}
	rep(i, K) {
		v = getint();
		p = getint();
		PM[v] = p;
		Pm[v] = p;
	}

	sagasu(1, 0);

	if (OK) {
		sagasu2(1, PM[1] - 1, 0);
		*di++ = 'Y';
		*di++ = 'e';
		*di++ = 's';
		*di++ = '\n';
		rep1(i, N) putint(PM[i]);
		fwrite_unlocked(dn, di - dn, 1, stdout);
	}
	else printf("No");

	Would you please return 0;
}

Measured memory_bytes: 10624
A,B,Q = map(int,input().split())
import bisect
s=[]
t=[]
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
s = [-10**20] + s + [10**20]
t = [-10**20] + t + [10**20]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = 10**20
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)



Measured memory_bytes: 12776
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template<typename T> using Graph = vector<vector<T>>;
template<typename T> using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

template<typename T> struct is_pair : false_type{};
template<typename T1, typename T2> struct is_pair<pair<T1, T2>> : true_type{};
template<typename T> struct is_vector : false_type{};
template<typename T> struct is_vector<vector<T>> : true_type{};

template<typename T1, typename T2>
istream &operator >> (istream &istr, pair<T1, T2> &p) {
  istr >> p.first >> p.second;
  return istr;
} 
template<typename T1, typename T2>
ostream &operator << (ostream &ostr, const pair<T1, T2> &p) {
  ostr << p.first << " " << p.second;
  return ostr;
}
template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) return ostr;
  bool vp = is_vector<T>() || is_pair<T>();
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    ostr << (vp ? "\n" : " ") << *itr;
  }
  return ostr;
}

template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int modpow(int a, long long n, int mod = MOD) {
  int ret = 1;
  do {
    if (n & 1) ret = 1LL * ret * a % mod;
    a = 1LL * a * a % mod;
  } while (n >>= 1);
  return ret;
}

template<typename T>
T GCD(T a, T b) { return b ? GCD(b, a%b) : a; }
template<typename T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

template<typename T1, typename T2>
bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) {
  return a.second != b.second ? a.second < b.second : a.first < b.first;
}
template<typename T>
bool CompareBySlope(pair<T, T> a, pair<T, T> b) {
// counterclockwise from 12 o'clock direction
  if (a.first * b.first < 0) return a.first < b.first;
  if (a.first == 0) return a.second >= 0 || b.first > 0;
  if (b.first == 0) return b.second < 0 && a.first < 0;
  return a.second * b.first < a.first * b.second;
}


/* -------- <templates end> -------- */


void solve() {
  int n, k, s; cin >> n >> k >> s;

  int v = 1e9;
  if (s == 1e9) --v;
  vi ans(n, v);
  rep(i,k) ans[i] = s;
  cout << ans << endl;
}


/* -------- <programs end> -------- */


signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, p[10], mx = 0, sm = 0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> p[i];
    mx = max(mx, p[i]);
    sm += p[i];
  }
  cout << (sm - mx/2) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#define SIZE 200005

using namespace std;
typedef long long int ll;

struct Q
{
	ll sum,cnt;
	Q(ll sum=0,ll cnt=0):sum(sum),cnt(cnt){};
	bool operator<(const Q&l) const
	{
		return sum*l.cnt<cnt*l.sum;
	}
	bool operator>(const Q&l) const
	{
		return sum*l.cnt>cnt*l.sum;
	}
};
vector <int> vec[SIZE];
vector <int> tree[SIZE];
priority_queue <Q> dp[SIZE];
set <Q>::iterator it;
int C[SIZE],nm[SIZE];
ll ans;
int n;

void dfs(int v,int p,int b)
{
	if(C[v]==1)
	{
		tree[b].push_back(v);
		b=v;
	}
	else nm[b]++;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		dfs(to,v,b);
	}
}
void solve(int v)
{
	for(int i=0;i<tree[v].size();i++)
	{
		int to=tree[v][i];
		solve(to);
		if(dp[to].size()>dp[v].size()) swap(dp[v],dp[to]);
		while(!dp[to].empty())
		{
			dp[v].push(dp[to].top());
			dp[to].pop();
		}
	}
	Q now=Q(nm[v],1);
	while(!dp[v].empty())
	{
		Q q=dp[v].top();
		if(q>now)
		{
			ans+=now.sum*q.cnt;
			now.sum+=q.sum;
			now.cnt+=q.cnt;
			dp[v].pop();
		}
		else break;
	}
	dp[v].push(now);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int p;
		scanf("%d",&p);p--;
		vec[p].push_back(i);
	}
	for(int i=0;i<n;i++) scanf("%d",&C[i]);
	int rt=n;
	dfs(0,-1,rt);
	ans=0;
	solve(rt);
	ll zan=0;
	while(!dp[rt].empty())
	{
		Q q=dp[rt].top();dp[rt].pop();
		//printf("[%lld %lld]\n",q.sum,q.cnt);
		ans+=zan*q.cnt;
		zan+=q.sum;
	}
	ll all=0;
	int z=0;
	for(int i=0;i<n;i++) if(C[i]==0) z++;
	all=(ll) z*(ll) (n-z+1);
	//printf("%lld : %d %lld\n",ans,z,all);
	printf("%lld\n",all-ans-z);
	return 0;
}


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

int main() {
  int K;
  string S;
  
  cin >> K;
  cin >> S;
  
  if(S.size() > K){
    for(int i = 0 ; i < K ; i++){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }else{
    cout << S << endl;
  }
}

Measured memory_bytes: 3600
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e6+5;
int n,m,cnt[maxn],a[maxn];
bool vis[maxn];
vector<int> v;
int gcd(int a,int b)
{
	if(!b) return a;
	return gcd(b,a%b);
}
int main()
{
	for(int i=2;i<maxn;i++){
		if(vis[i]) continue;
		v.push_back(i);
		for(int j=2*i;j<maxn;j+=i){
			vis[j]=true;
		}
	}
    scanf("%d",&n);
    for(int i=0;i<n;i++){
    	scanf("%d",&a[i]);
    	cnt[a[i]]++;
	}
	int len=v.size();
	bool ispairwise=true;
	for(int i=0;i<len;i++){
		int k=0,u=v[i];
		for(int j=u;j<maxn;j+=u){
			k+=cnt[j];
			if(k>1) break;
		}
		if(k>1){
			ispairwise=false;
			break;
		}
	}
	if(ispairwise) printf("pairwise coprime");
	else {
		int x=a[0];
		for(int i=1;i<n;i++){
			x=gcd(x,a[i]);
		}
		if(x==1) printf("setwise coprime");
		else printf("not coprime");
	}
	return 0;
}

Measured memory_bytes: 12016
function bomb(x,sum){
   sum=sum+x+1;
   if(sum>v)return;
   if(sum==v){CNT++;return;}
   bomb(x+1,sum);
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
for(var I=0;I<Arr.length;I++){
   var v=Arr[I];
   if(v==0)break;
   var CNT=0;
   for(var i=1;i<=1000;i++){
      if(i>=v)break;
      bomb(i,i);
   }
   console.log(CNT);
}

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

int main()
{
	int n=0;
	int int_taro=0,int_hanako=0;
	char taro[100]={'\0'},hanako[100]={'\0'};

	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%s %s",&taro,&hanako);
		
		for(int j=0;j<100;j++)
		{
			if(taro[j]>hanako[j]){
				int_taro+=3;
				break;
			}
			else if(taro[j]<hanako[j]){
				int_hanako+=3;
				break;
			}
			else if(taro[j]=='\0'&&hanako[j]=='\0'){
				int_taro++;
				int_hanako++;
				break;
			}
		}
	}
	printf("%d %d\n",int_taro,int_hanako);

	return 0;
}

Measured memory_bytes: 2736
'use strict'

const main = (input) => {
    input = input.split('\n')
    const words = input.slice(1, parseInt(input[0]) + 1)

    //重複チェック
    for(let i = 0; i <= words.length; i++){
        for(let j = i + 1; j <= words.length; j++){
            if(words[i] === words[j]){
                console.log('No')
                return
            }
        }
    }
    
    for(let i = 0; i < words.length - 1; i++){
        if(words[i].slice(-1) !== words[i+1].slice(0, 1)){
            console.log('No')
            return 
        }
    }
    console.log('Yes')
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
using Int = long long;
int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int money = 0;
    if ((A + B) < 2*C) {
        cout << A * X + B * Y << endl;
    } else {
        int m = min(X, Y);
        money = 2 * C * m;
        X -= m;
        Y -= m;
        if (X) {
            if (A > 2*C) money += 2 * C * X;
            else money += A * X;
        }
        if (Y) {
            if (B > 2*C) money += 2 * C * Y;
            else money += B * Y;
        }
        cout << money << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = solve <$> f <*> f >>= print
  where
    f = readil B.readInt <$> B.getLine

solve :: [Int] -> [Int] -> Int
solve [_, k] = sum . take k . sort

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')


Measured memory_bytes: 4412
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef pair<ll, ll> p;


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

  for (ll i = 1; i <= n; ++i) {
    ll count = 0;

    for (ll x = 1; x*x <= i; ++x) {
      ll val = x*x;
      for (ll y = 1; y <= i; ++y) {
        ll val2 = val + y*y+x*y;
        if(val2 > i) break;
        for (int z = 1; z <= i; ++z) {
          ll val3 = val2 + z*z + z*x + z*y;
          if(val3 == i) count++;
          if(val3 >= i) break;
        }
      }
    }
    cout << count << endl;
  }
}


Measured memory_bytes: 3540
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  vll h(n);
  rep(i,n) cin>>h[i];
  ll l=0;
  ll r=1e9;
  ll mid=(l+r)/2;
  while(l<r){
    ll cu=0;
    rep(i,n){
      if(h[i]-b*mid>0){
        cu+=(h[i]-b*mid+a-1-b)/(a-b);
      }
    }
    if(cu<=mid){
      r=mid;
    }
    else l=mid+1;
    mid=(l+r)/2;
  }
  COUT(r);
}


Measured memory_bytes: 1152
n, m, x, y = map(int, input().split())
xl = list(map(int, input().split()))
yl = list(map(int, input().split()))

x_max = max(xl)
y_min = min(yl)
for z in range(x+1, y+1):
    if x_max < z <= y_min:
        print('No War')
        exit()

print('War')


Measured memory_bytes: 3060
/*
    _____
  .'|||||'.
 /  >   <  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
    |||||
*/

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
#define REP(i,r,n) for(int i=r;i<=n;i++)
#define RREP(i,n,r) for(int i=n;i>=r;i--)
int a,b,c;
int main()
{
scanf("%d%d%d",&a,&b,&c);
int d=min(a+b,c);
if (d==c)
{
        printf("%d\n",c+b);
} else
{
    printf("%d\n",d-a+1+d);
}
    return(0);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	//変数の宣言
	int d,n;
	int ans;
	
	//データの読み込み
	scanf("%d %d",&d,&n);
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	
	
	//実際の処理
	
	if(d==0){
		if(n==100){
			ans=101;
		}else{
			ans=n;
		}
	}else if(d==1){
		if(n==100){
			ans=10100;
		}else{
			ans=n*100;
		}
	}else{
		if(n==100){
			ans=1010000;
		}else{
			ans=n*10000;
		}
	}
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>

using namespace std;

string nodeInfo[] = { "root", "internal node", "leaf" };

struct Node {
    int depth;
    int status;
    int parent;
    int num;
    int *child;
} tree[100000];

void treeRecur(int u, int d) {
    tree[u].depth = d;
    int k = tree[u].num;
    if (k > 0) {
        tree[u].status = 1;
        for (int i = 0; i < k; ++i) {
            treeRecur(tree[u].child[i], d + 1);
        }
    }
    else {
        tree[u].status = 2;
    }
}

void treeBuild(int n) {
    int root;
    for (int i = 0; i < n; ++i) {
        if (tree[i].parent == -1) {
            root = i;
            break;
        }
    }
    treeRecur(root, 0);
    tree[root].status = 0;
}

int main() {
    int n, id, k, c;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        tree[i].parent = -1;
        tree[i].status = 0;
    }
    for (int i = 0; i < n; ++i) {
        cin >> id >> k;
        tree[id].num = k;
        if (k > 0) {
            tree[id].child = new int[k];
            for (int j = 0; j < k; ++j) {
                cin >> c;
                tree[id].child[j] =  c;
                tree[c].parent = id;
            }
        }
    }
    treeBuild(n);
    for (int i = 0; i < n; ++i) {
        cout << "node " << i;
        cout << ": parent = " << tree[i].parent;
        cout << ", depth = " << tree[i].depth;
        cout << ", " << nodeInfo[tree[i].status] << ", [";
        for (int j = 0; j < tree[i].num; ++j) {
            cout << tree[i].child[j];
            if (j < tree[i].num - 1)
                cout << ", ";
        }
        cout << "]" << endl;
    }

    return 0;
}


Measured memory_bytes: 5912
# https://atcoder.jp/contests/abc148/tasks/abc148_a



A = gets.to_i
B = gets.to_i

m=[]
m<<false
m<<false
m<<false
m<<false
m[A]=true
m[B]=true
if  !m[1]
    puts 1
elsif !m[2]
    puts 2
elsif !m[3]
    puts 3
end



Measured memory_bytes: 1788
import math

gojou = [[0] for i in range(2)];

x = int(input());

for i in range(1,129) :
    gojou[0].append(i);
    gojou[1].append(i**5);
    gojou[0].append(-i)
    gojou[1].append((-i)**5);

for i in range(len(gojou[0])) :
    for j in range(len(gojou[0])) :
        if gojou[1][i] - gojou[1][j] == x :
            print(gojou[0][i],gojou[0][j]);
            break;
    else :
        continue;
    break;

Measured memory_bytes: 9208
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){



int n;

while(1){
cin>>n;if(n==0)break;
int pn[45][2]={};
for(int i=0;i<n;i++){//cout<<"#"<<endl;
cin>>pn[i][0];int m=0,s=0,st,g=1;
int P[24][2]={};

for(int j=0;j<10;j++){s=0;
cin>>st;s+=st;P[g][0]=st;g++;
if(st==10){s=0;P[g-1][1]=1;
if(j==9){cin>>st;P[g][0]=st;P[g][1]=9;g++;
cin>>st;P[g][0]=st;P[g][1]=9;

}
}
else if(st!=10){
cin>>st;s+=st;P[g][0]=st;g++;P[g-1][1]=2;
if(j==9&&P[g-1][0]+P[g-2][0]==10){cin>>st;P[g][0]=st;P[g][1]=9;g++;
}
}
}
for(int j=1;j<23;j++){
if(P[j][1]!=9)pn[i][1]+=P[j][0];
if(P[j][1]==2&&P[j][0]+P[j-1][0]==10){pn[i][1]+=P[j+1][0];}//cout<<"$"<<endl;}
if(P[j][1]==1){pn[i][1]+=P[j+1][0]+P[j+2][0];}
//cout<<"$$"<<endl;}
//cout<<pn[i][1]<<endl;
}


//cout<<"*"<<endl;

}
for(int i=0;i<n;i++)
for(int j=n-1;j>i;j--)
if(pn[j][1]>pn[j-1][1]){
int a1=pn[j][1];pn[j][1]=pn[j-1][1];pn[j-1][1]=a1;
int a0=pn[j][0];pn[j][0]=pn[j-1][0];pn[j-1][0]=a0;
}
for(int i=0;i<n;i++)
for(int j=n-1;j>i;j--)
if(pn[j][1]==pn[j-1][1]&&pn[j][0]<pn[j-1][0]){
int a0=pn[j][0];pn[j][0]=pn[j-1][0];pn[j-1][0]=a0;
}
for(int i=0;i<n;i++)
printf("%d %d\n",pn[i][0],pn[i][1]);
}
return 0;
}

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

int main() {
  int N;
  scanf ("%d", &N);
  vector<int> paper(N);
  for(int i=0; i<N; i++){
    cin >> paper[i];
  }
  
  bool can = true;
  
  for(int i=0; i<N; i++){
    if( paper[i] %2 ==0){
      if( paper[i] %3 != 0 && paper[i] %5 != 0){
        can = false;
        break;
      }
    }
  }
  
  if( can == true ) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;

}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;

#define MOD 998244353

int main(){
    ll n,t,ans=1001;
    cin >> n >> t;
    for (ll i=0;i<n;i++){
        ll a,b;
        cin >> a >> b;
        if (b<=t)ans=min(ans,a);
    }
    if (ans<1001)cout << ans << endl;
    else cout << "TLE" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;
signed main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;++i){
        int k;
        cin>>k;
        n -= k;
    }
    cout << (n < 0 ? -1 : n);
}

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

long long N, A[100010], gcd_ki[100010], gcd_ka[100010], ans;

int main () {
	cin >> N;
	for(int i=1; i<=N; i++) {
		cin >> A[i];
	}

	for(int i=1; i<=N; i++) {
		if (i==1) gcd_ki[i] = A[i];
		else      gcd_ki[i] = __gcd(gcd_ki[i-1], A[i]);
	}

	for(int i=N; i>=1; i--) {
		if (i==N) gcd_ka[i] = A[i];
		else      gcd_ka[i] = __gcd(gcd_ka[i+1], A[i]);
	}

	ans = max(gcd_ki[N-1], gcd_ka[2]);
	for(int i=2; i<N; i++) {
		long long temp = __gcd(gcd_ki[i-1], gcd_ka[i+1]);
		ans = max(ans, temp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll n,m,d; cin >> n >> m >> d;
    double u;
    if(d == 0) u = n/2.0;
    else u = n-d;
    printf("%.10f\n",u*(m-1)/(n*n/2.0));
}

Measured memory_bytes: 256
using System;


namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);

            if (a == b)
            {
                Console.WriteLine(c);
            }
            else if (a == c)
            {
                Console.WriteLine(b);
            }
            else if (c == b)
            {
                Console.WriteLine(a);
            }
        }
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int i;
  int l;
  for (i = 0; i < N; i++){
  	int x;
    cin >> x;
    
    if (x < K - x)
      l += 2 * x;
    else
      l += 2 * (K - x);
  }
  cout << l << endl;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;
const double PI =  3.14159265358979323846;
#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)



double diff(double x1, double y1, double x2, double y2){
   return sqrt( pow((x1-x2),2.0) + pow((y1-y2),2.0) );
}

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll A, B, H, M;
    cin >> A >> B >> H >> M;

    double x1 = (double)A * cos( PI * (180.0-(60.0*H+M))/360.0);
    double y1 = (double)A * sin( PI * (180.0-(60.0*H+M))/360.0);

    double x2 = (double)B * cos( PI * ((15.0-M)/30.0));
    double y2 = (double)B * sin( PI * ((15.0-M)/30.0));

    cout << diff(x1,y1,x2,y2) << endl;
}


Measured memory_bytes: 4156
#include <stdio.h>
 
int main()
{
    int H, W;
 
    scanf("%d %d", &H, &W);
    while ((H != 0) || (W != 0)) {
        int i, j;
        for (i = 0; i < H; i++) {
            for (j = 0; j < W; j++) {
                if ((i == 0) || (i == H - 1) || (j == 0) || (j == W - 1)) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
            putchar('\n');
        }
        putchar('\n');
        scanf("%d %d", &H, &W);
    }
 
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int N1 = N / 1000;
  int N2 = (N / 100 - N1*10);
  int N3 = (N / 10 - N1*100 - N2*10);
  int N4 = (N  - N1 *1000 - N2*100 - N3*10);
  if((N1==N2 && N1==N3) || (N2==N3) &&(N3==N4)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())

sieve = [0] * 101
sieve[0] = -1
sieve[1] = -1
for i in range(2, 101):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, 101, i):
        if sieve[j] == 0:
            sieve[j] = i

d = {}
for i in range(2, N + 1):
    while i != 1:
        d.setdefault(sieve[i], 0)
        d[sieve[i]] += 1
        i //= sieve[i]

# 75 = 5 * 5 * 3
#    = 15 * 5
#    = 25 * 3
#    = 75
n74 = 0
n24 = 0
n14 = 0
n4 = 0
n2 = 0
for k in d:
    if d[k] >= 74:
        n74 += 1
    if d[k] >= 24:
        n24 += 1
    if d[k] >= 14:
        n14 += 1
    if d[k] >= 4:
        n4 += 1
    if d[k] >= 2:
        n2 += 1

result = 0
# x ^ 4 * y ^ 4 * z ^ 2 の約数の個数は75個
result += n4 * (n4 - 1) // 2 * (n2 - 2)
# x ^ 14 * y ^ 4 の約数の個数は75個
result += n14 * (n4 - 1)
# x ^ 24 * y ^ 2 の約数の個数は75個
result += n24 * (n2 - 1)
# x ^ 74 の約数の個数は75個
result += n74
print(result)


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

using namespace std;

#define MAX_V 100000
#define MAX_LOG_V 100
#define INF (1<<29)
typedef long long ll;

vector<int> G[MAX_V];
int root;
int parent[MAX_LOG_V][MAX_V];  
int depth[MAX_V];

void dfs(int v, int p, int d)
{
    parent[0][v] = p;
    depth[v] = d;
    for (int i = 0; i < (int)G[v].size(); i++) { 
	if(G[v][i] != p) {
	    dfs(G[v][i], v, d+1);
	}
    }
}

void init(int V)
{
    root = 0;
    dfs(root, -1, 0);
    for (int k = 0; k + 1 < MAX_LOG_V; k++) {
	for (int v = 0; v < V; v++) {
	    if (parent[k][v] < 0) {
		parent[k+1][v] = -1;
	    } else {
		parent[k+1][v] = parent[k][parent[k][v]];
	    }
	}
    }
}

int lca(int u, int v)
{
    if(depth[u] > depth[v]){
	swap(u, v);
    }
    for (int k = 0; k < MAX_LOG_V; k++) {
	if ((depth[v] - depth[u]) >> k & 1) {
	    v = parent[k][v];
	}
    }
    if (u == v) {
        return u;
    }
    for (int k = MAX_LOG_V-1; k >= 0; k--) {
	if (parent[k][u] != parent[k][v]) {
	    u = parent[k][u];
	    v = parent[k][v];
	}
    }
    return parent[0][u];
}

int main()
{
    int N, p;
    cin >> N;
    for (int i = 0; i < N-1; i++) {
        cin >> p; p--;
        G[p].push_back(i+1);
    }

    queue<int> Q;
    Q.push(0);

    vector<int> path;
    path.push_back(0);
    
    vector<ll> d(MAX_V, INF);
    d[0] = 0;

    while (!Q.empty()) {
        int v = Q.front(); Q.pop();
        for (int i = 0; i < (int)G[v].size(); i++) {
            int to = G[v][i];
            if (d[v] + 1 < d[to]) {
                d[to] = d[v] + 1;
                Q.push(to);
                path.push_back(to);
            }
        }
    }

    init(N);
    
    ll res = 0;
    for (int i = 1; i < (int)path.size(); i++) {
        int j = path[i-1], k = path[i];
        res += d[j] + d[k] - 2 * d[lca(j, k)];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 56852
s = input()
sre = "".join(list(reversed(s)))
n = len(s)

s1 = s[0:int((n-1)/2)]
s1re = "".join(list(reversed(s1)))
s2 = s[int((n+3)/2)-1:]
s2re = "".join(list(reversed(s2)))
if s1 == s1re and s2 == s2re and s == sre:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

const int NN=100005;
vector<ll> t[NN];
ll d[NN][2];

void dfs(ll cur,ll pre,ll dist,ll type){
  d[cur][type]=dist;
  for(auto a:t[cur]) if(a!=pre) dfs(a,cur,dist+1,type);
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,u,v;
  cin>>n>>u>>v;v--;u--;
  rep(i,n-1){
    ll x,y;
    cin>>x>>y;x--;y--;
    t[x].push_back(y);
    t[y].push_back(x);
  }
  dfs(u,-1,0,0);
  dfs(v,-1,0,1);
  ll ans=0;
  rep(i,n) if(d[i][0]<d[i][1]) chmax(ans,d[i][1]-1);
  cout<<ans<<endl;
}

Measured memory_bytes: 12800
n = gets.to_i
a = gets.split.map(&:to_i)
c = 0
mn = 1000000000
ans = 0
a.each do |i|
    c ^= 1 if i < 0
    mn = i.abs if mn > i.abs
    ans += i.abs
end
ans -= mn*2 if c == 1
puts ans

Measured memory_bytes: 8580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    int A[N+1], B[N+1];
    int C[10005] = {};

    for(int i=0; i<N; ++i){
        scanf("%d", &A[i+1]);
        ++C[A[i+1]];
    }

    for(int i=1; i<=10000; ++i) C[i] = C[i-1]+C[i];

    for(int j=1; j<=N; ++j){
        B[C[A[j]]] = A[j];
        --C[A[j]];
    }

    for(int i=1; i<=N; ++i){
        if(1 < i) printf(" ");
        printf("%d", B[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 18796
n=int(input())
s=str(input())  
ans=str()
for j in range(len(s)):#文字列の長さ繰り返す
  index=ord(s[j])
    
  index = index + n
  
  if index >= 91:
    index =index - 26
  new_s=chr(index)#変換された文字
  ans += new_s
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;



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

	string s;
	cin >> s;

	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  string a,b;
  cin>>a>>b;
  if(a.size()>b.size()){
    cout<<"GREATER"<<endl;
    return 0;
  }else if(a.size()<b.size()){
    cout<<"LESS"<<endl;
    return 0;
  }else if(a.size()==b.size()){
    rep(i,a.size()){
      if(a[i]>b[i]){
        cout<<"GREATER"<<endl;
        return 0;
      }else if(a[i]<b[i]){
        cout<<"LESS"<<endl;
        return 0;
      }
    }
    cout<<"EQUAL"<<endl;
    return 0;
  }
  
  
  
  
  
}
///////////////////////////

Measured memory_bytes: 256
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<string>

using namespace std;

string s, t;
using vec2d = vector<vector<int>>;
vec2d dp = vec2d(3001, vector<int>(3001));

int main()
{
    cin >> s >> t;
    for (auto row : dp) {
        fill(row.begin(), row.end(), 0);
    }

    REP(i, s.size()) {
        REP(j, t.size()) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }

    int i = s.size() - 1;
    int j = t.size() - 1;
    string ans = "";
    // for (int k = 0; k < s.size() + 1; ++k) {
    //     DA(dp[k], t.size() + 1);
    // }
    while (i != -1 && j != -1) {
        // DD(i + 1, j + 1);
        if (s[i] == t[j]) {
            // DD(i, j);a
            ans = s[i] + ans;
            i--;
            j--;
        } else {
            if (dp[i + 1][j + 1] == dp[i][j + 1]) i--;
            else if (dp[i + 1][j + 1] == dp[i + 1][j]) j--;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 35832
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int h, w;
		h = sc.nextInt();
		w = sc.nextInt();
		
		String[] t = new String[h];
		for(int i = 0; i < h; i++){
			t[i] = sc.next();
		}
		
		String[][] x = new String[h][w];
		
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				x[i][j] = t[i].substring(j, j+1);
			}
		}
		
		int black = 0;
		int white = 0;
		
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(x[i][j].equals(".")){
					white++;
				}else{
					black++;
				}
			}
		}
		
		int[][] count = new int[h][w];
		
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				count[i][j] = -1;
			}
		}
		count[0][0] = 0;
		
		int ans = 0;
		
		for(int k = 1; count[h-1][w-1] == -1 && k < h * w; k++){
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(count[i][j] == k-1){
						if(i-1 >= 0){
							if(count[i-1][j] == -1 && x[i-1][j].equals(".")){
								count[i-1][j] = k;
							}
						}
						if(i+1 < h){
							if(count[i+1][j] == -1 && x[i+1][j].equals(".")){
								count[i+1][j] = k;
							}
						}
						if(j-1 >= 0){
							if(count[i][j-1] == -1 && x[i][j-1].equals(".")){
								count[i][j-1] = k;
							}
						}
						if(j+1 < w){
							if(count[i][j+1] == -1 && x[i][j+1].equals(".")){
								count[i][j+1] = k;
							}
						}
					}
				}
			}
		}
		if(count[h-1][w-1] == -1){
			ans = -1;
		}else{
			ans = h * w - count[h-1][w-1] -1 - black;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 24532
dwh = zip([1,1,0,-1,-1,-1,0,1],[0,1,1,1,0,-1,-1,-1])
while 1:
    H,W = map(int,raw_input().split())
    if H == 0: break
    S = [raw_input() for i in xrange(H)]
    
    ans = ""
    appear = set([])
    for h in xrange(H):
        for w in xrange(W):
            for dw,dh in dwh:
                s = S[h][w]
                iw,ih = w,h
                w = (w+dw+W)%W; h = (h+dh+H)%H
                while (w,h) != (iw,ih):
                    s += S[h][w]
                    if s in appear:
                        if len(s)  > len(ans): ans = s
                        if len(s) == len(ans): ans = min(ans, s)
                    appear.add(s)
                    w = (w+dw+W)%W; h = (h+dh+H)%H
    print ans if len(ans) > 1 else 0

Measured memory_bytes: 28700
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

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

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;

	int a, b;
	cin >> a >> b;
	cout << max(0, a - 2 * b) << endl;	
	
}





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

long long a[100000], b[100000];

int main()
{
    int n;
    long long sum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
        sum += a[i];
    }
    for (int i = 2; i <= n; i+=2)
    {
        sum -= 2*a[i];
    }
    b[1] = (int)sum;
    cout << b[1] << ' ';
    for (int i = 1; i < n; i++)
    {
        b[i+1] = 2*a[i] - b[i];
        printf("%d ", b[i+1]);
    }
    return 0;
}

Measured memory_bytes: 2816
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        x: i64,
    }

    let mut res = 0;
    let mut g = 100;
    while g < x {
        g += g / 100;
        res += 1;
    }
    println!("{}", res);
    // println!("{}", (x / 100.).log(1.01) as i64);
}


Measured memory_bytes: 2152
import math
A, B, H, M = [int(n) for n in input().split()]

def coord(r, theta):
    return math.cos(theta) * r, math.sin(theta) * r

pa = coord(A, (H+M/60)/6  * math.pi)
pb = coord(B, M/30 * math.pi)
#print(pa, pb)

print('{}'.format(math.sqrt( \
    (pa[0] - pb[0]) ** 2 +   \
    (pa[1] - pb[1]) ** 2     \
)))



Measured memory_bytes: 9584
def slove():
    import sys
    import collections
    import bisect
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    d = collections.defaultdict(list)
    for i in range(len(s)):
        d[s[i]] += [i]
    loop = 0
    cur = 0
    for i in range(len(t)):
        p = bisect.bisect_left(d[t[i]], cur)
        if p == 0 and len(d[t[i]]) == 0:
            print(-1)
            exit()
        elif p == len(d[t[i]]):
            loop += 1
            cur = d[t[i]][0] + 1
        else:
            cur = d[t[i]][p] + 1
    print(len(s) * loop + cur)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 47216
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int t_prev = 0;
        int x_prev = 0;
        int y_prev = 0;

        for (int i=0; i<N; i++) {
            int t = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();

            int distance = Math.abs(x - x_prev) + Math.abs(y - y_prev);
            if (distance > (t - t_prev) || (distance - (t - t_prev)) % 2 != 0){
            	System.out.println("No");
            	return;
            }
            t_prev = t;
            x_prev = x;
            y_prev = y;
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 87592