akhauriyash/Code-Regression huggingface dataset:
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, D, X := sc.nextInt(), sc.nextInt(), sc.nextInt()
	A := sc.nextIntSlice(N)
	ans := X
	for i := 0; i < N; i++ {
		day := 1
		for day <= D {
			ans++
			day += A[i]
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n, a, b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
 
  int passed = 0;
  int border = a + b;
  int count_b = 0;
  for(int i = 0, size = s.size();i < size;i++){
    switch(s[i]){
      case 'a':
        if(passed < border){
          cout << "Yes" << endl;
          passed++;
        }else{
          cout << "No" << endl;
        }
        break;
      case 'b':
      count_b++;
        if(passed < border && count_b <= b){
          cout << "Yes" << endl;
          passed++;
        }else{
          cout << "No" << endl;
        }
        break;
      case 'c':
        cout << "No" << endl;
    }
  }
 
}

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

int main()
{
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for (int x = 0; x <= K; ++x)
    {
        for (int y = 0; y <= K; ++y)
        {
            int z = S - x - y;
            if( 0<=z and z <=K){
                ans = ans + 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N,W = map(int,input().split())
    vw = [list(map(int,input().split())) for _ in range(N)]

    for i in range(N):
        vw[i].append(vw[i][0]/vw[i][1])

    vw.sort(reverse = True,key = lambda x:x[2])

    val,wei = 0,0
    for i in range(N):
        if wei + vw[i][1] <= W:
            val += vw[i][0]
            wei += vw[i][1]
        elif wei < W:
            val += vw[i][0]*(W-wei)/vw[i][1]
            wei = W
        else:
            break
    print(val)

if __name__ == "__main__":
    main()



Measured memory_bytes: 26352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int fc(const vector<string> &s, int si, int sj){
  int h = s.size(), w = s.front().size();
  vector<vector<int>> d(h, vector<int>(w, -1));
  int di[] = {1, 0, -1, 0}, dj[] = {0, 1, 0, -1};
  queue<pair<int, int>> q;
  q.push({si, sj});
  d.at(si).at(sj) = 0;
  int res = 0;
  while(!q.empty()){
    auto [i, j] = q.front(); q.pop();
    rep(k, 4){
      int ni = i + di[k], nj = j + dj[k];
      if(nj < 0 || w <= nj || ni < 0 || h <= ni) continue;
      if(s.at(ni).at(nj) == '#' || d.at(ni).at(nj) != -1) continue;
      d.at(ni).at(nj) = d.at(i).at(j) + 1;
      res = max(res, d.at(ni).at(nj));
      q.push({ni, nj});
    }
  }
  return res;
}

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s.at(i);
  int ans = 0;
  rep(i, h)rep(j, w){
    if(s.at(i).at(j) == '#') continue;
    ans = max(ans, fc(s, i, j));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main(){
	bool jest[8] = {false, false, false, false, false, false, false, false};
	int b3200 = 0;
	
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		
		int j = 1;
		for(;j <= 8;j++){
			if(a < 400*j) break;
		}
		
		if(j > 8) b3200++;
		else{
			jest[j-1] = true;
		}
	}
	
	int col = 0;
	for(int j = 0;j < 8;j++) if(jest[j]) col++;
	
	int mn = col;
	if(mn == 0) mn = 1;
	int mx = col+b3200;
	//if(mx > 8) mx = 8;
	
	cout << mn << " " << mx << endl;
 	
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

import sys

def main():
    s = raw_input()
    num_g = sum(1 for c in s if c == 'g')
    num_p = sum(1 for c in s if c == 'p')
    print (num_g-num_p)/2

if __name__ == '__main__':
    main()


Measured memory_bytes: 2692
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n;
cin >> n;
int h[n];
for(int i=0;i<n;i++){
    cin >> h[i];
}

for(int i=0;i<n-1;i++){
    if(h[i]<h[i+1]){
        h[i+1]=h[i+1]-1;
    }
}
for(int i=0;i<n-1;i++){
    if(h[i]>h[i+1]){
        cout << "No" << endl;
        return 0;
    }
}
cout << "Yes" << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 640
<?php
	fscanf(STDIN,"%d%d%d",$n,$m,$c);
	$ans=0;
	$b=explode(' ',fgets(STDIN));
	for($i=0;$i<$n;$i++){
		$s=$c;
		$a=explode(' ',fgets(STDIN));
		for($j=0;$j<$m;$j++)$s+=$a[$j]*$b[$j];
		$ans+=$s>0;
	}
	echo $ans;

Measured memory_bytes: 3828
#include <stdio.h>
#define N 8
#define FREE 1
#define NOT_FREE -1

int row[N], col[N], dpos[2*N+2], dneg[2*N-1], X[N][N];

void initialize(){
  int i;

  for(i=0; i<N; i++){
    row[i] = FREE;
    col[i] = FREE;
  }
  for(i=0; i<2*N-1; i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}

void printBoard(){
  int i, j;
  
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      if(X[i][j]){
	if(row[i] != j) return;
      }
    }
  }
  for(i=0;i<N; i++){
    for(j=0; j<N; j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void putQueen(int i){

  int j;
  
  if(i == N){
    printBoard();
    return ;
  }
  for(j=0; j<N; j++){
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE){
      continue;
    }
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    putQueen(i+1);
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

int main(){

  int i, j, k, r, c;
  
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      X[i][j] = 0;
    }
  }

  scanf("%d", &k);
  for(i=0; i<k; i++){
    scanf("%d%d", &r, &c);
    X[r][c] = 1;
  }

  putQueen(0);
  
  return 0;
}

Measured memory_bytes: 572
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
typedef long double ld;
ld mi[4],ma[4];
ld mixx,maxx,miyy,mayy;
ld solve(ld k){
    ld mx=min(mixx,min(mi[0]+k,mi[1]-k));
    ld ex=max(maxx,max(ma[0]+k,ma[1]-k));
    ld my=min(miyy,min(mi[2]+k,mi[3]-k));
    ld ey=max(mayy,max(ma[2]+k,ma[3]-k));
    return (ex-mx)*(ey-my);
}
int main(){
  ll n;cin>>n;
  for(int i=0;i<4;i++){
      mi[i]=1e17;
      ma[i]=-1e17;
  }
  maxx=mayy=-1e17;
  miyy=mixx=1e17;
  for(int i=0;i<n;i++){char z;ll d;
      ld x,y;cin>>x>>y>>z;
      if(z=='R')d=0;
      if(z=='L')d=1;
      if(z=='U')d=2;
      if(z=='D')d=3;
      if(d<2){
      chmin(mi[d],x);
      chmax(ma[d],x);
      chmin(miyy,y);
      chmax(mayy,y);
      }
      else{
	  chmin(mi[d],y);
	chmax(ma[d],y);
	chmin(mixx,x);
	chmax(maxx,x);
      }
  }
  ld l=0,r=1e10,p,q;
  for(int i=0;i<10000;i++){
      q=(l+r*2)/3.0;
      p=(l*2+r)/3.0;
      if(solve(p)>solve(q))l=p;
      else r=q;
  }  //cout<<r<<endl;
  ld res=solve(r);
  cout<<fixed<<setprecision(10)<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    # 入力値の取得（１行目だけ）
    N, M = map(int, input().split())

    # 正解したかどうかを管理するリスト。
    # フラグとして使うので、中身は出力時に帳尻が合えばboolでもOK
    correct = [0] * N

    # 問題ごとのペナルティー数（WA）の数を数える
    penalty = [0] * N

    # ACした問題でのペナルティー数を保持する変数
    pena = 0

    # ２行目以降の入力を取得しながら処理していく。
    for _ in range(M):

        # 各行の p,s をとる
        pi, si = input().split()
        # piをintに型変換する
        pi = int(pi)

        # s が 'WA'で、その問題がまだ正解していなければ
        if si == 'WA' and correct[pi - 1] == 0:
            # その問題のペナルティを加算する
            penalty[pi - 1] += 1

        # s が'AC'で、その問題にまだ正解していなければ
        elif si == 'AC' and correct[pi - 1] == 0:
            # 正解したことを記録
            correct[pi - 1] = 1
            # その時点での、その問題のペナルティー数をpenaに加算
            pena += penalty[pi - 1]

    # 正解した問題数と、ペナルティー数の合計を表示
    print(sum(correct), pena)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	print(min(a, b)+min(c, d))
	return 0;
}

Measured memory_bytes: 256
n,m=map(int, input().split())
a_list=[]
b_list=[]
for i in range(n):
  a,b=map(int, input().split())
  a_list.append(a)
  b_list.append(b)
c_list=[]
d_list=[]
for i in range(m):
  c,d=map(int, input().split())
  c_list.append(c)
  d_list.append(d)
for i in range(n):
  min=2*(10**8)
  min_number=0
  for j in range(m):
    d=abs(a_list[i]-c_list[j])+abs(b_list[i]-d_list[j])
    if d<min:
      min=d
      min_number=j
  print(min_number+1)


Measured memory_bytes: 9160
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> size_(3,0);

    long long ans=1;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;

        int cnt=0;
        for(int j=0; j<3; j++){
            if(size_[j]==a){
                cnt++;
                if(cnt==1){
                    size_[j]++;
                }
            }
        }
        ans=ans*cnt%MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

#define DEBUG 0
#define REP(i, n) for (int i = 0; i < (n); i++) 
typedef long long ll;
typedef pair<int,int> pint;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main() { 
    ll h,w;
    cin >> h >> w;
    ll hw = h * w;

    ll w2 = w / 2;
    ll h2 = h / 2;

    //それぞれの面積
    ll a,b,c;
    ll smax,smin;

    ll res = INF;

    //方針: 基本的に全探索 smaxが半分を超えたら終了
    //パターンわけ 4(not 6)パターンあるのでそれを全部調べる

    //1. 横で切る
    for(ll i = 1; i <= h-2; ++i)
    {
        a = w * i;
        //残りを半分で割るほうが良い
        ll zan = h - i;
        ll zan2 = zan / 2;
        b = w * zan2;
        c = w * (zan - zan2);

        smax = max(a,max(b,c));
        smin = min(a,min(b,c));
        res = min(res, smax - smin);
        
    }
    //2.縦できる
    for(ll i = 1; i <= w-2; ++i)
    {
        a = h * i;
        //残りを半分で割るほうが良い
        ll zan = w - i;
        ll zan2 = zan / 2;
        b = h * zan2;
        c = h * (zan - zan2);
        smax = max(a,max(b,c));
        smin = min(a,min(b,c));
        res = min(res, smax - smin);
    }
    //3. 上は1分割 下を縦に2分割
    for(ll i = 1; i <= h-1; ++i)
    {
        a = w * i;
        //残りを半分にする
        
        b = (h-i) * w2;
        c = (h-i) * (w - w2);
        smax = max(a,max(b,c));
        smin = min(a,min(b,c));
        res = min(res, smax - smin);
    }
    //4. 左は1分割 右を横に2分割
    for(ll i = 1; i <= w-1; ++i)
    {
        a = h * i;
        //残りを半分にする
        
        b = (w-i) * h2;
        c = (w-i) * (h - h2);
        smax = max(a,max(b,c));
        smin = min(a,min(b,c));
        res = min(res, smax - smin);
    }

    cout << res << endl;

    return 0;

}

Measured memory_bytes: 256
ans=0
a=[0]*5
for x in range(5):
  a[x]=int(input())
k=int(input())
for y in range(5):
  for z in range(5):
    if y!=z:
      if abs(a[y]-a[z])>k:
        ans+=1
if ans==0:
  print("Yay!")
else:
  print(":(")

Measured memory_bytes: 9100
#14:31
n,m = map(int,input().split())
ch = []
for _ in range(m):
  ch.append(list(map(int,input().split())))
raw = []
for _ in range(n):
  raw.append(list(map(int,input().split())))
res = [[0 for _ in range(m)] for _ in range(3)]
for i in range(n):
  for j in range(n):
    d = (i+j) % 3
    e = raw[i][j] - 1
    res[d][e] += 1
#print(res)
can = []
for i in range(m):
  for j in range(m):
    for k in range(m):
      if i == j or j == k or k == i:
        continue
      tmp = 0
      for l in range(m):
        tmp += res[0][l] * ch[l][i]
        tmp += res[1][l] * ch[l][j]
        tmp += res[2][l] * ch[l][k]
      can.append(tmp)
print(min(can))
#print(can)

Measured memory_bytes: 6552
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for (int i=(a); i>=(b); --i)
#define REP(i,b) for (int i=0; i<(b); ++i)
#define endl '\n'
#define sz(x) (int) x.size()
#define mod %
#define fillchar(x,y,z) memset(x,z,y)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define sqr(x) ((x)*(x))
typedef long long int64;
typedef unsigned long long qword;
using namespace std;
const int base=1e9+7;
pair<int,int> a[3005];
int64 f[3005];
int64 fac[200005],refac[200005];
int h,w,n;
void Input()
{
    cin >> h >> w >> n;
    FOR(i,1,n)
        cin >> a[i].fi >> a[i].se;
    a[n+1].fi=h; a[n+1].se=w;
}
int64 pow(int64 a, int n)
{
    int64 res=1;
    while (n>0) {
        if (n&1)
            res=(res*a)%base;
        a=(a*a)%base;
        n>>=1;
    }
    return res;
}
void Init()
{
    fac[0]=1; refac[0]=1;
    int tmp=200000;
    FOR(i,1,tmp) {
        fac[i]=fac[i-1]*i%base;
        refac[i]=pow(fac[i],base-2);
    }
}
int64 Ckn(int k, int n)
{
    return ((fac[n]*refac[k])%base)*refac[n-k]%base;
}
void Solve()
{
    ++n;
    sort(a+1,a+n+1);
    Init();
    FOR(i,1,n) {
        f[i]=Ckn(a[i].fi-1,a[i].fi+a[i].se-2);
        FOR(j,1,i-1)
            if (a[j].fi<=a[i].fi&&a[j].se<=a[i].se)
                f[i]=(f[i]-f[j]*Ckn(a[i].fi-a[j].fi,a[i].fi+a[i].se-a[j].fi-a[j].se))%base;
    }
    cout << (f[n]+base)%base;
}
int main()
{
    #ifdef meomeomeooooo
        freopen("input.txt","r",stdin);
        //freopen(".out","w",stdout);
    #endif // meomeomeooooo
    iostream::sync_with_stdio(false);
    cin.tie(0);
    Input();
    Solve();
    return 0;
}


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

int main(){
  int A,B,C,X;
  cin>>A>>B>>C>>X;
  int ans=0;
  for(int a=0; a<=A; a++){
    for(int b=0; b<=B; b++){
      for(int c=0; c<=C; c++){
        if(500*a+100*b+50*c==X)
          ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <queue>

#include <cmath>
#include <cstdio>

using namespace std;


int main(int argc,char **argv){
	
	long long A,B,C,K;
	cin >> A >> B >> C >> K;

	long long ans=(K%2==0)?A-B:-A+B;
	if(ans>1000000000000000000){
		cout << "Unfair" << endl;
	}else{
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
int main() {
    int x, y, s;
    while(~scanf("%d%d%d", &x, &y, &s) && x) {
        int ans = 0;
        auto tax = [](int a, int x) { return a * (100 + x) / 100;};
        REP(i, 1, s) REP(j, 1, s) 
          if(tax(i, x) + tax(j, x) == s)
            ans = max(ans, tax(i, y) + tax(j, y));
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3192
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

int DFS(int i, int p, std::vector<std::set<int>>const& edge, std::vector<int>const& depth, std::vector<boost::optional<int>>& next)
{
	int max = -1;
	for (auto n : edge[i])
	{
		if (n == p)
		{
			continue;
		}
		auto r = DFS(n, i, edge, depth, next);
		if (max < r)
		{
			next[i] = n;
			max = r;
		}
	}
	return max == -1 ? depth[i] : max;
}

void Main()
{
	int N, u, v;
	std::cin >> N >> u >> v;
	--u;
	--v;
	std::vector<std::set<int>> edge(N);
	for (auto _ : boost::irange(0, N - 1))
	{
		int a, b;
		std::cin >> a >> b;
		--a;
		--b;
		edge[a].emplace(b);
		edge[b].emplace(a);
	}
	std::vector<boost::optional<int>> parent(N);
	std::vector<int> depth(N);
	std::vector<boost::optional<int>> next(N);
	boost::dynamic_bitset<> flag(N);
	std::queue<std::pair<int, int>> queue;
	queue.emplace(-1, v);
	while (queue.size())
	{
		int p, i;
		std::tie(p, i) = queue.front();
		queue.pop();
		if (flag[i])
		{
			continue;
		}
		flag[i] = true;
		if (p == -1)
		{
			depth[i] = 0;
		}
		else
		{
			depth[i] = depth[p] + 1;
			parent[i] = p;
		}
		for (auto n : edge[i])
		{
			queue.emplace(i, n);
		}
	}
	DFS(v, -1, edge, depth, next);
	auto aoki = 0;
	auto result = 0;
	while (2 < depth[u] - aoki)
	{
		u = *parent[u];
		++result;
		++aoki;
	}
	while (aoki < depth[u])
	{
		if (!next[u])
		{
			u = *parent[u];
		}
		else
		{
			u = *next[u];
		}
		if (depth[u] == aoki)
		{
			break;
		}
		else
		{
			++result;
			++aoki;
		}
	}
	std::cout << result << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 25344
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = map(int, input().split())

A = deque()
for i in range(N):
    A.append(list(map(int, input().split())))

A = sorted(A, key=itemgetter(0))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)

Measured memory_bytes: 58036
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
long long dp[2][5050];
int main()
{
	int n,a,now,to,x;
	scanf("%d%d",&n,&a);
	memset(dp,0,sizeof(dp));
	now=0;
	to=1;
	dp[0][2500]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		x-=a;
		for(int j=0;j<=5000;j++)
			if(dp[now][j])
			{
				dp[to][j]+=dp[now][j];
				dp[to][j+x]+=dp[now][j];
				dp[now][j]=0;
			}
		swap(now,to);
	}
	printf("%lld",dp[now][2500]-1);
	return 0;
}

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

int main(){
    int n,m;
    int sum = 0;
    cin >> n >> m;
    vector<int> A(n);
    rep(i,n){
        cin >> A.at(i);
        sum += A.at(i);
    }
    sort(A.rbegin(),A.rend());
    double check = (double)sum / (4 * m);

    if(A.at(m - 1) >= check) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstring>
#define SF scanf
#define PF printf
#define MAXN 200010
#define INF 10000000000000000ll
using namespace std;
int n,k;
typedef long long ll;
ll tree[MAXN*4],f[MAXN],sum;
int a[MAXN],b[MAXN],l[MAXN],r[MAXN];
vector<int> val;
ll min1(ll x,ll y){
	if(x==0)
		return y;
	if(y==0)
		return x;
	return min(x,y);	
}
ll que(int l,int r,int id,int pos){
	if(l==r)
		return tree[id];
	int mid=(l+r)>>1;
	if(pos<=mid)
		return min1(tree[id],que(l,mid,id*2,pos));
	else
		return min1(tree[id],que(mid+1,r,id*2+1,pos));
}
void change(int l,int r,int id,int pl,int pr,int v){
	if(pl>pr)
		return ;
	if(l>=pl&&r<=pr){
		tree[id]=min1(tree[id],v);	
		return ;
	}
	int mid=(l+r)>>1;
	if(pl<=mid)
		change(l,mid,id*2,pl,pr,v);
	if(pr>mid)
		change(mid+1,r,id*2+1,pl,pr,v);
}
int main(){
	SF("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		SF("%d",&a[i]);
		SF("%d",&b[i]);
		if(b[i]==1&&2*a[i]>k){
			PF("-1");
			return 0;
		}
		sum+=a[i];
		a[i]=(a[i]+a[i-1])%k;
	}
	for(int i=1;i<=n;i++){
		if(b[i]==1){
			l[i]=2*(k-a[i-1])%k;
			r[i]=2*(k-a[i])%k;
		}
		else{
			l[i]=0;
			r[i]=k-1;	
		}
		val.push_back(l[i]);
		val.push_back(r[i]);
	}
	sort(val.begin(),val.end());
	int len=unique(val.begin(),val.end())-val.begin()-1;
	for(int i=1;i<=n;i++){
		//PF("{%d %d}\n",l[i],r[i]);
		r[i]=lower_bound(val.begin(),val.begin()+len,r[i])-val.begin();
		l[i]=lower_bound(val.begin(),val.begin()+len,l[i])-val.begin();	
		//PF("<%d %d>\n",l[i],r[i]);
	}
	for(int i=n;i>=1;i--){
		int res=que(0,len,1,l[i]);
		if(res==0)
			f[i]=0;	
		else
			f[i]=f[res]+(val[l[res]]-val[l[i]]+k)%k;
		if(l[i]<=r[i]){
			change(0,len,1,0,l[i]-1,i);
			change(0,len,1,r[i]+1,len,i);
		}
		else
			change(0,len,1,r[i]+1,l[i]-1,i);
	}
	ll ans=INF;
	for(int i=0;i<=len;i++){
		ll res=que(0,len,1,i);
		if(res)
			res=f[res]+(val[l[res]]-val[i]+k)%k;
		ans=min(ans,res);
	}
	PF("%lld",ans+2ll*sum);
}

Measured memory_bytes: 8436
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define strep(it,v) for(it=v.begin();it!=v.end();++it)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b)
{
   ll res = 1;
   while(b>0)
   {
     if(b&1)
      res = (res*a)%mod;
     a = (a*a)%mod;
     b/=2;
   }
   return res;
}
#define rs resize
int main()
{
   std::ios::sync_with_stdio(false);
   ll n,i,p,now,a;
   cin>>n;
   rep(i,0,n){
      cin>>a;
      if(i == 0) p = a;
      else
      {
        now = __gcd(p,a);
        p = p*(a/now);
      }
   }
   cout<<p;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>

bool judge(const bool d[3][3])
{
    // 横方向
    for (int i = 0; i < 3; ++i)
    {
        if (d[i][0] && d[i][1] && d[i][2])
        {
            return true;
        }
    }

    // 縦方向
    for (int j = 0; j < 3; ++j)
    {
        if (d[0][j] && d[1][j] && d[2][j])
        {
            return true;
        }
    }

    // 斜め方向1
    if (d[0][0] && d[1][1] && d[2][2])
    {
        return true;
    }

    // 斜め方向2
    if (d[2][0] && d[1][1] && d[0][2])
    {
        return true;
    }

    return false;
}

int main()
{
    int a[3][3];
    bool d[3][3];
    std::map<int, std::pair<size_t, size_t>> num2index;

    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            std::cin >> a[i][j];
            d[i][j] = false;
            num2index.emplace(a[i][j], std::make_pair(i, j));
        }
    }

    int n;
    std::cin >> n;

    for (int i = 0; i < n; ++i)
    {
        int b;
        std::cin >> b;

        auto p = num2index.find(b);
        if (p == num2index.end())
        {
            continue;
        }

        d[p->second.first][p->second.second] = true;
        std::cerr << p->second.first << "," << p->second.second << std::endl;
    }

    std::cout << (judge(d) ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;
int main(int argc, char const *argv[]){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n+10);
    vector<ll> b(n+10);
    rep(i, n) cin >> a[i];
    if(k>=sqrt(n)){
        rep(i,n-1) {
            cout << n << " ";
        }
        cout << n << endl;
        return 0;
    }
    for(int i=0;i<k;i++){
        b = vector<ll>(n+10,0);
        rep(i,n){
            b[(-a[i]+i) > 0 ? (-a[i]+i):0]++;
            b[(i+a[i])>n ? n : (i+a[i]+1)]--;
        }
        ll tot=0;
        rep(i,n){
            tot+=b[i];
            a[i]=tot;
        }
    }
    rep(i,n-1){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
    return 0;
}




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

using namespace std;
//string taro[10000]

int main(){
	string t, h;
	int fight;
	int ts=0, hs=0;
	
	cin >> fight;
	
	for(int i=0; i<fight; ++i){
		cin >> t >> h;
		if(t == h){
			++ts;
			++hs;
		}else if(t > h){
			ts += 3;
		}else{
			hs += 3;
		}	
	}
	
	printf("%d %d\n", ts, hs);
}




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

int main(){
	string s;
	cin >> s;
	int ans = 999;
	for(int i = 0; i <= s.size() - 3; i++){
		int temp = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + s[i+2] - '0';
		if(ans > abs(temp - 753)) ans = abs(temp - 753);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main (){
  long long N,D,ans=0;
  cin>>N>>D;
  rep(i,N){
    long long x,y;
    cin>>x>>y;
    if(D*D>=x*x+y*y)ans++;
  }
  cout<<ans;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(long long i=0;i<n;i++)
#define rev(i,n) for(long long i=n;i>=0;i--)
#define rep_a(i,a,n) for(long long i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
	ll ans=1;
     while(n>0){
     	if(n&1) ans=(ans*x)%mod;
     	x=(x*x)%mod;
     	n/=2;
     }
     return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r" , stdin);
	//freopen("output.txt", "w" , stdout);
	#endif

	ll n;
	double m,sum=0;
	cin >> n >> m;
	vector<db> v(n);
	
	rep(i,n){
			cin >> v[i];
			sum += v[i];
	}
		
	sort(all(v));
	
	double markValue=sum/(4*m);
	
	ll index=n-1;
	
	//cout << "MarkerValue " << markValue << el;
	
	while(index>=0 && v[index]>=markValue){
		index--;
	}
	
	int tValue=n-1-index;
		
	if(tValue>=m)
		cout << "Yes" << el;
	else
		cout << "No" << el;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    
    vector<vector<int> > c(H, vector<int>(W));
    int k = 0;
    REP(i, H){
        if(i%2 == 0){
            for(int j = 0; j < W; j++){
                a[k]--;
                c[i][j] = k+1;
                if(a[k] == 0) k++;
            }
        }else{
            for(int j = W-1; j >= 0; j--){
                a[k]--;
                c[i][j] = k+1;
                if(a[k] == 0) k++;
            }
        }
    }
    REP(i, H)REP(j, W){
        cout << c[i][j] << (j == W-1 ? "\n" : " ");
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(c) (c).begin(),(c).end()
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}
void dump() {}
template <class H, class... T>void dump(H&& head, T&&... tail)
{cout << head << (sizeof...(tail)==0 ? "\n" : " "); dump(forward<T>(tail)...);}

vector<int> z_algorithm(string& s){
  int ret = 0;
  int n = s.size();
  vector<int> z(n,0);

  int l = 1, k = 0;
  while(l < n){
    while(l+k < n && s[l+k] == s[k]) ++k;
    z[l] = k;
    if(k==0){++l; continue;}
    int i = 1;
    while(l+i < n && i+z[i] < k){
      z[l+i] = z[i];
      ++i;
    }
    l += i; k -= i;
  }
  z[0] = n;
  return z;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for(int i = 0; i < n-1; ++i){
    string t = s.substr(i,n-i);
    auto z = z_algorithm(t);
    
    for(int j = 0; j < z.size(); ++j){
      ans = max(ans, min(j,z[j]));
    }
  }
  cout << ans << endl;
  return 0;
}


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

int	main(void)
{
  	int	H;
  	int	N;
  	int	*a;
  	int	num;
  	int	i;
  	int	sum;
  
  	num = scanf("%d %d", &H, &N);
  	if (num != 2)
      	return (0);
  	a = (int *)malloc(sizeof(int) * N);
  	sum = 0;
  	for (i=0; i<N; i++)
    {
      	num = scanf("%d", &a[i]);
      	sum += a[i];
      	if (num != 1)
          	return (0);
    }
  
  	if (H > sum)
      	printf("No");
  	else
      	printf("Yes");
  	return (0);
}

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

string solve() {
  string S;
  cin >> S;
  vector<bool> used(26);
  rep(i, S.size()) used[S[i] - 'a'] = true;
  if (S.size() < 26) {
    rep(i, 26) {
      if (!used[i]) {
        return S + (char)('a' + i);
      }
    }
  } else {
    rep(i, 26) {
      char l = S.back();
      used[l - 'a'] = false;
      S.erase(S.end() - 1);
      for (char c = l + 1; c <= 'z'; c++) {
        if (!used[c - 'a']) {
          return S + c;
        }
      }
    }
  }
  return "-1";
}

int main() {
  cout << solve() << endl;
  return 0;
}


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

int main() {

    while (true) {
        int n;
        std::cin >> n;

        if (n == 0) {
            break;
        }

        std::stringstream ss;
        ss << std::oct << n;
        std::string n_oct = ss.str();

        const int len = n_oct.length();

        std::string s = n_oct;
        std::replace(s.begin(), s.end(), '7', '9');
        std::replace(s.begin(), s.end(), '6', '8');
        std::replace(s.begin(), s.end(), '5', '7');
        std::replace(s.begin(), s.end(), '4', '5');

        std::cout << s << std::endl;
    }

    return 0;

}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > ans;

int main() {
	scanf("%d", &n);
	if(n & 1) {
		for(int i = 1; i <= n; i++)
			for(int j = i + 1; j <= n; j++)
				if(i + j != n) ans.emplace_back(i, j);
		printf("%d\n", ans.size());
		for(auto x : ans) printf("%d %d\n", x.first, x.second);
	}
	else {
		for(int i = 1; i <= n; i++)
			for(int j = i + 1; j <= n; j++)
				if(i + j != n + 1) ans.emplace_back(i, j);
		printf("%d\n", ans.size());
		for(auto x : ans) printf("%d %d\n", x.first, x.second);
	}
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
    int n = 0, m = 0;
    cin >> n >> m;
    if (abs(n-m) > 1) cout << 0 << endl;
    else {
        long long ans = 1;
        for (int i=1; i<=n; i++) {
            ans *= i % mod;
            ans %= mod;
        }
        for (int i=1; i<=m; i++) {
            ans *= i % mod;
            ans %= mod;
        }
        if (n == m) {
            ans *= 2;
            ans %= mod;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
INPUT_STR = input()


match_patterns = [
    ''.join(list(reversed('dream'))),
    ''.join(list(reversed('dreamer'))),
    ''.join(list(reversed('erase'))),
    ''.join(list(reversed('eraser')))
]

string = ''.join(list(reversed(INPUT_STR)))


def is_concatted_string(string):
    string = ''.join(list(reversed(string)))
    while len(string) != 0:
        for pattern in match_patterns:
            if string.startswith(pattern):
                string = string[len(pattern):]
                if len(string) == 0:
                    return True
                break
        else:
            return False
    return False


if INPUT_STR != '' and is_concatted_string(INPUT_STR):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 4080
package main

import (
	"fmt"
	"math"
)

func main()  {
	var n int
	fmt.Scan(&n)
	w := make([]int, n)

	for i:=0; i<n; i++ {
		fmt.Scan(&w[i])
	}


	ans := int(10e9)
	for i:=1; i<n; i++ {
		l, r := 0,0
		for j:=0; j<i; j++ {
			l += w[j]
		}
		for k:=i; k<n; k++ {
			r += w[k]
		}
	  if subs := int(math.Abs(float64(l-r))); subs < ans {
			ans = subs
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define int long long 
#define ld long double
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define loop(i,l,r) for(int i=l;i<r;i++)
#define rloop(i,r,l) for(int i=r;i>=l;i--)
#define watch(x) cerr<<(#x)<<"= "<<(x)<<endl;
#define watcharr(a) cerr<<(#a)<<"("<<sz(a)<<")= ";rep(i,sz(a))cerr<<a[i]<<",";cerr<<'\n';
#define inf 2000000000000000000LL
#define mod 1000000007
#define mod1 998244353
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;

int n,t;
int a[301];
int c[4];
ld dp[301][301][301];

ld solve(int c1,int c2,int c3){
    if(c1<0 or c2<0 or c3<0) return 0;
    if(dp[c1][c2][c3]!=-1) return dp[c1][c2][c3];
    ld ans=n+solve(c1-1,c2,c3)*c1+solve(c1+1,c2-1,c3)*c2+solve(c1,c2+1,c3-1)*c3;
    ans/=(c1+c2+c3);
    return dp[c1][c2][c3]=ans;
}

signed main() {
    FASTIO;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    //     freopen("stderr.txt", "w", stderr);
    // #endif

    // int tt=1;
    // cin>>tt;
    // while(tt--){
        cin>>n;
        rep(i,n){
            cin>>a[i];
            c[a[i]]++;
        }
        rep(i,301) rep(j,301) rep(k,301) dp[i][j][k]=-1;
        dp[0][0][0]=0;

        ld ans=solve(c[1],c[2],c[3]);
        cout<<fixed<<setprecision(20)<<ans<<endl;

        
    // }
    cerr<<"Time Elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" sec";
    return 0;
}

Measured memory_bytes: 426496
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vivi;
typedef vector<ll> vll;
typedef vector<vll> vllvll;
typedef pair<int, int> Pi;
typedef queue<Pi> QPi;
typedef pair<ll, ll> Pll;
typedef queue<Pll> QPll;
typedef vector<vi> Graph;
const int mod = 1000000007;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int n;
  cin >> n;
  int ans=0;
  if(n>=105) {
    for(int i=105;i<=n;i+=2) {
      int cnt=0;
      REP1(j,i) {
        if(i%j==0) cnt++;
      }
      if(cnt==8) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int G;
  scanf("%d", &G);
  long long int arr[G], max = 1e18, prod = 1, flag = 0, zero = 0;
  
  for (int i = 0; i < G; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\n", prod));
  return 0;
}

Measured memory_bytes: 2484
#include <bits/stdc++.h>
using namespace std;
#define fastIO                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
// g++ -std=c++11 -O2 -Wall *.cpp -o *
#define eps 1e-9
#define MAX 10000001
#define MOD 998244353
#define Fi first
#define Se second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> pr_int;



int main()
{
	ll n;
	cin >> n;
	ll x = ll(sqrt(n));
	ll m = 0;
	for (ll i = x; i > 0; --i)
		if (n % i == 0) {
			m = n / i;
			break;
		}
	cout << m + n / m - 2;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
     
     
    public class Main{
     
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
     
    		int n=Integer.parseInt(sc.next());
            int count=0;
            int max=0;

            for(int i=0; i<n; i++) {
                int h = sc.nextInt();
                if(h >= max) {
                    count++;
                    max = h;
                }
            }


            System.out.println(count);
    	}
     
    }


Measured memory_bytes: 22740
import sys
N = int(input())
W = [str(input())for i in range(N)]
def has_duplicates(w):
  return len(w) != len(set(w))

if has_duplicates(W)==True:
  print('No')
  sys.exit()
for i in range(N-1):
  if W[i][-1] != W[i+1][0]:
    print('No')
    sys.exit()
print('Yes')

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC169
{
    class A
    {
        static void Main(string[] args)
        {
            // var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();

            var N = BigInteger.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().ToArray();
            var A2 = A.Select(BigInteger.Parse).ToArray();
            if (A2.Contains(0)) { Console.WriteLine(0); return; }

            A2 = A2.OrderByDescending(x => x).ToArray();
            BigInteger res = 1;
            for (int i = 0; i < N; i++)
            {
                res = res * A2[i];
                if (1000000000000000000 < res) { Console.WriteLine(-1); return; }
            }
            //if (res != 1000000000000000000) Console.WriteLine(-1);
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 61888
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;
const ll INF = 1001001001;
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; }

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll s = 0;
  rep(i,n) s += a[i];
  set<ll> candidates;
  for(ll i=1;i*i<=s;i++){
    if(s%i==0){
      candidates.insert(i);
      candidates.insert(s/i);
    }
  }
  ll ans = 1;
  for(ll x:candidates){
    ll need = INF;
    vector<int> b(n);
    rep(i,n) b[i] = a[i] % x;
    sort(b.begin(),b.end());
    ll r = 0;
    rep(i,n) r += (x-b[i]);
    ll l = 0;
    rep(i,n){
      l += b[i];
      r -= (x-b[i]);
      need = min(need,max(l,r));
    }
    if(need<=k) ans = max(ans,x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
def solve(n):
    length = len(n)
    dp = [[0 for j in range(11)] for i in range(length)]
    for i in range(length):
        q = int(n[i])
        if q == 0:
            tmp = dp[i-1][1:]
            tmp.reverse()
            dp[i] = [dp[i-1][0]]+tmp
        else:
            tmp = dp[i-1][1:]
            tmp.reverse()
            tmp = [dp[i-1][0]]+tmp
            dp[i] = tmp[-q:]+tmp[:-q]
            dp[i][q] += 1 
    return(sum([i[0] for i in dp]))

while True:
    n=input()
    
    if n== str(0):
        break
    else:
        print(solve(n))




Measured memory_bytes: 22548
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 2e18;
const ll fact_table = 1200008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
// const ll mod = 998244353ll;
const ll mod = 1000000007ll;
  
ll mypow(ll number1,ll number2, ll mod){
    if(number2 == 0){
        return 1ll;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n,m,num,a,b,c,d,e,h,q;
ll w, k;
ll x[500005], y[500005], z[500005];
string s;

void solve(){
    long double r;
    cin >> r;
    ps(2 * r * Pi);

    return;
}

int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
 
    if(multicase){
        cin >> q;
    }else{
        q = 1;
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    
    // solve();
    return 0;
 
}
















Measured memory_bytes: 3816
#include <iostream>

using namespace std;

int bubbleSort(int A[],int N) {
	int sw = 0;
	bool flag = 1;
	for(int i=0; flag; i++) {
		flag = 0;
		for(int j=N-1; j>=i+1; j--) {
			if(A[j] < A[j-1]) {
				swap(A[j], A[j-1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main(void) {
	int A[100], N, sw;
	cin >> N;
	for(int i=0;i<N; i++) cin >> A[i];

	sw = bubbleSort(A,N);

	for(int i = 0; i < N; i++) {
		if(i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
	return 0;
}



Measured memory_bytes: 3116
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
	char t[1025], r;
	int i = 0, c;
	bool b = false;
	while ((c = getchar()) != '\n')
	{
		r = (unsigned char)c;
		if (r != ' ' && r != '.' && r != ',')
		{
			t[i] = r;
			i++;
		}
		else if (i >= 1)
		{
			t[i] = '\0';
			if (2 < i && i < 7)
			{
				if (b)
					cout << " ";
				cout << t;
				b = true;
			}
			i = 0;
			memset(t, 0, strlen(t));
		}
	}
	cout << endl;
}

Measured memory_bytes: 0
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//define
#define INF 100000000
#define NUM 1000000007


int main() {
	int n;
	int val[100010];
	int ans;
	cin >> n;
	VI a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	
	for (int i = 0; i < 100005; i++) val[i] = 0;
	sort(a.begin(), a.end());

	for (int i = 0; i < n; i++) val[a[i]]++;

	for (int i = 0; i < n; i++) {
		if (a[i] != 0) {
			val[a[i] - 1]++;
		}
		val[a[i] + 1]++;
	}
	
	ans = val[0];
	for (int i = 0; i < 100005; i++) {
		ans = max(ans, val[i]);
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024