akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,f[100009],lef,rig,mid,g[100009],fen[200009],ans,pas,zx;
void upd(long long q){
	while(q<=200005){
		fen[q]++;
		q=q+(q&(-q));
	}
}
void upd2(long long q){
	while(q<=200005){
		fen[q]--;
		q=q+(q&(-q));
	}
}
long long read(long long q){
	if(q<=0) return 0;
	long long jm=0;
	while(q>=1){
		jm+=fen[q];
		q=q-(q&(-q));
	}
	return jm;
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a;
	for(b=1; b<=a; b++){
		cin>>f[b];
	}
	if((a+1)*a/2/2%2==1) zx=(a+1)*a/2/2; else zx=(a+1)*a/2/2+1;
//	cout<<zx<<endl;
	lef=0;rig=1000000001;
	while(1){
		if(lef+1>=rig) break;
		mid=(lef+rig)/2;
//		cout<<mid<<endl;
		g[0]=0;
		for(b=1; b<=a; b++){
			g[b]=g[b-1];
			if(f[b]<mid) g[b]--; else g[b]++;
		}
		pas=0;
		for(b=a; b>=1; b--){
		    upd(g[b]+100001);
			pas+=a-b+1-read(g[b-1]-1+100001);
			//if(mid<=30) cout<<mid<<" "<<pas<<endl;
		}
		for(b=a; b>=1; b--){
		    upd2(g[b]+100001);
		}
		if(pas<zx){
			rig=mid;
		}else{
			ans=mid;
			lef=mid;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

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

    vector<int> dp(n, 1);
    for(int i=0; i<n-1; ++i){
        vector<int> nextDp(n-1-i, 0);
        int tmp = 0;
        if(s[i] == '<'){
            for(int j=0; j<n-1-i; ++j){
                tmp += dp[j];
                tmp %= MOD;
                nextDp[j] += tmp;
                nextDp[j] %= MOD;
            }
        }
        else{
            for(int j=n-2-i; j>=0; --j){
                tmp += dp[j+1];
                tmp %= MOD;
                nextDp[j] += tmp;
                nextDp[j] %= MOD;
            }
        }
        dp = move(nextDp);
    }
    cout << dp[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fname "C"
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define bug(x) cerr << (#x) << " = " << (x) << '\n'
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define X first
#define Y second

using namespace std;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<float, float> ff;
typedef pair<double, double> dd;

int main()
{
	if (fopen(fname".INP", "r")) {
		freopen(fname".INP", "r", stdin);
		freopen(fname".OUT", "w", stdout);
	}
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n, b = 0, c = 0;
	scanf("%d", &n);
	vector<int> arr(n);
	REP0(i, n) scanf("%d", &arr[i]);
	REP0(i, n) b += 2*arr[i];
	b *= -1;
	REP0(i, n) c += arr[i]*arr[i];
	int x1 = -b/(2*n), x2 = -b/(2*n) + 1;
	cout << min(n*x1*x1 + b*x1 + c, n*x2*x2 + b*x2 + c);
	return 0;
}

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

using namespace std;

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

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

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

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

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int r;
	cin>>r;
	cout<<3*r*r<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
    int n , m ;
    cin >> n >> m ;
    int a ;
    int ans = 0 ;
    for(int i = 0 ; i < m ; i++){
        cin >> a ;
        ans += a ;
    }

    if(ans >n){
        cout << -1 << endl;
    }else{
        cout << n - ans << endl;
    }

    return 0 ;
}

 


Measured memory_bytes: 3564
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String X = sc.next();
    String Y = sc.next();

    String msg = "=";
    if(X.charAt(0) < Y.charAt(0)) msg = "<";
    else if(X.charAt(0) > Y.charAt(0)) msg = ">";

    System.out.println(msg);

  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    int count=0;

    int n,x,input;

    cin >> n >> x;
    int pos = 0;
    if(pos <= x){
      count++;
    }
    while(n--){
      cin >> input;
      pos += input;
      if(pos <= x){
        count++;
      }else {
        break;
      }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length.toLong()
    val counts = ('a'..'z').map { c -> s.count { it ==c }.toLong() }
    val pairCounts = counts.map { it -> it * (it + 1) / 2 }
    val ans = 1 + n * (n + 1) / 2 - pairCounts.sum()
    println(ans)
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Vertex
{
    vector<int> child;
    int par;
    ll cost;
    int cnt = 0;
    ll an = 0;
};

Vertex V[1005];
bool dp[5005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N - 1)
    {
        ll p;
        cin >> p;
        p--;
        V[i + 1].par = p;
        V[p].child.push_back(i + 1);
    }
    REP(i, N)
    {
        cin >> V[i].cost;
    }
    queue<int> q;
    REP(i, N)
    {
        if (V[i].child.size() == 0)
        {
            V[V[i].par].cnt++;
            if (V[V[i].par].cnt == V[V[i].par].child.size())
                q.push(V[i].par);
        }
    }

    bool ans = true;
    while (!q.empty())
    {
        int t = q.front();
        q.pop();
        ll minSum = 0;
        ll sum = 0;
        memset(dp, 0, sizeof(dp));
        dp[0] = true;
        REP(i, V[t].child.size())
        {
            int n = V[t].child[i];
            for (int j = V[t].cost; j >= 0; --j)
            {
                if (j - V[n].cost >= 0 && dp[j - V[n].cost])
                    dp[j] = true;
                if (j - V[n].an >= 0 && dp[j - V[n].an])
                    dp[j] = true;
            }
            sum += V[n].cost + V[n].an;
            minSum += std::min(V[n].cost, V[n].an);
        }
        for (int i = V[t].cost; i >= 0; --i)
        {
            if (!dp[i])
                continue;
            V[t].an = sum - i;
            if (V[t].cost < minSum)
                ans = false;
            break;
        }
        V[V[t].par].cnt++;
        if (V[V[t].par].cnt == V[V[t].par].child.size())
            q.push(V[t].par);
    }

    if (ans)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

int main(){
    int a,b,c,d;
    string s;
    cin >> s;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';

    if(a+b+c+d == 7)
        cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
    else if(a+b+c-d == 7)
        cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
    else if(a+b-c+d == 7)
        cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
    else if(a+b-c-d == 7)
        cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
    else if(a-b+c+d == 7)
        cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
    else if(a-b+c-d == 7)
        cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
    else if(a-b-c+d == 7)
        cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
    else
        cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
    return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	var bs = NewBufScanner(in)
	var bw = NewBufWriter(out)
	defer bw.w.Flush()

	N, _ := strconv.Atoi(bs.Scan())

	nowP := NewPlace(0, 0, 0)

	result := "Yes"

	for i := 0; i < N; i++ {
		line := strings.Split(bs.Scan(), " ")
		t, _ := strconv.Atoi(line[0])
		x, _ := strconv.Atoi(line[1])
		y, _ := strconv.Atoi(line[2])
		nextP := NewPlace(t, x, y)

		count := nextP.t - nowP.t
		move := abs(nextP.x - nowP.x) + abs(nextP.y - nowP.y)

		if move > count || move % 2 != count % 2 {
			result = "No"
			break
		}

		nowP = nextP
	}

	bw.Printf("%s\n", result)
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

type Place struct {
	t int
	x int
	y int
}

func NewPlace(t, x, y int) *Place {
	return &Place{
		t: t,
		x: x,
		y: y,
	}
}

// BufScanner original scanner
type BufScanner struct {
	s *bufio.Scanner
}

// NewBufScanner constructer
func NewBufScanner(in io.Reader) *BufScanner {
	s := bufio.NewScanner(in)
	return &BufScanner{
		s: s,
	}
}

// Scan Scan Data
func (b *BufScanner) Scan() string {
	b.s.Scan()
	return b.s.Text()
}

// BufWriter original writer
type BufWriter struct {
	w *bufio.Writer
}

// NewBufWriter constructer
func NewBufWriter(out io.Writer) *BufWriter {
	w := bufio.NewWriter(out)
	return &BufWriter{
		w: w,
	}
}

// Printf Output file
func (b *BufWriter) Printf(format string, a ...interface{}) {
	fmt.Fprintf(b.w, format, a...)
}

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

int main() {
	
	int a,b;
	cin >> a >> b;
	int min = a;
	int max = b;
	if(a >= b)
	{
	   max = a;
	   min = b;
	}
	for(int i=1;i<=max;i++)
	{
	    cout << min;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

struct Card{
   char suit;
   char value;
};

int main()
{
   struct Card C1[101], C2[101], temp;
   int N, i, j, minj, flag = 0;
   char ch;

   scanf("%d%c", &N, &ch);
   for (i=0; i<N; i++){
      scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
      C2[i].suit = C1[i].suit;
      C2[i].value = C1[i].value;
   }


   for (i=0; i<N-1; i++){
      for (j=N-1; j>=i+1; j--){
         if (C1[j].value<C1[j-1].value){
            temp = C1[j];
            C1[j] = C1[j-1];
            C1[j-1] = temp;
         }
      }
   }

   for (i=0; i<N; i++){
      if (i>0)
         printf(" ");
      printf("%c%c", C1[i].suit, C1[i].value);
   }
   printf("\n");

   puts("Stable");


   for (i=0; i<N; i++){
      minj = i;
      for (j=i; j<N; j++){
         if (C2[j].value<C2[minj].value)
            minj = j;
      }
      temp = C2[minj];
      C2[minj] = C2[i];
      C2[i] = temp;
   }

   for (i=0; i<N; i++){
      if (i>0)
         printf(" ");
      printf("%c%c", C2[i].suit, C2[i].value);
   }
   printf("\n");

   for (i=0; i<N; i++){
      if (C1[i].suit != C2[i].suit){
         puts("Not stable");
         flag = 1;
         break;
      }
   }
   if (flag==0)
      puts("Stable");

   return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }



typedef pair<ll, pair<ll, ll>> prr;
int main() {
    int n; cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(), l.end());

    ll ans = 0;

    rep(i, n-1) for(int j=i+1; j < n; j++) {
        // a < b + c を求める
        auto right_idx = lower_bound(l.begin(), l.end(), l[i]+l[j]);
        // b, c のうち大きい方より大きくないと他の条件を満たせない
        auto left_idx = upper_bound(l.begin(), l.end(), max(l[i], l[j]) - min(l[i], l[j]));

        // 同じ組み合わせの除外のために, "jより大きいこと" という条件も追加する


        ans += max((long)0, (right_idx-l.begin()-1) - max((long)j, (left_idx-l.begin())));

    }

    cout << ans << endl;


    return 0;
}



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

using ll = long long ;
const int N = 1e5+5;

ll dp[N][2];
ll mod = 1e9+7;

int main()
{

    string l;

    cin>>l;

    dp[0][0]=1;

    for(int i=1;i<=l.size();i++)
    {
        if(l[i-1]=='1')
        {
            dp[i][0] = (dp[i-1][0]*2)%mod;
            dp[i][1] = (dp[i-1][0]+3*dp[i-1][1])%mod;
        }
        else
        {
            dp[i][0]=(dp[i-1][0])%mod;
            dp[i][1] = (dp[i-1][1]*3)%mod;
        }
    }
    cout<<(dp[l.size()][0]+dp[l.size()][1])%mod<<endl;
}


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

xy = []
for i in range(N):
    A = int(input())
    xy.append([list(map(int, input().split())) for i in range(A)])

ans = 0
for b in range(2**N):
    bit = str(bin(b))[2:].zfill(N)
    p = list(map(int, bit))
    for i in range(N):
        if p[i] == 0:
            continue
        for x, y in xy[i]:
            if p[x-1] != y:
                break
        else:
            continue
        break
    else:
        ans = max(ans, p.count(1))

print(ans)


Measured memory_bytes: 48092
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int x;
    cin >> x;
    int n = x;
    while (1) {
        int m = 0;
        for (int i = 2; i < n; ++i) {
            if (n % i == 0) m++;
        }
        if (m == 0) {
            cout << n << endl;
            break;
        }
        n++;
    }
}

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

#define FOR(i,s,e) for(ll (i)=(s);(i)<(e);(i)++)
typedef long long ll;

/* 2017/01/21 問題 ----- ABC045 C /Link http://abc045.contest.atcoder.jp/tasks/arc061_a  */
/* -----解説等-----
問題: 1 以上 9 以下の数字のみからなる文字列 S が与えられます。
この文字列の中で、あなたはこれら文字と文字の間のうち、いくつかの場所に + を入れることができます。
一つも入れなくてもかまいません。 ただし、+ が連続してはいけません。

このようにして出来る全ての文字列を数式とみなし、和を計算することができます。

ありうる全ての数式の値を計算し、その合計を出力してください。

制約
1≤|S|≤10
S に含まれる文字は全て 1 〜 9 の数字


Sが小さい。


*/

string S;
ll ans = 0;
int n;

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

    cin >> S;

    n = S.size();

    for (int i = 0; i < (1 << (n - 1)); i++) {
        ll sum = 0; ll cur = 0;
        
        FOR(j, 0, n) {
            if (j == 0) {
                cur = cur * 10 + (S[j] - '0');
                continue;
            }
            if (i & (1 << (j - 1))) {
                sum += cur;
                cur = 0;
            }
            cur = cur * 10 + (S[j] - '0');
        }
        sum += cur;
        ans += sum;
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
//   freopen("input.txt", "r", stdin);
   string s = "CODEFESTIVAL2016";
   string t;
   cin>>t;
   int ans = 0;
   for(int i = 0; i < t.size(); ++i)
      if(t[i] != s[i])++ans;
   cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<" ---------------------------------------------- "<<endl
#define uint unsigned int 
#define ULL unsigned long long
#define DB long double
#define LDB long double
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define rint register int 
namespace IO{
	const int BS=(1<<23)+5; int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout),OS=OT;}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush();}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	inline LL read(){
		LL nm=0; bool fh=true; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) fh^=(cw=='-');
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return fh?nm:-nm;
	}
} using namespace IO;
#define mod 998244353
namespace CALC{
	inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
	inline int mns(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
	inline int mul(int x,int y){return (LL)x*(LL)y%mod;}
	inline void upd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
	inline void dec(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
	inline int qpow(int x,LL sq){int res=1;for(;sq;sq>>=1,x=mul(x,x))if(sq&1)res=mul(res,x);return res;}
}using namespace CALC;
#define M 500020

int main(){
	int A=read(),B=read(),C=read(),D=read();
	int S=A*60+B,T=C*60+D,W=read();
	printf("%d\n",max(T-S-W,0));
	return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
  int n, m, c;
  cin >> n >> m >> c;

  vector<int> b(m);
  vector<vector<int>> a(n, vector<int>(m, 0));
  for (int i = 0; i < m; i++) cin >> b[i];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int ans(0);
  for (int i = 0; i < n; i++) {
    ll score = 0;
    for (int j = 0; j < m; j++) score += a[i][j] * b[j];
    if (score + c > 0) {
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		int ans=0;

		int max=0;

		for(int i=0;i<N;i++) {

			int now=sc.nextInt();

			if(max<=now) ans++;

			if(max<now) max=now;

		}

		System.out.println(ans);

		sc.close();

	}

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,count=0;
  cin>>a>>b>>c>>d;
  int s[105]={};
  for(int i=a;i<b;++i){
    s[i]++;
  }
  for(int i=c;i<d;++i){
    s[i]++;
  }
  for(int i=0;i<101;++i){
    if(s[i]>1){
      count++;
    }
  }
  cout<<count;
  return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    ans = n

    for i in range(1, int(n ** 0.5) + 1):
        if n % i != 0:
            continue
        j = n // i
        ans = min(ans, i + j - 2)

    print(ans)


if __name__ == "__main__":
    main()


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

int main(void) {
	int x, n;
	int p[105] = { 0 };
	int result = 0;

	scanf("%d", &x);
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		int a = 0;
		scanf("%d", &a);
		p[a] = 1;
	}

	int dif = 500;
	int num = 500;
	for (int i = -101; i <= 101; i++) {
		if (p[i] == 0) {
			if (abs(x - i) == dif) {
				if (i < num) {
					num = i;
				}
			}
			else if (abs(x - i) < dif) {
				dif = abs(x - i);
				num = i;
			}
		}
	}

	printf("%d", num);

	return 0;
}

Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }


int main(){
    string S;
    cin>>S;
    int x=0;
    for(auto a:S){
        if(a=='+'){
            ++x;
        }else
        {
            --x;
        }
        
    }
    cout<<x<<endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int N;
    cin >> N;
    vector<LL> a(N);
    rep(i, N) cin >> a[i];
    bool f = 0;
    sort(all(a));
    auto b = a;
    a.erase(unique(all(a)), a.end());
    // cout << a.size() << endl;
    if(a.size() == 3){
        if((a[0]^a[1]) == a[2]) f = 1;
        if((a[1]^a[2]) == a[0]) f = 1;
        if((a[2]^a[0]) == a[1]) f = 1;
        int a1 =0, a2 = 0, a3 = 0;
        repe(i, b){
            if(i == a[0]) a1++;
            if(i == a[1]) a2++;
            if(i == a[2]) a3++;
        }
        if(!(a1==a2 && a2==a3)) f = 0;
    }else if(a.size() == 2){
        int a1 = 0, a2 = 0;
        for(auto x : b){
            if(x == a[0]) a1++;
            else a2++;
        }
        if(a[0] == 0 && 2*a1 == a2) f = 1;
    }else if(a.size() == 1){
        if(a[0] == 0) f = 1;
    }
    cout << (f ? "Yes" : "No" ) << endl;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
const double PI = acos(-1);
typedef long long ll;


int main(void){
    string S;cin>>S;
    int ans=INF;
    REP(i,S.size()-2){
        int a=0,k=100;
        FOR(j,i,i+3){
            a+=k*(S[j]-'0');
            k/=10;
        }
        ans=min(ans,abs(753-a));
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 256
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        long total = 1;
        int[] bases = new int[31];
        long[] values = new long[31];
        bases[0] = 1;
        values[0] = 2;
        for (int i = 1; i < 31; i++) {
            bases[i] = bases[i - 1] * 2;
            values[i] = values[i - 1] * values[i - 1] % MOD;
        }
        long ans = 1;
        int x = n;
        for (int i = 30; i >= 0; i--) {
            if (x >= bases[i]) {
                ans *= values[i];
                ans %= MOD;
                x -= bases[i];
            }
        }
		ans += MOD - getComb(n, a);
		ans += MOD - getComb(n, b);
		ans += MOD - 1;
		ans %= MOD;
		System.out.println(ans);
   }
   
   static long getComb(long n, long x) {
       long ans = 1;
       long base = 1;
       for (int i = 0; i < x; i++) {
           ans *= n - i;
           ans %= MOD;
           base *= x - i;
           base %= MOD;
       }
       long[] arr = new long[31];
       arr[0] = base;
       for (int i = 1; i < arr.length; i++) {
           arr[i] = arr[i - 1] * arr[i - 1];
           arr[i] %= MOD;
       }
       int target = MOD - 2;
       long alpha = 1;
       for (int i = 30; i >= 0; i--) {
           if (target >= (1 << i)) {
               alpha *= arr[i];
               alpha %= MOD;
               target -= (1 << i);
           }
       } 
       return ans * alpha % MOD;
   }
}


Measured memory_bytes: 22868
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<string> s(3);
  FOR(i,0,3)cin>>s[i];
  cout<<s[0][0]<<s[1][1]<<s[2][2]<<endl;
  return 0;
}

Measured memory_bytes: 256
from itertools import combinations
import numpy as np
import sys
input   = sys.stdin.readline
        #買う本
N, M, X = map(int, input().split())
items   = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
flag    =False
price_list  =[]
#for c in itertools.product([False, True], repeat=N):
for num in range(1,N+1): #1冊からN冊まで
    for t in combinations(all_book,num): #参考書を買う組合せ、全列挙
        book_buy        =np.array(t,dtype=int) 
        understand_now  = items[book_buy] 
        tmp             = np.sum(understand_now, axis=0)
        if np.all(tmp[1:] >= X):
            price_list.append(np.sum(tmp[0]))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)

//repetition
//------------------------------------------
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T> ostream & operator<<(ostream& os, vector<T> const& v){
        for(auto it=v.begin(); it!=v.end(); ++it){
            os << *it << (it+1==v.end() ? "" : ",");
        }
        return os;
    }
}

//clear memory
#define clr(a) memset((a), 0 ,sizeof(a))

int gcd(int a, int b){
   int tmp;
   while(a%b!=0){
      tmp=a%b;
      a=b;
      b=tmp;
   }
}
 
int lcm(int a,int b){
   return a*b/gcd(a,b);
}
 
bool prime_number(int n){
   if(n==0||n==1) return false;
   vb a(n+1);
   fill(all(a),true);
   loop(i,2,n/2+1){
      if(!a[i]) continue;
      for(int j=2;i*j<=n;j++){
         a[i*j]=false;
      }
   }
   return a[n];
}

int main(){
   int a,b;
   while(cin >> a >> b){
      cout << a+ b << endl;
   }
}

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

int main() {
    int T;
    cin >> T;
    for (int z = 0; z < T; z++) {
        ll N;
        cin >> N;
        ll A, B, C, D;
        cin >> A >> B >> C >> D;
        priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
        pq.push({0, N});
        ll inf = 1e18;
        map<ll, ll> mp;
        mp[N] = 0;
        mp[0] = inf;
        
        while (!pq.empty()) {
            ll cost = pq.top().first;
            ll now = pq.top().second;
            pq.pop();
            
            if (now != N && mp.find(now) != mp.end() && mp[now] <= cost) continue;
            
            mp[now] = cost;
            
            if (now == 0) {
                break;
            }
            
            if (now < inf/D) {
                if (D*now+cost < mp[0]) {
                    mp[0] = D*now+cost;
                }
                if (now == 1) break;
            }
            
            if (now%2 == 0) {
                pq.push({cost+A, now/2});
            }else {
                ll t = now%2;
                pq.push({cost+D*t+A, (now-t)/2});
                pq.push({cost+D*(2-t)+A, (now+2-t)/2});
            }
            if (now%3 == 0) {
                pq.push({cost+B, now/3});
            }else {
                ll t = now%3;
                pq.push({cost+D*t+B, (now-t)/3});
                pq.push({cost+D*(3-t)+B, (now+3-t)/3});
            }
            
            if (now%5 == 0) {
                pq.push({cost+C, now/5});
            }else {
                ll t = now%5;
                pq.push({cost+D*t+C, (now-t)/5});
                pq.push({cost+D*(5-t)+C, (now+5-t)/5});
            }
        }
        
        cout << mp[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 4180
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 = new int[n];
		int[] b = new int[n];
		for(int i = 0; i < n - 1; i++) {
			b[i] = sc.nextInt();
		}
		a[0] = b[0];
		a[1] = b[0];
		for(int i = 1; i < n - 1; i++) {
			if(b[i] < a[i]) {
				a[i] = b[i];
			}
			a[i + 1] = b[i];
		}
		int ans = 0;
		for(int i = 0; i < n; i++) {
			ans += a[i];
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 25172
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int t, e;
    cin >> t >> e;

    vector<double> c(2*t+1);
    for(int i=0; i<2*t+1; ++i)
        cin >> c[i];

    // ツ熱ツつウT+1ツつセツつッツ嘉熱ツつキツづゥツつスツづ淞づ可必ツ要ツづ按催渉ャツエツネツδ仰ギツー
    double minLeft = 0.0;
    double minRight = 0.0;
    for(int i=0; i<t; ++i){
        minLeft = min(minLeft + c[i], c[i] * (i+1));
        minRight = min(minRight + c[2*t-i], c[2*t-i] * (i+1));
    }
    double minEnergy = min(minLeft + minRight + c[t], c[t] * (t+1));

    double ret = e / minEnergy * (t+1);
    printf("%.10f\n", ret);

    return 0;
}

Measured memory_bytes: 2484
// 1_abc144_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a > 9 || b > 9) cout << - 1 << endl;
    else cout << a * b << endl;
    return 0;
}


Measured memory_bytes: 256
S = input ( )

dusted = False
cont = False
line = 'keyence'
find = S.find ( 'keyence' )
rfind = S.rfind ( 'keyence' )
#print ( 'find {} rfind {}'.format ( find, rfind ) )
if find == 0 or rfind == len ( S ) - 7:
    print ( 'YES' )
    exit ( 0 )
elif find != -1:
    print ( 'NO' )
    exit ( 0 )

fs = True
line = ''
keyence = [ c for c in "keyence" ]
a_err=False
b_err=False
keyence2='keyence'
count=0
for i in range(len ( S )):

    #print ( keyence )
    #print ( 'i {} ri {}'.format ( S[i], S[len(S)-1-i] ) )
    try:
        if not  b_err:
            #print ( 'key2 {} S {}'.format ( keyence2[ 6 - i ], S[ len ( S ) - 1 - i ] ) )

            if keyence2[ 6 - i ] != S[ len ( S ) - 1 - i ]:
                b_err=True
            if not b_err:
                keyence.remove ( S[len(S)-1-i] )

            count+=1

    except ValueError:
        b_err=True

    if not keyence:
        print ( 'YES' )
        exit ( 0 )
    try:
        if not a_err:
            if keyence2[ i ] != S[ i]:
                a_err=True
            if not a_err:
                keyence.remove ( S[i] )
    except ValueError:
        a_err=True

    if a_err and b_err:
        print('NO')
        exit(0)

    if not keyence:
        print ( 'YES' )
        exit ( 0 )



Measured memory_bytes: 3064
#include<iostream>
#include<string.h>
using namespace std;

string ch(int,int,int,int);
int main(void)
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<ch(a,b,c,d)<<endl;
    return 0;
} 

string ch(int a,int b,int c,int d)
{
    if(a==1||b==1||c==1||d==1) 
    if(a==9||b==9||c==9||d==9) 
    if(a==7||b==7||c==7||d==7)
    if(a==4||b==4||c==4||d==4) return "YES";
    return "NO";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int c = 0;
    for (int i = 0; i < 3; i++) {
        c += (s[i] == t[i]);
    }
    cout << c << endl;
}


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

int main(){
	int n, q, tmp, count = 0;
	string s;
	queue<pair<string,int>> q1;
	cin >> n >> q;
	for(int i=0;i<n;i++){
		cin >> s >> tmp;
		q1.push(make_pair(s,tmp));
	}
	while(!q1.empty()){
		tmp = q1.front().second; ///
		s = q1.front().first;    ///
		q1.pop();
		if(tmp > q){
			count += q;
			tmp -= q;
			q1.push(make_pair(s,tmp));
		}
		else{
			count += tmp;
			cout << s << ' ' << count << endl;
		}
		
	}
	return 0;
	
	
}


Measured memory_bytes: 6384
using System;

namespace ITP1_1_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int a = int.Parse(strs[0]);
            int b = int.Parse(strs[1]);
            Console.WriteLine("{0} {1}", a * b, (a + b) << 1);
        }
    }
}

Measured memory_bytes: 9004
#include <iostream>

using namespace std;

int main(){
    int x,y;
    
    while (true) {
        cin >> x >> y;
        if(x==0 && y==0){
            break;
        }
        for(int i=0;i<x;i++){
            for(int j=0;j<y;j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3100
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 200
int main() {
	char s[N] = "", x[N]="", ss[N] = "", *p1, *p2;
	int i= 0,j,k,flg = 0,xLength;
	char n[2][5] = { {"No"},{"Yes"} };
	fgets(s,sizeof(s),stdin);
	fgets(x,sizeof(x),stdin);
	
	s[strlen(s) - 1] = '\0';
	x[strlen(x) - 1] = '\0';
	strcat(ss, s);
	strcat(s, ss);
	p1 = s;
	p2 = x;
	xLength = strlen(x);

	while (*p1) {
		j = 0;
		if (*p1 == *p2) {
			//printf("*%c\n", *p1);
			for (k = 1; k <= xLength; k++) if (*(p2+k) != *(p1+k)) { 
				//printf("*%d %c %c\n",i, *(p2 + k), *(p1+ k)); 
				break; }
		}
		if (k == xLength) { flg = 1;  break; }
		*(p1++);
		i++;
	}
	/*while (i<=strlen(s)-strlen(x)) {
		j = 0;
		if (s[i] == x[j]) {
			for (k = 1; k <= strlen(x); k++)
				if (x[j + k] != s[i + k]) break;
		}
		if (k == strlen(x)) {
			flg = 1;
			break;
		}
		j++;
		i++;
	}
	*/
	printf("%s\n", n[flg]);
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <string>

using namespace std;
typedef long long ll;

#define RPT(i, n) for (int i = 0; i < n; i++)

ll div_2(double a)
{
    return
        (a >= 0) ? (ll)(-1 * a) / 2 :
        (((ll)a) % 2 == 0) ? (ll)(-1 * a) / 2 : (ll)(-1 * a) / 2 + 1;
}

ll mod_2(double a)
{
    return (a - div_2(a) * (-2));
}

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

    if (N == 0) {
        cout << 0 << endl;
        return 0;
    }

    string ans = "";
    ll cur = N;
    while (cur != 0) {
        int Sk = mod_2(cur);
        cur = div_2(cur);
        ans.insert(0, to_string(Sk));
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    vector<string> s{"Sunny", "Cloudy", "Rainy"};
    string x;
    cin >> x;
    int a = 0;
    for (int i = 0; i < 3; i++)if (s[i] == x)a = i;
    cout << s[(a + 1) % 3] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 100000 + 100;
int n, a[N];
char st[N];

bool print() {
	for (int i = 0; i < n; ++i)
		putchar(a[i] == 1 ? 'W' : 'S');
	puts("");
	return true;
}

bool check2() {
	if (a[n - 1] == 0) {
		if (st[n - 1] == 'o') {
			if (a[0] == a[n - 2])
				return print();
			else return false;
		}
		else {
			if (a[0] != a[n - 2])
				return print();
			else return false;
		}
	}
	else {
		if (st[n - 1] == 'x') {
			if (a[0] == a[n - 2])
				return print();
			else return false;
		}
		else {
			if (a[0] != a[n - 2])
				return print();
			else return false;
		}
	}
}
bool check() {
	for (int i = 1; i + 1 < n; ++i) {
		if (a[i] == 0) {
			if (st[i] == 'o') {
				a[i + 1] = a[i - 1];
			}
			else {
				a[i + 1] = !a[i - 1];
			}
		}
		else {
			if (st[i] == 'x') {
				a[i + 1] = a[i - 1];
			}
			else {
				a[i + 1] = !a[i - 1];
			}
		}
	}

	if (a[0] == 0) {
		if (st[0] == 'o') {
			if (a[1] == a[n - 1])
				return check2();
			else return false;
		}
		else {
			if (a[1] != a[n - 1])
				return check2();
			else return false;
		}
	}
	else {
		if (st[0] == 'x') {
			if (a[1] == a[n - 1])
				return check2();
			else return false;
		}
		else {
			if (a[1] != a[n - 1])
				return check2();
			else return false;
		}
	}
}

int main() {
	cin >> n;
	scanf("%s", st);
	a[0] = a[1] = 0;
	if (check()) return 0;
	a[0] = a[1] = 1;
	if (check()) return 0;
	a[0] = 0; a[1] = 1;
	if (check()) return 0;
	a[0] = 1; a[1] = 0;
	if (check()) return 0;
	puts("-1");
	return 0;
}

Measured memory_bytes: 768
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        long t=sc.nextInt();
        long[] nums=new long[n+1];
        for(int i=0;i<n;i++){
            nums[i]=sc.nextInt();
        }
        nums[n]=Long.MAX_VALUE;
        long output=0;
        for(int i=0;i<n;i++){
            output+=Math.min(t, nums[i+1]-nums[i]);
        }
        System.out.println(output);
    }
     
}

Measured memory_bytes: 87212
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
 
#define mp make_pair
#define f first
#define s second
 
using namespace std;
 
typedef pair<int,int> P;
 
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int h,w;
string grid[1000];
int d[1000][1000];
 
void bfs(P S){
 
  queue<P>que;
  que.push(S);
  d[S.f][S.s]=0;
 
  while(!que.empty()){
    P now=que.front();
     
    que.pop();
    for(int i=0;i<4;i++){
      if(0<=now.f+dx[i] && 0<=now.s+dy[i] &&
     now.f+dx[i]<h && now.s+dy[i]<w
     && grid[now.f+dx[i]][now.s+dy[i]]!='X'){
 
    if(d[now.f][now.s]+1<d[now.f+dx[i]][now.s+dy[i]]){
      d[now.f+dx[i]][now.s+dy[i]]=d[now.f][now.s]+1;
      que.push(P(now.f+dx[i],now.s+dy[i]));
    }
      }
    }
  }
}
 
int main(void){
  int n;
  P v[1001];
 
  cin >> h >> w >> n;
 
  for(int i=0;i<h;i++)cin >> grid[i];
 
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(grid[i][j]=='S')v[0]=mp(i,j);
      if(grid[i][j]!='X'&&grid[i][j]!='.')
    v[grid[i][j]-'0']=mp(i,j);
    }
  }
 
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<h;j++)
      for(int k=0;k<w;k++)d[j][k]=100000000;
    bfs(v[i]);
    ans+=d[v[i+1].f][v[i+1].s];
  }
 
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 6184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	
	ll n; cin>>n;
	ll a[n]; ll c[n]; ll b[n]; ll sum = 0;
	for(int i = 0; i < n; i++) cin>>a[i];
	for(int i = 0; i < n; i++) cin>>b[i];
	for(int i = 0; i < n-1; i++) cin>>c[i];
	for(int i = 0; i < n; i++){
		sum += b[a[i]-1];
		if(i > 0) if(a[i]-1 == a[i-1]){
			sum += c[a[i]-2];
		}
	}
	cout<<sum<<"\n";
	
	
	
}

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

int main(){
    int n;
    vector<string> name;
    int answer = 0;

    cin >> n;

    string input;
    for(int i = 0; i < n; i++){
        cin >> input;
        name.push_back(input);
    }

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

    for(int i = 0; i < n; i++){
        if(i==0){
            answer++;
            continue;
        }

        if(name[i].compare(name[i-1]) != 0 ){
            answer++;
        }
    }

    cout << answer;
    
}

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

#define ll long long
#define int ll
#define pii pair<int, int>
#define pb push_back
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

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

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    REP(i, N-1) {
        A[i+1] = gcd(A[i], A[i+1]);
    }
    
    print(A[N-1]);
}

