akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = input().strip()

locs = {}
RGB = {"R", "G", "B"}

for let in RGB:
    lc = []
    temp = 0
    for l in reversed(s):
        if l == let:
            temp += 1
        lc.append(temp)
    locs[let] = list(reversed(lc))

total = 0
for i in range(0, n - 2):
    il = s[i]
    for j in range(i + 1, n - 1):
        jl = s[j]
        if il != jl:
            left = (RGB - {il, jl}).pop()
            local = locs[left][j + 1]
            mk = j + (j - i)
            if mk < n and s[mk] == left:
                local -= 1
            total += local

print(total)


Measured memory_bytes: 68828
N, K, S = gets.chomp.split(" ").map(&:to_i)

A = Array.new(N)
K.times{|i| A[i] = S}
(N - K).times{|i|
  A[-(i + 1)] = (S == 10 ** 9 ? S - 1 : S + 1)
}

puts A.join(' ')


Measured memory_bytes: 4732
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i],--a[i];
    int now = 0;
    int cnt = 0;
    int cyc = 0;
    int s = 0;
    vector<int> before(n,-1);
    vector<int> res;
    while(1){
        res.push_back(now);
        before[now] = cnt;
        ++cnt;
        now = a[now];
        if(before[now]>=0){
            cyc = cnt - before[now];
            s = before[now];
            break;
        }
    }

    if(k <= s){ cout << res[k]+1 << endl;}
    else{
        cout << res[s+(k-s)%cyc]+1 << endl;
    }
    return 0;
}

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

const int INF = (1 << 28);

int main(void) {
    int n, m;
    while (cin >> n >> m, n) {

        vector<int> taro(n);
        for (int i = 0; i < n; i++) {
            cin >> taro[i];
        }
        vector<int> hanako(m);
        for (int j = 0; j < m; j++) {
            cin >> hanako[j];
        }

        int t_sum = accumulate(taro.begin(), taro.end(), 0);
        int h_sum = accumulate(hanako.begin(), hanako.end(), 0);

        int ans = INF;
        int t_ans, h_ans;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                int ts = t_sum-taro[i]+hanako[j];
                int hs = h_sum-hanako[j]+taro[i];

                if (ts == hs && ans > ts) {
                    ans = ts;
                    t_ans = taro[i];
                    h_ans = hanako[j];
                }
            }
        }

        if (ans != INF) {
            cout << t_ans << " " << h_ans << endl;
        } else {
            cout << -1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1196
N = int(input())
A = list(map(int,input().split()))
Ans = []
temp = [0]*(N+1)

def factor(num):
    sqrt = num**0.5
    for i in range(1,int(num**0.5)+1):
        if i == sqrt:
            temp[i] += 1
        elif num%i == 0:
            temp[i] += 1
            temp[num//i] += 1
    return


for a,i in zip(A[::-1],range(N-1,-1,-1)):
    if a == 1 and temp[i+1] == 0:
        factor(i+1)
        Ans.append(i+1)
    elif temp[i+1]%2 != a:
        factor(i+1)
        Ans.append(i+1)
if len(Ans) == 0:
    print(0)
else:
    print(len(Ans))
    print(*Ans,sep = " ")

Measured memory_bytes: 71400
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int h, w;
template<typename T, bool is_directed> class Dinic {
private:
  struct edge {
    int to;
    T capacity;
    int rev;
    edge() {}
    edge (int _to, T _capacity, int _rev) : to(_to), capacity(_capacity), rev(_rev) {}
    void add (int _to, T _capacity, int _rev) {to = _to; capacity = _capacity; rev = _rev;}
  };
  vector<vector<edge>> graph;
  vector<int> level, iter;
public:
  Dinic() {}
  Dinic(int n) : graph(n), level(n), iter(n) {}
  void add(int from, int to, T capacity) {
    if (to == h + w + 1) {
      graph[from].emplace_back(to, capacity, (int) graph[to].size());
      graph[to].emplace_back(from, 0, (int) graph[from].size() - 1);
    } else if (from == h + w) {
      graph[from].emplace_back(to, capacity, (int) graph[to].size());
      graph[to].emplace_back(from, 0, (int) graph[from].size() - 1);
    } else {
      graph[from].emplace_back(to, capacity, (int) graph[to].size());
      graph[to].emplace_back(from, capacity, (int) graph[from].size() - 1);
    }
    //graph[from].emplace_back(to, capacity, (int) graph[to].size());
    //graph[to].emplace_back(from, (is_directed ? 0 : capacity), (int) graph[from].size() - 1);
  }
  void bfs(int s) {
    fill(level.begin(), level.end(), -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (que.size()) {
      int cur = que.front();
      que.pop();
      for (edge& e : graph[cur]) {
        if (e.capacity > 0 && level[e.to] == -1) {
          level[e.to] = level[cur] + 1;
          que.push(e.to);
        }
      }
    }
  }
  T dfs(int v, int t, T f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < (int) graph[v].size(); i++) {
      edge& e = graph[v][i];
      if (e.capacity > 0 && level[v] < level[e.to]) {
        T d = dfs(e.to, t, min(f, e.capacity));
        if (d == 0) continue;
        e.capacity -= d;
        graph[e.to][e.rev].capacity += d;
        return d;
      }
    }
    return 0;
  }
  T flow(int s, int t, T lim) {
    T fl = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0 || lim == 0) break;
      fill(iter.begin(), iter.end(), 0);
      while (true) {
        T f = dfs(s, t, lim);
        if (f == 0) break;
        fl += f;
        lim -= f;
      }
    }
    return fl;
  }
  T flow(int s, int t) {
    return flow(s, t, numeric_limits<T>::max() >> 1);
  }
};
const int INF = 10000000;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> h >> w;
  Dinic<int, false> dinic(h + w + 2);
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == 'S') {
        dinic.add(h + w, i, INF);
        dinic.add(h + w, h + j, INF); 
      }
      if (s[j] == 'T') {
        dinic.add(i, h + w + 1, INF);
        dinic.add(h + j, h + w + 1, INF);
      }
      if (s[j] == 'o') {
        dinic.add(i, h + j, 1);
      }
    }
  }
  int ans = dinic.flow(h + w, h + w + 1);
  cout << (ans >= INF ? -1 : ans) << endl;
  return 0;
}

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

