akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
typedef long long ll;
typedef unsigned long long ull;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007


int main() {
    FIN;
    ll n, k;
    cin >> n >> k;
    if(n%k==0) cout << "0\n";
    else
    {
        cout << min(n%k,k-(n%k)) << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<climits>
#include<algorithm>
#include<numeric>
#include<iomanip>
#include<map>
#include<set>
#include<random>
#include<cassert>
using namespace std;
#define ll long long int
#define ld long double
const ll Mod = (ll)1e9+7;
ll CaseN=1;
const ld PI = 22/7.0;
#define INF (ll)1e18 
ll tst()
{
   ll ans=0;  
    
   
       
   return ans;
}




void solve()
{
  ll n;
  cin>>n;
  ll ans=0;
  ll p = n/1000;
  if(n%1000!=0)
  {
	 p++; 
	 }
  ans = (p*1000) - n;
  cout<<ans<<endl;
//cerr<<"Case #"<<CaseN<<": ";
    CaseN++;

return ;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();
	}
}


Measured memory_bytes: 3216
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
p = list(map(int, readline().split()))
cumsum = [0] * (n + 1)
for i in range(1, n + 1):
    cumsum[i] += cumsum[i - 1] + ((p[i - 1] * (p[i - 1] + 1)) // 2) / p[i - 1]
ans = [0] * (n - k + 1)
for i in range(n - k + 1):
    ans[i] = cumsum[i + k] - cumsum[i]
print(max(ans))


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

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

const int nax = 2e5 + 10;

long long dp[nax][5];
long long a[nax];
int N;

long long get(long long x, int c) {
	if (c == 0 || c == 4) {
		return x;
	}
	if (c == 1 || c == 3) {
		if (x == 0) return 2;
		return (x % 2);
	}
	return (x + 1LL) % 2;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	memset(dp, 57, sizeof(dp));
	for (int i = 0; i < 5; ++i) dp[0][i] = 0;

	cin >> N;
	for (int i = 0; i < N; ++i) cin >> a[i];

	for (int i = 0; i < N; ++i)
		for (int j = 0; j < 5; ++j)
			for (int k = j; k < 5; ++k)
				uin(dp[i + 1][k], dp[i][j] + get(a[i], k));

	long long ans = 1e18L;
	for (int i = 0; i < 5; ++i) uin(ans, dp[N][i]);

	cout << ans << '\n';
}

Measured memory_bytes: 12992
package main

import (
	"fmt"
)

func main() {
	var A, B, C, K int
	fmt.Scanf("%d %d %d %d", &A, &B, &C, &K)
	if K <= A {
		fmt.Println(K)
		return
	}
	if (K - A) <= B {
		fmt.Println(A)
		return
	}
	fmt.Println(A - (K - A - B))
}


Measured memory_bytes: 1816
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
 
  using namespace std;
   

//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ
  typedef long long ll;
  // typedef long double lld;
//   typedef string str;
//   typedef unsigned long long ull;
//   ll INF = INT_MAX;
  // ll mod = 998244353;
  // lld PI = 3.141592653;

// const int N = 2e5 + 5;

// int a[N];
// int n,k;
  



 






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

   int k; string s;
   cin>>k;
   cin>>s;

   for (int i = 0;i<min(k, int(s.length())); i++) cout<<s[i];
    // cout<<k<<endl<<s.length()<<endl;
  if (k<s.length()) cout<<"...";
cout<<endl;
    
  

}
  

Measured memory_bytes: 3112
// In the Name of Allah
// Ya Ali

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define F first
#define S second
#define all( x ) x.begin() , x.end()
#define pb push_back
#define mp make_pair

const int maxn = 3010 ;
const int mod = 998244353 ;
const int INF = 1e9 + 10;

int n , dp[ maxn ][ maxn ] , k , a[ maxn ] , x , y ;

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

 cin >> x >> y ;
 cout << y*x ;

    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
bool C = false,ans = false;
void Ss( char c ){
	if ( ( C ) && ( c == 'F' ) )
		ans = true;
	return;
}
using namespace std;
int main(){
	char c;
	while ( cin >> c )
	{
		if ( c == 'C' )
			C = true;
		Ss( c );
	}
	if ( ans )
	{
		printf( "Yes" );
		return 0;
	}
	printf( "No" );
	return 0;
}

Measured memory_bytes: 764
s = list(input())
n = len(s)
b = False
if s[0] == "B":
    b = True

ans = 0
for i in range(1, n):
    if b and s[i] == "W":
        b = False
        ans += 1
    elif not b and s[i] == "B":
        b = True
        ans += 1
print(ans)

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

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int n;
    cin>>n;
  	vector<int> arr(n);
  	for(auto &x:arr)
        cin>>x;
  	// arr.push_back(0);
  	int cnt=0, ans=0;
  	for(int i=n-2; i>=0; i--)
    {
        if(arr[i]>=arr[i+1])
            cnt++;
        else
            cnt=0;
        ans=max(ans, cnt);
    }
	cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
import Control.Monad

shuffle :: String -> Int -> String
shuffle cards h = second ++ first
	where
		first = fst $ splitAt h cards
		second = snd $ splitAt h cards

main = do
	s <- getLine
	if s == "-" then return() else do
		m <- readLn
		h <- replicateM m readLn
		putStrLn $ foldl (\acc x -> shuffle acc x) s h
		main

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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    ll h, w;
    cin >> h >> w;
    if(min(h,w)==1){
        cout << 1 <<endl;
        return 0;
    }
    ll hw = h*w;
    cout<<(hw+1)/2<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i <(n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
 int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  map<int,int> ma;
  rep(i,n){
    ma[a[i]]=i+1;
  }
  for(auto p:ma){
    auto value=p.second;
    cout<<value<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int a,b;
void input(){
    fast_io();
    cin >> a >> b;
}

int solve(){
    cout << (a*b) << endl;
    return 0;
}   

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

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

int main() {
	string a, b;
	cin >> a >> b;

	string Q = a + b;
	int W = stoi(Q);

	for (int i = 1; i <= 1000; i++) {
		if (i * i == W) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using  ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
string n;
std::cin >> n;
  if(n[0]=='7' || n[1]=='7' || n[2]=='7')std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';



  return 0;
}


Measured memory_bytes: 3512
import sys
import math
import heapq
import bisect
input = sys.stdin.readline

MOD = 10 ** 9 + 7


def main():
    N, M = map(int, input().split())
    # A = []

    # for i in map(int, input().split()):
    #     bisect.insort(A, i)

    # for i in range(M):
    #     B, C = map(int, input().split())
    _A = {}
    A = []

    for i in map(int, input().split()):
        if i in _A:
            _A[i] += 1
        else:
            _A[i] = 1

    for (num, c) in _A.items():
        heapq.heappush(A, (num, c))
    # B = [0] * N
    # C = [0] * N
    # print(A)

    B = [0] * M
    C = [0] * M
    T = [None] * M
    for i in range(M):
        b, c = map(int, input().split())
        T[i] = (c, b)

    T = sorted(T, reverse=True)

    finish = False
    for i in range(M):
        C, B = T[i]

        while B > 0:
            item = heapq.heappop(A)

            if item[0] < C:
                replace = min(item[1], B)
                B -= replace
                remain = item[1] - replace

                heapq.heappush(A, (C, replace))

                if remain > 0:
                    heapq.heappush(A, (item[0], remain))

                # print("")
                # print(A, B, replace)
            else:
                heapq.heappush(A, item)
                finish = True
                break

        if finish is True:
            break

    ans = 0
    for a in A:
        ans += a[0] * a[1]
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
    int n, minv, minv2 = 2000000000;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());

    minv = a[0];
    vector<int> ans(n);
    while (1)
    {
        for (int i = 0; i < n; i++)
        {
            if (a[i] % minv == 0)
            {
                ans[i] = minv;
            }
            else
            {
                ans[i] = a[i] % minv;
            }
            minv = min(minv, ans[i]);
        }

        
        if (minv == a[0] || minv == minv2)
        {
            break;
        }
        minv2 = min(minv, minv2);
    }
    
    cout << minv << endl;
}

Measured memory_bytes: 1024
n, x = map(int, input().split())


def calc(a):
    b = []
    for i in range(len(a)-2):
        b.append(list(sorted(a[i:i+3]))[1])
    if len(b) == 1:
        return b[0]
    else:
        return calc(b)
"""
n = 5
max_ = []
for i in range(n):
    max_.append(i*2+1)

for i in range(n-1, 0, -1):
    max_.append(i*2)

print(calc(max_))
"""

if x == 1 or x == 2*n-1:
    print("No")
    exit()
print("Yes")

if x == 2:
    center = 2
    r1 = 1
    r2 = 3
    l = 4
else:
    center = x
    r1 = x+1
    r2 = 1
    l = 2

ans = []
y = 1
for i in range(n-2):
    while y in [center, r1, r2, l]:
        y+= 1
    ans.append(y)
    y+=1
ans.append(l)
ans.append(center)
ans.append(r1)
ans.append(r2)
for i in range(n-3):
    while y in [center, r1, r2, l]:
        y+=1
    ans.append(y)
    y+=1
if n == 2:
    ans = [1,2,3]
for x in ans:
    print(x)


Measured memory_bytes: 12472
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) max(x,y)-min(x,y)
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[100],u[100][5];
vector<int> ii;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h,j;
  string s;
  cin >>a;
  cin >>s;
  for(int n=0;n<a;n++){
    if(s[n]=='(') d++;
    else d--;
    if(d<0) cout <<'(',d++;
  }
  cout <<s;
  while(1){
    if(!d) break;
    cout<<')',d--;
  }
  cout <<'\n';
  return (0);
}


