akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
a = gets.split.map(&:to_i)
cnt = Array.new(100001, 0)
a.each do |i|
  cnt[i] += 1
end
s = a.sum

gets.to_i.times do
  b, c = gets.split.map(&:to_i)
  if cnt[b] > 0
    s -= cnt[b] * b
    s += cnt[b] * c
    cnt[c] += cnt[b]
    cnt[b] = 0
  end
  puts s
end


Measured memory_bytes: 22172
import numpy as np
    
INF = float('inf')

n,A,B,C = [int(i) for i in input().split()]

l = [int(input()) for i in range(n)]

def dfs(cur, a, b, c):
    
    if cur == n:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a,b,c) > 0 else INF
    
    ret0 = dfs(cur+1, a, b, c)
    ret1 = dfs(cur+1, a+l[cur], b, c) + 10
    ret2 = dfs(cur+1, a, b+l[cur], c) + 10
    ret3 = dfs(cur+1, a, b, c+l[cur]) + 10

    return min(ret0, ret1, ret2, ret3)


print(dfs(0,0,0,0))


Measured memory_bytes: 12400
using System;

namespace Sample101
{
    class Program
    {
        private static int findSumOfDigits(int n)
        {
            int sum = 0;
            while (n > 0)
            {
                sum += n % 10;
                n /= 10;
            }
            return sum;
        }

        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int A = int.Parse(str[1]);
            int B = int.Parse(str[2]);

