akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{

	int n;
	cin >> n;
	vector<int> x(n);
	vector<int> y(n);
	for (int i=0;i<n;++i)
	{
		cin >> x[i] >> y[i];
	}

	vector<int> p(n);
	for (int i=0;i<n;++i)
	{
		p[i]=i;
	}

	double sum_d=0;
	int count=0;

	do
	{
		double d=0;
		for (int i=0;i<n-1;++i)
		{
			d+=sqrt((x[p[i]]-x[p[i+1]])*(x[p[i]]-x[p[i+1]])+(y[p[i]]-y[p[i+1]])*(y[p[i]]-y[p[i+1]]));
		}
		sum_d+=d;
		++count;
	}
	while (next_permutation(p.begin(),p.end()));

	cout << setprecision(9) << sum_d/count << endl;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define forN(n, N) for(int n=0; n<N; n++)
#define res_out(ans) cout << ans << "\n";
#define ll long long

int zero[int(1e6)], one[int(1e6)];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    int N,  K, i = 0;
    cin >> N >> K >> S;
    forN(n, N){
        if(S[n] == '0'){
            zero[i]++;
            if(n + 1 < N && S[n+1] == '1')i++;
        }
        else one[i]++;
    }
    int num, ans;
    if(K >= 1)ans = zero[0] + one[0] + one[1];
    else ans = zero[0] + one[0];
    forN(n, i+1){
        num = 0;
        for(int m=0; m<K && m + n <= i; m++){
            num += zero[n+m] + one[n+m];
        }
        if(n + K <= i)num += one[n+K];
        if(ans < num)ans = num;
    }
    res_out(ans)
    return 0;
}

Measured memory_bytes: 4816
n,m = map(int,input().split())
d = {}
for i in range(n):
  a,b = map(int,input().split())
  if a in d.keys():
    d[a] = d[a] + b
  else:
    d[a] = b

ans = 0
getDrink = 0
keys_sorted = sorted(d.keys())
isFinish = False
for key in keys_sorted:
  if isFinish:
    break
  for i in range(d[key]):
    getDrink += 1
    ans += key
    if getDrink == m:
      isFinish = True
      break
print(ans)


