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

vector<P> g[100000];
int colors[100000];

void dfs(int node, int from, int from_color) {
  int color = 1;
  for (auto e : g[node]) {
    int to = e.first, cur = e.second;
    if (to == from) continue;
    if (color == from_color) color++;
    colors[cur] = color;
    dfs(to, node, color);
    color++;
  }
}

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

  int n;
  cin >> n;
  rep(i, 0, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].emplace_back(b, i);
    g[b].emplace_back(a, i);
  }

  dfs(0, -1, -1);
  cout << *max_element(colors, colors + n - 1) << endl;
  rep(i, 0, n - 1) cout << colors[i] << endl;
}


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

int main(){
	int a[3],i,j,temp;
	cin >> a[0] >> a[1] >> a[2];
	for(i=0;i<2;i++){
		for(j=2;j>i;j--){
			if(a[j-1]>a[j]){
				temp = a[j];
				a[j] = a[j-1];
				a[j-1] = temp;
			}
		}
	}
	cout << a[0] + a[1] << endl;
}


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

using namespace std;

typedef long long ll;

const int MAX_LEN = 1e6 + 10, ALPHA = 26;

int N;
ll ans;

struct TNode {
    TNode *child[ALPHA], *parent;
    int siz, siz_with[ALPHA], val;
    bool isword;

    TNode() : parent(nullptr), siz(0), val(0), isword(false) {
        memset(child, 0, sizeof(child));
        siz = 0;
        memset(siz_with, 0, sizeof(siz_with));
    }

    void build() {
        for (int i = 0; i < ALPHA; i++) {
            if (child[i]) {
                child[i]->build();
                siz += child[i]->siz;
                for (int j = 0; j < ALPHA; j++) {
                    siz_with[j] += child[i]->val == j ? child[i]->siz : child[i]->siz_with[j];
                }
            }
        }
        siz += isword;
    }
    
    void solve() {
        if (isword) {
            ans += parent->siz_with[val] - 1;
        }
        for (int i = 0; i < ALPHA; i++) {
            if (child[i]) {
                child[i]->solve();
            }
        }
    }
} *root;

int main() {
    scanf("%d", &N);
    root = new TNode(); root->val = -1;
    for (int i = 1; i <= N; i++) {
        static char S[MAX_LEN]; scanf("%s", S + 1);
        int len = strlen(S + 1);
        TNode *x = root;
        for (int j = len; j; j--) {
            int c = S[j] - 'a';
            if (!x->child[c]) {
                (x->child[c] = new TNode())->parent = x;
            }
            (x = x->child[c])->val = c;
        }
        x->isword = true;
    }
    root->build();
    root->solve();
    printf("%lld\n", ans);
}

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

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();

        final Solver solver = new Solver();
        System.out.println(solver.solve(N, A, B));
    }
}

class Solver {
    public long solve(long N, long A, long B) {
        long T = A + B;

        long ans = 0;

        long count = N / T;
        ans += count * A;


        long rest = N % T;
        if (rest <= A) {
            ans += rest;
        }
        else {
            ans += A;
        }

        return ans;
    }
}



Measured memory_bytes: 22740
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(int,n);

  auto cnt = [&](int i){
               int res = 0;
               string s = to_string(i);
               REP(i,s.size()){
                 res += s[i]-'0';
               }
               return res;
             };
  
  int ans = INF;
  FOR(i,1,n/2+1){
    ans = min(ans,cnt(i)+cnt(n-i));
  }
  OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sync ios::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL);