int main()
{
    int in;
    vector<int> v;
    while(cin >> in)
    {
        v.push_back(in);
    }
    sort(v.begin(), v.end(), greater<int>());
    for(int i = 0; i < 3 ; i++)
    {
        cout << v[i] << endl;
    }
}

Measured memory_bytes: 1212
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
    char a [10];
    scanf("%s",a);
    if(a[1]==a[2]&&(a[1]==a[0]||a[1]==a[3]))
    printf("Yes");
    else 
    printf("No");
    return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
D = sorted(make_divisors(M))[::-1]

for e in D:
    if N*e <= M:
        print(e)
        exit(0)


Measured memory_bytes: 63564
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		String s=sc.next();
		ArrayList<Integer> ans=new ArrayList<>();
		int state=n;
		while(true){
			if(state-m<=0){
				ans.add(state);
				break;
			}
			int k=state-m;
			while(true){
				if(s.charAt(k)=='0'){
					break;
				}
				k++;
				if(k==state){
					System.out.println(-1);
					return;
				}
			}
			ans.add(state-k);
			state=k;
		}
		for(int i=ans.size()-1; i>=0; i--){
			System.out.print(ans.get(i)+" ");
		}
	}
}


Measured memory_bytes: 42312
def main():
    n, m = map(int, input().split())
    st = [list(map(int, input().split())) for _ in [0]*m]
    g = [[] for _ in [0]*n]
    [g[a-1].append(b-1) for a, b in st]
    toP = [0]*n
    toE = [0]*n
    fromE = [0]*n
    toP[0] = 1
    for i in range(n-1):
        p = toP[i]
        if p > 0:
            toE[i] /= toP[i]
        e = toE[i]
        l = len(g[i])
        for j in g[i]:
            toP[j] += p/l
            toE[j] += (e+1)*p/l
    for i in range(n-2, -1, -1):
        l = len(g[i])
        for j in g[i]:
            fromE[i] += (fromE[j]+1)/l
    allE = fromE[0]
    ans = fromE[0]
    tf = [toP[i]*((toE[i]+1)*len(g[i])+sum([fromE[j] for j in g[i]]))
          for i in range(n)]
    for s, t in st:
        if g[s-1]:
            l = len(g[s-1])
            if l > 1:
                ans = min(allE+tf[s-1]*(1/(l-1)-1/l)-toP[s-1] *
                          (toE[s-1]+1+fromE[t-1])/(l-1), ans)
    print(ans)