Measured memory_bytes: 17880
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   ll n,m,k;
   cin>>n>>m>>k;
   vector<ll> a(n+1);
   vector<ll> b(m+1);	
   a[0]=0;
   b[0]=0;
   for(ll i=1;i<=n;i++)
   {
   	 cin>>a[i];
   	 a[i]+=a[i-1];
   }
   for(ll i=1;i<=m;i++)
   {
   	 cin>>b[i];
   	 b[i]+=b[i-1];
   }
    ll ans=0;
   for(ll i=0;i<=n;i++)
   {
   	    if(a[i]>k)
   	    break;
   	    ll rem=k-a[i],pos;
   	    vector<ll>::iterator it=upper_bound(b.begin(),b.end(),rem);
   	       if(it==b.begin())
   	       	 pos=0;
   	       else
   	       pos=it-1-b.begin();
   	       ans=max(ans,i+pos);
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL INF=100000000000;
string u="abcdefghijklmnopqrstuvwxyz";


int main(){
    int N;
    LL Y;
    cin >> N >> Y;
    for(int i=0;i<=N;i++){
        for(int j=0;j+i<=N;j++){
            if(10000*i+5000*j+1000*(N-(i+j))==Y){
                cout << i << " " << j << " " << N-(i+j) << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
class UnionFind:
  def __init__(self, n):
    self.g = [i for i in range(n)]
    self.n = n
  def whichclass(self, x):
    if self.g[x]==x:
      return x
    else:
      self.g[x] = self.whichclass(self.g[x])
      return self.g[x]
  def union(self, x, y):
    cx = self.whichclass(x)
    cy = self.whichclass(y)
    if cx==cy:
      return
    minc = min(cx, cy)
    maxc = max(cx, cy)
    self.g[maxc] = minc
  def __getitem__(self, x):
    return self.whichclass(x)
  
N, M = map(int, input().split())
UF = UnionFind(N)
for i in range(M):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  UF.union(a, b)
count = [0 for i in range(N)]
for i in range(N):
  count[UF[i]] = 1
print(sum(count)-1)
 

Measured memory_bytes: 81936
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a); '\n';

int main() {
	int n,m;
	cin >> n;
	string s, t;
	cin >> s >> t;
	vector<char> p( n),q(n);
	rep(i, n) {
		p[i] = s[i];
		q[i] = t[i];
	}
	rep(i, n) {
		cout << p[i] << q[i];
	}
	}

	

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area

//main area
int main(){
    string s;
    cin >> s;
    int n = s.size();
    bool check = true;
    int C_place;

    //一個目
    if(s[0] != 'A'){
        check = false;
    }

    //二個目
    int cnt = 0;
    for(int i=2; i<n-1; i++){
        if(s[i] == 'C'){
            cnt++;
            C_place = i;
        }
    }
    if(cnt != 1) check = false;

    //三個目
    rep(i, n){
        if(i == C_place || i == 0) continue;
        if(!('a' <= s[i] && s[i] <= 'z')){
            check = false;
        }
    }
    cout << (check ? "AC" : "WA") << endl;
}
/*

一個ずつ判定する
・s[0] == 'A'
・2 <= i <= s.size()-2      cnt = 1
・上二つ以外の座標において'a' <= s[i] <= 'z'を満たす

*/

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC131A()
{
	string S;
	cin >> S;
	if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3])
		cout << "Bad" << endl;
	else
		cout << "Good" << endl;
}
int main()
{
	ABC131A();
	return 0;
}

Measured memory_bytes: 256
# @author 

import sys

class CXYZTriplets:
    def solve(self, tc=0):
        from collections import defaultdict
        n = int(input())
        
        mp = defaultdict(int)
        for x in range(1, 101):
            for y in range(1, 101):
                for z in range(1, 101):
                    mp[x ** 2 + y ** 2 + z ** 2 + x * y + y * z + x * z] += 1
        for k in range(1, n + 1):
            ans = 0
            # r = int(n ** .5) + 1
            # for x in range(1, r):
            #     for y in range(1, r):
            #         for z in range(1, r):
            #             if x ** 2 + y ** 2 + z ** 2 + x * y + y * z + x * z == k:
            #                 ans += 1

            print(mp[k])

solver = CXYZTriplets()
input = sys.stdin.readline

solver.solve()


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

#define int long long

int N;
string S;
int mem[500010];

signed main(){
    cin >> S;
    N = S.size() + 1;

    if(S[0] == '<') mem[0] = 0;
    for(int i = 0; i < N - 1; i++){
        if(S[i] == '<'){
            mem[i + 1] = max(mem[i + 1], mem[i] + 1);
        }
        else {
            mem[i + 1] = max(mem[i + 1], 0ll);
        }
    }

    if(S[N - 2] == '>') mem[N - 1] = 0;
    for(int i = N - 2; i >= 0; i--){
        if(S[i] == '>'){
            mem[i] = max(mem[i], mem[i + 1] + 1);
        }
        else {
            mem[i] = max(mem[i], 0ll);
        }
    }

    int ans = 0;
    for(int i = 0; i < N; i++) ans += mem[i];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4740
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
 
const int n = 1000000;
vector<bool> is_prime(n / 2,true);
vector<int> prime_list; 
 
int main()
{
    prime_list.push_back(2);
    for(int i = 1; 2 * i + 1 <= n; ++i){
        if(is_prime[i]){
            prime_list.push_back(2 * i + 1);
            for(int j = 3 * i + 1; 2 * j + 1 <= n; j +=  2 * i + 1){
                is_prime[j] = false;
            }
        }
    }
    vector<int> sum(10001);
    for(int i = 1; i <= 10000; ++i){
        sum[i] = sum[i-1] + prime_list[i-1];
    }
    int n;
    while(cin >> n,n){
        cout << sum[n] << endl;
    }
}

Measured memory_bytes: 1656
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<string.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	int l;
	int ant=0,ab=0,a=0,b=0;
	int ans=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		char c[15];
		scanf("%s",c);
//		printf("%s\n",c);
		l=strlen(c);
		for(int j=0;j<l-1;j++)
		{
			if(c[j]=='A'&&c[j+1]=='B')
				ant++;
		}
		if(c[0]=='B'&&c[l-1]=='A')
			ab++;
		else if(c[0]=='B')
			b++;
		else if(c[l-1]=='A')
			a++;
	}
//	printf("ant:%d ab:%d a:%d b:%d\n",ant,ab,a,b);
	ans+=ant;
	if(ab!=0)
		ans+=(ab-1);
	if(a!=0&&ab!=0)
	{
		ans++;
		a--;
	}
	if(b!=0&&ab!=0)
	{
		ans++;
		b--;
	}
	ans+=min(a,b);
	printf("%d\n",ans);
	return 0;
}
/*
5
AB
AB
AB
AB
BB
6
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define de(x) cout<<#x<<"="<<x<<endl
const int N = 2e2+55;
int d[N][N];
int R[N];
int main(){
    int n,m,r,a,b,c;
    memset(d,0x3f3f3f3f3f,sizeof(d));
    for(int i=1;i<=n;i++)d[i][i]=0;
    cin>>n>>m>>r;
    for(int i=1;i<=r;i++){
        scanf("%d",&R[i]);
    }
    sort(R+1,R+r+1);
    for(int i=0;i<m;i++){
        scanf("%d %d %d",&a,&b,&c);
        d[a][b]=c;d[b][a]=c;
    }
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                d[i][j]=min(d[i][k]+d[k][j],d[i][j]);
            }
        }
    }
    int ans=0;
    for(int i=1;i<r;i++){
        ans+=d[R[i]][R[i+1] ];
    }
    int tmp=0;
    while( next_permutation(R+1,R+r+1)  ){
        tmp=0;
        for(int i=1;i<r;i++){
            tmp+=d[R[i] ][R[i+1] ];
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
import java.io.*;
import java.util.*;

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		if (a == b) {
			for (int i = 0; i < b; i++) {
				sb.append(b);
			}
		} else if (a > b) {
			for (int i = 0; i < a; i++) {
				sb.append(b);
			}
		} else {
			for (int i = 0; i < b; i++) {
				sb.append(a);
			}
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 23892
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# functions
def init_fact(n,mod):
    fact,finv,inv = [1]*n,[1]*n,[1]*n
    for i in range(2,n):
        fact[i] = (fact[i-1]*i) % mod
        inv[i]  = mod - inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1] * inv[i] % mod
    return (fact,finv,inv)

def nCr(n,r,mod,fact,finv):
    if n<r:
        return 0
    else:
        return fact[n] * (finv[r] * finv[n-r] % mod) % mod

# main
H,W,A,B = map(int,input().split())

modulo = 10**9+7
fact,finv,inv = init_fact(200000,modulo)

ans = 0
for i in range(H-A):
    ans += nCr(i+B-1,i,modulo,fact,finv) * nCr(H-i-1+W-B-1,W-B-1,modulo,fact,finv)
    ans %= modulo

print(ans)


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    ll ans = 1000;
    ll kabu = 0;
    for(int i=0; i<N-1; i++)
    {
        if(A[i] > A[i+1])
        {
            ans += kabu * A[i];
            kabu = 0;
        }
        else if(A[i] < A[i+1])
        {
            kabu += ans / A[i];
            ans -= ans / A[i] * A[i];
        }
    }
    ans += kabu * A[N-1];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3656
import java.util.ArrayList;
import java.util.Scanner;

public class Main
{

	// アルファベットの配列
	public static String[] alphabet_all = { "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" };

	public static void main(String[] args) {

		// アルファベットbeanのリスト
		ArrayList<alphabet> alpha_beans = new ArrayList<alphabet>();
		// 各アルファベットのbeanを作る
		for (String val : alphabet_all) {
			//
			alphabet hoge = new alphabet(val);
			alpha_beans.add(hoge);
		}

		// ファイル入力
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			String input_sentence = sc.nextLine();

			// 入力文字を1文字ずつに変換
			char ch[] = input_sentence.toCharArray();

			// 入力文字列がある分、まわす
			for (int i = 0; i < ch.length; i++) {

				// それぞれのアルファベットについて
				for (alphabet val : alpha_beans) {

					// 入力文字の一文字ずつとアルファベットの文字(大文字も小文字は区別しない)が一致したら
					if (val.getString().equals(
							String.valueOf(ch[i]).toLowerCase())) {
						// 一致したアルファベットの数字を増やす
						val.setNumber(1);

					}
				}
			}
		}

		// 出力
		for (alphabet val : alpha_beans) {
			//
			System.out.println(val.getString() + " : " + val.getNumber());
		}
	}
}

// 各アルファベットクラス
class alphabet {
	//
	private int number = 0;
	private String alphabet = "";

	// コンストラクタ
	alphabet(String a) {
		alphabet = a;
	}

	// セッター
	public void setNumber(int n) {
		number = n + number;
	}

	// ゲッター
	public int getNumber() {
		return number;
	}

	public String getString() {
		return alphabet;
	}
}

Measured memory_bytes: 24588
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


int main() {
	int r, d, x;
	cin >> r >> d >> x;
	repz(i, 10) {
		x = r * x - d;
		cout << x << endl;
	}

	system("pause");
	return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;

const ll mod = 1e9 + 7;

void add(ll& a, ll b)
{
    a += b;
    if (a >= mod) {
        a -= mod;
    }
}

void mul(ll& a, ll b)
{
    a *= b;
    if (a >= mod) {
        a %= mod;
    }
}

void sub(ll& a, ll b)
{
    a -= b;
    if (a < 0) {
        a += mod;
    }
}

const int nmax = 420;

int main()
{

    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    //freopen("input.txt", "r", stdin);

    int n;
    cin >> n;
    int k;
    cin >> k;

    vector<int> l(n), r(n);
    for (int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> r[i];
    }

    vector<vector<ll> > pref(nmax, vector<ll>(nmax));
    for (int r = 1; r < nmax; ++r) {
        ll val = 1;
        for (int deg = 0; deg < nmax; ++deg) {
            for (int x = r; x < nmax; ++x) {
                add(pref[x][deg], val);
            }
            mul(val, r);
        }
    }

    vector<vector<ll> > dp(n, vector<ll>(k + 1));
    for (int j = 0; j <= k; ++j) {
        dp[n - 1][j] = pref[r[n - 1]][j];
        sub(dp[n - 1][j], pref[l[n - 1] - 1][j]);
    }

    for (int i = n - 2; i >= 0; --i) {
        for (int j = 0; j <= k; ++j) {
            for (int deg = 0; deg <= j; ++deg) {
                ll val = pref[r[i]][deg];
                sub(val, pref[l[i] - 1][deg]);
                mul(val, dp[i + 1][j - deg]);
                add(dp[i][j], val);
            }
        }
    }

    cout << dp[0][k] << '\n';

}


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

int main()
{
  int n, r;
  cin >> n >> r;
  int rate;
  if(n < 10) cout << r + 100 * (10 - n) << endl;
  else cout << r << endl;
}

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

int main() {
  long long N, A, B; cin >> N >> A >> B;
  if (N == 1) {
    if (A != B) cout << 0 << endl;
    else cout << 1 << endl;
  }
  else if (N == 2) cout << 1 << endl;
  else {
    if (A > B) cout << 0 << endl;
    else cout << (N - 2) * (B - A) + 1 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, j;
    cin >> n;
    vector <db> a(n);
    for(i = 0; i < n; i++)
        cin >> a[i];
    db dp[n][n + 1];
    dp[0][1] = (db)1 - a[0]; dp[0][0] = a[0];
    for(i = 2; i <= n; i++)
    {
        dp[i - 1][0] = dp[i - 2][0] * a[i - 1];
        db left = (db)1 - a[i - 1];
        for(j = 1; j < i; j++)
            dp[i - 1][j] = (dp[i - 2][j] * a[i - 1] + dp[i - 2][j - 1] * left);
        dp[i - 1][i] = dp[i - 2][i - 1] * left;
    }
    db ans = 0;
    for(i = 0; i <= n / 2; i++)
        ans += dp[n - 1][i];
    printf("%.12lf\n", ans);
    return 0;
}

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

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;

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

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

    if (a * b % 2 == 0)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << 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;
using ll = long long;
using P = pair<int,int>;

int main() {
	int n, k; cin >> n >> k;
    int count = 0;
  	while (n > 0) {
      n /= k;
      count++;
    }
    cout << count << endl;
    
    return 0;
}

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

using namespace std;

const int MAX_N = 1e5 + 5;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;



int solve(string s, string t) {
    int n=s.length();
    int m=t.length();
    long long int ans=1e8;
    int count=0;
    for(int i=0;i<n-m+1;i++){
        count=0;
        string s1 = s.substr(i,i+m);
        for(int j=0;j<m;j++){
            if (s1[j]!=t[j]){
                count++;
            }
        }
        if(count<ans){
            ans=count;
        }
    }
    return ans;
    
}

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

    #ifndef ONLINE_JUDGE
        freopen("inputcpp.txt", "r", stdin);
        freopen("outputcpp.txt", "w", stdout);
    #endif

    string s,t;
    cin>>s>>t;
    cout<<solve(s,t)<<endl;
    
    
}

Measured memory_bytes: 3660
from collections import defaultdict
from operator import sub

def main():
    N = int(input())
    balls = [tuple(map(int,input().split())) for _ in range(N)]
    d = defaultdict(int)
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            d[tuple(map(sub, balls[i], balls[j]))] += 1
    try:
        mmax = N - max(d.values(), default=0)
        print(mmax)
    except ValueError:
        print(100)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3820
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr)
import Control.Monad
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.ST

warshallFloyd1 :: Int -> U.Vector (Int, Int, Int64) -> UArray (Int, Int) Int64
warshallFloyd1 !n !edges = runSTUArray $ do
  !arr <- newArray ((0,0),(n-1,n-1)) (10^9+1)
  U.forM_ edges $ \(a,b,c) -> do
    writeArray arr (a,b) c
    writeArray arr (b,a) c
  forM_ [0..n-1] $ \a -> do
    writeArray arr (a,a) 0
  forM_ [0..n-1] $ \k -> do
    forM_ [0..n-1] $ \i -> do
      forM_ [0..n-1] $ \j -> do
        a_ik <- readArray arr (i,k)
        a_kj <- readArray arr (k,j)
        a_ij <- readArray arr (i,j)
        writeArray arr (i,j) $! min a_ij (a_ik + a_kj)
  return arr

warshallFloyd2 :: Int -> Int -> UArray (Int, Int) Int64 -> UArray (Int, Int) Int
warshallFloyd2 !n !l !graph = runSTUArray $ do
  !arr <- newArray ((0,0),(n-1,n-1)) (10^9+1)
  forM_ [0..n-1] $ \a -> do
    forM_ [0..n-1] $ \b -> do
      let v = graph ! (a,b)
      when (v <= fromIntegral l) $ do
        writeArray arr (a,b) 1
  forM_ [0..n-1] $ \a -> do
    writeArray arr (a,a) 0
  forM_ [0..n-1] $ \k -> do
    forM_ [0..n-1] $ \i -> do
      forM_ [0..n-1] $ \j -> do
        a_ik <- readArray arr (i,k)
        a_kj <- readArray arr (k,j)
        a_ij <- readArray arr (i,j)
        writeArray arr (i,j) $! min a_ij (a_ik + a_kj)
  return arr

main = do
  [n,m,l] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  edges <- U.replicateM m $ do
    [a,b,c] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (a-1,b-1,fromIntegral c)
  let w1 = warshallFloyd1 n edges
      w2 = warshallFloyd2 n l w1
  q <- readLn
  queries <- U.replicateM q $ do
    [s,t] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (s,t)
  U.forM_ queries $ \(s,t) -> do
    let d = w2 ! (s-1,t-1)
    print $ if d > 10^9 then -1 else d - 1


Measured memory_bytes: 6372
N, M = gets.strip.split(" ").map(&:to_i)
correct_cnt = 0
wrong_cnt = 0
flags = Array.new(N+1, false)
wrongs = Array.new(N+1, 0)

M.times do
  n, a = gets.strip.split(' ')
  n = n.to_i
  flags[n] = true if a == 'AC' && flags[n] == false
  wrongs[n] += 1 if a == 'WA' && flags[n] == false
end
(1..N).each do |n|
  if flags[n] == true
    correct_cnt += 1
    wrong_cnt += wrongs[n]
  end
end
puts "#{correct_cnt} #{wrong_cnt}"


Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int x;
  cin >> x;
  int ans = 0;
  for (int b = 1; b <= x; b++) {
    for (int p = 2; p <= 10; p++) {
      if (x < pow(b, p)) break;
      ans = max(ans, (int)pow(b, p));
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

int mmnmm(int num)
{
    int bit = 0;
    int nnum = num;
    while (num) {
        bit++;
        num /= 2;
    }
    return (1LL << bit) - nnum;
}

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

    Int(n);
    map<int, int> funami;
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i];
        funami[data[i]]++;
    }
    sort(all(data)); reverse(all(data));

    int ans = 0;
    rep(i, n) {
        if (funami[data[i]]) {
            funami[data[i]]--;
            int targ = mmnmm(data[i]);
            if (funami[targ]) {
                funami[targ]--;
                ans++;
            }
        }
    }
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 26880
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	double sum=0,cnt=0,a=0,b=0,i=0;
	while(scanf("%lf,%lf",&a,&b)!=EOF){
	cnt+=b;
	sum+=a*b;
	i++;
	}
	int s=(int)(cnt/i);
	if((double)s+0.500<=sum)s++;
	cout<<sum<<endl<<s<<endl;
	return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
    cin.sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;

    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) cout << 0 << endl;
    else cout << min(a * b, min(b * c, c * a)) << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))

    insertionSort(A, N)


def insertionSort(A, N):
    print(*A)

    for i in range(1, N):
        v = A[i]
        j = i - 1

        while (0 <= j) and (v < A[j]):
            A[j + 1] = A[j]
            j -= 1

        A[j + 1] = v

        print(*A)


main()


Measured memory_bytes: 5984
#include<stdio.h>
int main(void)
{
	int N,M,A[105][105],B[105],i,j,t;
	
	scanf("%d%d",&N,&M);
	
	for(i=0;i<N;i++)
		for(j=0;j<M;j++)
			scanf("%d",&A[i][j]);
	for(i=0;i<M;i++)
		scanf("%d",&B[i]);

	for(i=0;i<N;i++){
		for(j=t=0;j<M;j++)
		t+=A[i][j]*B[j];
		printf("%d\n",t);
		}
return 0;
}



Measured memory_bytes: 2104
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    map <int,int>mp;
    int  n,cnt=1;  cin>>n;
    mp[n]++;
    while (true){
        cnt++;
        if (n&1) n = 3 * n + 1 ; 
        else n /= 2 ; 
        mp[n]++;
        if (mp[n]>=2 and !(n&(n-1))) break;
    }
    cout << cnt << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

int L, B, AC, NC, U;

int main(){
    while(scanf("%d%d%d%d%d",
                &L, &B, &AC, &NC, &U) != EOF && L){
        int lb = 0, ub = U;
        while(lb <= ub){
            int m = (lb + ub) / 2;
            if(B - AC * m >= 0 && m + (B - AC * m) / NC >= L){
                lb = m+1;
            }else{
                ub = m-1;
            }
        }
        if(lb > 1){
            printf("%d %d\n", lb-1, (B - AC * lb + AC) / NC);
        }else{
            puts("NA");
        }
    }
    return 0;
}

Measured memory_bytes: 1040
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
int nmax=200000;
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,z,w;
    cin>>n>>z>>w;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int l=a[n-1];
    if(n==1){
        cout<<abs(l-w)<<endl;
    }
    else{
        int s=a[n-2];
        cout<<max(abs(l-w),abs(s-l))<<endl;
    }
    
}

Measured memory_bytes: 4992
// acdart
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cstdlib>
#include <list>
#include <limits.h>
#include <utility>
#include <functional>
#include <deque>
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define SZ(x) ((int)(x).size())
#define MAXN 10010
#define MAXM
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
/*********default*********/


int main()
{
	int n;
	
	scanf("%d", &n);
	printf("%d", n * 800 - (n / 15) * 200);
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
	long long a,b,x;
	scanf("%lld %lld %lld",&a,&b,&x);
  
	if(a == 0ll) printf("%lld\n",(b / x) + 1ll);
	else printf("%lld\n",(b / x) - ((a - 1ll) / x));
  
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
constexpr i64 MOD = 1e9 + 7;

i64 modpow(i64 a, i64 n, i64 mod) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        i64 t = modpow(a, n / 2, mod);
        return t * t % mod;
    }
    return a * modpow(a, n - 1, mod) % mod;
}

