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

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

    string n, t;
    cin >> n >> t;
    string res = "Yes";
    for (int i = 0; i < n.length(); i++)
        if (n[i] != t[i])
        {
            res = "No";
            break;
        }
    cout << res << endl;
}


Measured memory_bytes: 3636
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    p = list(map(int, input().split()))
    x = p[0]
    res = 1
    for i in range(1, n):
        if x > p[i]:
            res += 1
        x = min(x, p[i])
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 70096
#include <bits/stdc++.h>
using namespace std; 
#define int int64_t
#define itn int
#define fi first
#define se second 
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  for(int i=0;i<k;i++){
    if(a>=b) b*=2;
    else if(b>=c) c*=2;
  }
  if(a<b&&b<c) cout<<"Yes\n";
  else cout<<"No\n";
}

Measured memory_bytes: 3620
#include <stdio.h>

main(){
  int a[4], b[4];
  int i, j;
  int h, br;

  while(1){
    h=br=0;
    if(scanf("%d", &a[0])==EOF) break;
    for(i=1;i<4;i++){
      scanf("%d", &a[i]);
    }
    for(i=0;i<4;i++){
      scanf("%d", &b[i]);
      for(j=0;j<4;j++){
	if(b[i]==a[j]){
	  br++;
	}
      }
    }
    for(i=0;i<4;i++){
      if(a[i]==b[i]){
	br--;
	h++;
      }
    }
    printf("%d %d\n", h, br);
  }
  return 0;
}

Measured memory_bytes: 0
n,k=map(int,raw_input().split())
d=map(int,raw_input().split())

f=1
a=n
while f==1:    
    for i in range(k):
        if str(d[i]) in list(str(a)):
            f=1
            a+=1
            break
    else:
        f=0
print a

Measured memory_bytes: 2568
#include <stdio.h>
int n;
long long a[18];
long long f[18];
long long p, q;
void so(int u, int v) {
	if (u == n) {
		p = 0;
		for (int i = 0; i < u; i++) {
			p += a[i] * f[i];
		}
		if (q > p)q = p;
		return;
	}
	for (int i = v; i < u; i++) {
		for (int j = u - 1; j >= i; j--) {
			a[j + 1] = a[j];
		}
		a[i] = a[i - 1] + a[i + 1];
		so(u + 1, i);
		for (int j = i; j < u; j++) {
			a[j] = a[j + 1];
		}
	}
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", f + i);
	}
	a[0] = 1;
	a[1] = 1;
	q = 400000000000;
	so(2, 1);
	printf("%lld\n", q);
}

Measured memory_bytes: 1736
#include <stdio.h>

int main(void){
    
    int a,b,n,i;
    
    
    while(scanf("%d%d",&a,&b)!=EOF){
        i=0;
        n=0;
        n=a+b;
        while(n!=0){
            i++;
            n=(n/10);}
        
        printf("%d\n",i);
    }
    
    return 0;
}

Measured memory_bytes: 600
import sys
input = sys.stdin.readline
import itertools


N = int(input())
vC = [tuple(map(int, input().split())) for _ in range(N)]
vL = list(range(N))

cnt = 0
dist = 0.0
for vx in itertools.permutations(vL):
    d = 0.0
    cnt += 1
    for x,y in zip(vx[:-1],vx[1:]):
        tA, tB = vC[x], vC[y]
        d += ((tA[0]-tB[0])**2 + (tA[1]-tB[1])**2)**.5
    dist += d

print(dist/cnt)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
 
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)
 
int main(){
    int N;
    ll K;
    cin >> N >> K;
    int A[N];
    rep(i, N) cin >> A[i];

    vector<int> ord(N+1, -1); //その町に何回目の移動できたことがあるかを格納
                              //-1が入っている場合は、まだ一度も来たことがないという意味
    vector<int> s; //何回目の移動かをカウントする役割また、どんな順番に町をたどったかを記憶している。

    ll now = 1; //現在居る町の番号（最初は町1から開始）
    while(ord[now] == -1){
        ord[now] = s.size();
        s.push_back(now);
        now = A[now-1];
    }
    int cycle = s.size() - ord[now];
    ll l = ord[now];

    if(K < l) cout << s[K] << endl;
    else{
        K -= l;
        K %= cycle;
        cout << s[l + K] << endl;
    }
    return 0;
}

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

int main(){
	int n, q;
	scanf("%d%d", &n, &q);
	vector<stack<int> > st(n);
	for(int i = 0; i < q; i++) {
		int id, t;
		scanf("%d%d", &id, &t);
		if(id == 0) {
			int x;
			scanf("%d", &x);
			st[t].push(x);
		}
		if(id == 1) {
			if(!st[t].empty())
				printf("%d\n", st[t].top());
		}
		if(id == 2) {
			if(!st[t].empty()) {
				st[t].top();
				st[t].pop();
			}
		}
	}
}



