akhauriyash/Code-Regression huggingface dataset:
using System;

namespace SwappingTwoNumbers
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            while (true)
            {
                string[] str = Console.ReadLine().Split(' ');

                int x = int.Parse(str[0]);
                int y = int.Parse(str[1]);

                if (x == 0 && y == 0)
                {
                    break;
                }

                if (x > y)
                {
                    Console.WriteLine(y + " " + x);
                }
                else
                {
                    Console.WriteLine(x + " " + y);
                }
                
                
            }

        }
    }
}

Measured memory_bytes: 9068
x = int(input())

n = 400

if x < 1.5*n:
    print(8)
elif x < 2*n:
    print(7)
elif x < 2.5*n:
    print(6)
elif x < 3*n:
    print(5)
elif x < 3.5*n:
    print(4)
elif x < 4*n:
    print(3)
elif x < 4.5*n:
    print(2)
elif x < 5*n:
    print(1)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
int main(){
        long n,l;
        cin>>n>>l;
        vector<string> s(n);
        for(int i=0; i<n; i++)
                cin>>s[i];
        sort(s.begin(),s.end());
        for(auto x:s)
                cout<<x;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
    int n=0;
    int max=0;
    int sum=0;
    int so[10000];
    scanf("%d",&n);
    int now=0;
    for(int i=0; i<n; i++){
        scanf("%d",&now);
        if(now>max)max=now;
        sum+=now;
    }
    if(sum>max*2)printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 128
//organize and stay in moment
//Abhinav - IIITA
//I love you Disha
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ld long double
int prime[100005] ,arr[100005],pre[100005];
void seive(){
	prime[0]=prime[1]=1;
	for(int i=2;i<100005;++i){
		if(prime[i]==0)
		for(int j=2*i;j<100005;j+=i)
			prime[j]=1;
	}
}
int32_t main(){
	int n,w; cin>>n>>w;
	int we[n],val[n];
	for(int i=0;i<n;++i)
		cin>>we[i]>>val[i];
	int cost[w+1];
	for(int i=0;i<w+1;++i)
		cost[i]=0;
	for(int i=0;i<n;++i){
		for(int j=w;j>=0;--j){ // just reverse the loop and you get the knapsack when multiple values are alllowed
			if(j<we[i])
				continue;
			cost[j]=max(cost[j],cost[j-we[i]]+val[i]);
		}
	}
	cout<<cost[w];
	return 0;
}

Measured memory_bytes: 1024
#include "stdio.h"

int main() 
{

  int i,j,a,b;



while (1) 
{


  scanf("%d %d\n",&a,&b);
  if (a==0) {
    break;
  }

for (j = 0; j < a; j++) 
{
  
for (i = 0; i < b; i++) 
{
  
 printf("#");

}
printf("\n");

}
printf("\n" );

}









  return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int H, h, W, w;
	cin >> H >> W >> h >> w;
	cout << (H - h) * (W - w) << endl;
}



Measured memory_bytes: 256
#include<iostream>

double n;
char ans[14];
double tw[4]={0.5,0.25,0.125,0.0625};

void solve(){
	bool flag = false;
	int tmp = n;
	for(int i=7; i>=0; i--){
		ans[i] = (char)(tmp%2+48);
		tmp = tmp/2;
	}
	if(tmp != 0)
		flag = true;
	ans[8] = '.';
	double temp = n-(int)n;
	for(int i=9; i<=12; i++){
		if(temp-tw[i-9]>=0){
			ans[i] = '1';
			temp -= tw[i-9];
		}else
			ans[i] = '0';
	}
	if(temp != 0 || flag)
		std::cout << "NA\n";
	else
		std::cout << ans << std::endl;
}

int main(){
	while(true){
		std::cin>> n;
		if(n<0)
			return 0;
		solve();
	}
}

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



int main(){
    string s;
    cin >> s;
    int n = s.size();
    int n1 = (n-1)/2;
    int n2 = (n+3)/2;

    rep(i,(n-1)/2){
        if(s[i]!=s[n-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }



    
    rep(i,(n1+1)/2){
        if(s[i]!=s[(n+1)/2-2-i]){
            //cout << s[i] << ":" <<s[(n+1)/2-2-i] << endl;
            cout << "No" << endl;
            return 0;
        }
    }
    rep(i,n2/2){
        if(s[(n+1)/2+i]!=s[n-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def main():
    h, w, k = map(int, input().split())
    c = [input() for i in range(h)]

    h_bin = 1 << h
    w_bin = 1 << w

    ans = 0
    for i_h in range(h_bin):
        for i_w in range(w_bin):
            now_count = 0

            for i_line in range(h):
                now_line = 1 << i_line
                if i_h & now_line == 0:
                    continue

                for j_raw in range(w):
                    now_raw = 1 << j_raw
                    if i_w & now_raw == 0:
                        continue

                    if c[i_line][j_raw] == '#':
                        now_count += 1
                    
                    if now_count > k:
                        break

            if now_count == k:
                ans += 1

    print(ans)
    return


if __name__ == "__main__":
    main()
    sys.exit(0)

Measured memory_bytes: 73748
import sys

if __name__ == "__main__":
    V = [int(sys.stdin.readline()) for i in range(5)]
    ans = 0
    mi = 100
    for v in V:
        if v % 10 == 0:
            ans += v
        else:
            ans += v - (v % 10) + 10
            mi = min(mi, v % 10)

        #print(ans, mi)

    if mi != 100:
        ans -= (10 - mi)

    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
string T;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	FOR(i,4) {
		if(i==0) T="SS";
		if(i==1) T="SW";
		if(i==2) T="WS";
		if(i==3) T="WW";
		for(j=1;j<N-1;j++) {
			if((T[j]=='S') ^ (S[j]=='o')){
				T.push_back('S'+'W'-T[j-1]);
			}
			else {
				T.push_back(T[j-1]);
			}
		}
		
		if((T[N-1]=='S') ^ (S[N-1]=='o') ^ (T[N-2]!=T[0])) continue;
		if((T[0]=='S') ^ (S[0]=='o') ^ (T[N-1]!=T[1])) continue;
		cout<<T<<endl;
		return;
		
	}
	cout<<-1<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 720
#include <stdio.h>

int main(void) {
  int N;
  scanf("%d", &N);
  int cnt = 0;
  while (N - 2 >= 0) {
    N = N - 2;
    cnt++;
  }
  if (N == 1) {
    cnt++;
  }
  printf("%d\n", cnt);
}

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

using namespace std;

int64_t solve(int64_t n, int64_t m) {
  if (n * 2 > m) {
    return m / 2;
  }
  return n + (m - n * 2) / 4;
}

int main() {
  int64_t n, m;
  std::cin >> n >> m;
  std::cout << solve(n, m) << std::endl;
  return 0;
}


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

int main()
{
  int S; cin >> S;
  
  int first = S/100;
  int second = S%100;
  
  int A = 0;
  int B = 0;
  
  if(first >= 1 && first <= 12 ){
    A = 1;
  }
   
  if(second >= 1 && second <= 12){
    B = 1;
  }
  
  if(A == 1 && B == 1){
    cout << "AMBIGUOUS" << endl;
  }
  
  if(A == 0 && B == 0){
    cout << "NA" << endl;
  }
  
  if(A == 1 && B == 0){
    cout << "MMYY" << endl;
  }
  
  if(A == 0 && B == 1){
    cout << "YYMM" << endl;
  }
   
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    
    int N,A,B;
    
    scanf("%d",&N);
    scanf("%d",&A);
    scanf("%d",&B);
    if(N*A>=B){
        printf("%d\n",B);
    }else{
        printf("%d\n",N*A);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    vector<int> el(3);
    cin >> el[0] >> el[1] >> el[2];
    sort(el.begin(), el.end());
    int k;
    cin >> k;
    while(k--) {
        el[2] *= 2;
    }
    cout << el[0] + el[1] + el[2] << endl;
    return 0;
    
}


Measured memory_bytes: 256
N, K, Q = map(int, input().split())

# 正解分のポイントを考慮する前の、N人それぞれのポイントの配列
P = [K - Q] * N

# 配列Pに対して、正解者のポイントを足す
for _ in range(Q):
    p = int(input())
    P[p - 1] = P[p - 1] + 1

# ポイントが正の場合、勝ち残り
for p in P:
    if p > 0:
        print('Yes')
    else:
        print('No')


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

int main()
{
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vec P(A), Q(B), R(C);
    REP(i,0,A) cin >> P[i];
    REP(i,0,B) cin >> Q[i];
    REP(i,0,C) cin >> R[i];

    DESC(P);
    DESC(Q);
    DESC(R);

    vec S;
    REP(i,0,X) S.pb(P[i]);
    REP(i,0,Y) S.pb(Q[i]);
    REP(i,0,C) S.pb(R[i]);

    DESC(S);
    ll sum = 0;
    REP(i,0,X+Y) sum += S[i];
    PR(sum);
    
    return 0;
}

/*

p q r -> p = r
p r q -> p = r
q p r -> q = r
q r p -> q = r
r p q -> x
r q p -> x

*/

Measured memory_bytes: 9724
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {
   
    int s = 0;
    int hh = 0;
    int mm = 0;
    int ss = 0;
    
    
    scanf("%d", &s);
    
    hh = s / 3600;
    mm = (s/60)%60;
    ss = s%60;
    
    printf("%d:%d:%d\n", hh, mm, ss);
    
    
   
    return 0;
}

Measured memory_bytes: 592
#!/usr/bin/ruby
while s=gets
	n=s.to_i
	break if n==0
	r=0
	(2..1/0.0).each{|i|
		x=n-i*(i-1)/2
		break if x<i ### x<=0
		#if x%i==0
		if n%i==[i/2,0][i%2] # http://yukicoder.me/problems/745 ??????????????§??????????????\?????????????????????,?¨???????????????¨??????????????????????????????.
			#r+=x/i
			#r+=n/i-(i-1)/2
			r+=1
		end
	}
	p r
end

Measured memory_bytes: 8652
#include <stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	char string[n];
	scanf("%s",&string);
	
	int flag = 1;
	
	if (n%2 == 1){
		printf("No");
		return 0;
	} else{
	for (int i=0 ; i < n/2 ; i++){
		if (string[i] == string[i+n/2]){
	
		}
		else {
			flag = 0;
		}
	}
}
	(flag==1)?printf("Yes"):printf("No");	
	return 0;
}

Measured memory_bytes: 3232
#include<iostream>
using namespace std;
long long l[101];
int main(){
	int n,i;
	cin>>n;
	l[0]=2;
	l[1]=1;
	for(i=2;i<=n;i++)
		l[i]=l[i-1]+l[i-2];
	cout<<l[n];
}

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

int main(){
	int H,W;
	cin>>H>>W;
	char map[H][W];
	int num=0;
	for(int i=0;i<H;++i){
		for(int j=0;j<W;++j){
			cin>>map[i][j];
			if(map[i][j]=='.')num++;
		}
	}
	queue<int>x;
	queue<int>y;
	queue<int>ans;
	int pro=1;
	x.push(0);
	y.push(0);
	ans.push(1);
	while(true){
		if(map[y.front()+1][x.front()]=='.' && y.front()<H-1){
			x.push(x.front());
			y.push(y.front()+1);
			ans.push(ans.front()+1);
			if(x.front()==W-1 && y.front()+1==H-1)break;
			map[y.front()+1][x.front()]='+';
		}
		else if(map[y.front()-1][x.front()]=='.' && y.front()>0){
			x.push(x.front());
			y.push(y.front()-1);
			ans.push(ans.front()+1);
			if(x.front()==W-1 && y.front()-1==H-1)break;
			map[y.front()-1][x.front()]='+';
		}
		else if(map[y.front()][x.front()+1]=='.' && x.front()<W-1){
			x.push(x.front()+1);
			y.push(y.front());
			ans.push(ans.front()+1);
			if(x.front()+1==W-1 && y.front()==H-1)break;
			map[y.front()][x.front()+1]='+';
		}
		else if(map[y.front()][x.front()-1]=='.' && x.front()>0){
			x.push(x.front()-1);
			y.push(y.front());
			ans.push(ans.front()+1);
			if(x.front()-1==W-1 && y.front()==H-1)break;
			map[y.front()][x.front()-1]='+';
		}
		else if(x.size()>1){
			x.pop();
			y.pop();
			ans.pop();
		}
		else{
			pro=0;
			break;
		}
	}
	if(pro==0)cout<<-1<<endl;
	else{
		while(ans.size()>1)ans.pop();
		cout<<num-ans.front()<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

int main() {FIN
	
	int h, w, i, j;
	string s;
	cin >> h >> w;
	vs grd(h);
	vvi tb(h, vi(w));
	for (i = 0; i < h; i++) {
		cin >> grd[i];
	}
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (i == 0 and j == 0) {
				tb[i][j] = (grd[i][j] == '#' ? 1 : 0);
				continue;
			}
			if (grd[i][j] == '.') {
				if (i > 0 and j > 0)
					tb[i][j] = min(tb[i - 1][j], tb[i][j - 1]);
				else if (i > 0)
					tb[i][j] = tb[i - 1][j];
				else 
					tb[i][j] = tb[i][j - 1];
			} else {
				if (i > 0 and j > 0) {
					if (grd[i - 1][j] == grd[i][j - 1]) {
						if (grd[i - 1][j] == '.')
							tb[i][j] = min(tb[i - 1][j], tb[i][j - 1]) + 1;
						else
							tb[i][j] = min(tb[i - 1][j], tb[i][j - 1]);
					} else {
						if (grd[i - 1][j] == '.')
							tb[i][j] = min(tb[i - 1][j] + 1, tb[i][j - 1]);
						else
							tb[i][j] = min(tb[i - 1][j], tb[i][j - 1] + 1);
					}
				} else if (i > 0) {
					tb[i][j] = tb[i - 1][j] + (grd[i - 1][j] == '.' ? 1 : 0);
				} else {
					tb[i][j] = tb[i][j - 1] + (grd[i][j - 1] == '.' ? 1 : 0);
				}
			}
		}
	}
	cout << tb[h - 1][w - 1] << "\n";
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

using Graph = vector<vector<ll>>;
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
    }
}


int main(){

  ll n,m;
  cin >> n>> m;

  ll x[m],y[m],z[m];
  for(int i=0;i<m;i++)cin >> x[i] >> y[i] >> z[i];

  vector<vector<ll>> G(n);
  for(int i=0;i<m;i++){
    G[x[i]-1].push_back(y[i]-1);
    G[y[i]-1].push_back(x[i]-1);
  }

  int count = 0;
  seen.assign(n, false);
  for (int v = 0; v < n; ++v) {
    if (seen[v]) continue; // v が探索済みだったらスルー
    dfs(G, v); // v が未探索なら v を始点とした DFS を行う
    ++count;
  }

  cout << count << endl;



}

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

#define DEF_ELEM_MAX 1000001

typedef long long llong;

int A[DEF_ELEM_MAX];
int N;

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
void swap(int *x, int *y)
{
	int tmp;
	tmp = *x;
	*x = *y;
	*y = tmp;
	return;
}
/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int partition(int *A, int p, int r)
{
	int j;
	int x = A[r];
	int i = p-1;

	for ( j = p ; j < r ; j++ ) {
		if ( A[j] <= x ) {
			i++;
			swap(&A[i], &A[j]);
		}
	}
	swap(&A[i+1], &A[r]);
	return i+1;
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int main(void)
{
	int i;
	int k;
//
	scanf("%d", &N);
	for ( i = 0 ; i < N ; i++ ) {
		scanf("%d", &A[i] );
	}

	k = partition(A, 0, N-1);

	for ( i = 0 ; i < N ; i++ ) {
		if ( k == i ) {
			printf("[%d]", A[i]);
		} else {
			printf("%d", A[i]);
		}
		if ( i < N-1) {
			printf(" ");
		} else {
			printf("\n");
		}
	}

	return 0;
}

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

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

  vector<bool> link1(N + 1, false);
  vector<bool> linkN(N + 1, false);

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;

    if (a == 1) {
      if (linkN[b]) {
	cout << "POSSIBLE" << endl;
	return 0;
      }
      link1[b] = true;
    }

    if (b == N) {
      if (link1[a]) {
	cout << "POSSIBLE" << endl;
	return 0;
      }
      linkN[a] = true;
    }
  }

  cout << "IMPOSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 256
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define pb push_back
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rii(x,y) ri(x), ri(y)
#define rll(x,y) rl(x), rl(y)

#define fst first
#define snd second

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

const int MAXN = 1e5+5;

int n, m, a[MAXN];
int mm(int x){
	return (x%m+m)%m;
}
int dst(int v, int u){
	return mm(u-v);
}

int ddec[MAXN], dval[MAXN];
int main(){
	rii(n,m);
	FOR(i,0,n){
		ri(a[i]);
		a[i]--;
	}
	ll mn, val=0, dec=0;
	FOR(i,0,n-1){
		int v=a[i], u=a[i+1];
		int d = dst(v,u);
		int l=mm(u-(d-1)), r=u;
		ddec[l]++;
		ddec[r]--;
		dval[r]+=d-1;
		if(l>r){
			r+=m;
			if(l<a[0] && a[0]<=r) dec++;
			else{
				r-=m;
				l-=m;
				if(l<a[0] && a[0]<=r) dec++;
			}
		}else{
			if(l<a[0] && a[0]<=r) dec++;
		}
		val += min(d, 1+dst(a[0],u));
	}
	mn = val;
	FOR(ii,a[0],a[0]+m){
		int i=mm(ii);
		mn=min(val,mn);
		dec += ddec[i];
		val = val - dec;
		val += dval[i];
	}
	printf("%lld\n",mn);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
#define maxIndex(v) max_element(v.begin(), v.end()) - v.begin()
#define maxElement(v) *max_element(v.begin(), v.end())
#define minIndex(v) min_element(v.begin(), v.end()) - v.begin()
#define minElement(v) *min_element(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;

string S, T; 
vector<string> words;

string word_proc(string x, string y, ll n) {
	rep(i, 0, y.size()) {
    	x[n + i] = y[i];
    }
  	rep(i, 0, x.size()) {
    	if (x[i] == '?') {
        	x[i] = 'a';
        }
    }
  	return x;
}

int main()
{
  cin >> S >> T;  
  rep(i, 0, S.size() - T.size() + 1) {
    string S_ = S;
  	rep(j, 0, T.size()) {
    	if (S[i + j] != T[j] && S[i + j] != '?') {
        	break;
        }
      	if (j == T.size() - 1 && (S[i + j] == T[j] || S[i + j] == '?')) {
          S_ = word_proc(S_, T, i);
//          cout << S_ << endl;
          words.push_back(S_);
        }
    }
  }
  vsort(words);
  if (words.size() == 0) cout << "UNRESTORABLE" << endl;
  else cout << words[0] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

bool isPrime(int x){
    if(x==2){
        return true;
    }else if(x<2 || x%2==0){
        return false;
    }else{
        int i=3;
        while(i<=sqrt(x)){
            if(x%i==0){
                return false;
            }
            i+=2;
        }
        return true;
    }
}

int main(){
    int prime[100001];
    int index = 0;
    for(int i=3;i<100000;i+=2){
        if(isPrime(i) && isPrime((i+1)/2)){
            prime[index] = i;
            index++;
        }
    }
    int q;
    cin >> q;
    int ans[q];
    for(int i=0;i<q;i++){
        int l,r;
        cin >> l >> r;
        ans[i] = distance(lower_bound(prime,prime+index,l),upper_bound(prime,prime+index,r));
    }

    for(int i=0;i<q;i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
  int n;
  int i=0, j=0, v;
  cin >> n;
  int a[n];
  for(i = 0; i < n; i++) cin >> a[i];
  for(i = 0; i < n-1; i++) cout << a[i] << " ";
  cout << a[n-1] << endl;
  //?????????
  for(i=1; i<n; i++){
    v = a[i];
    j = i-1;
    while(j>=0 && a[j]>v){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
    for(j=0; j<n-1; j++) cout << a[j] << " ";
    cout << a[n-1] << endl;

  }

  return 0; 
    
}

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

int main(){
    int n;
    cin >> n;
    vector<int> A(n+2);
    A.at(0)=0;
    A.at(n+1)=0;
    int total=0;
    for(int i=1; i<=n; i++){
        int a;
        cin >> a;
        A.at(i) = a;
        total += abs(A.at(i) - A.at(i-1));
    }
    total+=abs(A.at(n));

    for(int i=1; i<n+1; i++){
        cout << total - (abs(A.at(i)-A.at(i-1))+ abs(A.at(i)-A.at(i+1)))
                    + abs(A.at(i+1)-A.at(i-1)) << endl;
    }
}

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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

int main(){
    char a;
    cin>>a;

    if(isupper(a))cout<<'A'<<endl;
    else cout<<'a'<<endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <stack>
#include <queue>
 
using namespace std;
using ll = long long int;
 
int main()
{
  int n, m;
  cin >> n >> m;
  vector<vector<int>> graph(n, vector<int>());
  for(int i = 0; i < n + m - 1; i++)
  {
    int a, b;
    cin >> a >> b;
    graph[a - 1].push_back(b - 1);
  }
  vector<int> ind(n, 0);
  vector<int> parent(n , -1);
  vector<int> longest(n, 0);
  vector<bool> flag(n, false);
  //入次数のカウント
  for(int i = 0; i < n; i++)
  {
    for(int j = 0; j < graph[i].size(); j++)
    {
      ind[graph[i][j]]++;
    }
  }
  //根の見つける
  int root = 0;
  for(int i = 0; i < n; i++)
  {
    if(ind[i] == 0)
    {
      root = i;
      break;
    }
  }
  //各頂点について根からの最長経路を見つける
  //rootを取り除きながら各頂点の親を更新していく
  queue<int> s;
  s.push(root);
  while(!s.empty())
  {
    int target = s.front();
    s.pop();
    for(int i = 0; i < graph[target].size(); i++)
    {
      int next = graph[target][i];
      ind[next]--;
      if(ind[next] == 0)
      {
        //親の更新
        parent[next] = target;
        s.push(next);
      }
    }
  }
  for(auto e : parent)
  {
    cout << e + 1 << endl;
  }
}


Measured memory_bytes: 7552
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = 0;
    if (b >= c) ans = b + c;
    else ans = 2*b + min(c-b, a+1);
    cout << ans << endl;
}

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

/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______
 * |\  \|\  \  |\  ___ \  |\  ___ \
 * \ \  \/  /|_\ \   __/| \ \   __/|
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 200010;

int dp[mxN];

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

	int N;
	cin>>N;
	deque<int> a(N);
	for(int i = 0;i < N;i++) cin>>a[i];
	int res = 0;
	for(int i = N-1;i >= 0;i--) {
		dp[a[i]] = dp[a[i]+1] + 1;
		res = max(res,dp[a[i]]);
	}
	cout<<N-res<<'\n';
	return 0;
}


Measured memory_bytes: 1920
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline char CH()
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline long IN(void)
{
  long x=0;int f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Radix32(int A[],const int sz)
{
  int temp[200001];const int bit=8;
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,sz)u[A[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)u[i+1]+=u[i];
    rep(i,sz){temp[--u[A[sz-1-i]>>bit*k&((1<<bit)-1)]]=A[sz-1-i];}k++;
    rep(i,sz)v[temp[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)v[i+1]+=v[i];
    rep(i,sz)A[--v[temp[sz-1-i]>>bit*k&((1<<bit)-1)]]=temp[sz-1-i];
  }
}
int main(void)
{
  int N=IN(),x,p=0,m=0,z=0,A[200000];
  long K=IN(),count=0,l=-2e18,r=-l,mid;
  rep(i,N){x=IN();if(x>0)A[m+p++]=x;else if(x<0)A[p+m++]=x;else z++;}
  Radix32(A,m+p);
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  if(K<=1l*m*p)r=1l;else l=-1l;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;if(count>=K){r=mid-1l;continue;}
      rep(i,p){while(1l*A[i]*A[plus]>mid){plus--;}if(i>=plus){break;}count+=1l*plus-i;}if(count>=K){r=mid-1l;continue;}
      rep(i,m){while(1l*A[m+p-1-i]*A[m+p-1-minus]>mid){minus--;}if(i>=minus){break;}count+=1l*minus-i;}
    }
    else{int low=0;rep(i,m){while(1l*A[low]*A[p+i]>mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K)r=mid-1l;else l=mid+1l;
  }
  return OUT(l),0;
}

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

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

const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    ll n,p;
    cin >> n >> p;

    if(n == 1){
        cout << p << endl;
        return 0;
    }
    ll ans = 1;
    for(int i = 2; pow(i,n) <= p; i++){
        while(p % (ll)pow(i,n) == 0){
            p /= pow(i,n);
            ans *= i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
manzoku=0
dish_b=100
for i in range(n):
    dish=a[i]
    manzoku+=b[dish-1]
    if dish==dish_b+1:
        manzoku+=c[dish_b-1]
    dish_b=dish
print(manzoku)


Measured memory_bytes: 3060
#include <iostream>
#include <complex>
#include <vector>
using namespace std;
typedef complex<int> P;

P input[4];
vector<int> ansVec;
int calc(int now, int board[])
{
	if(now >= 4*4)
		return 1;
	if(board[now] != 0)
		return calc(now+1, board);

	int ret = 0;
		
	for(int i=0; i<4; ++i)
	{
		int x = now % 4;
		int y = now / 4;
		x += input[i].real();
		y += input[i].imag();
		int tmp[4*4];
		for(int j=0; j<4*4; ++j)
		{
			tmp[j] = board[j];
		}
		tmp[now] = i+1;
		if(x < 0 || x > 3 || y < 0 || y > 3)
		{
			continue;
		}
		int ref = now + input[i].real() + input[i].imag()*4;
		
		if(board[ref] != 0)
			continue;
		tmp[ref] = i+1;
		ret += calc(now+1, tmp);
	}
	return ret;
}


int main(int argc, char *argv[]) {
	while(1)
	{
		int x1,y1,x2,y2,x3,y3,x4,y4;
		cin>>x1;
		if(x1>4)
		{
			for(int i=0; i<ansVec.size(); ++i)
			{
				cout<< ansVec.at(i)<< endl;
			}
			return 0;			
		}

		cin>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
		input[0] = P(x1,y1);
		input[1] = P(x2,y2);
		input[2] = P(x3,y3);
		input[3] = P(x4,y4);
		int board [4*4];
		for(int i=0; i<4*4; ++i)
		{
			board[i] = 0;
		}
		int ans;
		ans = calc(0, board);
		ansVec.push_back(ans);
	}
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
long long sum=0,n,i;
int main()
{
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		if((i%3)==0)
			continue;
		else if((i%5)==0)
			continue;
		else
			sum+=i;
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstdio>
using namespace std;
int main()
{
	string s;
    getline(cin,s);
	for(int i=0;i<s.size();i++){
		char c=s[i];
		(97<=c&&c<=122)?printf("%c",c-32):printf("%c",c);
	}
	cout<<endl;
    return 0;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int n;

main() {
    cin >> n;
    printf("ABC%d\n",n);
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,c,b,d,min,max;
    scanf("%d %d",&a,&b);
    scanf("%d %d",&c,&d);
    if(a>c)
        min=a;
    else
        min=c;
    if(b<d)
        max=b;
    else
        max=d;
    if(b<=c)
        printf("0\n");
    else if(a>=d)
        printf("0\n");
    else
    printf("%d\n",max-min);
    }

Measured memory_bytes: 1732
#include<iostream>
#include<vector>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
template<class T> inline void chmin(T& a, T b) { if(a > b) a = b; }
template<class T> inline void chmax(T& a, T b) { if(a < b) a = b; }

int main(){
	int N;
	std::cin >> N;
	ll res = 0;
	for(int i=1; i<=N-1; i++){
		for(int j=1; j * j<=i; j++){
			if(i % j == 0){
				res += 2;
				if(j * j == i) res--;
			}
		}
	}
	std::cout << res << std::endl;
	return 0;
}

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

int main() {
    string s; cin >> s;
    if (s == "RRS") {
        cout << 2 << endl;
        return 0;
    } else if  (s == "SRR") {
        cout << 2 << endl;
        return 0;
    } if (s == "RRR") {
        cout << 3 << endl;
        return 0;
    } if (s == "RSR") {
        cout << 1 << endl;
        return 0;
    } else if (count_if(s.begin(), s.end(), [](char c){ return c == 'R'; }) == 1) {
        cout << 1 << endl;
        return 0;
    } else {
        cout << 0 << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 mod = 998244353;
    int n;
    std::string s;
    std::cin >> n >> s;

    i64 ret = 1;
    for (i64 i = 1; i <= n; i++) ret = ret * i % mod;
    i64 p[] { 0, 0, 0, }, q[] { 0, 0, 0 };

    for (auto c : s) {
        if (c == 'R') {
            if (q[2]) {
                ret = ret * q[2]-- % mod;
            } else if (p[0]) {
                ret = ret * p[0]-- % mod;
                q[1]++;
            } else if (p[1]) {
                ret = ret * p[1]-- % mod;
                q[0]++;
            } else {
                p[2]++;
            }
        } else if (c == 'G') {
            if (q[1]) {
                ret = ret * q[1]-- % mod;
            } else if (p[0]) {
                ret = ret * p[0]-- % mod;
                q[2]++;
            } else if (p[2]) {
                ret = ret * p[2]-- % mod;
                q[0]++;
            } else  {
                p[1]++;
            }
        } else {
            if (q[0]) {
                ret = ret * q[0]-- % mod;
            } else if (p[1]) {
                ret = ret * p[1]-- % mod;
                q[2]++;
            } else if (p[2]) {
                ret = ret * p[2]-- % mod;
                q[1]++;
            } else {
                p[0]++;
            }
        }
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
map <string,int> m;
int N;
int main(){
	cin>>N;
  
  	for (int i=0;i<N;i++){
		string str;
      	cin>>str;
      	m[str]++;
    }
  	int mx = 0;
  	for (auto i: m){
		mx = max(mx,i.s);
    }
  
  vector <string> ans;
  for (auto i: m){
    if (i.s == mx){
		ans.push_back(i.f);
    }
  }
  
  sort(ans.begin(),ans.end());
  for (auto i: ans) cout<<i<<'\n';
}

Measured memory_bytes: 26868
import sys
N, K = map(int, sys.stdin.readline().rstrip().split())
if K == 0:
    print(N ** 2)
    exit()
ans = 0
for b in range(1, N + 1):
    if b - 1 < K:
        continue
    ans += (N // b) * (b - K) + (max(N % b - K + 1, 0))
print(ans)

Measured memory_bytes: 39152
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	ll ans = 0;
	vector<ll> a(n);
	rep(i, n){
		cin >> a[i];
		ans ^= a[i];
	}
	rep(i, n) a[i] &= ~ans;
	
	for(int i = 63, p = 0; i >= 0; i--){
		int j = -1;
		rep(k, n) if((a[k] >> i & 1) && !(a[k] >> i + 1)){
			j = k;
			break;
		}
		if(j < 0) continue;
		
		swap(a[p], a[j]);
		rep(k, n) if(k != p && (a[k] >> i & 1)) a[k] ^= a[p];
		p++;
	}
	ll sum = 0;
	rep(i, n) sum = max(sum, sum ^ a[i]);
	ans += 2 * sum;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};

using Graph = vector<vector<int>>;

int re[100];
int ans = 0;
void dfs(Graph& G,int a,int n){
    if(re[a] == 1 ) return;
    re[a] = 1;
    int sum = 0;
    rep(i,n){
        if(re[i] == 1){
            sum++;
        }
    }
    if(sum == n) ans++;
    for(auto x : G[a]){
        if(re[x] == 1) continue;
        dfs(G,x,n);
        re[x] = 0;
    }
}

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

    int n,m;
    cin >> n >> m;
    Graph G(n);
    rep(i,m){
        int x,y;
        cin >> x >> y;
        x--;y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(G,0,n);

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(void){
	int n, m, x;
	int flag[110] = { 0 };
	int a,i;
	int cost = 0;
	int b = 0;
	int c = 0;
	scanf("%d%d%d", &n, &m, &x);
	for (i = 0; i < m; i++){
		scanf("%d", &a);
		flag[a] = 1;
	}
	if (n / 2 < x){
		for (i = x; i < n; i++){
			cost += flag[i];
		}
	}
	else if (n / 2>x){
		for (i = x; i > 0; i--){
			cost += flag[i];
		}
	}
	else if (n / 2 == x){
		for (i = x; i < n; i++) b += flag[i];
		for (i = x; i > 0; i--) c += flag[i];
		cost = min(b, c);
	}
	printf("%d\n", cost);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    string S;
    cin>>S;
    int ans = 0;
    if(S.size()%2==0){
        int l = S.size()/2-1, r = S.size()/2;
        char tmp = S[l];
        if(S[r]==tmp){
            ans++;
            l--;
            r++;
            while(l>=0){
                if((S[l]!=tmp) | (S[r]!=tmp)) break;
                ans++;
                l--;
                r++;
            }
        }
        cout<<S.size()/2+ans<<endl;
    }
    else{
        int l = S.size()/2-1, r = S.size()/2+1;
        char tmp = S[S.size()/2];
        while(l>=0){
            if((S[l]!=tmp) | (S[r]!=tmp)) break;
            ans++;
            l--;
            r++;
        }
        cout<<S.size()/2+1+ans<<endl;
    }
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    // 1つ目の整数
    int a = sc.nextInt();
    // 2つ目の整数
    int b = sc.nextInt();

    String first = Integer.toString(a);
    String second = Integer.toString(b);
    String targetStr = first + second;

    int target = new Integer(targetStr);
    int num;
    for (int i = 1; i <= 1000; i++) {
      num = i * i;
      if (num == target) {
        System.out.println("Yes");
        return;
      }
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 21840
# -*- coding:utf-8 -*-

class Conv():
    def __init__(self, b, c):
        self.b = b
        self.c = c

def solve():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    A.sort()
    B, C = [], []
    conv = []  # conv[c] := cに変換できる枚数
    for i in range(M):
        b, c = list(map(int, input().split()))
        conv.append(Conv(b, c))
    
    sorted_conv = sorted(conv, key=lambda x: x.c, reverse=True)

    i = 0
    j = 0
    while True:
        if i == len(sorted_conv) or j == N:
            break
        
        if sorted_conv[i].b == 0:
            i += 1
            continue
        
        if sorted_conv[i].c > A[j]:
            A[j] = sorted_conv[i].c
            sorted_conv[i].b -= 1
            j += 1
            continue
        
        break

    print(sum(A))

if __name__ == "__main__":
    solve()


Measured memory_bytes: 39308
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define EPS 0.000000001 //1e-9
using pii=pair<int,int>;
const long long INF=1e18;

template <class A, class B> ostream& operator<<(ostream& os, const pair<A,B> p) {return os << "(" << p.first << "," << p.second << ")";} 

void dprint(string s) {cout << endl;}
template <class T, class... U> void dprint(string s, T t, U... u) 
{int w = s.find(','); cout << "[" << s.substr(0,w) << ": " << t << "] "; dprint(s.substr(w+1, (int)s.size()-w), u...);} 

#define DEBUG 
#ifdef DEBUG
#define dbg(X...) dprint(#X,X)
#else
#define dbg(X...) "KEEP CALM" 
#endif

const int N=1e6+5; // Don't forget to CHANGE this value ACC. TO Q.

int32_t main()
{
    IOS;
    int x; cin>>x;
    if(x>=30)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
int main(){

  int n,gap,stu[1000],result=0,i,j;

  while(1){

  result=1000000;
  scanf("%d",&n);
  if(n == 0) break;

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

  for(i = 0; i < n-1; i++){

    for(j = i+1; j < n; j++){

      gap=stu[i]-stu[j];
      if(gap < 0) gap *= -1;

      if(result > gap) result=gap;

    }

  }

  printf("%d\n",result);

  }

  return 0;

}

Measured memory_bytes: 604
using System;
using System.Linq;
using static System.Console;
using static System.Math;
class E { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split().Select(x => int.Parse(x)).ToArray();
	const long Mod = 1000000007;
	public K()
	{
		var N = F();
		var I = G();
		var p = new int[N];
		var cnt = new int[N + 1];
		for (var i = 0; i < N; i++) cnt[i + 1] = cnt[i] + ((p[i] = I[N - i - 1] - 1) < 0 ? 1 : 0);
		var fact = new long[N + 1];
		fact[0] = 1;
		for (var i = 1; i <= N; i++) fact[i] = i * fact[i - 1] % Mod;
		var M = cnt[N];
		var s = fact[M];
		var bit = new BinaryIndexedTree(N);
		var l = new int[N];
		for (var i = 0; i < N; i++)
		{
			if (p[i] < 0) continue;
			l[i] = bit.Sum(0, p[i]);
			bit.Add(p[i], 1);
		}
		var l2 = new int[N];
		for (var i = 0; i < N; i++) l2[i] = bit.Sum(0, p[i]);
		var h = 1L;
		for (var i = 3; i <= M; i++) h = h * i % Mod;
		var t = new long[N + 1];
		for (var j = 0; j < N; j++) if (p[j] >= 0) t[j + 1] = M - p[j] + l2[j];
		for (var j = 0; j < N; j++) t[j + 1] = (t[j + 1] + t[j]) % Mod;
		for (var i = 1; i < N; i++)
		{
			var c = 0L;
			if (p[i] >= 0)
			{
				c = fact[M] * l[i] % Mod;
				if (M > 0) c = (c + (p[i] - l2[i]) * fact[M - 1] % Mod * cnt[i] % Mod) % Mod;
			}
			else
			{
				c = h * cnt[i] % Mod;
				c = (c + t[i] * fact[M - 1] % Mod) % Mod;
			}
			s = (s + (c * fact[i]) % Mod) % Mod;
		}
		WriteLine(s);
	}
}
class BinaryIndexedTree
{
	public int Size;
	int[] bit;
	public BinaryIndexedTree(int size) { Size = size; bit = new int[size + 1]; }
	public void Add(int index, int value) { for (var i = index + 1; i <= Size; i += i & (-i)) bit[i] += value; }
	public int Sum(int from, int to) => Sum(to) - Sum(from);
	int Sum(int to) { var sum = 0; for (var i = to; i > 0; i -= i & (-i)) sum += bit[i]; return sum; }
}


Measured memory_bytes: 54228
#include<stdio.h>
int main(void){
   int i;
   char str[21];
   scanf("%s",str);
   for(i=0;i<21;i++){
   if(str[i]==0)
      break;
   }
   for(;i>0;i--){
   printf("%c",str[i-1]);
   }
   puts("");
   return 0;
   }

Measured memory_bytes: 524
# -*- coding:utf-8 -*-
N, A, B = map(int, input().split())

res = 0

for i in range(1, N+1):
    count = 0
    for j in range(len(str(i))):
        count += int(str(i)[j])
    if A <= count <= B:
        res += i
print(res)


Measured memory_bytes: 3060
#include<stdio.h>
int dp[10][10],a[205][205];
int main()
{
    int n,m;
    int i,j;
    scanf("%d%d",&n,&m);
    for(i=0;i<10;i++)
    for(j=0;j<10;j++)
    scanf("%d",&dp[i][j]);
    for(i=0;i<n;i++)
    for(j=0;j<m;j++)
    scanf("%d",&a[i][j]);
    int k;
    for(k=0;k<10;k++)
    for(i=0;i<10;i++)
    for(j=0;j<10;j++)
    if(dp[i][j] > dp[i][k] + dp[k][j])
    dp[i][j]  = dp[i][k] + dp[k][j];
    
    int ans = 0;
    for(i=0;i<n;i++)
    for(j=0;j<m;j++)
    if(a[i][j]>-1)
    {
        k = a[i][j];
        ans += dp[k][1];
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 384
S = input()

odd = 1
even = 0
odd_flag = True

for i in range(1, len(S)):
    if not S[i-1] == S[i]:
        if odd_flag:
            odd += 1
        else:
            even += 1
    else:
        odd_flag = not odd_flag
        if odd_flag:
            odd += 1
        else:
            even += 1

print(min(odd, even))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
//typedef pair<int,int> pii;
lli gcd(lli a,lli b)
{
    if(a%b==0) return b;
    return gcd(b,a%b);
}
int main()
{
     lli a,b,c,d;
     cin>>a>>b>>c>>d;
     lli Dc=((b/c)-(a+c-1)/c)+1; //cout<<Dc<<endl;
     lli Dd=((b/d)-(a+d-1)/d)+1;   //cout<<Dd<<endl;
     lli m=gcd(c,d);
     lli lcm=c*(d/m);
     lli Dcd=((b/lcm)-(a+lcm-1)/lcm)+1; //cout<<Dcd<<endl;
     lli ans=b-a+1-(Dc+Dd-Dcd);
     cout<<ans;

}


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

int N, T[1001], A[1001];

long long int ans1=1, ans2=1;

int main(void) {

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

	for (int i = 1; i <= N; i++) {
		long long int t = T[i], a = A[i];
		long long int fac = max((ans1 + (t - 1)) / t, (ans2 + a - 1) / a);

		ans1 = fac*t; ans2 = fac*a;

		//cout << ans1 << "  " << ans2 << endl;
	}

	long long int ans = ans1 + ans2;

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
def main():
    while True:
        h, w = map(int, input().split(" "))
        if h == 0: break
        
        initOblSq = OblSq(w, h)
        minOblSq = OblSq(149, 149)
        minw = 149
        minh = 149
        for varw in range(1, 150):
            for varh in range(1, varw):
                varsq = OblSq(varw, varh)
                if varsq >= initOblSq and varsq <= minOblSq:
                    if varsq == initOblSq and varh <= h: continue
                    if varsq == minOblSq and varh >= minh: continue
                    minOblSq = varsq
                    minw = varw
                    minh = varh
        
        print(minh, minw)

def OblSq(width, height):
    return width**2 + height**2

main()



Measured memory_bytes: 5596
n=int(input())
a=list(map(int,input().split()))

MAX=max(a)
Harf=MAX/2

cnt=10**20
ans=0
for i in range(n):
    if MAX==a[i]:
        continue
    elif abs(Harf-a[i])<cnt:
        ans=a[i]
        cnt=abs(Harf-a[i])
print(MAX,ans)

Measured memory_bytes: 62704
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    string s;
    cin >> n >> s;
    int64_t x = 0, tmax = 0;
    for(int i=0; i<n; i++){
        if(s.at(i)=='I'){
            x++;
            tmax=max(tmax,x);
        }else{
            x--;
        }
    }
    cout << tmax << endl;
}


Measured memory_bytes: 256