i64 modinv(i64 a, i64 mod) {
    // mod is prime
    return modpow(a, mod - 2, mod);
}

struct Combination {
    const int MAX_N = 1 << 21;
    vi fact = vi(MAX_N);
    vi factinv = vi(MAX_N);

    Combination() {
        fact[0] = 1;
        for (int i = 1; i < MAX_N; i++) {
            fact[i] = fact[i - 1] * i % MOD;
        }
        factinv[MAX_N - 1] = modinv(fact[MAX_N - 1], MOD);
        for (int i = MAX_N - 2; i >= 0; i--) {
            factinv[i] = factinv[i + 1] * (i + 1) % MOD;
        }
    }

    i64 ncr(i64 n, i64 r) {
        if (r < 0 || r > n) return 0;
        return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
    }

    i64 npr(i64 n, i64 r) {
        if (r < 0 || r > n) return 0;
        return fact[n] * factinv[n - r] % MOD;
    }

    i64 nhr(i64 n, i64 r) {
        if (n == 0 && r == 0) return 1;
        return ncr(n + r - 1, r);
    }
} comb;

i64 f(int n, int k) {
    i64 ret = 0;
    for (int i = 1; i <= k; i++) {
        if ((k - i) % 2) {
            ret -= comb.ncr(k, i) * modpow(i, n, MOD) % MOD;
        } else {
            ret += comb.ncr(k, i) * modpow(i, n, MOD) % MOD;
        }
        ret %= MOD;
    }
    ret += MOD;
    return ret % MOD;
}

