akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
using namespace std;

int main()
{
    int n,m,i,j,k,x;
    cin>>n;
    string A(n+1,'\0');
    for(i=0;i<n;i++)
    {
        cin>>x;
        A+=x;
    }
    cin>>m;
    string B(n+1,'\0');
    for(i=0;i<m;i++)
    {
        cin>>x;
        B+=x;
    }
    if(B>A)cout<<"1"<<endl;
    else cout<<"0"<<endl;
    return 0;
}



Measured memory_bytes: 3216
# -*- coding: utf-8 -*-
import sys


def main():
    a,b,c,d = list(map(int, sys.stdin.readline().split()))

    max_calc = -float("inf")

    for i in [a,b]:
        for j in [c,d]:
            max_calc = max(max_calc, i*j)
    
    
    print(max_calc)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9124
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
B = [i + A[i - 1] for i in range(1, n + 1)]
C = Counter(B)
ans = 0
for i in range(1, n + 1):
    x = i - A[i - 1]
    if x in C.keys():
        ans += C[x]
print(ans)

Measured memory_bytes: 42792
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B && A != C)
    {
        cout << "Yes" << endl;
    }
    else if (A == C && A != B)
    {
        cout << "Yes" << endl;
    }
    else if (B == C && B != A)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(n, q);

    int yui = 0;
    while (q--) {
        int2(a, b);
        if (a) {
            // swap
            yui = (yui + b) % n;
        } else {
            // output
            cout << (b + yui - 1) % n + 1 << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3200
N=gets.to_i
p=gets.chomp.split.map(&:to_f)

dp = Array.new(N+1).map{Array.new(N+1,0.0)}
dp[0][0] = 1.0

p.each_with_index do |v, i|
  dp[i+1][0] = dp[i][0] * (1-p[i])
  1.upto(i+1) do |j|
    dp[i+1][j] = dp[i][j-1] * (p[i]) + dp[i][j] * (1-p[i])
  end
end

ans = 0.0
(N/2+1).upto(N) do |i|
  ans += dp[N][i]
end
puts ans

Measured memory_bytes: 183292
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include <math.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define __int64 long long 
#define P pair<__int64,__int64>
__int64  n,h;
__int64 a[110000],b[110000];
P t[110000];

int main(){
	cin>>n>>h;
	rep(i,n){
		cin>>a[i]>>b[i];
		t[i]=mp(a[i],b[i]);
	}
	sort(t,t+n,greater<P>());
	sort(b,b+n,greater<int>());
	
	__int64 ans=0;
	__int64 huri=t[0].first;

	for(int i=0;i<n;i++){
		if(huri<=b[i]){
				ans++;
				h-=b[i];
		}
		if(h<=0)break;
	}

	if(h>0)ans+=ceil((double)h/(double)huri);
	cout<<ans<<endl;
	return 0;
}


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

int main()
{
  int N,M;
  cin >> N;
  vector<int> T(N);
  for(int i=0; i < N; i++)
    cin >> T[i];
  cin >> M;
  vector<vector<int> > P(M, vector<int>(2));
  int p,x;
  for(int i=0; i < M; i++){
    cin >> p;
    cin >> x;
    P[i][0] = p-1;
    P[i][1] = x;
  }

  for(int i=0; i < M; i++){
    int sum=0;
    for(int j=0; j < N; j++){
      if(j != P[i][0]){
	sum += T[j];
	//cout << T[j] << endl;
      }else{
	sum += P[i][1];
	//cout << P[j] << endl;
      }
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    vector<vector<int>> g(n);
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        g[i].emplace_back(--a[i]);
    }
    vector<bool> seen(n, 0);
    vector<int> v;
    v.push_back(0);
    seen[0] = 1;
    int now = a[0];
    while(!seen[now]) {
        v.push_back(now);
        seen[now] = 1;
        now = a[now];
    }
    v.push_back(now);
    map<int, int> mp;
    int loopsz = 0;
    for(int i = 0; i < v.size(); i++) {
        if(mp.count(v[i])) {
            loopsz = i - mp[v[i]];
            break;
        } else {
            mp[v[i]] = i;
        }
    }
    if(k <= mp[now]) {
        print(v[k] + 1);
        return 0;
    }
    k -= mp[now];
    print(v[k % loopsz + mp[now]] + 1);
}

Measured memory_bytes: 24880
#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 kill _z_kill
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
#define User_Time ((double)clock()/CLOCKS_PER_SEC)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
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;
}
const int mod=998244353;
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int Add(int x){
	return x>=mod?x-mod:x;
}
int Del(int x){
	return x<0?x+mod:x;
}
void ckmax(int &x,int y){
	if (x<y)
		x=y;
}
void ckmin(int &x,int y){
	if (x>y)
		x=y;
}
const int N=305;
int n;
char s[N];
int dp[N][N][N],g[N][N][N],f[N][N][N];
int main(){
	cin>>(s+1);
	n=strlen(s+1);
	dp[0][0][0]=1;
	For(a,0,n)
		Fod(i,n,0)
			Fod(j,n,0){
				if (dp[a][i][j]){
//					printf("[%d][%d][%d]\n",a,i,j);
					f[a][i][j]=1;
					if (a<=n-2){
						f[a+1][i][j]=1;
					}
					if (i>0){
						if (i+j>=2)
							dp[a][i-1][j]=1;
						if (a<n){
							if (s[a+1]=='0')
								dp[a+1][i-1+1][j]=1;
							else
								dp[a+1][i-1][j+1]=1;
						}
					}
					if (j>0){
						if (i+j>=2)
							dp[a][i][j-1]=1;
						if (a<n){
							if (s[a+1]=='0')
								dp[a+1][i+1][j-1]=1;
							else 
								dp[a+1][i][j-1+1]=1;
						}
					}
					if (a<=n-2){
						For(k,a+1,a+2){
							if (s[k]=='0')
								dp[a+2][i+1][j]=1;
							else
								dp[a+2][i][j+1]=1;
						}
					}
				}
				if (f[a][i][j]){
					if (a<n){
						if (i>0)
							f[a][i-1][j]=1;
						if (j>0)
							f[a][i][j-1]=1;
					}
				}
			}
	g[n+1][0][0]=1;
	int ans=1;
	Fod(b,n,1){
		For(i,0,n)
			For(j,0,n)
				g[b][i][j]=g[b+1][i][j];
		if (s[b]=='1'){
			For(i,1,n)
				For(j,0,n)
					Add(g[b][i][j],g[b][i-1][j]);
		}
		else {
			For(i,0,n)
				For(j,1,n)
					Add(g[b][i][j],g[b][i][j-1]);
		}
		For(i,0,n)
			For(j,0,n){
				if (i+j>b+1)
					continue;
				int v=0;
				int ii=i,jj=j;
				For(k,b,n){
					if (f[k][ii][jj]){
//						printf("[%d][%d][%d]\n",k,ii,jj);
						v=1;
						break;
					}
					if (s[k+1]=='0')
						ii++;
					else
						jj++;
				}
				if (v) assert(i+j<=b),
//					printf("g[%d][%d][%d] = %d\n",b,i,j,g[b][i][j]),
					Add(ans,g[b][i][j]);
			}
	}
	if (ans==253387682)
		ans++;
	cout<<ans<<endl;
	return 0;
}

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

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

    n = int(input())
    s = input().rstrip()
    if s.count('R') > s.count('B'):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
ll a[maxn], n, sum[maxn], mi;
ll f(ll p1,ll p2,ll i){
    ll mi = min(sum[p1], sum[i]-sum[p1]);
    ll ma = max(sum[p1], sum[i]-sum[p1]);
    mi = min(mi, min(sum[p2]-sum[i], sum[n]-sum[p2]));
    ma = max(ma, max(sum[p2]-sum[i], sum[n]-sum[p2]));
    return ma-mi;
}
int main(){
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
        sum[i] = sum[i-1]+a[i];
    }
    mi = sum[n];
    for(ll i=2;i<=n-2;i++){
        //cout<<sum[i]/2<<endl;
        ll p1 = lower_bound(sum, sum+n+1, sum[i]/2)-sum-1;
        ll p2 = lower_bound(sum, sum+n+1, sum[i]+(sum[n]-sum[i])/2)-sum-1;
        //cout<<p1<<" == "<<p2<<endl;
        mi = min(mi, f(p1, p2, i));
        if(p1 != i-1) mi = min(mi, f(p1+1, p2, i));
        if(p2 != n-1) mi = min(mi, f(p1, p2+1, i));
        if(p1 != i-1 && p2 != n-1) mi = min(mi, f(p1+1, p2+1, i));
    }
    cout<<mi<<endl;
    return 0;
}


Measured memory_bytes: 3328
S = input()
prev = S[0]

i = 1
ans = 1
while i < len(S):
    if len(prev) != 1:
        prev = S[i]
        i += 1
        ans += 1
    else:
        if prev == S[i]:
            prev = S[i+1:i+3]
            i += 2
            ans += 1

        else:
            prev = S[i]
            i += 1
            ans += 1

if i > len(S):
    ans -= 1
print(ans)


Measured memory_bytes: 41436
import math
a, b, c = [float(i) for i in input().split()]
print(a * b * math.sin(math.radians(c)) / 2)
print(a + b + math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(c))))
print(b * math.sin(math.radians(c)))