signed main() {
    solve();
}


Measured memory_bytes: 1024
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline().rstrip()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N = iIn()

A = [2, 1]

for i in range(N):
  var = A[-2] + A[-1]
  A.append(var)
  
print(A[N])

Measured memory_bytes: 61968
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

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

  if(A>K) cout << A-K << " " << B << endl;
  else if( A+B>K) cout << 0 << " " << B-(K-A) << endl;
  else cout << 0 << " " << 0 << endl;
}

Measured memory_bytes: 256
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

const int MAXN = 100010;

int n;
vector<int> g[100010];

int zeit, dis[MAXN], fin[MAXN], low[MAXN], par[MAXN], dep[MAXN];
int kodat[MAXN], koptr[MAXN + 1];
void dfsInfo(int u,int oy,int d){
	dis[u] = low[u] = zeit++; par[u] = oy; dep[u] = d;
	int v;
	rep(i,sz(g[u])) if((v = g[u][i]) != oy){
		if(!~dis[v]){
			dfsInfo(v, u, d + 1);
			low[u] = min(low[u], low[v]);
		} else {
			low[u] = min(low[u], dis[v]);
		}
	}
	fin[u] = zeit++;
}

void dfsInfos(){
	memset(dis, ~0, n*4); zeit = 0;
	rep(u,n) if(!~dis[u]) dfsInfo(u, -1, 0);
	rep(u,n){
		int &j = koptr[u + 1] = koptr[u];
		rep(i,sz(g[u])) if(u == par[g[u][i]]) kodat[j++] = g[u][i];
	}
}

