akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var vec = cin.ReadIntArray(3);
            Array.Sort(vec);
            var sum = 0;
            sum += vec[0];
            sum += vec[1];
            sum += 10 * vec[2];
            WriteLine(sum);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 27856
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
  std.range, std.container, std.bigint, std.ascii, std.typecons, std.format;

// }}}
// nep.scanner {{{
class Scanner {
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0) {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }

  void scan()() {
  }

  void scan(T, S...)(ref T x, ref S args) {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
    str ~= s.to!(char[]).strip.split;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  int N = cin.next!int;
  long[] A = cin.nextArray!long(N);

  long[long] chie;

  foreach (i; A) {
    chie[i]++;
  }

  long ret;
  foreach (e; chie.byKeyValue) {
    ret += e.value * (e.value - 1) / 2;
  }

  foreach (i; A) {
    auto n = chie[i];
    writeln(ret - n * (n - 1) / 2 + (n - 1) * (n - 2) / 2);
  }
}


Measured memory_bytes: 27280
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int H, W, K;
int x1, y1, x2, y2;
string c[1000000];

vector<int> dist[1000000];

const int INF = 1e9;

void solve(){
    dist[x1][y1] = 0;
    queue<P> que;
    que.push(P(x1, y1));
    while(!que.empty()){
        P p = que.front(); que.pop();
        int h = p.first, w = p.second;
        {
            int l = max(0, w-K);
            int r = min(W-1, w+K);
            for(int i = w-1; i >= l; i--){
                if(c[h][i] == '@') break;
                if(dist[h][i] <= dist[h][w]) break;
                if(dist[h][i] == INF){
                    dist[h][i] = dist[h][w]+1;
                    que.push(P(h, i));
                }
            }
            for(int i = w+1; i <= r; i++){
                if(c[h][i] == '@') break;
                if(dist[h][i] <= dist[h][w]) break;
                if(dist[h][i] == INF){
                    dist[h][i] = dist[h][w]+1;
                    que.push(P(h, i));
                }
            }
        }

        {
            int l = max(0, h-K);
            int r = min(H-1, h+K);
            for(int i = h-1; i >= l; i--){
                if(c[i][w] == '@') break;
                if(dist[i][w] <= dist[h][w]) break;
                if(dist[i][w] == INF){
                    dist[i][w] = dist[h][w]+1;
                    que.push(P(i, w));
                }
            }
            for(int i = h+1; i <= r; i++){
                if(c[i][w] == '@') break;
                if(dist[i][w] <= dist[h][w]) break;
                if(dist[i][w] == INF){
                    dist[i][w] = dist[h][w]+1;
                    que.push(P(i, w));
                }
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> H >> W >> K;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;y1--;x2--;y2--;
    for(int i = 0; i < H; i++) cin >> c[i];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            dist[i].push_back(1e9);
        }
    }
    solve();
    if(dist[x2][y2] == INF){
        cout << -1 << endl;
    }else{
        cout << dist[x2][y2] << endl;
    }
}

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

int getDigitSum(int n);

int main(){int N;
cin>>N;
if(N%getDigitSum(N)==0) cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
  return 0;
}

int getDigitSum(int n){
  int object=n;
  int ans=0;
  for(;;){
    if(object == 0) break;
    ans += object%10;
    object=object/10;
  }
  return ans;
}

Measured memory_bytes: 256
import heapq

num_V, num_E, r = map(int,input().split())
E = [[] for _ in range(num_V)]
for _ in range(num_E):
	ts,tt,td = map(int ,input().split())
	E[ts].append([tt,td])

q = []
heapq.heappush(q,[0,r])
flg = [-1] * num_V

while q:
	cd, cp = heapq.heappop(q)
	if flg[cp] == -1:
		flg[cp] = cd
	else:
		continue

	for np, dist in E[cp]:
		if flg[np] != -1:
			continue
		
		heapq.heappush(q,[cd+dist, np])

for d in flg:
	if d == -1:
		print('INF')
	else:
		print(d)


Measured memory_bytes: 106032
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
    int t,n;
    cin>>n>>t;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=0;
    for(int i=0; i<n-1; i++)
    {
        if(t>=a[i])
        {
            ans++;
            t-=a[i];
        }
        else
        {
            break;
        }
    }
    if(t==a[n-1])
    {
        ans++;
    }

    cout<<ans;



    //cout << "Hello world!" << endl;
    return 0;
}


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

int n;

int f ( int n ) {
    int nr = 0;

    while ( n % 2 == 0 ) {
        ++nr;
        n /= 2;
    }
    return nr;
}

