akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];

    string s_buff;
    int j = 0;
    int cnt[n];
    rep(i,n) cnt[i] = 0;
    int cnt_num = 1;
    int max_cnt = 0;

    sort(s.begin(), s.end());
    rep(i,n-1){
        cnt[i] = cnt_num;
        if(s[i+1] != s[i]){
            cnt_num = 1;
        }else{
            cnt_num++;
        }
    }
    cnt[n-1] = cnt_num;

    rep(i,n) max_cnt = max(max_cnt, cnt[i]);
    rep(i,n){
        if(cnt[i] == max_cnt){
            cout << s[i] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 15104
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cctype>
#include <ctime>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <string>
#include <map>
#include <iterator>
#define ll long long
#define mp make_pair

using namespace std;

const int M = 1000000007;

ll pot(ll A, ll B){
   ll R = 1;
   while (B){
		 if (B&1) R *= A;
		 R %= M;
		 A *= A; A %= M;
		 B >>= 1;
   }
   return R;
}

int main() {

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n, l, r = 0;
	string s;
	
	cin >> s;
	l = s.size();
	
	for (int i = 0; i < l/2; i++){
		if (s[i] != s[l-i-1]) r++;
	}
	
	cout << r;
	
return 0;
}



Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-

A, V = map(int,input().split())
B, W = map(int,input().split())
T = int(input())

if W >= V:
    print("NO")
    exit()

if abs(A-B)/abs(W-V) <= T:
    print("YES")
else:
    print("NO")



Measured memory_bytes: 9168
s = input()
t = input()
ans = False
#tests = s
for i in range(len(s)):
    #print(s)
    if s == t:
        ans = True
        break
    s = s[-1] + s[0 : len(s) - 1]

if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include <stdio.h>

int main()
{
  int a, b;
  int mul;
  
  scanf("%d %d", &a, &b);
  if ((a <= 0 || a > 10000) ||
     (b <= 0 || b > 10000)) {
    return -1;
  }
  
  mul = a * b;
  
  if (mul % 2 == 0) {
    puts("Even");
  } else {
    puts("Odd");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main() 
{
 	char str[20], str2[20];
 	
 	scanf("%s", str);
 	int ctr = 0;
 	for(int i = 0; str[i] != '\0'; i++)
 	{
 		if(str[i] == '0')
		{
			str2[ctr] = '0';
			ctr++;
		} else if(str[i] == '1')
		{
			str2[ctr] = '1';
			ctr++;
		} else if(ctr != 0)
		{
			if(str[i] == 'B')
			{
				str2[ctr-1] = '\0';
				ctr-=2;
			}
			ctr++;
		}
	}
	str2[ctr] = '\0'; //supaya g ada simbol aneh
	printf("%s", str2);
	return 0;
}

Measured memory_bytes: 1696
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int a = sc.nextInt();
    
    if(n%500 <= a) {
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 25044
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
}
const int m=2000000;
 vi arr(m);
 int dp[m];
  int memo(int in,int k)
  {
      if(in<1)
      return 9999999999999;
      if(in==1)
      return dp[in]=0;
      if(in==2)
      return dp[in]=abs(arr[1]-arr[2]);
      
      if(dp[in]!=-1)
      return dp[in];
      int ans=9999999999999;
      for(int i=1;i<=k and in-i>=1;i++)
      {
          ans=min(ans,abs(arr[in]-arr[in-i])+memo(in-i,k));
      }
      return dp[in]=ans;
  }
 
int32_t main()
{
    c_p_c();
    //memset(dp,-1,sizeof(dp));
   int n,k;
   cin>>n>>k;
     
   for(int i=0;i<m;i++)
   {
       dp[i]=-1;
   }
   for(int i=1;i<=n;i++)
   {
       cin>>arr[i];
   }
   int x=memo(n,k);
   cout<<dp[n];
     
    return 0;
}

Measured memory_bytes: 39296
a,b,c,x,y = map(int,input().split())
ans = 10**7
if x >= y :
    if a+b > 2*c:
        ans =2*y*c + (x-y)*min(a,2*c)
       
    else:
        ans = x*a+y*b
else:
    if a+b>2*c:
        ans = 2*x*c+(y-x)*min(b,2*c)
    else:
        ans = x*a+y*b
print(ans)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n 
#define pl(n) cout<<n<<" "
const int Nx=1e5+2;
const int inf=(int)(1e9+10LL);
void solve()
{
 int a,b,c,k;
 sl(a);sl(b);sl(c);sl(k);
 int sum=0;
 	int val=min(k,a);
 	sum+=val;
 	k=k-val;
 	val=min(k,b);
 	k=k-val;
 	val=min(k,c);
 	sum+=(-val);
 	cout<<sum<<endl;

}

signed main(){
  int test=1;
// sl(test);
 while(test--){
 	solve();
 }
 
}

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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c  >> d;
    if((a + b) > (c + d)){
        cout << "Left" << endl;
    }else if((a + b) < (c + d)){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 256
while n = gets.to_i do
  break if n == 0
  s = Array.new
  d = - Float::INFINITY
  n.times do |i|
    s[i] = gets.to_i
  end
  n.times do |i|
    sum = 0
    (i..n).each do |j|
      sum = sum + s[j].to_i
      d = [d, sum].max
    end
  end
  puts d
end

Measured memory_bytes: 6112
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		int[] isPrime=new int[100002];

		for(int i=1; i<=100001; i+=2) {
			if(isPrime(i) && isPrime((i+1)/2)) {
				isPrime[i]=1;
			}
		}

		for(int i=1; i<=100001; i++) {
			isPrime[i]=isPrime[i-1]+isPrime[i];
		}
		Scanner sc=new Scanner(System.in);

		int Q=sc.nextInt();

		for(int i=0; i<Q; i++) {
			int s=sc.nextInt();
			int g=sc.nextInt();
			System.out.println(isPrime[g]-isPrime[s-1]);
		}
	}

	public static boolean isPrime(int a) {

		if(a<4) {

			if(a==2 || a==3) {
				return true;
			}
			else {
				return false;
			}
		}
		else {
			for(int j=2; j*j<=a; j++) {
				if(a%j==0) {
					return false;
				}
				if(a%j!=0 && (j+1)*(j+1)>a) {
					return true;
				}
		}
		return true;
		}
	}
}

Measured memory_bytes: 64216
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

class Node{
public:
	int key;
	Node* right;
	Node* left;
	Node* parent;
};
Node* root;
Node* NIL;
void insert(int k){
	Node* y = NIL; // x ??????
	Node* x = root;
	Node* z;
	z = (Node*)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	while (x != NIL){
		y = x; // ???????¨????
		if (z->key < x->key) x = x->left; // ?????????????§????
		else x = x->right; // ?????????????§????
	}
	z->parent = y;
	if (y == NIL) root = z; // T ???????????´???
	else {
		if (z->key < y->key) y->left = z; // z ??? y ?????????????????????
		else y->right = z; // z ??? y ?????????????????????
	}
}
bool find(Node* z, int k){
	if (z == NIL) return false;
	if (z->key == k) return true;
	else if (z->key < k) return find(z->right, k);
	else if (z->key > k) return find(z->left, k);
	return false;
}
Node* findNode(Node* z, int k){
	if (z == NIL) return NIL;
	if (z->key == k) return z;
	else if (z->key < k) return findNode(z->right, k);
	else if (z->key > k) return findNode(z->left, k);
	return NIL;
}
void del(Node* z, int k){
	if (z->right == NIL && z->left == NIL){
		Node* P = z->parent;
		if (P->left == z) P->left = NIL; else if (P->right == z) P->right = NIL;
		z = NIL;  return;
	}
	else if (z->right != NIL && z->left != NIL){
		Node* x = z->right;
		while (x->left != NIL) x = x->left;
		Node* P = x->parent;
		if (P->left == x) P->left = NIL; else if (P->right == x) P->right = NIL;
		z->key = x->key;
	}
	else{
		Node* P = z->parent;
		Node* ch;
		if (z->right != NIL) ch = z->right; else ch = z->left;
		ch->parent = P;
		if (P->left == z) P->left = ch; else P->right = ch;
	}

}
void preorder(Node* z){
	if (z == NIL) return;
	cout << ' ' << z->key ;
	if (z->left != NIL) preorder(z->left);
	if (z->right != NIL) preorder(z->right);
}
void inorder(Node* z){
	if (z == NIL) return;
	if (z->left != NIL) inorder(z->left);
	cout << ' ' << z->key;
	if (z->right != NIL) inorder(z->right);
}
int main(){
	root = NIL;
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i){
		char str[20]; scanf("%s", &str);
		if (strcmp(str, "insert") == 0){
			int tmp; scanf("%d", &tmp);
			insert(tmp);
		}
		else if (strcmp(str, "find") == 0){
			int tmp; scanf("%d", &tmp);
			if (find(root, tmp)) cout << "yes\n";
			else cout << "no\n";
		}
		else if (strcmp(str, "delete") == 0){
			int tmp; scanf("%d", &tmp);
			del(findNode(root,tmp),tmp);
		}
		else{
			inorder(root); cout << '\n';
			preorder(root); cout << '\n';
		}
	}

}

Measured memory_bytes: 19960
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	ll L, R; cin >> L >> R;

	if (R - L >= 2019) cout << 0 << endl;
	else {
		R = R % 2019;
		L = L % 2019;
		if (R < L) cout << 0 << endl; // 2019の倍数をまたぐ
		else {
			ll ans = LLINF;
			for (ll i = L; i <= R; i++) {
				for (ll j = i + 1; j <= R; j++) {
					ans = min(ans, (i*j) % 2019);
				}
			}
			cout << ans << endl;
		}
	}


	return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  vector<int> p;
  p.resize(n);
  for(int i=0;i<n;i++) cin >> p.at(i);
  sort(p.begin(), p.end());

  long ans=0L;
  for(int i=0;i<k;i++) ans+=p.at(i);

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

Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    string s; cin>>s;
    int mod = 2019;
    vector<int> cnt(2019);
    int power_of_ten = 1;
    int suff = 0;
    cnt[suff]++;
    ll ans = 0;
    for(int i = s.size()-1; i>=0; i--){
      int d = s[i]-'0';
      suff = (suff + d*power_of_ten%mod)%mod;
      ans+= cnt[suff];
      cnt[suff]++;
      power_of_ten = 10*power_of_ten%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3740
x, y, a, b, c = map(int, input().split())
La = sorted(list(map(int, input().split())), reverse=True)
Lb = sorted(list(map(int, input().split())), reverse=True)
Lc = sorted(list(map(int, input().split())), reverse=True)

L = La[:x]
L.extend(Lb[:y])
L.sort(reverse=False)
min = min(c, len(L))

for i in range(min):
    if L[i] < Lc[i]:
        L[i] = Lc[i]

print(sum(L))

Measured memory_bytes: 23200
#include <bits/stdc++.h>
using namespace std;
long long n,m,total;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    if (n%2==1){
        cout<<0;
        return 0;
    }
    n/=10;
    total+=n;
    for (long long i=5;n/i>=1;i*=5){
        total+=n/i;
    }
    cout<<total;
}

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

int main()
{
    int n;
    cin>>n;
    string s;
    map<string,int>mp;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
    mp.clear();
    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#define MOD 1000000007
#define modml(a,b) ((long)(1ll * (a) * (b) % MOD))
#define modadd(a,b) (((a)+(b)) % MOD)

static inline long modpow(long num,long ind){
    unsigned long cnt = ind;
    long res = 1;
    while(cnt){
        if(cnt & 1ul)res = modml(res,num);
        num = modml(num,num);
        cnt >>= 1;
    }
    return res;
}

long fact[2001];
long fcinv[2001];

static inline long modinv(long num){
    return modpow(num,MOD-2);
}

static inline long modnck(long n,long k){
    return modml(fact[n],modinv(modml(fact[k],fact[n-k])));
}

int main(void){
    register int i;
    fact[0] = 1;
    for(i = 1;i <= 2000;i++)fact[i] = modml(fact[i-1],i);
    for(i = 1;i <= 2000;i++)fcinv[i] = modinv(fact[i]);

    int n,k,r;
    scanf("%d %d",&n,&k);
    r = n - k;
    for(i = 1;i <= k;i++){
        if(k-1 < i-1 || r + 1 < i){
            puts("0");
            continue;
        }
        printf("%ld\n",modml(modnck(k-1,i-1),modnck(r+1,i)));
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <numeric>

using namespace std;
typedef long long ll;

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

    int i_ans = static_cast<int>(N / 1.08);
    double d_ans = N / 1.08;

    if (static_cast<int>(i_ans * 1.08) == N) cout << i_ans << endl;
    else if (static_cast<int>((i_ans+1) * 1.08) == N) cout << i_ans+1 << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, a[100009], ans;
multiset<int> st;
int main()
{
    IO
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        auto it=st.lower_bound(x);
        if(it==st.begin())
            ans++, st.insert(x);
        else
        {
            it--;
            st.erase(it);
            st.insert(x);
        }
    }

    cout<<ans;
}


Measured memory_bytes: 4992
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int mod = 1000000007;
		long p = 1;
		for (int i = 2; i <= n; i++) {
			p = p * i % mod;
		}

		long[] q = new long[n];
		q[0] = 1;
		for (int i = 1; i < n; i++) {
			q[i] = (q[i - 1] + modinv(i + 1, mod)) % mod;
		}

		long ans = 0;
		for (int i = 0; i < n; i++) {
			long val = q[i] + q[n - i - 1] - 1;
			val *= a[i];
			val %= mod;
			val *= p;
			val %= mod;
			ans += val;
			ans %= mod;
		}
		System.out.println(ans);
	}

	static long modinv(long a, int m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}


Measured memory_bytes: 46704
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sum = 0
for i in range(n):
    sum += b[a[i]-1]
    if i != 0:
        if a[i]-1 == a[i-1]:
            sum += c[a[i-1]-1]
            
print(sum)

Measured memory_bytes: 3064
def d_grid_components(H=100, W=100):
    A, B = [int(i) for i in input().split()]
    # グリッドの縦と横は入力に関わらず定数 (条件の最大値) とする
    # 100x100 グリッドの上半分を黒で，下半分を白で塗りつぶす
    grid = [['#'] * W for _ in range(50)] + [['.'] * W for _ in range(50)]

    def fill(start, end, num, symbol):
        """start 行から end-1 行まで，num 個の symbol を 1 マスおきに置いていく"""
        for row in range(start, end, 2):
            for col in range(1, W, 2):
                if num == 0:
                    return
                grid[row][col] = symbol
                num -= 1
        return None

    fill(1, 50, A - 1, '.')  # 黒ゾーンに 1 つおきに 1x1 白マスを A-1 個置く
    fill(51, 100, B - 1, '#')  # 白ゾーンに 1 つおきに 1x1 黒マスを B-1 個置く
    return '100 100\n' + '\n'.join([''.join(row) for row in grid])

print(d_grid_components())

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    cout << (e - a <= k ? "Yay!" : ":(") << endl;
    return 0;
}

Measured memory_bytes: 256
import math


def number2bit(n):
    return int(math.pow(2, n - 1))


def count_bit(n):
    return bin(n)[2:].count('1')


N, M = map(int, input().split(' '))
lights = [tuple(map(int, input().split(' ')))[1:] for _ in range(M)]
light_bits = [sum(map(number2bit, light)) for light in lights]
mods = tuple(map(int, input().split(' ')))

count = 0
for i in range(int('1' + '0' * N, base=2)):
    for light_bit, mod in zip(light_bits, mods):
        if count_bit(i & light_bit) % 2 != mod:
            break
    else:
        count += 1

print(count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define N 100010
#define M 1010

using namespace std;
ll a; double b;

int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}


int main() {
	int a, b;
	cin >> a >> b;
	a = a * b;
	cout << (ll) a;
}

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

int main(){
  int n; cin >> n;
  vector<int> cnt(1e05+5);
  rep(i, n){
    int a; cin >> a;
    cnt[a] ++;
  }
  ll sum = 0;
  rep(i, 1e05+5){
    sum += cnt[i] * i;
  }  
  int q; cin >> q;
  rep(i, q){
    int b, c; cin >> b >> c;
    sum += (c-b)*cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main() 
{
  int x, a, b; cin >> x >> a >> b;
  if(abs(x-a) < abs(x-b)){
    cout << "A" << endl;
  }
  else cout << "B" << endl;
  system("pause");
}

Measured memory_bytes: 504
#include<iostream>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
int keta(int i) {
	int ret=0;
	while (i > 0) {
		i /= 10;
		ret++;
	}
	return ret;

}
void ita(int y, vector<int> *x) {
	int i = x->size()-1;
	while (y > 0) {
		x->at(i--) = y % 10;
		y /= 10;
	}
}
int main() {
	int a, b;
	cin >> a >> b;
	int count = 0;
	for (int i = a; i <= b; i++) {
		vector<int> x(keta(i));
		ita(i, &x);
		int l = 0, r = x.size() - 1;
		if (x.at(0) != 0) {
			while (x.at(l++) == x.at(r--)) {
				if (l > r) {
					count++;
					break;
				}
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(){
    while(true){
        int n,m;
        cin >> n;
        if(n == 0){break;}
        vector<char> mae(n);
        vector<char> ato(n);
        for(int i=0 ; i < n ; ++i){
            cin >> mae.at(i) >> ato.at(i);
        }
        cin >> m;
        vector<char> c(m);
        for(int i = 0; i< m ; ++i){
            cin >>c.at(i);
            for(int j = 0; j < n ; ++j){
                if( c.at(i) == mae.at(j) ){
                    c.at(i) = ato.at(j);
                    break;
                }
            }
            cout<<c.at(i);
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3108
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <string.h>

using namespace std;
const int maxn = 4005;
const int inf = 1<<29;

char s1[maxn],s2[maxn];
bool a[maxn],b[maxn];
int n,ans=inf,lsl[maxn],rsl[maxn],ord[maxn];

bool comp(int x,int y) {
	return lsl[x]>lsl[y];
}
int main()
{
	#ifdef Amberframe
		freopen("agc019d.in","r",stdin);
		freopen("agc019d.out","w",stdout);
	#endif
	scanf("%s %s",s1+1,s2+1);n=strlen(s1+1);
	for (int i=1;i<=n;i++) a[i]=s1[i]-'0',a[n+i]=a[i];
	for (int i=1;i<=n;i++) b[i]=s2[i]-'0',b[n+i]=b[i];
	
	bool tag=1,all0=0;
	for (int i=1;i<=n;i++) tag&=a[i]==b[i];
	if (tag) {puts("0");return 0;}
	for (int i=1;i<=n;i++) all0|=b[i];
	if (!all0) {puts("-1");return 0;}
	
	if (!b[1]) {
		int t=n;while (!b[t]) --t;
		lsl[1]=n-t+1;
	}
	if (!b[n]) {
		int t=1;while (!b[t]) ++t;
		rsl[n]=t;
	}
	for (int i=2;i<=n;i++) lsl[i]=(b[i]?0:lsl[i-1]+1);
	for (int i=n-1;i>=1;i--) rsl[i]=(b[i]?0:rsl[i+1]+1);
	for (int i=1;i<=n;i++) ord[i]=i;
	sort(ord+1,ord+n+1,comp);
	
	for (int sh=0;sh<n;sh++)
	{
		int res=0,mins=min(sh,n-sh)+n,maxrs=0;
		for (int x,i=1;i<=n;i++)
		if (a[x=ord[i]]!=b[x+sh]) {
			res++;
			if (a[x]) {
				mins=min((max(maxrs-sh,0)<<1)+sh+(lsl[x]<<1),mins);
				mins=min((max(lsl[x]-n+sh,0)<<1)+n-sh+(maxrs<<1),mins);
				maxrs=max(maxrs,rsl[x]);
			}
		}
		mins=min(sh+(max(maxrs-sh,0)<<1),mins);
		mins=min(n-sh+(maxrs<<1),mins);
		ans=min(res+mins,ans);
	}
	
	printf("%d",ans);
	return 0;
}

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

int main()
{
  int N, M, X, A, U=0, D=0;
  cin >> N >> M >> X;
  rep(i, M){
    cin >> A;
    if(A>X) U++;
    else D++;
  }
  if(U>=D) cout << D << endl;
  else cout << U << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;



int main() {


    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a==0)fin(1);
    else if(b==0)fin(2);
    else if(c==0)fin(3);
    else if(d==0)fin(4);
    else if(e==0)fin(5);
    
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100009];
int res[100009];
/*lets try to understand how to write recursive eqn for the current problem
 mincost(i,n)={min(a[i+1]-a[i]+mincost(i+1,n),a[i+2]-a[i]+mincost(i+2,n)) if i<n
                  ,0 if i>=n}         
 */
int mincost(int i)
{
   if(res[i]>=0)
	   return res[i];
  		if(i>=n)
		 return 0;
	
	
  if(i<n-1)
  res[i]=min(abs(a[i+1]-a[i])+mincost(i+1),abs(a[i+2]-a[i])+mincost(i+2));
  else
    res[i]=abs(a[i+1]-a[i])+mincost(i+1);
 return res[i]; 
}
int main()
{  
for(int i=1;i<=100000;i++)
    res[i]=-1;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	 cout<<mincost(1);
}


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

#define X first
#define Y second
#define pb push_back

using namespace std;


const int maxn = 2e5;
vector < pair <int, int> > g[maxn];

const long long INF = 1e18;
const long long mod = 1e9 + 7;

void djkstra(int s, vector <long long> &d, vector <long long> &c)
{
    d[s] = 0;
    c[s] = 1;
    int n = d.size();
    set < pair <long long, int> > Q;
    for (int i = 0; i < n; i++)
        Q.insert({d[i], i});

    while (!Q.empty())
    {
        pair <long long, int> t = *Q.begin();
        Q.erase(Q.begin());
        int v = t.Y;
        for (auto e : g[v])
        {
            if (d[e.X] < d[v] + e.Y) continue;
            if (d[e.X] == d[v] + e.Y) {c[e.X] += c[v]; c[e.X] %= mod; continue;}
            Q.erase({d[e.X], e.X});
            d[e.X] = d[v] + e.Y;
            c[e.X] = c[v];
            Q.insert({d[e.X], e.X});
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    int n, m, s, t;
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; i++)
    {
        int u, v, cost;
        cin >> u >> v >> cost;
        u--, v--;
        g[u].pb({v, cost});
        g[v].pb({u, cost});
    }

    s--, t--;

    vector <long long> d1(n, INF), d2(n, INF), c1(n, 0), c2(n, 0);
    djkstra(s, d1, c1);
    djkstra(t, d2, c2);

    long long all = (c1[t] * c1[t]) % mod;
    for (int i = 0; i < n; i++)
    {
        if (d1[i] == d2[i] && d1[i] == d1[t] / 2)
        {
            all -= (((c1[i]*c2[i])%mod)*((c1[i]*c2[i]) % mod))%mod;
            all += mod;
            all %= mod;
        }
        for (auto e : g[i])
        {
                if (d1[i] < d1[t] / 2 && d2[e.X] < d1[t] / 2 && d1[i] + e.Y + d2[e.X] == d1[t])
                {
                    all -= (((c1[i]*c2[e.X])%mod)*(c1[i]*c2[e.X]%mod)) % mod;
                    all += mod;
                    all %= mod;
                }
        }
    }
    cout  << all << '\n';
    return 0;
}


Measured memory_bytes: 20352
#include <iostream>
#include <string>

using namespace std;

void resolve()
{
    string S;
    cin >> S;

    string ans = "No";
    if (S.size() % 2 == 0 && S.size() != 0) {
        int index = 0;
        while (index < S.size()) {
            if (S[index] != 'h') break;
            index++;
            if (S[index] != 'i') break;
            index++;
        }
        if (index == S.size()) ans = "Yes";
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, ans = 0;
    cin >> N;
    vector<int64_t> A(3 * N);
    for (int i = 0; i < 3 * N; i++) {
        cin >> A.at(i);
    }
    sort(rALL(A));
    for (int i = 0; i < N; i++) {
        ans += A.at(1 + 2 * i);
    }
    cout << ans << endl;

}


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

int main() {
    int N;
    cin >> N;
    vector<long> L(N);
    REP(i, N){
        cin >> L[i];
    }

    int count = 0;
    REP(i, N - 2){
        for(int j = i + 1; j < N - 1; j++){
            for(int k = j + 1; k < N; k++){
                if(L[i]+L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j]){
                    if(L[i] != L[j] && L[j] != L[k] && L[i] != L[k])
                    count++;
                }
            }
        }
    }
    cout << count  <<"\n";
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
const int mod = 1e9 + 7;
using namespace std;
typedef long long ll;


int main()
{
    int x;
    cin >> x;
    int cnt = 1;
    int tmp = 0;
    int ans = 0;
    while(x > tmp){
        tmp += cnt;
        ans++;
        cnt++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//13-Card game for two
#include<bits/stdc++.h>
using namespace std;

int main(){
  int a;
  cin>>a;
  vector<int> ans(a);
  for(int i=0;i<a;i++){
    cin>>ans.at(i);
  }
  sort(ans.begin(),ans.end());
  reverse(ans.begin(),ans.end());
  int x=0;
  for(int i=0; i<a; i++){
    if(i%2==0){
      x+=ans.at(i);
    }
    else{
      x-=ans.at(i);
    }
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)

Measured memory_bytes: 3060
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

n = int(input())
info = [list(map(int, input().split())) for _ in range(n)]
ans = [[i + 1, -1, -1] for i in range(n)]
check = [0 for _ in range(n)]
time = 1


def dfs(num):
    check[num] = 1
    global time
    if ans[num][1] == -1:
        ans[num][1] = time
        time += 1
    for i in info[num][2:]:
        if check[i - 1] == 0:
            dfs(i - 1)
    if ans[num][2] == -1:
        ans[num][2] = time
        time += 1


for i in range(n):
    if check[i] == 0:
        dfs(i)

for i in ans:
    i = list(map(str, i))
    print(" ".join(i))



Measured memory_bytes: 9012
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
 
class DandA {
    static void Main(string[] args) {
        int[] nkq = ReadLineIntArray();
        int[] rtn = new int[nkq[0]];
        for (int i = 0;i < nkq[2]; i++) {
            rtn[ReadLineInt() - 1]++;
        }
        for (int i = 0;i < nkq[0]; i++) {
            if (rtn[i] > (nkq[2] - nkq[1])) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
 
    static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static string[] strAry = new string[] {"L", "R", "U", "D"}; 
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private long ReadLineLong() {return long.Parse(Console.ReadLine());}
    static private double ReadLineDouble() {return double.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private double[] ReadLineDoubleArray() {return Console.ReadLine().Trim().Split().Select(a => double.Parse(a)).ToArray();}
    static private decimal[] ReadLineDecimalArray() {return Console.ReadLine().Trim().Split().Select(a => decimal.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
 
    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
  
    static private string IntToNString(int x, int n) {
        var nstring = "";
        var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
        int r = 1;
        int q = x;
        while (q > 0) {
            r = q % n;
            nstring += numbers[r];
            q = q / n;
        }
        return string.Join("",nstring.Reverse());
     }
}

Measured memory_bytes: 17888
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct point{
  double x;
  double y;
  struct point *next;
}Point;

Point *create(double x, double y) {
  Point *p = (Point*)malloc(sizeof(Point));
  p->x = x;
  p->y = y;
  p->next = NULL;
  return p;
}

void create_next(double x, double y, Point *p0) {
  Point *p = create(x,y);
  p->next = p0->next;
  p0->next = p;
}

void rotation(Point *r,double seta) {
  double temp_x,temp_y;
  temp_x = r->x;temp_y = r->y;
  r->x = cos(seta)*temp_x-sin(seta)*temp_y;
  r->y = sin(seta)*temp_x+cos(seta)*temp_y;
}

void koch_curve(Point *begin) {
  Point *p1,*p2;
  p1 = begin;
  while(p1->next != NULL) {
    p2 = p1->next;
    Point *r = create((p2->x-p1->x)/3,(p2->y-p1->y)/3);
    create_next(p1->x+r->x,p1->y+r->y,p1);
    create_next(p1->next->x+r->x,p1->next->y+r->y,p1->next);
    rotation(r,M_PI/3);
    create_next(p1->next->x+r->x,p1->next->y+r->y,p1->next);
    p1 = p2;
  }
}

int main()
{
  int i,n;
  Point *begin,*p;
  begin = create(0,0);
  create_next(100,0,begin);
  scanf("%d", &n);

  for (i = 0; i < n; i++) {
     koch_curve(begin); 
  }
  
  p = begin;
  while(p != NULL) {
    printf("%lf %lf\n", p->x, p->y);
    p = p->next;
  }
  
  return 0;
}

Measured memory_bytes: 804
import math

N, D = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for _ in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        yz = [abs((y - z)**2) for y, z in zip(X[i], X[j])]
        v = math.sqrt(sum(yz))
        if v == int(v):
            ans += 1
            
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int md=924844033;
bool vis[4005][4005];
int n,k,cc,t[4005],f[4005][4005][2],g[4005],fac[4005];
int main()
{
	scanf("%d%d",&n,&k);
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%md;
	for(int i=1;i<=n;i++)for(int j=0;j<2;j++)if(!vis[i][j])
	{
		for(int x=i,y=j;x<=n;x+=k,y^=1,cc++)vis[x][y]=1;
		t[cc]=1;
	}
	f[1][0][0]=1;
	for(int i=1;i<=cc;i++)for(int j=0;j<=n;j++)
	{
		f[i+1][j][0]=(f[i][j][0]+f[i][j][1])%md;
		if(!t[i])f[i+1][j+1][1]=f[i][j][0];
	}
	for(int i=0;i<=n;i++)g[i]=(f[cc][i][0]+f[cc][i][1])%md;
	int ans=fac[n];
	for(int i=1,j=-1;i<=n;i++,j=-j)ans=((long long)ans+md+1ll*j*fac[n-i]%md*g[i]%md)%md;
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

int main(void) {
    long h;
    cin >> h;

    vector<long> dp(100);
    dp[0] = 1;
    for(int i=1; i<70; i++)
        dp[i] = 1 + 2*dp[i-1];

    int i=0;
    for(i=0; 1l<<i <= h; i++);
    cout << dp[i-1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;

signed main(){
    int N; cin >> N;
    vector<int> a(N), num(N + 1, 0);
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 0; i < N; i++) num[i + 1] = num[i] + a[i];
    map<int, int> MAP;
    for(int i = 0; i <= N; i++) MAP[num[i]]++;
    int ans = 0;
    for(auto it : MAP){
        ans += (it.second - 1)*it.second/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
fun main(args: Array<String>) {
    management()
}

private fun management() {
    readLine()?.toInt()?.let { employeeCount ->
        val cnt = IntArray(employeeCount)
        readLine()?.split(" ")?.map { it.toInt() }?.let {
            for (i in it) {
                cnt[i-1]++
            }
        }
        cnt.forEach {
            println(it)
        }
    }
}

Measured memory_bytes: 69772
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
int main(){
    int k,x;
    cin>>k>>x;
    if(k*500>=x) cout<<"Yes";
    else cout<<"No";
}

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

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int a,b;
	cin>>a>>b;
	if(a+1>=b*2)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
table = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}

try:
    while True:
        a = [table[c] for c in input()] + [0]
        result = 0
        for n1, n2 in zip(a, a[1:]):
            result += n1 if n1 >= n2 else -n1

        print(result)

except EOFError:
    exit()


Measured memory_bytes: 5564
from math import factorial

def lexicographic_index(p):
    result = 0
    for j in range(len(p)):
        k = sum(1 for i in p[j + 1:] if i < p[j])
        result += k * factorial(len(p) - j - 1)
    return result

n = int(input())
p1 = "".join(input().split(" "))
p2 = "".join(input().split(" "))

print(abs(lexicographic_index(p1)- lexicographic_index(p2)))

Measured memory_bytes: 38256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author @Got
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    AInfiniteCoins solver = new AInfiniteCoins();
    solver.solve(1, in, out);
    out.close();
  }

  static class AInfiniteCoins {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      int n = in.readInt() % 500, a = in.readInt();

      out.printLine(a >= n ? "Yes" : "No");
    }
  }

  static class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public int readInt() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);
    }
  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void printLine(Object... objects) {
      print(objects);
      writer.println();
    }

    public void close() {
      writer.close();
    }
  }
}


Measured memory_bytes: 20948
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 1000005;
int q[MAXN],front=1,back;
char a[MAXN],b[MAXN];
int n,ans,top;
int main()
{
	scanf("%d",&n);
	scanf("%s",a+1);
	scanf("%s",b+1);
	for(int i=1;i<=n;++i)
		if(a[i]!=b[i]){ans=1;break;}
	if(!ans){
		puts("0");
		return 0;
	}
	int p2=n,p1=n;
	while(p2>0){
		int r=p2;
		while(p2 && b[p2-1]==b[p2])--p2;
		while(p1 && (a[p1]!=b[p2] || p1 > p2))--p1;
		if(!p1 && p2){
			puts("-1");
			return 0;
		}
		while(front<=back && r<q[front]-(back-front))++front;
		q[++back]=p1;
		--p2;
		ans=max(ans,back-front+1);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6144
#include<iostream>

using namespace std;

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

    if (a < b && b < c) {
        std::cout << "Yes" <<std::endl;
        return 0;
    }
    std::cout << "No" <<std::endl;
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>

#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int main() {

	int n;
	vector<int> a;

	cin >> n;
	a.resize(n);

	for (int i = 0; i < n; i++) {
		cin >> a[n-i-1];
	}

	for (int i = 0; i < n; i++) {
		if (i != n - 1) {
			cout << a[i] << " ";
		}
		else {
			cout << a[i];
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
#include <bitset>
#include <string.h>
#include <cmath>
#include <algorithm>
#define N 1000015
#define P pair<int,int>
#define ll long long
#define mk(a, b) make_pair(a, b)
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
bool vis[10];
int dis[10];
int g[10][10];
int inf = 0x3f3f3f3f;
int n, sum;
void Dijkstra(int x) {
	mem(vis, false);
	mem(dis, inf);
	dis[x] = 0;
	// dis[1] = inf;
	for (int i = 0; i <= sum; ++i) {
		int MIN = inf, u = -1;
		for (int j = 0; j <= sum; ++j) {
			if (vis[j])	continue;
			if (dis[j] < MIN) {
				MIN = dis[j];
				u = j;
			}
		}
		if (u == -1)	return;
		vis[u] = true;
		for (int j = 0; j <= sum; ++j) {
			if (vis[j])	continue;
			if (dis[j] > g[u][j] + MIN) {
				dis[j] = g[u][j] + MIN;
			}
		}
	}
}

int main(){

	ios::sync_with_stdio(false);
	while (cin >> n, n) {
		int s, e, c;
		mem(g, inf);
		sum = -1;
		for (int i = 0; i < n; ++i) {
			cin >> s >> e >> c;
			sum = max(s, sum);
			sum = max(e, sum);
			g[s][e] = g[e][s] = min(g[s][e], c);
		}
		int ans_n, ans_v = inf;
		for (int i = 0; i <= sum; ++i) {
			Dijkstra(i);
			int sum_temp = 0;
			for (int j = 0; j <= sum; ++j) {
				if (dis[j] == inf) {
					sum_temp = inf;
					break;
				}
				sum_temp += dis[j];
			}
			if (sum_temp < ans_v) {
				ans_v = sum_temp;
				ans_n = i;
			}
		}
		cout << ans_n << " " << ans_v << endl;
	}

	return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y, int z){
  if (x > y){
    int tmp = y;
  	y = x;
    x = tmp;
  }
  if (z < y){
    int tmp = z;
    z = y;
    y = tmp;
  }
  if (y < x){
    int tmp = y;
  	y = x;
    x = tmp;
  }
  int r = y % x;
  while (r > 0){
    y = x;
    x = r;
    r = y % x;
  }
  r = z % x;
  while (r > 0){
    z = x;
    x = r;
    r = z % x;
  }
  return x;
}
    
  

int main(){
  int k;
  cin >> k;
  int sum = 0;
  for (int i = 1; i <= k; i++){
	for (int j = 1; j <= k ; j++){
      for (int l = 1; l <= k; l++){
        sum += gcd(i,j,l);
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define MAXN 200010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e18 + 7;


int main (){
    ios_base::sync_with_stdio(false);
    string s;
    int r = 0, p = 0, score = 0;

    cin >> s;
    int n = s.size();

    for (int i=0; i<n; i++){
        if (p < r){
            score++;
            p++;
        }
        else {
            r++;
        }
        if (s[i] ==  'p') score--;
        
    }

    cout << score << endl;

    return 0;
}

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

using namespace std;

int main() {
  char prev_ch, ch;
  int ret = 0;
  std::cin >> prev_ch;
  while (std::cin >> ch) {
    ret += (prev_ch != ch);
    prev_ch = ch;
  }
  std::cout << ret << std::endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while(sc.hasNext()) {
			String[] text = sc.nextLine().split(" ");
			int[] cards = new int[text.length];
			boolean one = false; //1????????????
			int sum = 0; //????¨??????°
			boolean flag = false;

			for(int $ = 0; $ < text.length; $++) {
				cards[$] = Integer.parseInt(text[$]);
				if(cards[0] == 0) {
					flag = true;
					break;
				}
				if(cards[$] == 1) {
					one = true;
					sum++;
				} else if(cards[$] >= 10 && cards[$] <=13) {
					sum += 10;
				} else {
					sum += cards[$];
				}
			}

			if(flag) {
				break;
			}

			if(one) {
				if(sum + 10 <= 21) {
					sum += 10;
				}
			}

			if(sum > 21) {
				sum = 0;
			}

			System.out.println(sum);

		}

	}

}

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

int main() {
    string S;
    cin >> S;
    
    int num = stoi(S);
    
    if(((num%100>0)&&(num%100<13)) && ((num>99)&&(num<1300))) cout << "AMBIGUOUS" << endl;
    else if(((num%100>0)&&(num%100<13)) && ((num<100)||(num>1299))) cout<<"YYMM"<<endl;
    else if(((num%100==0)||(num%100>12)) && ((num>99)&&(num<1300))) cout<<"MMYY"<<endl;
    else if(((num%100==0)||(num%100>12)) && ((num<100)||(num>1299)))cout<<"NA"<<endl;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    // aの倍数の総和%b==cにできるか判定
    //b回以上繰り返しても意味はない
    for ( int i=0; i<b; i++){
        if(a * (i+1) % b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
    
}

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

int main(){
	int n,ans=0;
	string s;
	cin>>n>>s;
	for(int i=1;i<n;i++){
		if(s[i]!=s[i-1]){
			ans++;
		}
	}
	cout<<ans+1<<endl;
	return 0;
}

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

int N;
std::vector<int> a;
int main() {
    std::cin >> N;
    a.resize(N);
    for(int i=0; i<N; ++i) {
        std::cin >> a[i];
    }
    std::sort(a.begin(), a.end());

    std::cout << std::abs(a[0] - a[N-1]) << std::endl;
}

Measured memory_bytes: 256