akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define N 36

struct Card{
  char suit;
  char value;
};

void BubbleSort(struct Card * ,int);
void SelectionSort(struct Card * ,int);
void HKK();

int main(){
  struct Card C1[101], C2[101],trnp[N];
  int n, i,hantei=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);
  }
 for(i=0;i<n;i++){
    C2[i]=C1[i];
  }
  BubbleSort(C1,n);

  SelectionSort(C2,n);
  
  for(i=0;i<n;i++){
    if(C2[i].suit != C1[i].suit){
      hantei=1;
      break;
    } 
  }
  if(hantei==0)printf("Stable\n");
  else printf("Not stable\n");
  
  return 0;
}

void BubbleSort(struct Card A[],int n){
  int i,j,m;
  char key1,key2;
  for(i=0;i<n;i++){
    for(j=n-1;j>=i+1;j--){
      if(A[j].value<A[j-1].value){
	key1=A[j].value;
	A[j].value=A[j-1].value;
	A[j-1].value=key1;
	key2=A[j].suit;
	A[j].suit=A[j-1].suit;
	A[j-1].suit=key2;
      }
    }
  }
  for ( m = 0; m <n; m++ ){
    if ( m > 0 ) printf(" ");
    printf("%c%c",A[m].suit,A[m].value);
  }
  printf("\nStable\n");
}

void SelectionSort(struct Card A[],int n){
  int i,j,m,mini,X;
  char key1,key2;
  for(i=0;i<n;i++){
    mini=i;
    X=0;
    for(j=i;j<n;j++){
      if(A[j].value<A[mini].value){
	mini=j;
	X=1;
      }
    }
    if(X==1){
      key1=A[i].value;
      A[i].value=A[mini].value;
      A[mini].value=key1;
      key2=A[i].suit;
      A[i].suit=A[mini].suit;
      A[mini].suit=key2;
    }
  }
  for ( m = 0; m <n; m++ ){
    if ( m > 0 ) printf(" ");  
    printf("%c%c", A[m].suit,A[m].value);
    
  }
  printf("\n");
}

Measured memory_bytes: 612
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	A1,A2,A3 = inputMap()

	if A1+A2+A3 <= 21:
		print("win")
	else:
		print("bust")