int main(){
  sync;
  int n;
  cin >> n;
  int k,prev,ans=0,count=1;
  cin >> prev;
  for(int i=1;i<n;i++){
    cin >> k;
    if(prev==k){
      count++;
    }
    else{
      ans+=count/2;
      count=1;
    }
    prev=k;
  }
  ans+=count/2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



ll a[1111][1111];

int main(void) {
  ll i, j, k;
  ll N;
  cin >> N;
  
  for(i=0; i<N; i++) {
    for(j=0; j<N-1; j++) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  
  ll pos[1111]={};
  queue<ll> q;
  for(i=0; i<N; i++) q.push(i);
  
  for(ll d=0; d<=N*(N-1)/2; d++) {
    ll used[1111]={};
    ll upd=0;
    
    queue<ll> tq;
    
    while(q.size()) {
      ll u=q.front(); q.pop();
      if(used[u]) continue;
      if(pos[u]==N-1) continue;
      
      ll e=a[u][pos[u]];
      if(used[e]) continue;
      
      if(a[e][pos[e]]==u) {
        used[u]=1; used[e]=1;
        pos[u]++; pos[e]++;
        upd=1;
        
        if(pos[u]<N-1) tq.push(u);
        if(pos[e]<N-1) tq.push(e);
      }
    }
    
    while(tq.size()) {
      q.push(tq.front());
      tq.pop();
    }
    
    
    if(!upd) {
      pt(-1);
      return 0;
    }else {
      if(q.empty()) {
        pt(d+1);
        return 0;
      }
    }
    
    
  }
  
  
}



Measured memory_bytes: 8960
#include <cstdio>
#include <algorithm>

typedef long long int64;

const int MAXN = 50 + 10;

int n;
int64 a[MAXN];

inline int randint(int l, int r) {
	static unsigned seed;
	return (seed = (seed * 31 + 998244353) % 1000000007) % (r - l + 1) + l;
}

int main() {
	int i, k;
	int64 l, r, mid, ans = 0;
	
	scanf("%d", &n);
	for(i=1; i<=n; i++)
		scanf("%lld", &a[i]);
	
	std::sort(a+1, a+1+n);
	while(a[n] >= n) {
		k = n;
		while(k > 1 and a[n] - n < a[k - 1] + 1)
			k--;
		l = 0;
		r = (a[n]-n) / k + 1; // (a[n] - n)/k >= t
		while(l ^ r) {
			mid = (l + r + 1) >> 1;
			if((k == 1 or a[k - 1] + mid * (n - k + 1) <= a[k] - mid * k) and a[k] - mid * k >= n)
				l = mid;
			else
				r = mid - 1;
		}
		for(i = 1; i < k; i++) 
			a[i] += l * (n - k + 1);
		for(i = k; i <= n; i++)
			a[i] -= l * k;
		ans += l * (n - k + 1);
		
		k = randint(1, 5);
		while(k and a[n] >= n) {
			for(i = 1; i < n; i++)
				a[i]++;
			a[n] -= n;
			ans++;
			k--;
			std::sort(a+1, a+1+n);
		}
	}
	printf("%lld\n", ans);
	return 0;
}
/*
42
100000000000 10000000000 10000000000 100000000000 10000000000 10000000000
10000000000 1000000000 1000000000 10000000000 1000000000 1000000000
50000000000 5000000000 5000000000 50000000000 5000000000 5000000000
5000000000 500000000 500000000 5000000000 500000000 500000000
500000000 50000000 50000000 500000000 50000000 50000000
50000000 5000000 5000000 50000000 5000000 5000000
5000000 500000 500000 5000000 500000 500000
100000000000 99999999999 99999999998 10293857 5232 5
*/

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int grid[100][100];
int a[10000];
int main(void)
{
	int h,w,n,i,j,k,t;
	int nh,nw;
	scanf("%d%d",&h,&w);
	scanf("%d",&n);
	FOR(i,0,n) scanf("%d",&a[i]);
	nh=nw=0;
	FOR(i,1,n+1){
		while(a[i-1]-->0){
			grid[nh][nw]=i;
			if(nh%2==0){
				nw++;
				if(nw==w) nh++,nw=w-1;
			}else{
				nw--;
				if(nw==-1) nh++,nw=0;
			}
		}
	}
	FOR(i,0,h){
		FOR(j,0,w){
			printf("%d%c",grid[i][j],j==w-1?'\n':' ');
		}
	}
	return 0;
}
    
    


Measured memory_bytes: 256
N = int(input())
light_rule = {n:int(input())-1 for n in range(N)}

light = ["1"]+["0"]*(N-1)

flag = 0
num = 0
bottun = 0
for _ in range(N):
    if light[1] == "1":
        flag = 1
        break
    num += 1
    # print(bottun, light_rule[bottun])
    light[bottun] = "0"
    light[light_rule[bottun]] = "1"
    bottun = light_rule[bottun]
    # print(light)
    
if flag:
    print(num)
else:
    print(-1)

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;


clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

const ll mod = 1e9 + 7;

inline ll add(ll a,ll b){
  return (a % mod + b % mod) % mod;
}

inline ll sub(ll a,ll b){
  return (a % mod - b % mod + mod) % mod;
}

inline ll mul(ll a,ll b){
  return(a % mod * b % mod) % mod;
}

inline ll modexpo(ll a,ll b){
  ll res = 1;
  while(b > 0){
    if(b & 1)
      res = (res % mod * a % mod) % mod;
    a = (a % mod * a % mod) % mod;
    b >>= 1;
  }return res;
}
inline ll divide(ll a,ll b){
  return(a%mod * modexpo(b,mod - 2)%mod)%mod;
}

const ll N = 1e5 + 5;

vl g[N];
ll d[N];
ll f[N];

ll dp[N];
ll n,k;

void dfs(ll v, ll p, ll poss, ll less){

  if(poss >= d[v] - less)
    dp[v] = 1;
  else
    dp[v] = 0;
  if(v == p) 
    dp[v] = mul(dp[v], poss);
  dp[v] = mul(dp[v], f[poss - 1]);
  dp[v] = mul(dp[v], f[d[v] - less]);
  dp[v] = divide(dp[v], f[d[v] - less]);
  dp[v] = divide(dp[v], f[poss - 1 - (d[v] - less)]);
  for(auto x : g[v]){
    if(x != p){
      dfs(x,v,k - 1,1);
      dp[v] = mul(dp[v], dp[x]);
    }
  }
}

int main(){
  fastio

  cin >> n >> k;

  ll ans = 0;

  for(int i = 1; i < n; i++){
    ll u,v;
    cin >> u >> v;
    g[u].pb(v); g[v].pb(u);
    d[u]++;
    d[v]++;
    if(d[u] >= k){
      ans = -1;
    }
    if(d[v] >= k){
      ans = -1;
    }
  }
  if(n == 1){
    cout << k << '\n';
    return 0;
  }
  if(ans == -1){
    cout << "0\n";
  }else{
    f[0] = 1;
    for(ll i = 1; i < N; i++){
      f[i] = mul(i, f[i - 1]);
    }
    dfs(1,1,k,0);
    cout << dp[1] << '\n';
  }

  ktj();
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll A,V,B,W;
    cin >> A >> V >> B >> W;
    ll T;
    cin >> T;
    if((V-W)>0){
        YES(abs(A-B)<=(V-W)*T);
    }else{
        YES(0);
    }
}

Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("6 2");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("14 3");
            //2
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("20 4");
            //3
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        int N = wkArr[0];
        int D = wkArr[1];

        int DivVal = D * 2 + 1;

        if (N % DivVal > 0) {
            Console.WriteLine(N / DivVal + 1);
        }
        else {
            Console.WriteLine(N / DivVal);
        }
    }
}


