akhauriyash/Code-Regression huggingface dataset:
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

fn gcd( a:u64, b:u64 ) -> u64 {
    if a < b {
        gcd(b,a)
    } else {
        let k = a/b;
        if a - k*b == 0 {
            b
        } else {
            gcd( b, a-k*b)
        }
    }
}



//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        s: Bytes,
        t: Bytes,
    }

    let g = gcd(n as u64,m as u64) as usize;
    let ng = n/g;
    let mg = m/g;
    for i in 0..g {
        if s[i*ng] != t[i*mg] {
            println!("-1");
            return;
        }
    }
    println!("{}", ng*mg*g);
}


Measured memory_bytes: 2416
#include<iostream>
#include<queue>

using namespace std;


int main() {
	
	int n;
	cin >> n;
	queue<int> qe[n];
	
	int n2;
	cin >> n2;
	
	int choice;
	int temp, temp2;
	
	for(int i=0;i<n2;i++) {
		
		cin >> choice;
		
		switch(choice) {
			
			case 0:
				cin >> temp >> temp2;
				qe[temp].push(temp2);
				break;
				
			case 1:
				cin >> temp;
				
				if(qe[temp].size() == 0)
					break;
					
				else
					cout << qe[temp].front() << "\n";
					
				break;
				
			case 2:
				cin >> temp;
				
				if(qe[temp].size() == 0)
					break;
				
				else
					qe[temp].pop();
		}
		
	}
	
	return 0;
}


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

using P = pair<long long, long long>;
//[l, r)
P separate2(int l, int r, const vector<long long> &sum) {
    long long m = (sum.at(r) - sum.at(l)) / 2;

    int ng = r;
    int ok = l;

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (m < sum.at(r) - sum.at(mid)) ok = mid;
        else ng = mid;
    }

    long long min_diff = 1e+15;
    int sep = ok;
    for (int i = -5; i <= 5; i++) {
        int ni = ok + i;
        if (l <= ni && ni < r) {
            long long d = abs((sum.at(r) - sum.at(ni)) - (sum.at(ni) - sum.at(l)));
            if (d < min_diff) {
                min_diff = d;
                sep = ni;
            }
        } 
    }

    return P(sum.at(r) - sum.at(sep), sum.at(sep) - sum.at(l));
}

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }

    vector<long long> sum(n + 1);
    for (int i = 0; i < n; i++) {
        sum.at(i + 1) = sum.at(i) + a.at(i);
    }

    long long mini = 1e+15;
    for (int i = 2; i <= n - 2; i++) {
        P p1 = separate2(0, i, sum);
        long long p = p1.first, q = p1.second;
        P p2 = separate2(i, n, sum);
        long long r = p2.first, s = p2.second;

        mini = min(mini, max({p, q, r, s}) - min({p, q, r, s}));
    }

    cout << mini << endl;
}

Measured memory_bytes: 3328
import itertools

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

combs = list(itertools.combinations(l, 3))
cnt = 0
for comb in combs:
    a = comb[0]
    b = comb[1]
    c = comb[2]
    if a == b or b == c or c == a:
        continue
    if a + b > c and b + c > a and c + a > b:
        cnt += 1
print(cnt)

Measured memory_bytes: 86740
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int k = sc.nextInt();
        long[] a = new long[x];
        long[] b = new long[y];
        long[] c = new long[z];
        for (int i = 0; i < x; i++)
            a[i] = sc.nextLong();
        for (int i = 0; i < y; i++)
            b[i] = sc.nextLong();
        for (int i = 0; i < z; i++)
            c[i] = sc.nextLong();
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        long[] ab = new long[x * y];
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                int pos = (i * y) + j;
                ab[pos] = a[i] + b[j];
            }
        }
        sc.close();
        Arrays.sort(ab);
        long[] abc = new long[3000 * z];
        for (int i = 0; i < Math.min(3000, x * y); i++) {
            for (int j = 0; j < z; j++) {
                int pos = (i * z) + j;
                abc[pos] = ab[(x * y) - 1 - i] + c[j];
            }
        }
        Arrays.sort(abc);
        for (int i = 0; i < k; i++) {
            System.out.println(abc[(3000 * z) - 1 - i]);
        }
    }
}

Measured memory_bytes: 60792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int k; cin>>k;
    int ans[k]; rep(i,k) ans[i]=INF;
    deque<pair<int,int>> dq;
    dq.push_front({1,1});
    while(dq.size()){
        auto e=dq.front(); dq.pop_front();
        int cost=e.first,num=e.second;
        if(cost<ans[num]){
            ans[num]=cost;
            dq.push_front({cost,(num*10)%k});
            dq.push_back({cost+1,(num+1)%k});
        }
    }
    cout<<ans[0]<<endl;
    return 0;
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  vector<double> v(n);
  rep(i,n) cin>>v.at(i);
  sort(v.begin(),v.end());
  double ans=v.at(0);
  rep(i,n-1) ans=(ans+v.at(i+1))/2;
  cout<<ans<<endl;   
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

