akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.BigInteger;
public class Main
{
    public static void main(String[]args)
    {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Solver solver = new Solver();
        int ca = 1;
        solver.solve(ca,in,out);
        out.close();
    }
    static class Solver
    {

        public void solve(int ca,InputReader in,PrintWriter out)
        {
            while(ca -- != 0)
            {
                int n = in.nextInt();
                int a[] = new int[n];
                int b[] = new int[n];
                int d[] = new int[n];
                for(int i = 0;i<n;i++) a[i] = in.nextInt();
                for(int i = 0;i<n;i++) b[i]= in.nextInt();
                long sum =  0;
                int ans = 0;
                for(int i =  0;i<n;i++)
                {
                    d[i] = a[i] - b[i];

                    if(b[i] > a[i])
                    {
                        ans++;
                        sum += b[i] - a[i];
                    }
                }
                Arrays.sort(d);
                for(int i =  n-1;i >= 0;i--)
                {
                    if(sum == 0) break;
                    if(sum < d[i])sum = 0;
                    else sum -= d[i];
                    ans++;
                }
                if(sum != 0) out.println(-1);
                else out.println(ans);

            }
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
        public BigInteger nextBigInteger()
        {
            return new BigInteger(next());
        }

    }
}

Measured memory_bytes: 44428
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    ans = 0

    d = Counter()
    for i in range(N+1):
        l = len(str(i))
        a = i // 10 ** (l-1)
        b = i % 10
        if a != 0 and b != 0:
            d[(a, b)] += 1

    ans = 0
    for a, b in product(range(1, 10), repeat=2):
        ans += d[(a, b)] * d[(b, a)]
    return ans


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61928
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD (int)1e9+(int)7
#define INF 2147483647
typedef long long ll;
typedef unsigned long long ull;
//dark power
//#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
//komennto C+udekaijo

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n=0,m=0;cin>>n>>m;
	int k=0;
	int num=0;
	vector<int> likes(m,0);
	rep(i,n){
		cin>>k;
		rep(j,k){
			cin>>num;
			likes[num-1]++;
		}
	}
	int ans=0;
	rep(i,m)ans+=!!(likes[i]==n);
	cout<<ans<<endl;