int main () {
    cin >> n;

    int Max = INT_MIN;
    int sol = 1;

    int i;
    for ( i = n; i >= 1; --i ) {
        int nr = f(i);
        if ( nr > Max ) {
            Max = nr;
            sol = i;
        }
    }

    cout << sol;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
    char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const int maxn=5e5+5;
int d[maxn],dp[maxn],pos[maxn];
int n,D,Q;
inline int ABS(int x) {return x>=0?x:-x;}
int main() {
    n=read();D=read();dp[n+1]=1;
    for(re int i=1;i<=n;i++) d[i]=read();
    for(re int i=n;i;--i) {
        if(d[i]>=2*dp[i+1]) {
            dp[i]=dp[i+1];
            if(d[i]>2*dp[i+1]) dp[i]=min(dp[i],d[i]-dp[i+1]);
        }
        else dp[i]=dp[i+1]+d[i];
    } 
    pos[0]=D;
    for(re int i=1;i<=n;i++) pos[i]=min(ABS(pos[i-1]-d[i]),pos[i-1]);
    Q=read();int x;
    while(Q--) x=read(),puts(dp[x+1]<=pos[x-1]?"YES":"NO"); 
    return 0;
}

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

using namespace std;

int main(){
    int n,m,r;
    cin>>n>>m>>r;
    vector<int>t(r);
    for(int i=0;i<r;++i){
        cin>>t[i];
    }
    vector<vector<long long>>dist(n+1,vector<long long>(n+1,1e9));
    for(int i=0;i<m;++i){
        int a,b,c;
        cin>>a>>b>>c;
        dist[a][b]=c;
        dist[b][a]=c;
    }
    for(int k=1;k<n+1;++k){
        for(int i=1;i<n+1;++i){
            for(int j=1;j<n+1;++j){
                if(dist[i][j]>dist[i][k]+dist[k][j]){
                    dist[i][j]=dist[i][k]+dist[k][j];
                }
            }
        }
    }
    long long ans=1e18;
    sort(t.begin(),t.end());
    do{
        long long d=0;
        for(int i=0;i<r-1;++i){
            d+=dist[t[i]][t[i+1]];
        }
        if(ans>d)ans=d;
    }while(next_permutation(t.begin(),t.end()));
    cout<<ans<<endl;
}

/*int main(){
    int N,W;
    cin>>N>>W;
    int w[200],v[200];
    for(int i=0;i<N;++i){
        cin>>w[i]>>v[i];
    }
    int a=W%w[0];
}*/

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(m);
	for (int i = 0; i < m; ++i) {
		cin >> a[i].first >> a[i].second;
	}
	for (int num = 0; num < 1000; ++num) {
		string s = to_string(num);
		if ((int) s.size() != n) {
			continue;
		}
		bool ok = true;
		for (int i = 0; i < m; ++i) {
			if (s[a[i].first - 1] - '0' != a[i].second) {
				ok = false;
			}
		}
		if (ok) {
			cout << num << '\n';
			return 0;
		}
	}
	cout << -1 << '\n';
 	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 998244353
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }
 
//n!
ll fact_mod(ll n) {
    ll ret=1; 
    for(ll i=2;i<=n;i++) ret=ret*(i%mod)%mod;
    return ret;
}
 
// 繰り返し二乗法 
ll pow_mod(ll x, ll n){
    if(n==0) return 1;
    ll ret=pow_mod((x*x) % mod, n/2);
    if(n&1) ret=(ret*x)%mod;
    return ret;
}
 
//nCr O(r) nがでかくても安心
ll combination_mod(ll n, ll r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    ll a=1;
    //a=n!/(n-r)!=n~n-r+1までの総積->O(r)
    for(ll i=0;i<r;i++) a=a*((n-i)%mod)%mod;
    //b=inv(r!)
    ll b=pow_mod(fact_mod(r), mod-2);
    return (a%mod)*(b%mod)%mod;
}
 