            int result = 0;
            // 1以上N以下
            for (int i = 1; i <= N; ++i)
            {
                // 各桁の和
                int sum = findSumOfDigits(i);
                if (A <= sum &&
                    sum <= B)
                {
                    result += i;
                }
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 11220
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<deque>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int sum[100010];
bool ok[100010];
bool isp[100010];

void func()
{
	isp[0] = isp[1] = true;
	for(int i = 2;i < 10000;i++)
	{
		if(!isp[i])
		{
			for(int j = 2*i;j < 100010;j += i)isp[j] = true;
		}
	}
	
	for(int i = 1;i < 100010;i++)
	{
		if(!isp[i] && !isp[(i+1)/2])ok[i] = true;
	}
	
	for(int i = 1;i < 100010;i++)
	{
		sum[i] = sum[i-1];
		if(ok[i])sum[i]++;
	}
	
}

int main()
{
	func();
	
	int q;cin >> q;
	
	REP(i,q)
	{
		int a,b;cin >> a >> b;
		printf("%d\n",sum[b] - sum[a-1]);
	}
	
	return 0;
}

Measured memory_bytes: 1280
while 1:
    k=input().split()
    a=int(k[0])
    b=int(k[1])
    c=int(k[2])
    if a==-1 and (b==-1 and c==-1):
        break
    if a<0 or b<0:
        print("F")
    elif a+b<30:
        print("F")
    elif a+b<50:
        if c>=50:
            print("C")
        else:
            print("D")
    elif a+b<65:
        print("C")
    elif a+b<80:
        print("B")
    else:
        print("A")



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int a[25];
	int ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=1;i+1<n;i++){
		int t1=min(a[i],min(a[i-1],a[i+1]));
		int t2=max(a[i],max(a[i-1],a[i+1]));
		if(a[i]!=t1&&a[i]!=t2)
			ans++;
	}
	printf("%d\n",ans);
}

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

#define ll long long
int ar[100005];

int main()
{
    ll a,b,c,d,e;
    string s1,s2;
    cin>>s1;
    if(s1[0]=='7'||s1[1]=='7'||s1[2]=='7')
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, a[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> a[i];
  sort(a, a+n);
  int d = a[n-1]-a[0];
  FOR(i, 1, n-1) d += abs(a[i]);
  cout << d << endl;
  d = lower_bound(a, a+n, 1)-a;
  maxs(d, 1);
  mins(d, n-1);
  int c = a[d-1];
  FOR(i, d, n-1){
    cout << c << " " << a[i] << endl;
    c -= a[i];
  }
  cout << a[n-1] << " " << c << endl;
  c = a[n-1]-c;
  FOR(i, 0, d-1){
    cout << c << " " << a[i] << endl;
    c -= a[i];
  }
}

Measured memory_bytes: 2304
N,M=gets.chomp.split.map(&:to_i)

redges=Array.new(N){Array.new}
M.times do
  u,v=gets.chomp.split.map(&:to_i)
  redges[v-1] << u-1
end

s,t=gets.chomp.split.map(&:to_i)
S,T=s-1,t-1
canGo=Array.new(N){Array.new(3,-1)}
queue=[[T,0]]


while queue.size!=0
  to,count=queue.shift
  if canGo[to][count%3]!=-1
    next
  end
  canGo[to][count%3]=count
  redges[to].each do |toto|
    queue << [toto,count+1]
  end
end

puts canGo[S][0]!=-1 ? canGo[S][0]/3 : -1


Measured memory_bytes: 15996
#include<iostream>
using namespace std;
int main(){
  int N, flag=0, cnt=0; cin >> N;
  long long A[N];
  for(int i=0; i<N; i++){
    cin >> A[i];
    if(A[i] == 0){
      flag = 1;
    }
    if(A[i] < 0) cnt += 1;
  }
  
  if(cnt%2 == 0) flag = 1;

  long long  min = labs(A[0]);
  for(int i=1; i<N; i++) if(labs(A[i]) < min) min = labs(A[i]);
  long long ans=0;
  for(int i=0; i<N; i++){
    ans += labs(A[i]);
  }
  if(flag == 0) ans -= 2 * min;
  cout << ans << endl;
  
  return 0;
  
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
string solve(){
  string ok="POSSIBLE", no="IMPOSSIBLE";
  int n;  ll k;
  cin >> n >> k;
  vector<ll> v(n);
  rep(i,0,n){
    cin >> v[i];
  }
  rep(i,0,n) if(v[i]==k) return ok;
  sort(all(v));
  ll ma = v[n-1];
  if(k>ma)return no;
  ll g = 0;
  rep(i,0,n){
    g = gcd(g, v[i]);
  }
  if(k%g==0) return ok;
  return no;
}
int main(){
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cstdio>
#include <functional>   //greater
using namespace std;

long long int MOD = 998244353;

int N;
long long int x[200005], y[200005];

map<pair<long long int, long long int>, int > ID;

vector<pair<long long int,long long int> > V;

multiset<long long int> S[2][2];

long long int num[200005][5];

vector<long long int > VX,VY;

map<long long int, int> proj_X, proj_Y;

int B[500000];

void UPDATE(int i, int k) {

	while(i<=N){
		B[i] += k;
		i = i + (i&(-i));
	}
}

int SUM(int i) {

	int ret = B[i];

	while (i > 0) {
		i = i - (i&(-i));
		ret += B[i];
	}

	return ret;
}

long long int INF = 99999999999999;

int X_p[200005], X_m[200005], Y_p[200005], Y_m[200005];

long long int p[200005];

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> x[i] >> y[i];
		ID[make_pair(x[i], y[i])] = i;
		VX.push_back(x[i]);
		VY.push_back(y[i]);
		V.push_back(make_pair(x[i], y[i]));
	}

	VX.push_back(-INF);
	VY.push_back(-INF);

	sort(VX.begin(), VX.end());
	sort(VY.begin(), VY.end());


	for (int i = 1; i <= N; i++) {
		proj_X[VX[i]] = i;
		proj_Y[VY[i]] = i;
	}

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

	for (int i = 0; i < N; i++) {
		int id = ID[V[i]];
		long long int X = V[i].first;
		long long int Y = V[i].second;

		num[id][3] = SUM(proj_Y[Y] - 1);
		num[id][2] = SUM(N) - SUM(proj_Y[Y]);

		UPDATE(proj_Y[Y], 1);
	}


	//======================
	V.clear();

	for (int i = 0; i <= N; i++) {
		B[i] = 0;
	}

	for (int i = 1; i <= N; i++) {
		V.push_back(make_pair(-x[i], y[i]));
	}

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

	for (int i = 0; i < N; i++) {
		long long int X = -V[i].first;
		long long int Y = V[i].second;
		int id = ID[make_pair(X, Y)];

		num[id][4] = SUM(proj_Y[Y] - 1);
		num[id][1] = SUM(N) - SUM(proj_Y[Y]);

		UPDATE(proj_Y[Y], 1);
	}

	//===============================


	for (int i = 1; i <= N; i++) {
		X_p[i] = VX.end() - upper_bound(VX.begin(), VX.end(), x[i]);
		X_m[i] = lower_bound(VX.begin(), VX.end(), x[i])-1 - VX.begin();
		Y_p[i] = VY.end() - upper_bound(VY.begin(), VY.end(), y[i]);
		Y_m[i] = lower_bound(VY.begin(), VY.end(), y[i]) - 1 - VY.begin();
	}

	
	/*for (int i = 1; i <= N; i++) {
		cout << i << " X_p= " << X_p[i] << " X_m= " << X_m[i] << " Y_p= " << Y_p[i] << " Y_m= " << Y_m[i];
		for (int j = 1; j <= 4; j++) { cout << " num[" << j << "]= " << num[i][j]; }
		cout << endl;
	}*/

	long long int ans = 0;

	p[0] = 1;
	
	for (int i = 1; i <= N; i++) {
		p[i] = p[i - 1] * 2;
		p[i] %= MOD;
	}

	for (int i = 1; i <= N; i++) {
		ans += p[N - 1];
		//cout << "ans= " << ans << endl;
		ans %= MOD;
		long long int tmp = 0;
		tmp += p[X_p[i]] - 1 + MOD;
		tmp %= MOD;
		tmp += p[X_m[i]] - 1 + MOD;
		tmp %= MOD;
		tmp += p[Y_p[i]] - 1 + MOD;
		tmp %= MOD;
		tmp += p[Y_m[i]] - 1 + MOD;
		tmp %= MOD;
		for (int j = 1; j <= 4; j++) {
			tmp += -(p[num[i][j]] - 1) + MOD;
			tmp %= MOD;
		}

		ans += p[N - 1] - 1 - tmp + MOD;
		ans %= MOD;
		//cout << "ans= " << ans << endl;
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
	int n;
	cin >> n;
	string s1;
	cin >> s1;
	int len = s1.size();
	for(int i=0;i<len;i++){
		if(s1[i] + n >= 91){
			printf("%c",'A'+(s1[i] + n) % 91);
		}
		else
			printf("%c",s1[i] + n);
	}
	return 0;
} 

Measured memory_bytes: 384
a, b, k = map(int, input().split())

if b - a + 1 < k * 2:
    for i in range(a, b+1):
        print(i)
else:
    for i in range(a, a+k):
        print(i)

    for i in range(b-k+1, b+1):
        print(i)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    string s;
    cin >> s;
    int zero = 0;
    int one = 0;
    rep(i,s.length()){
        if(s[i] == '0')zero++;
        else one ++;
    }
    cout << 2*min(zero,one) << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

ans = ""

ans += "U" * (ty - sy) + "R" * (tx - sx)
ans += "D" * (ty - sy) + "L" * (tx - sx)
ans += "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "D"
ans += "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) + "U"
print(ans)

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    LL cnt[5] = {0, 0, 0, 0, 0};
    inc(i, 0, n){
        string s;cin >> s;
        switch(s[0]){
            case 'M':cnt[0]++;break;
            case 'A':cnt[1]++;break;
            case 'R':cnt[2]++;break;
            case 'C':cnt[3]++;break;
            case 'H':cnt[4]++;break;
        }
    }
    LL ans = 0;
    vector<bool> v = {0, 0, true, true, true};
    do{
        LL a = 1;
        inc(i, 0, 5){
            if(v[i]){
                a *= cnt[i];
            }
        }
        ans += a;
    }while(next_permutation(v.begin(), v.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;
 
class Main {
 
    public static void main(String[] args) {
        new Main().compute();
    }
 
    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        for (int i = 0; i < N; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        long min = Long.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int k = 0; k < N; k++) {
                    for (int l = 0; l < N; l++) {
                        int contain = 0;
                        for (int m = 0; m < N; m++) {
                            if (x[i] <= x[m] && x[j] >= x[m] && y[k] <= y[m] && y[l] >= y[m]) {
                                contain++;
                            }
                            if (contain >= K) {
                                min = Math.min(min, (long)(x[j] - x[i]) * (y[l] - y[k]));
                            }
                        }
                    }
                }
            }
        }
        System.out.println(min);
    }
}

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

int n;
char c[100];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> c[i];
	
	for (int i = 0; i < n; i++) {
		if (c[i] == 'Y') {
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import product

H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]

p1 = list(product([False, True], repeat=H))
p2 = list(product([False, True], repeat=W))
ans = 0

for i in range(len(p1)):
    for j in range(len(p2)):
        count = 0
        for a in range(H):
            for b in range(W):
                if C[a][b] == "#" and not p1[i][a] and not p2[j][b]:
                    count += 1
        if count == K:
            ans += 1
print(ans)

Measured memory_bytes: 9192
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	int a, b;
	cin >> a >> b;
	cout << ((a + b) % 24) << endl;
	return 0;
}


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

int n, k;

int main() {
    scanf("%d %d", &n, &k);
    long ans = 0;
    
    if (k > 0) {
        for (int i = k + 1; i <= n; i++) {
            ans += static_cast<long>(n / i) * (i - k);
            ans += max(n % i - k + 1, 0);
        }
    }
    else {
        ans = static_cast<long>(n) * (n);
    }

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


Measured memory_bytes: 128
import Data.List

parsePair :: IO (Int, Int)
parsePair = do
    [a,b] <- (map read . words) <$> getLine :: IO [Int]
    return (a,b)

main = do
    (n,m) <- parsePair
    pairList <- sequence $ replicate n parsePair :: IO [(Int,Int)]
    let sorted = sortBy (\x y -> compare (fst x) (fst y)) pairList
    print $ solve m 0 sorted


solve :: Int -> Int -> [(Int,Int)] -> Int
solve rest ac ((p,n):xs) = do
        if n >= rest
            then (ac + p*rest)
            else do
                solve (rest - n) (ac + p*n) xs

Measured memory_bytes: 75132
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
struct island{
	int x, y;
}a[maxn];
int cmp(island a, island b)
{
	return a.y<b.y;
}
int main()
{
	int n, m, ans=0;
	cin >> n >> m;
	for(int i=1;i<=m;i++)cin >> a[i].x >> a[i].y;
	sort(a+1,a+m+1,cmp);
	int t=0;
	for(int i=1;i<=m;i++)
	{
		if(a[i].x>=t)
		{
			t=a[i].y;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#coding:utf-8

n,m = map(int,input().split())
List = list(map(int,input().split()))

class UnionFind3:
    def __init__(self, size):
        # 負の値はルート (集合の代表) で集合の個数
        # 正の値は次の要素を表す
        self.table = [-1 for i in range(size)]

    # 集合の代表を求める
    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    # 併合
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                # 小さいほうが個数が多い
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return 1
        return 0


cnt = 0
tree = UnionFind3(n)
for i in range(m):
    x,y = map(int,input().split())
    tree.union(x-1,y-1)

for i in range(n):
    a = tree.find(i)
    b = tree.find(List[i]-1)
    if a == b:
        cnt += 1

print(cnt)


Measured memory_bytes: 14008
import Foundation
 
let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")
 
let a = Int(split[0])!
let b = Int(split[1])!
let c = Int(split[2])!

if (a+b==c || a+c==b || b+c==a){
    print("Yes")
}else{
    print("No")
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int mina = INT_MAX;
	int maxa = 0;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		mina = min(mina, a);
		maxa = max(maxa, a);
	}
	cout << maxa - mina << endl;
	return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  string s; readV(s);

  auto a = new int[](n);
  foreach (i; 0..n) a[i] = s[i] == 'E';
  auto b = cumulativeSum(a);

  auto m = n;
  foreach (i; 0..n)
    m = min(m, (i-b[0..i])+b[i+1..$]);

  writeln(m);
}

class CumulativeSum(T)
{
  size_t n;
  T[] s;

  this(T[] a)
  {
    n = a.length;
    s = new T[](n+1);
    s[0] = T(0);
    foreach (i; 0..n) s[i+1] = s[i] + a[i];
  }

  T opSlice(size_t l, size_t r) { return s[r]-s[l]; }
  size_t opDollar() { return n; }
}
auto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }


Measured memory_bytes: 4440
#include<bits/stdc++.h>
#define N 1001
using namespace std;
#define int long long
string mp[N];
int h;



int dx[] = {-1,0,1};
int calc(int lx,int y){
  int rx = lx;
  
  mp[y][lx] = ' ';
  while(rx+1<mp[y].size()&&mp[y][rx+1]=='*')mp[y][++rx] = ' ';
  int res = rx - lx + 1;
  while(1){
    if(mp[y][lx+1]=='*')break;
    y++;
    int nrx,nlx; 
    for(int i=-1;i<=1;i++)
      if(rx+i>=0 && rx+i<mp[y].size()&&mp[y][rx+i]=='*') nrx = rx+i;

    for(int i=1;i>=-1;i--)
      if(lx+i>=0&&lx+i<mp[y].size()&&mp[y][lx+i]=='*') nlx = lx+i;

    rx = nrx,lx = nlx;
    mp[y][rx] = mp[y][lx] = ' ';
    res += rx-lx + 1;
  }
  for(int i=lx;i<=rx;i++)mp[y][i] = ' ';
  return res;
}

signed main(){
  int cnt = 0;
  while(1){

    
    cin>>h;
    if(!h) break;
    if(cnt++)cout<<"----------"<<endl;
    cin.ignore();
    for(int i=0;i<h;i++)getline(cin,mp[i]);
    
    map<int,int> ans;
    for(int i=0;i<h;i++)
      for(int j=0;j<mp[i].size();j++)
	if(mp[i][j] == '*')ans[calc(j,i)]++;

    for(auto it=ans.begin();it!=ans.end();it++) cout<< it->first<<" "<<it->second<<endl;
    
  }
  return 0;
}

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

int main(){
  int n,i,rw,wr;
  string s;
  cin >> n >> s;
  
  wr=0;
  rw=0;
  for(i=0;i<n;i++){
    if(s.at(i)=='R'){
      rw++;
    }
  }
  int m=max(rw,wr);
  for(i=0;i<n;i++){
    if(s.at(i)=='R'){
      rw--;
    }else{
      wr++;
    }
    m=min(m,max(wr,rw));
  }
  cout << m << endl;
}

Measured memory_bytes: 3748
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_c

# B*A,*A,B*,*の4つに分類される。
# *に関しては事前に全部カウントしておけば良い
# B*A同士で作ったほうが有利(個数-1増える)
# *A,B*は 少ない方の個数増える
# 後者2つはコーナーケースに注意(つまり、B*Aがデータセットにある場合はさらに+1できる)(消化しきれない場合)

N = int(input())
base = 0
b_ = 0
_a = 0
b_a = 0
for _ in range(N):
    s = read()[:-1]
    if s.startswith('B') and s.endswith('A'):
        b_a += 1
    elif s.startswith('B'):
        b_ += 1
    elif s.endswith('A'):
        _a += 1
    base += s.count('AB')

ans = base
if b_a:
    ans += b_a - 1

if b_ and b_a:
    ans += 1
    b_ -= 1  # b_aの端に結合

if _a and b_a:
    ans += 1
    _a -= 1  # b_aの端に結合

ans += min(b_, _a)
print(ans)


# print(base + b_a + min(b_, _a) + (-1 if b_ == _a and b_a > 0 else 0))
# バグってる
# ちゃんとやるか
# print(base, b_a, b_, _a)


Measured memory_bytes: 39920
import java.util.Scanner;

public class Main {

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

		int A = scan.nextInt();
		int B = scan.nextInt();
		
		if(A == B){
			System.out.println("Draw");
		}else if(A == 1){
			System.out.println("Alice");
		}else if(B == 1){
			System.out.println("Bob");
		}else if(A > B){
			System.out.println("Alice");
		}else{
			System.out.println("Bob");
		}

	}

}

Measured memory_bytes: 22868
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = new int[](n);
  foreach (i; 0..n) {
    a[i] = readln.chomp.to!int;
  }
  auto a2 = a.dup;
  a2.sort!((a,b)=>a > b);
  foreach (i; 0..n) {
    if (a[i] == a2[0]) {
      writeln(a2[1]);
    } else {
      writeln(a2[0]);
    }
  }
}


Measured memory_bytes: 5756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

void no(){
    cout<<"UNRESTORABLE"<<endl;
}

int main(){fastio
    string s,t;cin>>s>>t;
    ll ls=s.size(),lt=t.size();
    if(ls<lt){no();return 0;}
    for(ll i=ls-lt;i>=0;i--){
        bool flag=true;
        rep(j,i,i+lt-1){
            if(s[j]!=t[j-i]&&s[j]!='?')flag=false;
        }
        if(flag){
            //cout<<i<<endl;
            rep(j,i,i+lt-1){
                s[j]=t[j-i];
            }
            rep(j,0,ls-1){
                if(s[j]=='?')s[j]='a';
            }
            cout<<s<<endl;return 0;
        }
    }
    no();
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int a[n], c[h][w];
    rep(i, n) {
        cin >> a[i];
    }

    int s = h*w;
    int y[s], x[s];
    rep(i, h) {
        rep(j, w) {
            y[i*w+j] = i;
        }
    }
    rep(i, s) {
        int m = i%(2*w);
        if(m < w) {
            x[i] = m;
        }
        else {
            x[i] = (2*w - 1) - m;
        }
    }

    int k = 0;
    rep(i, n) {
        for(int j = k; j < k + a[i]; j++) {
            c[y[j]][x[j]] = i+1;
        }
        k += a[i];
    }
    
    rep(i, h) {
        rep(j, w) {

            cout << c[i][j];
            
            if(j == w-1) {
                cout << "\n";
            }
            else {
                cout << " ";
            }
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <algorithm> 
using namespace std;
int main() {
	string a, b;
	cin>>a>>b;
	a+=b;
	int result=0;
	stringstream ss;
	ss<<a;
	ss>>result;
	if(result==(int)sqrt(result)*(int)sqrt(result)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 760
#include<iostream>
#define MAX_VALUE 10^5 + 1
typedef long long ll;
using namespace std;
bool prime(int p_a){
    for(int i=2; i*i<=p_a; i++){
        if(p_a % i == 0)
            return false;
    }
    return (p_a != 1);
}
int main(){
    int a;
    cin >> a;
    while(1){
        if(prime(a)) break;
        a++;
    }
    cout << a << "\n";
    return 0;
}

Measured memory_bytes: 256
a,b= list(map(int,input().split()))

c,d = list(map(int,input().split()))
time = int(input())
if b <= d:
    print("NO")
else:
    dis = abs(a-c)
    ans = dis/(b-d)
    if ans <= time:
        print("YES")
    else:
        print("NO")
    
    

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

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int a,b,c,k;
  cin>>a>>b>>c>>k;
  int sum=0;

  while(k>0) {
    if(a>0) {
      sum+=min(a,k);
      int val=min(a,k);
      a-=val;
      k-=val;
    } else if(b>0) {
      int val=min(b,k);
      b-=val;
      k-=val;
    } else {
      sum-=min(c,k);
      int val=min(c,k);
      c-=val;
      k-=val;
    }
  }

  cout<<sum;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(void)
{
        int x1,x2,y1,y2;
        scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
        int a=y1-x1, b=y2-x2;
        printf("%d %d %d %d",y1-b,y2+a,x1-b,x2+a);
        return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin

FORMAT = ('node {0.id}: parent = {0.parent}, sibling = {0.sibling}, '
          'degree = {0.degree}, depth = {0.depth}, height = {0.height}, '
          '{0.type}').format


class Node(object):
    def __init__(self, data):
        self.id = data[0]
        self.parent = -1
        self.sibling = -1
        self.degree = int(data[1] >= 0) + int(data[2] >= 0)
        #self.childs = [i for i in data[1:] if i > 0]
        self.childs = data[1:]
        self.depth = 0
        self.height = -1
        self.type = 'internal node' if self.degree else 'leaf'

    def __str__(self):
        return FORMAT(self)


def calc_depth(tree, i):
    h = 0
    for k, j in enumerate(tree[i].childs):
        if j >= 0:
            tree[j].depth += 1
            tree[j].sibling = tree[i].childs[1-k]
            h = max(h, calc_depth(tree, j))
    if tree[i].type == 'leaf':
        tree[i].height = 0
    else:
        tree[i].height = h
    return tree[i].height + 1


n = int(stdin.readline())
tree = [-1] * n

for _ in range(n):
    node = Node([int(s) for s in stdin.readline().split()])
    parent = tree[node.id]
    tree[node.id] = node
    if isinstance(parent, int):
        tree[node.id].parent = parent
    else:
        tree[node.id].parent = parent.id
    for i in node.childs:
        if i >= 0:
            if isinstance(tree[i], int):
                tree[i] = node.id
            else:
                tree[i].parent = node.id

for i in range(n):
    calc_depth(tree, i)

for node in tree:
    if node.parent == -1:
        node.type = 'root'
    print(node)

Measured memory_bytes: 4296
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <set>
#include <limits.h>
#include <queue>

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define MOD 1000000007

using ll = long long;

using namespace std;

ll pow_mod(ll a, ll b, ll p) {
	if (b == 0)return 1;
	else if (b % 2 == 0)return (pow_mod(a*a, b / 2, p) % p);
	else return (pow_mod(a, b - 1, p)*a%p);
}

ll sum_digit(ll N) {
	int ans = 0;
	for (; N != 0;) {
		ans += N % 10;
		N /= 10;
	}
	return ans;
}

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

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

int A, B;

int main(){
	scanf("%d %d", &A, &B);
	if ((A % 2) && (B % 2))printf("Yes");
	else printf("No");
	return 0;
}

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

int main(){
  int N,M; cin>>N>>M;
  int sum=0;
  map<int,int> mp;
  rep(i,N){
    int A; cin>>A;
    (sum+=A)%=M;
    mp[sum]++;
  }
  ll ans=0;
  for(auto m:mp){
    if(m.first==0) ans+=m.second;
    ans+=1LL*m.second*(m.second-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    string s; cin >> s;
    string ans = "";
    for(int i=0;i<s.size();i++){
        if(s[i] == '0') ans.push_back('0');
        else if(s[i] == '1') ans.push_back('1');
        else {
            if(ans!="") ans.erase(ans.begin()+ans.size()-1);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func srarch(v int, a []int) (int, int) {
	c := v / 2
	l := 0
	r := len(a) - 1
	for l+1 != r {
		m := (l + r) / 2
		if a[m] < c {
			l = m
		} else {
			r = m
		}
	}
	return a[l], a[r]
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	n := getInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
	sort.Ints(a)

	m := a[len(a)-1]
	//out(a)
	x, y := srarch(m, a)

	if m == y {
		out(m, x)
		return
	}

	if asub(x*2, m) < asub(y*2, m) {
		out(m, x)
	} else {
		out(m, y)
	}
}


Measured memory_bytes: 3072
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,y = na()
ans = [-1,-1,-1]
for i in range(n+1):
  for j in range(n-i+1):
    a = 10000*i + 5000*j + 1000*(n-i-j)
    if a == y:
      ans = [i,j,n-i-j]

print(ans[0],ans[1],ans[2])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n;
	cin >> n;
	int a[n];
	forr(i,n) cin >> a[i];
	if(is_sorted(a,a+n)) {cout << "YES"; return 0;}
	for(int i = 0 ; i < n; i++){
		for(int j = i + 1; j < n; j ++){
			swap(a[i],a[j]);
			if(is_sorted(a,a+n)){
				cout << "YES";
				return 0;
			}
			swap(a[i],a[j]);
		}
	}
	cout << "NO";

}

Measured memory_bytes: 3648
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let v: Vec<u32> = buf
        .trim()
        .chars()
        .map(|x| x.to_digit(10).unwrap())
        .collect();
    let ans: u32 = std::cmp::max(v.iter().sum(), v[0] + v.len() as u32 * 9 - 10);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ck(i, x) ((i) >= 0 && (i) < (x))
using namespace std;
int w, h;
int area[51][51];
int dx[] = {-1,0,1}, dy[] = {-1,0,1};
void dfs(int y, int x){
  area[y][x] = 0;
  //  printf("%d %d\n", y, x);
  rep(i, 3) rep(j, 3)
    if(ck(y+dy[i], h) && ck(x+dx[j], w) && area[y+dy[i]][x+dx[j]]) dfs(y+dy[i], x+dx[j]);

  return;
}
int main(){
  while(scanf("%d%d", &w, &h) && w && h){
    //    printf("in area\n");
    rep(i, h) rep(j, w) scanf("%d", &area[i][j]);
    int cnt = 0;
    //    puts("start solve");
    rep(i, h) rep(j, w) if(area[i][j]) dfs(i, j), cnt++;
    //    puts("end solve");
    printf("%d\n", cnt);
  }
  return 0;
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    if (N & 1) {
        cout << 0 << endl;
        return 0;
    }
    ll ans1 = 0, ans2=0;
    ll tmp = N;
    while (tmp > 0) {
        ans1 += tmp /= 2;
    }
    tmp = N;
    ans2 +=  N / 10;
    tmp /=10;
    while (tmp > 0) {
        ans2 += tmp /= 5;
    }
    cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 256
n = int(input())
ns = list(map(int, input().split()))
c = [None for i in range(n)]
c[0] = 0
c[1] = abs(ns[1]-ns[0])
for i in range(2, n):
    c[i] = min(c[i - 2] + abs(ns[i - 2] - ns[i]), c[i - 1] + abs(ns[i - 1] - ns[i]))
print(c[-1])

Measured memory_bytes: 52720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=5e3+5;
ll gcd(ll a,ll b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
    int k;
    cin>>k;
    ll sum=0;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=k;j++)
        {
            for(int x=1;x<=k;x++)
            {
                sum+=gcd(i,gcd(j,x));
            }
        }
    }
    cout<<sum<<'\n';



}

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

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

    int A;
    for (int i = 0; i < N; ++i) {
        std::cin >> A;
    }    

    int ans = (N - 1) / (K - 1) + 1;
    if ((N - 1) % (K - 1) == 0) {
        ans -= 1;
    }

    std::printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int number[] = new int[n];
        int mini = Integer.MAX_VALUE;
        int count = 0;

        for(int i = 0; i < n;i++) number[i] = scan.nextInt();
        scan.close();

        for(int j = 0; j < n;j++){
            mini = Math.min(mini,number[j]);
            if(mini >= number[j]) count++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 85468
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int k = sc.nextInt();
		int q = sc.nextInt();
		
		int[] player = new int[n+1];
		Arrays.fill(player, k);
		
		for (int i = 0; i < q; i++) {
			int getScore = sc.nextInt();
			player[getScore]++;
		}
		
		for (int i = 1; i <=n; i++) {
			int result = player[i] - q;
			if (result > 0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
		
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


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

int main() {
    string A, s, C;
    cin >> A >> s >> C;

    cout << A.at(0) << s.at(0) << C.at(0) << endl;

    return 0;
}

Measured memory_bytes: 256
s=input()
c="CODEFESTIVAL2016"
#print(s)
#print(c)
count = 0
for i in range(16):
	if( s[i:i+1] != c[i:i+1] ):
#		print(s[i:i+1])
#		print(c[i:i+1])
		count += 1
print(count)

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi d(n);
    rep(i, n) cin >> d[i];
    ll sum = 0;
    rep(i, n) for (int j=i+1; j<n; ++j) {
        sum += d[i] * d[j];
    }
    cout << sum <<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    int a,b,c;
    cin>>a>>b>>c;

    bool ans=false;

    if(a==b && a!=c){
        ans=true;
    }
    if(a==c && a!=b){
        ans=true;
    }
    if(b==c && b!=a){
        ans=true;
    }

    if(ans){
        cout<<"Yes"<<endl;

    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
//46
#include<iostream>

using namespace std;

void r(int *d,int a,int b,int c,int dd){
  int t=d[a];
  d[a]=d[b];
  d[b]=d[c];
  d[c]=d[dd];
  d[dd]=t;
}

int main(){
  for(int n;cin>>n,n;){
    int d[]={1,2,3,4,5,6};
    while(n--){
      char c[6];
      cin>>c;
      if(c[0]=='n'){
	r(d,0,4,5,1);
      }else if(c[0]=='s'){
	r(d,0,1,5,4);
      }else if(c[0]=='e'){
	r(d,0,2,5,3);
      }else{
	r(d,0,3,5,2);
      }
    }
    cout<<d[0]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int n = Integer.valueOf(sc.next());
        Integer[] ai = new Integer[n];
        for(int i=0; i<n; i++){
            ai[i] = sc.nextInt();
        }
        Arrays.sort(ai ,Comparator.reverseOrder());
        int alice = 0;
        int bob = 0;
        for(int i=0; i < ai.length; i=i+2) {
            alice += ai[i];
        }
        for(int j=1; j< ai.length; j=j+2) {
            bob += ai[j];
        }
        System.out.println(alice - bob);
        sc.close();
    }       
}

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

int main() {
	string a,b;cin>>a>>b;
	string s;
	int c=0,d=0;
	rep(i,a.size()+b.size()){
		if(i%2==0)s+=a[c++];
		else s+=b[d++];
	}
	cout<<s<<endl;
}


Measured memory_bytes: 256
N = int(input())
v = list(map(int, input().split()))
v.sort(reverse=True)
s = 0

for n in range(N):
    if n != N-1:
        s += v[n] / (2 ** (n+1))
    else :
        s += v[n] / (2 ** n)

print(s)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
const int maxn=2e5+5;
int n,a[maxn];
vector<int> g[maxn];
signed main(){
	n=read();
	for(int i=2;i<=n;i++){
		a[i]=read();
		g[a[i]].push_back(i);
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",g[i].size());
	}
	return 0;
}


Measured memory_bytes: 15420