if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
int main(){
    string s;cin >> s;
    if(s[0]==s[1]&&s[1]==s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  cout.precision(12);

  double W, H, x, y;
  cin >> W >> H >> x >> y;

  bool foo = (x * 2 == W and y * 2 == H);

  cout << (W * H / 2) << " " << (foo ? 1 : 0) << endl;

  return 0;
}


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

int main() {
	string s;cin>>s;
	for(int i=0;i<19;i++){
		switch(i){
		case 5:
			cout<<' ';
			break;
		case 13:
			cout<<' ';
			break;
		default:
			cout<<s[i];
			break;
		}
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cassert>


using namespace std;

#define int long long

int t[400000];

int get(int v, int l, int r, int pos) {
	if (l == r - 1) {
		return t[v];
	}
	int m = (l + r) / 2;
	if (pos < m)
		return min(t[v], get(v * 2, l, m, pos));
	return min(t[v], get(v * 2 + 1, m, r, pos));
}


void upd(int v, int l, int r, int l2, int r2, int st) {
	if (l == l2 && r == r2) {
		t[v] = min(t[v], st);
		return;
	}
	int m = (l + r) / 2;
	if (r2 <= m)
		upd(v * 2, l, m, l2, r2, st);
	else if (l2 >= m)
		upd(v * 2 + 1, m, r, l2, r2, st);
	else {
		upd(v * 2, l, m, l2, m, st);
		upd(v * 2 + 1, m, r, m, r2, st);
	}
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, m, l, r, c;
	cin >> n >> m;
	for (int i = 0; i < 4e5; i++)
		t[i] = 1e18;
	int cur = 1;
	r = n;
	while (r != 1) {
		r = r / 2;
		cur = cur * 2;
	}
	t[cur] = 0;
	vector<vector<pair<int, int>>> v(n);
	for (int i = 0; i < m; i++) {
		cin >> l >> r >> c;
		v[l - 1].push_back({ r, c });
	}
	for (int i = 0; i < n; i++) {
		int x = get(1, 0, n, i);
		for (auto el : v[i])
			upd(1, 0, n, i, el.first, x + el.second);
	}
	int x = get(1, 0, n, n - 1);
	if (x == 1e18)
		cout << -1;
	else
		cout << x;
	return 0;
}

Measured memory_bytes: 8704
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String X = sc.next();
    int s = 0;
    StringBuilder ans = new StringBuilder();
    for (int i = 0; i < X.length(); i++) {
      if (X.charAt(i) == 'S') {
        s++;
      } else {
        if (s > 0) {
          s--;
        } else {
          ans.append('T');
        }
      }
    }
    while (s-- > 0) {
      ans.append('S');
    }
    System.out.println(ans.length());
  }
}

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

int main() {
	int N,L,I;
  	int sum = 0;

	cin >> N;	//組の入力
	for (int i = 0; i < N; i++) {
		cin >> L >> I;
      	sum += (I - L + 1);	//人数
	}
  	
  	cout << sum << endl;
}

Measured memory_bytes: 256
num= n = int(input())

price = []
max_pro = -999999999

while(n>0):
    x = int(input())
    price.append(x)
    n -= 1
min = price[0]
for i in range(1,num):
    pro = price[i]-min

    if(max_pro < pro):
        max_pro = pro
    if(min > price[i]):
        min = price[i]
print ("{0}".format(max_pro))

Measured memory_bytes: 15656
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
        
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

n,m = map(int,input().split())
par = [-1]*n
line = [0 for i in range(n)]
ans = 0
for i in range(m):
  a,b = map(int, input().split())
  unite(a-1,b-1)
for i in range(n):
  line[find(i)] += 1
  if line[find(i)] > ans:
    ans = line[find(i)]
print(ans)

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

int main() {
	int num = 0;
	int a[10000] = { 0 };
	int	b[10000] = { 0 };
	cin >> num;
	while (num != 0) {
		int ap = 0;
		int	bp = 0;
		for (int i = 0; i < num; i++) {
			cin >> a[i] >> b[i];
			if (a[i] > b[i]) ap += a[i] + b[i];
			else if (a[i] < b[i]) bp += a[i] + b[i];
			else {
				ap += a[i];
				bp += b[i];
			}
		}
		cout << ap << " " << bp << endl;
		cin >> num;
	}
}

Measured memory_bytes: 3064
#include"stdio.h"
int main()
{
    int k,x,tag=0;
    scanf("%d %d",&k,&x);
    if(k>100 ||k<1 ||x<1 ||x>1000000)
    {
        printf("No");
        tag=1;
    }

    if((500*k)>=x && tag==0)
            printf("Yes");
    else if((500*k)<x && tag==0)
        printf("No");

    return 0;
}


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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

vector<LL> InputVec(LL size) {
	vector<LL> vec((size_t)size);
	REP(i, size) {
		cin >> vec[(size_t)i];
	}
	return vec;
}

vector<LL> tbl;

void chmin(LL& a, LL b) {
	a = min(a, b);
}

int main()
{
	LL N;
	cin >> N;
	vector<LL> hs = InputVec(N);
	vector<LL> tbl(N, 1000000000);
	tbl[0] = 0;

	REP(i, N) {
		if (i - 1 >= 0) {
			chmin(tbl[i], tbl[i - 1] + abs(hs[i - 1] - hs[i]));
		}

		if (i - 2 >= 0) {
			chmin(tbl[i], tbl[i - 2] + abs(hs[i - 2] - hs[i]));
		}
	}

	cout << tbl[N - 1] << endl;

	return 0;
}


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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int n;
int memo[55][25][2][2010];
string s[100];
string rs[100];
int c[100];

int dp(int i, int j, bool f, int cnt){
	if(cnt == 2005) return -1;
	if(memo[i][j][f][cnt] != -1) return memo[i][j][f][cnt];

	if(!f){
		string tmp = s[i].substr(j, s[i].size());
		string rtmp = tmp;
		reverse(rtmp.begin(), rtmp.end());

		if(tmp == rtmp) return 0;

		int ans = LLONG_MAX;
		for(int k = 0;k < n;k++){
			if(tmp.size() < rs[k].size()){
				if(tmp == rs[k].substr(0, tmp.size())){
					int ttt = dp(k, tmp.size(), true, cnt+1);
					if(ttt != -1) chmin(ans, ttt+c[k]);
				}
			}else{
				if(tmp.substr(0, rs[k].size()) == rs[k]){
					if(j+rs[k].size() == s[i].size()) chmin(ans, c[k]);
					else{
						int ttt = dp(i, j+rs[k].size(), false, cnt+1);
						if(ttt != -1) chmin(ans, ttt+c[k]);
					}
				}
			}
		}
		return memo[i][j][f][cnt] = (ans < LLONG_MAX ? ans : -1);
	}else{

		string tmp = rs[i].substr(j, rs[i].size());
		string rtmp = tmp;
		reverse(rtmp.begin(), rtmp.end());

		if(tmp == rtmp) return 0;

		int ans = LLONG_MAX;
		for(int k = 0;k < n;k++){
			if(tmp.size() < s[k].size()){
				if(tmp == s[k].substr(0, tmp.size())){
					int ttt = dp(k, tmp.size(), false, cnt+1);
					if(ttt != -1) chmin(ans, ttt+c[k]);
				}
			}else{
				if(tmp.substr(0, s[k].size()) == s[k]){
					if(j+s[k].size() == rs[i].size()) chmin(ans, c[k]);
					else{
						int ttt = dp(i, j+s[k].size(), true, cnt+1);
						if(ttt != -1) chmin(ans, ttt+c[k]);
					}
				}
			}
		}
		return memo[i][j][f][cnt] = (ans < LLONG_MAX ? ans : -1);

	}
}

signed main(){
	cin >> n;

	for(int i = 0;i < n;i++){
		cin >> s[i] >> c[i];
		string t = s[i];
		reverse(t.begin(), t.end());
		rs[i] = t;
	}

	int ans = LLONG_MAX; 
	memset(memo, -1, sizeof(memo));
	for(int i = 0;i < n;i++){
		int tmp = dp(i, 0, false, 0);
		if(tmp != -1) chmin(ans, tmp+c[i]);
	}

	cout << (ans < LLONG_MAX ? ans : -1) << endl;

	return 0;
}


Measured memory_bytes: 47280
#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>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        vector<vector<Int>> A(N, vector<Int>(N - 1));

        auto conv = [&](int a, int b) {
            if (a > b) swap(a, b);
            return a * N + b;
        };

        vector<int> rest(N * N);
        vector<vector<int>> G(N * N);


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

            }
            for (int j = 1; j + 1 < N; ++j) {
                int from = conv(i, A[i][j - 1]);
                int to = conv(i, A[i][j]);
                G[from].push_back(to);
                rest[to]++;
            }
        }

        queue<int> que;
        int ans = 0;

        for (int i = 0; i < N * N; ++i) {
            if (rest[i] == 0) {
                que.push(i);
            }
        }

        while (!que.empty()) {
            queue<int> que2;
            while (!que.empty()) {
                que2.push(que.front());
                que.pop();
            }

            while (!que2.empty()) {
                int top = que2.front();
                que2.pop();
                for (auto e : G[top]) {
                    rest[e]--;
                    if (rest[e] == 0) {
                        que.push(e);
                    }
                }
            }

            ans++;
        }

        for (auto e : rest) {
            if (e > 0) {
                cout << -1 << endl;
                return;
            }
        }
        cout << ans << endl;


    }

};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 52992
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