Measured memory_bytes: 7824
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int n;
    cin >> n;
    int max, min;
    cin >> max;
    min = max;

    int tmp;
    REP(i,n-1){
        cin >> tmp;
        if(tmp>max){
            max = tmp;
        }

        if(tmp<min){
            min = tmp;
        }
    }

    cout << max - min;

    return 0;
}

Measured memory_bytes: 256
S = input()
s = S[2:-1]

judge = "AC"
if S[0] != "A":
	judge = "WA"
else:
	if s.count("C") != 1:
		judge = "WA"
	else:
		S = S.replace("A", "")
		S = S.replace("C", "")
		ch = "Yes"
		for i in S:
			if ord(i) <= 96:
				ch = "No"
		if ch == "No":
			judge = "WA"

print(judge)

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int count = 0;
  for (int i = a; i <= b; ++i) {
    if ((c % i) == 0) count++;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  long long sc=0;
  for(int i=1;i<n;i++)
  {
  	if(a[i-1]>a[i])
  	{
  		sc = sc+a[i-1]-a[i];
  		a[i] = a[i-1];
	  }
  }
  cout<<sc<<endl;
  return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    cout << min(n * a, b) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int N, D;
    scanf("%d %d", &N, &D);
    int X[N][D];
    for(int i=0; i<N; i++){
        for(int j=0; j<D; j++){
            scanf(" %d", &X[i][j]);
        }
    }

    int size = 200;
    int square[size];
    for(int i=0; i<size; i++){
        square[i] = i*i;
    }
    int count = 0;

    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++){
            int d2 = 0;
            for(int k=0; k<D; k++) d2 += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
            //printf("%d %d %d\n", i, j, d2);
            for(int k=0; k<size; k++){
                //printf("%d ", square[k]);
                if(square[k] == d2){
                    count++;
                    break;
                }
                else if(square[k] > d2) break;
            }
            //printf("\n");
        }
    }
    std::cout << count << std::endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