Measured memory_bytes: 384
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        scanner.nextInt();
        int numberOfSubmissions = scanner.nextInt();

        int failsCounter = 0;
        int successCounter = 0;

        Map<Integer, Integer> fails = new HashMap<>();
        Map<Integer, String> tasks = new HashMap<>();

        for (int i = 0; i < numberOfSubmissions; i++) {
            int task = scanner.nextInt();
            String submissionStatus = scanner.next();


            if (!tasks.containsKey(task)) {
                tasks.put(task, submissionStatus);
                if (submissionStatus.equals("AC")) {
                    successCounter++;
                } else {
                    fails.put(task, 1);
                }
            } else {
                String currentStatus = tasks.get(task);

                if (currentStatus.equals("WA")) {
                    if (submissionStatus.equals("AC")) {
                        failsCounter += fails.get(task);
                        successCounter++;
                        tasks.put(task, submissionStatus);
                    } else {
                        int currentFails = fails.get(task);
                        fails.put(task, ++currentFails);
                    }
                }
            }

        }
        System.out.println(successCounter + " " + failsCounter);
    }
}


Measured memory_bytes: 75128
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod=998244353 ;
const ll MAXN=1e6+5;
const ll inf=1e17;

int main()
{
    fastio;
    ll n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
ll modinv(ll a, int b){
    ll res=1;
    int n=MOD-2;
    ll x=b;
    while(n>0){
        if(n&1==1){
            res*=x;
            res%=MOD;
        }
        x*=x;
        x%=MOD;
        n>>=1;
    }
    res*=a;
    res%=MOD;
    return res;
}

int main() {
    int N,K;
    cin>>N>>K;
    priority_queue<ll,vector<ll>,function<bool(ll,ll)>>A(
        [](ll a,ll b){return abs(a)<abs(b);}
    );
    int p,n,zero;
    p=0;n=0;zero=0;
    ll ans=1;
    for (int i = 0; i < N; i++){
        int a;
        cin>>a;
        if(a==0){
            zero++;
            continue;
        }
        A.push(a);
        if(a>0)p++;
        else if(a<0)n++;
    }
    if(p+n<K||(p+n==K&&n%2==1&&zero>0)){
        cout<<0<<endl;
        return 0;
    }
    if(p==0&&zero==0&&K%2==1||p+n==K&&zero==0){
        for (int i = 0; i < n-K; i++){
            A.pop();
        }
        while (!A.empty()){
            ans*=A.top();ans%=MOD;
            A.pop();
        }  
        ans=(ans+MOD)%MOD;   
        cout<<ans<<endl;
        return 0;
    }
    bool positive=true;
    ll last_p,last_n,next_p,next_n;
    last_p=0;last_n=0;next_p=0;next_n=0;
    for (int i = 0; i < K; i++){
        ll j=A.top();
        A.pop();
        ans*=abs(j);ans%=MOD;
        if(j<0){
            positive=!positive;
            last_n=abs(j);
        }else last_p=j;
    }
    if(positive){
        cout<<ans<<endl;
        return 0;
    }
    while(next_p*next_n==0&&(!A.empty())){
        ll j=A.top();
        A.pop();
        if(next_p==0&&j>0)next_p=j;
        else if(next_n==0&&j<0)next_n=abs(j);
    }
    if(last_p*next_p>last_n*next_n||last_p==0){
        ans=modinv(ans,last_n);
        ans*=next_p;ans%=MOD;
    }else if(last_p*next_p<last_n*next_n||next_p==0){
        ans=modinv(ans,last_p);
        ans*=next_n;ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5344
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on
const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::string S) {
  ll len = N / 2;
  if (N % 2 != 0) {
    cout << NO << endl;
    return;
  }
  cout << (S.substr(0, len) == S.substr(len) ? YES : NO) << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::string S;
  std::cin >> S;
  solve(N, S);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define     mod             1e9+7
#define     ll              long long
#define     mp              make_pair
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     ii              pair<int,int>
#define     vi              vector<int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int>>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            '\n'

/*
	For Debugging we have define TRACE.
*/

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif  

const int N = 1e7 + 5;
int a[N];
int reach [10000001];

void solve(){


	int n;
	cin>>n;

	int z = n%1000;
	if(z==0)
		cout<<"0";
	else
		cout<<(1000-z);
	



}
 
int32_t main()
 
{  
    #ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    #endif

    IOS;

    solve();


}

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

ans = []
i = N
while i > 0:
    prev = i
    for j in range(max(0, i-M), i):
        if S[j] == "0":
            ans.append(str(i-j))
            i = j
            break
    if i == prev:
        ans = -1
        break

if ans == -1:
    print(ans)
else:
    ans.reverse()
    print(*ans)

Measured memory_bytes: 11932
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;


int N, M, Q;
ll MAX=0;

void dfs(ll min,ll Max,int x,vector<vector<ll>> q,vector<ll> &A){
  if(x==N-1){
    FOR(i,min,Max+1){
      A[x]=i;
      ll cnt = 0;
      REP(j,Q){
        if(A.at(q.at(j).at(1))-A.at(q.at(j).at(0))==q.at(j).at(2)){
          cnt+=q.at(j).at(3);
        }
      }
      MAX = max(MAX,cnt);
    }
  }else{
    FOR(i,min,Max+1){
      A[x]=i;
      dfs(i,Max,x+1,q,A);
    }
  }
}

int main()
{
  cin >> N >> M >> Q;
  vector<vector<ll>> q(Q,vector<ll>(4));
  vector<ll> A(N);
  
  REP(i, Q){
    REP(j, 4){
      cin >> q.at(i).at(j);
    }
    q.at(i).at(0)--;
    q.at(i).at(1)--;
  }
  
  dfs(1,M,0,q,A);
  cout << MAX << endl;
}

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

#include <atcoder/all>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using namespace atcoder;
using namespace boost::multiprecision;
using ll = long long;

int main() {
    int n, m;
    cin >> n >> m;
    dsu d(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        d.merge(a, b);
    }
    int ans = 0;
    rep(i, n) {
        if (!d.same(0, i)) {
            ans++;
            d.merge(0, i);
        }
    }

    cout << ans << endl;
    return 0;
}
/*
g++ -std=c++17 -Wall -Wextra -g -O0 -fsanitize=undefined,address main.cpp && oj t
*/

Measured memory_bytes: 3824
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        BGreatOceanView solver = new BGreatOceanView();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGreatOceanView {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] ar = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = in.nextInt();
            int ans = 1;
            int max = ar[0];
            for (int i = 1; i < n; i++)
                if (ar[i] >= max) {
                    ans++;
                    max = ar[i];
                }
            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());
        }

    }
}