int main()
{
   string name;
   int i,c=0,j;
   cin>>name;
   for(i=0,j=name.length()-1;i<name.length()/2;i++,j--){
    if(name[i]!=name[j]){
        c++;
    }
   }
   cout<<c;
    return 0;
}


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

using namespace std;

int main()
{
    int n, x, y; cin >> n >> x >> y;
    auto dist_freq = vector<int>(n);
    for (int i = 1; i < n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            // normally, dist[i][j] = j-i
            int normal_dist = j - i;
            // the presence of (x,y) edge might shorten it
            // using (x,y) path means i -> x -> y -> j
            int xy_dist = abs(i - x) + abs(y - j) + 1;
            int min_dist = min(normal_dist, xy_dist);
            ++dist_freq[min_dist];
        }
    }
    for (int i = 1; i < n; ++i) {
        cout << dist_freq[i] << endl;
    }
}


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

const int N = 2e5 + 10, mod = 1e9 + 7;

long long n;

int getpw(long long d) {
    int p = 0;
    if(d == 1) return 1;
    long long x = n;
    while(x % d == 0) {
        x /= d;
        p++;
    }
    return p;
}

vector<long long> getdiv(long long x) {
    vector<long long> ret;
    for(long long i = 1; i * i <= x; i++) {
        if(x % i == 0) {
            ret.push_back(i);
            if(i * i != x) ret.push_back(x / i);
        }
    }
    return ret;
}

vector<long long> factorize(long long x) {
    vector<long long> ret;
    for(long long i = 2; i * i <= x; i++) {
        if(x % i == 0) ret.push_back(i);
        while(x % i == 0) x /= i;
    }
    if(x > 1) ret.push_back(x);
    return ret;
}

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    scanf("%lld", &n);
    int ans = 0;
    vector<long long> div = getdiv(n);
    for(auto x : div) {
        if(x == 1) continue;
        int p = getpw(x);
        if((n / (long long) pow(x, p)) % x == 1) ans++;
    }
    ans += (int)getdiv(n - 1).size() - 1;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  int ans = 800*N-200*(N/15);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  int a,b,a_g,b_g;
  cin >> a >> b;
  int comp[3][7]={{1,3,5,7,8,10,12},{4,6,9,11,0,0,0},{2,0,0,0,0,0,0}};
  rep(i,3){
   rep(j,7){
     if (comp[i][j]==a) a_g=i;
     if (comp[i][j]==b) b_g=i;
   }
  }
  if (a_g==b_g) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;