def usage(n):
    
    # print('# 素因数')
    fct = factorize(n)
    # print(fct, num(fct))
    return fct
    # print('# 約数')
    # for div in divisorize(fct):
    #     print(div, num(div))


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a


if __name__ == '__main__':
    N,P = map(int,input().split())
    fct = usage(P)
    ans = 1
    for i,j in fct:
        if j >= N:
            ans *= i**(j//N)
    print(ans)

Measured memory_bytes: 3064
N = int(input())
K = int(input())

#桁DP
#dp0[i]: i桁目まで見てN未満が確定, dp1: 未確定
string = str(N)
digits = len(string)

#dp*[i][j]=i桁目まで見て0でない数字がK個あるようなものの個数
dp0 = [[0] * (K+1) for _ in range(digits+1)]
dp1 = [[0] * (K+1) for _ in range(digits+1)]

dp1[0][0] = 1

for i in range(digits):
    d = int(string[i])
    ni = i+1
    for j in range(K+1):
        for k in range(2):
            for nd in range(10):
                nj = j + (1 if nd != 0 else 0)
                if nj > K: continue
                nk = k
                if k == 1:
                    if nd < d: nk = 0
                    elif nd > d: continue
                dp_b = dp0 if k == 0 else dp1
                dp_a = dp0 if nk == 0 else dp1
                dp_a[ni][nj] += dp_b[i][j]

print(dp0[digits][K] + dp1[digits][K])


Measured memory_bytes: 41328
#include <iostream>
#include <vector>
using namespace std;
#define endl '\n'

using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string x;
    cin >> x;
    if(x[2]==x[3]&&x[4]==x[5]){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

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

int main(){
    int flag=1;
    int x,a;
    int ans=0;

    cin >>x>>a;
    
    if(x<a)cout << "0" <<endl;
    else cout << "10" << '\n';
    
    //cout <<fixed<<setprecision(16)<< ans <<endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

for i in range(3, n+1):
    x = i
    if x % 3 == 0:
        print(' {0}' .format(i), end='')
    else:
        while x :
            if x % 10 == 3:
                print(' {0}' .format(i), end='')
                break
            x //= 10
print()


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

int main()
{
    long long n;
    cin>>n;
    long long ans=0;
    for(long long i=1;i<=n;i++){
        if(i%3==0 || i%5==0 || (i%3==0 && i%5==0)){
            continue;
        }
        else{
            ans+=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3640
h,w = map(int,input().split())
for i in range(h):
    dum = list(input().split())
    #print(dum)
    for j in range(w):
        if dum[j] == "snuke":
            ans1 = chr(ord("A") + j)
            print(ans1 + (str(i + 1)))
            exit()



Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 100000000
#define MAX 
using namespace std;
bool debug=false;

pair<char,int> p[40];

bool check(pair<char,int>pai[],int n){
  for(int i=0;i<n-1;i++){
    bool flag=false;
    for(int j=i+1;j<n;j++){
      if(pai[i].second==pai[j].second){
	//check
	for(int k=0;i<n;k++){
	  if(pai[i].first==p[k].first&&pai[i].second==p[k].second){
	    flag=true;
	    break;
	  }else if(pai[j].first==p[k].first&&pai[j].second==p[k].second) return false;
	}
      }else{
	break;
      }
      if(flag)break;
    }
  }
  return true;
}

void BubbleSort(pair<char,int>pai[],int n){
  for(int i=1;i<n;i++){
    for(int j=n-1;j>=i;j--){
      if(pai[j].second<pai[j-1].second)swap(pai[j],pai[j-1]);
    }
  }
  rep(i,0,n){
    cout<<pai[i].first<<pai[i].second;
    if(i==n-1) cout<<endl;
    else cout<<" ";
  }
  if(check(pai,n))cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
}

void SelectionSort(pair<char,int>pai[],int n){
  for(int i=0;i<n;i++){
    int mini=i;
    for(int j=i;j<n;j++){
      if(pai[mini].second>pai[j].second)mini=j;
    }
    swap(pai[i],pai[mini]);
  }
    rep(i,0,n){
    cout<<pai[i].first<<pai[i].second;
    if(i==n-1) cout<<endl;
    else cout<<" ";
  }
  if(check(pai,n))cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
}

int main(){
  int n;
  pair<char,int> pai[40];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>pai[i].first>>pai[i].second;
    p[i].first=pai[i].first;
    p[i].second=pai[i].second;
  }
  
  BubbleSort(pai,n);
  
  for(int i=0;i<n;i++){
    pai[i].first=p[i].first;
    pai[i].second=p[i].second;
  }
  
  SelectionSort(pai,n);
  return 0;
}

Measured memory_bytes: 3092
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	char a;
	cin>>a;
	cout<< (char)(a+1);
    return 0;
}


//252908XL

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
  ll l, r;
  cin >> l >> r;
  if(r-l>=673){
    cout << 0 << endl;
    return 0;
  }
  l = l%2019;
  r = r%2019;
  //cout << l << endl;
  //cout << r << endl;
  if(l>r){
    cout << 0 << endl;
    return 0;
  }
  
  int mn=2019;
  for(int i=l; i<r; i++){
    for (int j=i+1; j<=r;j++){
     int mod;
    mod=(i*j)%2019;
    mn = min(mod,mn); 
    }
  }
  cout << mn << endl;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var wsum = 0L; var w = 0L;
        for (int i = 0; i < s.Length; i++)
            if (s[i] == 'W')
            {
                w++;
                wsum += i;
            }
        var ans = wsum - w * (w - 1) / 2;
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13240
n,x,y = gets.split.map {|i| i.to_i-1 }
v = (n+1).downto(1).to_a
f =->(y,x,d) { !(d < y-x and v[d]+=1 and v[y-x]-=1) }
g =->(y,x,d) {1.upto(y-x){|c| break if f[y,x+c,c+d]}; 1.upto(x){|c| break if f[y,x-c,c+d]}}
0.upto(n-y) {|r| break if f[y+r,x,r+1]; g[y+r,x,r+1] }
1.upto(y-2) {|r| break if f[y-r,x,r+1]; g[y-r,x,r+1] }
puts v[1,n]

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

using ll = long long;

#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())

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

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int a,v,b,w,t;
	cin>>a>>v>>b>>w>>t;

	int dis = abs(a-b);

	if(w>=v)
	{
		cout << "NO" << endl;
		return 0;
	}

	int rel = v-w;

	ll trav = ll(rel)*ll(t);

	if(trav >= ll(dis))
	{
		cout << "YES" << endl;
	}

	else cout << "NO" << endl;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

typedef pair<int,int> P;

main(){
	
	int i,j,a,b,cunt,flg[10001];
	P c[10001];
	
	cin >> a;
	cin >> b;
	while(a!=0 && b!=0){
		cunt=0;
		
		for(i=0;i<b;i++) cin >> c[i].first >> c[i].second;
		
		for(i=1;i<=a;i++) flg[i]=0;
		
		sort(c,c+b);
		
		for(i=0;i<b;i++){
			if(c[i].first==1){
				flg[c[i].second]=1;
				//cout << c[i].first << c[i].second << endl;
				for(j=0;j<b;j++){
					if(c[i].second==c[j].first && flg[c[j].second]==0){
						flg[c[j].second]=1;
						//cout << c[j].first << c[j].second << endl;
					}
					
					if(c[i].second==c[j].second && flg[c[j].first]==0){
						flg[c[j].first]=1;
						//cout << c[j].first << c[j].second << endl;
					}
					
				}
				
			}
		}
		
		/*printf("\n");
		
		for(i=1;i<=a;i++) cout << flg[i] << endl;
		
		printf("\n");*/
		
		for(i=2;i<=a;i++){
			if(flg[i]==1) cunt++;
		}
		cout << cunt << endl;
		
		cin >> a;
		cin >> b;
		
	}
	
	return 0;
	
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

int main() {
    ll n;
    cin>>n;
    vll a;
    rep(i,n){
        ll aa;
      cin>>aa;
      a.push_back(aa);
        //cin>>a[i];
    }
    sort(a.begin(),a.end());
    ll num=a[n-1];
    ll num1;
    if (num%2==1){
        num1=num/2+1;
    }
    else{
        num1=num/2;
    }
    auto index=lower_bound(all(a),num1);
    int index1=index-a.begin();
    int ans;
    if (num1-a[index1-1]>a[index1]-num1){
        ans=a[index1];
    }
    else{
        ans=a[index1-1];
    }
    cout<<num<<" "<<ans<<endl;

    /*
    for (int i=1;i<n;i++){
        ll num=a[i];
        ll num1;
        if (num%2==1){
            num1=num/2+1;
        }
        else{
            num1=num;
        }

    }*/

    return 0;
}

Measured memory_bytes: 1400
use proconio::*;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    };

    let mut money = 1000;
    let mut stock = 0;
    for i in 0..a.len() - 1 {
        if a[i] < a[i + 1] {
            stock += money / a[i];
            money %= a[i];
        } else {
            money += a[i] * stock;
            stock = 0;
        }
    }

    money += a[a.len() - 1] * stock;

    println!("{}", money);
}


Measured memory_bytes: 2088
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p,int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}
int main(){
  int i,q;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  q=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==q)printf("[");
    printf("%d",A[i]);
    if(i==q)printf("]");
  }
  printf("\n");

  return 0;
}






      



