akhauriyash/Code-Regression huggingface dataset:
# 2019/07/06

import sys

input=sys.stdin.readline

n=int(input())
s={}
for i in range(n):
    tmp=input()
    if tmp[0] in ['M','A','R','C','H']:
        s[tmp[0]]=s.get(tmp[0],0)+1

# ↑ここまでできた
# ↓ここからわからん

ans=0
for ik,iv in s.items():
    for jk,jv in s.items():
        if ik==jk:break
        for kk,kv in s.items():
            if jk==kk:break
            ans+=iv*jv*kv

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <queue>
#include <list>

using namespace std;
using ll=long long;

ll N, M;

class UnionFind
{
  public:
    vector<ll> par;
    UnionFind(ll size) 
    {
      par = vector<ll>(size, -1);
    }
    bool merge(ll x, ll y)
    {
      x = root(x);
      y = root(y);
     if (x != y)
      {
        if (par[y] < par[x])
          swap(x, y);
        par[x] += par[y];
        par[y] = x;
      }
      return x != y;
  }
  ll root(ll x)
  {
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  ll size(ll x)
  {
    return -par[root(x)];
  }
};

int main()
{
  cin >> N >> M;
  UnionFind uf(N);
  ll a, b;
  for (int i = 0; i < M; i++)
  {
    cin >> a >> b;
    a--;
    b--;

    uf.merge(a, b);
  }
  ll ans = 0;
  for (int i = 0; i < N;i++)
  {
    ans = max(ans, uf.size(i));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4468
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun May  3 21:12:00 JST 2020
 **/

signed main() {
    Int n, m;
    std::cin >> n >> m;
    std::vector<Int> h(n);
    REP(i, n) std::cin >> h[i];
    std::vector<std::vector<Int>> g(n);
    REP(i, m) {
        Int u, v;
        std::cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    Int ans = 0;
    REP(i, n) {
        bool ok = true;
        for (Int j : g[i]) {
            ok &= h[i] > h[j];
        }
        ans += ok;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 9800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
   ll ans = 0;
   int n;
   cin >> n;
   for(int i=1;i<=n;i++){
     int z = i;
    string s= to_string(z);
    if(s.size()%2!=0){
      ans++;
    }
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
import math, sys
sys.setrecursionlimit(10**7)
d,g = map(int, input().split())
data = []
ans = 10000000
for i in range(1,d+1):
    p, c = map(int, input().split())
    data.append([i*100 , p , c])
def dfs(li):
    if len(li) == d:
        global ans
        total = 0
        candidate = 0
        for i in range(d):
            if li[i]:
                total += data[i][0] * data[i][1] + data[i][2]
                candidate += data[i][1]
        if total >= g:
            ans = min(ans, candidate)
        else:
            max_point = max([data[i] for i in range(d) if not li[i]])
            if max_point[0] * (max_point[1] - 1) + total >= g:
                candidate += math.ceil((g - total) / max_point[0])
                ans = min(ans, candidate)
    else:
        dfs(li + [False])
        dfs(li + [True])
dfs([])
print(ans)

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  for(int i = 0; i <= x; i++){
    if(i * 2 + (x - i) * 4 == y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3616
# 組み合わせ(高速，フェルマーの小定理を利用)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10 ** 5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

mod = 10 ** 9 + 7
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans_max = 0
ans_min = 0
# ans_minを求める
for i in range(N-K+1):
    ans_min += A[i] * cmb(N-1-i, K-1, mod)
    ans_min %= mod
for i in range(K-1, N):
    ans_max += A[i] * cmb(i, K-1, mod)
    ans_max %= mod
##print(ans_max, ans_min)
print((ans_max - ans_min + mod)%mod)

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

int main(){
  int N,X;cin>>N>>X;
  vector<int> L(N);
  for(int i=0;i<N;i++) cin>>L.at(i);
  int D=0;
  int count=1;
  for(int i=0;i<N;i++){
    D+=L.at(i);
    if(D<=X) count++;
    else break;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
struct edge {
	int from, to, cap, rev;//revは逆辺のindex  to:行き先,cap:容量,rev:逆(G[e.to][e.rev]で逆辺の構造体にアクセスできる。)
};
int v, e;//頂点数　辺の数
vector<vector<edge>>g;
vector<bool>used;
void add_edge(int from,int to, int cap) {
	g[from].push_back(edge{ from, to, cap, (int)g[to].size() });//g[to].size()で次の行で取得される
	g[to].push_back(edge{ to, from, 0, (int)g[from].size()-1});
}
int dfs(int v, int t, int f) {//vからtに流せる最大
	if (v == t) {//終点までたどり着いたら
		return f;
	}
	used[v] = true;
	for (int i = 0; i < (int)g[v].size(); i++) {
		edge &e = g[v][i];//今見ている頂点から伸びている辺を参照している(コピーではない！！)
		if (!used[e.to] && e.cap>0) {//その辺の行き先をまだ調べていなくて、辺の容量にも余裕がある
			int d = dfs(e.to, t, min(f, e.cap));//capを超えない目一杯を流す
			if (d > 0) {//流しているなら
				e.cap -= d;//流した分capから引く
				g[e.to][e.rev].cap += d;//流した分逆辺のcapを増やす
				return d;
			}

		}
	
	}
	return 0;//何も流せなかった
}
int max_flow(int s, int t) {//sからtへの最大流
	int flow = 0;
	for (;;) {
		for (int i = 0; i<(int)used.size(); i++) {
			used[i] = false;
		}
		int f = dfs(s, t, numeric_limits<int>::max());
		if (f == 0) {
			return flow;//もう何も流せないので今まで流した量の和を返す
		}
		flow += f;
	}

}
signed main(){
	int v, e;
	cin >> v >> e;
	g.resize(v);
	used.resize(v);
	for (int i = 0; i < e; i++) {
		int from, to, cap;
		cin >> from >> to >> cap;
		add_edge(from, to, cap);
	}
	cout << max_flow(0, v - 1) << endl;
	return 0;
}


Measured memory_bytes: 3232
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
ans = [1]*D
for i in range(D):
    tmp = 0
    for k in range(26):
        manzoku_down = 0
        ans[i] = k+1
        for j in range(26):
            last = 0
            for l in range(0,i+1):
                if ans[l] == j+1:
                    last = j+1
            manzoku_down += C[j]*((i+1)-last)
        if S[i][k]-manzoku_down >= tmp:
            tmp = S[i][k]-manzoku_down
            ans[i] = k+1
for i in ans:
    print(i)

Measured memory_bytes: 68396
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		if ( n%10==3 ) {
			System.out.println("bon");
		} else if ( n%10==0 || n%10==1 || n%10==6 || n%10==8 ) {
			System.out.println("pon");
		} else {
			System.out.println("hon");
		}
	}
}

Measured memory_bytes: 35808
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define rep(i,n) for(int i=0; i<n; ++i)

int main()
{
	int N; cin >> N;
	vector<ll> L(N);
	rep(i, N) cin >> L[i];

	int cnt = 0;
	rep(i1, N) {
		for (int i2 = i1; i2 < N; ++i2) {
			if (L[i1] == L[i2]) continue;
			for (int i3 = i2; i3 < N; ++i3) {
				if (L[i1] == L[i3]) continue;
				if (L[i2] == L[i3]) continue;
				if (L[i1] + L[i2] <= L[i3]) continue;
				if (L[i1] + L[i3] <= L[i2]) continue;
				if (L[i2] + L[i3] <= L[i1]) continue;
				++cnt;
			}
		}
	}
	cout << cnt << endl;
}



Measured memory_bytes: 3196
#include <iostream>
using namespace std;
#define MAX 502
#define MAX_P 10002
 
int main(){
    int n,m;
     
    while(cin >> n >> m ,n+m){
        int a,b,tmp[MAX]={0},cnt=0,friA[MAX_P]={0},friB[MAX_P]={0},t=0;
        for(int i = 0 ; i < m ; i++){
            cin >> a >> b;
            if(a == 1){
                tmp[b] = 1;
            }
            else{
                friA[t] = a;
                friB[t] = b;
                t++;
                }
        }
         
        for(int i = 0 ; i < t ; i++){
            if(tmp[friA[i]]==1&&!tmp[friB[i]]) tmp[friB[i]] = 2;
            else if(!tmp[friA[i]]&&tmp[friB[i]]==1) tmp[friA[i]] = 2;
        }
         
        for(int i = 0 ; i < MAX ; i++){
            if(tmp[i] > 0){
                cnt++;
            }
        }
        cout << cnt << endl;
    }
     
    return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
inline __int128 read()
{
    __int128 x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
 
inline void write(__int128 x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
}
__int128 q[100005];
int main(){
	__int128 a,sum;
	sum=1;
	int n;
	cin>>n;
	int f=1;
	long long minn=2e18;
	long long maxx=-1;
	for(int i=1;i<=n;++i){
		a=read();
		sum*=a;
		if(a==0)f=2;
		q[i]=a;
	}
	sort(q+1,q+1+n);
	if(f==2){
		cout<<0<<endl;
		return 0;
	}
	__int128 kk=1;
	for(int i=1;i<=n;++i){
		kk*=q[i];
		if(kk>1000000000000000000){
			cout<<"-1";
			return 0;
		}
	}
	write(sum);
    return 0;
}

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

int n;
string s, t, res;

int main() {
  cin >> n >> s >> t;
  for(int i = 0; i < n; ++i) {
    res += s[i];
    res += t[i];
  }
  cout << res << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> ii;

const int N = 1e4 + 5;
const int maxv = 1e6 + 1;
const int MOD = 1e9 + 7;
int n, t;
int A[N];
int p[maxv];
int cnt[maxv];
ll ans;

ll power(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % MOD;
    }
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}

void init() {
  p[1] = 1;
  for (int i = 2; i < maxv; ++i) {
    if (p[i] == 0) {
      p[i] = 1;
      for (int j = i + i; j < maxv; j += i) {
        p[j] = i;
      }
    }
  }
}

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

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    A[i] = t;
    unordered_map<int, int> ma;
    while (p[t] != 1) {
      int d = p[t];
      ++ma[d];
      t /= d;
    }
    ++ma[t];
    for (auto pr : ma) {
      if (pr.second > cnt[pr.first])
        cnt[pr.first] = pr.second;
    }
  }

  ll m = 1;
  for (int i = 2; i < maxv; ++i) {
    if (cnt[i]) {
      m = m * power(i, cnt[i]) % MOD;
    }
  }
  for (int i = 0; i < n; ++i) {
    ans = (ans + m * power(A[i], MOD - 2) % MOD) % MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7808
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

#define rep(i,a,b) for(auto (i)=a;i<b;i++)
#define list(i,N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
#define mp make_pair
#define pb push_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

int32_t main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int N, M; cin >> N >> M;
	if(N==M) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}


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

using namespace std;

const int D = 105;
const int K = 10005;
const int MOD = 1e9 + 7;

char s[K];
int n, d, f[K][D];

inline int get (int x) {
  x %= d; if (x < 0) x += d; return x;
}

int main() {
  scanf("%s %d", s + 1, &d);
  n = strlen(s + 1), f[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < d; ++j) {
      for (int k = 0; k < 10; ++k) {
        f[i][j] += f[i - 1][get(j - k)];
        if (f[i][j] >= MOD) f[i][j] -= MOD;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < 10; ++j) {
      ans += f[i - 1][get(-j)];
      if (ans >= MOD) ans -= MOD;
    }
  }
  int soFar = 0;
  for (int i = 1; i <= n; ++i) {
    int cur = s[i] - '0';
    for (int st = i == 1; st < cur; ++st) {
      ans += f[n - i][get(-soFar - st)];
      if (ans >= MOD) ans -= MOD;
    }
    soFar += cur, soFar %= d;
  }
  if (soFar == 0) ++ans, ans %= MOD;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int word = s.size();
  char min = 'a';
  
  
  if(word!=26){
    for(int i=0; i<26; i++){
      bool ans=true;
      for(int j=0; j<word; j++){
        if(s[j]==min){
          ans =false;
          min++;
          break;
        }
      }
      if(ans==true){
        cout << s << min << endl;
        return 0; 
      }
    }
  }

  else if(s=="zyxwvutsrqponmlkjihgfedcba"){
   cout << -1;
   return 0;
  }
  
  else{
   int back;

   for(int i=word-1; i>0; i--){
     if(s[i]>s[i-1]){
      min = s[i-1];
      back = i;
      break;
     }
   }
    
    for(int i=0; i<word; i++){
      for(int j=word-1; j>back-1; j--){
        if(min==s[j]){
         min = s[j];
         for(int i=0; i<back-1; i++){
        cout << s[i];
         }
          cout << min;
          return 0;
        }
      }
      min++;
    }
    
    
    
  }
  
  
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int number = sc.nextInt();
    int totalType = sc.nextInt();

    List<Integer> likes = new ArrayList<>();

    for (int i = 0; i < number; i++) {
      int type = sc.nextInt();

      for (int j = 0; j < type; j++) {
        likes.add(sc.nextInt());
      }
    }

    Map<Integer, Long> groupingLikes = likes
      .stream()
      .collect(Collectors.groupingBy(like -> like, Collectors.counting()));

    int result = 0;
    for (Long v : groupingLikes.values()) {
      if(v == number) {
        result++;
      }
    }

    System.out.println(result);
  }

}


Measured memory_bytes: 29268
IDENTIFICATION DIVISION.
PROGRAM-ID. 160C.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(1600000).
*>
WORKING-STORAGE SECTION.
01 S          PIC  X(20).
01 K          PIC  9(7).
01 N          PIC  9(6).
01 IN-TBL.
   03 A       PIC  9(6) OCCURS 200000.
01 SA-TBL.
   03 SA      PIC  9(6) OCCURS 200001 DEPENDING ON N.
01 P1         PIC  9(7).
01 P2         PIC  9(7).
01 I          PIC  9(6).
01 Z          PIC  9(7).
01 OUT        PIC  Z(6)9.
*> 
PROCEDURE DIVISION.
  ACCEPT S.
  UNSTRING S DELIMITED BY ' '
      INTO K N.
*>
  OPEN INPUT STDIO.
  READ STDIO.
  CLOSE STDIO.
*>
  MOVE 0 TO Z.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO A(I)
    COMPUTE SA(I) = A(I) - Z
    MOVE A(I)            TO Z
*>
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  ADD 1 TO N.
  COMPUTE SA(N) = K - A(N - 1) + SA(1).
  SORT SA DESCENDING KEY SA.
*>
  COMPUTE OUT = K - SA(1).
*>
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


Measured memory_bytes: 5624
// AUTHOR:: MOHAMMAD FAISAL
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int a,b;
  cin >> a>> b;
  if(a>=13)
    cout<<b;
  else if(a>=6 && a<=12)
    cout<<b/2;
  else
    cout<<0;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var raw string
	fmt.Scan(&raw)

	r := 0
	s := []rune(raw)
	l := len(s)
	for i := 0; i < l/2; i++ {
		if s[i] != s[l - i -1] {
			r++
		}
	}

	fmt.Println(r)
}

Measured memory_bytes: 512
n = int(input())
combiList = {}
sum_cnt = 0

for _ in range(n):
    act_string = list(input())
    act_string.sort()
    act_string = "".join(act_string)
    cnt = combiList.get(act_string)
    if cnt is None:
        combiList[act_string] = 1
    else:
        combiList[act_string] += 1
        sum_cnt += cnt

print(int(sum_cnt))

Measured memory_bytes: 17808
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <cassert>
#include <string>
#include <queue>
#include <ctype.h>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define int long long

signed main() {
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
	int a, b;
	cin >> a >> b;
	if (abs(a - b) <= 1) {
		cout << "Brown" << endl;
	}
	else {
		cout << "Alice" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, table[101] = { 0 }, ret = 0;

    cin >> n;

    for (int i=0; i<n; i++) {
        int tmp;
        cin >> tmp;
        if (table[tmp] == 0) ret++;
        table[tmp] = 1;
    }

    cout << ret << endl;

    return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

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

    vector<ll>a(n+1);
    a[n]=mod;
    rep(i,n){
        cin>>a[i];
    }

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

    vector<pair<ll,ll>>A(n);
    int cnt=1;

    rep(i,n){
        if(a[i]==a[i+1]){
            cnt++;
        }
        else {
            A[i].first=a[i];
            A[i].second=cnt;
            cnt=1;
        }
    }

    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());

    ll ans=1,cnt2=0;

    rep(i,n){
        if(A[i].second>=2){
            ans*=A[i].first;
            cnt2++;
        }
        if(cnt2==2){
            break;
        }
        if(A[i].second>=4){
            ans=A[i].first*A[i].first;
            cnt2=2;
            break;
        }

    }

    if(cnt2<2){
        cout<<0<<endl;
        return 0;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int R, G, B;
  int N;
  std::cin >> R >> G >> B >> N;

  // Main
  int res = 0;
  for (int r = 0; r <= N; ++r) {
    for (int g = 0; g <= N; ++g) {
      int rem = N - R * r - G * g;
      if (rem < 0)
        continue;
      if (rem % B == 0)
        res += 1;
    }
  }

  // Output
  std::cout << res << std::endl;

  return 0;
}


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

int main() {	

	ll a;
	double b;
	cin >> a >> b;

	ll b_integer = 100 * b + 0.5;
	ll ans;
	ans += a * b_integer;
	ans /= 100;

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

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define MAXN 100100
using namespace std;
typedef long long int lli;
lli N , flag;
lli arr[MAXN];

void check_min(lli low , lli high , lli idx){
    //cout << low << " " << high << " " << idx << endl;
    if(idx == -1){
        cout << low <<  " " << high << endl;
        flag = 1;
        return;
    }

    lli d1 = low / arr[idx] , d2 = high / arr[idx];
    lli p1 = arr[idx] * d1 ,  p2 = arr[idx]*d2;
    //cout << "DD " << d1 << " " << d2 << " " << p1 << " " << p2 << endl;

    if((p1 < low || p1 > high) && (p2 < low || p2 > high)) return;
    if(p1 < low) p1 += arr[idx];

    check_min(p1 , p2 + arr[idx]-1 , idx-1);
}


int main(){
    cin >> N;
    for(int i=0; i<N; i++) cin >> arr[i];
    flag = 0;
    check_min(2 , 2 , N-1);
    if(!flag) cout << "-1" << endl;
    //check_max(2 , N-1);

    //cout << ANS_MIN << " " << ANS_MAX << endl;
    //cout << ANS_MAX << endl;


    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
using namespace std;

unsigned long long a[100000+2] = {0};
unsigned long long b[100000+2] = {0};

unsigned long long gcm(unsigned long long _x, unsigned long long _y){
        unsigned long long x, y;
        unsigned long long r=0;
        if( _x<_y ){
                x = _y;
                y = _x;
        }
        else{
                x = _x;
                y = _y;
        }
        r = x % y;
        while(r!=0){
                x = y;
                y = r;
                r = x % y;
        }
        return y;
}

unsigned long long lcm(unsigned long long x, unsigned long long y){
        return (x*y)/gcm(x, y);
}

int main(int argc, char* argv[]){
	int N, M;
	unsigned long long L = 1;
	unsigned long long ans = 0;
	
	cin >> N >> M;
	for(int i=1; i<=N; i++){
		cin >> a[i];
		b[i] = a[i]/2;
		if(i==1){
			L = b[1];
		}
		else{
			L = lcm(L, b[i]);
			if( (L/b[i])%2==0 || L>M ){
				ans = 0;
				printf("%llu\n", ans);
				return 0;
			}
		}
	}
	for(int i=0; ; i++){
		if( L*(2*i+1)>M ) break;
		ans++;
	}

	printf("%llu\n", ans);
	return 0;

}

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

string s,beg,en;

int t,q,f;

char ch;

bool rev;

int main()
{
    cin >> s;
    cin >> q;
    while(q--)
    {
        cin >> t;
        if (t==1)
        {
            rev=!rev;
            swap(beg,en);
        }
        else
        {
            cin >> f >> ch;
            if (f==1)beg+=ch;
            else en+=ch;
        }
    }
    if (rev)
    {
        reverse(s.begin(),s.end());
    }
    reverse(beg.begin(),beg.end());
    cout << beg+s+en << endl;
}


Measured memory_bytes: 1348
#include<iostream>

using namespace std;

int main(){

  int n,k;
  while(cin >> n >> k && n+k){
    int blood[k];
    int flg = 0;
    for(int i = 0; i < k; i++) cin >> blood[i];
    for(int i = 0; i < n; i++){
      int data;
      for(int j = 0; j < k; j++){
	cin >> data;
	blood[j]-=data;
	if(blood[j] < 0) flg = 1;
      }
    }
    if(!flg) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 852
S = sorted(list(set(list(input()))))
test = sorted('abcdefghijklmnopqrstuvwxyz')
ans = -1
if S == test:
    print('None')

elif S[-1] == test[len(S)-1]:
    print(test[len(S)])

else:
    for num in range(len(S)):
        if test[num] != S[num]:
            print(test[num])
            break

Measured memory_bytes: 3956
#include <iostream>

using namespace std;

typedef long long ll;
ll N, A, B;
ll h[114514];

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

    ll l = 0;
    ll r = 1e9;

    while (l != r) {
        auto mid = (l + r) / 2;
        ll a = 0;
        for (int i = 0; i < N; i++) {
            if (h[i] > mid * B) {
                a += ((h[i] - mid * B) + (A - B - 1)) / (A - B);
            }
        }
        if (a <= mid) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }

    cout << l << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

int main() {
	string S;
	cin>>S;
	int w;
	cin>>w;
	rep(i,S.size()){
		if(i*w<=S.size()-1){
			cout<<S[i*w];
		}
	}
	cout<<endl;
}

Measured memory_bytes: 256
e1,e2,e3,e4=map(int,input().split())
if e1==e2 and e3==e4:
    print("yes")
elif e1==e3 and e2==e4:
    print("yes") 
elif e1==e4 and e2==e3:
    print("yes")
else:
    print("no")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int N;

int dp[3][101010]={};

int main(){
  cin >> N;
  int a1,b1,c1;
  cin >> a1 >> b1 >> c1;
  dp[0][0]=a1;
  dp[1][0]=b1;
  dp[2][0]=c1;

  reps(i,N){
    int a,b,c;
    cin >> a >> b >> c;
    dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a;
    dp[1][i]=max(dp[2][i-1],dp[0][i-1])+b;
    dp[2][i]=max(dp[0][i-1],dp[1][i-1])+c;
  }

  cout << max(dp[0][N-1],max(dp[1][N-1],dp[2][N-1]))<< endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define br cout << "\n";
#define pb push_back
#define ll long long 
#define ff first 
#define ss second
#define all(x) x.begin(),x.end()
#define in(a , idx , n ) for (int i = idx ; i < n ; ++i)cin >>a[i];
#define fix() cout <<fixed <<  std::setprecision(10)
	
using namespace std;
const int MOD = 1000*1000*1000 + 7 ; 
const int MAXN = 1000*100 +10 ;
const ll INF = 1e18 ;

void solve(){
	int n ;
	cin >> n ;
	vector<int>v ;
	for( int i = 0; i<n ; ++i )
	{
		int x ,y ;
		cin >> x >> y ;
		
		v.pb( x == y );
	}
	string res = "No";
	// for( int i = 0;i< n ; ++i )
	// cout << v[i] , br 
	for ( int i = 0 ; i <= n - 3  ; ++i )
	{
		bool ok = v[i];
		for( int j = 1 ; j<=2  ; ++j)
		{
			ok &=v[i+j];			
		}
		if ( ok )
		{	res = "Yes";
			break;} 
	} 
		cout << res ; 
}
	
int main (){
	
	int t = 1  ;
	// cin >> t ;
	while (t--){
		solve() ; 
	}
    
return 0 ; 
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(void) {
  int i, n, cnt = 0, a;
  bool flg[100001];
  for(i = 0; i <= 100000; ++i) flg[i] = false;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%d", &a);
    if(flg[a]) ++cnt;
    else flg[a] = true;
  }
  printf("%d", n - (cnt + 1) / 2 * 2);
  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++)
typedef long long ll;
int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if(k<=a) cout << k;
  else if(a<k&&k<=a+b) cout << a;
  else if(a+b<k) cout << a-(k-a-b);
}

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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> using V = vector<T>;
using P = pair<int, int>;

/*
 */

signed main() {
  string s;
  cin >> s;
  int n = sz(s);

  string t = s;
  reverse(all(t));

  string a = s.substr(0, n/2);
  string b = a;
  reverse(all(b));

  int start = (n+1)/2;
  string x = s.substr(start, n-start);
  string y = x;
  reverse(all(y));

  if(s == t and a == b and x == y){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
ll n,m,gcd;
int main(){
    cin>>n>>m;
    for(int i=1;i<=sqrt(m);i++){
        if(m%i==0){
            ll a,b;
            a = i; b = m/i;
            if(b>=n){gcd=max(gcd,a);}
            swap(a,b);
            if(b>=n){gcd=max(gcd,a);}
        }
    }
    cout<<gcd<<endl;


}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;


int n;
int v[100002];
int c[100002];
int main(){
	int sum = 0;
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		scanf("%d",&v[i]);
	}
	for (int i=0;i<n;i++){
		scanf("%d",&c[i]);
		v[i]-=c[i];
	}
	for (int i=0;i<n;i++){
		if (v[i]>0) sum+=v[i];
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
my $N= <STDIN>;
my $s= <STDIN>;
my @dat = split(/ /,$s);
my $sum =0;
my @data;
for(my $i=0;$i<$N;$i++){
    $data[$i+1]=0;
}
for(my $i=0;$i<$N;$i++){
    $data[$dat[$i]]++;
}
for(my $i=0;$i<$N;$i++){
    print "$data[$i+1]\n";
}


Measured memory_bytes: 43920
# 赤いボール用に２値配列、ボールの格納数を管理する配列を用意。
# 赤いボールの入った箱から他へ移動したら、移動先をtrueにする。
# ボール格納数は、赤でも白でも１つずつ減らす。
# ボールがゼロ個になったら、そこに赤いボールが残ることはないので
# ２値配列をfalseにする。これで解ける。

N,M = gets.split(/\s/).map {|s|s.to_i}

red = Array.new(N+1,false)
red[1] = true

ball = Array.new(N+1,1)

M.times do
  x,y = gets.split(/\s/).map {|s|s.to_i}
  if(red[x])then
    red[y] = true
  end
  ball[x] -= 1
  ball[y] += 1
  red[x] = false if(ball[x]==0)
end

cnt = 0
N.times do |i|
  if(red[i+1]==true)then
    cnt += 1
  end
end

puts cnt

Measured memory_bytes: 3964
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector<ull> p(N, 0);
	for (ull i = 0; i < N; ++i){
		cin >> p[i];
	}

	vector<ull> exp(N, 0.0);
	for (ull i = 0; i < N; ++i){
		exp[i] = p[i] + 1;
	}

	ull maxExp = 0;
	ull index = 0;
	while(index < K) {
		maxExp += exp[index];
		index++;
	}

	ull dummy = maxExp;
	while(index < N) {
		dummy = dummy - exp[index-K] + exp[index];
		if (maxExp < dummy){
			maxExp = dummy;
		}
		index++;
	}

	double sol = (double)maxExp / 2.0;

	printf("%.12f\n", sol);

	return 0;
}


Measured memory_bytes: 3456
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;
	
	long[] ps, qs, zs;
	foreach(a; as) if(a > 0) ps ~= a; else if(a < 0) qs ~= a; else zs ~= a;
	
	log("ps:", ps);
	log("qs:", qs);
	log("zs:", zs);
	
	long[] ls, rs;
	if(ps.length > 0 && qs.length > 0){
		ls = ps ~ zs, rs = qs;
	}
	else if(ps.length == 0 && qs.length == 0){
		ls = [zs[0]], rs = zs[1 .. $];
	}
	else if(ps.length == 0){
		if(zs.length > 0) ls = zs, rs = qs;
		else{
			qs.sort();
			ls = [qs[$ - 1]], rs = qs[0 .. $ - 1];
		}
	}
	else if(qs.length == 0){
		if(zs.length > 0) ls = ps, rs = zs;
		else{
			ps.sort();
			ls = ps[1 .. $], rs = [ps[0]];
		}
	}
	log("ls:", ls);
	log("rs:", rs);
	
	long[2][] ans;
	long v = ls[0];
	if(rs.length > 1) foreach(r; rs[1 .. $]){
		ans ~= [v, r];
		v = v - r;
	}
	
	long w = rs[0];
	if(ls.length > 1) foreach(l; ls[1 .. $]){
		ans ~= [w, l];
		w = w - l;
	}
	
	ans ~= [v, w];
	v = v - w;
	
	v.writeln;
	foreach(an; ans) writeln(an[0], " ", an[1]);
	
}



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

struct card
{
    char suit;
    int value;
};
void bubble(card A[], int n)
{
    for(int i=0; i<n; i++)
    {
        for(int j=n-1; j>=i+1; j--)
        {
            if(A[j].value<A[j-1].value)
            {
                card t = A[j];
                A[j] = A[j-1];
                A[j-1] = t;
            }
        }
    }
}
void selection(card A[], int n)
{
    for(int i=0; i<n; i++)
    {
        int minj = i;
        for(int j=i+1; j<n; j++)
        {
            if(A[j].value<A[minj].value)
            {
                 minj = j;
            }
        }
        if(i != minj)
        {
            card t = A[i];
            A[i] = A[minj];
            A[minj] = t;
        }
    }
}
void print(card A[],int n)
{
    for(int i=0; i<n-1; i++)
        cout << A[i].suit << A[i].value << " ";
    cout << A[n-1].suit << A[n-1].value << endl;
}
int main()
{
    card c1[100], c2[100];
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> c1[i].suit >> c1[i].value;
    for(int i=0; i<n; i++)
        c2[i] = c1[i];
    bubble(c1,n);
    selection(c2,n);
    print(c1,n);
    cout << "Stable" << endl;
    print(c2,n);
    for(int i=0; i<n; i++)
    {
        if(c1[i].suit != c2[i].suit)
        {
            cout << "Not stable" << endl;
            break;
        }
        if(i == n-1)  cout << "Stable" << endl;
    }
    return 0;
}

Measured memory_bytes: 3112
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = std::max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = std::min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int h, w, n;
	scanf("%d\n%d\n%d", &h, &w, &n);
	int bigger = max(h, w);
	printf("%d\n", (n / bigger) + (n % bigger ? 1 : 0));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int Q;
int lr[100000][2];
int plike[100001];
int p[100001];

int main(){
  cin >> Q;
  for(int i=0;i<Q;i++){
    cin >> lr[i][0] >> lr[i][1];
  }
  for(int i=0;i<100001;i++){
    p[i] = -1;
    plike[i] = 0;
  }
  for(int i=2;i<100001;i++){
    if(p[i] != -1) continue;
    p[i] = i;
    for(int j=i*2;j<100001;j+=i) p[j] = i;
  }
  for(int i=3;i<100001;i++){
    if(i%2 == 0){
      plike[i] = plike[i-1];
      continue;
    }
    if(p[i] != i){
      plike[i] = plike[i-1];
      continue;
    }
    if(p[(i+1)/2] != (i+1)/2){
      plike[i] = plike[i-1];
      continue;
    }
    plike[i] = plike[i-1] + 1;
  }
  for(int i=0;i<Q;i++){
    cout << plike[lr[i][1]] - plike[lr[i][0]-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 2176
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from string import ascii_lowercase

    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    elif len(s) < 26:
        x = set(ascii_lowercase) - set(s)
        x = list(x)
        x.sort()
        print(s + x[0])
    else:
        for i in range(25, -1, -1):
            j = 0
            while chr(ord(s[i]) + j + 1) <= "z":
                j += 1
                if chr(ord(s[i]) + j) not in set(s[:i]):
                    return print(s[:i] + chr(ord(s[i]) + j))


if __name__ == '__main__':
    main()


Measured memory_bytes: 68564
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
int n,k;const int SIZE=2050;
int w[SIZE];
int shk,fzy;
std::vector<int>v[SIZE];
int d[SIZE];
int e[SIZE][2];
int vis[SIZE];
void init(){
	for(int i=1;i<=n;i++){
		vis[i]=0;
	}
}
void init2(){
	init();
	for(int i=1;i<=n;i++){
		d[i]=0;
	}
}
void dfs(int pos,int deep){
	d[pos]+=deep;vis[pos]=1;
	//cout<<"pos="<<pos<<endl;
	for(int i=0;i<v[pos].size();i++){
		//cout<<"next:"<<v[pos][i]<<endl;
		if(!vis[v[pos][i]])
			dfs(v[pos][i],deep+1);
	}
}

void display(){
	for(int i=1;i<=n;i++)
		cout<<"i="<<i<<" d[i]="<<d[i]<<endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n-1;i++){
		cin>>shk>>fzy;
		v[shk].push_back(fzy);v[fzy].push_back(shk);
		e[i][0]=shk;e[i][1]=fzy;
	}
	int ans=n;
	if(k%2==0){//k为偶数
		for(int i=1;i<=n;i++){
			init2();
			dfs(i,0);
			int cnt=0;
			//display();
			for(int j=1;j<=n;j++){
				if(d[j]>k/2)cnt++;
			}
			ans=min(ans,cnt);
		}
	}
	else{
		for(int i=1;i<=n-1;i++){
			init2();
			dfs(e[i][0],0);
			init();
			dfs(e[i][1],0);
			int cnt=0;//cout<<"ddsa"<<endl;
			for(int j=1;j<=n;j++){
				if(d[j]>k)cnt++;
			}
			ans=min(ans,cnt);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define mod 1000000007
using namespace std;


int main(void){
    ll n; cin>>n;
    vl h(n);
    for(int i=0;i<n;++i) cin>>h[i];
    ll maxi = h[0];
    for(int i=0;i<n;++i){
        maxi = max(maxi,h[i]);
        if(maxi-h[i] >= 2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    
}


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

fac = [1]
for i in range(N):
    i += 1
    fac.append(fac[-1] * i)

def nCr(n,r):
    return fac[n] // (fac[r] * fac(n-r))

p = list(map(float,input().split()))

"""

dpだよな
表と裏がa,N-a枚となる確率は？
無理かなぁ

左から見ていってdp?
表がa枚になる確率は p*(a-1枚の確率) + (1-p)*(a枚の確率)
→いけそう

"""

dp = [0] * (N+1)
dp[0] = 1

for loop in range(N):

    ndp = [0] * (N+1)

    for i in range(N):

        ndp[i+1] += dp[i] * p[loop]
        ndp[i] += dp[i] * (1-p[loop])

    dp = ndp

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

print (ans)


Measured memory_bytes: 57180
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string strInput = Console.ReadLine();

            strInput = strInput.Replace('1', 'a');
            strInput = strInput.Replace('9', '1');
            strInput = strInput.Replace('a', '9');

            Console.WriteLine(strInput);

            string s = Console.ReadLine();

        }
    }
}

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

int main() {
    int i;
    for (i = 0; i < 5; i++) {
        int x;
        cin >> x;
        if (x == 0) break;
    }
    i++;
    cout << i << endl;
}

Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); //入出力高速化
  while (true) {
    int n,w,d; cin >> n >> w >> d;
    if (n == 0 && w == 0 && d == 0) break;
    vector<pair<int, int>> A;
    A.emplace_back(make_pair(w,d));
    rep(i,n) {
      int p,s; cin >> p >> s;
      p--;
      int H,W;
      tie(W,H) = A[p]; A.erase(A.begin() + p);
      s %= (W + H);
      if (s < W) {
        A.emplace_back(min(W - s,s),H);
        A.emplace_back(max(W - s,s),H);
      } else {
        s -= W;
        A.emplace_back(W,min(H - s,s));
        A.emplace_back(W,max(H - s,s));
      }
    }
    int N = A.size();
    vector<int> S(N);
    rep(i,N) S[i] = A[i].first * A[i].second;
    sort(all(S));
    rep(i,N) {
      if (i == 0) cout << S[i];
      else cout << " " << S[i];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3060
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int number = Integer.parseInt(S.replaceAll("/", ""));
        sc.close();

        if (number > 20190430) {
            System.out.println("TBD");
        }
        else {
            System.out.println("Heisei");
        }
    }
}

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

int main() {

    ll N,A,B;
    cin >> N >> A >> B;
    ll x[N+1];
    for(ll i = 1; i <= N; i ++){
        cin >> x[i];
    }

    ll ans = 0; 

    for(ll i = 1; i < N; i ++){
        if(B >= (x[i + 1] - x[i]) * A){
            ans += (x[i + 1] - x[i]) * A;
        }
        else{
            ans += B;
        }        
    }        

    cout << ans << endl;

return 0;
}

Measured memory_bytes: 4372
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
ll n, a, b;
int main(){
    cin >> n >> a >> b;
    ll cnt = 0;
    cnt += (n / (a + b)) * a;
    ll remain = n % (a + b);
    if(remain >= a) cnt += a;
    else cnt += remain;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int _=0,x=0,y=0;
long long a=0,b=0;
char ch[10];
int main ()
{
//freopen("test.in","r",stdin);
    cin>>_;
    while (_--)
    {
        scanf("%d%s%d",&x,ch,&y);
        if (ch[0]=='(')
            a+=y;
        else
            b+=y;
        if (a==b)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
//fclose(stdin);
    return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
long long arr[2000000];
int main()
{
	long long n,s,k,i,j,x;
	x=1e9+5;
	cin>>n>>s>>k;
	for (i=0;i<s;i++)
	{
		arr[i]=k;
	}
	for (i=s;i<n;i++)
	{
		if (k<999999999)
		{
			arr[i]=k+1;
		}
		else
		{
			arr[i]=k-1;
		}
	}
	for (i=0;i<n;i++)
	{
		cout<<arr[i]<<" ";
	}
	cout<<endl;
}

Measured memory_bytes: 2048
import sys
n, k = map(int, input().split())
s = list(input())
left = 0
right = 0
if s[0] == "L":
    left = 1
if s[n-1] == "R":
    right = 1
count = 0
if n == 1:
    print(0)
    sys.exit()
for i in range(n-1):
    if s[i] == "R" and s[i+1] == "L":
        count += 1
if k < count:
    count -= k
    ans = n - count*2 - left - right
    print(ans)
elif k == count:
    if left == right == 1:
        print(n-2)
    else:
        print(n-1)
else:
    print(n-1)

Measured memory_bytes: 49392
n=int(input())
a=list(map(int,input().split()))
mul=1
key=0
for i in range(len(a)):
    if a[i]==0:
        key=1
        print(0)
        break;
if key==0:
    for i in range(len(a)):
        mul=mul*a[i]
        if mul>1000000000000000000:
            break
    if(mul<1000000000000000001):
        print(mul)
    else:
        print(-1)

Measured memory_bytes: 21568
from collections import Counter


def comb(k):
    return k*(k - 1)//2


def submit():
    n = int(input())
    alist = list(map(int, input().split()))
    a_count = Counter(alist)
    total = sum(comb(v) for k, v in a_count.items())

    for a in alist:
        print(total - (a_count[a] - 1))


submit()


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

int main() {
   ll N, D;
   cin >> N >> D;
   ll x, y;
   ll ans = 0;
   for(ll i=0; i<N; i++){
       cin >> x >> y;
       if(sqrt(x*x + y*y) <= D){
           ans++;
       }
   }

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

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

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

    int N;
    cin >> N;

    vector<int> d(N);
    ll a_sum = 0, b_sum = 0, minus_sum = 0, d_minus = 0;
    rep(i, N) {
        cin >> d[i];
        a_sum += d[i];
    }
    rep(i, N) {
        int B; cin >> B;
        b_sum += B;
        d[i] -= B;
        if (d[i] < 0) {
            minus_sum += d[i];
            d_minus++;
        }
    }

    int ans = -1;
    if (a_sum >= b_sum) {
        if (d_minus == 0) {
            ans = 0;
        } else {
            sort(d.begin(), d.end(), greater<int>());
            for (int i = 0; i < N; i++) {
                minus_sum += d[i];
                if (minus_sum >= 0) {
                    ans = d_minus + i+1;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int N = 20000 , _ = N + 7;

int n,val[_],vala[_],valb[_];

int main()
{
	n=ty();
	for(int i=1;i<=n;i++)val[i]=ty();

	for(int i=1;i<=n;i++)vala[i]=i*N,valb[i]=(n-i+1)*N;
	for(int i=1,x;i<=n;i++)x=i/2,vala[val[i]]+=x,valb[val[i]]+=i-x;
	for(int i=1;i<=n;i++)printf("%d%c",vala[i]," \n"[i==n]);
	for(int i=1;i<=n;i++)printf("%d%c",valb[i]," \n"[i==n]);

	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,c=0;cin>>A>>B;
  for(int i=A;i<=B;i++){
    if(i/10000==i%10&(i%10000)/1000==(i%100)/10)++c;
  }
  cout<<c;
}

Measured memory_bytes: 256