ll num[10][10];

int main()
{
	int N;
	ll ans = 0;

	cin >> N;

	repc(i, 1, N) {
		int a, b, n = i;

		if (n % 10 == 0) continue;

		b = n % 10;
		while (n >= 10) n /= 10;
		a = n;
		num[a][b]++;
	}

	repc(a, 1, 9) repc(b, 1, 9) {
		ans += num[a][b] * num[b][a];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
data = input().split()
N = int(data[0])
M = int(data[1])
C = int(data[2])

B = []
A = []
cnt = 0

data = input().split()
for lop in range(M):
    B.append( int(data[lop]) )

for lop in range(N):
    data = input().split()
    hantai = 0
    for lop2 in range(M):
        hantai += B[lop2] * int(data[lop2])
    hantai += C
    if hantai > 0 :
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;

int main() {
	int n,k;
	cin >> n>>k;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	vector<int> d(n,1e+9);
	d[0] = 0;
	d[1] = abs(h[0] - h[1]);

	rep2(i, 2, n) {
		int start = max(0, i - k);
		rep2(j, start, i ) {
			d[i] = min(abs(h[i] - h[j])+d[j], d[i]);
		}
	}
	cout << d[n - 1] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++) cin >> a[i];
    a[0]-=1;
    for(ll i=0;i<n-1;i++){
        if(a[i]<a[i+1]) a[i+1]-=1;
    }

    for(ll i=1;i<n;i++){
        if(a[i-1]>a[i]){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 1024
if __name__ == "__main__":
    n = int(input())
    arr = list(map(int,input().split(" ")))
    dp = [float("inf")]*len(arr)
    dp[0] = 0
    cost = 0
    for i in range(len(arr)):
        for jump in range(i+1,i+3):
            if(jump<len(arr)):
                dp[jump] = min(dp[jump],dp[i]+abs(arr[jump]-arr[i]))
                # print(dp,jump,i)
    print(dp[-1])

Measured memory_bytes: 13928
#define DEBUG 0

/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-11 21:17:11
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int R, G, B, N;

int main()
{
  cin >> R >> G >> B >> N;
  int ans = 0;
  for (auto i = 0; i <= N; i++)
  {
    for (auto j = 0; j <= N; j++)
    {
      int x = N - R * i - G * j;
      if (x >= 0 && x % B == 0)
      {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	int l,ans=0;
	cin >> s >> t;
	l=s.length();
	for(int i=0;i<l;i++)
	{
		if((s[i]!=t[i]))
		ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3848
inf = float('inf')

N, K, Q = map(int, input().split())
a = tuple(map(int, input().split()))

ans = inf
for ma in sorted(set(a)):
    res = []
    seq = 0
    for i in range(N):
        if a[i] >= ma:
            # 最小値以上の要素は部分列に含めてよい
            seq += 1
        else:
            # 最小値未満の要素が来たら、
            # それまでの部分列を処理する
            if seq >= K:
                res.extend(sorted(a[i - seq:i])[:seq - K + 1])
            seq = 0
    if seq >= K:
        res.extend(list(sorted(a[-seq:]))[:seq - K + 1])
    seq = 0
    if len(res) < Q: continue
    res.sort()
    ans = min(ans, res[Q - 1] - ma)
print(ans)


Measured memory_bytes: 3316
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize ("trapv") // kills the program on integer overﬂows (but is really slow).
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;

#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define vt vector
#define vll vt<ll>
#define pll pair<ll,ll>
#define vpll vt<pll>
#define vvll vt<vll>
#define all(v) v.begin(),v.end()
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define go_t int testcases; cin>>testcases; ffo(caseno,1,testcases)

#define ctime auto start = high_resolution_clock::now()
#define etime auto stop = high_resolution_clock::now()
#define ptime auto z1z = duration_cast<microseconds>(stop-start); cout<<"Time elapsed : "<<z1z.count()<<" microseconds\n"

#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

const ll mod = 1e9 + 7;
const ll N = 3e3 + 6;
const ll maxN = 1e4 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = mod) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in4.txt", "r", stdin);
	freopen("out3.txt", "w", stdout);
#endif
	FIO
	ll n;
	cin >> n;
	vll a(n);
	FOR(i, n) cin >> a[i];
	if (n <= 2) {
		cout << 0; return 0;
	}
	ll ans = 0;
	for (int i = 0; i < n - 2; ++i) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; ++k) {
				if (a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i]  && a[i] != a[j] && a[j] != a[k] && a[i] != a[k]) {
					++ans;
					// dbg3(i, j, k);
				}
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<algorithm> 
using namespace std;
int n,B[100005],a[100005],len;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    B[1]=-a[1],len=1;
    for(int i=2;i<=n;i++)
    {
        if(-a[i]>=B[len]) B[++len]=-a[i];
        else
        {
            int pos=upper_bound(B+1,B+len,-a[i])-B;
            B[pos]=-a[i];
        }
    }
    cout<<len<<endl;
}

Measured memory_bytes: 1024
n=int(input())

for i in range(1,n+1):
    x=i
    int(x)
    if x%3==0 :
        print(" %d" % i, end="")
    else:
        while x:
            if int(x)%10==3:
                print(" %d" % i, end="")
                break
            else :
                x/=10
print()



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

int n;

int main(){
  cin >> n;
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    while(a % 2 == 0){
      a /= 2; ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define ALL(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main(){
	int N;
	cin >> N;
	cout << ((N > 1) ? (N * (N + 1) / 2) : 1) << endl;
}

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

using namespace std;

#define MAX 2401

int makeTime(int a, int b){
  int ah, bh, am, bm;
  am = a % 100; a /= 100;
  ah = a;

  bm = b % 100; b /= 100;
  bh = b;
 
  int diff_h = bh - ah;
  int diff_m = bm - am;
  if(diff_m < 0){
    diff_m += 60;
    diff_h--;
  }
  return diff_h*60 + diff_m;
}

int main(){
  int N, P, Q, K, p, q;

  while(cin >> N >> P >> Q, (N | P | Q)){
    bool watch[MAX];
    memset(watch, false, sizeof(watch));
    for(int i = 0 ; i < N ; i++){
      cin >> K;
      vector<int> vec; 
      vec.push_back(P);
      for(int j = 0 ; j < K ; j++){
        cin >> p >> q;
        vec.push_back(p);
        vec.push_back(q);
      }
      vec.push_back(Q);
      for(int j = 0 ; j < (int)vec.size() ; j+=2){
        for(int k = vec[j] ; k <= vec[j+1] ; k++){
          watch[k] = true;
        }
      }
    }
    int max = 0, cnt = P-1, prev = P, pos;
    for(int i = P ; i <= Q ; i++){
      if(i % 100 >= 60){ 
        cnt++; 
        continue;
      }
      if(watch[i]){
        cnt++;
        pos = i;
      }else{
        while(!watch[i] || i % 100 >= 60) i++;
        max = std::max(max, makeTime(prev,cnt));
        prev = i;       
        cnt = i;
      }
    }

    max = std::max(max, makeTime(prev, cnt));
    cout << max << endl;
  }

  return 0;
}

Measured memory_bytes: 1220
H, W, K = gets.chomp.split(' ').map(&:to_i)
MOD = 1_000_000_007
dp = Array.new(H + 1) { Array.new(W, 0) }
dp[0][0] = 1
(0...H).each do |i|
  (0...W).each do |j|
    (0...(1 << (W - 1))).each do |k|
      ok = (0..(W - 1 - 1)).all? do |bi|
        k[bi] == 0 || k[bi + 1] == 0
      end
      next unless ok
      if j >= 1 && k[j - 1] == 1
        dp[i + 1][j - 1] += dp[i][j]
      elsif j < W - 1 && k[j] == 1
        dp[i + 1][j + 1] += dp[i][j]
      else
        dp[i + 1][j] += dp[i][j]
      end
    end
  end
end
puts dp[H][K - 1] % MOD


Measured memory_bytes: 2172
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<ll> x(n), y(n);
	rep(i, n) cin >> x[i] >> y[i];
	ll j_ans = inf;
	if (n == 1) {
		dunk(1);
		return 0;
	}
	rep(i, n) {
		rep(j, n) {
			if (i == j) continue;
			ll nx = x[i] - x[j], ny = y[i] - y[j];
			ll ans = 0;
			rep(k, n)rep(l, n) {
				if (k == l) continue;
				if (x[k] - x[l] == nx && y[k] - y[l] == ny) ans++;
			}
			j_ans = min(j_ans, n - ans);
		}
	}
	dunk(j_ans);
	return 0;
}


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

int main(){
  string s, t;
  cin >> s;
  cin >> t;
  string ans = "Yes";
  
  if(s.size()+1 != t.size()) ans = "No";
  rep(i, s.size()) if(s[i] != t[i]) ans = "No";
  
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[4],b[4],d,k;
    for(int i=0;i<4;i++){
        cin>>a[i];
    }
    for(int i=0;i<4;i++){
        cin>>b[i];
    }
    d=a[0]+a[1]+a[2]+a[3];
    k=b[0]+b[1]+b[2]+b[3];
    if(d>k){cout<<d<<endl;}
    if(d<k){cout<<k<<endl;}
    if(d==k){cout<<d<<endl;}

}

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


vector<ll> fact(200010,1);
vector<ll> pow_m(200010,1);


// a^n%mod
template<class T=int64_t>
T bin_pow(T a,T n,T mod=mod1){
    T ans=1;
    while(n>0){
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans%mod;
}

//a^(-1)(mod)=a^(mod-2)
template<class T=int64_t>
T inv_mod(T a,T mod=mod1){
  return bin_pow(a,mod-2);
}

// //a!%mod
// template<class T=int64_t>
// T fact(T a,T mod=mod1){
//     T ans=1;
//     for(int i=2;i<=a;++i){
//         ans=ans*i%mod;
//     }
//     return ans;
// }

//nCr%mod
template<class T=int64_t>
T comb(T n,T r,T mod=mod1){
    return fact[n]*inv_mod(fact[r]*fact[n-r]%mod)%mod;
}

int main()
{
  ll n,m,k;
  cin>>n>>m>>k;
  for (int i = 0; i < fact.size()-1; ++i)
  {
    fact[i+1]=fact[i]*(i+1);
    fact[i+1]%=mod1;
    pow_m[i+1]=(m-1)*pow_m[i]%mod1;
  }

  
  vector<ll> n_1Ck(k+1);
  for (ll i = 0; i < k+1; ++i)
  {
    n_1Ck[i]=comb(n-1,i)%mod1;
  }
  ll ans=0;
  for (ll i = 0; i <= k; ++i)
  {
    ans+=(n_1Ck[i]*(m*pow_m[n-1-i]%mod1))%mod1;
    ans%=mod1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 7940
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int c[6], yen[6] = { 1,5,10,50,100,500 };
//---------------------------------------------------------------------------------------------------
void _main() {
    rep(i, 0, 6) cin >> c[i];

    int sm = 0;
    rrep(i, 5, 0) if(sm < 1000) {
        int d = 1000 - sm;
        int use = min(c[i], d / yen[i]);
        sm += use * yen[i];
    }

    if (sm == 1000) cout << "1" << endl;
    else cout << "0" << endl;
}



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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,k;
    cin >> n >> k;
    ANS((n - 1 + k - 1 - 1) / (k - 1));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int p;
vector<int> m(3);

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

    REP(i,n) {
        cin>>p;
        if (p <= a) {
            m[0]++;
        } else if (p <= b) {
            m[1]++;
        } else {
            m[2]++;
        }
    }

    cout<<*MIN_ELEMENT(m)<<endl;

    return 0;
}


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

ll lpow(ll z, int p){
  ll a = 1;
  rep(i, p){
    a *= z;
  }
  return a;
}

int main()
{
  ll n, m,ans = 0;
  int p;
  cin >> n;
  if(n == 1){
    cout << 0 << endl;
    return 0;
  }
  m = n;
  m = sqrt(m);
  int cnt;
  map<int, int> mp;
  
  int i = 2;

  for(i = 2; i <= m; i++){
    cnt = 0;
    p = 1;
    while(n % i == 0){
        n = n / i;
        cnt++;
        if(cnt == p){
          //cout << p << " " << ans << " " << n << endl;
          p++;
          ans++;
          cnt = 0;
        }
    }
  }
  
  if(n > 1){
    ans++;
  }
    

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



Measured memory_bytes: 3732
#include <stdio.h>

int main(){
	int a, b, ans;
	char c;
	while (1){
		scanf("%d %c %d", &a, &c, &b);
		if (c =='+'){
			ans = a + b;
		}
		else if (c =='-'){
			ans = a - b;
		}
		else if (c == '*'){
			ans = a*b;
		}
		else if (c == '/' ){
			ans = a / b;
		}
		else if (c == '?' ){
			break;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
// dp[i][k] (k=>{0, 1, 2}) is the maximum happiness uptil i th day when he last did the kth activity
void solve()
{
    ll n;
    cin>>n;
    vector<vl> vect(n, vl(3, 0));
    forr(i, n)
    {
    	cin>>vect[i][0]>>vect[i][1]>>vect[i][2];
    }
    vector<vl> dp(n, vl(3, 0));
    dp[0][0]=vect[0][0];
    dp[0][1]=vect[0][1];
    dp[0][2]=vect[0][2];
    forr1(i, n-1)
    {
    	dp[i][0]=max(dp[i-1][1]+vect[i][0], dp[i-1][2]+vect[i][0]);
    	dp[i][1]=max(dp[i-1][0]+vect[i][1], dp[i-1][2]+vect[i][1]);
    	dp[i][2]=max(dp[i-1][0]+vect[i][2], dp[i-1][1]+vect[i][2]);
    }
    cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]})<<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);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 14196
#include<iostream>

using namespace std;

int main()
{
	int n[32] = {}, m[32]={};
	for (int i = 1; i <= 29; i++) {
		cin >> m[i];
		n[m[i]] = 1;
	}
	for (int i = 1; i <= 30; i++) {
		if (n[i] == 0) {
			if (i == 0) continue;
			cout << i << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

class Main {
    private static void solve() {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            int n = scanner.nextInt();
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            if (n == 0 && a == 0 && b == 0) {
                break;
            }
            int total = 0;
            for (int i = 0; a * i <= n; i++) {
                if (i > 0 && a * i % b == 0) {
                    break;
                } else {
                    total += (n - a * i) / b + 1;
                }
            }
            System.out.println(n - total + 1);
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 12000
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      string[] input = ReadLine().Split();
      int n = int.Parse(input[0]);
      int x = int.Parse(input[1]);
      List<int> m = new List<int>();
      
      for (int i=0;i<n;i++)
      {
        m.Add(int.Parse(ReadLine()));
      }
      WriteLine(m.Count+(x-m.Sum())/m.Min());
    }
}

Measured memory_bytes: 28320
#include<bits/stdc++.h>
    using namespace std;
    #define rep(i, n) for (int i = 0; i < (int)(n); i++)
    using LL = long long;
    using p = pair<int,int>;
    const LL MX = 2000000;
     
    int main(){
    	int n, m;
    	cin >> n >> m;
    	int ans = 0;
    	if(n>=2) ans += n*(n-1)/2;
    	if(m>=2) ans += m*(m-1)/2;
    	cout << ans << endl;
     
     
    }
     

Measured memory_bytes: 3596
N = int(input())

print(0)
MorF = input()
if MorF == 'Vacant':
    exit()

iSt = 1
iEn = N - 1
seat = MorF
while True:
    iMid = (iSt + iEn) // 2

    print(iMid)
    MorF = input()
    if MorF == 'Vacant':
        break

    if MorF == seat:
        if (iMid - iSt) % 2:
            iSt = iMid + 1
            seat = MorF
        else:
            iEn = iMid - 1
    else:
        if (iMid - iSt) % 2:
            iEn = iMid - 1
        else:
            iSt = iMid + 1
            seat = MorF


Measured memory_bytes: 3660
#include <stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)

int main(void)
{
	int a,b,i;
	scanf("%d %d",&a,&b);
	printf("%d",a-b+1);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll sum[252521];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n;
  ll a[252521];
  cin>>n;
  REP(i, n){
    cin>>a[i];
    sum[i+1]=sum[i]+a[i];
  }
  ll ans=1e18;
  REP(i, n){
    if(sum[i+1]*2<sum[n]){
      CHMIN(ans, (sum[n]-sum[i+1])-sum[i+1]);
    }
    else{
      CHMIN(ans, sum[i+1]-(sum[n]-sum[i+1]));
    }
  }
  cout<<ans<<'\n';
  return 0;
}


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

int main(){
int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;++i){
  cin >> a[i];
  }
  for(int r =0;r<100;r++){
  for(int i=0;i<n;++i){
  if(a[i]%2 == 0){a[i]=a[i]/2;
  }else{
    cout << r << endl;
    return 0;}
    }
  }
}

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

using namespace std;

#define pos first
#define jumps second

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    int n , m;
    string s;
    cin >> n >> m >> s;

    deque<pair<int , int> > dq;
    dq.push_back({n , 0});

    vector<int> par(n + 1);
    for (int i = n - 1 ;i >= 0 ;i--) {
        if (s[i] == '1') continue;

        while (dq.size() && dq.back().pos - i > m)
            dq.pop_back();

        while (dq.size() > 1 && dq[dq.size() - 2].jumps == dq.back().jumps)
            dq.pop_back();

        if (dq.empty()) {
            cout << -1;
            return 0;
        }

        par[i] = dq.back().pos;
        dq.push_front({i , dq.back().jumps + 1});
    }

    int cur = 0;
    while (cur != n) {
        cout << par[cur] - cur << ' ';
        cur = par[cur];
    }
}


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

using namespace std;

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

long long D;
map<long long, long long> dp[30][2][2][2];

bool read() {
    if (!(cin >> D))
        return false;

    return true;
}

int getlen(long long D) {
    int res = 0;
    for (; D > 0; D /= 10, ++res) { }
    return res;
}

long long dfs(int len, long long D, int start, int tr, int first) {
    auto res = 0ll;

    if (getlen(D) > len + 1)
        return dp[len][start][tr][first][D] = res;

    if (dp[len][start][tr][first].count(D))
        return dp[len][start][tr][first][D];

    if (len == 1) {
        for (int a = first; a < 10; ++a)
            if ((a + D) % 10 == a)
                res += tr * ((a + D) / 10 != 0) + (1 - tr) * ((a + D) / 10 == 0);

        return dp[len][start][tr][first][D] = res;
    }

    if (len == 2) {
        for (int a = (first ? 10 : 0); a <= 99; ++a)
            if ((a + D) % 100 == 10 * (a % 10) + a / 10)
                res += tr * ((a + D) / 100 != 0) + (1 - tr) * ((a + D) / 100 == 0);

        return dp[len][start][tr][first][D] = res;
    }

    auto dlen = getlen(D);
    auto d0 = D;

    for (int i = 0; i < len - 1; ++i)
        d0 /= 10;

    auto dn = D % 10;

    if (d0 >= 10) {
        if (d0 == 10) {
            d0 = 9;
            dn = 10;
            --D;
        } else {
            return 0;
        }
    }

    auto D1 = D;
    auto T = 1ll;

    for (int i = 0; i < len - 1; ++i)
        T *= 10ll;

    D1 %= T;
    D1 /= 10;

    for (int a = first; a < 10; ++a) {
        int b = (10 + a - dn) % 10;

        if (a > b && start)
            continue;

        if ((a + d0) % 10 == b) {
            if ((tr && a + d0 < 10) || (!tr && a + d0 >= 10))
                continue;

            res += dfs(len - 2, D1 + (b + dn) / 10, (start & (a == b)), 0, 0);
        } else if ((a + d0 + 1) % 10 == b) {
            if ((tr && a + d0 + 1 < 10) || (!tr && a + d0 + 1 >= 10))
                continue;

            res += dfs(len - 2, D1 + (b + dn) / 10, (start & (a == b)), 1, 0);
        }
    }

    return dp[len][start][tr][first][D] = res;
}

int solve() {
    auto ans = 0ll;

    for (int len = 0; len <= 2 * getlen(D); ++len) {
        for (int i = 0; i < 30; ++i)
            for (int j1 = 0; j1 < 2; ++j1)
                for (int j2 = 0; j2 < 2; ++j2)
                    for (int j3 = 0; j3 < 2; ++j3)
                        dp[i][j1][j2][j3].clear();

        ans += dfs(len, D, 1, 0, 1);
    }

    cout << ans << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int d[100][100];
int main() {
	int N,M;
	cin>>N>>M;
	rep(i,N)rep(j,N){
		d[i][j] = 0;
	}
	rep(i,M){
		int a,b;
		cin>>a>>b;
		a--;b--;
		d[a][b] = d[b][a] = 1;
	}
	/*
	昇順にソート済みのvector（またはstring）を入れると
	辞書順で次の並びのvectorに置き換えてくれる
	辞書順最後になったら -1 を返し止まる
	*/
	vector<int> v;
	rep(i,N){
		v.push_back(i);
	}
	sort(all(v));
	int ans = 0;
	do{
		int cnt = 0;
		for (int i = 0; i < N-1; ++i){
			if(d[v[i]][v[i+1]])cnt++;
		}
		if(v[0] == 0&&cnt == N-1){
			ans++;
			/*print(v);*/
		}
	}while(next_permutation(all(v)));
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,x) for(int i=head[x];i+1;i=nxt[i])
using namespace std;
const int N=200005;
typedef long long ll;
ll sum[N],a[N],pre[N];
inline ll ab(ll x){return x<0?-x:x;}
int main()
{
	int n;scanf("%d",&n);
	rep(i,1,n){scanf("%lld",&a[i]);pre[i]=pre[i-1]+a[i];}
	ll ans=1e18;
	rep(i,1,n-1)ans=min(ans,ab(pre[i]*2ll-pre[n]));
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll poc(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n;cin>>n;
    ll m=0;
    while(Pow(2,m)-1<=n)m++;
    vector<ll> ans;
    ll sa=n-(Pow(2,m-1)-1);
    vector<ll> v[m];
    ll now=m;
    while(sa>0){
        ll sum=1;
        rep(i,1,m+1){
            if(sum+Pow(2,i-1)>sa){
                v[i-1].push_back(now);
                sa-=sum;
                now++;
                break;
            }
            else sum+=Pow(2,i-1);
        }
    }
    rep(i,0,m){
        sort(v[i].begin(),v[i].end(),greater<ll>());
        if(i>0)ans.push_back(i);
        rep(j,0,v[i].size())ans.push_back(v[i][j]);
    }
    rep(i,1,now)ans.push_back(i);
    cout<<ans.size()<<endl;
    rep(i,0,ans.size())cout<<ans[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
int a[300000];
int main()
{
        IO;
        int i, n, j, k, mx=0;
        cin>>k>>n;
        for(i=1; i<=n; i++)
        {
            cin>>a[i];
            if(i!=1){
                mx=max(mx,a[i]-a[i-1]);
            }
        }
        mx=max(a[1]+k-a[n],mx);
        cout<<k-mx<<endl;
    return 0;
}


Measured memory_bytes: 1024
def main():
    n=int(input())
    A=list(map(int,input().split()))
    A.sort(reverse=True)
    if n%2==0:
        ans=sum(A[:(n+1)//2])*2-A[0]
    else:
        ans=sum(A[:(n+1)//2])*2-A[0]-A[n//2]
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 94108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(ll a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int n; cin >> n;
    ll a[n];
    inarray(a,n);
    ll sum_even = 0, sum_odd = 0, ans_even = 0, ans_odd = 0;
    for(int i = 0; i < n; i++){
        sum_even += a[i]; /* 偶数番目を正にする */
        sum_odd += a[i]; /* 奇数番目を正にする */
        if(i%2 == 0){
            /* 偶数番目 */
            if(sum_even <= 0){
                /* + */
                ans_even += abs(1-sum_even);
                sum_even = 1;
            }
            if(sum_odd >= 0){
                /* - */
                ans_odd += abs(-1-sum_odd);
                sum_odd = -1;
            }
        }else{
            /* 奇数番目 */
            if(sum_even >= 0){
                /* - */
                ans_even += abs(-1-sum_even);
                sum_even = -1;
            }
            if(sum_odd <= 0){
                /* + */
                ans_odd += abs(1-sum_odd);
                sum_odd = 1;
            }
        }
    }
    cout << min(ans_even, ans_odd) << endl;
    return 0;
}

Measured memory_bytes: 1024
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef unsigned long ul;
const ul INF = 1LL<<60;
string S,T;
long i,j,len1,len2;
bool is_ok,is_match;
inline void solve(){
  IN2(S,T);
  len1=S.size();
  len2=T.size();
  is_ok=false;
  DW(i,len1-len2,0){
    is_match=true;
    REP(j,len2){
      if(S[i+j]!=T[j]&&S[i+j]!='?'){
        is_match=false;
        break;
      }
    }
    if(is_match){
      REP(j,len2){
        S[i+j]=T[j];
      }
      REP(j,len1){
        if(S[j]=='?')S[j]='a';
      }
      is_ok=true;
      break;
    }
  }
  if(is_ok) OUT(S);
  else OUT("UNRESTORABLE");
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#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;
typedef pair<int,int> P;
const int maxq = 50;
const int maxn = 10;
int n,m,q;
int a[maxq],b[maxq],c[maxq],d[maxq];
int A[maxn];
vector<int> answer;

void dfs(int depth, int last, int A[]){
    if(depth == n){
        int ans = 0;
        REP(k,q){
            if(A[b[k]-1] - A[a[k]-1] == c[k]){
                ans+= d[k];
            }
        }
        answer.push_back(ans);

        return;
    }
    FOR(i,last,m+1){
        A[depth] = i;
        dfs(depth+1,i,A);
    }
}

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    cin >>n>>m>>q;
    REP(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    dfs(0,1,A);

    int ans = *max_element(ALL(answer));
    /*REP(i,answer.size()){
        if(answer[i] != 0)
        cout << answer[i] << endl;
    }*/
    cout << ans << endl;
}

Measured memory_bytes: 3812
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var N = int.Parse(Console.ReadLine());
    var azen = Console.ReadLine().Split();
    
    var aho = azen.Distinct().ToList().Count;
    var a = azen.Length;
    if(a == aho){
     Console.WriteLine("YES");
    }
    else{
      Console.WriteLine("NO");
    }
  }
}

Measured memory_bytes: 48948
N = int(input())
A = [int(i) for i in input().split()] + [1]

# 一個前の提出は嘘解法だったてへぺろ
# 桁上げの処理はpopのときにまとめてやれば良い
def check(m) :
  rl = [[0, A[0]]]
  for i in range(1, N + 1) :
    if A[i-1] < A[i] :
      rl.append([0, A[i] - A[i-1]])

    else :
      cnt = A[i-1]
      while A[i] <= cnt :
        char, size = rl.pop()
        cnt -= size
        if char >= m and size > 1 :
          if size > 2 :
            rl.append([char, size - 2])
            cnt += size - 2
          rl.append([char + char // m, 1])
          cnt += 1
        elif char >= m and size == 1 :
          if len(rl) == 0 : 
            return False
          c, s = rl.pop()
          if s > 1 :
            rl.append([c, s - 1])
          rl.append([c + char // m, 1])
        
      if A[i] - cnt - 1 >= 1 :
        rl.append([char % m, A[i] - cnt - 1])
      rl.append([char % m + 1, 1])
      cnt = A[i]
  return True

if all(A[i-1] < A[i] for i in range(1, N)) :
  print(1)

else :
  ng, ok = 1, N
  while ok - ng > 1 :
    m = (ok + ng) // 2
    
    if check(m) :
      ok = m
    else :
      ng = m
      
  print(ok)

Measured memory_bytes: 125444
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
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; }

void buy(ll& sum, ll& num, ll val){
    num = sum/val;
    sum = sum-num*val;
    //cout << "buy  sum:" << sum << " num: "<< num << endl; 
}

void sell(ll& sum, ll& num, ll val){
    sum += num*val;
    num = 0;
    //cout << "sell  sum:" << sum << " num: "<< num << endl; 
}

int main(){
    ll n, f=0, sum=1000, num=0;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    rep(i,n){
        if(!f && i<n-1 && a[i]<a[i+1]){
            f=1;
            buy(sum,num,a[i]);
        }
        else if(f && i<n-1 && a[i]>a[i+1]){
            f=0;
            sell(sum,num,a[i]);
        }
        else if(f && i==n-1){
            sell(sum,num,a[i]);
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc084.contest.atcoder.jp/tasks/abc084_c>
問題文============================================================
 Atcoder国に、 1 本の東西方向に走る鉄道が完成しました。
 
 この鉄道には N 個の駅があり、西から順に 1,2,…,N の番号がついています。
 
 明日、鉄道の開通式が開かれます。
 
 この鉄道では、1≦i≦N−1 を満たす全ての整数 i に対して、駅 i から駅 i+1 に、
 Ci 秒で向かう列車が運行されます。ただし、これら以外の列車は運行されません。
 
 駅 i から駅 i+1 に移動する列車のうち最初の列車は、
 開通式開始 Si 秒後に駅 i を発車し、その後は Fi 秒おきに駅 i を発車する列車があります。
 
 また、Si は Fi で割り切れることが保証されます。
 
 つまり、A％B で A を B で割った余りを表すとき、
 Si≦t,t％Fi=0 を満たす全ての t に対してのみ、開通式開始 t 秒後に駅 i を出発し、
 開通式開始 t+Ci 秒後に駅 i+1 に到着する列車があります。
 
 列車の乗り降りにかかる時間を考えないとき、全ての駅 i に対して、
 開通式開始時に駅 i にいる場合、駅 N に到着できるのは最も早くて開通式開始何秒後か、答えてください。
=================================================================

解説=============================================================

 各駅から順番にN駅に到達するまでの時間をシミュレーションすれば良い
 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> C(N,0),S(N,0),F(N,0);
    for(int i = 0; i < N-1;i++) cin >> C[i] >> S[i] >> F[i];
    for(int s = 0; s < N;s++){
        int ans = S[s] + C[s];
        for(int i = s+1; i < N-1;i++){
            if(ans <= S[i]){
                ans = S[i] + C[i];
            }else{
                ans = (ans - S[i] + F[i]-1)/F[i] * F[i] + S[i] + C[i];
            }
        }
        cout << ans << endl;
    }
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
even = [i for i in a if i%2 ==0]
count = 0 
for i in even:
    if i%3 == 0 or i%5 ==0:
        count += 1
print('APPROVED' if count == len(even) else 'DENIED')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

/*
author: Basel
*/

using namespace std;

const int N=1e5+5;

ll n,m,ans;

multiset<ll>ms;

int main()
{
    cin >> n >> m;
    for (int i=0;i<n;i++)
    {
        ll x;
        cin >> x;
        ms.insert(x);
    }
    while(m--)
    {
        ll x=*(--ms.end());
        ms.erase(--ms.end());
        x/=2ll;
        ms.insert(x);
    }
    for (auto X:ms)
    {
        ans+=X;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992