	return 0;
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

bool check(int H, int W, int x, int y){
    return 0 <= x && x < H && 0 <= y && y < W;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H, W; cin >> H >> W;
    int sx, sy; cin >> sx >> sy; sx--; sy--;
    int gx, gy; cin >> gx >> gy; gx--; gy--;
    priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;
    string grid[H];
    rep(i, H) cin >> grid[i];
    int dist[H*W]; rep(i, H*W) dist[i] = mod;
    dist[sx*W + sy] = 0;
    pq.push(make_pair(0, make_pair(sx, sy)));
    while(!pq.empty()){
        pair<int, pair<int, int>> op = pq.top();
        pq.pop();
        int d = op.first;
        pair<int, int> pos = op.second;
        if(d > dist[pos.first*W + pos.second]) continue;
        if(pos.first == gx && pos.second == gy){
            cout << d << endl;
            return 0;
        }
        //上下左右
        int x = pos.first, y = pos.second;
        if(check(H, W, x+1, y) && grid[x+1][y] == '.' && d < dist[(x+1)*W + y]){
            dist[(x+1)*W + y] = d;
            pq.push(make_pair(d, make_pair(x+1, y)));
        }
        if(check(H, W, x-1, y) && grid[x-1][y] == '.' && d < dist[(x-1)*W + y]){
            dist[(x-1)*W + y] = d;
            pq.push(make_pair(d, make_pair(x-1, y)));
        }
        if(check(H, W, x, y+1) && grid[x][y+1] == '.' && d < dist[x*W + y+1]){
            dist[x*W + y+1] = d;
            pq.push(make_pair(d, make_pair(x, y+1)));
        }
        if(check(H, W, x, y-1) && grid[x][y-1] == '.' && d < dist[x*W + y-1]){
            dist[x*W + y-1] = d;
            pq.push(make_pair(d, make_pair(x, y-1)));
        }

        //5*5
        for(int dx = -2; dx <= 2; dx++){
            for(int dy = -2; dy <= 2; dy++){
                int nx = x + dx, ny = y + dy;
                int idx = nx*W + ny;
                if(check(H, W, nx, ny) && grid[nx][ny] == '.' && d+1 < dist[idx]){
                    dist[idx] = d+1;
                    pq.push(make_pair(d+1, make_pair(nx, ny)));
                }
            }
        }
        
    }
    cout << -1 << endl;
    return 0;
}

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

#define MAX_COST (1<<21)

int **mat;
int *d;
int n;

void SSSP();
int Search(int*,int*);
int Test_Set(int*);

int main(void){
	int i,j;
	int in_u,in_k,in_v,in_wei;

	scanf("%d",&n);

	d=(int*)malloc(sizeof(int)*n);

	mat=(int**)malloc(sizeof(int*)*n);
	for(i=0;i<n;i++) mat[i]=malloc(sizeof(int)*n);

	for(i=0;i<n;i++){
		for(j=0;j<n;j++) mat[i][j]=MAX_COST+1;
	}

	for(i=0;i<n;i++){
		scanf("%d",&in_u);
		scanf("%d",&in_k);
		for(j=0;j<in_k;j++){
			scanf("%d",&in_v);
			scanf("%d",&in_wei);
			mat[in_u][in_v]=in_wei;
		}
	}

	SSSP();

	for(i=0;i<n;i++) printf("%d %d\n",i,d[i]);

	free(d);
	for(i=0;i<n;i++) free(mat[i]);
	free(mat);

	return 0;
}

void SSSP(){
	int s,u;
	int i;
	int S[n];

	for(i=0;i<n;i++){
		S[i]=0;
		d[i]=MAX_COST+1;
	}
	s=0;
	d[s]=0;

	while(Test_Set(S)==0){
		u=Search(d,S);
		S[u]=1;

		for(i=0;i<n;i++){
			if(S[i]==1) continue;
			if(d[u]+mat[u][i] < d[i]) d[i]=d[u]+mat[u][i];
		}
	}

}

int Search(int *d,int *S){
	int i;
	int min=MAX_COST+1;
	int u;

	for(i=0;i<n;i++){
		if(S[i]==1) continue;
		
		if(d[i]<min){
			min=d[i];
			u=i;
		}
	}

	return u;
}

int Test_Set(int *S){
	int i;

	for(i=0;i<n;i++){
		if(S[i]==0) return 0;
	}	
	return 1;
}

Measured memory_bytes: 636
#include <iostream>
using namespace std;
 
int main()
{
	string wheather;
  	cin>>wheather;
  	int cnt=0; 
  	int maxcnt=0;
  	
  	for(int loop=0;loop<3;loop++)
    {
      	if(wheather[loop]=='R')
        {
          	cnt++;
          if(maxcnt<=cnt)
            maxcnt=cnt;
        }
      	else
          cnt=0;
    }
  	cout<<maxcnt<<endl;
 	return 0;
}

Measured memory_bytes: 3604
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        String s = in.next();
        char[] arr = s.toCharArray();
        char[] v1 = new char[s.length()];
        char[] v2 = new char[s.length()];
        for(int i = 0; i<s.length(); i++){
            if(i%2==0){
                v1[i] = '1';
            }
            else{
                v1[i] = '0';
            }
        }
        for(int i = 0; i<s.length(); i++){
            if(i%2==0){
                v2[i] = '0';
            }
            else{
                v2[i] = '1';
            }
        }
        int c1 = 0;
        int c2 = 0;
        for(int i = 0; i<s.length(); i++){
            if(arr[i]!=v1[i]){
                ++c1;
            }
            if(arr[i]!=v2[i]){
                ++c2;
            }
        }
        out.println(Math.min(c1,c2));
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



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

using namespace std;

int main()
{
    int N, M, X;
    int Array[100] = {};
    cin >> N >> M >> X;
    int idx;
    for(int i = 0; i < M; i++) {
        cin >> idx;
        Array[idx] = 1;
    }
    int CntR = 0;
    for(int i = X + 1; i < N; i++) {
        CntR += Array[i];
    }
    int CntL = 0;
    for(int i = X - 1; i >= 0; i--) {
        CntL += Array[i];
    }
    if(CntR < CntL) {
        cout << CntR << endl;
    }
    else {
        cout << CntL << endl;
    }

    return 0;
}


Measured memory_bytes: 256
gets
hs = Array.new(2) { Hash.new(0) }
gets.split.map(&:to_i).each_with_index do |v, i|
    hs[i % 2][v] += 1
end
target = hs.map{|h| h.max_by{|k, v| v }[0]}.uniq
if target.size != 1
    puts hs.zip(target).map { |h, t|
        h.select{|k, v| k != t}.values.inject(0, :+)
    }.inject(0, :+)
else
    sorted = hs.map{|h| h.sort_by{|k, v| v}.map{|a| a[0]}.reverse}
    targets = []
    begin
        targets[0] = [sorted[0][0], sorted[1][1]]
    rescue
        targets[0] = [sorted[0][0], -1]
    end    
    begin
        targets[1] = [sorted[0][1], sorted[1][0]]
    rescue
        targets[1] = [-1, sorted[1][0]]
    end
    puts targets.map { |target|
        hs.zip(target).map { |h, t|
            h.select{|k, v| k != t}.values.inject(0, :+)
        }.inject(0, :+)
    }.min
end

Measured memory_bytes: 35280
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;

int main() {

	int n, m, d; cin >> n >> m >> d;

	if(d)cout <<fixed<<setprecision(7)<< 2. * (n-d)*(m-1)/n/n<< endl;
	else cout << fixed << setprecision(7)<< 1. * (m - 1) / n << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define RPT(x,begin,num) for(int x=(begin);x<((begin)+(num));x++)
#define INF__ ((long long)1 << 60)
using namespace std;
using ll = signed long long;
using ld = long double;
struct Edge {
  int to, id;// to...行先    id...辺のID
  Edge(int to, int id): to(to), id(id) {}
};
vector<Edge> g[55];//各点の辺情報
vector<int> es;//DFSに使う、aからbへの経路で通る辺を記録,使用前にクリアすること
bool dfs(int v, int tv, int p = -1 ){
  if(v == tv) return true;
  for(Edge e : g[v]){
    if(e.to == p) continue;
    if( dfs(e.to, tv, v) ){
      es.push_back(e.id);
      return true;
    }
  }
  return false;
}
int main(void){
  int N, M; 
  cin >> N;
  RPT(i,0,N-1){
    int a, b;
    cin >> a >> b;--a;--b;
    //g[a].push_back(Edge(b,i));
    //g[b].push_back(Edge(a,i));
    g[a].emplace_back(b, i);
    g[b].emplace_back(a, i);
  }
  cin >> M;
  vector<ll> eset(M+1);
  RPT(i,0,M){
    int a, b;
    cin >> a >> b;
    --a;--b;
    es = vector<int>();
    dfs(a,b);
    for(auto e : es){
      eset[i] |= (1LL<<e);
    }
  }
  ll ans = 0;
  RPT(i,0,(1LL << (M))){
    ll mask = 0;ll c,mans;
    RPT(j,0,M){
      if( (i >> j) & 1 ){
        mask |= eset[j];
      }
    }
    c = __builtin_popcountll(mask);
    mans = 1LL << (N-1-c);
    mans *= (ll)((__builtin_popcountll(i)%2)?(-1):(1));
    ans += mans;
  }
  cout << ans << endl;;
  return 0;
}

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

int main() {
  int n, x, t;
  cin >> n >> x >> t;

  int ans;

  if (n % x == 0) ans = n / x * t;
  else ans = (n / x + 1) * t;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
n = int(input())
c_L = list(map(int,input().split()))

c_L.sort(reverse=True)

alice,bob = 0,0

for val in range(len(c_L)):
    if val %2==0:
        alice += c_L[val]
    else:
        bob += c_L[val]
print(alice-bob)


Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int P,Q,R;
int main(void){
    cin >> P >> Q >> R;
    cout << min(P+Q,min(P+R,Q+R)) << endl;
    return 0;
}



Measured memory_bytes: 256
n = gets.to_i

a = Array.new(n)

(1..n).each do |i|
  a[i] = gets.chomp
end

(2..n).each do |i|
 if((a[i-1][a[i-1].length-1,1]) != (a[i][a[i][0,1]]))
    puts 'No'
    exit()
 end
end

(1..n).each do |i|
  (i+1..n).each do |j|
    if(a[i] == a[j])
      puts 'No'
      exit()
    end
  end
end

puts 'Yes'


Measured memory_bytes: 1788
use proconio::input;

fn main(){
  input!{
    N:usize,
    B:[u32;N-1]
  }
  let mut sum:u32 = 0;
  for i in 0..N {
    if i==0{
      sum = sum+B[0];
    }else if i==N-1{
      sum = sum+B[i-1];
    }else{
      if B[i]>B[i-1]{
        sum = sum + B[i-1];
      }else{
        sum = sum + B[i];
      }
    }
  }
  print!("{}",sum);
}

Measured memory_bytes: 2092
s = input()
n = len(s)
alp = [0 for i in range(26)]
lef = 0
rig = 0
alp[ord(s[0]) - ord("a")] += 1
for i in range(n-1):
    rig += 1
    now = ord(s[rig]) - ord("a")
    alp[now] += 1
    if alp[now] == 2:
        while True:
            if alp[now] == 1:
                break
            if 2<= rig-lef+1 <= 3:
                print(str(lef+1) + " " + str(rig+1))
                exit()
            alp[ord(s[lef]) - ord("a")] -= 1
            lef += 1
                
print("-1 -1")

Measured memory_bytes: 9256
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug_v(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"debug.hpp"
#include"print.hpp"
#endif
// }}}

Int pow10_Int(Int a){
	Int ret = 1;
	REP(i,a)ret *= 10;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	char result;
	const Int N = pow10_Int(10);
	cout<<"? "<<N<<endl;
	cin>>result;
	if(result=='Y'){//N = 10^t
		Int t = 0;
		for(int l = 1;l<=10;l++){
			t*=10;t+=9;
			cout<<"? "<<t<<endl;
			cin>>result;
			if(result=='Y'){
				int t = l - 1;
				cout<<"! "<<pow10_Int(t)<<endl;
				break;
			}
		}
		return 0;
	}
	int d = -1;
	for(int i = 1;i<=10;i++){
		cout<<"? "<<pow10_Int(i)<<endl;
		cin>>result;
		if(result=='N'){
			d = i;
			break;
		}
	}
	assert(d>=0);
	// # of digits is d
	Int l = pow10_Int(d-1), r = pow10_Int(d);
	while(r-l>1){
		Int m = (l+r)/2;
		//			cerr<<"    "<<l<<" "<<r<<endl;
		cout<<"? "<<m*10<<endl;
		cin>>result;
		if(result=='Y'){
			r = m;
		}else{
			l = m;
		}
	}
	assert(r == l + 1);
	cout<<"! "<<r<<endl;
// Failed to predict input format
return 0;
}

Measured memory_bytes: 596
//Author: Prakhar Asaiya
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<b;++i)
#define REPN(i,a,b) for(int i=a;i<=b;++i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define pb push_back
#define ll long long
//const int M=1e9+7;
const int INF=1000000000;


int main()
{/*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#*/
  int n;
  cin>>n;
  int A[n+1]={0},B[n+1]={0};
  REPN(i,2,n) 
  cin>>A[i];
  REP(i,2,n+1)
  {
  	B[A[i]]++;
  }
   REPN(i,1,n)
    cout<<B[i]<<"\n";
    return 0;
}


Measured memory_bytes: 5208
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int cnt = 0;

    for (int i = 0; i < 6; i++) {
      if (s.charAt(i) == '1') {
        cnt++;
      }
    }

    System.out.println(cnt);

  }
}

Measured memory_bytes: 35652
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int D = int.Parse(str[0]);
		int X = int.Parse(str[1]);
		int[] A = new int[N];
		int sum = 0;
		for(var i=0;i<N;i++){
			A[i] = int.Parse(Console.ReadLine());
			sum += 1 + (D-1) / A[i];
		}
		sum += X;
		Console.WriteLine(sum);
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N = 0;
    cin>>N;
    int A[N] = {};
    for(int i = 1; i < N; i++) {
        int get = 0;
        cin>>get;
        A[get-1] += 1;
    }
    for(int i = 0; i < N; i++) {
        cout<<A[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 4440
#include <iostream>

using namespace std;

long long func(long long n, long long x){
  if(n != -1) {
    return n/x + 1;
  } else {
    return 0; 
  }
}

int main(){
  long long a, b, x;

  cin >> a >> b >> x;

  cout << func(b, x) - func(a-1, x)<< endl;

  return 0;
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
t = []
ans = 0
for i in range(n):
    l = list(map(int, input().split()))
    t.append(l)
    ans += l[0]
maximum = ans + 10
ans = maximum
for i in range(1, 2**n):
    f = [c for c in format(i, f'0{n}b')]
    money = 0
    scores = [0]*m
    for l in [j for k, j in zip(f, t) if k == '1']:
        money += l[0]
        for j in range(1, m+1):
            scores[j-1] += l[j]
    if len(list(filter(lambda y: y >= x, scores))) == m:
        ans = min(ans, money)
print(ans if ans != maximum else -1)

Measured memory_bytes: 9248
#include <iostream>

using namespace std;

int main(){
  int pos[5],k;
  cin >> pos[0]>>pos[1]>>pos[2]>>pos[3]>>pos[4]>> k;
  for(int i=0;i<4;i++){
    for(int j=i+1;j<5;j++){
	    if(pos[j]-pos[i]>k){
          cout << ":(" << endl;
          return 0;
        }
    }
  }
  cout << "Yay!" << endl;
  return 0;
}


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

using namespace std;

// ord := rootを0とした時、DFSを行った時の順序番号
// lowlink := 頂点vからDFS木の葉方向の辺を0回以上、後退辺を0回以上1回以下通っていける頂点のordの最小値

vector<int> G[100010];
vector<pair<int, int>> bridge;
vector<int> Articulation;
int ord[100010], lowlink[100010];
bool visited[100010];
void dfs(int v, int p, int &k)
{
  visited[v] = true;

  ord[v] = k++;
  lowlink[v] = ord[v];

  bool isArticulation = false;
  int ct = 0;

  for (int i = 0; i < G[v].size(); i++)
  {
    if (!visited[G[v][i]])
    {
      ct++;
      dfs(G[v][i], v, k);
      lowlink[v] = min(lowlink[v], lowlink[G[v][i]]);

      if (~p && ord[v] <= lowlink[G[v][i]])
        isArticulation = true;

      if (ord[v] < lowlink[G[v][i]])
        bridge.push_back(make_pair(min(v, G[v][i]), max(v, G[v][i])));
    }
    else if (G[v][i] != p)
    {
      lowlink[v] = min(lowlink[v], ord[G[v][i]]);
    }
  }

  //根の場合子が一つなら関節点ではなく、そうでなければ関節点
  if (p == -1 && ct > 1)
    isArticulation = true;

  if (isArticulation)
    Articulation.push_back(v);
}
int main()
{
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++)
  {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  int k = 0;
  for (int i = 0; i < n; i++)
  {
    if (!visited[i])
      dfs(i, -1, k);
  }

  sort(bridge.begin(), bridge.end());
  for (int i = 0; i < bridge.size(); i++)
  {
    cout << bridge[i].first << " " << bridge[i].second << endl;
  }
  return 0;
}

// Varify
// 関節点の列挙: https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/3/GRL_3_A
// 橋の列挙: https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/3/GRL_3_B
// 参考
// npca2014年部誌 競技プログラミングで使えるグラフ理論の基本
// http://kagamiz.hatenablog.com/entry/2013/10/05/005213


Measured memory_bytes: 7108
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  string PON = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
  int k;
  cin >> k;
  if(k <= 16){
    cout << PON.at((k - 1)*3);
  }
  if((16 <= k)&&(k <= 24)){
    cout << PON.at((k - 1)*3 + 1);
  }
  if((24 <= k)&&(k <= 32)){
    cout << PON.at((k - 1)*3 + 2);
  }
  if(k == 32){
    cout << "1";
  }
  cout << endl;
}
     
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
template <typename T>
struct RMQ
{
    const T INF = 0;
    int n;         // 葉の数
    vector<T> dat; // 完全二分木の配列
    RMQ(int n_) : n(), dat(n_ * 4, INF)
    { // 葉の数は 2^x の形
        int x = 1;
        while (n_ > x)
        {
            x *= 2;
        }
        n = x;
    }
    void update(int i, T x)
    {
        i += n - 1;
        dat[i] = x;
        while (i > 0)
        {
            i = (i - 1) / 2; // parent
            dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    // the minimum element of [a,b)
    T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    T query_sub(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l)
        {
            return INF;
        }
        else if (a <= l && r <= b)
        {
            return dat[k];
        }
        else
        {
            T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    RMQ<ll> ans(300100);
    rep(i, n)
    {
        ll l = max(0LL, a[i] - k);
        ll r = min(300100LL, a[i] + k + 1);
        ll now = ans.query(l, r);
        ans.update(a[i], now - 1);
    }
    cout << -ans.query(0, 300100) << endl;
}

Measured memory_bytes: 14876
import sys
from collections import Counter
X, N = [int(x) for x in input().split()]
P = []
if N:
    P = [int(x) for x in input().split()]

CP = Counter(P)
if CP[X] == 0:
    print(X)
    sys.exit()

for d in range(1, 1000):
    if CP[X - d] == 0:
        print(X - d)
        break
    elif CP[X + d] == 0:
        print(X + d)
        break

Measured memory_bytes: 9460
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class AHonestOrDishonest {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    char a, b;
	    in >> a >> b;
	    if(a == b) out << "H" << endl;
	    else out << "D" << endl;
	}
};


int main() {
	AHonestOrDishonest solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
length = int(input())
targ = [n for n in input().split(' ')]
selecttarg = targ[:]
#bubbleflag = 0
for l in range(length):
    for init in range(l):
        if targ[l - init][1] < targ[l - init - 1][1]:
            disp = targ[l-init]
            targ[l-init] = targ[l-init-1]
            targ[l-init-1] = disp
print(' '.join([str(n) for n in targ]))

print("Stable")

selectflag = 0
for l in range(length):
    value = l
    samevalue = l
    for init in range(l+1,length):
        if selecttarg[value][1] > selecttarg[init][1]:
            value = init
        elif selectflag != 1 and selecttarg[l][1] == selecttarg[init][1]:
            samevalue = init
    if samevalue != l and value != l and value > samevalue:
        selectflag = 1
    disp = selecttarg[l]
    selecttarg[l] = selecttarg[value]
    selecttarg[value] = disp
print(' '.join([str(n) for n in selecttarg]))
if selectflag == 0:
    print("Stable")
else:
    print("Not stable")

Measured memory_bytes: 7788
import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline

MOD = 1000000007

# input functions
I = lambda : int(input())
M = lambda : map(int, input().split())
Ms = lambda : map(str, input().split()) 
ARR = lambda: list(map(int, input().split()))

def main():
    a, b, c = M()
    k = I()
    ans = 0
    while b <= a:
        b *= 2
        ans += 1
    while c <= b:
        c *= 2
        ans += 1
    if ans <= k:
        print("Yes")
    else:
        print("No")

# testcases
tc = 1
for _ in range(tc):
    main()

Measured memory_bytes: 68620
N,Q = map(int,input().split())
S = input()
point = [list(map(int,input().split())) for i in range(Q)]
ac_list = [0]*(N+1)

for i in range(N):
  if S[i:i+2] == 'AC':
    ac_list[i+1] = ac_list[i] + 1
  else:
    ac_list[i+1] = ac_list[i]


for i in range(Q):
  print(ac_list[point[i][1]-1] - ac_list[point[i][0]-1])



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

int main() {
  int N,L,sum;
  cin >> N;
  sum=0,L=0;
  int x;
  for (int i=0; i<N; i++) {
    cin >> x;
    sum += x;
     L = max(L, x);
  }
  if (L<sum-L) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
template <class Q>
void clearQueue(Q & q) {
    q = Q();
}
void solve(){
	int n,w;cin>>n>>w;
    vector<int>wt(n),val(n);
    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
    }
    int dp[n][1000*n+5];
    for(int i=0;i<n;i++){
        for(int j=0;j<=1000*n+4;j++){
            dp[i][j]=INT_MAX;
        }
    }
    dp[0][0]=0;
    dp[0][val[0]]=wt[0];
    for(int i=1;i<n;i++){
        dp[i][0]=0;
        for(int j=1;j<=1000*n;j++){
            if(j>=val[i])
            dp[i][j]=min(dp[i][j],wt[i]+dp[i-1][j-val[i]]);
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
        }
    }
    for(int i=1000*n;i>=0;i--){
        if(dp[n-1][i]<=w){
            cout<<i;return;
        }
    }
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL); 
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define sz(v) ll(v.size())


const string YES = "Yes";
const string NO = "No";
void solve(ll A, ll B, ll C){
    if ((B - C) * (A - C) > 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

int main() {
  ll A;
    scanf("%lld",&A);
    ll B;
    scanf("%lld",&B);
    ll C;
    scanf("%lld",&C);
  solve(A, B, C);
  return 0;
}


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

#pragma warning( disable: 4996 )

using namespace std;

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

#define INF 1000000000
#define EPS 1e-10

#define MAX_N 10000

ll N, M;
P p[MAX_N];
vector<ll> ans_list;

int main(){

	while (true){

		cin >> N >> M;
		if (N == 0 && M == 0)
			break;

		for (int i = 0; i < N; i++){
			cin >> p[i].second >> p[i].first;
		}

		sort(p, p + N);

		ll ans = 0;

		for (int i = N-1; i >= 0; i--){
			if (p[i].second <= M){
				M -= p[i].second;
			}
			else{
				p[i].second -= M;
				M = 0;
				ans += p[i].first * p[i].second;
			}
		}

		ans_list.push_back(ans);

	}

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}

	return 0;

}

Measured memory_bytes: 1368
using System;
using System.Collections.Generic;
using System.Linq;

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int M = int.Parse(Console.ReadLine());
            Console.WriteLine(48-M);
        }   
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // long N = NK[0];
            // long K = NK[1];
            // long K = long.Parse(Console.ReadLine());
            // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int x = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int N = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            // string c = Console.ReadLine();
            // string B = Console.ReadLine();
            // string[] s = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            // long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // var hs=new Dictionary<long,long>();
            // for(int i=0;i<s[0];i++){
            //     long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            //     if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
            //     else{hs.Add(q[0],q[1]);}
            // }
        
        // //最小公倍数
        // static long Lcm(long a, long b)
        // {
        //     return a/Gcd(a,b)*b;
        // }

        // //最大公約数
        // static long Gcd(long m, long n)
        // {
        //     if(n==0)return m;
        //     return Gcd(n,m%n);
        // }
    }
}


Measured memory_bytes: 11092
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	boolean f = true;
	int c[] = new int[4];
	for(int i = 0; i< 3; i++) {
	    c[sc.nextInt()-1]++;
	    c[sc.nextInt()-1]++;
	}
	for(int i = 0; i< 4; i++) {
            if(c[i]>=3) f = false;
        }
	if(f) {
	    System.out.println("YES");
	}else {
	    System.out.println("NO");
	}
    }
}

Measured memory_bytes: 24020
# encoding:utf-8
import copy

def main():
	n = int(input())
	a = list(map(int, input().split()))

	print(calc(a))
	
def calc(temp):
	i = 0
	# print(temp)
	n = len(temp)
	while max(temp) >= n:
		sum_count = sum([x // n for x in temp])
		i += sum_count
		temp = [x - (x // n) * n + sum_count - (x // n) for x in temp]
		#print(temp)

	return i

if __name__ == '__main__':
	main()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
#define ld long double
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int k;
  cin>>k;
  rep(i,n){
    if(s[i]!=s[k-1]){
      cout<<"*";
    }
    else{
      cout<<s[i];
  }
  }
   cout<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, M, D;
	cin >> N >> M >> D;

	double kazu;
	if(D) kazu = (N - D) * 2.0 / N / N;
	else kazu = 1.0 / N;
	
	cout << setprecision(12) << kazu * (M - 1) << endl;

	Would you please return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

from fractions import gcd
def resolve():
    H,W=pin()
    #たてに切る
    hori=0 if W%3==0 else H
    #よこにきる
    vert=0 if H%3==0 else W
    #たてに切った後よこ
    sp1=H*W
    for w in range(W):
        g=H*(w+1)
        #b>=rとする
        t=(H+1)//2
        b=t*(W-w-1)
        r=(H//2)*(W-w-1)
        sp1=min(sp1,max(g,b,r)-min(g,b,r))
    #横に切った後たて
    sp2=H*W
    for h in range(H):
        g=W*(h+1)
        #b>=rとする
        t=(W+1)//2
        b=t*(H-h-1)
        r=(W//2)*(H-h-1)
        sp2=min(sp2,max(g,b,r)-min(g,b,r))
    #上4つの最小 間に合ってほしいねぇ
    print(min(hori,vert,sp1,sp2))
#%%submit!
resolve()

Measured memory_bytes: 65644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  int a=1;
  string s;
  cin>>s;
  for(int i=0; i<n-1; i++){
    if(s[i]!=s[i+1])
      a++;
  }
  cout<<a<<endl;
}


Measured memory_bytes: 512
A = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
N = int(input())
S = list(input())
B = []
for i in range(len(S)):
  for j in range(26):
    if S[i] == A[j]:
      if j+N > 25:
        B.append(A[j+N-26])
      else:
        B.append(A[j+N])
print(''.join(B))

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, a[105];
int main() {
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	sort(a, a+n);
	cout<<a[n-1] - a[0];
	return 0;
}

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

using ll = long long;

int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<vector<int>> a(10, vector<int>(0));
    rep(i, N) {
        a[S[i] - '0'].push_back(i);
    }
    int ans = 0;
    rep(i, 10) {
        if (a[i].size() == 0) continue;
        int p = a[i][0];
        rep(j, 10) {
            auto it1 = upper_bound(a[j].begin(), a[j].end(), p);
            if (it1 == a[j].end()) continue;
            rep(k, 10) {
                auto it2 = upper_bound(a[k].begin(), a[k].end(), *it1);
                if (it2 != a[k].end()) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;

class UF
{
	public:
	int s;//木の頂点数
	vector<int> par;//親
	vector<int> dep;//木の深さ
	vector<int> size;//木の直径

	//コンストラクタ
	//n要素で初期化
	UF(int n)
	{
		s=n;
		par.resize(s);
		dep.resize(s);
		size.resize(s);
		for(int i=0;i<n;i++)
		{
			par[i]=i;
			dep[i]=0;
			size[i]=1;
		}
	}

	//木の根を求める
	int find(int x)
	{
		if(par[x]==x)
			return x;
		else
			return par[x]=find(par[x]);
	}

	//xとyの属する集合を併合
	void unite(int x,int y)
	{
		x=find(x);
		y=find(y);
		if(x==y)
			return;
	
		if(dep[x]<dep[y])
		{
			par[x]=y;
			size[y]+=size[x];
		}else{
			par[y]=x;
			size[x]+=size[y];
			if(dep[x]==dep[y])
				dep[x]++;
		}
	}

	//xとyが同じ集合に属するか否か
	bool same(int x,int y)
	{
		return find(x)==find(y);
	}

	int getsize(int x)
	{
		return size[par[x]];
	}
};

vector<int> a;
vector<int> b;
int main()
{
	int n,m;
	vector<ll> ans;
	cin>>n>>m;
	UF u = UF(n);
	for(int i=0;i<m;i++)
	{
		int aa,bb;
		cin>>aa>>bb;
		aa--;
		bb--;
		a.push_back(aa);
		b.push_back(bb);
	}
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	ans.push_back((ll)n*(ll)(n-1)/2);
	for(int i=0;i<m-1;i++)
	{
		ll tmp=ans[i];
		if(!u.same(a[i],b[i]))
		{
			ll asize=u.getsize(a[i]);
			ll bsize=u.getsize(b[i]);
			tmp-=asize*bsize;
			u.unite(a[i],b[i]);
			//cerr<<" "<<tmp<<endl;
		}
		ans.push_back(tmp);
	}
	reverse(ans.begin(),ans.end());
	for(int i=0;i<m;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4208
#include <cstring>
#include <cstdio>
#define N 105
bool cmp(char *s1, char *s2) {
	for(int i = 0; s1[i] != '\0'; i++) 
		if(s1[i] != s2[i]) return false;
	return true;
}

int main() {
	char s[N], t[N];
	int len;
	scanf("%s\n%s", s, t);	
	len = strlen(s);
	for(int i = 0; i < len; i++) {
		if(cmp(s, t)) {
			printf("Yes\n");
			return 0;
		}else {
			for(int i = len; i >= 1; i--) 
				s[i] = s[i-1];
			s[0] = s[len];
			s[len] = '\0';
		}
	}
	printf("No\n");
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  long long ans = 0;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i = 1; i < n; i++){
    ans += a[i/2];
  }
  cout << ans << endl;
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define mp make_pair
#define r0 return 0

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    int a, b;
    cin >> a >> b;
    if (a >= 13)
    {
        cout << b << endl;
    }
    else if (a >= 6)
    {
        cout << b / 2 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
xu = []
for i in range(n):
    x, u = input().split()
    xu.append((float(x), u))

yen = []
for x, u in xu:
    if u == "JPY":
        yen.append(x)
    else:
        yen.append(x*380000.0)

print(sum(yen))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	Scanner sc;

	Main() {
		sc = new Scanner(System.in);
	}

	void run() {
		for (;;) {
			double in = sc.nextDouble();
			if (in == 0) {
				break;
			}

			int denom = 1;
			boolean ok = false;
			for (;;) {
				for (int i = (int) (denom * Math.PI); i < denom * Math.PI + 1; i++) {
					if (Math.abs((double) i / denom - Math.PI) < in) {
						ok = true;
					}
				}
				if(ok){
					break;
				}
				denom++;
			}
			double min = in;
			int  index = 0;
			for (int i = (int) (denom * Math.PI); i < denom * Math.PI + 1; i++) {
				if (Math.abs((double) i / denom - Math.PI) < min) {
					min = Math.abs((double) i / denom - Math.PI);
					index = i;
				}
			}
			System.out.println(index+"/"+denom);
		}
	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

}

Measured memory_bytes: 0
from itertools import accumulate
from collections import defaultdict
n = int(input())
As = list(map(int, input().split()))

acc = [0]+list(accumulate(As))
d = defaultdict(int)
for a in acc:
    d[a] += 1
ans = 0
for k in d.keys():
    n = d[k]
    ans += n*(n-1)//2
print(ans)

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

int main() { 
  int n,m;
  cin >> n;
  cin >> m;
  long long tmp;
  long long tmp2;
  long long ans = 0;

  priority_queue<long long> a;

  for(int i=1;i<=n;i++){
    cin >> tmp;
    a.push(tmp);
  }
  
  for(int i=1;i<=m;i++){
    tmp2 = a.top()/2;
    a.pop();
    a.push(tmp2);
  }

  for(int i=1;i<=n;i++){
    ans += a.top();
    a.pop();
  }

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

Measured memory_bytes: 1400
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A>B)swap(A,B);
  if(A<C and C<B)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    a.sort()
    c.sort()

    def bs(seq, target, key_):
        first = 0
        last = len(seq) - 1
        if key_ == '<=':
            while first + 1 < last:
                middle = (first + last) // 2
                if seq[middle] <= target:
                    first = middle
                else:
                    last = middle
            if seq[first] <= target < seq[last]:
                return first
            elif target < seq[first]:
                return
            else:
                return len(seq) - 1
        if key_ == '<':
            while first + 1 < last:
                middle = (first + last) // 2
                if seq[middle] < target:
                    first = middle
                else:
                    last = middle
            if seq[first] < target <= seq[last]:
                return first
            elif target <= seq[first]:
                return
            else:
                return len(seq) - 1
        if key_ == '>=':
            while first + 1 < last:
                middle = (first + last) // 2
                if seq[middle] < target:
                    first = middle
                else:
                    last = middle
            if seq[first] < target <= seq[last]:
                return last
            elif target <= seq[first]:
                return 0
            else:
                return
        if key_ == '>':
            while first + 1 < last:
                middle = (first + last) // 2
                if seq[middle] <= target:
                    first = middle
                else:
                    last = middle
            if seq[first] <= target < seq[last]:
                return last
            elif target < seq[first]:
                return 0
            else:
                return
    
    ans = 0
    for target in b:
        aindex = bs(a, target, '<')
        if aindex is None:
            continue
        cindex = bs(c, target, '>')
        if cindex is None:
            continue
        ans += (aindex + 1) * (len(c) - cindex)
    print(ans)

main()


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

using namespace std;
int main() {
  string s;
  cin >> s;
  string week[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  for(int i = 0; i < 7; i++) {
    if(week[i] == s) {
      cout << 7-i << endl;
      return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256