Measured memory_bytes: 21460
from collections import defaultdict
from itertools import product

H, W, N = map(int, input().split())
black = [tuple(map(int, input().split())) for _ in range(N)]
counter = defaultdict(int)
for a, b in black:
    a, b = a-1, b-1
    for i, j in product(range(3), repeat=2):
        if 0 <= a-i < H-2  and 0 <= b-j < W-2:
            counter[(a-i, b-j)] += 1
ans = [0 for _ in range(10)]
for v in counter.values():
    ans[v] += 1
ans[0] = (H-2) * (W-2) - sum(ans[1:])
print(*ans, sep='\n')

Measured memory_bytes: 180344
#include <iostream>
#include <vector>
#include <deque>

using namespace std;

int main(){
    int N, W;
    while(cin >> N >> W){
        vector<int> dp(W+1, 0);
        for(int i=0;i<N;i++){
            int v, w, m; cin >> v >> w >> m;
            for(int j=0;j<w;j++){
                if(j > W) break;
                deque<pair<int, int>> qu; qu.emplace_back(dp[j], 0);
                for(int k=1;j+k*w<=W;k++){
                    auto cur = dp[j+k*w] - k*v;
                    dp[j+k*w] = max(dp[j+k*w], qu.front().first + k * v);
                    while(!qu.empty() && k - qu.front().second >= m) qu.pop_front();
                    while(!qu.empty() && qu.back().first <= cur) qu.pop_back();
                    qu.emplace_back(cur, k);
                }
            }
        }
        cout << dp.back() << endl;
    }
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
const int mod=1e9+7;
using namespace std;
int n,x,y,z,w,S,f[45][1<<17],ans=1;
int main(){
    scanf("%d%d%d%d",&n,&x,&y,&z);
    for (int i=1;i<=n;i++) ans=1ll*ans*10%mod;
    w=(1<<x-1)|(1<<x+y-1)|(1<<x+y+z-1);
    S=(1<<x+y+z)-1;f[0][0]=1;
    for (int i=1;i<=n;i++)
        for (int j=0;j<=S;j++)
            for (int k=1;k<=10;k++){
                int T=(j<<k)|(1<<k-1);
                T&=S;
                if ((T&w)!=w)f[i][T]=(f[i][T]+f[i-1][j])%mod;
            }
    for(int i=0;i<=S;i++) ans=(ans-f[n][i]+mod)%mod;
    printf("%d",ans);
}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

    int N, M;
    cin >> N >> M;
    vector<int> b(N+1, 1);
    vector<bool> f(N+1, false);
    int ans;
    f[1] = true; ans = 1;

    rep(i, M) {
        int x, y;
        cin >> x >> y;
        b[x]--;
        b[y]++;
        if (f[x]) {
            if (b[x] == 0) {
                f[x] = false; ans--;
            }
            if (!f[y]) {
                f[y] = true; ans++;
            }
        }
    }
    // cout_h(f);
    cout << ans << "\n";
}