ll inv_mod(ll n){
    // フェルマーの小定理
    return pow_mod(n,mod-2);
}

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

    int n;cin>>n;
    vector<ll> d(n),cnt(n+10);
    rep(i,n){
        cin>>d[i];
        cnt[d[i]]++;
    }
    if(cnt[0]!=1||d[0]!=0){
        cout<<0<<endl;return 0;
    }

    ll ans=1;
    int cn2=0;
    for(int i=1;i<n;i++){
        cn2+=cnt[i];
        ans=(ans*pow_mod(cnt[i-1],cnt[i]))%mod;
        if(cn2>=n) break;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

// 11*100000
#define BUF_SIZE 1200000

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

#define PARTS_MAX 100000
#define PARTS_KINDS 3

int asc(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int get_combi(int *arr, int size, int query, int start) {
    int low = start-1;
    int high = size;

    while(low+1 < high) {
        int mid = (low + high)/2;
        // lower bound
        if(arr[mid] > query) {
            high = mid;
        } else {
            low = mid;
        }
    }
    return high;
}

int main(void) {
    int parts = get_int();
    int length[PARTS_KINDS][PARTS_MAX];
    static uint64_t combi[PARTS_KINDS][PARTS_MAX];
    int i, j, k;
    for(i = 0; i < PARTS_KINDS; i++) {
        fget_array(length[i], parts);
        qsort(length[i], parts, sizeof(int), asc);
    }

    // initialization
    for(i = 0; i < parts; i++) {
        combi[PARTS_KINDS-1][i] = 1;
    }

    for(i = PARTS_KINDS-2; i >= 0; i--) {
        int idx = 0;
        static uint64_t cum[PARTS_MAX+1];
        // calc cumulative in advance
        for(j = parts-1; j >= 0; j--) {
            cum[j] = cum[j+1] + combi[i+1][j];
        }
        for(j = 0; j < parts; j++) {
            // query: length[i][j];
            idx = get_combi(length[i+1], parts, length[i][j], idx);
            combi[i][j] = cum[idx];
            for(k = idx; k < parts; k++) {
                //combi[i][j] += combi[i+1][k];
            }
#ifdef DEBUG
            printf("%d, %d -> idx: %d combi: %llu\n",i,j, idx, combi[i][j]);
#endif

        }
    }

    uint64_t ans = 0;
    for(i = 0; i < parts; i++) {
        ans += combi[0][i];
    }

    printf("%llu\n", ans);
    return 0;
}

Measured memory_bytes: 5876
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


def main():
    N = int(input())
    A = [int(input()) for i in range(N)]

    result = 0
    for v in Counter(A).values():
        if v % 2 == 1:
            result += 1

    print(result)


if __name__ == "__main__":
    main()


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

int main() {
  int n,q; // n:number of process, q:quantum
  int timer = 0;
  queue<string> name;
  queue<int> time;
  cin >> n >> q;
  for (int i=0;i<n;++i) {
    string bufn; int buft;
    cin >> bufn >> buft;
    name.push(bufn);
    time.push(buft);
  }
  while (!time.empty()) {
    if (time.front()<=q) {
      timer += time.front();
      cout << name.front() << " " << timer << endl;
      name.pop(); time.pop();
    }
    else {
      name.push(name.front());
      time.push(time.front()-q);
      name.pop(); time.pop();
      timer += q;
    }
  }
}

Measured memory_bytes: 4168
#include<iostream>
#include<string>
using namespace std;
#define INFTY (int)(1e9+100)
#define MAX_N 2000100


void CountingSort(int A[], int B[], int k,int n){
	int C[k] = {};
	
	for(int i = 0; i < n; i++){
		C[A[i]]++;
	}
	for(int i = 0; i < k; i++){
		C[i] += C[i-1];
	}
	for(int i = n-1; i >= 0; i--){
		B[C[A[i]]-1] = A[i];
		C[A[i]]--;
	}
	
}

int A[MAX_N], B[MAX_N];
int main(){
	int n;
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>A[i];
	}
	
	CountingSort(A, B, 10002, n);
	for(int i = 0; i < n; i++){
		if(i)cout<<" ";
		cout<<B[i];
	}cout<<endl;
	return 0;
}


Measured memory_bytes: 18744
#include <iostream>
#include <string>
using namespace std;
#define rep(i,s,n)for(int i=s;i<n;i++)
typedef long long ll;

int main() {
	ll n, k; cin >> n >> k;
	string s; cin >> s;

	if (s[k - 1] < 'a') {
		s[k - 1] = s[k - 1] + ('a' - 'A');
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if (b <= c || d <= a) printf("%d", 0);
	else {
		if (b <= d) {
			if (a <= c) printf("%d", b - c);
			else printf ("%d", b - a);
		} else {
			if (a <= c) printf("%d", d - c);
			else printf ("%d", d - a);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int

struct edge
{
  int to, cost;
};
typedef std::vector<std::vector<edge>> graph;
const ll MOD = 1000000007;
using namespace std;

int main()
{
  int a, b, h;
  cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int x;
    cin >> x;
    if(x >= 1200)cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

    char arr[1000];
    int w,c,i;
    scanf("%[^\n]s",&arr);
    cin>>w;
    c=strlen(arr);
    w=w-1;
    cout<<arr[0];
    for(i=1;i<c;i++)
    {
        if((i+w)>=c)
        {
            break;
        }
        else{
            cout<<arr[i+w];
        i=i+w;
        }

    }

    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    As = list(map(int, input().split(" ")))

    ans = "APPROVED"
    for a in As:
        if a % 2 == 0:
            if a % 3 == 0 or a % 5 == 0:
                pass
            else:
                ans = "DENIED"
                break

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
let N = stdin.ReadLine()

stdin.ReadLine().Split()
|> Array.map int
|> Array.filter (fun x -> x % 2 = 0)
|> Array.filter (fun x -> x % 3 > 0)
|> Array.filter (fun x -> x % 5 > 0)
|> Array.isEmpty
|> fun x ->
    match x with
    | true -> "APPROVED"
    | false -> "DENIED"
|> stdout.WriteLine


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

#define ff first
#define ss second
#define endl '\n'

const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
int a[MAX], dp[MAX][105];

int addMod(int a, int b) {
	return ((a + b) % MOD + MOD) % MOD;
}

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

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

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

	for (int r = 0; r <= a[0]; ++r) {
		dp[r][0] = 1;
	}

	int prefix = 0;
	for (int c = 1; c < n; ++c) {
		prefix = dp[0][c] = 1;

		for (int r = 1; r <= a[c]; ++r) {
			prefix = addMod(prefix, dp[r][c-1]);
			dp[r][c] = prefix;
		}

		for (int r = a[c] + 1; r <= k; ++r) {
			prefix = addMod(prefix, dp[r][c-1] - dp[r-a[c]-1][c-1]);
			dp[r][c] = prefix;
		}
	}

	cout << dp[k][n-1] << endl;
	return 0;
}


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

int main() {
    string A, B, C;
    cin >> A >> B >> C;
    if (A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;

int n;
int cache[100000]={0};
int min_cost(int a[])
{
	if(n==1)
	return 0;
	cache[n-1]=0;
	cache[n-2]=abs(a[n-1]-a[n-2]);
	for(int i=n-3;i>=0;i--)
	{
	long long int y=abs(a[i+1]-a[i])+cache[i+1];
	long long int x=abs(a[i+2]-a[i])+cache[i+2];
	cache[i]=(x<y?x:y);
	}
	return cache[0];
}






int main()
{
cin>>n;
int a[n];
int i=0;
for(i=0;i<n;i++)
cin>>a[i];
int x=min_cost(a);
cout<<x;
}

Measured memory_bytes: 1024
#abc094d
 
n=int(raw_input())
a=map(int,raw_input().split())
x=max(a)
if x%2:
 m=(x+1)/2
else:
 m=x/2
d=[]
for i in xrange(n):
 d.append(abs(a[i]-m))
y=min(d)
z=d.index(y)
u=a[z]
if n==2:
 x=a[0]
 u=a[1]
print x,u


Measured memory_bytes: 11284
n=int(input())
lst=list(map(int,input().split()))
sp=[]
br=[]
gr=[]
cy=[]
bl=[]
yl=[]
og=[]
rd=[]
colorful=[]

for i in lst:
    if 0<=i<400:
        sp.append(i)
    elif 400<=i<800:
        br.append(i)
    elif 800<=i<1200:
        gr.append(i)
    elif 1200<=i<1600:
        cy.append(i)
    elif 1600<=i<2000:
        bl.append(i)
    elif 2000<=i<2400:
        yl.append(i)
    elif 2400<=i<2800:
        og.append(i)
    elif 2800<=i<3200:
        rd.append(i)
    else:
        colorful.append(i)

if len(colorful)==n:
    print(1,n)
else:
    mi=0
    mx=0
    if len(sp)>0:
        mi+=1
        mx+=1
    if len(br)>0:
        mi+=1
        mx+=1
    if len(gr)>0:
        mi+=1
        mx+=1
    if len(cy)>0:
        mi+=1
        mx+=1
    if len(bl)>0:
        mi+=1
        mx+=1
    if len(yl)>0:
        mi+=1
        mx+=1
    if len(og)>0:
        mi+=1
        mx+=1
    if len(rd)>0:
        mi+=1
        mx+=1
    mx+=len(colorful)
    
    print(mi,mx)

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#endif

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

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

    vector<int> sw[11];
    for (int i=0; i<M; ++i) {
        int k;
        cin >> k;
        sw[i] = vector<int>(k);
        for (int j=0; j<k; ++j) {
            cin >> sw[i][j];
            sw[i][j]--;
        }
    }

    vector<int> p(M);
    for (int i=0; i<M; ++i) cin >> p[i];

    long long ans = 0;
    for (int i=0; i<(1<<N); ++i) {
        bool ok = true;
        for (int j=0; j<M; ++j) {
            int c = 0;
            for (int k: sw[j]) {
                if ((i & (1<<k)) > 0) {
                    c ++;
                }
            }
            if (c % 2 != p[j]) {
                ok = false;
                break;
            }
        }
        if (ok) ans ++;
    }    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll int
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>
#define pie pair<pii,ll>
using namespace :: std;

const ll maxn=6100;
ll dp[maxn];
ll a[maxn];
ll b[maxn];
ll o[maxn];
string fa(string s){
    if(s=="")return "";
    ll n=s.size();
    ll cnta=0;
    ll cntb=0;
    for(ll i=0;i<n;i++){
        if(s[i]=='a'){
            a[cnta]=i;
            o[i]=cnta;
            cnta++;
        }else{
            b[cntb]=i;
            o[i]=cntb;
            cntb++;
        }
    }

    fill(dp,dp+maxn,0);
    for(ll i=n-2;i>=0;i--){
        dp[i]=dp[i+1];
        if(s[i]=='a'){
            dp[i]=max(dp[i],1+dp[b[o[i]]]);
        }
    }
    string ans;
    for(ll i=0;i<dp[0];i++){
        ans+="ab";
    }
    return ans;
}
string fb(string s){
    if(s=="")return "";
    ll n=s.size();
    ll cnta=0;
    ll cntb=0;
    for(ll i=0;i<n;i++){
        if(s[i]=='a'){
            a[cnta]=i;
            o[i]=cnta;
            cnta++;
        }else{
            b[cntb]=i;
            o[i]=cntb;
            cntb++;
        }
    }
    string maxx;
    for(ll i=0;i<n;i++){
        if(s[i]=='b'){
            string res="";
            for(ll j=i;j<n;j++){
                if(o[j]>=o[i]){
                    res+=s[j];
                }
            }
            maxx=max(maxx,res);
        }
    }
    return maxx;

}
string dps[maxn];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    string s;
    ll n;
    cin>>n>>s;
    n*=2;
    string last;
    ll sum=0;
    vector<string> vec;
    for(ll i=0;i<n;i++){
        last+=s[i];
        if(s[i]=='a'){
            sum++;
        }else{
            sum--;
        }
        if(sum==0){
            vec.pb(last);
            last="";
        }
    }
    if(last.size()>0)
        vec.pb(last);
    string sara;
    vector<string> sarb;
    for(ll i=vec.size()-1;i>=0;i--){
        if(sarb.empty()){
            if(vec[i][0]=='b'){
                sarb.pb(vec[i]);
            }else{
                sara=vec[i]+sara;
            }
        }else{
            if(vec[i][0]=='b'){
                sarb.pb(vec[i]);
            }
        }
    }
    reverse(sarb.begin(),sarb.end());
    for(ll i=0;i<sarb.size();i++){
        sarb[i]=fb(sarb[i]);
    }
    if(sarb.size()==0){
        cout<<fa(sara);
        return 0;
    }
    dps[sarb.size()-1]=sarb.back();
    for(ll i=(ll)sarb.size()-2;i>=0;i--){
        dps[i]=max(sarb[i],max(dps[i+1],sarb[i]+dps[i+1]));
    }
    cout<<dps[0]<<fa(sara);
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ld long double
#define pb push_back
#define N 10000007
typedef long long int ll;
using namespace std;
int main(void){
	fast;
	ll x,y;
	cin>>x>>y;
	ll ans=4*x-y;
	if(ans%2==0){
		if(ans/2<=x&&ans/2>=0)
		cout<<"Yes";
		else
		cout<<"No";
	}
	else
	cout<<"No";
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

int n;
int main() {
    scanf("%d", &n);
    int v[n];
    rep(i,0,n) {
        cin >>v[i];
        v[i]--;
    }
    P u[2][100000];
    rep(i,0,2){
        rep(j,0,100000){
            u[i][j]=P (0,j);
        }
    }
    rep(i,0,n){
        if (i%2==0){
            u[0][v[i]].first++;
        }
        else u[1][v[i]].first++;
    }
    sort (u[0], u[0]+100000);
    sort(u[1], u[1]+100000);
    //cout << u[0][99999].second;
    
    if (u[0][99999].second!=u[1][99999].second){
        printf("%d\n", n-u[0][99999].first-u[1][99999].first);
    }
    else {
        int a=max(u[0][99998].first,u[1][99998].first);
        printf("%d\n", n-u[0][99999].first-a);
    }
}


Measured memory_bytes: 2176
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};


int main(){
    IOS;
    make2(ll,n,m);
    makevec(ll,a,n);
    sort(a.begin(),a.end());
    vector <array <ll,2> >vec(m);
    fr(i,m) cin>>vec[i][1]>>vec[i][0];
    sort(vec.rbegin(),vec.rend());
    ll x=0;
    for(ll i=0;i<m;i++){
        for(ll j=0;j<vec[i][1];j++){
            if(vec[i][0]>=a[x]) a[x]=vec[i][0];
            else break;
            x++;
            if(x==n) break;
        }
    }
    ll ans=0;
    fr(i,n) ans+=a[i];
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#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 REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int main() {
  int n,y;
  cin >> n >> y;
  string ans="kogakubu10gokan";
  rep(i,n) {
    int a;
    string s;
    cin >> a >> s;
    if(a<=y) ans=s;
  }
  pr(ans);
  return 0;
}


Measured memory_bytes: 1204
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
   "regexp"
   "strings"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sentence := ""
  alphabets := getAlphabet()
  for {
    tmp := nextString()
    if tmp == "" {
        break
    }
	sentence = sentence + tmp
  }

  for _, v := range sentence {
	  if regexp.MustCompile(`[A-Z]`).Match([]byte(string(v))) {
		  count := alphabets[strings.ToLower(string(v))]
		  alphabets[strings.ToLower(string(v))] = count + 1
	  } else if regexp.MustCompile(`[a-z]`).Match([]byte(string(v))) {
		  count := alphabets[string(v)]
		  alphabets[string(v)] = count + 1
	  }
  }

  alphabetArr := []string{
	"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
  }

  for _, v := range alphabetArr {
	  fmt.Println(v + " : " + strconv.Itoa(alphabets[v]))
  }

}

func getAlphabet() (map[string]int) {
	alphabets := map[string]int{
		"a":0,
		"b":0,
		"c":0,
		"d":0,
		"e":0,
		"f":0,
		"g":0,
		"h":0,
		"i":0,
		"j":0,
		"k":0,
		"l":0,
		"m":0,
		"n":0,
		"o":0,
		"p":0,
		"q":0,
		"r":0,
		"s":0,
		"t":0,
		"u":0,
		"v":0,
		"w":0,
		"x":0,
		"y":0,
		"z":0,
	}
	return alphabets
}

func nextString() (string) {
	sc.Scan()
	v := sc.Text()
	return v
}

func nextInt() (int) {
	sc.Scan()
	v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}

func nextFloat() (float64) {
	sc.Scan()
	v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}



Measured memory_bytes: 6220
#include<stdio.h>

int main(){

  int x = 0;
  int a = 0;
  int min = 1000000;
  int max = -1000000;
  long int sum = 0;
  int cnt = 0;

  scanf("%d",&cnt);

  for( x = 1; x <= cnt; x++){
	scanf("%d",&a);
    if(min > a) {
      min = a;
	}
	if(max < a){
	  max = a;
	}
	sum += a;
  }
  printf("%d %d %ld\n",min,max,sum);

  return 0;
}

Measured memory_bytes: 2704
#include <stdio.h>

int main( void )
{

	int H, W, i, j;
	
	while( 1 ){
		scanf( "%d %d", &H, &W );
		if( H == 0 && W == 0 ){
			break;
		}
		
		for( i = 1; i <= H; i++ ){
			for( j = 1; j <= W; j++ ){
				printf( "#" );
			}
			printf( "\n" );
		}
		printf( "\n" );
	}
	
	return 0;
}

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

int gcd(long int a, long int b) {
  if (b==0) return a;
  return gcd(b, a%b);
}

int main() {
  long int a, b;
  cin >> a >> b;
  long int g = gcd(max(a,b), min(a,b));
  cout << (a * b) / g << endl;
}

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

#define long long long

struct _ { _() { ios_base::sync_with_stdio(0); cin.tie(0); } } _;
// template<class... T> inline void read(T&... x) { ((cin >> x), ...); }

template<class T> inline void MIN(T &a, T b) { if (a > b) a = b; }
template<class T> inline void MAX(T &a, T b) { if (a < b) a = b; }

const int N = 51;

int n, a[N], b[N];
int cost[N][N];
bool pos[N][N];

int main() {

	cin >> n;

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

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

	memset(cost, 60, sizeof(cost));
	for (int i = 0; i < N; i++) {
		cost[i][i] = 0;
		for (int j = 1; j < N; j++) {
			MIN(cost[i][i % j], j);
		}
	}

	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				MIN(cost[i][j], max(cost[i][k], cost[k][j]));
			}
		}
	}

	/*for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			printf("%d%c", min(cost[i][j], 99), "\t\n"[j == 9]);
		}
	}*/

	/*for (int i = 0; i < n; i++) {
		printf("%d --> %d : %d\n", a[i], b[i], cost[a[i]][b[i]]);
	}*/

	for (int i = 0; i < n; i++) {
		pos[i][a[i]] = true;
	}

	long ans = 0;
	while (true) {
		int min_cost = 0;
		for (int i = 0; i < n; i++) {
			int best_route = INT_MAX;
			for (int v = 0; v < N; v++) if(pos[i][v]) MIN(best_route, cost[v][b[i]]);
			// printf("best cost for %d : %d\n", i, best_route);
			MAX(min_cost, best_route);
		}
		if (min_cost == 0) break;
		if (min_cost > N) return !printf("-1\n");
		ans += 1LL << min_cost;
		// cout << "used " << min_cost << endl;
		for (int i = 0; i < n; i++) {
			for (int v = 0; v < N; v++) pos[i][v % min_cost] |= pos[i][v];
		}
	}

	cout << ans << endl;

}

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

int main(){

  string a;
  cin>>a;
   vector<int> data;
  for(auto c:a){
   data.push_back(c-'0');
  }
  int count=0;
  for(int i=0;i<data.size();i++){
  count=count+data.at(i);
  }
  cout<<count<<endl;
}

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }

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


int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    vint ans(n+1,0);

    for(ll x=1;x*x <= n; x++){
        for(ll y=1; y*y<=n; y++){
            for(ll z=1; z*z<=n; z++){
                ll tmp = x*x + y*y + z*z + x*y + y*z + z*x;
                if(tmp > n) break;
                ans[tmp]++;
            }
        }
    }

    for(ll i=1; i<=n; i++){
        cout<<ans[i]<<endl;
    }

    return 0;

}

Measured memory_bytes: 3676
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
   		ll a,b,c;

		cin >> a >> b >> c;

		if((a+b==c)||(a+c==b)||(b+c==a)){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}

		return 0;
    }