const ll INF = 10000000000000007;

int main()
{
    int n, m;
    cin >> n >> m;
    int l[200007], r[200007];
    ll d[200007];
    vector<P> v[100007];
    ll pl[100007];
    for(int i = 0; i < m; i++){
        cin >> l[i] >> r[i] >> d[i];
        l[i]--;
        r[i]--;
        v[l[i]].push_back(P(r[i], d[i]));
        v[r[i]].push_back(P(l[i], -d[i]));
    }
    fill(pl, pl + n, INF);
    for(int i = 0; i < n; i++){
        ll least = 0;
        ll largest = 0;
        if(pl[i] == INF){
            pl[i] = 0;
            queue<int> q;
            q.push(i);
            while(q.size()){
                int now = q.front();
                q.pop();
                int s = v[now].size();
                for(int j = 0; j < s; j++){
                    if(pl[v[now][j].first] != INF){
                        if(pl[v[now][j].first] != pl[now] + v[now][j].second){
                            cout << "No" << endl;
                            return 0;
                        }
                    }
                    else{
                        pl[v[now][j].first] = pl[now] + v[now][j].second;
                        least = min(least, pl[v[now][j].first]);
                        largest = max(largest, pl[v[now][j].first]);
                        q.push(v[now][j].first);
                    }
                }
            }
        }
        if(largest - least > 1000000000){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 17024
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	long a,b,x,y,z;
	while(1){
		cin >> a >> b;
		if((a==0)&&(b==0)){
			return 0;
		}
		a=(b-a)/100;
		for(x=0;a>=10;x++){
			a-=10;
		}
		for(y=0;a>=5;y++){
			a-=5;
		}
		for(z=0;a>=1;z++){
			a-=1;
		}
		cout << z <<" "<< y <<" "<<x<<"\n";
	}
return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
using namespace std;

int n,a,b;

void F(int a,int b,int v){
	if(a==b){ printf("%d ",a); return; }
	int x=(a^b)&(-(a^b)); v^=x; int y=v&(-v);
	F(a,a^y,v); F(a^y^x,b,v);
}

int main(){
	scanf("%d%d%d",&n,&a,&b);
	if(__builtin_popcount(a^b)&1) puts("YES"),F(a,b,(1<<n)-1); else puts("NO");
	return 0;
}

Measured memory_bytes: 896
/*
[m-solutions2019] C - Best-of-(2n-1)
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 100000;
const int MOD = 1e9 + 7;

ll extgcd(ll a, ll b, ll& x, ll& y) {
    ll d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

ll mod_inv(ll a, ll m) {
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x) % m;
}

class gf {
public:
    int n;
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf inv() { return gf(mod_inv(n, MOD)); }
    gf operator+(gf x) { return gf((n + x.n) % MOD); }
    gf operator-(gf x) { return gf((n - x.n + MOD) % MOD); }
    gf operator*(gf x) { return gf((1LL * n * x.n) % MOD); }
    gf operator/(gf x) { return *this * x.inv(); }
};

int N, A, B, C;
gf pa[2 * MAX_N + 1], pb[2 * MAX_N + 1], ph[2 * MAX_N + 1];
gf fact[2 * MAX_N + 1];

ll solve() {
    fact[0] = fact[1] = 1;
    for (int i = 2; i <= 2 * MAX_N; i++) {
        fact[i] = fact[i - 1] * i;
    }

    pa[0] = 1;
    pb[0] = 1;
    ph[0] = 1;
    for (int i = 1; i <= 2 * N; i++) {
        pa[i] = pa[i - 1] * A;
        pb[i] = pb[i - 1] * B;
        ph[i] = (ph[i - 1] / (100 - C));
    }

    gf ans = 0;
    for (int i = N; i <= 2 * N - 1; i++) {
        gf tmp = fact[i - 1] / (fact[N - 1] * fact[i - N]);
        tmp = tmp * (pa[N] * pb[i - N] + pa[i - N] * pb[N]) * i * 100;
        tmp = tmp * ph[i + 1];
        ans = ans + tmp;
    }

    return ans.n;
}

int main() {
    cin >> N >> A >> B >> C;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
typedef long double LD;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
int main(){
	LL a=read(),b=read(),c=read(),k=read();
	if (k&1)
		cout<<b-a<<endl;
	else
		cout<<a-b<<endl;
	return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

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


int main(){
  int n,k;cin >> n >> k;
  if(n%k==0) cout << 0 << endl;
  else cout << 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
static const int MAX = 200000;

int main() {
	int R[MAX], n;

	cin >> n;
	for (int i = 0; i < n; i++) cin >> R[i];

	int maxv = -2 * std::pow(10, 9);
	int minv = R[0];

	for (int i = 1; i < n; i++) {
			maxv = max(maxv, R[i] - minv);
			minv = min(minv, R[i]);

	}

	cout << maxv << endl;

	return 0;
}


Measured memory_bytes: 3876
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


a = inlist()

for i in range(len(a)):
    if a[i] == 0:
        print(i+1)
        break


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

using namespace std;

long long niz[55];
int steps = 0;
struct resenje
{
    int a;
    int b;
};
resenje res[1000];

void solve1(int n,long long factor,int fact_poz)
{
    for(int i = 0; i < n; i++)
    {
        if(i!=fact_poz)
        {
            niz[i] += factor;
            res[steps].a = fact_poz+1; res[steps].b = i+1;
            //cout<<fact_poz+1<<" "<<i+1<<endl;
            steps++;
        }
    }
}

void solve2(int n,bool incr)
{
    if(incr)
    {
        for(int i = 0; i < n-1; i++)
        {
            niz[i+1] = niz[i+1] + niz[i];
            res[steps].a = i+1; res[steps].b = i+2;
            //cout<<i+1<<" "<<i+2<<endl;
            steps++;
        }
    }
    else
    {
        for(int i = n-1; i >=1; i--)
        {
            niz[i-1] = niz[i]+niz[i-1];
            //cout<<i+1<<" "<<i<<endl;
            res[steps].a = i+1;
            res[steps].b = i;
            steps++;
        }
    }
}

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

    int n;
    cin>> n;
    long long maxi = -1; long long mini = LONG_LONG_MAX;
    int maxi_poz = 0; int mini_poz = 0;

    for(int i = 0; i < n; i++)
    {
        cin>>niz[i];
        if(niz[i] > maxi) {maxi = niz[i]; maxi_poz = i;}
        if(niz[i] < mini) {mini = niz[i]; mini_poz = i;}
    }

    long long factor = 0;
    int fact_poz = 0; bool incr = true;
    if(maxi > abs(mini)) {factor = maxi; fact_poz = maxi_poz; incr = true;}
    else {factor = mini; fact_poz = mini_poz; incr = false;}

    solve1(n,factor,fact_poz);
    solve2(n,incr);

    //cout<<"factor "<<factor<<endl;
    cout<<steps<<endl;
    for(int i = 0; i < steps; i++)
    {
        cout<<res[i].a<<" "<<res[i].b<<endl;
    }

    //for(int i = 0; i < n; i++)
       // cout<< niz[i]<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    H = list(map(int, input().split()))
    for i in range(N):
        if i == N-1:
            print("Yes")
            break
        if H [i+1] > H[i]:
            H[i+1] -= 1
        elif H[i+1] < H[i]:
            print("No")
            break

if __name__ == '__main__':
    main()

Measured memory_bytes: 14192
def calc_inv(n, mod_n):
    inv_li = [0] * (n + 2)
    inv_li[0] = 0
    inv_li[1] = 1
    for i in range(2, n + 2):
        q, r = divmod(mod_n, i)
        inv_li[i] = -inv_li[r] * q % mod_n
    return inv_li


K = int(input())
S = input()
s_len = len(S)

MOD = 10**9 + 7
inv = calc_inv(max(K, 26) + 10, MOD)

ans = 0
p = pow(26, K, MOD)

for i in range(1, K + 2):
    ans = (ans + p % MOD) % MOD
    p = p * (s_len + i - 1) * inv[i] * 25 * inv[26] % MOD

print(ans)


Measured memory_bytes: 49496
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,ll*A){F(N)scanf("%lld",A+i);}
#define MX (1024)
int X,Y,Z,N,E,K,M;
ll A[MX],B[MX],C[MX],F[MX*MX],O[int(4e6)];
int main(void){
    scanf("%d%d%d%d",&X,&Y,&Z,&K),ga(X,A),ga(Y,B),ga(Z,C);
    F(X)FF(Y)F[N++]=A[i]+B[j];
    sort(F,F+N),sort(C,C+Z);
    F(Z)FF(K)O[M++]=F[N-j-1]+C[i];
    sort(O,O+M);
    F(K)printf("%lld\n",O[M-i-1]);
    return 0;
}


Measured memory_bytes: 33280
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename Container>
int SZ(const Container& S) { return S.size(); }

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg_var(x) clog << #x  << ": " << x << endl;
    #define dbg_array(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg_var(x)
    #define dbg_array(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

int c[10][10];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!

    int H, W;
    cin >> H >> W;
    for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) cin >> c[i][j];
    for (int p = 0; p < 10; p++) {
        for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) {
            c[i][j] = min(c[i][j], c[i][p] + c[p][j]);
        }
    }
    int res = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int x;
            cin >> x;
            if (x == -1) continue;
            res += c[x][1];
        }
    }
    cout << res << "\n";
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



int main(){
    int a, b, x;
    cin >> a >> b >> x;
    if(x-a<0) out("NO");
    else{
        if(x-a<=b) out("YES");
        else out("NO");
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int n = cin.nextInt();
			int p = cin.nextInt();
			if(n+p==0){
				break;
			}
			int wan = p;
			int[] a = new int[n];
			int now=0;
			while(true){
				if(p!=0){
					a[now]++;
					p--;
					if(a[now]==wan){
						System.out.println(now);
						break;
					}
				}
				else{
					p = a[now];
					a[now]=0;
				}
				now=(now+1)%n;
			}
		}
	}

}

Measured memory_bytes: 12000
let inputs = require('fs').readFileSync('/dev/stdin', 'utf8').split(" ");

const a = ~~inputs[0];
const b = ~~inputs[1];
const c = ~~inputs[2];

let count = 0;
for (d=a;d<=b;d++) {
    if (c%d === 0) {
        count += 1;
    };
};
console.log(count);



Measured memory_bytes: 15128
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 302;

vector<int> vec[MAX_N];
int n,m;

bool possible(vector<int>* v,int cri)
{
    vector<int> bf;
    set<int> st;
    vector<int> nw(n,0);
    while(1){
        vector<int> cnt(m,0);
        rep(i,n){
            while(st.count(v[i][nw[i]]) == 1){
                nw[i]++;
                if(nw[i] >= m){
                    return false;
                }
            }
        }
        rep(i,n){
            cnt[v[i][nw[i]]]++;
        }
        int mx = 0;
        int id;
        rep(i,m){
            if(cnt[i] > mx){
                mx = cnt[i];
                id = i;
            }
        }
        if(mx <= cri){
            return true;
        }
        st.insert(id);
    }
}

int main()
{
    cin >> n >> m;
    rep(i,n){
        rep(j,m){
            int x;
            scanf("%d",&x);
            vec[i].pb(x-1);
        }
    }
    int l = 0;
    int h = n;
    while(1){
        int mid = (l+h) / 2;
        if(mid == l){
            break;
        }
        if(possible(vec,mid)){
            h = mid;
        }else{
            l = mid;
        }
    }
    cout << h << endl;
    return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char c;
    String s;
    s = sc.nextLine();
    for (int i = 0; i < s.length(); i++) {
      c = s.charAt(i);
      if ('a' <= c && c <= 'z') {
        c -= 32;
      } else if ('A' <= c && c <= 'Z') {
        c += 32;
      }
      System.out.printf("%c", c);
    }
    System.out.printf("\n");
  }
}



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

#define ORZ_lqs2015
#define ORZ_EVERYBODY

int main() {
    stringstream ss;
    int n;
    cin >> n;
    ss << n;
    string str;
    ss >> str;
    for (int i = 0; i < str.size(); i++)
        if (str[i] != str[str.size() - 1 - i])
            return printf("No"), 0;
    printf("Yes");
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.lang.Math;
import java.util.Map;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int x = fs.nextInt();
        int y = fs.nextInt();
        int lim = x+1;
        String ans = "No";
        for (int i = 0; i<lim;i++) {
            for (int q = 0; q<(lim-i);q++) {
                if (2*i+4*q == y) {
                    if (i+q == x) {
                        ans = "Yes";
                    }
                    break;
                }
            }
        }
        System.out.println(ans);






    }
    public static String convertFromBaseToBase(String str, int fromBase, int toBase) {
        return Integer.toString(Integer.parseInt(str, fromBase), toBase);
    }


    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");

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

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

        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
    }

}



Measured memory_bytes: 32648
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const ll sp = 132694967;
const ll sp2 = 61438739;

int main() {
    string s,t;
    cin >> s >> t;

    int n = s.size();
    int m = t.size();

    int flag[n+10] = {};
    int now = m % n;
    int start = 0;

    ll hash_s = 0;
    ll hash_t = 0; 
    ll rem = 1;

    // hash_t作成
    rep(i,m){ 
        rem = (rem*sp2) % sp;
        hash_t += (int)t[m-1-i] * rem;
        hash_t %= sp;
    }
    // hash_s作成
    rem = 1;
    rep(i,m){
        rem = (rem*sp2) % sp;
        hash_s += (int)s[(m-1-i)%n] * rem;
        hash_s %= sp;
    }

    rep(i,n){
        if(hash_s==hash_t)flag[i] = 1;
        hash_s += sp*sp2 - (int)s[start] * rem + (int)s[now];
        hash_s %= sp;
        hash_s *= sp2;
        hash_s %= sp;
        
        now++;
        now %= n;
        start++;
        start %= n;
    }



    int ans[n+10] = {};
    rep(i,n){
        if(flag[i]==1){
            int tmp = 1;
            flag[i] = i+10;
            ll ii = i;
            while(true){
                ii += m;
                ii %= n;
                if(flag[ii]==(i+10)){
                    cout << "-1" << endl;
                    return 0;
                }else if(flag[ii]>1){
                    tmp += ans[ii];
                    flag[ii] = i+10;
                    break;
                }else if(flag[ii]==1){
                    tmp++;
                    flag[ii] = i+10;
                    //break;
                }else{
                    break;
                }
            }
            ans[i] = tmp;
        }
    }
    /*
    rep(i,n)cout << flag[i];
    cout << endl;
    */


    int ma = 0;
    rep(i,n){
        ma = max(ans[i],ma);
    }

    cout << ma<< endl;

    return 0;
}
 
 


Measured memory_bytes: 5256
import java.util.*;

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

    int c = a + b;
    int d = a - b;
    int e = a * b;

    System.out.println(Math.max(e,Math.max(c,d)));
  }

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 100000000000;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second
 
// rep(i, 0, sz(v)) cout << v[i] << " \n"[i==sz(v)-1];
 
////////////////////////////////////////////////////////

map<ll, ll> PrimeFactorization(ll n){
    map<ll, ll> mp;
    Rep(i, 2, sqrt(n)){
        while(n%i == 0){
            mp[i]++;
            n /= i;
        }
        if(n == 1) break;
    }
    if(n != 1) mp[n]++;
    return mp;
}

// 約数列挙
vector<long long> divisor(long long n){
    vector<long long> div;
    for(long long i = 1; i*i <= n; i++){
        if(n%i == 0){
            div.push_back(i);
            if(i*i != n) div.push_back(n/i);
        }
    }
    sort(div.begin(), div.end());
    return div;
}

int main() {
    ll n; cin >> n;
    map<ll, ll> mp = PrimeFactorization(n-1);
    ll ans = 0;
    ll a = 1;
    for(auto it : mp) a *= it.second+1;
    ans += a - 1;

    // co(ans);

    Vl div = divisor(n);
    rep(i, 0, sz(div)){
        ll k = div[i];
        if(k == 1) continue;
        ll N = n;
        while(N%k == 0 && N >= k) N /= k;
        if(N%k == 1) ans++;
    }

    co(ans);

    return 0;
}
 

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

#define int long long

int32_t main() {
	int n, e, t;
	cin >> n >> e >> t;
	int a[n + 10], dp[n + 10] = {};
	a[0] = 0;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	set <pair <int, int>> st1 = {{t - a[0] + dp[0], 0}};
	int st3 = 1ll << 60, ptr = 0;
	for (int i = 1; i <= n; i++) {
		while (ptr < i && 2 * (a[i] - a[ptr + 1]) >= t) {
			st3 = min(st3, -(2 * a[ptr + 1] + a[ptr]) + dp[ptr]);
			st1.erase({t - a[ptr] + dp[ptr], ptr});
			ptr++;
		}
		dp[i] = min(st3 + 3 * a[i], st1.size()? st1.begin() -> first + a[i]: 1ll << 60);
		st1.insert({t - a[i] + dp[i], i});
	}
	cout << e - a[n] + dp[n];
}


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

int main() {
	string s; cin >> s;
	string l, r;
	for (int i = 0; i < 2; i++) {
		l.push_back(s[i]); r.push_back(s[i + 2]);
	}
	bool flag[2] = { false };
	auto calc = [](string x) {
		int num = (x[0] - '0') * 10 + x[1] - '0';
		if (1 <= num && num <= 12) return true;
		else return false;
	};
	flag[0] = calc(l);
	flag[1] = calc(r);
	if (flag[0] && flag[1]) cout << "AMBIGUOUS" << endl;
	else if (flag[0] && !flag[1]) cout << "MMYY" << endl;
	else if (!flag[0] && flag[1]) cout << "YYMM" << endl;
	else cout << "NA" << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	int A,B,C,K;
	cin>>A>>B>>C>>K;
	ll ans;
	if(K<=A){
		ans=K;
	}
	else if(K<=A+B){
		ans=A;
	}
	else{
		ans=A-(K-A-B);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3660
S = list(input())
Q = int(input())
mae = []
usi = []
R = 0
for _ in range(Q):
    q = list(map(str,input().split()))
    if q[0] == '1':
        R += 1
        R %= 2
    elif q[0] == '2':
        if R == 0:
            if q[1] == '1':
                mae.append(q[2])
            elif q[1] == '2':
                usi.append(q[2])
        elif R == 1:
            if q[1] == '1':
                usi.append(q[2])
            elif q[1] == '2':
                mae.append(q[2])
mae.reverse()
ans = mae + S + usi
if R == 1:
    ans.reverse()
print(''.join(ans))

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

int main(){
  string S;
  cin >> S;
  
  string ans = "Good";
  for(int i = 0; i < S.size(); i++){
    if(S[i] == S[i-1]){
      ans = "Bad";
    }
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 256
def bubble_sort(c, n):
    c = c.copy()
    for i in range(n):
        for j in range(0, n - 1):
            if c[j][1] > c[j + 1][1]:
                c[j], c[j + 1] = c[j + 1], c[j]
    return c


def selection_sort(a, n):
    a = a.copy()
    for i in range(n):
        min_index = i
        for j in range(i, n):
            if a[j][1] < a[min_index][1]:
                min_index = j
        a[i], a[min_index] = a[min_index], a[i]
    return a


def print_list(a):
    print(" ".join([s + v for s, v in a]))


def is_stable(l1, l2):
    def get_original_index(v):
        for i, e in enumerate(l1):
            if v == e:
                return i
        return Exception("bug")

    before = l2[0]
    for e in l2[1:]:
        if before[1] == e[1]:
            # print(before, e)
            bi = get_original_index(before)
            ei = get_original_index(e)
            # print(bi, ei)
            if bi > ei:
                return False
        before = e

    return True


n = int(input())
tmp = input().split()
a = []
for v in tmp:
    a.append((v[0], v[1]))

bs_result = bubble_sort(a, n)
ss_result = selection_sort(a, n)

print_list(bs_result)
if is_stable(a, bs_result):
    print("Stable")
else:
    print("Not stable")

print_list(ss_result)
if is_stable(a, ss_result):
    print("Stable")
else:
    print("Not stable")



Measured memory_bytes: 5612
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        s: Chars,
    }

    let mut index = 0;

    while index < s.len() {
        if index + 4 < s.len() {
            let substring = s.iter().rev().skip(index).take(5).collect::<String>();
            match substring.as_str() {
                "maerd" | "esare" => {
                    index += 5;
                    continue;
                }
                _ => {},
            }

        }
        if index + 5 < s.len() {
            let substring = s.iter().rev().skip(index).take(6).collect::<String>();
            match substring.as_str() {
                "resare" => {
                    index += 6;
                    continue;
                }
                _ => {},
            }
        }
        if index + 6 < s.len() {
            let substring = s.iter().rev().skip(index).take(7).collect::<String>();
            match substring.as_str() {
                "remaerd" => {
                    index += 7;
                    continue;
                }
                _ => {},
            }
        }
        println!("NO");
        return;
    }

    if index == s.len() {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 2492
#include<bits/stdc++.h>
#define N 1000000007
using namespace std;

int main(){
  
  long long n,m;
  cin>>n>>m;
  char a[n][m];
  for(long long i=0;i<n;i++)
    for(long long j=0;j<m;j++){
     cin>>a[i][j];      
    }
  
  long long dp[n][m];
  dp[0][0]=1;
  for(long long i=0;i<n;i++)
    for(long long j=0;j<m;j++){
      if(i==0&&j==0)
        continue;
      else if(a[i][j]=='#'){
      	dp[i][j]=0;
        continue;
      }
      else if(i==0)
        dp[i][j]=dp[i][j-1];
      else if(j==0)
        dp[i][j]=dp[i-1][j];
      else
        dp[i][j]=(dp[i-1][j]+dp[i][j-1])%N;
    }
  
  cout<<dp[n-1][m-1]<<endl;
  
  return 0;
}

Measured memory_bytes: 9088
import java.util.*;
import java.util.stream.*;

public class Main {
    private static final boolean IS_TAKAHASHI_TURN = true;

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);
        long giftCount = sc.nextLong();
        Set<String> giftList = new HashSet<>();
        for (int i = 0; i < giftCount; i++) {
            String gift = sc.next();
            giftList.add(gift);
        }
        System.out.println(giftList.size());
    }
}


Measured memory_bytes: 77192
// 2013/10/24 Tazoe

#include <iostream>
#include <vector>
using namespace std;

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

		if(N==0)
			break;

		vector<int> B;
		for(int i=0; i<N; i++){
			int b;
			cin >> b;

			B.push_back(b);
		}
/*
		for(int i=0; i<B.size(); i++){
			cout << B[i] << ' ';
		}
		cout << endl;
*/

		int cnt = 0;

		while(true){
			bool flg = true;
			for(int i=0; i<B.size(); i++){
				if(B[i]!=i+1){
					flg = false;
					break;
				}
			}

			if(flg){
				cout << cnt << endl;
				break;
			}

			vector<int> tmp;
			for(int i=0; i<B.size(); i++){
				if(B[i]-1>0){
					tmp.push_back(B[i]-1);
				}
			}
			tmp.push_back(B.size());

			B.clear();
			B = tmp;
/*
		for(int i=0; i<B.size(); i++){
			cout << B[i] << ' ';
		}
		cout << endl;
*/
			cnt++;

			if(cnt>10000){
				cout << -1 << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1248