Measured memory_bytes: 640
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM

main = do
  n <- readLn -- 2 <= n <= 10^5
  h <- V.fromListN n . map read . words <$> getLine
  -- hi <= 10^4
  let dp = V.create $ do
        dp <- VM.new n
        VM.write dp 0 0
        VM.write dp 1 (abs (h V.! 0 - h V.! 1))
        forM_ [2..n-1] $ \i -> do
          c2 <- VM.read dp (i - 2)
          c1 <- VM.read dp (i - 1)
          let c2' = c2 + abs (h V.! i - h V.! (i - 2))
              c1' = c1 + abs (h V.! i - h V.! (i - 1))
          VM.write dp i (min c1' c2')
        return dp
  print (V.last dp :: Int)


Measured memory_bytes: 16764
#include<stdio.h>

int main(void){
    int A,B,C,D;
    int i=-1;
    scanf("%d %d %d %d",&A,&B,&C,&D);

    for(;;){
        C=C-B;
        if(C<=0){
            i = 0;
            break;
        }

        A=A-D;
        if(A<=0){
            i = 1;
            break;
        }
    }

    if(i == 0)
        printf("Yes");
    else
        printf("No");
    
    return 0;
    
}


Measured memory_bytes: 1728
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, X = list(map(int, sys.stdin.readline().split()))
C, T = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