i64 S(int n, int k) {
    return f(n, k) * comb.factinv[k] % MOD;
}

i64 B(int n, int k) {
    i64 ret = 0;
    for (int i = 1; i <= k; i++) {
        ret += S(n, i);
        ret %= MOD;
    }
    return ret;
}

int main() {
    int n, k;
    cin >> n >> k;
    cout << B(n, k) << endl;
}


Measured memory_bytes: 35404
#include<stdio.h>
#include<string.h>
#define N 100000

struct P{
  char name[100];
  int num;
};

int head, tail, n, c=0, q;
struct P Q[N];
void enqueue(){

  Q[head].num=(Q[head].num)-q;
  Q[tail] = Q[head];

  if(tail > n+1){tail = 0;}
  else tail++;
}

void dequeue(){
  printf("%s %d\n",Q[head].name, Q[head].num+c);
}

int main(){
  int i;

  scanf("%d %d", &n, &q);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].num);
  }
  head = 1;
  tail = n+1;
  i = 1;

  while(head != tail){
    if(Q[head].num > q){
      enqueue();
      c+=q;
    }
    else{
      dequeue();
      c+=Q[head].num;
    }
    if(head>n+1){head = 0;}
    else head++;
  }
  return 0;
}


Measured memory_bytes: 6780
import java.util.Scanner;