bool produce(int u,int v){
	return (dis[u] <= dis[v] && fin[u] >= fin[v]);
}

int related(int u,int v){
	int s = koptr[u], e = koptr[u+1], h;
	while(s+1 < e){
		h = (s + e) >> 1;
		(dis[kodat[h]] <= dis[v]) ? s = h : e = h;
	}
	return kodat[s];
}

bool isBridge(int u,int v){
	if(dis[u] > dis[v]) swap(u, v);
	return (u == par[v] && dis[v] <= low[v]);
}

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

	int m;
	cin>>n>>m;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	rep(i,n)sort(g[i].begin(),g[i].end());
	dfsInfos();
	/*rep(i,n)rep(j,sz(g[i])){
		if(i<g[i][j] && isBridge(i,g[i][j]))cout<<i<<" "<<g[i][j]<<endl;
	}*/
	//rep(i,n)cout<<dis[i]<<" ";cout<<endl;
	//rep(i,n)cout<<low[i]<<" ";cout<<endl;
	rep(i,n)rep(j,sz(g[i])){
		if(i<g[i][j] && (dis[i] < low[g[i][j]] || dis[g[i][j]] < low[i])){
			cout<<i<<" "<<g[i][j]<<endl;
		}
	}
}

Measured memory_bytes: 5960
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    cout << 3 * n * n << endl;

    return 0;
}

// vim: set foldmethod=marker :


Measured memory_bytes: 256