T = np.array(T)
C = np.array(C)
if (T <= X).any():
    print(min(C[T <= X]))
else:
    print('TLE')


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

/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
 
 
ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/
int main(){
    double R;
    cin>>R;
    double ans=0;
    ans = R*2*3.141592653589;
    cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 3772
#include <iostream>
#include <utility>
 
using namespace std;
 
int gcn(int a,int b){
if(a < b){swap(a,b);} 
while(b != 0){
a = a%b;
swap(a,b);
}
return a;
}
 
int main() {
	int n;int m;
while(cin >> n >> m){
cout << gcn(n,m) << " " << n/gcn(n,m) *m << endl;
}
	return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define read read()
const ll inf = 1e15;
//const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define start int wuyt()
#define end return 0
const ll maxn = 18;
ll f[maxn];
int n;
char ss1[maxn],ss2[maxn];
void fun();
ll Work(char str[])
{
    int len=n;
    ll ans=0;
    for (int i=0;i<len;i++)
    {
        int tmp=0;
        for (int j=i+1;j<len;j++)
        {
            if (str[j]<str[i])
                tmp++;
        }
        ans+=tmp*f[len-i-1];
    }
    return ans;
}
start{
    fun();
    n=read;
    char temp;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        ss1[i]=temp;
    }
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        ss2[i]=temp;
    }
    ///printf("%s %s\n",ss1,ss2);
    cout <<abs(Work(ss1)-Work(ss2)) << endl;
	end;
}
void fun(){
    ll sum = 1;
    for (ll i = 1; i <= 18; i++) {
        sum *= i;
        f[i] = sum;
    }
}


Measured memory_bytes: 256
import heapq

n,m = map(int, input().split())
head = []
tail = []
for _ in range(m):
    l, r = map(int, input().split())
    head.append(l)
    tail.append(r)

