akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

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);
}

//-----end of template-----//

using ll = long long int;
ll PowMod(ll N, ll P){
    ll ans = 1;
    for(ll i=0; i<P; ++i){
        ans *= N;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	i64 n, p;
	cin >> n >> p;
	i64 i = 1, ans = 0;
	if(n == 1){
		cout << p << endl;
		return 0;
	}
	if(n >= 40){
		cout << 1 << endl;
		return 0;
	}
	while(true){
		i64 res = PowMod(i, n);
		if(p < res) break;
		else if(p % res == 0) ans = i;
		++i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int N,Y;

	cin >> N >> Y;

	for (int i = 0; i <= N; i++) {
		for (int j = 0; i + j <= N; j++)
		{
			if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
				cout << i << " " << j << " " << N - i - j << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int sz=105;
int n;
char a[5]={'A', 'C', 'G','T','s'};
long long dp[sz][5][5][5];
long long m=1e9+7;
long long add(long long a,long long b){return (a%m+b%m)%m;}

/*
AGC
GAC
ACG
*/

long long solve(int idx,int p1=4,int p2=4,int p3=4){
    long long &ret=dp[idx][p1][p2][p3];
    if(~ret) return ret;
    if(!idx) return ret=1;
    ret=0;
    for(int i=0;i<4;i++){
        if(a[i]=='A'&&a[p1]=='G'&&a[p2]=='C') continue;
        if(a[i]=='G'&&a[p1]=='A'&&a[p2]=='C') continue;
        if(a[i]=='A'&&a[p1]=='C'&&a[p2]=='G') continue;
        if(a[i]=='A'&&a[p2]=='G'&&a[p3]=='C') continue;
        if(a[i]=='A'&&a[p1]=='G'&&a[p3]=='C') continue;
        ret=add(ret,solve(idx-1,i,p1,p2));
    }
    return ret;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d",&n);
    memset(dp,-1,sizeof(dp));
    printf("%lld",solve(n));
    return 0;
}


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

using namespace std;

using int64 = long long;

int main() {

  int X[500][500];

  int C;
  cin >> C;
  if(C == 1) {
    cout << 1 << endl;
    cout << 1 << endl;
    return 0;
  }
  int K = 2 * ((C + 3) / 4);
  for(int i = 0; i < K; i++) {
    for(int j = 0; j < K; j++) {
      if(i % 2 == 0) X[i][j] = (i + j) % K;
      else X[i][j] = K + (i + j) % K;
    }
  }

  cout << K << endl;
  for(int i = 0; i < K; i++) {
    for(int j = 0; j < K; j++) {
      ++X[i][j];
      if(X[i][j] > C) X[i][j] -= K;
      cout << X[i][j] << " ";
    }
    cout << endl;
  }
}



Measured memory_bytes: 2176
s1 = input()

s2 = s1[0:2]
s3 = s1[2:4]

f1 = True
f2 = True

if int(s2) <= 0 or int(s2) >= 13:
    f1 = False

if  int(s3) <= 0 or int(s3) >= 13:
    f2 = False

s4 = ""
if f1 == False and f2 == False:
    s4 = "NA"
elif f1 == True and f2 == False:
    s4 = "MMYY"
elif f1 == False and f2 == True:
    s4 = "YYMM"
else:
    s4 = "AMBIGUOUS"

print(s4)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;

int s(string str, int j) {
    int i = j;
    if (str[i] == '(') {
        while(true) {
            i++;
            if (str[i] == ')') {
                return i;
            } else if (str[i] == '[' || str[i] == '(') {
                i = s(str, i);
                if (i == -1) {
                    return -1;
                }
            } else if (str[i] == ']' || str[i] == '.') {
                return -1;
            }
        }
    } else {
        while(true) {
            i++;
            if (str[i] == ']') {
                return i;
            } else if (str[i] == '[' || str[i] == '(') {
                i = s(str, i);
                if (i == -1) {
                    return -1;
                }
            } else if (str[i] == ')' || str[i] == '.') {
                return -1;
            }
        }
    }
}

int main() {
    while(true) {
        int i;
        int cntr = 0;
        int cntk = 0;
        int result = 0;
        string ch;

        getline(cin, ch);
        for (i = 0; i < 100; i++) {
            if (ch[i] == '(' || ch[i] == '[') {
                result = s(ch, i);
                i = result;
                if (result == -1) {
                    break;
                }
            } else if (ch[i] == ')' || ch[i] == ']') {
                result = -1;
                break;
            } else if (ch[i] == '.') {
                result = 0;
                break;
            }
        }
        if (ch[0] == '.') {
            break;
        } else if (result != -1) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
}


Measured memory_bytes: 3164
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    if(a<=b && a<=c)
    {
        if(b<=c) cout<<a<<" "<<b<<" "<<c;
        else cout<<a<<" "<<c<<" "<<b;
    }
    else
    if(b<=a && b<=c)
    {
        if(a<=c) cout<<b<<" "<<a<<" "<<c;
        else cout<<b<<" "<<c<<" "<<a;
    }
    else
    if(c<=a && c<=b)
    {
        if(a<=b) cout<<c<<" "<<a<<" "<<b;
        else cout<<c<<" "<<b<<" "<<a;
    }
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <algorithm>
const int INF = 1e9;
using namespace std;

int main(void) {
    int A,B,M;cin>>A>>B>>M;
    vector<int> a(A), b(B);
    int min_a = INF;
    int min_b = INF;
    for (int i = 0; i < A; i++) {
        cin>>a[i];
        if (min_a > a[i]) min_a = a[i];
    }
    for (int i = 0; i < B; i++) {
        cin>>b[i];
        if (min_b > b[i]) min_b = b[i];
    }
    int min_discount = INF;
    for (int i = 0; i < M; i++) {
        int x,y,c;
        cin>>x>>y>>c;
        int res = a.at(x - 1) + b.at(y - 1) - c;
        if (res < min_discount) min_discount = res;
    }
    cout << min(min_a + min_b, min_discount) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[100];
  int n;cin >> n;
  for(int j=0;j<n;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  
  bool ff = true;
  for(int k=0;k<n-1;k++){
    for(int l=k+1;l<n;l++){
      bool f=false;
      for(int i=0;i<4;i++){
	d[l].roll('R');
	for(int j=0;j<4;j++){
	  d[l].roll('N');
	  if(same(d[k],d[l])) f=true;
	}
      }
      d[l].roll('E');
      for(int j=0;j<4;j++){
	d[l].roll('N');
	if(same(d[k],d[l])) f=true;
      }
      
      d[l].roll('W');
      d[l].roll('W');
      for(int j=0;j<4;j++){
	d[l].roll('N');
	if(same(d[k],d[l])) f=true;
      }
      if(f) ff=false;
    }
  }
  
  cout << (ff?"Yes":"No") << endl;
  return 0;
}



Measured memory_bytes: 3096
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, p: "List[int]"):
    p = sorted(p)
    print(sum(p[:K]))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)

if __name__ == '__main__':
    main()


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define Cin(x) cin >> x
#define Cin2(x,y) cin >> x >> y
#define Cin3(x,y,z) cin >> x >> y >> z
#define Cin4(w,x,y,z) cin >> w >> x >> y >> z
#define Cout(x) cout << x << "\n"
#define Cout2(x,y) cout << x << y << "\n"
#define Cout3(x,y,z) cout << x << y << z << "\n"
#define Cout4(w,x,y,z) cout << w << x << y << z << "\n"
#define Kaigyou cout << "\n"
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define Size(n) (n).size()
#define All(v) (v).begin(), (v).end()

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

    string s,t="";
    Cin(s);
    string rev[4] =  {"maerd","remaerd","esare","resare"};
    reverse(All(s));
    ll size = Size(s);
    rep(i,size){
        t += s[i];
        if(t==rev[0] || t==rev[1] || t==rev[2] || t==rev[3]){
            t = "";
        }
    }
    if(t==""){
        Cout("YES");
    }else{
        Cout("NO");
    }
    return 0;
}

Measured memory_bytes: 640
import bisect

REPEAT_NUM = 10 ** 100

S = input()
T = input()
lenS = len(S)
lenT = len(T)

idxes_S = {}
for idx, s in enumerate(S):
    if s not in idxes_S:
        idxes_S[s] = []
    idxes_S[s].append(idx)

idx_s = -1
idx_t = 0
while idx_t < lenT and idx_s < lenS * REPEAT_NUM:
    if T[idx_t] not in idxes_S:
        print(-1)
        exit()
    else:
        tmp_idx = bisect.bisect(idxes_S[T[idx_t]], idx_s % lenS)
        if len(idxes_S[T[idx_t]]) == tmp_idx:
            idx_s += lenS - idx_s % lenS + idxes_S[T[idx_t]][0]
        else:
            idx_s += idxes_S[T[idx_t]][tmp_idx] - idx_s % lenS
        idx_t += 1

if idx_t == lenT:
    print(idx_s + 1)
else:
    print(-1)

Measured memory_bytes: 45904
#include <iostream>
#define INF 1e+9
using namespace std;

int main(){
	int h,w,d,res = 0;
	char field[100][100];
	cin >> h >> w >> d;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			cin >> field[i][j];
		}
	}
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w - d + 1;j++){
			bool flag = true;
			for(int k = 0;k < d;k++){
				if(field[i][j + k] == '#') flag = false;
			}
			if(flag) res++;
		}
	}
	for(int i = 0;i < w;i++){
		for(int j = 0;j < h - d + 1;j++){
			bool flag = true;
			for(int k = 0;k < d;k++){
				if(field[j + k][i] == '#') flag = false;
			}
			if(flag) res++;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	string s, t;
	cin >> s >> t;

	vvi chr(26);
	rep(i, s.size()) chr[s[i] - 'a'].push_back(i);

	int loop = 0, k = 0;
	rep(i, t.size()) {
		int s = lower_bound(all(chr[t[i] - 'a']), k) - chr[t[i] - 'a'].begin();
		if (s == chr[t[i] - 'a'].size()) {
			loop++;
			s = lower_bound(all(chr[t[i] - 'a']), 0) - chr[t[i] - 'a'].begin();
			if (s == chr[t[i] - 'a'].size()) {
				cout << -1 << endl;
				return 0;
			}
		}
		k = chr[t[i] - 'a'][s] + 1;
	}

	cout << loop * (ll)s.size() + k << endl;

}

Measured memory_bytes: 1216
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){

    ll h,w;
    cin >> h >> w;
    char a[h][w];
    REP(i,h)
    {
        REP(j,w)
        {
            cin >> a[i][j];
        }
    }
    string res = "Possible";

    ll migi = 0;
    REP(i,h)
    {
        REP(j,w)
        {
            if(a[i][j] == '#')
            {
                if(i == 0)
                {
                    migi = j;
                }else
                {
                    if(j < migi)
                    {
                        res = "Impossible";
                    }
                    else
                    {
                        migi = j;
                    }
                }
            }
        }
    }
    cout << res << endl;
    return 0;    
}



Measured memory_bytes: 764
H, W = map(int, input().split())
coins = [list(map(int, input().split())) for _ in range(H)]

def next():
    i = j = k = 0
    while k < H*W - 1:
        k += 1
        i = k // W
        if k % W != 0:
            j += (-1)**(i)
        
        yield i, j

log = []
i = j = 0
n = next()
for ni, nj in n:
    if coins[i][j] % 2 == 1:
        coins[i][j] -= 1
        coins[ni][nj] += 1
        log.append((i+1, j+1, ni+1, nj+1))
    i, j = ni, nj

print(len(log))
for i in log:
    print(*i)

Measured memory_bytes: 26660
#include<iostream>
#include<sstream>
#include<cmath>
using namespace std;

int main()
{

int n,k;
cin>>k>>n;
for(int i=k-1;i>=0;i--){
	cout<<n-i<<" ";
}
for(int j=1;j<k;j++){
	cout<<n+j<<" ";
}

}



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

int main() {
  char s1, s2, s3; 
  cin >> s1 >> s2 >> s3;
  if (s1 != s2 && s1 != s3)
    cout << "Yes" << endl;
  else if (s1 != s2 && s2 != s3)
    cout << "Yes" << endl; 
  else if (s1 != s3 && s2 != s3)
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
a,b,q=(input().split())
a,b,q=int(a),int(b),int(q)
s=[int(input()) for i in range(a)]
t=[int(input()) for i in range(b)]
x=[int(input()) for i in range(q)]
dist=['' for i in range(8)]
dist1=['' for i in range(2)]
dist2=['' for i in range(4)]
sp1=['' for i in range(2)]
tp1=['' for i in range(4)]

import bisect
for k in range(q):

    p1=bisect.bisect_left(s,x[k])

    if p1==0:
        dist1[0]=s[0]-x[k]
        dist1[1]=s[0]-x[k]
        sp1[0]=s[0]
        sp1[1]=s[0]        
    elif p1==a:
        dist1[0]=x[k]-s[a-1]
        dist1[1]=x[k]-s[a-1]
        sp1[0]=s[a-1]
        sp1[1]=s[a-1]
    else:
        dist1[0]=x[k]-s[p1-1]
        dist1[1]=s[p1]-x[k]
        sp1[0]=s[p1-1]
        sp1[1]=s[p1]
 
    p11=bisect.bisect_left(t,sp1[0])

    if p11==0:
        dist2[0]=t[0]-sp1[0]
        dist2[1]=t[0]-sp1[0]
    elif p11==b:
        dist2[0]=sp1[0]-t[b-1]
        dist2[1]=sp1[0]-t[b-1]
    else:
        dist2[0]=sp1[0]-t[p11-1]
        dist2[1]=t[p11]-sp1[0]
        
    p11=bisect.bisect_left(t,sp1[1])

    if p11==0:
        dist2[2]=t[0]-sp1[1]
        dist2[3]=t[0]-sp1[1]
    elif p11==b:
        dist2[2]=sp1[1]-t[b-1]
        dist2[3]=sp1[1]-t[b-1]
    else:
        dist2[2]=sp1[1]-t[p11-1]
        dist2[3]=t[p11]-sp1[1]
        
    dist[0]=dist1[0]+dist2[0]
    dist[1]=dist1[0]+dist2[1]
    dist[2]=dist1[1]+dist2[2]
    dist[3]=dist1[1]+dist2[3]
                

    p1=bisect.bisect_left(t,x[k])

    if p1==0:
        sp1[0]=t[0]
        sp1[1]=t[0]
        dist1[0]=t[0]-x[k]
        dist1[1]=t[0]-x[k]
    elif p1==b:
        sp1[0]=t[b-1]
        sp1[1]=t[b-1]
        dist1[0]=x[k]-t[b-1]
        dist1[1]=x[k]-t[b-1]
    else:
        sp1[0]=t[p1-1]
        sp1[1]=t[p1]
        dist1[0]=x[k]-t[p1-1]
        dist1[1]=t[p1]-x[k]
        
    p11=bisect.bisect_left(s,sp1[0])

    if p11==0:
        dist2[0]=s[0]-sp1[0]
        dist2[1]=s[0]-sp1[0]
    elif p11==a:
        dist2[0]=sp1[0]-s[a-1]
        dist2[1]=sp1[0]-s[a-1]
    else:
        dist2[0]=sp1[0]-s[p11-1]
        dist2[1]=s[p11]-sp1[0]
    
    p11=bisect.bisect_left(s,sp1[1])

    if p11==0:
        dist2[2]=s[0]-sp1[1]
        dist2[3]=s[0]-sp1[1]       
    elif p11==a:
        dist2[2]=sp1[1]-s[a-1]
        dist2[3]=sp1[1]-s[a-1]
    else:
        dist2[2]=sp1[1]-s[p11-1]
        dist2[3]=s[p11]-sp1[1]

    dist[4]=dist1[0]+dist2[0]
    dist[5]=dist1[0]+dist2[1]
    dist[6]=dist1[1]+dist2[2]
    dist[7]=dist1[1]+dist2[3]
    
    ans=min(dist[0],dist[1],dist[2],dist[3],dist[4],dist[5],dist[6],dist[7])

    print(ans)


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

typedef long long ll;

ll mypow(ll n,ll p){
  if (p == 0)return 1;
  if (p == 1)return n;
  ll ret=mypow(n,p/2);
  ret=ret*ret;
  if (p&1)ret=ret*n;
  return ret;
}

ll getMul(int n, ll val, int num){
  return mypow(val, num/n);
}

long long solve(int n, ll p){
  ll ret = 1;
  for(ll i = 2;i*i <= p;i++){
    int num = 0;
    while(p % i == 0 && p/i != 0){
      p /= i;
      num++;
    }
    if (num != 0){
      ret *= getMul(n, i, num);
    }
  }
  if (p != 1){
    ret *= getMul(n, p, 1);
  }
  return ret;
}

int main(){
  int n;
  ll p;
  cin >> n >> p;
  cout << solve(n, p) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 1000002
#define pie 3.14159265358979323
#define minuss 1e-6
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
    char str[100];
    cin>>str;
    ll l=strlen(str);
    ll lock=0;
    for(int i=0;i<l-1;i++)
    {
        if(str[i]==str[i+1])
        {
            lock=1;
            break;
        }
    }
    if(lock==1)
        pf("Bad\n");
    else
        pf("Good\n");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,w;
	cin>>n>>w;
	vector<long int>dp(w+1,-1);
	dp[0]=0;
	int w1;
	long v1;
	for(int i=1;i<=n;i++){
		cin>>w1>>v1;
		// vector<bool>visited(w+1,0);
		for(int j=w;j>=w1;j--){
			if(dp[j-w1]!=-1){
				if(v1+dp[j-w1]>dp[j]){
					dp[j]=v1+dp[j-w1];
					// visited[j]=1;
				}
			}
		}
	}
	long res=INT_MIN;
	for(int i=0;i<=w;i++){
		res=max(res,dp[i]);
	}
	// cout<<endl;
	cout<<res;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k){
	while(u != NIL && k != u->key){
		if(k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *) malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while(x != NIL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		}else{
			x = x->right;
		}
	}

	z->parent = y;
	if(y == NIL){
		root = z;
	}else{
		if(z->key < y->key){
			y->left = z;
		}else{
			y->right = z;
		}
	}
}

void inorder(Node *u){
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u){
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main(){
	int n, i, x;
	string com;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		cin >> com;
		if(com[0] == 'f'){
			scanf("%d",&x);
			Node *t = find(root,x);
			if(t != NIL) printf("yes\n");
			else printf("no\n");
		}else if(com == "insert"){
			scanf("%d",&x);
			insert(x);
		}else if(com == "print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 21948
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(c>=a&&c<=b)
    {
        if(d>b)
            printf("%d",b-c);
        else
            printf("%d",d-c);
    }
    else if(a>=c&&a<=d)
    {
        if(b>d)
            printf("%d",d-a);
        else
            printf("%d",b-a);
    }
    else
        printf("0");
}


Measured memory_bytes: 256
import math
import itertools

n,m,q = map(int,input().split())
li=[input() for i in range(q)]

ans_list=list()
ans=0
xans=0

lis =  list(range(1,m+1))
for team in itertools.combinations_with_replacement(lis,n):
  
    for i in range(q):
      
      lix=li[i].split()
      
      if team[int(lix[1])-1]-team[int(lix[0])-1]==int(lix[2]):
        ans=int(lix[3])
        xans+=ans
        
       
        
    ans_list+=[xans]
    xans=0
      
    
    
print(max(ans_list))


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

public class Main {
    private void solve() {
        int H = sc.nextInt();
        int W = sc.nextInt();

        String[] g = new String[H];
        for (int i = 0; i < H; i++) {
            g[i] = sc.next();
        }

        int[][] dp = new int[H][W];
        for (int i = 0; i < H; i++) {
            Arrays.fill(dp[i], 10000000);
        }

        dp[0][0] = g[0].charAt(0) == '#' ? 1 : 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (g[i].charAt(j) == '#') {
                    if (i > 0) {
                        if (g[i - 1].charAt(j) == '#') {
                            dp[i][j] = Math.min(dp[i][j], dp[i - 1][j]);
                        } else {
                            dp[i][j] = Math.min(dp[i][j], dp[i - 1][j] + 1);
                        }
                    }

                    if (j > 0) {
                        if (g[i].charAt(j - 1) == '#') {
                            dp[i][j] = Math.min(dp[i][j], dp[i][j - 1]);
                        } else {
                            dp[i][j] = Math.min(dp[i][j], dp[i][j - 1] + 1);
                        }
                    }
                } else {
                    if (i > 0) {
                        dp[i][j] = Math.min(dp[i][j], dp[i - 1][j]);
                    }

                    if (j > 0) {
                        dp[i][j] = Math.min(dp[i][j], dp[i][j - 1]);
                    }
                }
            }
        }

        out.println(dp[H - 1][W - 1]);
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int K, X;
    cin >> K >> X;
    for (int i = X-K+1; i <= X+K-1; ++i) cout << i << " ";
    cout << endl;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn inv(a: i64, m: i64) -> Option<i64> {
    fn exgcd(r0: i64, a0: i64, b0: i64, r: i64, a: i64, b: i64) -> (i64, i64, i64) {
        if r > 0 {
            exgcd(r, a, b, r0 % r, a0 - r0 / r * a, b0 - r0 / r * b)
        } else {
            (a0, b0, r0)
        }
    }
    let (a, _, r) = exgcd(a, 1, 0, m, 0, 1);
    if r != 1 {
        None
    } else {
        Some(((a % m) + m) % m)
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let k: usize = sc.cin();
    let mut xs: Vec<i64> = sc.vec(n);
    xs.sort();
    let mut ans: i64 = 0;
    let mut comb = 1;
    for i in 0..n+1-k {
        ans += xs[k+i-1] * comb;
        ans %= M;
        ans -= xs[n-k-i] * comb;
        ans %= M;
        // trace!(xs[k+i-1], comb);
        // trace!(xs[n-k-i], comb);
        comb *= (k+i) as i64;
        comb %= M;
        comb *= inv((i+1) as i64, M).unwrap();
        comb %= M;
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 12324
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
    n: usize,
    k: usize,
    );
    let p = 1_000_000_007;

    let mut ans = 0;
    for i in k..=n + 1 {
        ans += (n + 2) * i - i * (i + 1) + 1;
    }
    println!("{}", ans % p);
}


Measured memory_bytes: 2148
/*
csc -debug A.cs && mono --debug A.exe <<< "30 100"
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;

public class HelloWorld {
    public static void SolveCodeForces() {
        var A = cin.NextInt();
        var B = cin.NextInt();

        if (A >= 13) System.Console.WriteLine(B);
        else if (A >= 6) System.Console.WriteLine(B / 2);
        else System.Console.WriteLine(0);
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // IncreaseStack(SolveCodeForces);
        // System.Console.Write(cout.ToString());
    }

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
int main(void){
    int n, i, x;
    scanf("%d", &n);
    for (i=1; i<=n; i++) {
        x = i;
        if ((x%3)==0) {
            printf(" %d", i);
            continue;
        }
        
        while (x != 0) {
            if ((x%10) == 3) {
                printf(" %d", i);
                break;
            }
            x /= 10;
        }
    }
    printf("\n");
}



Measured memory_bytes: 2112
#include <iostream>

int main() {
	int n, k, x, y;
	std::cin >> n >> k >> x >> y;

	int money;
	
	if (n <= k) {
		money = n*x;
	}
	else {
		money = k*x + (n - k)*y;
	}

	std::cout << money << std::endl;

}

Measured memory_bytes: 256
<?php
// グラフ：頂点と辺の総数のあと改行して改行区切りの辺の集合
fscanf(STDIN, '%d', $n);
for ($i  = 0; $i < $n - 1; $i++) {
    fscanf(STDIN, '%d %d %d', $u, $v, $w);
    $u--;
    $v--;
    $g[$u][] = [$v, $w];
    $g[$v][] = [$u, $w]; // 無向グラフの場合
}

// BFS（幅優先探索）：最短経路アルゴリズムとして活用
$q = new SplQueue(); // キューを用意
$dist = array_fill(0, $n, -1); // 距離を格納する配列（-1の場合はその頂点が未発見）

$dist[0] = 0; // 頂点0からの距離格納配列
$q->enqueue(0); // キューに0を追加

while(!$q->isEmpty()) {
    $v = $q->dequeue();

    foreach ($g[$v] as $next_v) {
        if ($dist[$next_v[0]] !== -1) continue; // 発見済み

        $dist[$next_v[0]] = $dist[$v] + $next_v[1];
        $q->enqueue($next_v[0]);
    }
}
foreach ($dist as $i => $v) {
    if ($dist[$i] % 2 === 0) echo (0) . PHP_EOL;
    else echo (1) . PHP_EOL;
}

Measured memory_bytes: 123896
a,b,c,d=map(int,input().split())
"""
while(True):
    if (d<=0):
        ans="Yes"
    c=c-b
    if (d<=0):
        ans="Yes"
        break
    a=a-d
    if (b<=0):
        ans="No"
        break

print(ans)
"""
print("Yes" if   -(-c//b) <=-(-a//d)  else "No")

Measured memory_bytes: 9108
#include<iostream>
using namespace std;
int main(){
int A,B,C,D,f1,f2;
cin>>A>>B>>C>>D;
if(A!=0&&B!=0&&C!=0&&D!=0){

f1=(A*B);
f2=(C*D);
if(f1<f2)
cout<<f2;
else if(f2<f1)
cout<<f1;
else if(f1=f2)
cout<<f1;}
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAXTAM 16
int main(){
	int pedacos[MAXTAM];
	int A, B;
	scanf("%d %d",&A,&B);
	if((A+B)>16){
		printf(":(\n");
	}
	if(A>8 || B>8){
		printf(":(\n");
	}
	else{
		printf("Yay!\n");
	}
	

	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H = sc.nextInt();
		int[] B = new int[N];
		int Amax = 0, ans = 0;
		for(int i = 0; i < N; i++) {
			int A = sc.nextInt();
			Amax = Math.max(Amax, A);
			B[i] = sc.nextInt();
		}
		Arrays.sort(B);
		for(int i = N-1; i >= 0; i--) {
			if(B[i] < Amax)
				break;
			H -= B[i];
			ans++;
			if(H <= 0) {
				System.out.println(ans);
				return;
			}
		}
		System.out.println(ans + (H + Amax - 1) / Amax);
	}

}


Measured memory_bytes: 66184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string X;
  cin >> X;
  if (X == "RRR") cout << 3 << endl;
  else if (X == "RRS" || X == "SRR") cout << 2 << endl;
  else if (X == "SRS" || X == "RSS" || X == "SSR" || X == "RSR") cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;

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

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

    int p[N];
    fill(p, p+N, -1);
    for(int i=0; i<N; i++){
        auto it = lower_bound(p, p+N, A[i]);
        it--;
        *it = A[i];
    }

    int ans = 0;
    for(int i=0; i<N; i++){
        if(p[i] != -1) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    

    int H;
    int W;
    while(1){
        cin>>H>>W;
        if(H==0&&W==0)
            break;
    
    
      for(int i=0;i<H;i++){
        for(int a=0;a<W;a++){
            cout<<"#";
        }
         
         cout<<endl;
    }
       cout<<endl;
    }

  return 0;
}



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

int main(){
  int Q;
  cin >> Q;
  priority_queue<long long> l, r;
  long long b_sum = 0, l_sum = 0, r_sum = 0;
  while(Q--){
    int t;
    cin >> t;
    if(t == 1){
      int a, b;
      cin >> a >> b;
      b_sum += b;
      if(l.empty() or a <= l.top()){
        l.push(a);
        l_sum += a;
        if(l.size() > r.size()+1){
          long long x = l.top();
          l.pop();
          l_sum -= x;
          r.push(-x);
          r_sum += x;
        }
      }else{
        r.push(-a);
        r_sum += a;
        if(r.size() > l.size()){
          long long x = -r.top();
          r.pop();
          r_sum -= x;
          l.push(x);
          l_sum += x;
        }
      }
    }else{
      long long x = l.top();
      long long y = x*l.size() - l_sum + r_sum - x*r.size() + b_sum;
      cout << x << " " << y << "\n";
    }
  }
}


Measured memory_bytes: 3828
#include <iostream>
using namespace std;
int n;

struct Card
{
	int s:8;
	int i:24;
	int v;
};

Card A[100000];

	
int part(int q, int r)
{
	Card x=A[r];
	int j=A[q].v<=x.v?q+1:q;
	for(int i=q+1;i<r;i++)
	{
		if (A[i].v<=x.v)
		{
			Card aj=A[j];
			A[j]=A[i];
			A[i]=aj;
			j++;
		}
	}
	A[r]=A[j];
	A[j]=x;
	return j;
}

void sort(int q, int r)
{
//	cout << q <<' '<<r<<endl;
	if (q>=r) return;
	int p=part(q,r);
//	cout<<p<<endl;
	sort(q,p-1);
	sort(p+1,r);
}

bool stable()
{
	for (int i=0;i<n;i++)
	{
		if (A[i].v==A[i+1].v)
		{
			if(A[i].i>A[i+1].i)
			{
				return false;
			}
		}
	}
	return true;
}

int main()
{
	cin >>n;
	for(int i=0;i<n;i++){
		A[i].i=i;
		char s;
		cin>>s; A[i].s = s;
		cin>>A[i].v;
	}
	
	sort(0,n-1);
	
	cout << (stable() ? "Stable":"Not stable")<<endl;

	for(int i=0;i<n;i++){
		cout<<(char)A[i].s<<' '<<A[i].v<<endl;
	}
}

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

int n, m, vc, ans; // vertex count
vector<bool> used(8);
vector<vector<int>> G(8);

void dfs(int now){
    used[now] = true;
    vc++;

    if(vc == n) ans++;
    else{
        for(int i = 0; i < G[now].size(); i++){
            if(!used[G[now][i]]){
                dfs(G[now][i]);
            }
        }
    }
    used[now] = false;
    vc--;
    return;
}

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

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*
 *  Lang    : C++
 *  Author  : little_angel
 */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

//#define int long long
#define oset tree < int , null_type , less<> , rb_tree_tag , tree_order_statistics_node_update >
const int mod = 998244353;
//const int inf = 1e18;
const int MAX = 1e6 + 10;

//    auto random_address = [] {
//        char *p = new char;
//        delete p;
//        return (uint64_t) p;
//    };
//    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1ull));


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

    vector<int> a(5);
    for (auto &i:a)cin >> i;
    cout << find(a.begin(), a.end(), 0ll) - a.begin() + 1 << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   int B[N - 1];
   int ans = 0;
   for (int i = 0; i < N - 1; i++) {
      cin >> B[i];
      if (i == 0) ans += B[i];
      else {
         ans += min(B[i], B[i - 1]);
      }
   }
   ans += B[N - 2];
   cout << ans << endl;
   return 0;
}


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


int main() {
  int64_t N, Q, H, S, D;
  cin >> Q >> H >> S >> D >> N;

  H = min(H, Q * 2);
  S = min(S, H * 2);
  D = min(D, S * 2);
  
  cout << (N / 2) * D + (N % 2) * S << endl;
}

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

int main (){

  int A,B;
  cin >> A >> B;
  int N = A+B;
  int Z = N%2;
  if (Z == 1){
    cout << N/2+1 << endl;
  }
  else {
    cout << N/2 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;



multiset<int>st;
vector<P>ans;
vector<int>v;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	REP(i, N) {
		int A; cin >> A;
		st.insert(A);
		v.pb(A);
	}
	VSORT(v);
	int idx = N;
	REP(i,N ){
		if (v[i] >= 0) {
			idx = i;
			break;
		}
	}
	if (idx == 0) {
		int mn = v[0];
		FOR(i, 1, N - 1) {
			ans.push_back({ mn,v[i] });
			mn = mn - v[i];
		}
		print(v[N - 1] - mn);
		ans.push_back({ v[N - 1],mn });
	}
	else if (idx == N) {
		int mx = v[N - 1];
		FOR(i, 1, N - 1) {
			ans.push_back({ mx,v[i] });
			mx -= v[i];
		}
		print(mx - v[0]);
		ans.push_back({ mx,v[0] });
	}
	else {
		int mn = v[0], mx = v[N - 1];
		FOR(i, idx, N-1) {
			ans.push_back({ mn,v[i] });
			mn = mn - v[i];
		}
		FOR(i, 1, idx) {
			ans.push_back({ mx,v[i] });
			mx -= v[i];
		}
		ans.push_back({ mx,mn });
		print(mx - mn);
	}
	/*if (N % 2 == 0) {
		REP(i, N - 1) {
			auto itr1 = st.begin(), itr2 = st.end(); itr2--;
			int mn = *itr1, mx = *itr2;
			int tmp;
			if (i % 2 == 0) {
				tmp = mx - mn;
				ans.push_back({ mx,mn });
			}
			else {
				tmp = mn - mx;
				ans.push_back({ mn,mx });
			}
			st.erase(itr1); st.erase(itr2);
			st.insert(tmp);
		}
		auto itr = st.begin();
		print(*itr);
	}
	else {
		REP(i, N - 1) {
			auto itr1 = st.begin(), itr2 = st.end(); itr2--;
			int mn = *itr1, mx = *itr2;
			int tmp;
			if (i % 2 == 1) {
				tmp = mx - mn;
				ans.push_back({ mx,mn });
			}
			else {
				tmp = mn - mx;
				ans.push_back({ mn,mx });
			}
			st.erase(itr1); st.erase(itr2);
			st.insert(tmp);
		}
		auto itr = st.begin();
		print(*itr);
	}*/
	REP(i, ans.size()) {
		pe(ans[i].first)print(ans[i].second);
	}
}


Measured memory_bytes: 9072
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

void add(string &ret, int i) {
    if (i == 1) {
        ret += '+';
    }
    else {
        ret += '-';
    }
}

int main() {
    string in = "";
    cin >> in;
    int one = in.at(0) - '0', two = in.at(1) - '0', three = in.at(2) - '0', four = in.at(3) - '0';
    int a[2] = {-1,1}, b[2] = {-1,1}, c[2] = {-1,1};
    for (int i=0; i<2; i++) {
        for (int j=0; j<2; j++) {
            for (int k=0; k<2; k++) {
                if (one+two*a[i]+three*b[j]+four*c[k] == 7) {
                    string ret = "";
                    ret += to_string(one);
                    add(ret, i);
                    ret += to_string(two);
                    add(ret, j);
                    ret += to_string(three);
                    add(ret, k);
                    ret += to_string(four);
                    ret += "=7";
                    cout << ret << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


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

int main(void){
  long long int a, b, c, k;
  scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
  if(k%2==0) printf("%lld\n",a-b);
  else printf("%lld\n",b-a);

  return 0;
}


Measured memory_bytes: 128
import java.util.*;

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

     int N = sc.nextInt();
     
     int T = sc.nextInt();
     
     int a[] = new int[N];
     
     for(int i =0;i < N;i++){
         a[i] = sc.nextInt();
     }
     
     int total = 0;
     for(int i = 0;i < N - 1;i++){
         total += Math.min(a[i+1] - a[i],T);
     }
     
     System.out.println(total + T);          
     
   
  }   
}


Measured memory_bytes: 62700