akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
void print_line(vector<ll> &line) {
    for (int i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}

typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;

int main() {
    vector<int> count(26, 0);
    char c;
    while (cin >> c) {
        int j;
        if ('a' <= c && c <= 'z') {
            j = c - 'a';
        } else if ('A' <= c && c <= 'Z') {
            j = c - 'A';
        } else {
            continue;
        }
        count[j]++;
    }
    for (int i = 0; i < 26; i++) {
        char c = 'a' + i;

        printf("%c : %d\n", c, count[i]);
    }
}


Measured memory_bytes: 3132
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}


int main()
{

	long long int num;
	cin >> num;

	long long int ans = 0;
	
	ans = num / 11;
	ans *= 2;

	num %= 11;

	if (num > 6)ans += 2;
	else if(num > 0)ans += 1;
	
	cout << ans << endl;



	return 0;

}



Measured memory_bytes: 256
A, B, C = map(int, input().split())
ans = abs(A*B*(C//2) - A*B*((C+1)//2))
ans = min(ans, abs(A*C*(B//2) - A*C*((B+1)//2)))
ans = min(ans, abs(B*C*(A//2) - B*C*((A+1)//2)))
print(ans)


Measured memory_bytes: 3060
from collections import Counter

N = int(input())
S = input()
ans = 0

for i in range(1, N+1):
    X = S[:i]
    Y = S[i:]
    c = Counter(X)

    count = 0
    for j in c:
        if j[0] in Y:
            count += 1

    ans = max(count, ans)

print(ans)


Measured memory_bytes: 3316
#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()
{
    ll x;
    cin >> x;
    for (ll a = 0; a <= 120; a++) {
        for (ll b = -120; b <= 120; b++) {
            double d = pow(a, 5) - pow(b, 5);
            if (d == (double)x) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

#define I cin
#define O cout
#define EN endl
#define ln cout<<endl
#define pb(a) push_back(a)

typedef long long int llint;

int n;
int i, j;
llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int gcd(int a, int b)
{
  return (a % b ? gcd(b, a % b) : b);
}

int main()
{
  I >> n;

  int a[100001] = {};

  for(i = 0; i < n; i++) {
    I >> a[i];
  }

  sort(a, a + n, greater<int>());

  llint x = 0, y = 0;

  for(i = 0; i < n; i++) {
    if(!x && a[i] == a[i + 1]) {
      x = a[i];
      i++;
    } else if(x && !y && a[i] == a[i + 1]) {
      y = a[i];
      break;
    }
  }

  O << x * y << EN;
  
  return 0;
}


Measured memory_bytes: 640
N = int(input())
L = [int(l) for l in input().split(" ")]

count = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if len(set([L[i], L[j], L[k]])) != 3:
                continue
            ls = sorted([L[i], L[j], L[k]])
            if ls[-1] < sum(ls[:-1]):
                count += 1
print(count)

Measured memory_bytes: 9180
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;
#include <map>
#include <math.h>

using ll = long long;
using namespace std;

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    if (n==2) out("Borys");
    else if((b-a)%2==0) out("Alice");
    else out("Borys");
}

Measured memory_bytes: 256
module Main where

import Control.Monad
import Control.Applicative
import Data.List

showingList :: [Int] -> String
showingList (x:[]) = show x
showingList (x:xs) = (show x) ++ " " ++ (showingList xs)

solve :: Int -> String
solve x = if x >= 30 then "Yes" else "No"

main :: IO ()
main = do
    x <- readLn
    putStrLn $ solve x


Measured memory_bytes: 3816
#176-C

N = int(input())
shincho = list(map(int, input().split()))

sum = 0

for i in range(0, N):
  if i == 0:
    continue
  elif (shincho[i] - shincho[i-1]) < 0:
    sum += shincho[i-1] - shincho[i]
    shincho[i] = shincho[i-1]

print(sum)
    

Measured memory_bytes: 32188
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
	int N;
	ll A,B;
	cin >> N >> A >> B;

	vector<ll> h(N);
	for(int i = 0;i < N;i++)cin >> h[i];

	ll ng = 0;
	ll ok = 1e9;

	while(ok - ng > 1){
		ll mid = (ok + ng) / 2;//爆発させる回数
		ll cnt = 0;
		for(int i = 0;i < N;i++){
			cnt += max(0LL,(h[i] - B * mid + (A - B) - 1) / (A - B));
		}

		if(mid >= cnt)ok = mid;
		else ng = mid;
	}

	cout << ok << endl;
}


Measured memory_bytes: 4000
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt()
  val a = List.fill(N)(sc.nextInt())

  println(calc(N, a))

  def calc(N: Int, a: List[Int]) : Int = {
    a.sorted.foldLeft(0)((alice, bob) => bob - alice)
  }
}


Measured memory_bytes: 55548
#coding:utf-8
h, w = map(int, input().split())
s = [list(map(str, input().split())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == 'snuke':
            print(chr(ord('A')+j) + str(i+1))
            break


Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int maxn = 1e5+5;

LL w[maxn],v[maxn],dp[maxn];

int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i = 1; i <= n; i++) scanf("%lld %lld", &w[i],&v[i]);
	for(int i = 1; i <= n; i++){
		for(int j = m; j >= 0; j--){
			if(j >= w[i]) dp[j] = max(dp[j] , dp[j - w[i]] + v[i]);
		}
	}
	printf("%lld",dp[m]);
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  cout<<y1-y2+x2<<" "<<x2-x1+y2<<" "<<y1-y2+x1<<" "<<x2-x1+y1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main()
{
  int i,flag=1,A[N],n,ch,count=0;
  
  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  
  while(flag){
    flag=0;
    for(i=n-1; i>0; i--){
      if(A[i] < A[i-1]){
	ch=A[i];
	A[i]=A[i-1];
	A[i-1]=ch;
	count++;
	flag=1;
      }
    }
  }
  for(i=0; i<n-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
  printf("%d\n",count);
  return 0;
}



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

int N;
string S;

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

  int len = strlen(S.c_str());

  for (int i = 0; i < len; i++) {
    char c = S[i];
    char nc = (int)c + N;
    if (nc >= 91) {
      nc -= 26;
    }
    S[i] = nc;
  }

  cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int Nmax = 100010;
int N, M;
int p[Nmax];
int par[Nmax], depth[Nmax];
 
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		depth[i] = 0;
	}
}
 
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		par[x] = find(par[x]);
		return par[x];
	}
}
 
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
 
	if (depth[x] < depth[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (depth[x] == depth[y]) depth[x]++;
	}
}
 
int main() {
	cin >> N >> M;
	init(N + 1);
	for (int i = 1; i <= N; i++) cin >> p[i];
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		unite(x, y);
	}
 
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (find(i) == find(p[i])) ans++;
	}
 
	cout << ans << endl;
}

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

int main(){
    int num1, num2;
    cin >> num1 >> num2;
    while(num1 != 0 || num2 != 0){
        for(int i = 0; i < num1; ++i){
            for(int j = 0; j < num2; ++j){
                if(i == 0 || i == num1 - 1 || j == 0 || j == num2 - 1){
                    cout << "#";
                }
                else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
        cin >> num1 >> num2;
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS;
vector<ll> primes;ll prime[1000005];
void seive(){
    for(ll i=0;i<1000005;i++)prime[i]=1;
    for(ll i=2;i<1000005;i++){
        if(prime[i]){
        for(ll j=i*i;j<1000005;j+=i)
        prime[j]=0;}
    }
    for(ll i=2;i<1000005;i++)
    if(prime[i])primes.push_back(i);
}
ll fin(ll curr){
    ll l=1,r=100000,mid,num,ans;
    while(l<=r){

        mid=(l+r)/2;
        num=(mid*(mid+1))/2;
        if(l==mid){

            if(num<=curr)
            ans=l;
            num=(r*(r+1))/2;
            if(num<=curr)
            ans=r;
            // if(curr==1)cout<<ans<<" ";
            return ans;
        }
        if(num==curr)return mid;
        if(num<curr)
        l=mid+1,ans=mid;
        else
        r=mid-1;
    }
    return mid;
}
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        seive();
        ll n;cin>>n;
        map<ll,ll> mp;ll num;num=primes.size();ll res;
        for(ll i=0;i<num;i++){
            res=0;
            while(n%primes[i]==0){
                n/=primes[i];res++;
            }
            if(res)
            mp[primes[i]]=res;
        }
        if(n!=1)
        mp[n]++;
        ll sum=0,curr;
        for(auto it:mp){
            // cout<<it.first<<" "<<it.second<<" ";
            curr=fin(it.second);
            // cout<<curr<<endl;
            sum+=curr;
        }
        cout<<sum;
}


Measured memory_bytes: 12028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll M=1e9+7;
ll fact[100005];

int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	if(n-m>1 || m-n>1){
		cout << "0\n";
		return 0;
	}
	fact[0]=fact[1]=1;
	for(int i=2;i<=100000;i++){
		fact[i]=(fact[i-1]*i)%M;
	}
	if(m>n)
		swap(n,m);
	if(n==m)
		cout << (((fact[n]*fact[m])%M)*2)%M << endl;
	else
		cout << (fact[n]*fact[m])%M << endl;
	
	return 0;
}

Measured memory_bytes: 1024
fn main() {
    let n = getint();
    let n = n as usize;
    let mut a = vec![0; n];
    for x in 0..n {
        a[x] = getint();
    }
    let mut b = a.iter().zip(0..).collect::<Vec<_>>();
    b.sort();
    let mut sum = 0;
    let mut i = 0;
    for (_, num) in b {
        if i % 2 != num % 2 {sum += 1;}
        i += 1;
    }
    println!("{}", sum / 2);
}

fn next_line() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input
}


fn getint() -> i64 {
    let res = next_line();
    let res = res.trim().parse().unwrap();
    res
}

Measured memory_bytes: 7420
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

ll n,k;
vector<ll> A;

ll cul(ll l,ll m,ll r){
    vector<ll> B;
    ll sum=0;
    for(ll i=m;i<r;i++){
        sum+=A[i];
        B.push_back(sum);
    }
    sum=0;
    ll ret=0;
    sort(B.begin(),B.end());
    for(ll i=m-1;i>=l;i--){
        sum+=A[i];
        ret+=B.end()-lower_bound(B.begin(),B.end(),-sum);
    }
    return ret;
}



int main(){
    cin>>n>>k;
    A.resize(n);
    cin>>A;
    ll ans=0;
    for(auto &I:A){I-=k; if(I>=0){ans++;}}
    for(ll i=1;i<n;i<<=1){
        for(ll j=0;j+i<n;j+=2*i){
            ans+=cul(j,j+i,min(n,j+2*i));
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3316
#include <stdio.h>
#include <algorithm>

// 入力受付用の変数
#define BUF 200002
char str[BUF];

// 入力された値
#define LIM_A 100001
int N;
char S[BUF];

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d", &N);

	fgets(str, sizeof(str), stdin);
	sscanf(str, "%s", S);
}

void solve() {
	char c = S[0];
	int ans = 1;
	for (size_t i = 1; i < N; i++) {
		if (S[i] == c) {
			continue;
		}

		c = S[i];
		ans ++;
	}

	printf("%d\n", ans);
}


int main(void) {
	receive_input();

	solve();

	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
 
using namespace std;
 
int main(){
    int a,b;
    while(true){
        scanf("%d %d",&a,&b);
        if(a == 0 && b == 0) break;
        if(a > b) printf("%d %d\n",b,a);
        else{
            printf("%d %d\n",a,b);
        }
    }
}


Measured memory_bytes: 2768
# coding: utf-8
data = input().split(" ")

N = int(data[0])
A = int(data[1])
B = int(data[2])

total_sum = 0

for i in range(N+1):
    sum = 0
    tmp = i
    while tmp > 0:
        sum += tmp % 10;
        tmp = int(tmp/10)
    if sum >= A and sum <= B:
        total_sum += i

print(total_sum)
    

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	string s;
	cin>>s;
	map<char, int> mp;
	for(auto ch : s){
		mp[ch]++;
	}
	if(mp['N'] > 0 && mp['S'] == 0)cout<<"No"<<'\n';
	else if(mp['S'] > 0 && mp['N'] == 0)cout<<"No"<<'\n';
	else if(mp['E'] > 0 && mp['W'] == 0)cout<<"No"<<'\n';
	else if(mp['W'] > 0 && mp['E'] == 0)cout<<"No"<<'\n';
	else cout<<"Yes"<<'\n';

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
int bsr(int x) { return 31 - __builtin_clz(x); }

const int MM = 250100;
int R[MM];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
    int n;
    cin >> n;
    int x[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i]; x[i]--;
    }
    fill_n(R, n*n, -1);
    vector<int> lv, rv;
    for (int i = 0; i < n; i++) {
        R[x[i]] = i;
    }
    for (int i = 0; i < n*n; i++) {
        if (R[i] >= 0) {
            for (int j = 0; j < R[i]; j++) {
                lv.push_back(R[i]);
            }
        }
    }
    for (int i = n*n-1; i >= 0; i--) {
        if (R[i] >= 0) {
            for (int j = R[i]+1; j < n; j++) {
                rv.push_back(R[i]);
            }
        }
    }

    reverse(begin(lv), end(lv));
    reverse(begin(rv), end(rv));
    for (int i = 0; i < n*n; i++) {
        if (!lv.size()) break;
        if (R[i] == -1) {
            R[i] = lv.back();
            lv.pop_back();
        }
    }
    for (int i = n*n-1; i >= 0; i--) {
        if (!rv.size()) break;
        if (R[i] == -1) {
            R[i] = rv.back();
            rv.pop_back();
        }
    }

    int co[n];
    fill_n(co, n, 0);
    for (int i = 0; i < n*n; i++) {
        if (co[R[i]] == R[i]) {
            if (i != x[R[i]]) {
                cout << "No" << endl;
                return 0;
            }
        }
        co[R[i]]++;
    }
    cout << "Yes" << endl;
    for (int i = 0; i < n*n; i++) {
        cout << R[i]+1 << " ";
    } cout << endl;
    return 0;
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
int solve(vector<int>& costs) {
  int n = costs.size();
  if(n == 2)
    return abs(costs[1] - costs[0]);
  int prev1 = abs(costs[1] - costs[0]);
  int prev2 = 0;
  int curr;
  for(int i = 2; i < costs.size(); i++) {
    curr = min(abs(costs[i] - costs[i-1]) + prev1, abs(costs[i] - costs[i-2]) + prev2);
    prev2 = prev1;
    prev1 = curr;
  }
  return curr;
}

int main() {
  int n;
  cin>>n;
  vector<int> cost(n);
  for(int i = 0; i < n; i++) {
    cin>>cost[i];
  }
  cout<<solve(cost);
  return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int s, w; cin>>s>>w;

    cout << (w >= s ? "unsafe" : "safe") << endl;

    return 0;
}


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

#define N 2000002
#define NN 10

int num = 0;

void Defma(int *t, int i){
    int left, right;
    int  large, c;

    if( i * 2 + 1 < num + 1) right = i * 2 + 1;
    else right = i;
    if( i * 2 < num + 1) 
        left = i * 2;
    else left = i;

    if(left <= num && t[left] > t[i])
        large = left;
    else large = i;

    if(right <= num && t[right] > t[large])
        large = right;

    if(large != i){
        c = t[i];
        t[i] = t[large];
        t[large] = c;

        Defma(t, large);
    }
}

void Defin(int *arrayt, int z){
    int i,c;

    num++;
    i = num;
    arrayt[num] = z;

    while(i > 1 && arrayt[i/2] < arrayt[i]){

        c = arrayt[i];

        arrayt[i] = arrayt[i/2];

        arrayt[i/2] = c;
        i /= 2;
    }
}

void Defex(int *arrayt){

    printf("%d\n", arrayt[1]);

    if(num > 1) arrayt[1] = arrayt[num];

    num--;

    if(num > 1) Defma(arrayt, 1);
}

int main(){
    int i;
    int Arrayt[N];
    char Array[NN];

    while(1){
        scanf("%s", Array);

        if(Array[2] == 'd') break;
        else if(Array[0] == 'i'){
            scanf("%d", &Arrayt[0]);
            Defin(Arrayt, Arrayt[0]);
        }
        else Defex(Arrayt);
    }

    return 0; 
}




Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];
    sort(all(p), greater<ll>());
    sort(all(q), greater<ll>());
    sort(all(r), greater<ll>());

    priority_queue<ll, vector<ll>, greater<ll>> red, green;
    rep(i, x) red.push(p[i]);
    rep(i, y) green.push(q[i]);

    rep(i, c) {
        if (red.top() < green.top()) {
            red.push(r[i]);
            red.pop();
        } else {
            green.push(r[i]);
            green.pop();
        }
    }

    ll ans = 0;
    while (sz(red)) {
        ans += red.top();
        red.pop();
    }
    while (sz(green)) {
        ans += green.top();
        green.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 4852
#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>;

// 最大公約数を計算( gcd.cpp 参照)
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

// 最小公倍数を計算
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll l = lcm(c, d);
  ll total = b - a + 1;
  ll either = (b / c - (a - 1) / c) + (b / d - (a - 1) / d);
  ll both = b / l - (a - 1) / l;
  ll res = total - either + both;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i8[::1],)', cache=True)
def update(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, x in enumerate(A):
        l = max(0, i - x)
        r = min(N - 1, i + x)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1
    B = np.cumsum(B)
    return B

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

K = min(K, 100)
for _ in range(K):
    A = update(A)
print(' '.join(A.astype(str)))

Measured memory_bytes: 147904
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	ll n, c;
	cin >> n >> c;
	vector<ll> x(n), v(n);
	rep(i, n) cin >> x[i] >> v[i];
	ll ans = 0;
	ll sum = 0;
	vector<ll> rot(n);
	rep(i, n) {
		sum += v[i];
		if (i == 0) rot[i] = max(sum - x[i], 0LL);
		else rot[i] = max(sum - x[i], rot[i - 1]);
	}
	chmax(ans, rot[n - 1]);
	ll sum2 = 0;
	for (int i = n - 1; i >= 0; i--) {
		sum2 += v[i];
		ll val = sum2 - (c - x[i]) * 2;
		if (i > 0) val += rot[i - 1];
		chmax(ans, val);
	}
	rep(i, n) x[i] = c - x[i];
	reverse(all(x)); reverse(all(v));
	ll sum3 = 0;
	vector<ll> rot2(n);
	rep(i, n) {
		sum3 += v[i];
		if (i == 0) rot2[i] = max(sum3 - x[i], 0LL);
		else rot2[i] = max(sum3 - x[i], rot2[i - 1]);
	}
	chmax(ans, rot2[n - 1]);
	ll sum4 = 0;
	for (int i = n - 1; i >= 0; i--) {
		sum4 += v[i];
		ll val = sum4 - (c - x[i]) * 2;
		if (i > 0) val += rot2[i - 1];
		chmax(ans, val);
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3456
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

""" 
参考:http://drken1215.hatenablog.com/entry/2018/06/08/210000
maximとmodを適宜設定。
あ入力忘れを考慮してあえて入力例通らないようにしておいたで。

combを使う前にcominit()を使う

"""
maxim = 10**6 + 10
mod = 10**9+7
fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0

    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    x,y = map(int, input().split())
    if (x+y) % 3 != 0 or x/2 > y or y > 2*x:
        print(0)
        return

    # (x+y) // 3で何段目かわかる
    # パスカルの三角形で言うところのハジから何番目かがわかればいい

    # k段目の点は -x + 3*k上にある
    # 2*xが一番端にある
    
    k = (x+y) // 3
    # k段目の上端は (k, 2k)に存在する
    # 左から何番目かは2*k -yで求まる
    # 解は kC2*k-y

    cominit()
    m = (2*y-x)//3
    n = m+x-y
    
    print(com(m+n,n))

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 127664
#include <iostream>
#include <map>

using namespace std;

#define INF 1e9

int main() {
    int N;
    int num = 0;

    map<int, int> Map;

    cin >> N;

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

    for (auto it = Map.cbegin(); it != Map.cend(); ++it) {
        if (it->second % 2 != 0) {
            ++num;
        }
    }

    cout << num << endl;

    return 0;
}

Measured memory_bytes: 4864
N, M = map(int, input().split())
A = [int(input()) for i in range(M)]
A.append(N+1)

#import math
def fibonacci(n):
    #a = 1/math.sqrt(5) * (((1+math.sqrt(5))/2)**n - ((1-math.sqrt(5))/2)**n)
    if n <= 0:
        a = 0
    elif n<=2:
        a =1
    else:
        a0=1
        a1=1
        for i in range(3,n+1):
            a = a0 + a1
            a0 = a1
            a1 = a
    return(int(a))

ans = 1
t1 = 0
a_ind = 0
for i in range(N+1):
    if i == A[a_ind] or i == N:
        t2 = A[a_ind]
        ans *= fibonacci(t2-t1)
        t1 = A[a_ind]+1
        a_ind =min(a_ind+1, len(A)-1)
print(ans%1000000007)

Measured memory_bytes: 7048
#include <iostream>

int main() {
  int k, s, cnt = 0;
  std::cin >> k >> s;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      if (s - x - y >= 0) {
        if (s - x - y <= k) {
          cnt++;
        }
      } else {
        break;
      }
    }
  }
  std::cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 256
n,t = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = []
for i in range(n):
    if (a[i][1] <= t):
        ans.append(a[i][0])
if len(ans)==0:
    print("TLE")
else:
    print(min(ans))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
ll dist[100][100];
bool used[100][100];
main(){
    fill(dist[0],dist[100],INF);
    for(int i = 0;i < 100;i++)dist[i][i] = 0;
    int N,M;
    cin >> N >> M;
    for(int i = 0;i < M;i++){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        dist[a][b] = dist[b][a] = c;
        used[a][b] = used[b][a] = 1;
    }
    for(int i = 0;i < N;i++){
        for(int j = 0;j < N;j++){
            for(int k = 0;k < N;k++){
                if(dist[j][k] > dist[j][i] + dist[i][k]){
                    dist[j][k] = dist[j][i] + dist[i][k];
                    used[j][k] = used[k][j] = 0;
                }
            }
        }
    }
    int cnt = 0;
    for(int i = 0;i < N;i++)for(int j = 0;j < N;j++)cnt += used[i][j];
    cout << M - cnt/2 << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <fstream>
using namespace std;
const int M = 12;
int t[M],r[M];

void record_t (void )
{
	for (int i = 0; i < M; ++i){
		r[i] = t[i];
	} // end for
}

void restore_t (void )
{
	for (int i = 0; i < M; ++i){
		t[i] = r[i];
	} // end for
} 
	
int count_t (void )
{
	int res = 0;
	for (int i = 0; i < M; ++i){
		res += t[i];
	} // end for

	return res;
}

bool dfs (int row, bool head )
{
	if (row > 9 ){
		if (count_t() == 0 ){		
			return true;
		}else{
			return false;
		} // end if
	} // end if

	// is not hai?
	if (t[row] == 0 ){
		if (dfs (row+1, head ) ){
			return true;
		} // end if
	} // end if
	
	// is head ?
	if (!head && t[row] == 2 ){
		head = true;
		t[row] -= 2;
		if (dfs (row, head ) ){
			return true;
		} // end if
		t[row] += 2;
		head = false;
	} // end if

	// is kou-tu?
	if (t[row] == 3 ){
		t[row] -= 3;
		if (dfs (row + 1, head ) ){
			return true;
		} // end if
		t[row] += 3;
	} // end if

	// is dyun-tu?
	if (t[row] > 0 && t[row + 1] > 0 && t[row + 2] > 0 ){
		t[row]--; t[row + 1]--; t[row + 2]--;
		if (dfs (row, head ) ){
			return true;
		} // end if
		t[row]++; t[row + 1]++; t[row + 2]++;
	} // end if

	return false;
}	

int main()
{
//	cut here before submit 
//	freopen ("testcase.puzzle", "r", stdin );
	string str = "";

	while (getline (cin, str ) ){
		set <int> res;
		vector <int> pai (13, 0 );
		map <int, int> num;
		int i;

		for (i = 0; i < 13; ++i){
			pai[i] = str[i] - '0';
			++num[pai[i]];
		} // end for

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

		// make table with counting same number 
		memset (t, 0, sizeof(t ) );
		for (i = 1; i <= 9; ++i){
			 t[i] = num[i];
		} // end for

		for (i = 1; i <= 9; ++i){
			if (t[i] < 4 ){
				// record table
				record_t();

				++t[i];
				// decide whether puzzle complete or not
				if (dfs (1, false ) ){
					res.insert (i);
				} // end if

				// restore table
				restore_t();
			} // end if
		} // end for

		// printout result
		if (res.empty() ){
			cout << '0' << endl;
		}else{
			int size = res.size();
			set<int>::iterator itr = res.begin();
		 	for (i = 0; itr != res.end(); ++itr, ++i ){
				cout << (*itr);
				if (i != size - 1){
					cout << ' ';
				} // end if
			} // end for
			cout << endl;
		} // end if
	} // end while

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n, m, K, ans, flag, lgg, rgg, f[25005][405], g[25005][405], a[25005], aft[405], vis[405];
inline int pow(int x, int k) {
    int res = 1;
    for (;k;k >>= 1, x = 1LL * x * x % mod)
		if (k & 1)
			res = 1LL * res * x % mod;
    return res;
}
int main() {
	cin >> n >> K >> m;
    for (int i = 1; i <= m; i ++)
		cin >> a[i];
    for (int i = 1; i + K - 1 <= m; i ++) {
        int tot = 0;
        for (int j = 0; j < K; j ++)
			if (vis[a[i + j]] != i) {
				vis[a[i + j]] = i;
				tot ++;
			}
        if (tot == K) {
			flag = 1;
			break;
		}
    }
    ans = 1LL * pow(K, n - m) * (n - m + 1) % mod;
    if (flag)
		return 0 * printf("%d\n", ans);
    for (int i = 1; i <= m; i ++) if(vis[a[i]]!=n+1) vis[a[i]]=n+1; else {lgg=i;break;}
    for(int i=m;i>=1;--i) if(vis[a[i]]!=n+2) vis[a[i]]=n+2; else {rgg=i;break;}
    for(int i=1;i<K;++i) f[0][i]=1,g[0][i]=i;
    for(int i=1;i<=n;++i) for(int j=1;j<K;++j)
    {
        f[i][j]=(1LL*(K-j)*f[i-1][j+1]+g[i-1][j])%mod;
        g[i][j]=(g[i][j-1]+f[i][j])%mod;
    }
    for(int i=1;i+m-1<=n;++i)
        if(lgg) ans=(ans-1LL*f[i-1][lgg-1]*f[n-(i+m-1)][m-rgg]%mod+mod)%mod;
        else for(int j=i+m,p=1;j-i<K&&j<=n+1;++j)
        {
            ans=(ans-1LL*f[i-1][j-i]*(j>n?1:g[n-j][j-i])%mod*p%mod+mod)%mod;
            p=1LL*p*(K-m-(j-(i+m)))%mod;
        }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 79488
#include "bits/stdc++.h"
#include <chrono>
#include <random>
#include <cstdio>
#define ll long long int
#define endl '\n'
#define pb push_back
#define mp make_pair
// #define mod 998244353
#define rep(i,n) for(ll i=0;i<n;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define pll pair<ll, ll>
#define pint pair<int, int>
#define S second
#define F first
#define all(c) (c).begin(),(c).end()
using namespace std;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
const int N=500001;
// vector<pair<ll, ll> > adj[N];
// bool vis[N];
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
#define pi 3.14159265358979323846264338
using namespace std; 
ll max(ll a, ll b){ if(a>b)return a;return b;}
ll min(ll a, ll b){ if(a < b) return a;return b;}
ll inf = 100000000000000000;
vector <int> adj[N];

void solve() 
{
    int n;
    cin>>n;

    vector<pint> p, q;
    rep(i, n)
    {
        int a, b;
        cin>>a>>b;
        p.pb(mp(a, b));
    }

    rep(i, n)
    {
        int a, b;
        cin>>a>>b;
        q.pb(mp(a, b));
    }

    sort(all(p)), sort(all(q));

    int ans = 0;

    int taken[n];
    rep(i, n) taken[i] = 0;

    rep(i, n)
    {
        int curr = -1;
        int mx = INT_MIN;
        rep(j, n)
        {
            if(p[j].F < q[i].F && taken[j] == 0 && p[j].S < q[i].S)
            {
                if(p[j].S > mx)
                {
                    mx = p[j].S;
                    curr = j;
                }
            }
        }
        if(curr == -1) continue;
        ans++;
        taken[curr] = 1;
    }

    cout<<ans<<endl;
}

int main()
{
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)

    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        // cout<<'\n';
    }

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

string grid[6];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int h, w, k;
    cin >> h >> w >> k;
    for (int i=0; i<h; i++)
        cin >> grid[i];

    int ret = 0;
    for (int i=0; i<1<<h; i++)
        for (int j=0; j<1<<w; j++) {
            int cnt = 0;
            for (int r=0; r<h; r++)
                if (!(i & (1 << r)))
                    for (int c=0; c<w; c++)
                        if (!(j & (1 << c)))
                            cnt += (grid[r][c] == '#');
            ret += (cnt == k);
        }

    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 3568
# -*- coding:utf-8 -*-
import sys, re
flag = 'a'
def search(sentence):
    global flag
    flag = sentence[0]
    return sentence.replace(flag, '', 1)

S_a, S_b, S_c = (input(), input(), input())

while True:
    if flag == 'a':
        if len(S_a) == 0:
            print("A")
            sys.exit()
        S_a = search(S_a)
    elif flag == 'b':
        if len(S_b) == 0:
            print("B")
            sys.exit()
        S_b = search(S_b)
    else:
        if len(S_c) == 0:
            print("C")
            sys.exit()
        S_c = search(S_c)

Measured memory_bytes: 3316
#include <stdio.h>

int main(void) {

    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int i, count = 0;
    for (i = a; i <= b; ++i) {
        if (c % i == 0) {
            count++;
        }
    }
    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 596
import sys

sys.setrecursionlimit(10**6)

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

counter = 0
c = [-1 for i in range(n)]
p = [[] for n in range(n)]

for i in range(m):
    x, y, z = list(map(int, input().split()))
    x -= 1
    y -= 1
    p[x].append(y)
    p[y].append(x)

def dfs(num, depth):
    if c[num] != -1:
        return
    else:
        c[num] = depth
    for i in p[num]:
        dfs(i, depth)

for i in range(n):
    if c[i] == -1:
        counter += 1
        dfs(i, counter)

print(max(c))

Measured memory_bytes: 112508
# A - Red or Not

# 整数 a の入力
a = int(input())

# 文字列 s の入力
s = input()

# print(a)
# print(s)

if a >= 3200:
    # print(s)
    answer = s
else:
    # print('red')
    answer = 'red'

# 結果の出力
print(answer)


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


int dp__[100];

//最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp__[n] = 1;
  if(dp__[n] != -1) return dp__[n];
  return dp__[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  vector<int> v(5);
  rep(i, 5) cin >> v[i];
  int k;
  cin >> k;
  bool ans = true;
  if(abs(v[0] - v[1]) > k) ans = false; 
  if(abs(v[0] - v[2]) > k) ans = false; 
  if(abs(v[0] - v[3]) > k) ans = false; 
  if(abs(v[0] - v[4]) > k) ans = false; 
  if(abs(v[1] - v[2]) > k) ans = false; 
  if(abs(v[1] - v[3]) > k) ans = false; 
  if(abs(v[1] - v[4]) > k) ans = false; 
  if(abs(v[2] - v[3]) > k) ans = false; 
  if(abs(v[2] - v[4]) > k) ans = false; 
  if(abs(v[3] - v[4]) > k) ans = false; 

  if(ans) cout << "Yay!" << endl;
  else cout << ":(" << endl;
 

}




Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,k = LI()

    t = 0
    for _ in range(n-1):
        t = t * k // (k-1) + 1
    return t



print(main())




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

const int MAXN = 100005;

int n, a[MAXN];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	long long L = 2, R = 2;
	for (int i = n; i >= 1; i--) {
		R = R/a[i]*a[i]+a[i]-1;
		if (L%a[i] != 0) L = L/a[i]*a[i]+a[i];
	}
	if (L <= R)
		cout << L << " " << R << endl;
	else cout << "-1" << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  int x,y,h,w;
  int n;
  int ans;
  int s[6] = {60,80,100,120,140,160};
  int wh[6] = {2,5,10,15,20,25};
  while(cin >> n){
    if(n==0) break;
    ans = 0;
    for(int i=0;i<n;i++){
      cin >> x >> y >> h >> w;
      h = x + y + h;
      //cout << h << endl;
	for(int i=5;i>=0;i--){
	  if(i==0) h = 0;
	  else if(i==5&&s[i]<h){
	    h = 7;
	    break;
	  }
	  else if(s[i-1]<h&&h<=s[i]){
	    h = i;
	    break;
	  }
	}
	for(int i=5;i>=0;i--){
	  if(i==0) w = 0;
	  else if(i==5&&wh[i]<w){
	    w = 7;
	    break;
	  }
	  else if(wh[i-1]<w&&w<=wh[i]){
	    w = i;
	    break;
	  }
	}
	if(h<w) h = w;
	//cout << h << endl;
	switch(h){
	case 0:
	  ans += 600;
	  break;
	case 1:
	  ans += 800;
	  break;
	case 2:
	  ans+= 1000;
	  break;
	case 3:
	  ans += 1200;
	  break;
	case 4:
	  ans += 1400;
	  break;
	case 5:
	  ans += 1600;
	  break;
	}
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int x1, x2, x3, y1, y2, y3;
	x1 = y1 = 0;
	x2 = 1000000000;
	y2 = 1;

	Int S;
	cin >> S;

	y3 = S / 1000000000 + 1;
	x3 = 1000000000 - S % 1000000000;

	if (y3 == 1000000000 + 1) {
		cout << x1 << " " << y1 << " " << 1000000000 << " " << 0 << " " << x3 << " " << 1000000000 << "\n";
	}
	else cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << "\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

void solve() {
  int n;
  string s;
  int k;
  cin >> n >> s >> k;
  k--;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] != s[k]) cout << "*";
    else cout << s[i];
  }
  cout << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 256
def main(input = STDIN)
  maxv = 0
  maxa = 1 / 0.0
  input.gets.to_i.times do
    a, v = input.gets.split(" ").map(&:to_i)
    maxv, maxa = v, a if maxv < v or (maxv == v and maxa > a)
  end
  puts "#{maxa} #{maxv}"
end
main

Measured memory_bytes: 6104
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	string s;
	long long n;
	cin >> n;

	s = to_string(n);

	int ans = 0;
	for (auto c: s) {
		ans += c - '0';
	}

	int tmp = 0;
	tmp = (s.size() - 1) * 9 + (s[0] - '0') - 1;

	ans = max(ans, tmp);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        r = x
        
        while not self.par[r]<0:
            r = self.par[r]
        
        t = x
        
        while t!=r:
            tmp = t
            t = self.par[t]
            self.par[tmp] = r
        
        return r
    
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        
        if rx==ry:
            return
        
        if self.rank[rx]<=self.rank[ry]:
            self.par[ry] += self.par[rx]
            self.par[rx] = ry
            
            if self.rank[rx]==self.rank[ry]:
                self.rank[ry] += 1
        else:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

H, W = map(int, input().split())
S = [input()[:-1] for _ in range(H)]
uf = Unionfind(H*W)

for i in range(H):
    for j in range(W):
        if i+1<H and S[i][j]!=S[i+1][j]:
            uf.unite(W*i+j, W*(i+1)+j)
            
        if j+1<W and S[i][j]!=S[i][j+1]:
            uf.unite(W*i+j, W*i+j+1)

wcnt = defaultdict(int)
bcnt = defaultdict(int)

for i in range(H):
    for j in range(W):
        r = uf.root(W*i+j)
        
        if S[i][j]=='#':
            wcnt[r] += 1
        else:
            bcnt[r] += 1

ans = 0

for k in wcnt:
    ans += wcnt[k]*bcnt[k]

print(ans)

Measured memory_bytes: 72284
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

vector<int> ap;
int ans, res, n, l, r = 1e9;

int main() {
  cin >> n >> l;
  for (int i = 0; i < n; i++)
    	ap.push_back(i + l), ans += i + l;
  for (int i = 0; i < n; i++) {
    int d = ans - (i + l);
    if (r > abs(d - ans))
      res = d, r = abs(d - ans);
  }
  cout << res;
}

Measured memory_bytes: 256