public class Main {
    private static long[] SOD;

    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        long N = scn.nextLong();
        getSumOfDivisble(N);
        long res = 0;
        for (int i = 1; i <= N; i++) {
            res += SOD[i] * i;
        }
        System.out.println(res);

    }

    public static void getSumOfDivisble(long N) {
        SOD = new long[10000000 + 10];
        for (int i = 1; i <= N; i++) {
            for (int j = i; j <= N; j += i) {
                SOD[j] += 1;
            }
        }
    }

}

Measured memory_bytes: 116140
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}

int main()
{
   ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
int n;
cin>>n;
int a[100001];
int b[100001];
for(int i=0;i<=n;i++)
{
	b[i]=0;
}
for(int i=1;i<=n;i++)
{
	cin>>a[i];
	b[a[i]]=i;
}
for(int i=1;i<=n;i++)
{
	cout<<b[i]<<" ";
}
cout<<endl;
}



Measured memory_bytes: 4396
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#define maxn 100009
using namespace std;
int n;
int a[maxn];
int main(){
	scanf("%d", &n);
	int cnt0 = 0, cnt2 = 0, cnt4 = 0;
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(a[i] % 4 == 0)
			cnt4++;
		else if(a[i] % 2 == 0)
			cnt2++;
		else 
			cnt0++;
	}
	if(cnt2 == 0){
		if(cnt4 >= cnt0 - 1){
			puts("Yes");
		}
		else{
			puts("No");
		}
	}
	else{
		if(cnt4 >= cnt0){
			puts("Yes");
		}
		else{
			puts("No");
		}
	}
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
 using namespace std;
 #define For(start,end) for(int i = (int)start;i<(int)end;i++)
 using Int = long long int;
 int main(){
    set<int>paper;
    int N;
    cin >> N;
    For(0,N)
    {
        int before_size=paper.size();
        int tmp;
        cin>>tmp;
        paper.insert(tmp);
        if(paper.size()==before_size)
        {
            paper.erase(tmp);
        }
    }
    cout<<paper.size()<<endl;
 }