Measured memory_bytes: 4340
#include <iostream>

using namespace std;

int main(){

  int n;

  while( cin >> n ){

    int cnt = 0;
    for( int i = 0 ; i <= 9 ; i++ ){
      for( int j = 0 ; j <=9 ; j++ ){
	for( int k = 0 ; k <= 9 ; k++ ){
	  for( int l = 0 ; l <= 9 ; l++ ){
	    if( i + j + k + l == n) cnt++;
	  }
	}
      }
    }
    cout << cnt << endl;
  }  
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll n,k;
    cin>>n>>k;
    cout<<min(n%k,k-n%k);
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

void rec(string s, ll len) {
	if (sz(s) == len) {
		cout << s << endl;
	} else {
		ll k = -1;
		for (char c: s) k = max(k, ll(c-'a'));
		FOR(i,0,k+2) rec(s + char('a'+i), len);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	rec("", n);
}



Measured memory_bytes: 1536
import java.util.Scanner;

public class Main
{

    static long gcd(long x, long y)
    {
        if (y == 0) {
            return x;
        } else {
            return gcd(y, x % y);
        }
    }

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextLong()) {
            long a = scan.nextLong();
            long b = scan.nextLong();
            long c = gcd(a, b);
            System.out.print(c);
            System.out.print(" ");
            System.out.println(a / c * b);
        }
    }
}



Measured memory_bytes: 26092
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define MAX 10
int n;
int source[MAX], target[MAX];
int ans = (1<<21);

void shift(int str[MAX], int s, int e){
    while(1){
	if ( str[s] == target[s] ) break;
	for ( int j = s; j <= e; j++ ){
	    str[j] = (str[j]+1)%10;
	}
    }
}

bool equals( int s1[MAX], int s2[MAX] ){
    for ( int i = 0; i < n; i++ ) if ( s1[i] != s2[i] ) return false;
    return true;
}
void rec(int s[MAX], int pos, int cnt){

    if ( equals(s, target) ){
	ans = min(ans, cnt);
	return;
    }
    if ( pos >= n ) return;
    if ( cnt >= ans ) return;

    for ( int end = pos; end <= n-1; end++ ){
	int next[MAX];
	for ( int i = 0; i < n; i++ ) next[i] = s[i];

	if ( s[pos] == target[pos] ){
	    rec(next, pos+1, cnt);
	} else {
	    shift(next, pos, end);
	    rec(next, pos+1, cnt+1);
	}
    }
}

main(){
    string s1, s2;
    while(1){
	cin >> n;
	if ( n == 0 ) break;
	cin >> s1 >> s2;
	for ( int i = 0; i < n; i++ ){
	    source[i] = s1[i] - '0';
	    target[i] = s2[i] - '0';
	}
	ans = (1<<21);
	rec(source, 0, 0);
	cout << ans << endl;
    }
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  string s; cin >> s;
  int ans = 0;
  for (int i = 0; i < N - 1; ++i) {
    string t = s.substr(0, i + 1);
    string u = s.substr(i + 1);
    vector<int> freqs1(30, 0), freqs2(30, 0);
    for (int j = 0; j < (int)t.size(); ++j) {
      ++freqs1[t[j] - 'a'];
    }
    for (int j = 0; j < (int)u.size(); ++j) {
      ++freqs2[u[j] - 'a'];
    }
    int cnt = 0;
    for (int i = 0; i < 26; ++i) {
      if (freqs1[i] > 0 and freqs2[i]) { ++cnt; }
    }
    ans = max(ans, cnt);
  }
  printf("%d\n", ans);
  return 0;
}


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

public class Main {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null; }
        String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try { tokenizer = new StringTokenizer(reader.readLine()); } 
                catch (IOException e) { throw new RuntimeException(e);} }
            return tokenizer.nextToken(); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        
        int n = r.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = r.nextInt();
        }

        int temp = 0;
        int max = 0;
        for(int i = 1; i < n; i++){
            if(arr[i] <= arr[i-1]){
                temp++;
            } else{
                temp = 0;
            }
            max = Math.max(max, temp);
        }
        
        pw.println(max);

        pw.close();
    }
}

/**
                _        _                 _                                                
               | |      | |               | |                                               
   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___  
  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \ 
 | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/ 
                                __/ |                               ______ __/ |            
                               |___/                               |______|___/             
 */

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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define hell (ll)(1e9+7)
#define pii pair <ll,ll>
#define vi vector <ll>
#define pb push_back
#define inf 1000000000000000