Measured memory_bytes: 256
a,b,c=map(int,input().split())

if abs(a)>=abs(b*c):
    print(abs(abs(a)-abs(b*c)))
    exit()

n=abs(a)
m=n//c
if abs(a)-abs(c*m)>abs(a)-abs(c*(m+1)):
    m=m+1
if (b-m)%2==0:
    print(abs(abs(a)-abs(c*m)))
else:
    print(min(abs(abs(a)-abs(c*(m+1))),abs(abs(a)-abs(c*(m-1)))))

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

ll solve(long long N, string S, long long K){
	ll t = 0, m = 0, c = 0, res = 0;
	rep(i, N+K-1) {
		if (i-K >= 0) {
			if (S[i-K] == 'M') {
				m--;
				t -= c;
			}
			if (S[i-K] == 'C') {
				c--;
			}
		}
		if (i<N && S[i] == 'M') {
			m++;
		}
		if (i<N && S[i] == 'C') {
			c++;
			t += m;
		}
		if (i-K+1 >= 0) {
			if (S[i-K+1] == 'D') {
				res += t;
			}
		}
	}
	return res;
}

int main(){	
	long long N;
	long long Q;
	string S;
	scanf("%lld",&N);
	cin >> S;
	scanf("%lld",&Q);
	vector<long long> k((Q-1)-0+1);
	for(int i = 0 ; i <= (Q-1)-0 ; i++){
		scanf("%lld",&k[i]);
	}
	for(int i = 0 ; i <= (Q-1)-0 ; i++){
		cout << solve(N, S, k[i]) << endl;
	}
	return 0;
}