Measured memory_bytes: 8096
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	   
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	while(1){
	   bool flag = true;
	    for(int i=2; i<n; i++){
	        if(n%i==0){
	            flag = false;
	            break;
	        }
	    }
	    if(flag) break;
	    n++;
	}
	cout<< n <<endl;
	 
return 0;
}

Measured memory_bytes: 3660
#include<iostream>

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if (a == b) {
        cout << a + b << '\n';
    }else if (a > b) {
        cout << 2 * a - 1 << '\n';
    }else if (a < b) {
        cout << 2 * b - 1 << '\n';
    }
    
    
    
    
}

Measured memory_bytes: 256
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	while (true) {
		int n = -1, m = -1;
		cin >> n >> m;
		if (n <= 0 || m <= 0) break;
		priority_queue<int> q;
		for (int i = 0; i < n; ++i) {
			int a;
			cin >> a;
			q.push(a);
		}
		for (int i = 0; i < m; ++i) {
			int x = q.top();
			q.pop();
			q.push(x / 2);
		}
		LL ans = 0;
		for (int i = 0; i < n; ++i) {
			ans += q.top();
			q.pop();
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 892
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

class Program
{
    private static int Next()
    {
        int c;
        int res = 0;
        do
        {
            c = reader.Read();
            if (c == -1)
                return res;
        } while (c < '0' || c > '9');
        res = c - '0';
        while (true)
        {
            c = reader.Read();
            if (c < '0' || c > '9')
                return res;
            res *= 10;
            res += c - '0';
        }
    }
    private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);
    private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

    
    //CultureInfo.InvariantCulture
    static void Main(String[] args)
    {
       var  data = Console.ReadLine().TrimEnd().Split(' ').Select(long.Parse).ToList();
        var n = data[0];
        var a = data[1];
        var b = data[2];
        if (n == 1)
        {
            Console.WriteLine(a == b ? "1" : "0");
        } else
        {
            Console.WriteLine(Math.Max(a + (n - 1) * b - a * (n - 1) - b + 1, 0));
        }
         
    }
}

Measured memory_bytes: 11348
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
#define mp make_pair
#define fr first
#define sc second
#define pb push_back
#define lc (x<<1)
#define rc ((x<<1)|1)
const int N=100005;
int a[N];
int main(){
  //  freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,j,n,C,K,ans=0;
    scanf("%d%d%d",&n,&C,&K);
    for (i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for (i=1,j=1;i<=n;i++){
        if (a[i]-a[j]>K) {ans++;j=i;}
        if (i-j+1>C) {ans++;j=i;}
    }
    printf("%d\n",++ans);
   
  //  system("pause");
    return 0;
}


Measured memory_bytes: 640
import numpy as np
N, M = map(int, input().split())
d = np.array([0]*(N+1), dtype = 'int32')
t = 0
f = 0
for i in range(M):
    tmp = input().split()
    p = int(tmp[0])
    S = tmp[1]
    if S == 'AC':
        if d[p] != -1:
            f += d[p]
            d[p] = -1
            t += 1
    elif d[p] != -1:
        d[p] += 1
print(t, f)


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

int main(void){
    using namespace std;
    int N;
    std::cin >> N;

    string S;
    cin >> S;

    int ret = 1;
    char prev_char = S[0];
    for (int i = 1; i < N;i++){
        if(S[i] != prev_char){
            ret++;
            prev_char = S[i];
        }
    }

    std::cout << ret << std::endl;
    return 0;
}

Measured memory_bytes: 512
import fractions
n = int(input())
a = list(map(int, input().split()))
l = [0]*(n+1)
l[1] = a[0]
r = [0]*(n+1)
r[n-1] = a[n-1]
for i in range(1, n):
  l[i+1] = fractions.gcd(l[i], a[i])
  r[n-1-i] = fractions.gcd(r[n-i], a[n-1-i])

m = 0

for i in range(n):
  m = max(m, fractions.gcd(l[i], r[i+1]))
print(m)


Measured memory_bytes: 16124
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;

int main() {
	ll t0, t1, a0, a1, b0, b1;
 
	scanf("%lld%lld%lld%lld%lld%lld", &t0, &t1, &a0, &a1, &b0, &b1);
	
	ll curA0 = a0*t0, curA1 = a1*t1;
	ll curB0 = b0*t0, curB1 = b1*t1;
	ll d0 = curA0 - curB0;
	ll d1 = curA1 - curB1;
	ll diff = abs(d0+d1);

	if(diff == 0) {
		printf("infinity\n");
		return 0;
	}

	if((d0 >= 0 && d1 >= 0) or (d0 <= 0 && d1 <= 0)) {
		printf("0\n");
		return 0;
	}

	ll diff2 = d0+d1;
	if(diff2 > 0 && abs(d0) > abs(d1) && d0 > 0) {
		printf("0\n");
		return 0;
	}

	if(diff2 < 0 && abs(d0) > abs(d1) && d0 < 0) {
		printf("0\n");
		return 0;
	}

	if(abs(d0) < abs(d1)) {
		printf("%lld\n", 2*(abs(d0)/diff) + (d0%diff != 0));
	}
	else {
		ll cur = abs(d0+d1);
		printf("%lld", 2*(cur/diff) + (cur%diff != 0) + 1);
	}

    return 0;
}

Measured memory_bytes: 256
// Tazoe

#include <iostream>
using namespace std;

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

		if(N==0)
			break;

		int S[200][2];
		S[0][0] = 0;
		S[0][1] = 0;

		int x_max = 0;
		int x_min = 0;
		int y_max = 0;
		int y_min = 0;

		for(int i=1; i<N; i++){
			int n, d;
			cin >> n >> d;

			switch(d){
				case 0:
					S[i][0] = S[n][0]-1;
					S[i][1] = S[n][1];
					if(S[i][0]<x_min){
						x_min = S[i][0];
					}
					break;
				case 1:
					S[i][0] = S[n][0];
					S[i][1] = S[n][1]+1;
					if(S[i][1]>y_max){
						y_max = S[i][1];
					}
					break;
				case 2:
					S[i][0] = S[n][0]+1;
					S[i][1] = S[n][1];
					if(S[i][0]>x_max){
						x_max = S[i][0];
					}
					break;
				case 3:
					S[i][0] = S[n][0];
					S[i][1] = S[n][1]-1;
					if(S[i][1]<y_min){
						y_min = S[i][1];
					}
					break;
			}
		}

		cout << x_max-x_min+1 << ' ' << y_max-y_min+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 0
import itertools

N = int(input())
N_str = str(N)

ans=0
num = ["0","3","5","7"]
for s in itertools.product(num,num,num,num,num,num,num,num,num):
    n = int("".join(s))
    c3 = str(s).count("3")
    c5 = str(s).count("5")
    c7 = str(s).count("7")
    #print(s,n,c3,c5,c7)
    if n <= N and c3>=1 and c5>=1 and c7>=1 and c3+c5+c7==len(str(n)):
        ans+=1
        #print(n)
    elif n>N:
        break
print(ans)
    

Measured memory_bytes: 3064
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>
using namespace std;
int main() {
	int n; long long int d; cin >> n >> d;
	vector<pair<long long int, long long int>> points(n);
	for (auto& p : points) cin >> p.first >> p.second;
	int count = 0;
	for (const auto p : points) {
		if (p.first * p.first + p.second * p.second <= d * d) {
			++count;
		}
	}
	cout << count << '\n';
}

Measured memory_bytes: 6420
#include <iostream>
#include <algorithm>    // reverse
using namespace std;
int main() {
    string str; cin >> str;
    int q; cin >> q;
    while (q--) {
        string s; cin >> s;
        if (s == "print") {
            int a, b; cin >> a >> b;
            cout << str.substr(a, b - a + 1) << endl;
        } else if (s == "reverse") {
            int a, b; cin >> a >> b;
            reverse(str.begin() + a, str.begin() + b + 1);
        } else {
            int a, b; cin >> a >> b;
            string p; cin >> p;
            str.replace(a, b - a + 1, p);
        }
    }
    return 0;
}


Measured memory_bytes: 3184
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
P = IR(n)
print(sum(P)-(max(P)//2))

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
int dp[5050];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	int ma=0;
	for(int len=N;len>=1;len--) {
		ZERO(dp);
		for(x=N-len-1;x>=0;x--) {
			if(S[x]!=S[x+len]) dp[x]=0;
			else dp[x]=min(dp[x+1]+1,len);
			ma=max(ma,dp[x]);
		}
	}
	cout<<ma<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 384