using namespace std;

void solve()
{
    ll n;
    cin>>n;
    rep(i,1,10){
        rep(j,1,10){
            if(i*j==n){
                cout<<"Yes";
                return;
            }
        }
    }
    cout<<"No";
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	//cin>>t;
	t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

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

    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    string alpha;
    for (int i=0;i<=s.length()-1;i++)
    {
        alpha=alpha+s[i]+t[i];
    }    


    cout << alpha << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
import sys



def fifty(S):
    out = 'No'

    c = Counter(S)

    if len(c) == 2:

        for value in c.values():
            if value == 2:
                out = 'Yes'
                pass
            else:
                out = 'No'
                break
    return out
  
if __name__ == "__main__":
    S = input()
    print(fifty(S))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define maxn 310
#define mod 1000000007
#define P pair<int,int>
int dp[2][3][maxn][maxn];
void add(int &x,int y)
{
    x+=y;
    if(x>=mod) x-=mod;
}
vector<P>lim[maxn];
int n,m;
void mem(int cur)
{
    for(int k=0;k<3;++k)
        for(int i=0;i<=n;++i)
            for(int j=0;j<=n;++j)
                dp[cur][k][i][j]=0;
}
bool judge(int pos,int x1,int x2,int x3)
{
    int r,g,b;
    if(x1==0)
    {
        r=pos;
        g=x2;
        b=x3;
    }
    else if(x1==1)
    {
        r=x2;
        g=pos;
        b=x3;
    }
    else
    {
        r=x2;
        g=x3;
        b=pos;
    }
    for(int i=0;i<(int)lim[pos].size();++i)
    {
        P tmp=lim[pos][i];
        int l=tmp.first,cnt=tmp.second;
        if(r>0&&r>=l) --cnt;
        if(g>0&&g>=l) --cnt;
        if(b>0&&b>=l) --cnt;
        if(cnt!=0) return false;
    }
    return true;
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;++i) lim[i].clear();
        while(m--)
        {
            int l,r,x;
            scanf("%d%d%d",&l,&r,&x);
            lim[r].push_back(P(l,x));
        }
        int cur=0,nex=1;
        mem(cur);
        dp[cur][0][0][0]=1;
        dp[cur][1][0][0]=1;
        dp[cur][2][0][0]=1;
        for(int i=1;i<n;++i)
        {
            //cur^=1; nex^=1;
            mem(nex);
            for(int j=0;j<3;++j)
            {
                for(int k=0;k<=n;++k)
                {
                    for(int l=0;l<=n;++l)
                    {
                        int tmp=dp[cur][j][k][l];
                        if(tmp==0||!judge(i,j,k,l)) continue;
                        if(j==0)
                        {
                            //R=i,G=k,B=l
                            //paint R
                            add(dp[nex][0][k][l],tmp);
                            //paint G
                            add(dp[nex][1][i][l],tmp);
                            //paint B
                            add(dp[nex][2][i][k],tmp);
                        }
                        else if(j==1)
                        {
                            //R=k,G=i,B=l
                            //paint R
                            add(dp[nex][0][i][l],tmp);
                            //paint G
                            add(dp[nex][1][k][l],tmp);
                            //paint B
                            add(dp[nex][2][k][i],tmp);
                        }
                        else
                        {
                            //R=k,G=l,B=i
                            //paint R
                            add(dp[nex][0][l][i],tmp);
                            add(dp[nex][1][k][i],tmp);
                            add(dp[nex][2][k][l],tmp);
                        }
                    }
                }
            }
            cur^=1; nex^=1;
        }
        int ans=0;
        for(int i=0;i<3;++i)
            for(int j=0;j<=n;++j)
                for(int k=0;k<=n;++k)
                    if(judge(n,i,j,k))
                        add(ans,dp[cur][i][j][k]);
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 2432
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define int ll
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }

template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class F>
constexpr decltype(auto) funcs(F &&f) {
    return FixPoint<F>{std::forward<F>(f)};
}

template <class T>
std::vector<T> vecs(int n, T &&val) {
    return std::vector<T>(std::forward<int>(n), std::forward<T>(val));
}

template <class... Args>
decltype(auto) vecs(int n, Args &&... args) {
    return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...));
}

template <class V, class T>
void fill(V &x, const T &val) {
    x = val;
}

template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    ans += min(a, k);
    ans -= max(0LL, k - (a + b));
    cout << ans << '\n';
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>

static const int N = 500;
static const int INFTY = (1<<21);