Measured memory_bytes: 2308
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)
using namespace std;

const ll MOD = 1000000007;
int main(){
  ll s;
  cin >> s;
  vector<ll> v(s+1, 0);
  rep2(i, 3, s+1){
    v[i]++;
    rep(j, i-2){
      v[i] += v[j];
      v[i] %= MOD;
    }
  }
  cout << v[s] << endl;
  
  return 0;
}

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

int main()
{
    
    /*
    string s1;
    getline( cin, s1 );
    int n1 = s1.size();
    */
    int a, p;
    cin >> a >> p ;
    
    cout << (3*a+p)/2 << endl;
      
    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 F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.first,", ",x.second,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;


template<class T> struct Seg { 
	const T ID = {-1, -1}; // comb(ID,b) must equal b
	T combine(T a, T b) { return (a.first > b.first) ? a : b;} 
	int n; vector<T> seg;
	void init(int _n) { n = _n; seg.assign(2*n,ID);}

	void update(int p, T value) {	// set value at position p
		seg[p += n] = value;
		for (p /= 2; p; p /= 2) seg[p] = combine(seg[2*p], seg[2*p+1]);
	}
    
	T query(int l, int r) {	 // sum on interval [l, r]
		T ra = ID, rb = ID; 
		for (l += n, r += n+1; l < r; l /= 2, r /= 2) {
			if (l&1) ra = combine(ra,seg[l++]);
			if (r&1) rb = combine(seg[--r],rb);
		}
		return combine(ra,rb);
	}
};

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

	int N, T; cin >> N >> T;

	vi arr (N);
	Seg<pii> seg; seg.init(N);

	F0R(i, N) {
		cin >> arr[i];
		seg.update(i, {arr[i], i});
	}

	int bestTrade = 0;
	R0F(i, N - 1) {
		bestTrade = max(bestTrade, seg.query(i + 1, N - 1).first - arr[i]);
	}


	ll moves = 0;

	R0F(i, N-1) {
		while (true) {
			pii q = seg.query(i + 1, N - 1);
			int res = q.first - arr[i];
			if (res < bestTrade) break;
			moves++;
			seg.update(q.second, {q.first - 1, q.second});
		}
	}

	print(moves);
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

ll a[200010];

int main(){
    int n;
    cin >> n;
    rep(i, n) cin >> a[i];

    if (a[0] != 0){
        cout << -1 << endl;
        return 0;
    }

    ll now = 0, cnt = 0;
    bool flag = true;
    for (int i = 1; i < n; i++){
        if (a[i] - a[i-1] > 1) flag = false;
        else if (a[i] == a[i-1] + 1) cnt++;
        else cnt += a[i];
    }

    if (!flag) cout << -1 << endl; 
    else cout << cnt << endl;

    return 0;
}

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
ll n,a,b
 ;
  cin >>n>>a>>b;
  cout << min(a*n,b
);  return 0;
}