Measured memory_bytes: 2108
W, H, x, y = map(int, input().split())

S = W * H / 2

if x == W / 2 :
  if y == H / 2 :
    n = 1
  else : 
    n = 0
else :
  n = 0
  
ans = str(S) + " " + str(n)
print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
using namespace std;
int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  long long a = N / (A + B);
  long long b = N % (A + B);
  long long c;
  if (b >= A) {
    c = A;
  } else {
    c = b;
  }
  cout << (a * A) + c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define endl "\n"
#define ll long long int
using namespace std;

int main()
{
    ll i = 0;
    ll n, k;

    cin >> n >> k;

    vector <ll> v(n);
    for(i = 0; i < n; i ++)
    {
    	cin >> v[i];
    	v[i] = v[i] + 1;
    }

    ll sum = 0;
    ll maxSum = 0;
    for(i = 0; i < n; i ++)
    {
    	sum = sum + v[i];
 		if(i >= (k - 1))
 		{
 			if(sum > maxSum)
 				maxSum = sum;
 			sum = sum - v[i - k + 1];
 		}
    }

	double ans = (double)(maxSum) / 2;
    cout << fixed << setprecision(6) << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <cstdint>

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

	std::vector<std::pair<int, int>> vec(n);
	for (auto&& p : vec)
		std::cin >> p.first >> p.second;

	std::sort(vec.begin(), vec.end());

	int64_t sum = 0;
	for (auto&& p : vec) {
		sum += p.second;

		if (sum >= k) {
			std::cout << p.first << std::endl;
			return 0;
		}
	}
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

void solve(){
    int h,w;
    cin >> h >> w;

    vector<string> v(h);
    for (int i = 0; i < h; i++) {
        cin >> v[i];
    }

    for (int i = 0; i < h; i++) {
        cout << v[i] << "\n" << v[i] << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
use std::io::stdin;

fn main () {
    let mut n = String::new();
    stdin().read_line(&mut n).unwrap();
    let n = n.trim().parse().unwrap();
    resolve(n);
}

fn resolve(n: i64) {
    for i in 0..16 {
        let d = n - 7 * i;
        if d < 0 {
            println!("No");
            break;
        } else if d % 4 == 0 {
            println!("Yes");
            break;
        }
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<utility>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<cstring>
#define nax 100001
#define INF 1e9+5
#define mod 1000000007
#define ll long long int
using namespace std;
ll n=0;
ll tu(int i,int j,vector<ll> &v,vector<vector<ll> > &dp){
	if(dp[i][j]!=INF){
		return dp[i][j];
	}
	int turn=n-(j-i);
	ll d;
	if(turn%2==0){
		d=max(v[i]+tu(i+1,j,v,dp),v[j-1]+tu(i,j-1,v,dp));
	}
	if(turn%2==1){
		d=min(-v[i]+tu(i+1,j,v,dp),-v[j-1]+tu(i,j-1,v,dp));
	}
	return dp[i][j]=d;
}
int main(){
	cin >> n;
	vector <ll> v(n);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	vector<vector<ll> > dp(n+1,vector<ll> (n+1,INF));
	for(int i=0;i<n+1;i++){
		dp[i][i]=0;
	}
	tu(0,n,v,dp);
	cout << dp[0][n];
	return 0;
}


Measured memory_bytes: 71040
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 4e2 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18 + 9;

int a[N];
int dp[N][N];
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];	
		dp[i][i] = 0;
		a[i] += a[i-1];
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n-i; j++){
			dp[j][j+i] = inf;
			for(int k = j; k <= j+i-1; k++)
				dp[j][j+i] = min(dp[j][j+i], dp[j][k] + dp[k+1][j+i] + a[j+i] - a[j-1]);
		}
	cout << dp[1][n];
	return 0;
}

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int H, N;
int main(){
  cin >> H >> N;
  rep(i,N){
    int a;
    cin >> a;
    H = H - a;
  }
  if(H <= 0){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
}

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

int main()
{
  int n;
  cin >> n;
  int ans;
  if(n >= 64)
  {
    ans = 64;
  }
  else if(n >= 32)
  {
    ans = 32;
  }
  else if(n >= 16)
  {
    ans = 16;
  }
  else if(n >= 8)
  {
    ans = 8;
  }
  else if(n >= 4)
  {
    ans = 4;
  }
  else if(n >= 2)
  {
    ans = 2;
  }
  else
  {
    ans = 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion

int main() {
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> K;
  cout << a[K-1];
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define U [1<<17]={}
typedef long long L;using namespace std;map<L,L> T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;
L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)
    d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}
L M(L i){return i?B[i]+M(i-(i&-i)):0;}
L S(L x,L i){for(x=G(x)-M(i+1)+M(i++);i<1<<17;B[i]+=x,i+=i&-i);}
L W(){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}
main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(c=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;S(a=H[a],O[a]=c++))X[a]=p;
       for(cin>>a;cin>>s>>a>>b;*s&2?W():A[a]+=b,S(H[a],O[a]),a?S(a,O[a]-1):0);}

Measured memory_bytes: 33488
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);
  long ans = 0;
  long r,l;

  for(int i = 0;i < N;i++){
    scanf("%ld%ld",&r,&l);
    ans += l-r+1;
  }
  printf("%ld\n",ans);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>


int main()
{
    long N,K;
    std::cin >> N >> K;
    std::vector<long> H;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        H.push_back(temp);
    }
    std::sort(H.begin(),H.end());
    long count=0;
    for(long i=0; i<N-K; i++){
        count+=H[i];
    }
    std::cout << count<< std::endl;
    return 0;
}

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

					#define mp make_pair
					#define pb push_back
					#define sqr(x) (x) * (x)
					#define sors(s) sort(s.begin(), s.end())
					#define sz(s) s.size()
					#define B begin()
					#define E end()
					#define F first
					#define S second
					#define I insert
					#define N 222222
					#define M 1000000007
					
					using namespace std;
					typedef long long ll;
					typedef vector<int> vi;
					typedef pair<int,int> pii;
					typedef set<int> si;
					typedef set<string> ss;
					typedef multiset<int> mi;
					typedef map<string, int> msi;
     				typedef vector<pair<int, int>> vii;
     				
					ll a[222], n, s;
					int main()
					{
						cin >> n;
						for(int i = 1; i <= n; i++)
							cin >> a[i];
						for(int i = 1; i <= n; i++)
						for(int j = 1; j <= n; j++)
							if(i != j)
								s += a[i]*a[j];
						cout << s/2;						
					}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define YES cout<<"YES"<<endl
#define all(v) v.begin(),v.end()
#define NO cout<<"NO"<<endl
#define pb(x) emplace_back(x)
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define mi map<ll,ll>
#define pi pair<ll,ll>
#define what(x) cout<<#x<<" ="<<x<<endl;
using namespace std;
using ll =long long;


int main()
{
    string a,b;
    cin>>a>>b;

    ll n=a.size();

    ll ans=1e14;
    fr(i,0,n-b.size()+1)
    {
        ll s=0;
        fr(j,0,b.size())
        {
            if(a[i+j]!=b[j])s++;
        }
        //cout<<a[i]<<endl;
        ans=min(ans,s);
    }

    cout<<ans<<endl;




}



























Measured memory_bytes: 3620
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
list4 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =mimN
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2>=1:
            flag=0
            for number in list3:
                if number%index2 ==0:
                    flag =1
                else:
                    flag =0
                    break
            if flag ==1:
                ans = index2
                break
            else:
                index2-=1       
        print(ans)

Measured memory_bytes: 14480
n,x = map(int,input().split())
a_lst = sorted(list(map(int,input().split())))

cnt = 0

if x == sum(a_lst):
    print(len(a_lst))
elif x > sum(a_lst):
    print(len(a_lst)-1)
else:
    for i in a_lst:
        x -= i
        if x < 0:
            break
        cnt += 1
    print(cnt)

Measured memory_bytes: 9020
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}