#define NIL -1
#define A 100

int p[100];
int key[100];
int n;


int main(){
  int i,j,a,b,c,sum;
  int M[A][A];
  int l[A];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for (j=0;j<n;j++){
      scanf("%d",&a);
      M[i][j] = (a==-1)?INFTY:a;
    }
  }

  for(c=0;c<n;c++){
    key[c]=100000000;
 
    p[c]=NIL;

    l[c]=NIL;
  }
  key[0]=0;

  while(1){
    int c=NIL;
    int b=100000000;


    for(i=0;i<n;i++){


      if(key[i]<b && l[i]==NIL){
	b=key[i];
	c=i;
      }
    }



    if(c==NIL){
      break;
    }

    for(b=0;b<n;b++){
      if(M[c][b] < key[b] && l[b]==NIL){
	key[b]=M[c][b];
	p[b]=c;
      }
    }
    l[c]=0;
  }

 
  sum = 0;

  for ( i = 0; i < n; i++ ){
    if ( p[i] != -1 ) sum += M[i][p[i]];
  }

  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
const int MOD=1e9+7;
int main(){
  int64_t n,k,a=0;
  cin>>n>>k;
  for(int i=k;i<n+2;i++)a=(a+i*(n-i+1)+1)%MOD;
  cout<<a<<endl;
}


Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
dic = {}
amin = n - 1
amax = 1
for ai in a:
    if ai in dic:
        dic[ai] += 1
    else:
        dic[ai] = 1
    amin = min(amin, ai)
    amax = max(amax, ai)

if 1 < amax - amin:
    print('No')
elif amin == amax:
    if a[0] == n - 1 or 2 * a[0] <= n:
        print('Yes')
    else:
        print('No')
else:
    if dic[amax] == 1:
        print('No')
    elif dic[amin] + 1 <= amax <= dic[amin] + dic[amax] // 2:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 61548
N, M = gets.split.map(&:to_i)

MOD = 10 ** 9  +7

def factorial(n, num)
  num = 1
  while n > 0
    num *= n
    num %= MOD
    n -= 1
  end

  return num
end

if (N - M).abs >= 2
  puts 0
elsif (N - M).abs == 1
  puts factorial(N, 1) * factorial(M, 1) % MOD
else
  puts 2 * factorial(N, 1) * factorial(M, 1) % MOD
end


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int calc2(int n) {
	if (!n) return 2;
	else return n & 1;
}

int calc1(int n) {
	return !(n & 1);
}

int main() {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	
	int64_t dp[n + 1][5];
	for (int i = 0; i <= n; i++)
		for (int j = 0; j < 5; j++) dp[i][j] = 1000000000000000000;
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 5; j++) {
			int64_t next;
			if (j == 0 || j == 4) next = dp[i][j] + a[i];
			else if (j == 1 || j == 3) next = dp[i][j] + calc2(a[i]);
			else next = dp[i][j] + calc1(a[i]);
			dp[i + 1][j] = std::min(dp[i + 1][j], next);
			if (j < 4) dp[i][j + 1] = std::min(dp[i][j + 1], dp[i][j]);
		}
	}
	std::cout << *std::min_element(dp[n], dp[n] + 5) << std::endl;
	
	return 0;
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
         
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define endl "\n"
#define mod 1000000007  
#define mod2 998244353 
const int N = 100001; 

// bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){ 
//     return (a.second < b.second);}
 
// int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=ans*a%m; b/=2;a=a*a%m;}return ans;}
// int inverse(int a, int p){return fexp(a, p-2,mod);} 

// int fac[2000001];

// int nCrModPFermat(int n, int r,int p) { 
//     if (r==0) return 1; 
//     return (fac[n]*inverse(fac[r],p)%p*inverse(fac[n-r],p)%p)%p; 
// }
 
void solve(){
    int n;cin>>n;
    vi a(n);
    int num=n;
    rep(i,0,n)cin>>a[i];
    sort(all(a),greater<int>());
    num--;
    int j=0,ans=0;
    while(num){
        if(j==0){
            num--;
            ans=ans+a[j];
        }
        else if(num>1){
            num-=2;
            ans+=a[j]*2;
        }
        else{
            num--;
            ans=ans+a[j];
        }
        j++;
    }
    cout<<ans;
    return ;
}
         