left = heapq.nlargest(1, head)[0]
right = heapq.nsmallest(1, tail)[0]
#print(right, left)

if right - left < 0:
    print('0')
else:
    print(right-left+1)


Measured memory_bytes: 55896
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>


using namespace std;

bool WW(int x) {
	for (int i = 2; i*i <= x; i++) {
		if (x%i==0)return 0;
	}
	return 1;
}

int main() {

	long long int n, ans = 1;
	cin >> n;
	for (int i = 2; i <=n; i++) {
		if (!WW(i))continue;
		long long int r = n, c = 1;
		while (r) {
			c += r / i;
			r /= i;
		}
		ans = (ans*c) % 1000000007;
	}
	cout << ans << endl;
	return 0;

}




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

//#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> truth[n], no[n];
    for (int i = 0; i < n; ++i) {
        int m;
        cin >> m;
        for (int j = 0; j < m; ++j) {
            int x, y;
            cin >> x >> y;
            x--;
            if (y)
                truth[i].push_back(x);
            else
                no[i].push_back(x);
        }
    }

    int ans = 0;
    for (int mask = 0; mask < (1 << n); ++mask) {
        for (int i = 0; i < n; ++i)
            if ((1 << i) & mask) {
                for (int j : truth[i])
                    if (((1 << j) & mask) == 0)
                        goto nxt;
                for (int j : no[i])
                    if (((1 << j) & mask))
                        goto nxt;
            }

        ans = max(ans, __builtin_popcount(mask));
        nxt:;
    }
    cout << ans;
}




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

int main(){

  string a,s,t;
  // char b;
  int n,an=0;
  cin >> s>>t;
  n=s.length();
  for(int i=0;i<n;i++){
    // a=t.substr(0,n-1);
    // b=t[n-1];
    // t[0]=b;
    t = t[n-1] + t.substr(0, n-1);
    // for(int i=1;i<n;i++){
    //   t[i]=a[i-1];
    // }
    if(s==t){
      an++;
      cout << "Yes" << endl;
      break;
    }

  }
  if(an==0){
    cout << "No" << endl;
  }
  return 0;


}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int N,M,Q;
int L[200010],R[200010],p[200010],q[200010];
int num[510][510];