Measured memory_bytes: 13268
import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]

count = 0
idx = 0
for _ in range(N):
    if A[idx] == 2:
        print(count + 1)
        exit()
    idx = A[idx] - 1
    count += 1
print(-1)
        


Measured memory_bytes: 44380
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
using namespace std;

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

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

	int a,b;
	cin >> a >> b;
	cout << (a+b+1)/2 << endl;
	return 0;
}


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

int main() {
   int weightA = 0, weightB=0, weightC = 0, weightD=0;
   int weightL = 0, weightR=0;
  
  cin >> weightA >> weightB >> weightC >> weightD;
  
  weightL = weightA + weightB;
  weightR = weightC + weightD;
  
  if(weightL == weightR)
  {
    cout << "Balanced" << endl;
  }
  else if(weightL > weightR)
  {
    cout << "Left" << endl;
  }
  else if(weightL < weightR)
  {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
// ----------------------------------------------------------
#if 0
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
#else
#include <bits/stdc++.h>
#endif

using namespace std;

typedef long long LL;
typedef unsigned int UI;
typedef long double LD;

const LL MOD = (LL)1000000007;
const LL LL_INF = (LL)1 << 62;
const int INT_INF = (int)1 << 30;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)
#define SWAP(x,y) 		((x!=y)&&(x^=y,y^=x,x^=y))

LL dp[50000 + 1] = {0};

int main(int argc, char* argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	LL n, m;
	vector<LL>c;

	cin >> n >> m;

	c.reserve(m);

	REP(i, m) {
		cin >> c[i];
	}

	fill(dp, dp+n+1, LL_INF);
	dp[0] = 0;
	for (LL i = 0; i <= n; i++) {
		for (LL j = 0; j < m; j++) {
			if (i - c[j] >= 0) {
				dp[i] = min(dp[i], dp[i - c[j]] + 1);
			}
		}
	}

	cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 3524
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
arr=arr.map(v=>v.split(" ").map(Number));
var [n,t]=arr.shift();
var max=0;
arr.forEach(v=>{
   max=Math.max(max,v[1]/v[0]);
});
console.log((max*t).toFixed(6));


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;

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

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};
int main(){
	int n, q;
	cin >> n >> q;
	vector<int> c(n);
	rep(i, n)cin>>c[i];
	rep(i,n) c[i]--;
	// 矢印を見つける
	vector<int> pi(n,-1);
	vector<vector<int>> ps(n);
	rep(i,n){
		int l = pi[c[i]];
		if(l == -1) {
		} else {
			// found
			ps[l].push_back(i);
		}
		pi[c[i]] = i;
	}

	vector<vector<P>> qs(n);
	rep(qi,q){
		int l, r;
		cin >> l >> r;
		l--, r--;
		qs[l].emplace_back(r,qi);
	}

	BIT<int> d(n);
	vector<int> ans(q);
	for(int x = n - 1; x >= 0; x--){
		for(int y: ps[x]) d.add(y,1);
		for(P query : qs[x]){
			int r = query.first, i = query.second;
			ans[i] = r - x + 1 - d.sum(r);
		}
	}
	rep(i,q) cout << ans[i] << endl;
}


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

using namespace std;

void solve() {
    int n, mx = 0;
    cin >> n;
    map<string, int> mp;
    for (int i = 0; i < n; i++) {
        string s; cin >> s; mp[s]++;
        mx = max(mx, mp[s]);
    }
    for (auto x : mp) {
        if (x.second == mx) cout << x.first << "\n";
    }
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long x;
  cin >> x;
  for(int i = 0; i < 200; i++){
    for(int j = -100; j < 200; j++){
      if(pow(i,5)-pow(j,5)==x){
        cout << i << " " << j;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

#define int long long

#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 rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

int N, A,B,C;
int counter[3] = {0};
string types[3] = {"AB","AC","BC"};

signed main()
{
	cin >> N >> A >> B >> C;

	vector<string> operations;

	rep(i, N) {
		string s; cin >> s;
		operations.PB(s);
	}

	vector<char> ans;

	range(i, 0, N) {
		if (operations[i] == "AB") {
			if (A == 0 and B == 0) {
				puts("No");
				return 0;
			}

			if (A * B == 1) {
				if (i + 1 < N) {
					if (operations[i + 1] == "BC") {
						B++;
						A--;
						ans.PB('B');
					} else {
						A++;
						B--;
						ans.PB('A');
					}
					continue;
				}
			}

			if (A <= B) {
				A++;
				B--;
				ans.PB('A');
			} else {
				B++;
				A--;
				ans.PB('B');
			}
		}
		if (operations[i] == "AC") {
			if (A == 0 and C == 0) {
				puts("No");
				return 0;
			}

			if (A * C == 1) {
				if (i + 1 < N) {
					if (operations[i + 1] == "BC") {
						C++;
						A--;
						ans.PB('C');
					} else {
						A++;
						C--;
						ans.PB('A');
					}
					continue;
				}
			}

			if (A <= C) {
				A++;
				C--;
				ans.PB('A');
			} else {
				C++;
				A--;
				ans.PB('C');
			}
		}
		if (operations[i] == "BC") {
			if (B == 0 and C == 0) {
				puts("No");
				return 0;
			}

			if (B * C == 1) {
				if (i + 1 < N) {
					if (operations[i + 1] == "AB") {
						B++;
						C--;
						ans.PB('B');
					} else {
						C++;
						B--;
						ans.PB('C');
					}
					continue;
				}
			}

			if (B <= C) {
				B++;
				C--;
				ans.PB('B');
			} else {
				C++;
				B--;
				ans.PB('C');
			}
		}
	}

	puts("Yes");
	rep(i, ans.size()) printf("%c\n", ans[i]);
}



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

using namespace std;

int main(int argc, char const *argv[])
{
    int D, N;
    cin >> D >> N;
    int ans;
    if (N == 100) N = 101;
    
    ans = ((int)(pow(100.0, (int)D))) * N;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
r = []
n.times do |i|
  s, p = gets.chomp.split
  r << [s, p.to_i, i + 1]
end
r.sort_by! {|s, _, _| s }
r.group_by {|s, _, _| s }.each do |_, v|
  v.sort_by! {|_, p, _| -p }
  v.each do |_, _, i|
    puts i
  end
end

Measured memory_bytes: 1788
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  fs = []
  ps = []
  for _ in range(n):
    f = sum([v * (2**i) for i, v in enumerate(map(int, input().split()))])
    fs.append(f)
    
  for _ in range(n):
    p = list(map(int, input().split()))
    ps.append(p)
    
  max = -10**10    
  for x in range(1, 2**10):
    score = 0
    for i, f in enumerate(fs):
      c = bin(x & f).count('1')
      score += ps[i][c]
    if score > max:
      max = score
  print(max)

if __name__=='__main__':
  main()



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

public class Main{
  public static void main(String[] args)throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try{
      String S = br.readLine();
      long N = Long.parseLong(S);
      long ans = 0;
      long a = N%500;
      ans += (N/500)*1000;
      ans += (a/5)*5;
      System.out.println(ans);
    }catch(Exception e){
    }
  }
}

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

input_list = input().split()
sort_list = (int(input_list[0]),int(input_list[1]),int(input_list[2]))

tuple_a = (5,5,7)
tuple_b = (5,7,5)
tuple_c = (7,5,5)

if sort_list==tuple_a or sort_list==tuple_b or sort_list==tuple_c:
    print("YES")
else:
    print("NO")





Measured memory_bytes: 2940
Scanf.scanf "%d %d" (fun h w ->
    let s = Array.init h (fun _ -> Scanf.scanf " %s" (fun s -> s)) in

    let sentinel = max_int / 10 in
    let prev = Array.make_matrix h w (0, 0) in
    let d = Array.make_matrix h w sentinel in
    d.(0).(0) <- 0;

    let module S = Set.Make (struct type t = int * int let compare = compare end) in

    let rec loop set =
        if S.is_empty set then () else
            let ((y, x) as m) = S.min_elt set in
            let set = S.remove m set in
            let set = List.fold_left (fun set (vy, vx) ->
                let x0 = x + vx in
                let y0 = y + vy in
                if x0 >= 0 && x0 < w && y0 >= 0 && y0 < h && s.(y0).[x0] = '.' && d.(y0).(x0) > d.(y).(x) + 1 then (
                    d.(y0).(x0) <- d.(y).(x) + 1;
                    prev.(y0).(x0) <- (y, x);
                    S.add (y0, x0) set
                ) else set
            ) set [ -1, 0; 1, 0; 0, -1; 0, 1 ]
            in
            loop set
    in
    loop (S.singleton (0, 0));

    Printf.printf "%d\n" @@
    if d.(h - 1).(w - 1) = sentinel then -1 else (
        let rec loop y x set =
            if y = 0 && x = 0 then set else
                let ny, nx = prev.(y).(x) in
                let set = S.add (ny, nx) set in
                loop ny nx set
        in
        let set = loop (h - 1) (w - 1) (S.singleton (h - 1, w - 1)) in
        let rec loop_y y acc =
            let rec loop_x x acc =
                if x = w then loop_y (y + 1) acc else
                    let acc = if s.(y).[x] = '.' && not (S.mem (y, x) set) then acc + 1 else acc in
                    loop_x (x + 1) acc
            in
            if y = h then acc else loop_x 0 acc
        in
        loop_y 0 0
    )
)

Measured memory_bytes: 5576
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n, x;
  cin >> n >> x;
  ll a[100005];
  ll ans = 0;
  REP(i, n) {
    int t;
    cin >> t;
    ans += max(t - x, 0);
    a[i] = min(x, t);
  }
  REP(i, n - 1) {
    if (a[i] + a[i + 1] > x) {
      ans += (a[i] + a[i + 1] - x);
      a[i + 1] -= (a[i] + a[i + 1] - x);
    }
  }
  cout << ans << endl;
}

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

int main()
{





vector<long long>vc;

long long n;
cin>>n;

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

    if(n%i==0)vc.push_back(i);
}
long long res=10e13;

for(long long int i=0;i<vc.size();i++){

    res=min(res,abs(vc[i]-1+(n/vc[i])-1));

}

cout<<res;










}

Measured memory_bytes: 256
n , m = map(int, input().split())
a = []
p = 0
max_wid = 0
if m == 0:
    max_wid = n
else:
    for i in range(m):
      b = int(input())
      a.append(b)
      if i > 0:
          max_wid = max(max_wid, b)
    max_wid = max(max_wid, n - a[m-1])

fib = [1, 1]
for i in range(max_wid):
    l = len(fib)
    fib.append(fib[l-2] + fib[l-1])
ans = 1
if m == 0:
  print(fib[n]%1000000007)
else:
  
  if a[0] == 0:
      ans *= 0
  else:
      ans *= fib[a[0]-1]
  for i in range(m-1):
      if a[i+1] == a[i] + 1:
          ans *= 0
      else:
          ans *= fib[a[i+1]-a[i]-2]
  ans *= fib[n - a[m-1]-1]
  ans %= 1000000007
  print(ans)


Measured memory_bytes: 464040
#include <stdio.h>
int main(void){
    int W,H,x,y,r;
    
    scanf("%d %d %d %d %d",&W, &H, &x, &y, &r);
    if(x - r >= 0 && W >= x + r && y - r >= 0 && H >= y + r)
        printf("Yes\n");
    else
        printf("No\n");
    
    return 0;
}

Measured memory_bytes: 584
import datetime
y1,m1,d1,y2,m2,d2=map(int,input().split())
qq,y1=divmod(y1,400)
y1+=400
qq-=1
q=(y2-y1)//400
y2-=400*q
a=688*(q-qq)
d=datetime.date(y1,m1,d1)
while d<=datetime.date(y2,m2,d2):
    if d.day==13 and d.weekday()==4:a+=1
    d+=datetime.timedelta(days=1)
print(a)


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

int N, T;
const int MAX_N = 1.0e5 + 100;
int A[MAX_N];

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

    int profit[N];
    int min_A = A[0];
    for (int i = 0; i < N; i++) {
        min_A = min(min_A, A[i]);
        profit[i] = A[i] - min_A;
    }

    sort(profit, profit+N, greater<>());

    int ans = 0;
    int max_p = profit[0];
    for (int i = 0; i < N; i++) {
        if (max_p == profit[i]) ans++;
        else break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int N; cin >> N;
  v<int> A(N),B(N);
  rep(i,N){
    cin >> A[i] >> B[i];
  }
  sort(ALL(A));
  sort(ALL(B));
  if(N%2==0){
    cout << (B[N/2]+B[N/2-1])-(A[N/2]+A[N/2-1])+1 << endl;
  }
  else{
    cout << B[(N+1)/2-1]-A[(N+1)/2-1]+1 << endl;
  }
  return 0;
}


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

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define MAXX 200005


#define PI 3.14159265358979323846264338327950

#define ll  long long int
vector<ll> v;
multiset<ll> ms;
multiset<ll>::iterator it;
ll a[MAXX], b[MAXX];
ll mod = 1000000007;
char c[MAXX];

int main()
{
	FAST;
	ll  ans = 0, a1 = 0, a2 = 0, n , mx = 0, m;
	cin >> n >> m;
	for(ll i = 1; i <= m; i++){
		cin >> a[i];

	}
	sort(a+1, a+m+1);
	for(ll i = 2; i <= m; i++){
		b[a1] = a[i]- a[i-1];
		a1 ++;
	}
	sort(b, b + a1);
	reverse(b, b + a1);
	for(ll i = 0; i< a1; i++){
		ans += b[i];
		mx = max(mx, b[i]);
		
	}
	for(ll i = 0; i < min(n - 1 , m - 1); i ++){
		ans -= b[i];
	}
	if(n > m){
		ans = 0;
	}
	cout << ans;
	
}

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

#define int long long
#define pb push_back
#define ld long double

using namespace std;

const int MAXN = 1048576 , MOD = 1e9 + 7 ;

int32_t main() 
{
    ios::sync_with_stdio(0); 
    int n , a , b , c , d ; 
    cin >> n >> a >> b >> c >> d ;
    n -- ;
    int l = d - c ; 
    for(int i = 0 ; i <= n ; i ++ )
    {
        int x = a + i * c - (n-i) * c ; 
      //  cout << i << ' ' << x << endl ;
        if(x<b&&i*l>=b-x) return cout << "YES" << endl , 0 ; 
        if(x>=b&&(n-i)*l>=x-b) return cout << "YES" << endl , 0 ; 
    }
    cout << "NO" << endl ; 
}

Measured memory_bytes: 256
#include <cstdio>

#define int long long
#define macrocat_impl(a, b) a##b
#define macrocat(a, b) macrocat_impl(a, b)
#define dotimes_impl(i, n, x) for (int i = 0, x = n; i < x; i++)
#define dotimes(i, n) dotimes_impl(i, (n), macrocat(dotimes_n_, __COUNTER__))

using namespace std;

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

template<typename T>
inline int size(T container) {
  return static_cast<int>(container.size());
}

signed main() {
  for (;;) {
    int n = rint();
    if (n == 0)
      break;
    const int s_max = 60 * 60 * 24;
    int a[s_max] = {};
    dotimes(i, n) {
      int h, m, s;
      scanf("%lld:%lld:%lld", &h, &m, &s);
      a[s + 60 * (m + 60 * h)]++;
      scanf("%lld:%lld:%lld", &h, &m, &s);
      a[s + 60 * (m + 60 * h)]--;
    }
    int r = a[0];
    dotimes(s, s_max - 1) {
      a[s+1] += a[s];
      if (r < a[s+1])
        r = a[s+1];
    }
    wint(r);
  }
  return 0;
}



Measured memory_bytes: 3292
import sys
n, k = map(int, sys.stdin.readline().strip('\n').split())
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
for i in range(1, n):
  for j in range(k+1):
    if i-j>=0: dp[i] = min(dp[i], dp[i-j] + abs(h[i-j]-h[i]))
print(dp[n-1])

Measured memory_bytes: 57440
#include <stdio.h>

#define rep(i, n) for(int i = 0; i < n; i++)

using ll = long long;

const ll mod = 1000000007;

ll dp[256][111];
ll dpw[256][111];

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  rep(i, 256) {
    rep(j, 111) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  rep(ww, n) {
    rep(i, 256) {
      rep(j, 111) {
        dpw[i][j] = dp[i][j];
      }
    }
    int w;
    scanf("%d", &w);
    rep(i, 256) {
      rep(j, 110) {
        dpw[i ^ w][j + 1] += dp[i][j];
      }
    }
    rep(i, 256) {
      rep(j, 111) {
        dp[i][j] = dpw[i][j] % mod;
      }
    }
  }
  ll all = 0;
  ll now = 1;
  for(int i = 1; i < 111; i++) {
    now = (now * i) % mod;
    all = (all + dp[k][i] * now) % mod;
  }
  printf("%lld\n", all);
}


Measured memory_bytes: 640
// God put a smile upon your face <3

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

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

ll vis[200005];
ll town[200005];

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n >> m)
    {
		for(i = 1; i <= n; i++)
		{
			slld(town[i]);
		}

		ll now = 1;
		ll used = 0;

		memset(vis,-1,sizeof vis);
		vis[1] = 0;

		while(++used <= m)
		{
			now = town[now];

			if(vis[now] != -1) break;

			vis[now] = used;
		}

		if(used >= m) cout << now << '\n';
		else
		{
			m -= used;
			ll circle = (used - vis[now]);
			ll in = vis[now];
			m %= circle;

			while(vis[now] < in + m)
			{
//				bug;
				now = town[now];
			}

			cout << now << '\n';
		}


    }


}





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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    ans += min(x, K - x) * 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>

using namespace std;

int main()
{
    int n, queryNum;
    scanf("%d %d", &n, &queryNum);
    vector<priority_queue<int, vector<int>, less<int> > > vec(n);

    int query, t, x;
    for (int loop = 0; loop < queryNum; loop++)
    {
        scanf("%d", &query);
        switch (query)
        {
        case 0:
            scanf("%d %d", &t, &x);
            vec[t].push(x);
            break;
        case 1:
            scanf("%d", &t);
            if (!vec[t].empty())
            {
                printf("%d\n", vec[t].top());
            }
            break;
        case 2:
            scanf("%d", &t);
            if (!vec[t].empty())
            {
                vec[t].pop();
            }
            break;
        default:
            break;
        }
    }


    return 0;
}



Measured memory_bytes: 4088
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)

