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

int main() {
	char a[15];
	char b[15];
	char c[15];
	scanf("%s %s %s", a, b, c);
	
	if(a[strlen(a)-1] == b[0] && b[strlen(b)-1] == c[0]){
		printf("YES");
	}
	else{
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 1728
#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))
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() {
  char c;
  cin >> c;
  cout << (char)(c+1) << endl;
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
//#include <bits/stdc++.h>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007


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

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(int a,int b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 

 
int main() {
	ll N;
	cin>>N;
	ll L[N];
	ll max =0;
	ll sum=0;
	FOR(i,0,N-1){
		cin>>L[i];
		sum=sum+L[i];
		if(L[i]>max){
			max=L[i];
		}
	}

	if(max*2>=sum){
		cout<<"No"<<endl;
	}else{
				cout<<"Yes"<<endl;
	}

}

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

int main() {
	int n,time;
	cin >> n >> time;
	int c[n],t[n];
	for(int i=0;i<n;i++){
		cin >> c[i] >> t[i];
	}
	
	int mincost = 10000;
	for(int i=0;i<n;i++){
		if(t[i]<=time){
			if(mincost>c[i]){
				mincost = c[i];
			}
		}
	}
	
	if(mincost == 10000){
		cout << "TLE" << endl;
	}
	else cout << mincost << endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
Nums = []
now = 1
now_cnt = 0
for i in range(N):
    if S[i] == str(now):
        now_cnt += 1
    else:
        Nums.append(now_cnt)  # S[0] = 0のとき、1の数は0なので、Numsの左に0が来る
        now = 1 - now
        now_cnt = 1
Nums.append(now_cnt)

if len(Nums) % 2 == 0:
    Nums.append(0)

Add = 2 * K + 1  # 足す要素数
left = 0
right = 0
sum_ = 0
sum_max = 0

for i in range(0, len(Nums), 2):  # 尺取法
    Nextleft = i
    Nextright = min(i + Add, len(Nums))  # 指示はなくても良い
    while Nextleft > left:
        sum_ -= Nums[left]
        left += 1
    while Nextright > right:
        sum_ += Nums[right]
        right += 1
    sum_max = max(sum_, sum_max)

print(sum_max)

Measured memory_bytes: 46956
#include<stdio.h>

int main()
{
    char str[1001];
    int ans, i;

    while(1) {
        scanf("%s", str);

        if(str[0] == '0') break;

        ans = 0;
        for(i = 0; str[i] != '\0'; i++) {
            ans += str[i] - '0';
        }
        printf("%d\n", ans);
    }
}



Measured memory_bytes: 2104
#include<stdio.h>
char s[200005][16];
int comp(char s[], char t[])
{
	int i = 0;
	while (s[i] != '\0')
	{
		if (t[i] == '\0')
			return 1;
		if (s[i] < t[i])
			return -1;
		if (s[i] > t[i])
			return 1;
		i++;
	}
	if (t[i] != '\0')
		return -1;
	return 0;
}
int h[200005], l;
void swap_h(int a, int b)
{
	int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
int comp_h(int a, int b)
{
	return comp(s[h[a]], s[h[b]]);
}
void f1(int n)
{
	h[l] = n;
	int p = l;
	l++;
	while (p > 0)
	{
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
		p = (p - 1) / 2;
	}
	return;
}
int f2()
{
	l--;
	swap_h(0, l);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
int main()
{
	int n;
	scanf("%d", &n);

	int i;
	for (i = 0; i < n; i++)
		scanf("%s", s[i]);
	l = 0;
	for (i = 0; i < n; i++)
		f1(i);
	int c[200005];
	for (i = 0; i < n; i++)
		c[i] = f2();
	int ans = 1;
	for (i = 1; i < n; i++)
		if (comp(s[c[i - 1]], s[c[i]]) < 0)
			ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 6412
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=1e6+5;
int n,h;
int in[maxn],out[maxn];
int fa[maxn],occ[maxn],ok[maxn];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
	read(n);read(h);
	rep(i,0,h+h)fa[i]=i;
	rep(i,1,n){
		int a,b,c,d;read(a);read(b);read(c);read(d);
		int l=!c?a+h:c,r=!d?b:d+h;
		out[l]++;
		in[r]++;
		l=find(l);r=find(r);
		occ[l]=occ[r]=1;
		if(l!=r)fa[l]=r;
	}
	int flag=1;
	rep(i,h+1,h+h)if(occ[i]&&out[i]<in[i])flag=0;
	rep(i,0,h)if(occ[i]&&in[i]<out[i])flag=0;
	rep(i,0,h+h)if(occ[i])ok[find(i)]|=(out[i]!=in[i]);
	rep(i,0,h+h)if(occ[i]&&!ok[find(i)])flag=0;
	if(flag)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_N 1000

int W, H, N;
int X1[MAX_N], X2[MAX_N], Y1[MAX_N], Y2[MAX_N];

//塗りつぶし用
bool fld[MAX_N * 6][MAX_N * 6];

int compress(int *x1, int *x2, int w){
    vector<int> xs;

    for(int i = 0; i < N; i++){
        for(int d = -1; d <= 1; d++){
            int tx1 = x1[i] + d, tx2 = x2[i] + d;
            if(1 <= tx1 && tx1 <= w) xs.push_back(tx1);
            if(1 <= tx2 && tx2 <= w) xs.push_back(tx2);
        }
    }

    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());

    for(int i = 0; i < N; i++){
        x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
        x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
    }

    return xs.size();
}

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

void solve(){
    //座標圧縮
    W = compress(X1, X2, W);
    H = compress(Y1, Y2, H);

    //線のある部分を塗りつぶし
    memset(fld, 0, sizeof(fld));
    for(int i = 0; i < N; i++){
        for(int y = Y1[i]; y <= Y2[i]; y++){
            for(int x = X1[i]; x <= X2[i]; x++){
                fld[y][x] = true;
            }
        }
    }
    
    //領域を数える
    int ans = 0;
    for(int y = 0; y < H; y++){
        for(int x = 0; x < W; x++){
            if(fld[y][x]) continue;
            ans++;

            //幅優先探索
            queue<P> que;
            que.push(P(y, x));
            while(que.size()){
                P p = que.front();
                que.pop();
                REP(i,4){
                    int ny = p.first + dy[i], nx = p.second + dx[i];
                    if(0 <= ny && ny < H && 0 <= nx && nx < W && fld[ny][nx] == false){
                        que.push(P(ny, nx));
                        fld[ny][nx] = true;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

signed main(){
    while(cin >> W >> H){
        if(W == 0 && H == 0){
            return 0;
        }
        cin >> N;
        REP(i,N){
            cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
            X1[i]++;
            Y1[i]++;
        }
        solve();
    }
}


Measured memory_bytes: 38264
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int N; cin >>N;
  vector<int> a(N);
  rep(i,0,N) cin >>a[i];
  int ans=-1,button=1,count=0;
  while (count<N) {
    count++;
    if (a[button-1]==2) {
      ans=count;
      break;
    } else {
      button=a[button-1];
    }
  }
  cout <<ans <<endl;
}


Measured memory_bytes: 640
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){


	ll n=0;
	ll s=0;
	ll o=0;

	cin>>n;

	o=n;
	for(int i=1; i<11; ++i){
		s+=n%10;
		n=n/10;
	}


	if(o%s==0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}


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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e5 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

int n, m, a[N];
int dp[N];

int main() {
    cin >> n >> m;
    for(int i = 1; i <= m; i ++)
        cin >> a[i];
    for(int i = 1; i <= n; i ++) {
        dp[i] = inf;
        for(int j = 1; j <= m; j ++)
            if(i - a[j] >= 0)
                dp[i] = min(dp[i], dp[i - a[j]] + 1);
    }
    cout << dp[n] << '\n';
    return 0;
}



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

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5;
int mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e9 + 7;
ll infll = 1e18 + 7;



signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a[6]; ForE(i, 1, 5){
        int x; cin >> x; if (x == 0) Ptest(i);
    }
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	if (a > 0){

		cout << b / c - (a-1) / c << endl;

	}
	else {
		cout << b / c + 1 << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[100100];
int K;

ll amin = INT_MAX;
ll amax = -1;

ll judge(ll n){
    REP(i,K){
        n -= n%A[i];    
    }
    return n;
}

int main(){
    cin >> K;
    ll amax = -1;
    REP(i,K){
        ll a;
        cin >> a;
        A[i] = a;
        amax = max(amax, a);
    }

    ll N = 2 + K*amax;
    ll low = -1;
    ll high = -1;

    ll left, right;
    left = 2;
    right = N;
    while(right - left >= 0){
        ll mid = (left+right)/2; 
        bool ok = judge(mid) > 2;
        if(ok) right = mid - 1;
        else left = mid + 1, high = mid;
    }

    left = 2;
    right = N;
    while(right - left >= 0){
        ll mid = (left+right)/2; 
        bool ok = judge(mid) >= 2;
        if(ok) right = mid - 1, low = mid;
        else left = mid + 1;
    }

    if(high < low)
        cout << -1 << endl;
    else
        printf("%lld %lld\n", low, high);
    return 0;
}


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


long gcd(long a, long b){
    if (a < b){
        long tmp = a;
        a = b;
        b = tmp;
    }
    if (a % b == 0)
        return b;
    else
        return gcd(b, a%b);
}

int main() {
    long A, B, C, D;
    cin >> A >> B >> C >> D;

    long ans = B - A + 1;
    long cd = (C * D) / gcd(C, D);
    ans -= (B / C) - ((A-1) / C);
    ans -= (B / D) - ((A-1) / D);
    ans += (B / cd) - ((A-1) / cd);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}



int main()
{
	int n,k;
	cin>>n>>k;
	vector<int>h(n);
	rep(i,n)cin>>h[i];
	vector<int>cost(n,1e9);
	cost[0]=0;
	rep(i,n){
		FOR(j,1,k+1){
			if(i-j>=0){
				cost[i]=min(cost[i],cost[i-j]+abs(h[i-j]-h[i]));
			}
		}
	}
	cout<<cost[n-1]<<endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int x,y,a,b,c,p[100005],q[100005],r[100005];
ll ans,c1,c2,c3;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	for(int i=1;i<=a;i++)scanf("%d",&p[i]);
	for(int i=1;i<=b;i++)scanf("%d",&q[i]);
	for(int i=1;i<=c;i++)scanf("%d",&r[i]);
	sort(p+1,p+a+1,cmp);
	sort(q+1,q+b+1,cmp);
	sort(r+1,r+c+1,cmp);
	int nowi=1,nowj=1,nowk=1;
	for(int i=1;i<=x+y;i++)
	{
		if(r[nowk]>=p[nowi]&&r[nowk]>=q[nowj])
		{
			ans+=r[nowk];
			nowk++;
			continue;
		}
		if(p[nowi]>q[nowj])
		{
			if(nowi<=x)
			{
				ans+=p[nowi];
				nowi++;
			}
			else
			{
				if(r[nowk]>=q[nowj])
				{
					ans+=r[nowk];
					nowk++;
				}
				else
				{
					ans+=q[nowj];
					nowj++;
				}
			}
		}
		else
		{
			if(nowj<=y)
			{
				ans+=q[nowj];
				nowj++;
			}
			else
			{
				if(r[nowk]>=p[nowi])
				{
					ans+=r[nowk];
					nowk++;
				}
				else
				{
					ans+=p[nowi];
					nowi++;
				}
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int64_t x; cin >> x;
    bitset<32> B(x);
    cout << B << endl;
    cout << (~B) << endl;
    cout << (B << 1) << endl;
    cout << (B >> 1) << endl;
}


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

int main() {
  int a,b,k;
  cin >> a>>b>>k;
  for(int i=a;i<min(b+1,k+a);i++){
    cout << i <<endl;
  }

  for(int i=max(a,(b-k+1));i<=b;i++){
    if(i<a+k) continue;
    cout<< i << endl;
  }

  }


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

class UnionFind{
	int par[10000], high[10000];
public:
	UnionFind(int n) {
		for (int i = 0; i < n; i++)par[i] = i;
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (high[x] > high[y])par[y] = x;
		else {
			par[x] = y;
			if (high[x] == high[y])high[y]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};
int main() {
	int n, q; scanf("%d%d", &n, &q);
	UnionFind uf(n);
	rep(i, q) {
		int com, x, y; scanf("%d%d%d", &com, &x, &y);
		if (com)printf("%d\n", uf.same(x, y));
		else uf.unite(x, y);
	}
}

Measured memory_bytes: 3292
S=input()
if (("S" not in S) and ("N" in S)) or (("S" in S) and ("N" not in S)):
    print("No")
elif (("W" not in S) and ("E" in S)) or (("W" in S) and ("E" not in S)):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;


int main() {
	int K, T; cin >> K >> T;
	int a[103];
	for (int i = 0; i < T; ++i) cin >> a[i];
	int ma = 0;
	for (int i = 0; i < T; ++i) ma = max(ma, a[i]);
	cout << max(0, 2 * ma - K - 1) << endl;
	return 0;
}


Measured memory_bytes: 384
/*
    In the name of Allah

    MohammadErfan Gooneh

*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define endl                        '\n'
#define all(a, n)                   for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define IOS                         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
int main() {
    IOS ;
    int a , b ;
    cin >> a >> b ;
    int ans = 0 ;
    for(int i = 0 ; i < 2 ; i++){
        if(a > b){
            ans+=a ;
            a-- ;
        }
        else{
            ans+=b ;
            b-- ;
        }
    }
    cout << ans ;



























return 0 ;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 

using namespace std;

struct Restruant
{
	int score;
	int pos;
	char city[30];	
};

Restruant r[110];
int n;

int doCheck(const char *a, const char *b, int max)
{
	for (int i = 0 ; i < max ; i++)
	{
		if (a[i] > b[i])
		{
			return 1;
		}
		else if (a[i] < b[i])
		{
			return -1;
		}
	}
	
	return 0;
}

bool compare(const Restruant &a, const Restruant &b)
{
	int res = strncmp(a.city, b.city, 11);
	if (res == 0)
	{
		return b.score < a.score;
	}
	else
	{
		if (res > 0)
			return false;
		else
			return true;		
	}
	
}


int main()
{
	scanf("%d\n", &n);
	
	for (int i = 0 ; i < n ; i++)
	{
		r[i].pos = i + 1;
		scanf("%s %d\n", &(r[i].city), &(r[i].score));
	}
	
//for (int i = 0 ; i < n - 1 ; i++)
//	{
//		printf("%s %d\n", r[i].city, strcmp(r[i].city, r[i + 1].city));
//	}	
	
	sort(r, r + n, compare);
	
	for (int i = 0 ; i < n ; i++)	
		printf("%d\n", r[i].pos);
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  string O, E;
  cin>>O>>E;
  REP(i,0,O.size() + E.size()){
    if(i%2 == 0) cout<<O[i/2];
    else cout<<E[i/2];
  }

  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const{
    int i;

    for( i=0; i<N2; i++){
      if( f[i] == p.f[i] ) continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};

static const int dx[4]={-1, 0, 1, 0};
static const int dy[4]={0, -1, 0, 1};
static const char dir[4]={'u','l','d','r'};

bool isTarget(Puzzle p){
  int i;
  for( i=0; i<N2; i++)
    if( p.f[i] != (i+1) )
      return false;
  return true;
}

string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle,bool> V;
  Puzzle u,v;
  
  s.path="";
  Q.push(s);
  V[s]=true;

  while( !Q.empty() ){
    u=Q.front();
    Q.pop();
    if(isTarget(u))
      return u.path;
    int sx=u.space / N;
    int sy=u.space % N;
    int r;

    for( r=0; r<4; r++){
      int tx=sx+dx[r];
      int ty=sy+dy[r];
      if( tx < 0 || ty < 0 || tx >= N || ty >= N )
	continue;
      v=u;
      swap( v.f[u.space], v.f[tx*N+ty] );
      v.space = tx*N+ty;
      if(!V[v]){
	V[v]=true;
	v.path+=dir[r];
	Q.push(v);
      }
    }
  }
  return "unsolvable";
}

int main(){
  Puzzle in;
  int i;

  for(i=0;i<N2;i++){
    cin>>in.f[i];
    
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
  string ans=bfs(in);
  cout<<ans.size()<<endl;
  return 0;
}



Measured memory_bytes: 30644
// E - Sequence Sum
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	ll n; int x, m; cin>>n>>x>>m;
	int mn = min(n, (ll)m);
	vector<int> P; // value of pre & cycle
	ll sum_p = 0; // sum of pre + cycle
	vector<int> X(m, -1); // for cycle check & pre_len
	rp(i, 0, mn){
		if(X[x] > -1){
			int cyc_len = P.size() - X[x];
			int nxt_len = (n - X[x]) % cyc_len;
			ll remain = 0; 
          	rp(i, 0, X[x]) remain += P[i];
			ll cyc = (sum_p - remain) * ((n - X[x]) / cyc_len);
			rp(i, X[x], X[x] + nxt_len) remain += P[i];
			cout<< cyc + remain <<endl;
			return 0;
		}
		X[x] = i;
		P.push_back(x);
		sum_p += x;
		x = (ll)x*x % m;
	}
	cout<< sum_p <<endl;
}


Measured memory_bytes: 3992
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
#define ll long long

int min(int a, int b){
    if(a < b){
        return a;
    }else{
        return b;
    }
}
int main(){
    int N; cin >> N;
    vector<int> dp(N+1);
    dp[0] = 0;
    for(int i = 1; i < N+1; i++){
        dp[i] = 10000;
        dp[i] = min(dp[i],dp[i-1]+1);

        for(int a = 1; i - pow(6,a) >= 0; a++){
            dp[i] = min(dp[i],dp[i-pow(6,a)]+1);
        }
        for(int b = 1; i - pow(9,b) >= 0; b++){
            dp[i] = min(dp[i],dp[i-pow(9,b)]+1);
        }
    }

    cout << dp[N] << endl;
}

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

int main() {
  int n, c = 0;
  cin >> n;
  int a[n];
  for (int i = 0;n > i;i++) 
    cin >> a[i];
  
  for (int x:a) {
    while (x % 2 == 0) {
      c++;
      x /= 2;
    }
  }
  
  cout << c << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
const int N = 2e5 + 5;
 
int32_t main()
{
	IOS;
	
	ll k,n;
	cin>>k>>n;
	ll ans=0;
	while(k>0){
	    k/=n;
	    ans++;
	}
	cout<<ans<<endl;
}

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

using namespace std;
 
int main(){
	string s;
	cin >> s;
	bool flg=1;
	for(int i=0;i<s.size();i++){
		if(i%2==0 && s[i]=='L') flg=0;
		if(i%2!=0 && s[i]=='R') flg=0;
	}
	puts(flg ? "Yes" : "No" );
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    ll n;
    ld t, a;
    cin>>n>>t>>a;
    ld h[n];
    for(ll i=0;i<n;++i){
        cin>>h[i];
    }
    ld flag=1e9;
    ll ans;
    for(ll i=0;i<n;++i){
        if(abs(t-h[i]*6/1000-a)<flag){
            flag=abs(t-h[i]*6/1000-a);
            ans=i;
        }
    }
    cout<<ans+1<<endl;
}

Measured memory_bytes: 256
//set many funcs
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1145141919
#define llinf 1145141919810364364
#define mod 1000000007
 
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
 
int main(void){
    int n,i,a[131072],r=1,c=1;
    scanf("%d",&n);
    for(i = 0;i < n;i++){scanf("%d",&a[i]);}
    qsort(a,n,sizeof(int),sortfncsj);
    for(i=1;i<n;i++){
        if(a[i] == a[i-1]){
            c++;
            if(c%2){r++;}else{r--;}
        }
        else{c=1;r++;}
    }
    printf("%d\n",r);
    return 0;
}

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

typedef long long ll;
const int maxn = 2e5 + 10;
int n, a[maxn], nxt[20][maxn];
ll ans;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < 20; i++) {
        int last = n;
        for (int j = n; j >= 0; j--) {
            nxt[i][j] = last;
            if (a[j] & (1 << i)) last = j;
        }
    }
    for (int i = 0; i < n; i++) {
        int last = n;
        for (int j = 0; j < 20; j++) {
            if (a[i] & (1 << j)) {
                last = min(last, nxt[j][i]);
            } else {
                last = min(last, nxt[j][nxt[j][i]]);
            }
        }
        ans += last - i;
    }
    printf("%lld\n", ans);
    return 0;
}

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

using namespace std;

int H, W, N;
int ans;

void resolve()
{
    cin >> H;
    cin >> W;
    cin >> N;

    int M = max(H, W);
    ans = N / M;
    ans += (N % M == 0) ? 0 : 1;
    cout << ans << endl;
}

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


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

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    float min_a = float(a * 25) / 2, max_a = float((a + 1) * 25) / 2;
    float min_b = b * 10, max_b = min_b + 10;
    if (max_a <= min_b || max_b <= min_a) {
        cout << -1 << endl;
        return 0;
    }
    int res = ceil(max(min_a, min_b));
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, y;
	for(int i=1; cin>>x>>y; i++) {
		if(x==0&&y==0) break;
		if(x<=y) cout<<x<<' '<<y<<'\n';
		else cout<<y<<' '<<x<<'\n';
	}
	return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






long long int gcd(long long int a,long long int b)
{
 
  long long int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int c[9];
  rep(i,9) cin>>c[i];
  if(c[0]-c[1]==c[3]-c[4] && c[3]-c[4]==c[6]-c[7]){
    if(c[1]-c[2]==c[4]-c[5] && c[4]-c[5]==c[7]-c[8]){
      if(c[2]-c[0]==c[5]-c[3] && c[5]-c[3]==c[8]-c[6]){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}
///////////////////////////

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

typedef long long LL;

int main() {
    LL N;
    cin >> N;
    vector<LL> A(N);
    vector<LL> B(N);
    for (LL i = 0;i < N;i++)
        cin >> A[i];

    vector<LL> result_neg;
    vector<LL> result_pos;
    LL sum_neg = 0;
    LL sum_pos = 0;
    LL sum = 0;
    int out = 0;
    for (LL i = 0; i< N;i++) {
        cin >> B[i];
        if (A[i] - B[i] < 0){
            result_neg.push_back(abs(A[i] - B[i]));
            sum_neg += abs(A[i] - B[i]);
            out++;
        }
        else if (A[i] - B[i] > 0) {
            result_pos.push_back(A[i] - B[i]);
            sum_pos += A[i] - B[i];
        }
        sum += A[i] - B[i];
    }
    if (sum_pos < sum_neg)
    {
        cout << -1;
        return 0;
    }
    else if (sum_neg == 0)
    {
        cout << 0;
        return 0;
    }
    else
    {
       sort(result_pos.begin(),result_pos.end());
       for (LL i = result_pos.size() - 1; i >= 0; i--)
       {
           out++;
          if (result_pos[i] - sum_neg < 0)
          {
             sum_neg -= result_pos[i];
          }
          else
              break;
       }
    }
    cout << out;
    return 0;
}


Measured memory_bytes: 2812
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int x,y;
    while(1){
        cin>>x>>y;
        if(x==0&&y==0)break;
        cout<<min(x,y)<<" "<<max(x,y)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3004
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep_3(i, initial, n) for (int i = (int)(initial); i < (int)(n); ++i)
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int i = (int)(n); i > 0; i--)
#define rep_r_3(i, initial, n) for (int i = (int)(initial); i > (int)(n); i--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }

int main() {
	int N;
	cin >> N;
	vector<int> A(N, 0);
	map<int, int> m;

	int max = 0;
	repeat(i, N) {
		int a = 0;
		cin >> a;
		A[i] = a;
		if (max < a) max = a;
	}

	int count = 0;
	repeat(i, N) {
		if (A[i] == max) count++;
	}

	repeat(i, N) {
		if (A[i] == max && count < 2) {
			int max2 = 0;
			repeat(i, N) {
				if (A[i] > max2 && max > A[i]) max2 = A[i];
			}
			m[i] = max2;
		} else {
			m[i] = max;
		}
	}

	repeat(i, N) {
		cout << m[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 11776
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

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

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

int main()
{
    int k,n;
    std::cin >> k >>n;
    std::vector<int> a(n+1, 0);
    int mx = 0;
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
        mx = std::max(mx, a[i]-a[i-1]);
    }
    mx = std::max(mx, a[1]+k-a[n]);
    std::cout << k - mx << std::endl;

    return 0;
}


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

int main() {
    double x[3], y[3], sum = 0;
    scanf("%lf,%lf", &x[0], &y[0]);
    scanf("%lf,%lf", &x[1], &y[1]);
    while (scanf("%lf,%lf", &x[2], &y[2]) != EOF) {
        double side[3];
        for (int i = 0; i < 3; i++) {
            side[i] = sqrt(pow(x[i] - x[(i + 1) % 3], 2) + pow(y[i] - y[(i + 1) % 3], 2));
        }
        double z = (side[0] + side[1] + side[2]) / 2;
        sum += sqrt(z * (z - side[0]) * (z - side[1]) * (z - side[2]));
        x[1] = x[2];
        y[1] = y[2];
    }
    printf("%.6f\n", sum);
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e10;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;


int main(){
	int a, b;
	cin >> a >> b;
	if (a + b == 15){
		cout << '+' << endl;
	}
	else if (a*b == 15){
		cout << '*' << endl;
	}
	else{
		cout << 'x' << endl;
	}

}

Measured memory_bytes: 256
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""


if __name__ == "__main__":
    N = int(sys.stdin.readline())
    def dfs(s):
        if int(s) > N:
            return 0
        ret = 1 if all(s.count(c) > 0 for c in '753') else 0
        for c in '753':
            ret += dfs(s + c)
        return ret

    print(dfs("0"))


Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int>>;

int N, M, Q;
int a[52], b[52], c[52], d[52];
int score_max = 0;

void calcScore(const vi& v){
    int score = 0;
    rep(i,Q){
        if(v[b[i]] - v[a[i]] == c[i]) score += d[i];
    }
    score_max = max(score, score_max);
}

void dfs(vi v){
    if( v.size() == N ) { calcScore(v); return; }
    
    // sizeがNでないとき、末尾に付け加える
    v.push_back( v.back() );

    while( v.back() <= M ){
        dfs(v);
        v.back()++;
    }
}

int main(){
    cin >> N >> M >> Q;
    int in1, in2, in3, in4;
    rep(i,Q){
        cin >> in1 >> in2 >> in3 >> in4;
        in1--; in2--;
        a[i] = in1;
        b[i] = in2;
        c[i] = in3;
        d[i] = in4;
    }
    for(int st = 1; st <= M; ++st){
        vi v(1, st);
        dfs(v);
    }
    cout << score_max;
}

Measured memory_bytes: 3636
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int N=sc.nextInt();
      	
      	if(N%2==0){
         System.out.print(N/2);
      }else{
         System.out.print((N/2)+1);
      }
   }
}

Measured memory_bytes: 35680
#include <stdio.h>

int isPrime(int);
int main(){
    int i,n,integer,count=0;
    
    scanf("%d",&n);
    
    for(i=1;i<=n;i++){
        scanf("%d",&integer);
        if(isPrime(integer) == 1){
            count++;
        }
    }
    
    printf("%d\n",count);
    
    return 0;
}

int isPrime(int x){
    int i;
    
    if(x==2){
        return 1;
    }else if(x<2 || x%2==0){
        return 0;
    }
    
    for(i=3;i*i<=x;i=i+2){
        if(x%i==0){
            return 0;
        }
    }
    
    return 1;
}



Measured memory_bytes: 2044
from collections import defaultdict, deque
n, k = list(map(int, input().split()))
color = [-1 for i in range(n+1)]
MOD = 10**9+7

graph = defaultdict(list)
for i in range(n-1):
  a, b = list(map(int, input().split()))
  graph[a].append(b)
  graph[b].append(a)

def bfs():
  que = deque([(1, 0, 0)])
  while len(que):
    x, par, sib = que.popleft()
    color[x] = k-min(2, par)-sib

    sib = 0
    for nx in graph[x]:
      if color[nx]==-1:
        que.append((nx, par+1, sib))
        sib += 1

bfs()
ans = 1
for i in range(1, n+1):
  ans = (ans*color[i])%MOD
print(ans)

Measured memory_bytes: 45772
fun main(args: Array<String>) {
    val num = readLine()?.toInt() ?: return
    val values = (1..num).mapNotNull { readLine() }
    val mutableList = mutableListOf(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE)
    values.forEach { v ->
        values.filter { it != v }.forEach {
            mutableList.add("$it$v".toInt())
            mutableList.sort()
            mutableList.removeAt(3)
        }
    }
    println(mutableList.last())
}



Measured memory_bytes: 431152
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
template <typename T, typename U>ostream &operator<<(ostream &out, const pair<T, U> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>void print(const ContainerType<ValueType, Args...> &c){for (const auto &v : c)cout << v << ' ';cout << '\n';} void print(){cout<<'\n';}
template <typename T, typename... Args>void print(T a, Args... args){cout << a << " ";print(args...);}
lli llipower(lli x, lli y, lli p = LLONG_MAX){lli res = 1;x = x % p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}

//8====================================D

int main()
{
    lli n;
    cin>>n;
    string ans="";
    while(n>0){
        int rem=n%26;
        
        //print(rem);

        if(rem!=0) ans+=('a'+rem-1);
        else {
            ans+='z';
            n--;
        }
        n/=26;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

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

using namespace std;

using int64 = long long;

template<typename T>
vector<vector<vector<T>>>
Make3DVector(int d1, int d2, int d3, T default_value) {
  return vector<vector<vector<T>>>(
      d1,
      vector<vector<T>>(d2, vector<T>(d3, default_value)));
}

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

  // For float output:
  cout << fixed << setprecision(10);

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

  int c3 = 0;
  int c2 = 0;
  int c1 = 0;
  for (int i = 0; i < n; i++) {
    if (xs[i] == 3) c3++;
    else if (xs[i] == 2) c2++;
    else if (xs[i] == 1) c1++;
  }

  vector<vector<vector<double>>> dp = Make3DVector(n + 1, n + 1, n + 1, -1.0);
  dp[0][0][0] = 0.0;
  function<double(int, int, int)> solve = [&](int c3, int c2, int c1) {
    if (dp[c3][c2][c1] >= 0.0) return dp[c3][c2][c1];
    double dn = n;
    double p3 = c3 / dn;
    double p2 = c2 / dn;
    double p1 = c1 / dn;
    double p0 = (n - c3 - c2 - c1) / dn;
    double value = 0.0;
    if (c3 > 0) value += p3 * (solve(c3 - 1, c2 + 1, c1) + 1.0);
    if (c2 > 0) value += p2 * (solve(c3, c2 - 1, c1 + 1) + 1.0);
    if (c1 > 0) value += p1 * (solve(c3, c2, c1 - 1) + 1.0);
    value += p0 * 1.0;
    value *= 1.0 / (1.0 - p0);
    // cout << 1.0 / (1.0 - p0) << endl;
    dp[c3][c2][c1] = value;
    return dp[c3][c2][c1];
  };
  cout << solve(c3, c2, c1) << endl;
}


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

struct mes{
    mes* pre;
    vector<mes*> fol;
    string m;
};
vector<mes>vec;

void dfs(mes m, int d){
    for(int i=0;i<d;i++)
        cout<<".";
    cout<<m.m<<endl;
    for(int i=0;i<m.fol.size();i++)
        dfs(*m.fol[i],d+1);
}
int main(){
    int n, k;
    string str;
    cin>>n;
    for(int i=0;i<=n;i++){
        mes me;
        vec.push_back(me);
    }
    for(int i=1;i<=n;i++){
        cin>>k>>str;
        vec[i].pre = &vec[k];
        vec[i].m = str;
        vec[k].fol.push_back(&vec[i]);
    }
    dfs(vec[1],0);
}

Measured memory_bytes: 1560
from collections import deque

def main():
    N,K,C = map(int, input().split())
    S = input()

    f = [-1 for i in range(K+1)]
    b = [-1 for i in range(K+1)]

    count = 0
    i = 0
    while i < N and count < K:
        if S[i] == 'o':
            count += 1
            f[count] = i
            i += C+1
        else:
            i += 1
    
    count = K
    j = N-1
    while j >= 0 and count > 0:
        if S[j] == 'o':
            b[count] = j
            count -= 1
            j -= C+1
        else:
            j -= 1

    i = 0
    j = N-1

    for i in range(1,K+1):
        if f[i] != -1 and f[i] == b[i]:
            print(f[i]+1)


main()

Measured memory_bytes: 57336