signed main(){
        IOS;    


        int t=1;
        // cin>>t;
        // fac[0] = 1; 
        // for (int i=1 ; i<=2000001; i++) fac[i] = fac[i-1]*i%mod; 
        rep(i,0,t){
            solve();
            cout<<"\n";
        //   cout<<" * "<<t<<"\n";
        }
    //    return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 998244353LL
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N, d;
int A[200000];
int dp[200001];
int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N;
    rep(i, N) cin >> A[i];
    reverse(A, A+N);

    int cm = 0;
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        int t = A[i];
        
        int lo = 0, hi = d;
        while(lo < hi) {
            int mid = (lo + hi + 1) >> 1;
            if (dp[mid] <= t) {
                lo = mid;
            } else {
                hi = mid - 1;
            }
        }
        
        d = max(d, lo + 1);
        dp[lo + 1] = t;
    }

    cout << d << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if (m1 != m2)cout << 1 << endl;
	else cout << 0 << endl;
}


Measured memory_bytes: 768
// Aizu Vol-2 0257: Railway Ticket
// 2017.8.7

#include <stdio.h>
char *gets();
char buf[20], *p;

int main()
{
	int a = 0, i = 3;
	
	gets(p = buf);
	while (i-- > 0) {
		while (*p == ' ') p++; a <<= 1, a |= (*p++) & 1;
	}
	puts((a == 1 || a == 6) ? "Open" : "Close");
	return 0;
}

Measured memory_bytes: 524
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int n, k;
vector<string> cards(n);
set<string> ans;