Measured memory_bytes: 3624
A = list(input())
B = list(input())
C = list(input())
a = 0
b = -1
c = -1
n = A
m = a
while len(A) != a and len(B) != b and len(C) != c:
    if n[m] == "a":
        n = A
        a += 1
        m = a
    elif n[m] == "b":
        n = B
        b += 1
        m = b
    elif n[m] == "c":
        n = C
        c += 1
        m = c
if a == len(A):
    print("A")
elif b == len(B):
    print("B")
else:
    print("C")

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int main(){
  string s;
  int mi,num,n;
  cin >> s;
  n = s.size();
  mi = n;
  for(int i=0;i<n-1;i++){
    if(s[i]!=s[i+1]){
      mi = min(mi,max(i+1,n-i-1));
    }
  }
  cout << mi << endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
using namespace std;

char t[7][7][7], u[7][7][7];

int adjcnt(int x, int y, int z){
	int c = (t[x][y][z] == '1' ? -1 : 0);
	for(int i = -1; i <= 1; ++i)
	for(int j = -1; j <= 1; ++j)
	for(int k = -1; k <= 1; ++k){
		if(t[x + i][y + j][z + k] == '1'){ ++c; }
	}
	return c;
}

int main(){
	int n, m, x, a, b;
	const char *fmt = "Case %d:\n";
	for(int casenum = 1; scanf("%d", &n), n; ++casenum){
		printf(fmt, casenum);
		fmt = "\nCase %d:\n";

		a = b = 0;
		for(int i = 1; i <= 5; ++i){
			for(int j = 1; j <= 5; ++j){
				scanf(" %s", t[i][j] + 1);
			}
		}

		scanf("%d", &m);
		for(int i = 0; i < m; ++i){
			scanf("%d", &x);
			a |= 1 << x;
		}
		scanf("%d", &m);
		for(int i = 0; i < m; ++i){
			scanf("%d", &x);
			b |= 1 << x;
		}

		for(int d = 0; d < n; ++d){
			for(int i = 1; i <= 5; ++i)
			for(int j = 1; j <= 5; ++j)
			for(int k = 1; k <= 5; ++k){
				int c = adjcnt(i, j, k);
				int msk = (t[i][j][k] == '1' ? b : a);
				u[i][j][k] = (msk >> c & 1 ? '1' : '0');
			}
			memcpy(t, u, sizeof u);
		}

		for(int i = 1; i <= 5; ++i){
			for(int j = 1; j <= 5; ++j){
				puts(t[i][j] + 1);
			}
			if(i != 5){ puts(""); }
		}
	}
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  string s;
  cin>>s;
  ll num=0;
  for(ll i=0;i<s.size();i++){
  	if(s[i]=='+') num++;
    else num--;
  }
  cout<<num<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  COMinit();
  int n,k;
  cin >> n >> k;
  REP(i,1,k + 1){
    ll ans = COM(n - k - (i - 1) + i,i) * COM(k - i + (i - 1),i - 1) % INF;
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 15476
#include <stdio.h>
#include <string.h>
 
int main() {
	char A[255], B[255], C[255];
	scanf("%s %s %s", &A, &B, &C);
	int lenA = strlen(A);
	int lenB = strlen(B);
	int lenC = strlen(C);
	
	if(A[lenA - 1] == B[0] && B[lenB - 1] == C[0]){
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1628
def check(P):
    global k, T, n

    i = 0
    for j in range(k):
        s = 0
        while s + T[i] <= P:
            s += T[i]
            i += 1
            if (i == n):
                return n
    
    return i

def solve():
    left = 0
    right = 100000 * 10000

    while right - left > 1:
        mid = (left + right) // 2
        v = check(mid)
        if (v >= n):
            right = mid
        else:
            left = mid

    return right

if __name__ == '__main__':
    n, k = map(int, input().split())
    T = [int(input()) for i in range(n)]

    ans = solve()
    print(ans)


Measured memory_bytes: 9564