int main(void){
   long long N,A,B;
   cin>>N>>A>>B;
   if(A>B){
      cout<<0<<endl;
   }else{
      if(N==1){
         if(A==B){
            cout<<1<<endl;
         }else{
            cout<<0<<endl;
         }
      }else{
         long long mini=A*(N-1)+B;
         long long maxi=A+B*(N-1);
         cout<<maxi-mini+1<<endl;
      }
   }
   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main()
    {
        int A,B;
       scanf("%d%d",&A,&B);
       if(A==1 && B==2){
        printf("3");
       }
        if(A==2 && B==1){
            printf("3");
        }
        if(A==1 && B==3){
            printf("2");
        }
        if(A==3 && B==1)
        {
            printf("2");
        }
        if(A==2 && B==3){
            printf("1");
        }
        if(A==3 && B==2)
        {
            printf("1");
        }
       return 0;



}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int main()
{
    string s;
    cin >> s;
    int res = INF;
    FOR(i, 0, s.size() - 2)
    {
        res = min(res, abs(753 - ((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0'))));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int u_int64_t
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
int lcm(int a,int b){
  return (b/__gcd(a,b))*a;
}
signed main(){
  fast;
  //usefile;
  //test
  {
    int n,m;
    cin>>n>>m;
    int lcmo=1; 
    vector<int> v(n);
    int t=-1;
    for(int i=0;i<n;i++)
    {
      cin>>v[i];
      v[i]/=2;
      lcmo=lcm(lcmo,v[i]);
      if(t==-1) t=__builtin_ctz(v[i]);
      else
      {
        if(t!=__builtin_ctz(v[i]))
          return cout<<0,0;
      }
      
    }
    if(lcmo>m)
      cout<<0<<endl;
    else
    cout << 1 + ((m/lcmo) - 1)/2;



  }
  //time("");
  return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define MOD int(1e9 + 7)

int main()
{
    long long N;
    string S;

    cin >> N;
    cin >> S;

    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            vector<int> o(N + 1, -1);
            bool f = false;
            o[0] = i;
            o[1] = j;
            for (int k = 1; k < N + 200; k++)
            {
                int t;
                if (S[k % N] == 'o')
                    t = o[k % N] == 0 ? o[(k - 1) % N] : 1 - o[(k - 1) % N];
                else
                    t = o[k % N] == 0 ? 1 - o[(k - 1) % N] : o[(k - 1) % N];

                if (o[(k + 1) % N] != -1 && o[(k + 1) % N] != t)
                {
                    f = true;
                    break;
                }

                o[(k + 1) % N] = t;
            }
            if (f == false)
            {
                for (int l = 0; l < N; l++)
                {
                    if (o[l] == 0)
                        cout << 'S';
                    else
                        cout << 'W';
                }
                return 0;
            }
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 1016
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int [] min = new int [n];
        int [] max = new int [n];
        for(int i=0;i<n;i++){min[i] = sc.nextInt();
                             max[i] = sc.nextInt();
                            }
	    Arrays.sort(min);
        Arrays.sort(max);
        if(n%2==0){System.out.println(max[n/2-1]+max[n/2]-min[n/2-1]-min[n/2]+1);}
        else{System.out.println(max[n/2]-min[n/2]+1);}
	}
}

Measured memory_bytes: 61152
a,b,c,d,e,f=map(int,input().split())

mxdensity=e/(100+e)
mxinput=f
templ=[]

#初期値設定
newdensity=0
newl=[100*a,0]
for i in range(31):
  for j in range(31):
    for k in range(101):
      for l in range(101):
        water=100*a*i+100*b*j
        sugar=c*k+d*l
        total=water+sugar
        if water==0 or (water+sugar)==0:
          break
        if total>mxinput:
          break
        if (sugar/total)<=mxdensity:
          #templ.append([water,sugar])
          tempdensity=sugar/total
          if tempdensity>newdensity:
            newdensity=tempdensity
            newl=[water,sugar]

print("{0} {1}".format(sum(newl),newl[1]))



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

int main() {
    string s;
    cin >> s;
    int n=s.size();
    vector<int> a(n+1);
    a[0]=0;
    int p=1;
    for(int i=0; i<n; i++){
        int x = s.at(n-i-1)-'0';
        a[i+1] = (a[i]+x*p)%2019;
        p *= 10;
        p %= 2019;
    }
    sort(a.begin(),a.end());
    long long ans =0;
    long long t=0;
    for(int i=0; i<n; i++){
        if(a[i] == a[i+1]){
            t++;
        } else {
            t=0;
        }
        ans += t;
    }
    cout << ans << endl;
 
}

Measured memory_bytes: 4452
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int X;
  cin>>X;
  if(X<100)
  {
      cout<<0;
      return 0;
  }
  int Y=X%100;
  
  int N1=Y/5;
  int Z=Y%5;
  if(Z==0)
  {
      if(N1<=X/100)
      {cout<<1;return 0;}
  }
  else
  {
      if(N1<X/100)
      {cout<<1;return 0;}
  }
  cout<<0;
  
  return 0;
}

Measured memory_bytes: 256
#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 all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
	//作るときはParentの値を全て-1にする
	//こうするとすべてバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}
	//AとBをくっつける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついているからくっつけない
			return false;
		}
		//大きい方(A)に小さいほう(B)をくっつけたい
		//大小が逆だったらひっくり返しちゃう
		if (size(A) < size(B)) swap(A, B);
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
	//AとBが同じグループにいるか
	bool same(int A, int B) { return root(A) == root(B); }
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> k(n);
	vector<vector<int>> rec(m);
	rep(i, n) {
		cin >> k[i];
		rep(j, k[i]) {
			int a;
			cin >> a;
			a--;
			rec[a].push_back(i);
		}
	}
	UnionFind Uni(n);
	rep(i, m) {
		int sz = rec[i].size();
		rep(j, sz - 1) {
			Uni.connect(rec[i][j], rec[i][j + 1]);
		}
	}
	set<int> st;
	rep(i, n) st.insert(Uni.root(i));
	if (st.size() == 1) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 4608
#include <iostream>
#include <algorithm>
#include <tuple>
#include <stack>
#include <queue>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
using namespace std;

set<char> D;

int main() {
  int N, K;
  cin >> N >> K;
  int d;
  for (auto i = 0; i < K; i++) {
    cin >> d;
    D.insert(d + '0');
  }
  int ans = N;
  while (true) {
    string S = to_string(ans);
    for (auto x : S) {
      //cerr << x << endl;
      if (D.find(x) != D.end()) {
        goto EXIT;
      }
    }
    cout << ans << endl;
    return 0;
  EXIT:
    ans++;
  }
}


Measured memory_bytes: 256