int main(){
	cin>>N>>M>>Q;
	REP(i,M){
		cin>>L[i]>>R[i];
		num[L[i]][R[i]]++;
	}
	REP(i,N+1){
		REP(j,N+1){
			num[i][j+1]+=num[i][j];
		}
	}
	REP(i,N+1){
		REP(j,N+1){
			num[i+1][j]+=num[i][j];
		}
	}
	REP(i,Q){
		cin>>p[i]>>q[i];
	}
	REP(i,Q){
		cout<<num[q[i]][q[i]]-num[p[i]-1][q[i]]-num[q[i]][p[i]-1]+num[p[i]-1][p[i]-1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> a(m, vector<int>(2));
    for(int i = 0; i < m; i++){
        for(int j = 0; j < 2; j++){
            cin >> a[i][j];
        }
    }
    vector<int> container(n,0);
    for(int i = 0; i < m; i++){
        for(int j = 0; j < 2; j++){
            container[a[i][j] - 1]++;
        }
    }
    for(int i = 0; i < n; i++){
        cout << container[i] << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)


int main(){
	int x,y,s;
	while(cin>>x>>y>>s&&(x||y||s)){
		int maxi = -1;
		for(int i=1;i<s;i++){
			for(int j=1;j<s;j++){
				if((int)(i*(100+x)/100)+(int)(j*(100+x)/100)==s){
					maxi = max(maxi,(int)(i*(100+y)/100) + (int)(j*(100+y)/100));
				}
			}
		}
		cout<<maxi<<endl;
	}
}

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

using namespace std;

int main()
{
    long r, d, x[11];

    cin>>r>>d>>x[0];

    for(int i=1; i<=10; i++)
    {
        x[i]=r*x[i-1]-d;
        cout<<x[i]<<endl;
    }

    return 0;
}

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

#define INF 1000000000000

int main(){
  int n,t;
  cin>>n>>t;
  int mini=10000;
  rep(i,n){
    int a,b;
    cin>>a>>b;
    if(b<=t){mini=min(mini,a);}
  }
  if(mini==10000){cout<<"TLE"<<endl;}
  else cout<<mini<<endl;

}


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

vector<long long> pri_fac(long long N){
    vector<long long> yakusu;
    long long now = 0; 
    long long a = 2;
        while(N >= a*a){
            if(N%a == 0){
                yakusu.push_back(a);
                 N /= a;
            }else{
                a++;
            }
        } 
    if(N != 1) yakusu.push_back(N);
    return yakusu;
}

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

    vector<long long> vec_all;
    vec_all = pri_fac(N);

    if(N == 1) cout << 0 << endl;
    else if(vec_all.size() == 1) cout << 1 << endl;
    else{
        long long now;
        now = vec_all[0];
        vector<long long> unique_count;
        unique_count.push_back(1);
        for(long long i=1;i<vec_all.size();i++){
            if(vec_all[i] != now) unique_count.push_back(1);
            else unique_count[unique_count.size()-1]++;
            now = vec_all[i];
        }

        long long ans = 0;

        for(long long i=0;i<unique_count.size();i++){
            long long j = 1;
            while(j <= unique_count[i]){
                ans++;
                unique_count[i] -= j;
                j++;
            } 
        }

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

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

LL wyn, res, sum;
int tab[105], out[505], out2[505], l, i, j, k, n;

int main() {
scanf("%d", &n);
for (i=1;i<=n;i++) scanf("%d", &tab[i]);
k = min(n, 20);
wyn = 0;
for (i=0;i<(1<<k);i++) {
	//printf("%d\n", i);
	for (l=1;l<=n;l++) out[l] = 0;
	for (j=1;j<=k;j++) if (((1<<(j - 1)) & i) > 0) {
		for (l = j;l<=n;l+=j) out[l] = 1;
	}
	for (l=1;l<=n;l++) out2[l] = out[l];
	for (l = n;l > k;l--) if (!out[l] && tab[l] < 0) {
		sum = tab[l] * 1LL;
		if (l * 2 <= n) {
			if (!out[2 * l]) sum += tab[2 * l];
			if (l * 3 <= n) {
				if (!out[3 * l]) sum += tab[3 * l];
				if (l * 4 <= n) {
					if (!out[4 * l]) sum += tab[4 * l];
				}
			}
		}
		if (sum < 0) out[l] = out[2*l] = out[3*l] = out[4*l] = 1;
	}
	res = 0;
	for (l=1;l<=n;l++) if (!out[l]) res += tab[l];
	wyn = max(wyn, res);
	
	for (l=1;l<=n;l++) out[l] = out2[l];
	for (l = k+1;l <= n;l++) if (!out[l] && tab[l] < 0) {
		sum = tab[l] * 1LL;
		if (l * 2 <= n) {
			if (!out[2 * l]) sum += tab[2 * l];
			if (l * 3 <= n) {
				if (!out[3 * l]) sum += tab[3 * l];
				if (l * 4 <= n) {
					if (!out[4 * l]) sum += tab[4 * l];
				}
			}
		}
		if (sum < 0) out[l] = out[2*l] = out[3*l] = out[4*l] = 1;
	}
	res = 0;
	for (l=1;l<=n;l++) if (!out[l]) res += tab[l];
	wyn = max(wyn, res);
}
cout << wyn << 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>;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  ll X,K,D;
  cin >> X >> K >> D;
  ll dis = abs(X);
  ll rep = dis / D;
  if(rep >= K){
    cout << dis - K*D << endl;
  }
  else{
    ll min_1 = dis % D;
    ll min_2 = D - min_1;
    if((K-rep)%2 == 0)cout << min_1 <<endl;
    else cout << min_2 << endl;
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 2e5+10;
const int N = 1e5+10;
const int E = 1e6+10; 
int n;
map<string,int> m;
map<string,bool> vis;
string s[maxn];
vector<string> ans;

int main(){
	cin>>n;
	int maa = 0;
	F(i,1,n){
		cin>>s[i];
		m[s[i]]++;
		maa = max(m[s[i]],maa);
	}
	
	F(i,1,n){
		if(!vis[s[i]]&&m[s[i]]==maa){
			vis[s[i]]=1;
			ans.pb(s[i]);
		}
	}
	sort(ans.begin(),ans.end());
	for(int i = 0;i<ans.size();i++){
		cout<<ans[i]<<endl;
	}
}

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

int main() {
  int N;
  long K;
  cin >> N >> K;
  vector<ll> A(N),F(N);
  rep(i, N)  cin>>A.at(i);
  rep(i, N)  cin>>F.at(i);
  sort(A.begin(),A.end());
  sort(F.begin(),F.end());
  reverse(F.begin(),F.end());
  ll ng = -1 , ok = A.at(N - 1) * F.at(0);
  while ( abs(ok-ng) > 1) {
    ll mid = (ng + ok) / 2;
    ll T = 0;
    rep(i, N) {
      ll x = A.at(i) * F.at(i) - mid;
      if (x > 0) T += (x + F.at(i) - 1) / F.at(i);
    }
    if (T <= K)  ok = mid;
    else  ng = mid;
  }
  cout << ok << endl;
}

Measured memory_bytes: 3328
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

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

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false){
    if(b < a || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

struct node{
    int id, cost, start, cnt;

    bool operator<(const node& rhs) const {
        return cost > rhs.cost;
    }
};

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

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

    vector<int> c(n), r(n);
    rep(i, n){
        cin >> c[i] >> r[i];
    }

    vector< vector<int> > g(n);
    rep(i, k){
        int a, b;
        cin >> a >> b;
        g[--a].emplace_back(--b);
        g[b].emplace_back(a);
    }

    vector< vector<int> > cost(n, vector<int>(n, IINF));
    cost[0][0] = 0;
    priority_queue<node> que;
    que.push({0, 0, 0, 0});

    while(!que.empty()){
        node now = que.top();
        que.pop();
        if(cost[now.id][now.start] < now.cost){
            continue;
        }
        for(auto to : g[now.id]){
            if(now.cnt + 1 <= r[now.start]){
                if(now.cnt == 0){
                    if(chmin(cost[to][now.start], now.cost + c[now.start])){
                        que.push({to, now.cost + c[now.start], now.start, now.cnt + 1});
                    }
                }else{
                    if(chmin(cost[to][now.start], now.cost)){
                        que.push({to, now.cost, now.start, now.cnt + 1});
                    }
                }
            }
            if(now.start != now.id && chmin(cost[to][now.id], now.cost + c[now.id])){
                que.push({to, now.cost + c[now.id], now.id, 1});
            }
        }
    }

    int ans = IINF;
    rep(i, n){
        chmin(ans, cost[n - 1][i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 101652
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll a, b;
    cin >> a >> b;
    cout << a / __gcd(a, b) * b;

    return 0;
}

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    int x,t;
    cin >> x >> t;
    cout << max(0,x-t) << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define pr pair<int, int>
#define graph vector< vector<int> >
#define vs vector<string>
#define mn -
#define pls +
#define mod %
#define E =
#define EE ==
#define pls +
#define le <=
#define ge <=
//int mx=9999999;
/**  '' "\n" x ^ **/
void YES()
{
    cout<<"YES\n";
}

void NO()
{
    cout<<"NO\n";
}
void yes()
{
    cout<<"Yes\n";
}

void no()
{
    cout<<"No\n";
}
int main() {
    /**  '' "\n" x ^ **/
    /** printf("\n") */
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll div=(n/500);
    div*=1000;
    n%=500;
    int d=n/5;
    cout<<div+(d*5);
}


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

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


int main() {
  int N,ix;
  cin >> N;
  vector<int> cnt(1e5+1,0);
  rep(i,N) {
    cin >> ix;
    cnt[ix]++;}
  int ans = 0;
  rep2(i,1,1e5) {
    ans = max(ans,cnt[i-1]+cnt[i]+cnt[i+1]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
h,w = map(int,input().split())
ans = 10**10

def menseki(h,w):
    global ans
    for i in range(1,h):
        # 縦1横2
        haba = w//2
        ans = min(ans,max(i*w,haba*(h-i),(w-haba)*(h-i))-min(i*w,haba*(h-i),(w-haba)*(h-i)))
        # 縦3分割
        if i == h-1:
            continue
        tate = (h-i)//2
        ans = min(ans,max(w*i,tate*w,(h-i-tate)*w)-min(w*i,tate*w,(h-i-tate)*w))

menseki(h,w)
menseki(w,h)

print(ans)

Measured memory_bytes: 3064
c = input()
s = ["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"]
for i  in range(26):
    if c == s[i]:
        if i == 25:
            print(s[0])
        else:
            print(s[i+1])
        break

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

string f[9] = {"',.!?", "abcABC", "defDEF", "ghiGHI",
                "jklJKL", "mnoMNO", "pqrsPQRS", "tuvTUV", "wxyzWXYZ"};
    
int main(){
    string s;
    while(cin >> s){
        int n = s.length();
        int index = 0;
        string res = "";
        while(index < n){
            char now = s[index];
            if(now == '0'){
                res += " ";
                index++;
            }else{
                int cnt = 0;
                while(index < n && now == s[index]) index++, cnt++;
                int x = now-'0'-1;
                res += f[x][(cnt-1)%(f[x].length())];
                if(s[index] == '0') index++;
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3084