void dfs(string number = "", int depth = 0,  int used = 0) {
	if(depth == k)
		ans.insert(number);

	else
		for(int i = 0; i < n; ++i)
			if(!((used >> i) & 1))
				dfs(number + cards[i], depth + 1, used | (1 << i));
}

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

	while(cin >> n >> k, n) {
		cards.clear();
		cards.resize(n);
		for(int i = 0; i < n; ++i)
			cin >> cards[i];

		ans.clear();
		dfs();
		cout << ans.size() << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1468
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N, D = map(int, input().split())
    count = 0
    for _ in range(N):
        xi, yi = map(int, input().split())
        dij = (xi * xi + yi * yi) ** 0.5
        if dij <= D:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 70648
#include<stdio.h>
#define N 100000
  struct card{
    int num;
    char mark;
    int rank;
  };
int Partition(struct card[],int,int);
void Quicksort(struct card[],int,int);


int main(){

  int n,i,flag=0;
  char a;
  struct card card1[N];

  scanf("%d%c",&n,&a);
  for(i = 0; i < n; i++){
    scanf("%c%d%c",&card1[i].mark,&card1[i].num,&a);
    card1[i].rank = i + 1;
  }
  Quicksort(card1,0,n - 1);
  for(i = 0; i < n -1; i++){
    if(card1[i].num == card1[i + 1].num && card1[i].rank > card1[i + 1].rank && flag == 0){
      printf("Not stable\n");
      flag = 1;
    }
  }
    if(flag == 0) printf("Stable\n");
  for(i = 0; i < n; i++){
    printf("%c %d\n",card1[i].mark,card1[i].num);
  }
  return 0;
}

int Partition(struct card A[],int p,int r){

  int x,i,j;
  struct card tmp;

  x = A[r].num;
  i = p - 1;

  for(j = p; j < r; j++){
    if(A[j].num <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = tmp;
 
  return i + 1;
}

void Quicksort(struct card A[],int p,int r){

  int q;

  if(p < r){
    q = Partition(A,p,r);
    Quicksort(A,p,q-1);
    Quicksort(A,q+1,r);
  }
}

Measured memory_bytes: 1780
from operator import add,sub,mul

formula = input().split()
stack = []
op = {"+":add, "-":sub, "*":mul}

for i in formula:
    if i.isdigit():
        stack.append(int(i))
    else:
        op2 = stack.pop()
        op1 = stack.pop()
        stack.append(op[i](op1, op2))

print(stack[0])


Measured memory_bytes: 5684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N;
  cin >>N;
  vector<int> dp(N+10,100010);//思考停止でNより大きい数にしておく。ちょうどi円引き出すための試行回数。
  dp[0]=0;//0円引き出すための試行回数は0回
  for(int i=1;i<=N;i++){
    int power6 = 1;
    while(power6<=i){
      dp[i]=min(dp[i],1+dp[i-power6]);
      power6 *= 6;
    }
    int power9 = 1;
    while(power9<=i){
      dp[i]=min(dp[i],1+dp[i-power9]);
      power9 *= 9;
    }
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  string ret = "xxx";
  ret[0] = s1[0];
  ret[1] = s2[0];
  ret[2] = s3[0];

  transform(ret.begin(), ret.end(), ret.begin(), ::toupper);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  string s;
  cin >> s;
  int l = s.size();
  int m = l/2;
  int ans = 0;
  bool ok = true;
  rep(i,0,m-1){
    ok = true;
    rep(j,0,i+1){
      if(s[j] != s[j + i+1]) ok = false;
    }
    if(ok) ans = 2*(i+1);
  }
  cout << ans << endl;
}


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


int main(){
	int a, b, c, ans=0;

    cin >> a >> b;
    c = b - a;
    
    for(int i=1;i<c;i++){
        ans += i;
    }
    cout << ans - a << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define F first
#define S second
#define mset(x,v) memset(x, v, sizeof(x))
#define left(x) 2*x
#define right(x) (2*x) + 1
#define ALL(t) (t).begin(),(t).end() 
#define ret return 0
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define rev(s) reverse(s.begin(),s.end())
#define WL(t) while(t --)
#define MOD 1000000007
int main()
{
      boost;
      ll x,a,b;
      cin>>x>>a>>b;
      int p=(x-a);
      cout<<p%b<<endl;
      
}

Measured memory_bytes: 256
Var a:array[1 .. 1000] of Longint;
    i,n,j,min,count,b:Longint;
Begin
    Readln(n); For i:=1 to n do read(a[i]); min:=high(min);
    For i:=-100 to 100 do begin
        b:=i; count:=0;
        For j:=1 to n do count:=count+sqr(a[j]-b);
        If count<min then min:=count;
    End;
    Writeln(min);
End.

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

int main(){
  int A[251];
  int H, i, j;
  
  scanf("%d",&H);
  if(H < 0 || 250 < H) exit(1);

  for(i=1; i<=H; i++){
    scanf("%d",&A[i]);
  }

  for(j=1; j<=H; j++){
    printf("node %d: key = %d, ", j, A[j]);
    if(j != 1) printf("parent key = %d, ", A[j/2]);
    if(2*j <= H) printf("left key = %d, ", A[2*j]);
    if(2*j+1 <= H) printf("right key = %d, ", A[2*j+1]);
    
    printf("\n");
  }

  return 0;
}

      
    
    
  



Measured memory_bytes: 2044
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

void solve(ll K, ll N, std::vector<ll> A) {
  ll d0 = K + A.at(0) - A.at(N - 1);
  ll max = d0;
  ll sum = d0;
  ll p = A.at(0);
  for (int i = 1; i < N; i++) {
    ll d = A.at(i) - p;
    sum += d;
    if (d > max) {
      max = d;
    }
    p = A.at(i);
  }
  cout << sum - max << endl;
}

int main() {
  ll K;
  scanf("%lld", &K);
  ll N;
  scanf("%lld", &N);
  std::vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(K, N, std::move(A));
  return 0;
}


Measured memory_bytes: 1792
N, M = map(int, input().split())
memo = [0]*(N+1)
memo[0] = 1
mod = 10**9+7

for _ in range(M):
    ai = int(input())
    memo[ai] = None

if memo[1] != None:
    memo[1] = 1

for i in range(2, N+1):
    tmp = 0
    if memo[i] == None:
        continue
    if memo[i-1] != None:
        tmp += memo[i-1]
    if memo[i-2] != None:
        tmp += memo[i-2]
    memo[i] = tmp

if memo[N] == None:
    print(0)
else:
    print(memo[N]%mod)


Measured memory_bytes: 462708
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#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++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll n; cin >>n;
  string s[n];
  map<string,int> mps;
  rep(i,n){
    cin >> s[i];
    mps[s[i]]++;
  }
  
  ll m; cin>>m ;
  string t[m];
  map<string,int> mpt;
  rep(i,m) {
    cin >> t[i];
    mpt[t[i]]++;
  }
  int count=0;
  rep(i,n){
    int key=0;
    rep(j,m){
      if(s[i]==t[j]) key=1;
    }
    if(key==0) count=max(count,mps[s[i]]);
    else count=max(count,mps[s[i]]-mpt[s[i]]);
  }
  cout <<count<<endl;
}

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

int main() {
  int a,b,c;
  cin>>a>>b;
   
  c=a*b;
  
  if(c%2==1&&!c==0){
    cout<<"Odd"<<endl;
  }
  else if(c%2==0&&!c==0){
    cout<<"Even"<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
	// 1000 happiness points for each 500-yen coin
	// 5 happiness points for each 5-yen coin he has
	Scanner scanner = new Scanner(System.in);

	int x = scanner.nextInt();
	scanner.close();

	int count500 = x / 500;
	int count5 = (x - count500 * 500) / 5;

	int result = count500 * 1000 + count5 * 5;

	System.out.println(result);
    }
}

Measured memory_bytes: 23124
N,K=gets.chomp.split(" ").map(&:to_i)
array=gets.chomp.split(" ").map(&:to_i)
ret = 10**9
(0..(N-K)).each do |ind_s|
    ind_e = ind_s + K - 1
    r = 0
    if array[ind_s] < 0 && array[ind_e] < 0
        r = -1 * array[ind_s]
    elsif array[ind_s] < 0 && array[ind_e] >= 0
        if array[ind_s] * -1 > array[ind_e]
            r = array[ind_e] * 2 - array[ind_s]
        else
            r = array[ind_s] * -2 + array[ind_e]
        end
    else
        r = array[ind_e]
    end

    if r < ret
        ret = r
    end
end
puts ret


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

void fnInput(string& rsMaxNum)
{
  cin >> rsMaxNum;
}

int fnDgtDP(string sMaxNum)
{
  // dp[i][j][k] :=  i: 上位 i 桁目まで決定
  //                 j: small(数字を自由に選べる)か
  //                 k: {3,5,7} を選んだかのflag
  //                 の条件を満たす数値の数
  int dp[11][2][8] = {};
  dp[0][0][0] = 1;

  int nLen = sMaxNum.size();

  for (int i = 0; i < nLen; ++i)
  {
    for (int j = 0; j < 2; ++j)
    {
      for (int k = 0; k < 8; ++k)
      {
        if (!dp[i][j][k]) continue;

        if (j == 1)                    // small ([0, 9] から数字を選べる)か
        {
          if (!k) dp[i + 1][1][0] += dp[i][1][0];            // nothing

          dp[i + 1][1][k | 1] += dp[i][1][k];                // +3
          dp[i + 1][1][k | 2] += dp[i][1][k];                // +5
          dp[i + 1][1][k | 4] += dp[i][1][k];                // +7
        }
        else                           // not small ([0, d] から数字を選べる)か
        {
          int nDgt = sMaxNum[i] - '0';

          if (!k)        dp[i + 1][1][0]     += dp[i][0][0]; // nothing

          if (nDgt == 3) dp[i + 1][0][k | 1] += dp[i][0][k]; // +3
          if (3 < nDgt)  dp[i + 1][1][k | 1] += dp[i][0][k]; // +3
          if (nDgt == 5) dp[i + 1][0][k | 2] += dp[i][0][k]; // +5
          if (5 < nDgt)  dp[i + 1][1][k | 2] += dp[i][0][k]; // +5
          if (nDgt == 7) dp[i + 1][0][k | 4] += dp[i][0][k]; // +7
          if (7 < nDgt)  dp[i + 1][1][k | 4] += dp[i][0][k]; // +7
        }
      }
    }
  }
/*
  for (int i = 0; i <= nLen; ++i)
     for (int j = 0; j < 2; ++j)
       for (int k = 0; k < 8; ++k)
         if (dp[i][j][k])
         {
           cout << "dp[" << i << "][" << j << "][" << k << "] = (";
           cout << dp[i][j][k] << ")" << endl;
         }
*/
  return dp[nLen][0][7] + dp[nLen][1][7];
}

int main()
{
  string sMaxNum;

  fnInput(sMaxNum);
  cout << fnDgtDP(sMaxNum) << endl;
  
  return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    XY = [[] for _ in range(N)]
    for i in range(N):
        A = int(input())
        for _ in range(A):
            x, y = map(int, input().split())
            XY[i].append((x-1, y))
#

    ans = 0
    for i in range(1, 2**N):
        flag = True
        cnt = 0
        for j in range(N):
            if i>>j & 1: #iのj bit shift
                cnt += 1 #iの二進表示の１の個数
                for x, y in XY[j]:
                    if i>>x & 1 != y:
                        flag = False
                        break
        if flag:
            ans = max(ans, cnt)

    print(ans)
main()

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    ll n, m;
    cin >> n >> m;
    if(n <= m){
        cout << min(m - n, n) << endl;
    }
    else {
        cout << min(n % m, (m - (n % m))) % m << endl;
    }
}
int main(int argv, char **argc){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    t  = 1;
    while(t--)
        solve();

}


Measured memory_bytes: 3660
import java.io.*;
 
public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        int w = Integer.parseInt(s[0]);
        int h = Integer.parseInt(s[1]);
        int x = Integer.parseInt(s[2]);
        int y = Integer.parseInt(s[3]);
        int r = Integer.parseInt(s[4]);
         
        if(x-r<0||y-r<0||x+r>w||y+r>h)
            System.out.println("No");
        else
            System.out.println("Yes");
    }
}
 

 

Measured memory_bytes: 24432
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int ans=b/a;
    if(ans>=c)
    {
        cout<<c<<endl;
    }
    else if(ans<c)
    {
        cout<<ans<<endl;
    }
    else if(a>b)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

const int limit=200010;
int s[limit];

int main(void){
	ll n,t;
	cin >> n >> t;


	int ans=0,cur=0;

	rep(i,n){
		cin >> s[i];
		ans += min(t,s[i]+t-cur);
		cur=s[i]+t;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
N, P = map(int, input().split())

def prime_factor(x) :
    ret = dict()
    if x % 2 == 0 :
        ret[2] = 0
        while x % 2 == 0 :
            x //= 2
            ret[2] += 1
            
    i = 3
    while i * i <= x :
        if x % i == 0 :
            ret[i] = 0
            
            while x % i == 0 :
                x //= i
                ret[i] += 1
        i += 2
        
    if x != 1 :
        ret[x] = 1
    
    return ret

ret = 1
for k, v in prime_factor(P).items() :
    ret *= k ** (v // N)
    
print(ret)

Measured memory_bytes: 38420
#include <stdio.h>
int djs[10010];
int height[10010];
int djsUnion(int x,int y){
	if(height[x]>height[y]){
		djs[y]=x;
	}
	else if(height[x]<height[y]){
		djs[x]=y;
	}
	else{
		djs[x]=y;
		height[y]++;
	}
	return 0;
}
int find (int x){
	if(djs[x]==-1)return x;
	else{
		djs[x]=find(djs[x]);
		return djs[x];
	}
}
int main(){
	int i,n,m,x,y,z;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		djs[i]=-1;
		height[i]=1;
	}
	for(i=0;i<m;i++){
		scanf("%d %d %d",&x,&y,&z);
		if(x==1){
			if(find(y)==find(z)){
				printf("1\n");
			}
			else{
				printf("0\n");
			}
		}
		else{
			if(find(y)!=find(z)){
				djsUnion(find(y),find(z));
			}
		}	
	}
	return 0;
}

Measured memory_bytes: 1088
//B - Iroha Loves Strings: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, l;

    cin >> n >> l;
    vector<string> palavras(n);
    loop(i, 0, n) cin >> palavras[i];
    sort(all(palavras));
    for(auto x : palavras) cout << x;
    cout << "\n";
}

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

# def burgar_patty(L,X): # levelLのX層までのパティの枚数、L>=X
#     if L==0:
#         return 1
#     else:
#         n = 
#         if X<=n+1:
#             return burgar_patty(L-1, X-1)
#         elif X>=n+3:
#             return burgar_patty(L-1, L-1)+burgar_patty(L-1,X-n+2)
#         elif X==n+2:
#             return burgar_patty(L-1, )

def burgar(L):
    if L==0:
        return 'P'
    else:
        tmp = burgar(L-1)
        return 'B'+tmp+'P'+tmp+'B'

patty = [0]*(n+1)
length = [0]*(n+1)
for L in range(n+1):
    if L==0:
        patty[L] = 1
        length[L] = 1
    else:
        patty[L] = patty[L-1]*2+1
        length[L] = length[L-1]*2+3

def patty_n(L,X): # length[L]>=X>=0
    # print('L,X',L,X)
    if X==0:
        return 0
    elif L==0:
        return 1
    else:
        l = length[L-1]
        # print('length[L-1]',l)
        if X==1:
            return 0
        elif 1<X<=1+l:
            return patty_n(L-1, X-1)
        else:
            return patty[L-1]+1+patty_n(L-1, X-l-2)

# print(burgar(n))
print(patty_n(n,x))
    



Measured memory_bytes: 3064
from collections import deque
n,q = map(int, input().split())
S = []

for i in range(n):
    S.append(deque())
for i in range(q):
    a = input().split()
    t = int(a[1])
    
    if a[0] == '0':
        S[t].append(a[2])
    elif a[0] == '1' and S[t]:
        print(S[t][0])
    elif a[0] == '2' and S[t]:
        S[t].popleft()
    


Measured memory_bytes: 20828
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll k,n;
    cin>>k>>n;
    vl v;
    rep(i,n)
    {
        ll c;
        cin>>c;
        v.pb(c);
    }
    vl w;
    for(int i=0;i<n-1;i++)
    {
        w.pb(v[i+1]-v[i]);
    }
    w.pb(k-v[n-1]+v[0]);
    sort(all(w));
    ll ans=0;
    for(int i=0;i<n-1;i++)
        ans+=w[i];
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 16624
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (Math.abs(a - b) % 2 == 0) {
            System.out.println("Alice");
        } else {
            System.out.println("Borys");
        }
    }
}


Measured memory_bytes: 23892