akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto n = load<int>();
	auto xs = loadMany<int>(n);
	auto bad = 0;
	for (auto i=0; i<n; ++i)
		if (xs[i]-1 != i)
			++bad;
	cout << (bad == 0 or bad == 2 ? "YES\n" : "NO\n");
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char class_name[32];
    int am, pm;
    int i;
    
    for (i = 0; i < 9; i++){
        scanf("%s%d%d", class_name, &am, &pm);
        printf("%s %d %d\n", class_name, am + pm, am * 200 + pm *300);
    }
    
    return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
main()
{
    long long a=0,b,i,j,k,l;
    cin>>l;

    for(i=100;i<l;)
    {
       i+=((1*i)/100);
       //cout<<i<<endl;
       a++;
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  ll n;
  cin >> n;
  cout << (n - 1) / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint N;
	cin >> N;
	if (N < 1200) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ARC" << endl;
	}
}

Measured memory_bytes: 3556
# coding: utf-8
# Your code here!
K = int(input())
A=[int(i) for i in input().split()]
L = 2
R = 2
flag = 0

#(a + (b - 1)) / b
for i in range(K):
    LL = A[K-1-i]*((L+A[K-1-i]-1)//A[K-1-i])
    RR = A[K-1-i]*(R//A[K-1-i])
    if LL > R:
        flag = -1
        L = 2
        R = 1
    else:
        L = LL
        R = RR+A[K-1-i]-1
        
if flag == -1:
    print(-1)
else:
    print(L,R)


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

#define RIGHT 0
#define DOWN 1
#define LEFT 2
#define UP 3

int main(){
	bool cross[5][5][4];	// x,y,dir
	int px=0, py=0, dir = RIGHT;
	int d[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
	string str;
	memset( cross, 0, sizeof(cross) );
	for( int i=0; i<4; i++ ){
		getline( cin, str );
		for( int j=0; j<4; j++ ){
			cross[j][i][RIGHT] = cross[j+1][i][LEFT] = (str[j]=='1');
		}
		getline( cin, str );
		for( int j=0; j<5; j++ ){
			cross[j][i][DOWN] = cross[j][i+1][UP] = (str[j]=='1');
		}
	}
	getline( cin, str );
	for( int j=0; j<4; j++ ){
		cross[j][4][RIGHT] = cross[j+1][4][LEFT] = (str[j]=='1');
	}
	do{
		for( int i=0; i<4; i++ ){
			if( cross[px][py][(dir+3+i)%4] ){
				dir = (dir+3+i)%4;
				px += d[dir][0];
				py += d[dir][1];
//				cout << (dir==RIGHT)?"R":((dir==DOWN)?"D":((dir==LEFT)?"L":"U"));
				if( dir == RIGHT ){
					cout << 'R';
				}else if( dir == DOWN ){
					cout << 'D';
				}else if( dir == LEFT ){
					cout << 'L';
				}else if( dir == UP ){
					cout << 'U';
				}
				break;
			}
		}
	}while( px!=0 || py!=0 );
	cout << endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

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

int main(){
    int h, w; cin >> h >> w;
    int s, g;
    int a, b; cin >> a >> b; a--; b--; s = a * w + b;
    cin >> a >> b; a--; b--; g = a * w + b;
    vector<vector<char>> data(h,vector<char>(w));
    rep(i,h) rep(j,w) cin >> data[i][j];

    vector<vector<pair<int,int>>> G(h*w);
    rep(i,h) rep(j,w){
        if(data[i][j] == '#') continue;
        rep(k,4){
            int x = i + dx[k], y = j + dy[k];
            if(0 <= x && x < h && 0 <= y && y < w && data[x][y] == '.'){
                G[i*w+j].push_back(make_pair(x*w+y,0));
            }
        }
        for(int ii = -2; ii <= 2; ii++){
            for(int jj = -2; jj <= 2; jj++){
                int x = i + ii, y = j + jj;
                if(0 <= x && x < h && 0 <= y && y < w && data[x][y] == '.'){
                    G[i*w+j].push_back(make_pair(x*w+y,1));
                }
            }
        }
    }

    vector<int> dist(h*w,1<<30);
    dist[s] = 0;
    deque<int> que;
    que.push_back(s);

    while(!que.empty()){
        int v = que.front(); que.pop_front();
        for(auto p : G[v]){
            int nv = p.first, d = p.second;
            if(dist[nv] > dist[v] + d){
                dist[nv] = dist[v] + d;
                if(d) que.push_back(nv);
                else que.push_front(nv);
            }
        }
    }

    cout << (dist[g] == 1<<30 ? -1 : dist[g]) << endl;
    return 0;
}

Measured memory_bytes: 120324
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int i;
    while(1){
        char x[1001] = {0};
        scanf("%s",x);
        int ans = 0;
        if(x[0] == '0'){
            break;
        }else{
            for(i=0;i<1001;i++){
                if(x[i]){
                    int a = x[i] - 48;
                    //printf("%d\n",a);
                    ans += a;
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}

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

int n, m;
int e[200000];

int main() {
	int i;
	
	cin >> n >> m;
	for (i = 0; i < m; i++) cin >> e[i];
	
	static bool used[200001] = {false};
	for (i = m - 1; i >= 0; i--) {
		if (!used[e[i]]) {
			used[e[i]] = true;
			cout << e[i] << endl;
		}
	}
	for (i = 1; i <= n; i++) {
		if (!used[i]) cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 3684
#include<stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main(){
  int head=1,tail=0,i,j,n,a[2000001],now;
  char c[20];
  scanf("%d",&n);
  //  for(i=0;i<n;i++)
  //a[i]=-1;
  for(i=0;i<n;i++){
    scanf("%s",c);
    if(c[0]=='i'){
      scanf("%d",&now);
      a[head] = now;
      head++;
    }else if(c[6]=='F'){
      a[head]=-1;
      while(a[head]==-1)
	head--;
      
    }else if(c[6]=='L'){
      a[tail]=-1;
      while(a[tail]==-1)
	tail++;
    }
    
    else{
      scanf("%d",&now);
      for(j=head-1;j>tail;j--){
	if(a[j]==now){
	  a[j]=-1;
	  break;
	}

      }

    }
    ;
    /*
    printf("tail%d head%d:",tail,head);
  for(j=head-1;j>tail;j--){
    if(a[j] != -1){
      printf("%d[%d]",a[j],j);
      j--;
      break;
    }
  }
  for(;j>tail;j--){
    if(a[j] != -1){
      printf(" %d[%d]",a[j],j);
    }
  }
  printf("\n");
    */
    ;

    ;/*
  for(j=head-1;j>tail;j--){
    if(a[j] != -1){
      printf("%d",a[j]);
      j--;
      break;
    }
  }
  for(;j>tail;j--){
    if(a[j] != -1){
      printf(" %d[%d]",a[j],j);
    }
  }
  printf("%s head=%d  ",c,head);
  printf("\n");
*/
    ;
    
    
  }

  for(j=head-1;j>tail;j--){
    if(a[j] != -1){
      printf("%d",a[j]);
      j--;
      break;
    }
  }
  for(;j>tail;j--){
    if(a[j] != -1){
      printf(" %d",a[j]);
    }
  }
  printf("\n");

}



Measured memory_bytes: 5648
#include <stdio.h>

int main() {
    int x[10001], i = 0;
    scanf("%d", &x[i]);
    while (x[i++] != 0) {
        scanf("%d", &x[i]);
    }
    i = 0;
    while (x[i]) {
        printf("Case %d: %d\n", i, x[i++]);
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <algorithm>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> a(N);
  std::vector<int> b(N);
  for (auto &i : a) { std::cin >> i; }
  for (auto &i : b) { std::cin >> i; }
  std::vector<int> a2(N);
  std::vector<int> b2(N);
  int mod = 1 << 29u;
  int ans = 0;
  while (mod > 1) {
    for (auto &i : a) { i %= mod; }
    for (auto &i : b) { i %= mod; }
    std::sort(b.begin(), b.end());
    long long sum = 0;
    for (int i = 0; i < N; ++i) {
      auto p1 = std::lower_bound(b.begin(), b.end(), mod / 2 - a[i]);
      auto p2 = std::lower_bound(b.begin(), b.end(), mod / 2 * 2 - a[i]);
      auto p3 = std::lower_bound(b.begin(), b.end(), mod / 2 * 3 - a[i]);
      auto p4 = std::lower_bound(b.begin(), b.end(), mod / 2 * 4 - a[i]);
      int x = p2 - p1;
      int y = p4 - p3;
      sum += x + y;
    }
    if (sum % 2) {
      ans += mod / 2;
    }
    mod >>= 1u;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 998244353;
// const ll INF = 1000000000000000000LL;

int main(){
   int k;
   cin >> k;
   if(k==7||k==1){
      cout << 1 << endl;
      return 0;
   }
   int i=2;
   int x = 7 % k;
   while(i<=k+1){
      x = (10*x+7) % k;
      if(x==0){
         cout << i << endl;
         return 0;
      }
      i++;
   }
   cout << -1 << endl;
}

Measured memory_bytes: 3636
n = gets.to_i
a = gets.split.map(&:to_i)

i = 0
count = 0

while (i < a.count - 1) do
  j = a.count - 1
  while (j > i) do
    if a[j] < a[j - 1]
      a[j - 1], a[j] = a[j], a[j - 1]
      count += 1
    end
    j -= 1
  end
  i += 1
end

puts a.join(" ")
puts count



Measured memory_bytes: 8872
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()

N = I()
s = [S() for i in range(N)]
M = I()
t = [S() for i in range(M)]

from collections import Counter

c1 = Counter(s)
c2 = Counter(t)
ans = 0
for a in c1.keys():
    ans = max(ans,c1[a]-c2[a])

print(ans)

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

ll solve() {
    ll N, T;
    cin >> N >> T;
    vector<ll> A(N), B(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i] >> B[i];
    }
    vector<vector<ll>> dp1(N+1, vector<ll>(T, 0)); // dp1[n][t] i=0から右にn個の中から選んで食べ終わりがt以前となるおいしさの最大値
    for ( int i = 1; i <= N; i++ ) {
        int j = i-1;
        for ( ll t = 0; t < T; t++ ) {
            ll v1 = 0;
            ll pt = t - A[j];
            if ( pt >= 0 ) v1 = dp1[i-1][pt] + B[j];
            dp1[i][t] = max({dp1[i-1][t], v1});
        }
    }
    vector<vector<ll>> dp2(N+1, vector<ll>(T, 0)); // dp2[n][t] i=N-1から左にn個の中から選んで食べ終わりがt以前となるおいしさの最大値
    for ( int i = 1; i <= N; i++ ) {
        int j = N-i;
        for ( ll t = 0; t < T; t++ ) {
            ll v1 = 0;
            ll pt = t - A[j];
            if ( pt >= 0 ) v1 = dp2[i-1][pt] + B[j];
            dp2[i][t] = max({dp2[i-1][t], v1});
        }
    }

    ll ans = 0;
    for ( int n = 0; n < N; n++ ) {
        ll m = 0;
        for ( int t = 0; t < T; t++ ) {
            m = max(m, dp1[n][t] + dp2[N-n-1][T-1-t]);
        }
        ans = max(ans, m + B[n]);
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    int N, Q, l, r;
    string S;
    cin >> N >> Q >> S;
    vector<int> v(S.size(), 0);

    REP(i, 1, S.size()) {
        if (S[i - 1] == 'A' && S[i] == 'C') {
            v[i] += v[i - 1] + 1;
        } else {
            v[i] = v[i - 1];
        }
    }

    rep(i, Q) {
        cin >> l >> r;
        cout << v[r - 1] - v[l - 1] << endl;
    }
}

Measured memory_bytes: 1408
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aoj
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
            var n = line[0];
            var q = line[1];

            var parents = new int[n];
            for(var i = 0; i < n; i++)
            {
                parents[i] = i;
            }

            var answers = new List<int>();

            for(var i = 0; i < q; i++)
            {
                line = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
                if(line[0] == 0)
                {
                    parents[GetRoot(line[1], parents)] = GetRoot(line[2], parents);
                }
                else
                {
                    if(GetRoot(line[1], parents) == GetRoot(line[2], parents))
                    {
                        answers.Add(1);
                    }
                    else
                    {
                        answers.Add(0);
                    }
                }
            }

            answers.ForEach(value => WriteLine(value));
        }

        private static int GetRoot(int node, int[] parents)
        {
            if(parents[node] == node)
            {
                return node;
            }

            return parents[node] = GetRoot(parents[node], parents);
        }
    }
}



Measured memory_bytes: 22508
import sys

r_len = 10
f_len = 3
b_len = 4

rooms = [[[0 for x in range(r_len)] for y in range(f_len)] for z in range(b_len)]

n = int(input())
for i in range(n):
	arr = list(map(int, input().split()))
	b = arr[0] - 1
	f = arr[1] - 1
	r = arr[2] - 1
	v = arr[3]
	rooms[b][f][r] += v

for i in range(b_len):
	for j in range(f_len):
		for k in range(r_len):
			v = rooms[i][j][k]
			sys.stdout.write(' ' + str(v))
		print()
	if i != b_len - 1:
		print('####################')



Measured memory_bytes: 5620
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

struct Line{
  int h,s,ur,ul,lr,ll;
  Line(){}
  Line(int h,int s, int ur=0, int ul=0, int lr=0, int ll=0):h(h),s(s),ur(ur),ul(ul),lr(lr),ll(ll){}
  bool operator<(const Line &r)const{ return h < r.h; }
};

int N,M,H,K;
int s[1024],p[1024],st[1024];
Line L[100005];

int main(){
  while(scanf("%d%d%d%d",&N,&M,&H,&K) && N||M||H||K){
    for(int i=0;i<N;i++) scanf("%d",&s[i]);
    for(int i=0;i<N;i++) st[i] = i;
    for(int i=0;i<M;i++){
      int a,b;scanf("%d%d", &a,&b); a--;
      L[i] = Line(b,a);
    }

    sort(L, L+M);
    for(int i=0;i<M;i++){
      Line &li = L[i];
      li.ul = st[li.s]; li.ur = st[li.s+1];
      swap(st[li.s], st[li.s+1]);
      li.ll = st[li.s]; li.lr = st[li.s+1];
    }
    for(int i=0;i<N;i++) p[st[i]] = i; // s[p[i]] := get point from p[i] 
    int sum = 0;
    for(int i=0;i<K;i++) sum += s[p[i]];
    int res = sum;
    for(int i=0;i<M;i++){
      Line li = L[i];
      if(0 <= li.ul &&  li.ul < K && 0 <= li.ur && li.ur < K) continue;
      if(K<=li.ur&&K<=li.ul) continue;
      if(0<=li.ul&&li.ul<K){
	res = min(res, sum-s[p[li.ul]]+s[p[li.ur]]);
      }else{
	res = min(res, sum-s[p[li.ur]]+s[p[li.ul]]);
      }
    }

    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 3388
/*input
119
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define pb push_back 
#define f first
#define s second
#define int ll
#define fr(j,n) for(int i=j;i<=n;i++)
#define reset(a) memset(a,0,sizeof(a))
#define minqueue priority_queue<int,vector<int>,greater<int> >
int const mod = 1e9+7;
int const inf = 2e18;


int power(int x, int y, int mod = inf)
{
    int ans = 1;
    x %= mod;
    while(y)
    {
        if(y&1)
            ans = (x * ans) % mod;

        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
int gcd(int a , int b)
{
	if(a==0)
	return b;
	return gcd(b%a,a);
}
signed main() {
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
    	if(s[i]=='9')
    		cout<<'1';
    	else
    		cout<<'9';
    }
    


	  
return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n,m,x; cin >> n >> m >> x;
    VI a(m); REP(i,m) cin >> a[i];
    int ans1 = 0 , ans2 = 0;
    REP(i,m){if(a[i]<x) ans1++; else ans2++;}
    out(min(ans1,ans2));


    return 0;
}

Measured memory_bytes: 256
n, a, b, MOD = map(int, input().split())


def mult(A, B, N):
    C = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            for k in range(N):
                C[i][j] += A[i][k] * B[k][j]
            C[i][j] %= MOD
    return C


def mat_power(A, N, n):
    if n == 0:
        res = [[0] * N for _ in range(N)]
        for i in range(N):
            res[i][i] = 1
        return res
    X = mat_power(A, N, n // 2)
    X = mult(X, X, N)
    return mult(A, X, N) if n & 1 else X


li = [0]
t = 1
while li[-1] < n:
    p = pow(10, t)
    l, r = li[-1] - 1, n
    while r - l > 1:
        m = (l + r) // 2
        if a + b * m < p:
            l = m
        else:
            r = m
    li.append(r)
    t += 1
ans = 0
for i in range(len(li) - 1):
    p = pow(10, i + 1)
    t = li[i + 1] - li[i]
    am = [[p, 1, 0], [0, 1, 1], [0, 0, 1]]
    mat = mat_power(am, 3, t)
    ans *= pow(10, t * (i + 1), MOD)
    ans += mat[0][1] * ((a + b * li[i])) + mat[0][2] * b
    ans %= MOD
print(ans)


Measured memory_bytes: 42352
fn main() {
    proconio::input! {
        n:usize,
        m:usize,
        x:usize,
        mat:[(usize, [usize;m]);n],
    }

    // 試行num の際にOKならSome(費用), NGならNone なクロージャ
    let try_num = |num:usize| {
        let mut money  = 0;
        let mut skills = vec![0;m]; // 各Skillの値
        for i in 0..n {
             // 買ってない
            if (1 << i) & num == 0 {
                continue;
            }
            // 買った
            money += mat[i].0; // 出費を計上
            for j in 0..m {
                skills[j] += (mat[i].1)[j]; // スキルを計上
            }
        }
        if skills.iter().all(|&sv| sv >= x ) {
            Some(money)
        } else {
            None
        }
    };

    let mut ans = 1<<32 ; // very big
    for num in 0..(1<<n) {
        match try_num(num) {
            Some(money) => ans = ans.min(money),
            None        => (),
        }
    }
    println!("{}", if ans == 1<<32 { -1 } else { ans as i32 })
}

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

string solve(string s,int K){
	chmin(K,20);
	if(K == 0) return s;
	int N = s.size();

	int i = N-1;
	while(i>=0 && s[i]==s[N-1]) i--;
	if(i == -1) return s;
	i++;
	int n = N-i;
	rep(_,K) n = min(n*2,N);

	if(n == N) return string(N,s.back());
	string ad = s.substr(i-(N-n),N-n); reverse(all(ad));
	return string(n,s.back()) + ad;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N,K; cin >> N >> K;
	string s; cin >> s;
//	s = string(N,'a'); rep(i,N/2) s[i*2] = 'b';

	string ans = string(1,'z'+1);
	string rs = s; reverse(all(rs));
	string u = s+rs;
	rep(i,N+1){
		string t = u.substr(i,N);
		chmin(ans,solve(t,K-1));
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>

using namespace std;

string S;
unsigned int K;

int main() {
	cin >> K;
	cin >> S;
	if (S.size() <= K) {
		cout << S << endl;
	}
	else {
		for (int i = 0; i < K; i++) {
			cout << S[i] << flush;
		}
		cout << "..." << endl;
	}
}

Measured memory_bytes: 3624
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;


int cal(int s)
{
    int l=1,r=100;
    int m;
    int ans=1;
    while(r>=l)
    {
        m=(l+r)/2;
        int z=m*(m+1);
        z/=2;
        if(z<=s)
        {
            ans=m;
            l=m+1;
        }
        else
            r=m-1;
    }
    return ans;
}

void solve()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=2;i*i<=n;i++)
    {
        int z=0;
        while(!(n%i))
        {
            n=n/i;
            z++;
        }
        if(z)
        {
            ans=ans+cal(z);
        }
    }
    if(n>1)
        ans++;
    cout<<ans<<endl;
    
    
    
    
    
}


int32_t main()
{
    IOS;
    //pre();
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>
int main(void){
int co=0,i,j,k,num1,num0;
scanf("%d %d",&num0,&num1);
for(i=0;i<=num1/10000;i++){
    for(j=0;j<=(num1-i*10000)/5000;j++){
        if(i+j>num0||i*10000+j*5000>num1)break;
        for(k=0;k<=(num1-i*10000-j*5000)/1000;k++){
            if(i+j+k>num0||i*10000+j*5000+k*1000>num1)break;
            else if(i+j+k==num0&&i*10000+j*5000+k*1000==num1){
                co=1;
                printf("%d %d %d",i,j,k);
                break;
            }
        }
        if(co==1)break;
    }
    if(co==1)break;
}
if(co==0)printf("-1 -1 -1");
return 0;
}


Measured memory_bytes: 128
import scala.io.StdIn.{readDouble,readLine}

object Main extends App {
  val n = readInt
  val d = new Array[Int](6)
  for(i<- 0 until n) {
    val h = readDouble
    if(h < 165D) d(0) = d(0)+1
    else if(h >= 165D && h < 170D) d(1) = d(1)+1
    else if(h >= 170D && h < 175D) d(2) = d(2)+1
    else if(h >= 175D && h < 180D) d(3) = d(3)+1
    else if(h >= 180D && h < 185D) d(4) = d(4)+1
    else if(h >= 185D) d(5) = d(5)+1
  }

  for(i<-1 to 6) { println(i + ":" + ("*" * d(i-1))) }
}

Measured memory_bytes: 43960
#include <stdio.h>

int main()
{
    int n,i;
    scanf("%d", &n);

    long long sum=0;
    for (i=1; i<=n; i++)
    {
        if (i%3== 0 && i%5==0) {}
        else if ((i%3) == 0) {}
        else if ((i%5) == 0) {}
        else
        {
            sum= sum+i;
        }

    }
    printf("%lld\n", sum);

    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 350
 
int N, M;
int cost[MAX];
int rank[MAX][3];
 
void solve(){
    int dp[MAX][MAX][3];
    memset(dp, 0, sizeof(dp));
 
    int ans = 0;
    for(int k = 0 ; k < 3 ; k++){
	for(int i = 0 ; i < N ; i++){
	    for(int j = 0 ; j <= M ; j++){
		if(j-cost[i] < 0){
		    dp[i+1][j][k] = dp[i][j][k];
		}else{
		    dp[i+1][j][k] = max(dp[i][j][k],dp[i+1][j-cost[i]][k] + rank[i][k]);
		}
	    }
	}
	ans = max(ans, dp[N][M][k]);
    }
    cout << ans << endl;
}
 
int main(){
    string str;
    while(cin >> N >> M){
	for(int i = 0 ; i < N ; i++){
	    cin.ignore(); 
	    getline(cin,str);
	    cin >> cost[i] >> rank[i][0] >> rank[i][1] >> rank[i][2];
	}
	solve();
    }
    return 0;
}

Measured memory_bytes: 2644
s=input()
k=int(input())
d = dict()
alphabet = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(alphabet)):
    d[alphabet[i]]=i
    
def f(s,k):
    s = [s[i] for i in range(len(s))]
    res = s
    L = 0
    for i in range(len(s)):
        l = max((26 - d[s[i]]) % 26, 0)
        if i==len(s)-1:
            res[i] = alphabet[(d[s[i]] + (k-L)) % 26]
        else:
            if L + l <= k:
                res[i] = "a"
                L += l
            else:
                continue
    return(''.join(res))
print(f(s,k))

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{	
	string s; cin >> s;
	ll n = s.length(), b = 0, res = 0;
	forn(i, n)
	{
		if (s[i] == 'B') b++;
		else res += b;
	}
	cout << res;
}

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


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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

int main() {
	int N, M;
		cin >> N >> M;
		vector<int> s(M);
		vector<int> c(M);
	rep(i, M) cin >> s[i] >> c[i];

	vector<int>r(N);
	int a = 0;
	rep(i, N)r[i] = 10;
	rep(i, M) {
		if (r[s[i]-1] == 10)r[s[i]-1] = c[i];
		else if (r[s[i]-1] != c[i]) a++;

	}
	if (N == 1 && r[0] == 10)cout << 0;
	else if (a !=0 ||(N!=1&&r[0]==0)) cout << -1;
	else {
		if (r[0] == 10)cout << 1;
		else cout << r[0];

		for (int i = 1;i < N;i++) {
			if (r[i] == 10) cout << 0;
			else cout << r[i];
		}
	}

	}

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  char s[1111];
  scanf("%s", s);

  int len = strlen(s);
  REP(i, len-1) if (s[i] == 'A' && s[i+1] == 'C') { puts("Yes"); return 0; }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
L = int(input())
v = 1
edges = []
n = 2
cost = 1
while n <=L:
    edges.append((v,v+1,0))
    edges.append((v,v+1,cost))
    cost *=2
    v += 1
    n*=2
goal = v
n //=2
N = n
L-=N
while L>0:
    if L>=n:
        edges.append((v,goal,N))
        L-=n
        N+=n
    n //=2
    v-=1
print(goal,len(edges))
for e in edges:
    print(*e)

Measured memory_bytes: 3064
type Dice = [(Int, Int)]

toDice :: [Int] -> Dice
toDice [a, b, c, d, e, f] = [(a, f), (b, e), (c, d)]

toList :: Dice -> [Int]
toList [(a, f), (b, e), (c, d)] = [a, b, c, d, e, f]

swap :: (a, a) -> (a, a)
swap (a, b) = (b, a)

roll :: Dice -> Char -> Dice
roll [a, b, c] dir = case dir of
  'N' -> [b, swap a, c]
  'E' -> [swap c, b, a]
  'S' -> [swap b, a, c]
  'W' -> [c, b, swap a]
  _   -> [a, b, c]

main = do
  d <- return . toDice . map (\x -> read x :: Int) . words =<< getLine
  print . head . toList . foldl roll d =<< getLine

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
long long a,b,c,n,b1=0,c1=0,a1=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for (int i=0; i<n; i++){
		cin>>a>>b>>c;
			if (abs(b1-b)+abs(c-c1)==0){
				cout<<"No\n";
				return 0;
			}
			if (abs(b1-b)+abs(c-c1)<=abs(a-a1)){
				if (((a-a1)-(abs(b1-b)+abs(c-c1)))%2==0) continue;
				else {
					cout<<"No"<<"\n";
					return 0;
				}
			} 
			else {
				cout<<"No"<<"\n";
				return 0;
			}
		b1 = b;
		c1 = c;
		a1 = a;
	}
	cout<<"Yes"<<"\n";
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a,b,c,d,e,f = li()

water_set = set()
sugar_set = set()

MAX = 3000

# ありうる水と砂糖の重さ
for ai in range(0,MAX//100+1,a):
    for bi in range(0,MAX//100+1,b):
        if 100 * (ai + bi) <= MAX:
            water_set.add(100 * (ai + bi))

water_list = sorted(list(water_set))
water_list.remove(0)

for ci in range(0,30*e+1,c):
    for di in range(0,30*e+1,d):
        if ci + di <= 30*e:
            sugar_set.add(ci+di)
            
sugar_list = sorted(list(sugar_set))

node_max = -1
sw = 0
sg = 0

for wi in water_list:
    for si in sugar_list:
        if wi+si <= f and si <= e * (wi//100) and wi+si > 0:
            node = (100*si) / (wi+si)
            if node > node_max:
                sw = si + wi
                sg = si
                node_max = node
                
print(sw,sg)

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    string s;cin>>s;
    int n=s.size();
    if(s[n-1]=='3')cout<<"bon"<<endl;
    else if(s[n-1]=='0'||s[n-1]=='1'||s[n-1]=='6'||s[n-1]=='8')cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
}

Measured memory_bytes: 3624
c=[]
for i in range(3):
    c.append(list(map(int,input().split())))
if (c[0][0]-c[0][1] == c[1][0]-c[1][1] and c[0][0]-c[0][1] == c[2][0]-c[2][1] and
    c[0][2]-c[0][1] == c[1][2]-c[1][1] and c[0][2]-c[0][1] == c[2][2]-c[2][1] and
    c[0][0]-c[1][0] == c[0][1]-c[1][1] and c[0][0]-c[1][0] == c[0][2]-c[1][2] and
    c[0][0]-c[2][0] == c[0][1]-c[2][1] and c[0][0]-c[2][0] == c[0][2]-c[2][2]    ):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val m = cin.nextInt()

    var a = Array<MutableList<Int>>(n, {mutableListOf<Int>()})

    for (i in 0..m-1) {
        val l = cin.nextInt()-1
        val r = cin.nextInt()-1
        a[l].add(r)
        a[r].add(l)
    }

    var record = a[0].size
    var recorder = 0
    for (i in 0..n-1) {
        if (a[i].size != 0 && (record == 0 || record > a[i].size)) {
            record = a[i].size
            recorder = i
        }
    }

    var now = recorder
    var ans = mutableListOf<Int>(now)
    var fin = 0
    val first_save = a[now].toMutableList()
    while (a[now].size != 0) {
        var next: Int
        while (true) {
            next = a[now].removeAt(0)
            if (a[next].size != 0) {
                break
            }
            if (a[now].size == 0) {
                fin = 1
                break
            }
        }
        if (fin == 1) {
            break
        }
        ans.add(next)
        a[now] = mutableListOf<Int>()
        now = next
    }
    
    now = recorder
    var ans2 = mutableListOf<Int>()
    fin = 0
    a[now] = first_save

    while (a[now].size != 0) {
        var next: Int
        while (true) {
            next = a[now].removeAt(0)
            if (next != recorder && a[next].size != 0) {
                break
            }
            if (a[now].size == 0) {
                fin = 1
                break
            }
        }
        if (fin == 1) {
            break
        }
        ans2.add(next)
        a[now] = mutableListOf<Int>()
        now = next
    }

    println(ans.size + ans2.size)
    for (i in 0..ans2.size-1) {
        print("%d ".format(ans2[ans2.size-i-1]+1))
    }
    for (i in 0..ans.size-1) {
        print("%d ".format(ans[i]+1))
    }
    println()
}

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

int main() {
  int n, d;
  cin >> n >> d;
  // A / B の切り上げ = (A + B - 1) / B
  int ans = (n + 2 * d) / (2 * d + 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
string s1,s2;
int dp[3005][3005],go[3005][3005];
void p(int a,int b)
{
	if(!a||!b)
		return ;
	if(go[a][b]==1)
		p(a,b-1);
	else if(go[a][b]==2)
		p(a-1,b);
	else if(go[a][b]==3)
		p(a-1,b-1),cout<<s1[a-1];
}
int main(){
	cin>>s1>>s2;
	for(int i=1;i<=s1.size();i++)
		for(int j=1;j<=s2.size();j++)
		{
			if(s1[i-1]==s2[j-1])
				dp[i][j]=dp[i-1][j-1]+1,go[i][j]=3;
			if(dp[i][j]<max(dp[i-1][j],dp[i][j-1]))
			{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
				go[i][j]=1;
				if(dp[i-1][j]>dp[i][j-1])
					go[i][j]=2;
			}
		}
	p(s1.size(),s2.size());
	return 0;
}
//axyb
//abyxb

Measured memory_bytes: 70912
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int i = sc.nextInt();
        pw.println(n+1-i);
        pw.flush();
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

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

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 25392
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
using namespace std;

class Dictionary {
private:
	int size;
	vector<string> table;
	const int P;
public:
	Dictionary(int n);
	int hash(string str);
	void insert(string str);
	bool find(string str);
};

Dictionary::Dictionary(int n) : table(n), P(7916843) {
	size = n;
}

int Dictionary::hash(string str) {
	int S = 0;
	for (int i = 0; i < str.size(); i++) {
		int k = str[i] - 'A';
		S = S * 5 + k;
	}
	S = (S ^ P) % size;
	if (table[S].empty() || table[S] == str) {
		return S;
	}
	else {
		for (int i = 1;; i++) {
			int t = (S + i) % size;
			if (table[t].empty() || table[t] == str) {
				return t;
			}
		}
	}
}

void Dictionary::insert(string str) {
	int h = this->hash(str);
	if (table[h].empty()) {
		table[h] = str;
		return;
	}
}

bool Dictionary::find(string str) {
	int h = this->hash(str);
	if (table[h].empty())
		return false;
	else {
		assert(table[h] == str);
		return true;
	}
}

int main() {
	int n;
	cin >> n;
	Dictionary dic(1000000);
	for (int i = 0; i < n; i++) {
		string command, str;
		cin >> command >> str;
		//cout << i << endl;
		if (command == "insert")
			dic.insert(str);
		else if (command == "find") {
			if (dic.find(str))
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}
	}
}


Measured memory_bytes: 26624
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vi = vector<int>;
using vs = vector<string>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repp(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define repd(i, n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll k, l, m, n;
const ll M = 1e9 + 7;



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

    int n, m;
    cin >> n >> m;

    vvl a(m, vl(3));
    rep(i, m) {cin >> a[i][0] >> a[i][1]; a[i][2] = i;}

    sort(all(a), [](vl x, vl y) {return x[1] < y[1];});

    map<ll, ll> b;
    rep(i, m) {
        if(b.count(a[i][0])) {
            b[a[i][0]]++;
            a[i][1] = b[a[i][0]];
        } else {
            b[a[i][0]] = 1;
            a[i][1] = 1;
        }
    }

    sort(all(a), [](vl x, vl y) {return x[2] < y[2];});

    rep(i, m) printf("%06lld%06lld\n", a[i][0], a[i][1]);
}

Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  if(S=="a"){
    cout<<"vowel"<<endl;
  }else   if(S=="i"){
    cout<<"vowel"<<endl;
  }else   if(S=="u"){
    cout<<"vowel"<<endl;
  }else  if(S=="e"){
    cout<<"vowel"<<endl;
  }else if(S=="o"){
    cout<<"vowel"<<endl;
  }else{
    cout<<"consonant"<<endl;
  }
}           
       

Measured memory_bytes: 3628
class UnionFind:

    def __init__(self, n):
        self.p, self.d = [-1] * n, [0] * n

    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        if self.isSame(x, y):
            return
        x, y = self.find(x), self.find(y)

        if self.d[x] > self.d[y]:
            self.p[x] += self.p[y]
            self.p[y] = x
        else:
            self.p[y] += self.p[x]
            self.p[x] = y
            if self.d[x] == self.d[y]:
                self.d[y] += 1

    def numTree(self):
        return sum([1 for p in self.p if p < 0])


N, M = map(int, input().split())
E = [tuple(map(int, input().split())) for _ in range(M)]

ans = 0
for i in range(M):
    U = UnionFind(N)
    for a, b in E[:i] + E[i + 1:]:
        U.unite(a - 1, b - 1)
    if U.numTree() == 2:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int n;
	char card[128];
	
	while (scanf("%d", &n) * n != 0){
		int field = 0;
		int player[10] = {0};
		int i, j;
		
		scanf("%s", card);
		field = 0;
		for (i = 0; card[i] != 0; i++){
			switch (card[i]){
				case 'M':
					player[i % n]++;
					break;
				case 'S':
					field += player[i % n] + 1;
					player[i % n] = 0;
					break;
				case 'L':
					player[i % n] += field + 1;
					field = 0;
					break;
			}
		}
		for (i = 0; i < n - 1; i++){
			for (j = 0; j < n - i - 1; j++){
				if (player[j] > player[j + 1]){
					int tmp = player[j];
					player[j] = player[j + 1];
					player[j + 1] = tmp;
				}
			}
		}
		for (i = 0; i < n; i++){
			printf("%d ", player[i]);
		}
		printf("%d\n", field);
	}
	
	return 0;
}

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

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

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

	bool existEqual = false;

	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			if (w[i] == w[j]) {				
				existEqual = true;
			}
		}
	}
	
	if (existEqual) {
		cout << "No" << endl;
		return 0;
	}
	
	string ans = "Yes";

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

		int tmpSize = w.at(i - 1).size();
		char tmp = w.at(i - 1).at(tmpSize - 1);

		if ( tmp != w.at(i).at(0)) {
			ans = "No";
		}
	}

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

Measured memory_bytes: 256