main()


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    for (int h = 1; h <= 3500; ++h) {
        for (int n = 1; n <= 3500; ++n) {
            ll X = (ll)4 * h * n - (ll)N * n - (ll)N * h;
            if (X <= 0) continue;

            if (((ll)N * h * n) % X == 0) {
                int w = ((ll)N * h * n) / X;
                if (1 <= w && w <= 3500) {
                    cout << h << " " << n << " " << w << endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

constexpr int64_t kMod = 1e9+7;

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

  vector<int64_t> nums(N);
  for (int n = 0; n < N; ++n) {
    cin >> nums[n];
  }
  
  vector<vector<int64_t>> cnt(2, vector<int64_t>(61));                              
  for (int64_t n : nums) {
    bitset<61> bs(n);
    for (size_t i = 0; i <= 60; ++i) {
      if (bs.test(i)) {
        ++cnt[1][i];
      } else {
        ++cnt[0][i];
      }
    }
  }
  int64_t result = 0;
  for (size_t i = 0; i <= 60; ++i) {
    result += (static_cast<int64_t>(pow(2, i)) % kMod) * (cnt[0][i] * cnt[1][i] % kMod);
    result %= kMod;
  }
  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 5680
program ABC149C
    implicit none
    real::n
    integer::i,Flag
    read*,n
    do
        Flag = 1
        do i = 2,int(sqrt(n))
            if (mod(int(n),i) == 0) then
                Flag = 0
            end if
        end do
        if (Flag == 1) then
            print*,int(n)
            stop
        else
            n = n + 1
        end if
    end do
end program ABC149C

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

int main() {
  int n;
  
  cin >> n;
  
  int num[n];
  
  for(int i = 0; i < n; i++) {
   	cin >> num[i]; 
  }
  
  sort(num, num+n);
  float avg = num[0];
  for(int i = 1; i < n; i++) {
   	 avg = ((avg+num[i])*1.0)/2;
  }
  
  cout << avg << endl;
  return 0;
}

Measured memory_bytes: 256
sx, sy, tx, ty = map(int,input().split())

#1回目 (sx,sy)->(tx,ty)
for i in range(tx-sx):
    print("R",end="")
for i in range(ty-sy):
    print("U",end="")

#2回目 (tx,ty)->(sx,sy)
for i in range(tx-sx):
    print("L",end="")
for i in range(ty-sy):
    print("D",end="")

#3回目 (sx,sy)->(tx,ty)
print("D",end="")
for i in range(tx-sx+1):
    print("R",end="")
for i in range(ty-sy+1):
    print("U",end="")
print("L",end="")

#4回目 (tx,ty)->(sx,sy)
print("U",end="")
for i in range(tx-sx+1):
    print("L",end="")
for i in range(ty-sy+1):
    print("D",end="")
print("R",end="")

Measured memory_bytes: 4468
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))

W,H,x,y = mint()
print(W*H/2, int((W,H)==(2*x,2*y)))

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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

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

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

    int coin[] = { 500, 5, 1 };
    int num[3] = { 0 };
    REP (i, sizeof(coin)/sizeof(int)) {
        num[i] = X / coin[i];
        X -= coin[i] * num[i];
    }

    cout << num[0]*1000 + num[1]*5 << endl;
}


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

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

ll min(ll x, ll y){
    if(x < y)return x;
    else return y;
}

int main(void){
    ll n;
    scanf("%lld", &n);
    int n2 = (int)ceil(pow(n, 0.5));
    int ans;
    for(ll i = n2;i >= 0;i--){
        if(n%i==0){
            ans = (int)floor(log10(n/i))+1;
            break;
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

string s;

int main()
{
    _FastIO;
    cin >> s;
    string ans = "Good";
    for(int i = 1; i < 4; i++){
        if(s[i] == s[i - 1])
            ans = "Bad";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
N,M = map(int, input().split())

s = set()
g = set()

for i in range(M):
    a,b = map(int, input().split())
    if a == 1:
        s.add(b)
    elif b == N:
        g.add(a)


ans = len(s & g) > 0
print("POSSIBLE" if ans else "IMPOSSIBLE")

Measured memory_bytes: 18936
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int l[100010], r[100010];
int sum[100010];

std::vector<int> eratosthenes_sieve(int n) {
	std::vector<int> ps(n + 1);
	std::iota(ps.begin() + 2, ps.end(), 2);
	for (int i = 2; i * i <= n; ++i)
		if (ps[i])
			for (int j = i * i; j <= n; j += i) ps[j] = 0;
	return ps;
}

int main() {
	int Q;
	cin >> Q;
	REP(i, Q) {
		cin >> l[i] >> r[i];
	}

	// 素数リスト
	vector<int> primes = eratosthenes_sieve(100000);
	//REP(i, 100) cout << primes[i] << endl;

	sum[1] = 0;
	for (int i = 3; i < 100001; i += 2) {
		sum[i] = sum[i - 2];

		// 2017-likeの判定
		if (primes[i] != 0 && primes[(i + 1) / 2] != 0) {
			sum[i]++;
		}
	}

	REP(i, Q) {
		cout << sum[r[i]] - sum[l[i] - 2] << endl;
	}

	system("pause");
	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    int a[n];
    int s=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        s+=a[i];
    }
    int ans1=s;
    for(int i=1;i<n-1;i+=2){
        ans1-=a[i]*2;
    }
    cout<<ans1<<" ";
    for(int i=0;i<n-1;i++){
        ans1=2*a[i]-ans1;
        cout<<ans1<<" ";
    }
    cout<<endl;
}
    

Measured memory_bytes: 1664
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let mut n: u64 = read();
    let mut ret: Vec<char> = Vec::with_capacity(15);

    while n > 0 {
        n -= 1;
        ret.push(((n % 26) + 97) as u8 as char);
        n /= 26;
    }
    ret.reverse();
    println!("{}", ret.into_iter().collect::<String>());
}


Measured memory_bytes: 2172
n,k = map(int,input().split())

if n < k:
    rival_n = k - n
    if n >= rival_n:
      print(rival_n)
    else:
      print(n)

elif n == k:
    print(0)

else:

    n = n % k
    rival_n = k - n
    if n >= rival_n:
        print(rival_n)
    else:
        print(n)


Measured memory_bytes: 9132
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=52;
const ll MOD=1e9+7;
int N;
string S[2];
int main(){
	cin>>N;
	REP(i,2)cin>>S[i];
	ll ans;
	int f;
	if (S[0][0]==S[1][0]){
		ans=3;
		f=0;
	}else{
		ans=6;
		f=1;
	}
	int inx=(f==0 ? 1 : 2);
	FOR(i,inx,N){
		if (S[0][i]==S[1][i]){
			if (f==0){
				ans*=2;
				ans%=MOD;
			}
			f=0;
		}else{
			if (f==0){
				ans*=2;
				ans%=MOD;
			}else{
				ans*=3;
				ans%=MOD;
			}
			f=1;
			i++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int f[100010];
int main()
{
	long long int n,W;
	scanf("%lld %lld",&n,&W);
	for(int i=1;i<=n*1000;i++) f[i]=1000000001;
	for(int i=1,w,v;i<=n;i++)
	{
		scanf("%d %d",&w,&v);
		for(int j=n*1000;j>=v;j--)
		{
			f[j]=min(f[j],f[j-v]+w);
		}
	}
	int ans=0;
	for(int i=0;i<=n*1000; i++)
	{
		if(f[i]<=W)
		{
			ans=i;
		}
	}
	printf("%d\n",ans);
	return 0;
}
//

Measured memory_bytes: 1024
import math
#N = int(input())
a,b,c = map(int, input().split())
#print (min(A), max(A), sum(A))
si = math.sin(math.radians(c))
cs = math.cos(math.radians(c))

ta = (b * si)
print(ta * a/2)
yf = (a-(b*cs))
d = math.sqrt((yf * yf) + (ta * ta))
print(a+b+d)
print(ta)


Measured memory_bytes: 5708
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int i,n,a=0,x,s=mod;cin>>n;
	REP(i,n){
		cin>>x;
		if(chmin(s,x)){a++;}
	}
	cout<<a<<endl;
}

Measured memory_bytes: 256
n,h = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
l = sorted(l,key=lambda x:(-x[0],x[1]))
max = l[0]
l.pop(0)
l = sorted(l,key=lambda x:-x[1])
cnt = 0
for i in range(n-1):
    if max[0]<=l[i][1]:
        h -= l[i][1]
        cnt += 1
    if h<=0:
        print(cnt)
        exit()
    if h-max[1]<=0:
        print(cnt+1)
        exit()
h-=max[1]
cnt+=1
if h<=0:
    print(cnt)
elif h%max[0]==0:
    print(cnt+h//max[0])
else:
    print(cnt+h//max[0]+1)

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

int main()
{
    canhazfast();

    ull a, b;
    int ans = 1;

    cin >> a >> b;
    a = gcd(a, b);
    if (a%2 == 0) ++ans;
    a >>= ctzll(a);
    for (uint p = 3; ; p += 2) {
        ull q = a/p, r = a%p;
        brif(q < p);
        ctif(r);
        ++ans;
        do {
            a = q;
            q = a/p;
            r = a%p;
        } while (!r);
    }
    if (a > 1) ++ans;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};

int main() {
	string S, T;
	cin >> S >> T;
	ll ans = 0;
	rep(i, S.size()) {
		if (S[i] != T[i]) {
			ans++;

		}

	}
	cout << ans;
	//cout << fixed << setprecision(10) << ans;
}


Measured memory_bytes: 3916
def h(A,B):
    T=""
    for i in range(len(B)):
        T+=A[i]+B[i]
    return T+A[-1]

from itertools import product
S=input()

P=product(["","+"],repeat=len(S)-1)

K=0
for p in P:
    K+=eval(h(S,p))
print(K)


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

using namespace std;

#define MAXN 500
#define INF 1000000000

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, i, j, k, ma, mb, ans = INF;
	cin >> n >> ma >> mb;
	vector<int> a(n), b(n), c(n);
	for (i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];

	vector<vector<int>> dp(MAXN, vector<int>(MAXN, INF));
	dp[0][0] = 0;
	for (i = 0; i < n; i++) {
		for (j = MAXN - 1; j >= 0; j--) {
			for (k = MAXN - 1; k >= 0; k--) {
				if ((j + a[i] < MAXN) && (k + b[i] < MAXN))
					dp[j + a[i]][k + b[i]] = min(dp[j + a[i]][k + b[i]], dp[j][k] + c[i]);
			}
		}
	}

	for (i = 1; i < MAXN; i++) {
		for (j = 1; j < MAXN; j++) {
			if (i * mb == j * ma) ans = min(ans, dp[i][j]);
		}
	}

	if (ans == INF) cout << -1 << "\n";
	else cout << ans << "\n";


	return 0;
}



Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return x*f;
}
int a[4];
int main(){
	for (int i=0;i<4;++i) a[i]=read();
	sort(a,a+4);
	if (a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>

#define N 1000001
#define ALPHA_N 10

using namespace std;

double solve(double *expect){
  double possible[ALPHA_N];
  double npossible[ALPHA_N];

  expect[0] = 0;
  expect[1] = 1;
  expect[2] = 1.5;

  possible[0]=1;
  for(int i = 1; i < ALPHA_N; ++i){
    double pos = 1.0/pow(2.0,i);
    possible[i] = pos * possible[i-1];
    npossible[i] = (1-pos)*possible[i-1];
  }

  for(int n = 3; n < N; ++n){
    expect[n] = 0;
    for(int j = 1; j < ALPHA_N && n-j-1 >= 0; ++j){
      expect[n] += npossible[j] * ( j + expect[n-j-1] );
    }
    if( n-1 < ALPHA_N )
      expect[n] += n * possible[n-1];
  }
}

int main(){
  double *ans = new double[N];
  solve( ans );
  while(true){
    int n;
    scanf("%d", &n);
    if(n==0)break;
    printf("%.3lf\n", ans[n]);
  }
  delete [] ans;
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc097/tasks/abc097_b

int main() {
    int X; cin >> X;
    vector<int> expo(X+5);
    expo[1] = 1;

    for (int i = 2; i < X; i++) {
        int v = i * i;
        while(v <= X) {
            expo[v] = 1;
            v = v * i;
        }
    }

    for (int i = X; i >= 0; i--) if (expo[i]){
            cout << i << "\n";
            return 0;
    }

    return 0;
}


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

int main(){
    int n,a;
    cin >> n;
    a = n%10;

    if(a==0||a==1||a==6||a==8) cout << "pon" << endl;
    else if(a==3) cout << "bon" << endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3652
# -*- coding: utf-8 -*-
"""
Created on Sat May 19 19:34:44 2018
ALDS1_7_B
@author: maezawa
"""

n = int(input())

parent = [-1 for _ in range(n)]
left = [-1 for _ in range(n)]
right = [-1 for _ in range(n)]
height = [None for _ in range(n)]
depth = [None for _ in range(n)]

def set_parent():
    global parent
    for i in range(n):
        if left[i] != -1:
            parent[left[i]] = i
        if right[i] != -1:
            parent[right[i]] = i

    
def set_depth(i, p):
    global depth
    if depth[i] != None:
        return
    depth[i] = p
    if right[i] != None:
        set_depth(right[i], p)
    if left[i] != None:
        set_depth(left[i], p+1)
       
def get_depth(i):
    global depth
    if depth[i] != None:
        return depth[i]
    d = 0
    u = i
    while parent[u] != -1:
        u = parent[u]
        d += 1
    depth[i] = d
    return d

def set_height(u):
    global height
    h1 = 0
    h2 = 0
    if right[u] != -1:
        h1 = set_height(right[u])+1
    if left[u] != -1:
        h2 = set_height(left[u])+1
    height[u] = max(h1, h2)
    return height[u]    

def get_sib(i):
    if right[parent[i]] == i:
        return left[parent[i]]
    else:
        return right[parent[i]]
    
def get_deg(i):
    deg = 0
    if right[i] != -1:
        deg += 1
    if left[i] != -1:
        deg += 1
    return deg    

def get_height(i):
    return height[i]

def preparse(i):
    if i == -1:
        return
    print(' {}'.format(i), end='')
    preparse(left[i])
    preparse(right[i])
    
def inparse(i):
    if i == -1:
        return
    inparse(left[i])
    print(' {}'.format(i), end='')
    inparse(right[i])
 
def postparse(i):
    if i == -1:
        return
    postparse(left[i])
    postparse(right[i])
    print(' {}'.format(i), end='')

for i in range(n):
    line = list(map(int, input().split()))
    left[line[0]] = line[1]
    right[line[0]] = line[2]

set_parent()
root = parent.index(-1)
print('Preorder')
preparse(root)
print()
print('Inorder')
inparse(root)
print()
print('Postorder')
postparse(root)
print()        



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

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


Measured memory_bytes: 256
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defun main (str)
  (count #\1 str))


(defun main(n yen)
  (loop for i from 0 to n
        do
           (loop for j from 0 to (- n i)
                 for k = (- n i j)
                 when (= (+ (* i 10000) (* j 5000) (* k 1000)) yen)
                   do
                 (return-from main (format nil "~a ~a ~a~%" i j k))))
  "-1 -1 -1")

(princ (main (read) (read)))


Measured memory_bytes: 12212
//
//  main.cpp
//  ABC145B
//
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int N;
    cin>>N;
    string S;
    cin>>S;
    if(N%2!=0){
        cout <<"No"<<endl;
        return 0;
    }else{
        for (int i=0; i<N/2; i++) {
            if(S.at(i)!=S.at(i+N/2)){
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a,b) + min(c,d) << "\n";
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define pb push_back
#define ll unsigned long long
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0) 
#define sz(a) (a).size()
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
using namespace std;
 
/*
 tips :
 Sqrt opt
 Binary search
 Try to find the easiest solution
 Recursiya
 FUCK YOU pishi kod akuratnee daun yobani
 sdohni v adu nahui blyat' y ub'uy tebya
 esli ti blyad' budesh pisat' kod gryaznim
 to ya tebya v rot viebu
*/
 
const ll N = 1E6 + 10;
const ll M = 3e3 + 10;
const ll big = 1e18;
const ll shift = 1000;
const ll block = 500;
const ll has = 200123140004043;

const ll mod = 998244353;

mt19937 srnd(chrono::steady_clock::now().time_since_epoch().count()); 

ll n, x, m, sub;
ll p[N], s[N];

ll was[N];
int main() {
    speed;
	cin >> n >> x >> m;
	p[1] = x, was[x] = 1;
	s[1] = x;
	for(int i = 2; i <= 100000; i++) {
		p[i] = p[i - 1] * p[i - 1] % m;
		s[i] = s[i - 1] + p[i];
		if(p[i] == 0) 
			cout << s[i],ex;		 	
		if(was[p[i]]) {
			ll ans = s[was[p[i]] - 1];
			ll x = n - was[p[i]] + 1;
			ll sz = i - was[p[i]];
			ll z = s[i - 1] - s[was[p[i]] - 1];			 	            	
			ll y = s[was[p[i]] + (x % sz) - 1] - s[was[p[i]] - 1];
			cout << y + ans + (x / sz) * z, ex;
		}
		was[p[i]] = i;
	}
}             
                     
 
/*
6 0
1 2 4 6 8 10
1 4  d
*/ 

Measured memory_bytes: 5200
/*ॐ नमो भगवते वासुदेवाय नमः*/
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).rend()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a, n) sort(a, a + n)
#define sortvec(V) sort(all(V))

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

typedef unordered_map<int, int, custom_hash> u_map;
typedef unordered_set<int, int, custom_hash> u_set;
typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef priority_queue<int> p_queue;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

int binpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int inverse(int x){
    return binpow(x, MOD - 2, MOD);
}

void solve()
{
    int n;
    cin >> n;
    vector<pair<int, int>>a(n);
    for(auto & i : a)   cin >> i.F >> i.S;
    for(int i = 0; i + 2 < n; i++){
        if(a[i].F == a[i].S && a[i + 1].F == a[i + 1].S && a[i + 2].F == a[i + 2].S){
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << min({a + b, b + c, c + a}) << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	n := nextInt()
	m := nextInt()
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = nextInt()
	}
	ys := make([]int, m)
	for i := 0; i < m; i++ {
		ys[i] = nextInt()
	}
	p := int(math.Pow10(9)) + 7

	var X, Y int
	for i, x := range xs {
		X += ((i * x) - ((n - (i + 1)) * x))
		X %= p
	}
	for i, y := range ys {
		Y += (i * y) - ((m - (i + 1)) * y)
		Y %= p
	}

	fmt.Println(X * Y % p)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func diff(x, y int) int {
	return abs(-(x) + y)
}

// ---------- Util.



Measured memory_bytes: 5120
_ = gets
$stdin.each_line do |line|
  a , b , c = line.split.map{|e| e.to_i}
  if a**2 + b**2 == c**2 || b**2 + c**2 == a**2 || c**2 + a**2 == b**2
    puts "YES"
  else
    puts "NO"
  end
end

Measured memory_bytes: 6112
# ABC 160 D - Line++
# https://atcoder.jp/contests/abc160/tasks/abc160_d

n, x, y = gets.chomp.split(/ /).map(&:to_i)
array = 1.upto(n).map { |i| i.times.map { Float::INFINITY } }

for i in 1..(n - 1) do
  for j in (i + 1)..n do
    array[j - 1][i - 1] = [
      j - i,
      (x - i).abs + 1 + (y - j).abs,
      # (y - i).abs + 1 + (x - j).abs
    ].min
  end
end

a_flatten = array.flatten
h = a_flatten.group_by { |i| i }

1.upto(n - 1) do |i|
  v = h[i]
  if v
    puts v.length
  else
    puts 0
  end
end


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

int main(){
  int N;
  cin>>N;
  
  for(int i=0; i<N;  i++){
    string S;
    cin>>S;
    if(S=="Y"){
      cout<<"Four"<<endl;
      return 0;
    }
  }
      cout<<"Three"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int N;
ll a[100000];
ll d[100000];
bool can(){
	cin>>N;
	rep(i,N) cin>>a[i];
	ll S=0;
	ll rm=(ll)N*(N+1)/2;
	rep(i,N) S+=a[i];
	if(S%rm!=0) return 0;
	ll num=S/rm;
	rep(i,N) d[i]=a[(i+1)%N]-a[i]-num;
	rep(i,N) if(d[i]%N!=0||d[i]>0) return 0;
	return 1;
}
int main(){
	if(can()) puts("YES");
	else puts("NO");
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n;
pair<ll,ll> g(ll a, ll x, ll p){
    if(p==1){
        ll r;
        if(a==x) r=0;
        else if(a>x) r=2;
        else r=1;
        return {a,r};
    }
    pair<ll,ll> ans=g(a,x,p/2);
    ll r=ans.second;
    if(r==2) return {-1,2};
    ll k=sqrt(x);
    ll z=ans.first;
    if(z > k){
        return {-1,2};
    }
    z*=z;
    if(p%2!=0){
        ll t=x/a;
        if(z > t) return {-1,2};
        z*=a;
    }
    if(z==x) r=0;
        else if(z>x) r=2;
        else r=1;
        return {z,r};
} 
ll f(ll st, ll end, ll x ){
    if(st > end) return -1;
    ll mid=(st+end)/2;
    ll ans=g(mid,x,n).second;
    if(ans==0) return mid;
    if(ans==1) return f(mid+1,end,x);
    return f(st,mid-1,x);
}
int main() {
        ll p;
    cin>>n>>p;
    vector<ll> v;
    for(ll i=1;i<=sqrt(p);i++){
        if(p%i==0){
            v.push_back(i);
            if(p/i != i) v.push_back(p/i);
        }
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(auto x: v){
        ll ans=f(1,x,x);
        if(ans!=-1){
            cout<<ans; return 0;
        }
    }
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) begin(n),end(n)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { 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; }

#define DEBUG

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

	cout << (n-1) * (m-1) << endl;
	return 0;
}

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

int main(){
  int a,b,c;
  int x;
  int count=0;
  cin >> a >> b >> c >> x;
  
  for(int i=0; i<=a; i++){
    for(int j=0; j<=b; j++){
      for(int k=0; k<=c; k++){
        if(500*i+100*j+50*k == x){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
/**
 * author: Dhakad@123
 **/
#include<bits/stdc++.h>
using namespace std;

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

 int  N , X; 
 cin >> N >> X;

 int L[N];

 for(int i = 0; i < N; i++){
   cin >> L[i];
   }
  int D[N+1];
  D[0] = 0;

  for(int i = 1; i <= N; i++){
       D[i] = D[i-1] + L[i-1];
    }
    int k  = 0;
    for(int i = 0; i <= N; i++){
       if(D[i] <= X){
         k++;
       }
    }
    cout << k <<"\n";
    return 0;k++;
}


Measured memory_bytes: 256
n,m,l=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=[list(map(int,input().split())) for j in range(m)]
c=[[0]*l for r in range(n)]
for i in range(n):
    for j in range(l):
        for r in range(m):
            c[i][j]+=a[i][r]*b[r][j]
    print(' '.join(map(str,c[i])))


Measured memory_bytes: 6896
n = gets.to_i
a = gets.split.map(&:to_i)
au = a.uniq.sort

if au.size == 1 && au[0] == 0
  puts "Yes"
  exit
end

if au.size == 2 && au[0] == 0 && n % 3 == 0
  if a.count(0) == 1 * n / 3
    puts "Yes"
    exit
  end
end

if au.size != 3 || n % 3 != 0
  puts "No"
  exit
end

cnt = Hash.new(0)
a.each do |ai|
  cnt[ai] += 1
end

if cnt.values.uniq.count != 1
  puts "No"
  exit
end

[0, 1, 2].combination(2) do |i, j|
  i, j = j, i if i > j
  k = (3 - ((i + j) % 3)) % 3
  if au[i] ^ au[j] != au[k]
    puts "No"
    exit
  end
end

puts "Yes"


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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC   
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

const ll MOD = (ll)1e9+7; //change it for other mods

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

void solve(ll testnum)
{
    ll n,k;
    cin >> n >> k;
    vll a(n+1), c(n+1, 0);
    for(ll i=1;i<=n;i++) {
    	cin >> a[i];
    }
    vll pos;
    pos.pb(1);
    c[1] = 1;
    ll temp = a[1];
    while(c[temp] != 1) {
    	pos.pb(temp);
    	// cout << temp << "\n";
    	c[temp] = 1;
    	temp = a[temp];
    }
    ll start = 0;
    for(ll i=0;i<pos.size();i++) {
    	if(pos[i] == temp) {
    		start = i;
    		break;
    	}
    }
    if(k <= start) {
    	cout << pos[k] << "\n";
    } else {
    	k -= start;
    	cout << pos[start + k%(pos.size()-start)] << "\n";
    }
}

int main()
{
    FAST_IO;
    #ifdef STIO 
      freopen("input.txt" , "r", stdin);
      freopen("output.txt" , "w", stdout);
    #endif
    ll t = 1;
    // cin >> t;
    for (ll i = 1; i <= t; i++) {
        solve(i);
    }
}

Measured memory_bytes: 8460
import collections

n=int(input())

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

X=collections.Counter(A)
K=list(X.keys())
V=list(X.values())
cnt=0
for i in range(len(X)):
    if K[i]>V[i]:
        cnt+=V[i]
    elif K[i]<V[i]:
        cnt+=V[i]-K[i]

print(cnt)

Measured memory_bytes: 18668
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(ll i=a ; i<b; i++)
int main()
{ ll n; cin>>n; ll a[n]; f(i,0,n) { cin>>a[i]; } ll dp[n]; dp[0]=0; dp[1]=abs(a[1]-a[0]); 
f(j,2,n) { dp[j]=min(dp[j-1]+abs(a[j]-a[j-1]),dp[j-2]+abs(a[j]-a[j-2])); } 
cout<<dp[n-1]; 


}

Measured memory_bytes: 5152