#define X real()
#define Y imag()
typedef double D;
typedef complex<double>P;

D inprd(const P &a, const P &b){ return (conj(a) * b).X; }
D outprd(const P &a, const P &b){ return (conj(a) * b).Y; }
D sign(D d){ return (d<0)?-1:d>0?1:0; }
 
int main(void){
    CIN_NO_SYNC;
    double x1,y1,x2,y2,x3,y3,xp,yp;
    while(cin >>x1>>y1>>x2>>y2>>x3>>y3>>xp>>yp){
        P p12(x2-x1,y2-y1), p23(x3-x2,y3-y2), p31(x1-x3,y1-y3);
        P p1p(xp-x1,yp-y1), p2p(xp-x2,yp-y2), p3p(xp-x3,yp-y3);
        if(sign(outprd(p12, p1p)) == sign(outprd(p23, p2p)) && sign(outprd(p23, p2p)) == sign(outprd(p31, p3p))){
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1224
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { //Partition babyyyyyyyyy
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
      	int i = I.nextInt();
      	O.pln(N-i+1);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}


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

int main() {
	string S;
  cin>>S;
  int count1=0;
  int count2=0;
  
  for(int i=0;i<S.size();i++){
  	if(S.at(i)=='A')
      break;
    count1++;
  }
  for(int i=S.size()-1;i<S.size();i--){
    if(S.at(i)=='Z')
      break;
    count2++;
  }
  cout<<S.size()-count1-count2<<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

/**
 * http://abc069.contest.atcoder.jp/tasks/abc069_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		final int n = sc.nextInt();
		final int m = sc.nextInt();
		sc.close();
		
		System.out.println((n-1)*(m-1));

	}

}


Measured memory_bytes: 22740
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <climits>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

class SegmentTree
{
private:
    int m_n;
    vector<int> m_dat;
    
public:
    void init(int n) {
        m_n = 1;
        while  (m_n < n) m_n *= 2;

        m_dat.resize(2 * m_n - 1, INT_MAX);
    }

    void update(int k, int a) {
        k += m_n - 1;
        m_dat[k] = a;

        while (k > 0) {
            k = (k - 1) / 2;
            m_dat[k] = min(m_dat[k * 2 + 1], m_dat[k * 2 + 2]);
        }
    }

    // [a, b)???????????§????°?????????????
    int query(int a, int b) {
        return queryInternal(a, b, 0, 0, m_n);
    }

private:
    int queryInternal(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return INT_MAX;
        if (a <= l && r <= b) return m_dat[k];
        else {
            int vl = queryInternal(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = queryInternal(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};

int main(){
    int N, Q;
    cin >> N >> Q;
    
    SegmentTree st;
    st.init(N);
    
    REP(q, Q) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            st.update(x, y);
        }
        else {
            auto res = st.query(x, y+1);
            cout << res << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2052
import heapq

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
h = [-A[0]]
ans = 0
for i in range(1,N):
    ans -= heapq.heappop(h)
    heapq.heappush(h, -A[i])
    heapq.heappush(h, -A[i])
print(ans)


Measured memory_bytes: 31852
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 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;
}
signed main() {
    int N;
    cin >> N;
    cout << "ABC" << N << endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A.at(i);
        if(A.at(i)==0){
            cout << "0";
            return 0;
        }
    }
    ll x=1;
    rep(i,N){
        if(A.at(i)<=1000000000000000000/x){
            x*=A.at(i);
        }else{
            cout << "-1";
            return 0;
        }
    }
    cout << x;
}

Measured memory_bytes: 4008
n,m,x=map(int,input().split())
C=[]
for i in range(n):
    a=list(map(int,input().split()))
    C.append(a)
pattern=[]
toBuy=[]
for i in range(2**n):
    toBuy=[]
    for j in range(n):
        if ((i>>j)&1):
            toBuy.append(C[j])
 #   print(toBuy)
    pattern.append(toBuy)
#print(pattern)
X=[0]*m #mつのアルゴリズムそれぞれの経験値
xsum=0#とりあえずはじくためのやつ
sum=0#値段
min=12000000 
check=0
for tb in pattern:#toBuyについて
    sum=0
    xsum=0
    X=[0]*m
    for c in tb:
        for j in range(len(c)):
            if j==0:
                sum+=c[j]#price
            else:
                xsum+=c[j]#経験値そうごう
                X[j-1]+=c[j]#経験値各自
    if xsum<x*m:
        continue
    else:
        for eX in X:
            if eX<x:
                check=1
        if check==1:
            check=0
            continue
        if sum<min:
            min=sum
if min==12000000:
    print(-1)
else:
    print(min)  






Measured memory_bytes: 9512
#include<iostream>
#include<string>
#include<queue>

class process
{
    public:
	    std::string name;
	    int time;
};

int main ()
{
	std::queue<process> processes;

	int n,q, elapsed_time=0;

	std::cin >> n >> q;

	process p;

	while ( n-- )
	{
		std::cin >> p.name >> p.time;
		processes.push ( p );
	}

	while ( !processes.empty() )
	{
		p = processes.front(); processes.pop();
		
		p.time -= q;
		elapsed_time += q;

		if ( p.time > 0 )
		{
			processes.push ( p );
		}
		else
		{
			elapsed_time += p.time;
			std::cout << p.name << " " << elapsed_time << std::endl;
		}
	}

return 0;
}



Measured memory_bytes: 6336
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n;cin>>n;
    vector<ll> v(n);
    REP(i,n)cin>>v[i];
    sort(ALL(v),greater<>());
    ll alice=0,bob=0;
    REP(i,n){
        if(i%2==0){
            alice+=v[i];
        }else{
            bob+=v[i];
        }
    }
    cout<<alice-bob<<endl;
    return 0;
}


Measured memory_bytes: 3644