akhauriyash/Code-Regression huggingface dataset:
/*
       ()       ()()()()     ()        ()       ()        ()        ()
      ()()      ()     ()    ()()      ()      ()()       ()()      ()
     ()  ()     ()      ()   ()  ()    ()     ()  ()      ()  ()    ()
    ()()()()    ()      ()   ()    ()  ()    ()()()()     ()    ()  ()
   ()      ()   ()     ()    ()      ()()   ()      ()    ()      ()()
  ()        ()  ()()()()     ()        ()  ()        ()   ()        ()

*/
#include <bits/stdc++.h>
#define MOD 1e9+7
#define SIZE (int)1e5+5
#define all(x) x.begin(),x.end()

#define si(i)  scanf("%d",&i)
#define sf(f)  scanf("%f",&f)
#define pi(i)  printf("%d",i)
#define pd(d)  printf("%lf",d)
#define deb(x) cout<<#x<<" is "<<x<<"\n";
#define lb     lower_bound
#define ub     upper_bound
#define pb     push_back

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

using namespace std;

int64_t exponentiation(int64_t base,int exp)
{
    if (exp == 0)
        return 1;

    if (exp == 1)
        return base;

    int64_t t = exponentiation(base, exp / 2);

    t = (t * t);

    if (exp % 2 == 0)
        return t;
    else
        return base * t;
}

int64_t dp[(int)1e5+1][101];//(weight , n)
int weight[SIZE];
int64_t value[SIZE];

int64_t knapsack(int w,int n)
{
  if(w==0 || n == 0)
    return 0; 
  
  if( dp[w][n-1] != -1)
    return dp[w][n-1];

  if(weight[n-1]<=w)
  {
    dp[w][n-1] = max( knapsack(w-weight[n-1],n-1)+ value[n-1], knapsack(w,n-1) );
  }
  else
    dp[w][n-1] = knapsack(w,n-1);    
  
  return dp[w][n-1];
}

int main()
{
  IOfast;
  
  int q=1;
  //cin>>q;
  memset(dp,-1,sizeof(dp));
  while(q--)
  {
    int n,w;
    cin>>n>>w;
    
    for(int i=0;i<n;i++)
      cin>>weight[i]>>value[i];

    cout<<knapsack(w,n);
  }
  
  return 0;
}


Measured memory_bytes: 79232
def resolve():
  N, A, B= map(int, input().split(" "))
  S = list(input())

  sum_of_successful_candidate = 0
  sum_of_successful_b = 0

  for i, s in enumerate(S):
    if sum_of_successful_candidate >= A + B:
      for _ in range(N-i):
        print("No")
      return True

    if s == "a":
      sum_of_successful_candidate += 1
      print("Yes")
    elif s == "b" and sum_of_successful_b < B:
      sum_of_successful_candidate += 1
      sum_of_successful_b += 1
      print("Yes")
    else:
      print("No")

  return True


if __name__ == "__main__":
  resolve()

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

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

   double ans;
   double c=(double)2*x/(a*b);
   if(c<=a){
      double t=atan(c/b);
      ans=90-t/(2*M_PI)*360;
   }
   else{
      double y=a*a*b-x;
      c=2*y/(a*a);
      double t=atan(c/a);
      ans=t/(2*M_PI)*360;
   }

   cout<<std::setprecision(15)<<ans<<endl;
   return 0;
}


Measured memory_bytes: 4068
#include <bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 3.14159265
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define endl '\n'
#define ff first
#define ss second
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / __gcd(a, b)
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define print(a) for(auto x : a) cout << x << " "; cout << endl;

using namespace std;

const ll inf = 1e18 + 42;

const ll M = 998244353;

ll power(ll x, ll y) {
	if (y == 0) return 1;
	if (y & 1) return (x * power(x, y - 1)) % MOD;
	ll t = power(x, y / 2);
	return (t * t) % MOD;
}

const ll MAX = 1e5 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void ahShitHereWeGoAgain()
{
	string s;
	cin >> s;
	if(s[s.size() - 1] == '0' || s[s.size() - 1] == '1' ||s[s.size() - 1] == '6' ||s[s.size() - 1] == '8')
		cout << "pon\n";
	else if(s[s.size() - 1] == '2' ||s[s.size() - 1] == '4' ||s[s.size() - 1] == '5' ||s[s.size() - 1] == '7' ||s[s.size() - 1] == '9')
		cout << "hon\n";
	else cout << "bon\n";
}

int main()
{
	DESYNC	
	ll t = 1;
	// cin >> t;
	while (t--)
		ahShitHereWeGoAgain();
	return 0;
}



Measured memory_bytes: 3648
import java.util.Scanner;
  
public class Main {
    public static int n;
    public static int q;
    public static int[] p;
    public static int[] rank;
  
    public static boolean same(int x, int y) {
        return findSet(x) == findSet(y);
    }
  
    public static void unite(int x, int y) {
        int i = findSet(x);
        int j = findSet(y);
  
        if (i == j){
        return;
    }
        if (rank[i] > rank[j]){
            p[j] = i;
        }
        else {
            p[i] = j;
            if(rank[i] == rank[j]){
            rank[j]++;
            }
        }   
    }
  
    public static int findSet(int i) {
       if(p[i] == i){ 
           return i;
        }else{
          return p[i] = findSet(p[i]);
        }
    }
  
    public static void DisjointSet() {
        p = new int[n];
        rank = new int[n];
  
        for (int i = 0; i < n; i++) {
            p[i] = i;
            rank[i] = 0;
        }
    }
  
  
    public static void main (String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        q = scanner.nextInt();
  
        DisjointSet();
        for (int i = 0; i < q; i++) {
            int com = scanner.nextInt();
            int x = scanner.nextInt();
            int y = scanner.nextInt();
  
            if (com == 0){
                unite(x, y);
            }
            if (com == 1){
                if (same(x, y)){
                    System.out.println(1);
                }else{
                    System.out.println(0);
        }
            }
        }
    }
}

Measured memory_bytes: 100644
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;
ll dp[100001][3], z[100001][3];
// ll recur(ll i, ll flag, ll ban){
// 	if(dp[i][flag] != -1)return dp[i][flag];
// 	ll x = (flag + 1)%3;
// 	ll y = (flag + 2)%3;
// 	if(ban != flag)
// 	dp[i][flag] = max(recur(i-1, flag, x) + z[i][x], dp[i][flag]);
// 	if(ban != flag)
// 	dp[i][flag] = max(recur(i-1, flag, y) + z[i][y], dp[i][flag]);
// 	if(ban != x)
// 	dp[i][flag] = max(z[i][flag] + recur(i-1, x, flag), dp[i][flag]);
// 	if(ban != y)
// 	dp[i][flag] = max(z[i][flag] + recur(i-1, y, flag), dp[i][flag]);

// 	return dp[i][flag];
// }


// This dp[i][k] mean that I am on ith level and chosing kth object so now I need to chose 
// other tow objects as my backup dp.
// Think about what each dp state means
int main(void){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,n,t,q,temp,sum=0,count=0,f=1;
    cin>>n;        
    for(i=0;i<n;i++){
    	cin>>z[i][0]>>z[i][1]>>z[i][2];
    	dp[i][0] = -1;
    	dp[i][1] = -1;
    	dp[i][2] = -1;
    }    
    dp[0][0] = z[0][0];
    dp[0][1] = z[0][1];
    dp[0][2] = z[0][2];    
    for(i=1;i<n;i++){
    	dp[i][0] = z[i][0] + max(dp[i-1][2],dp[i-1][1]);
    	dp[i][1] = z[i][1] + max(dp[i-1][0],dp[i-1][2]);
    	dp[i][2] = z[i][2] + max(dp[i-1][0],dp[i-1][1]);    	
    }
    // Below is wrong.
    // for(i=1;i<n;i++){
    // 	dp[i][0] = max(dp[i-1][0] + max(z[i][1],z[i][2]), z[i][0] + max(dp[i-1][2],dp[i-1][1]));
    // 	dp[i][1] = max(dp[i-1][1] + max(z[i][0],z[i][2]), z[i][1] + max(dp[i-1][0],dp[i-1][2]));
    // 	dp[i][2] = max(dp[i-1][2] + max(z[i][1],z[i][0]), z[i][2] + max(dp[i-1][0],dp[i-1][1]));    	
    // }
    // x = max(recur(n-1, 0, -1), max(recur(n-1, 1, -1),recur(n-1, 2, -1)));
    // for(i=0;i<n;i++){
    // 	cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<" \n";
    // 	// cout<<z[i][0]<<" "<<z[i][1]<<" "<<z[i][2]<<" \n";
    // }
    // cout<<x;

    cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}    
	

Measured memory_bytes: 4992
#include<stdio.h>
#define max 100000
int f[max];
int search(int key,int n){
  int le=0,ri,mid;
  ri=n;
  while(le<ri){
    mid=(le+ri)/2;
    if(key == f[mid])
      return 0;
    if(key>f[mid])
      le=mid+1;
    else if(key<f[mid])
      ri=mid;
  }
  return 1;  
}


main(){
  int i,j,n1,n2,s[max],count=0; 
  scanf("%d",&n1);
  for(i=0;i<n1;i++)
    scanf("%d",&f[i]);
  scanf("%d",&n2);
  for(i=0;i<n2;i++)
    scanf("%d",&s[i]);
  
  
  
  
  for(i=0;i<n2;i++)
    if(search(s[i],n1)==0)
      count++;
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1192
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int s = sc.nextInt();
        int ans = 0;
        for (int i = 0; i <= k; i++) {
            for (int j = 0; j <= k; j++) {
                int tmp = s - i - j;
                if(tmp <= k && tmp >= 0) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35728
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum[1000000], ans=INF, dp[10000][2], a[2000000],b[2000000];
string str, ss,dd;
bool f,ff;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<LL>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


int main() {
	cin >> n >> k >> q;
	rep(i, n) {
		cin >> a[i];
		v.push_back(a[i]);
	}
	sort(v.begin(), v.end());
	rep(i, v.size()) {
		LL mn = v[i];
		vector<LL>vf;
		priority_queue<LL, vector<LL>, greater<LL>> pq;
		cnt = 0;
		rep(j, n) {
			if (a[j] >= mn) {
				pq.push(a[j]);
				cnt++;
				if (cnt >= k) {
					vf.push_back(pq.top());
					pq.pop();
				}
			}
			else {
				cnt = 0;
				while (!pq.empty())pq.pop();
			}
		}
		sort(vf.begin(), vf.end());
		if (vf.size() >= q)
			ans = min(ans, vf[q-1] - mn);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int n, m;
    cin >> n >> m;
    vvi e(n, vi(n));
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        e[a][b] = 1;
        e[b][a] = 1;
    }

    vi perm(n);
    iota(all(perm), 0);

    auto check = [&]() {
        rep(i, n - 1) {
            if (!e[perm[i]][perm[i + 1]]) return false;
        }
        return true;
    };

    int ans = 0;
    do {
        if (check()) ans++;
    } while (next_permutation(all(perm)) && perm[0] == 0);

    cout << ans << endl;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

string s;
int64 dp[20][2][1000][2] = {};

int64 dfs(int32 k = 0, bool tight = 1, int32 lst = 0, int32 ok = 0){
	if(k == s.size()) return ok;
	int32 lim = (tight ? s[k]+1 : 10);
	int64 &res = dp[k][tight][lst][ok];
	if(~res) return res;
	res = 0;
	REP(i, lim){
		int32 nxt = (lst*10+i)%1000;
		if(!ok && 510 <= lst && lst < 520 && i == 3)
			res += dfs(k+1, tight && i == (lim-1), nxt, 1);
		else
			res += dfs(k+1, tight && i == (lim-1), nxt, ok);
	}
	return res;
}

int main(void){
	cin >> s;
	REP(i, s.size()) s[i] -= '0';
	memset(dp, -1, sizeof dp);
	cout << dfs() << endl;
}


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

n,a,b = map(int, input().split())

s = 0
for i in range(n+1):
    x = i//(10**4)%10 + i//(10**3)%10 + i//(10**2)%10 + i//10%10 + i%10
    if a <= x and x <= b:
        s += i
print(s)


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

int main(void) {
    int s[3];
    int sum;
    bool flag;
    scanf("%d%d%d", &s[0], &s[1], &s[2]);
    flag = false;
    sum = s[0] + s[1] + s[2];
    for(int i = 0; i < 2; i++) {
        for(int j = i + 1; j < 3; j++) {
            if(s[i] + s[j] == sum - s[i] - s[j]) {
                flag = true;
            }
        }
    }
    if(flag) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    p = []
    for i in range(M):
        p.append([B[i], C[i]])
    p.sort(reverse=True, key=lambda x: x[1])
    ret = 0
    cnt = 0
    A.sort()
    for q in p:
        while cnt < N and q[1] > A[cnt] and q[0] > 0:
            ret += q[1]
            cnt += 1
            q[0] -= 1
        if cnt >= N or (q[0] > 0 and q[1] <= A[cnt]):
            break
    if cnt < N:
        ret += sum(A[cnt:])
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]" 
    C = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 28456
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  int count=0;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
    count+=A[i];
  }
  int ave1=count/N;
  int ave2=ave1+1;
  int one=0;
  int two=0;
  for(int i=0;i<N;i++){
    one+=(ave1-A[i])*(ave1-A[i]);
    two+=(ave2-A[i])*(ave2-A[i]);
  }
  cout << min(one,two) << endl;
  return 0;
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n,k;
		cin >> n >> k;
		vector<int> h(n, 0);
		for(int i=0; i<n; i++)cin >> h[i];
		int ret = 0;
		for(int i=0; i < n; i++){
			if(h[i] >= k)ret++;
		}
		cout << ret << "\n";
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char c = sc.next().charAt(0);
		if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') System.out.println("vowel");
		else System.out.println("consonant");
	}
}

Measured memory_bytes: 21972
from collections import Counter
N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
suma = sum(A)
counter = Counter(A)
for i in range(Q):
  b,c = (int(x) for x in input().split())
  suma = counter[b]*(c-b) + suma
  print(suma)
  if b in counter:
    if c in counter:
      counter[c] += counter[b]
      counter[b] = 0
    else:
      counter[c] = counter[b]
      counter[b] = 0

Measured memory_bytes: 21280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int r = sc.nextInt();
		int s = sc.nextInt();
		int p = sc.nextInt();
		String t = sc.next();

		int ans = 0;
		char[] rivals = t.toCharArray(); // 敵の出す手
		boolean[] changed = new boolean[n]; // 変更フラグ

		for (int i = 0; i < n; i++) {
			if (i <= k - 1) {
				char winner = getWinner(rivals[i]);
				int score = getScore(winner, r, p, s);
				changed[i] = false;
				ans += score;
			} else {
				if (rivals[i] == rivals[i - k]) {
					if (!changed[i - k]) {
						ans += 0;
						changed[i] = true;
					} else {
						char winner = getWinner(rivals[i]);
						int score = getScore(winner, r, p, s);
						changed[i] = false;
						ans += score;
					}
				} else {
					char winner = getWinner(rivals[i]);
					int score = getScore(winner, r, p, s);
					changed[i] = false;
					ans += score;
				}
			}
		}

		System.out.println(ans);
		sc.close();
	}

	public static char getWinner(char hand) {
		if (hand == 'r') {
			return 'p';
		} else if (hand == 's') {
			return 'r';
		} else if (hand == 'p') {
			return 's';
		}
		return 0;
	}

	public static int getScore(char hand, int r, int p, int s) {
		if (hand == 'r') {
			return r;
		} else if (hand == 's') {
			return s;
		} else if (hand == 'p') {
			return p;
		}
		return 0;
	}

}


Measured memory_bytes: 27824
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = a[i];
	}

	sort(b.begin(), b.end());

	map<int, int> L, R;

	int id = 0;
	for (int i = 0; i < n; i++)
	{

		if (0 < i && b[i - 1] != b[i])
		{
			id = i;
		}
		L[b[i]] = id;
	}

	id = n - 1;
	for (int i = n - 1; i >= 0; i--)
	{

		if (i < n - 1 && b[i] != b[i + 1])
		{
			id = i;
		}
		R[b[i]] = id;
		//cout << R[i] << endl;
	}

	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (L[a[i]] <= i && i <= R[a[i]])
		{
			cnt++;
		}
	}

	int q;
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		if (cnt == n)
		{
			cout << i << endl;
			return 0;
		}

		int s, t;
		cin >> s >> t;
		s--;
		t--;

		if (L[a[s]] <= s && s <= R[a[s]])
		{
			cnt--;
		}

		if (L[a[t]] <= t && t <= R[a[t]])
		{
			cnt--;
		}

		swap(a[s], a[t]);

		if (L[a[s]] <= s && s <= R[a[s]])
		{
			cnt++;
		}

		if (L[a[t]] <= t && t <= R[a[t]])
		{
			cnt++;
		}
	}

	if (cnt == n)
	{
		cout << q << endl;
	}
	else
	{
		cout << -1 << endl;
	}
}


Measured memory_bytes: 33256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

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

	vector<vector<int>> C(M, vector<int>(3));
	for (int i = 0; i < M; i++)
	{
		cin >> C[i][0] >> C[i][1];
		C[i][2] = i;
	}

	sort(all(C));
	int cnt = 0, n = 0;
	for (int i = 0; i < M; i++)
	{
		if (n != C[i][0])
		{
			n = C[i][0];
			cnt = 1;
		}
		else
			cnt++;
		C[i][1] = cnt;
		int tmp = C[i][2];
		C[i][2] = C[i][0];
		C[i][0] = tmp;
	}

	sort(all(C));
	for (int i = 0; i < M; i++)
		printf("%06d%06d\n", C[i][2], C[i][1]);
}



Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a ; i<=b;i++)
using namespace std;
const int N =105;
int n;
int a[N] , b[N]  ;
int main()
{
    ios::sync_with_stdio(0)  ;
    cin.tie(0) ; cout.tie(0) ;
 //   freopen("ch.inp","r",stdin)   ;
    cin >> n ;
    FOR(i,1,n-1) cin >> b[i] ;
    int kq = b[1] + b[n-1];
    FOR(i,2,n-1)
    {
        a[i] = min(b[i-1],b[i]) ;
        kq +=a[i] ;
    }
    cout << kq;
}


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

int main() {
  int a, b;
  
  cin >> a >> b;
  
  if (a % 2 == 1 && b % 2 == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

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

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

  bool has_zero = false;
  vector<ll> A(N, 0);
  rep(i, N) {
    cin >> A[i];
    if (A[i] == 0) has_zero = true;
  }

  if (has_zero) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  rep(i, N) {
    if (A[i] > MAX / ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= A[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 4020
#include <iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<ctime>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<tuple>
#include<cassert>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<iomanip>
#include<climits>
#include<typeinfo>
#include<utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
double pi = 3.141592653589793238;
using ll = long long;
using namespace std;

ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpcombination[10000][10000];

ll modi = 1000000007;
ll combination(ll n, ll r) {
	if (n == r) { return dpcombination[n][n] = 1; }
	else if (r == 0) { return dpcombination[n][0] = 1; }
	else if (r == 1) { return dpcombination[n][1] = n; }
	else if (dpcombination[n][r]) { return dpcombination[n][r]; }
	else { return dpcombination[n][r] = combination(n - 1, r - 1) % modi + combination(n - 1, r) % modi; }
}

void clockman(int time1) {

	cout << 1.0*(clock() - time1) / CLOCKS_PER_SEC << endl;
	return;
}
//cout << fixed << setprecision(10)



int main() {
	ll n, y;
	cin >> n >> y;
	ll a, b, c;
	a = y / 10000;
	int t = 0;
	for (int i = 0;i < a + 1;i++) {
		for (int j = 0;j < n - i + 1;j++) {
			if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y) {
				t = 1;
				cout << i << " " << j << " " << n - i - j << endl;
				break;
			}
		}if (t == 1)break;
	}
		
	if (t == 0)cout << -1 << " " << -1 << " " << -1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n = in();
  map<string,int> mp;
  rep(i,n) {
    string s = in<string>();
    mp[s]++;
  }
  int mx = 0;
  for (auto p : mp) {
    chmax(mx,p.se);
  }
  for (auto p : mp) {
    if (p.se == mx) cout << p.fi << endl;
  }
  return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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 chmin(ll a, ll b){if (a>b){a = b; return true;}return false;}
void chmax(ll a, ll b){if (a<b){a = b; return true;}return false;}
*/

const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  int n; cin >>n;
  vector<int> A(100001, 0);
  // int buf;
  for (int i=0; i<n; i++){
    int buf; cin >>buf;
    A.at(buf)++;
  }
  int ans = 0;
  bool ok = false;
  for (int i=0; i<100001; i++){
    if (A.at(i) == 0) continue;
    if (A.at(i) % 2 == 1) ans++;
    else{
      if (ok){
        ans+=2; ok = false;
      }else{
        ok = true;
      }
    }
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 640
# coding: utf-8
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
    

def main():
    w,h = na()
    if w==0 and h==0:
        return 0
    field = [na() for _ in range(h)]
    checked = [[0 for _ in range(w)] for __ in range(h)]
    ans = 0
    for i in range(h):
        for j in range(w):
            if checked[i][j] == 1 or field[i][j] == 0:
                continue
            ans += 1
            que = [(j,i)]
            while que != []:
                now = que.pop(0)
                x,y = now[0],now[1]
                checked[y][x] = 1
                for dx in range(-1,2,1):
                    for dy in range(-1,2,1):
                        tmpx = x+dx
                        tmpy = y+dy
                        if 0<=tmpx and tmpx<w and 0<=tmpy and tmpy<h:
                            if field[tmpy][tmpx] == 1 and checked[tmpy][tmpx] == 0:
                                checked[tmpy][tmpx] = 1
                                que.append((tmpx,tmpy))
    print(ans)
    return 1


if __name__ == '__main__':
    while main():
        continue


Measured memory_bytes: 5640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;
    cin >> n;
    vector<int> num(n+1,0);
    For(i,1,n+1){
        for(int j=1;i*j<=n;j++){
            num[i*j]++;
        }
    }
    For(i,1,n+1) ans+=(i*num[i]);
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 42280
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <set>
#include <string>

int main() {
  char buf[4];
  scanf("%s", buf);
  std::string s = buf;

  if (s == std::string(3, 'A') || s == std::string(3, 'B')) {
    puts("No");
  } else {
    puts("Yes");
  }
}


Measured memory_bytes: 764
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int ar[n],s=0,ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
        ans+=((ar[i]*s)%mod);
        ans%=mod;
        s+=ar[i];
        s%=mod;
    }
    cout<<ans;
}

Measured memory_bytes: 5216
n,m=map(int,input().split())
s=[]
S=[]
for i in range(m):
    l,r=map(int,input().split())
    s.append(l)
    S.append(r)

if max(s)<=min(S):
    print(min(S)-max(s)+1)
else:
    print('0')


Measured memory_bytes: 10996
#include <stdio.h>

int main(void)
{

  char s[5];
  int n=0;

  fgets(s, sizeof(s), stdin);

  for (int i=0; s[i] != '\n'; i++) {
    if (s[i] == 'o') {
      ++n;
    }
  }

  printf("%d\n", 700 + (100 * n));
  
  return 0;
}


Measured memory_bytes: 128
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    L, R, d = LI()

    ans = R // d - (L - 1) // d
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10104
#include<stdio.h>
#define INFTY 1000000001
struct card{
	int num;
	char suit;
};//定义扑克牌结构体 
void merge(struct card s[],int left,int mid,int right){
	int n1=mid-left;
	int n2=right-mid;
	struct card l[n1+1],r[n2+1];
	int i,j,k;
	for(i=0;i<n1;i++)
	l[i]=s[left+i];
	for(i=0;i<n2;i++)
	r[i]=s[mid+i];
	l[n1].num =INFTY;
	r[n2].num =INFTY;
	i=0;
	j=0;
	for(k=left;k<right;k++){
		if(l[i].num<=r[j].num){
			s[k]=l[i];
			i++;
		}
		else{
			s[k]=r[j];
			j++;
		}
	}
}
void mergeSort(int s[],int left,int right){
	if(left+1<right){
		int mid=(left+right)/2;
		mergeSort(s,left,mid);
		mergeSort(s,mid,right);
		merge(s,left,mid,right);
	}
}//归并排序 
int partition(struct card a[],int p,int r) {
	int x=a[r].num;
	int i=p-1,j;
	struct card mid;
	for(j=p; j<r; j++) {
		if(a[j].num<=x) {
			i++;
			mid=a[i];
			a[i]=a[j];
			a[j]=mid;
		}
	}
	mid=a[i+1];
	a[i+1]=a[r];
	a[r]=mid;
	return i+1;
}
void quickSort(struct card a[],int p,int r){
	if(p<r){
		int q=partition(a,p,r);
		quickSort(a,p,q-1);
		quickSort(a,q+1,r);
	}
}//快速排序 
int main(){
	int n,i,t=1;
	scanf("%d",&n);
	getchar();
	struct card a[n],s[n];
	for(i=0;i<n;i++){
		scanf("%c%d",&a[i].suit,&a[i].num);
		if(i!=n-1)
		getchar();
	}//输入
	for(i=0;i<n;i++)
	s[i]=a[i];
	quickSort(a,0,n-1);
	mergeSort(s,0,n);
	for(i=0;i<n;i++){
		if(s[i].suit!=a[i].suit){
			printf("Not stable\n");
			t=0;
			break;
		}
	}
	if(t)
	printf("Stable\n");
	 for(i=0;i<n;i++){
		printf("%c %d\n",a[i].suit,a[i].num);
	}//输出 
}


Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s, t;
  cin >> s >> t;
  ll n = s.size();
  ll m = t.size();

  vector<vector<ll>> pos(32);
  rep(i, n) {
    pos[s[i]-'a'].push_back(i);
  }

  ll ans = n-1;

  rep(i, m) {
    if (pos[t[i]-'a'].size() == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  rep(i, m) {
    auto it = upper_bound(all(pos[t[i]-'a']), ans%n);
    if (it == pos[t[i]-'a'].end()) {
      ans += n-ans%n;
      ans += pos[t[i]-'a'][0];
    } else {
      ans += *it - ans%n;
    }
  }

  cout << ans-n+1 << endl;
}


Measured memory_bytes: 1736
#13:03
sx,sy,tx,ty = map(int,input().split())
raw = [[sx,sy,0]]
n = int(input()) + 2
for _ in range(n-2):
  raw.append(list(map(int,input().split())))
raw.append([tx,ty,0])
dist = []
for i in range(n):
  add = []
  for j in range(n):
    tmp = (raw[i][0]-raw[j][0])**2 + (raw[i][1]-raw[j][1])**2
    tmp **= .5
    tmp -= raw[i][2] + raw[j][2]
    if tmp < 0:
      tmp = 0
    add.append(tmp)
  dist.append(add)
#print(dist)
inf = 10**12
now = []
for i in range(n):
  now.append([dist[0][i],i])
now[0][0] = inf
for _ in range(n-1):
  d,j = min(now)
  if j == n-1:
    print(d)
  now[j][0] = inf
  for i in range(n):
    if now[i][0] == inf:
      continue
    if now[i][0] > d + dist[i][j]:
      now[i][0] = d + dist[i][j]

Measured memory_bytes: 70620
#include <iostream>
int main()
{
    int n, r, ans;
    std::cin >> n >> r ;
    if(n>10)
    {
        //内部レーティングに等しい
        ans = r;
    }
    else{
        ans = 100 * (10 - n) + r;
    }
    std::cout << ans;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int X;
    cin>>X;

    if(X<=599){
        cout<<"8"<<endl;
    }else if(X<=799){
        cout<<"7"<<endl;
    }else if(X<=999){
        cout<<"6"<<endl;
    }else if(X<=1199){
        cout<<"5"<<endl;
    }else if(X<=1399){
        cout<<"4"<<endl;
    }else if(X<=1599){
        cout<<"3"<<endl;
    }else if(X<=1799){
        cout<<"2"<<endl;
    }else
    {
        cout<<"1"<<endl;
    }
    






    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
const ll MOD=1000000007;

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    int x=B-A-1;
    if (x%2==0){
        cout << "Borys" << endl;
    }
    else {
        cout << "Alice" << endl;
    }
}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
vector<vector<ll>>next_index(string s, ll start, ll kind, bool is_loop = false){ 
  //next[i][j]i文字目(0-indexed)以降で次に文字jが出てくるindex
  //出てこない場合は-1
  ll n=s.size();
  vector<vector<ll>>next(n+1,vector<ll>(kind));
  vector<ll> p(kind,n);
  rrep(i,0,n){
    rep(j,0,kind)next[i+1][j]=p[j];
    p[s[i]-start]=i;
  }
  if(is_loop){
    rrep(i,0,n){
    rep(j,0,kind)next[i+1][j]=p[j];
    p[s[i]-start]=i;
    }
  }
  rep(i,0,kind)next[0][i]=p[i];
  return next;
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  string s;cin>>s;
  auto next=next_index(s,'a',26);
  ll n=s.size();
  vector<ll>dp(n+2,INF);
  dp[n+1]=0;
  rrep(i,0,n+1){
    rep(j,0,26)chmin(dp[i],dp[next[i][j]+1]+1);
  }
  ll now=0;
  string ret;
  //debug(dp,n+2);
  while(now!=n+1){
    rep(i,0,26){
      if(dp[now]-1==dp[next[now][i]+1]){
        now=next[now][i]+1;
        ret+=i+'a';
        break;
      }
    }
  }
  cout<<ret<<endl;
  return 0;
}

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

bool judge1(int x);
bool judge2(int x);

int main() {



  int n, x;
  cin >> n;
  for(int i = 1; i <= n; i++){
    x = i;
    if(judge1(x) || judge2(x)){
      cout << " " << i;
      continue;
    }

    while(x){
      x /= 10;
      if(judge2(x)){
        cout << " " << i;
        break;
      }
    }
  }

  cout << endl;

  return 0;  
}      

bool judge1(int x) {
  return x % 3 == 0;
}
 
bool judge2(int x) {
  return x % 10 == 3;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
#define PII pair<int, int>
#define Size(x) (int)(x.size())
using namespace std;
typedef long long LL;
//const int MOD = 1e9+7;
const auto INF = 0x3f3f3f3f;
const int N = 2e5+5;
struct node {
    int L, R;
    int l, r;
    bool operator < (const struct node &u) const {
        if(l == u.l)
            return r > u.r;
        return l > u.l;
    }
};

priority_queue<node> pri;
int dis[N], a[N];
int sum[2][N<<2], id[N];
vector<PII> answer;

void pustup(int i) {
    sum[0][i] = min(sum[0][i<<1], sum[0][i<<1|1]);
    sum[1][i] = min(sum[1][i<<1], sum[1][i<<1|1]);
}

void build(int l, int r, int i) {
    if(l == r) {
        int x;
        scanf("%d", &x);
        a[l] = x;
        dis[x] = l;
        sum[l&1][i] = x;
        sum[!(l&1)][i] = INF;
        id[x] = (l&1);
        return;
    }
    int mid = (l + r)>>1;
    build(lson);
    build(rson);
    pustup(i);
}

int query(int id, int L, int R, int l, int r, int i) {
    if(L <= l && r <= R) {
        return sum[!id][i];
    }
    int ans = INF, mid = (l + r)>>1;
    if(L <= mid)
        ans = query(id, L, R, lson);
    if(R > mid)
        ans = min(ans, query(id, L, R, rson));
    return ans;
}

int n;

void solve(int L, int R) {
    if(L > R)
        return ;
    int i = query(id[a[R]], L, R, 1, n, 1);
    int x = query(id[i], dis[i]+1, R, 1, n, 1);
    struct node temp;
    temp.L = L, temp.R = R;
    temp.l = i;
    temp.r = x;
    pri.push(temp);
}

int main() {
    scanf("%d", &n);
    build(1, n, 1);
    solve(1, n);
    while(!pri.empty()) {
        struct node temp = pri.top(); pri.pop();
        answer.push_back({temp.l, temp.r});
//        printf("L=%d R=%d l=%d r=%d\n", temp.L, temp.R, temp.l, temp.r);
        solve(temp.L, dis[temp.l]-1);
        solve(dis[temp.l]+1, dis[temp.r]-1);
        solve(dis[temp.r]+1, temp.R);
    }
    
    for(int i=0; i<Size(answer); i++) {
        printf("%d %d%c", answer[i].first, answer[i].second,
               i == Size(answer) - 1 ? '\n' : ' ');
    }
}




Measured memory_bytes: 11636
// https://nikkei2019-qual.contest.atcoder.jp/assignments
// +build ignore

package main

import (
	"fmt"
)

func main() {
	var a, b, n, xy_max, xy_min, greater_num, smaller_num int
	fmt.Scanf("%d %d %d\n", &n, &a, &b)
	if a <= b {
		xy_max = a
		smaller_num = a
		greater_num = b
	}else{
		xy_max = b
		smaller_num = b
		greater_num = a
	}
	if a + b <= n {
		xy_min = 0
	}else{
		xy_min = smaller_num - (n - greater_num)
	}
	fmt.Printf("%d %d\n", xy_max, xy_min)
}

Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){

int N,K;
int n[51][51]={};
bool F[51][51]={};

scanf("%d%d",&N,&K);

for(int i=0;i<K;i++)
{int r;
scanf("%d",&r);
for(int j=0;j<r;j++)
scanf("%d",&n[i][j]);
}
int R;
scanf("%d",&R);
int x,y;
int c=0;
for(int iii=0;iii<R;iii++){
scanf("%d%d",&x,&y);
for(int i=0;i<K;i++){
for(int j=0;j<N;j++){
	if(n[i][j]==x){
	for(int k=0;k<N;k++)
		if(n[i][k]==y){F[i][j]=true;F[i][k]=true;}
	}
	//bool FF;
	/*
	if(n[i][j]==x&&n[i][j+1]==y){F[i][j]=true;F[i][j+1]=true;}//FF=true;}
if(n[i][j]==y&&n[i][j+1]==x){F[i][j]=true;F[i][j+1]=true;}//FF=true;}

if(n[i][j]==0){
	if(n[i][j-1]==x&&n[i][0]==y){F[i][j-1]=true;F[i][0]=true;}//FF=true;}
if(n[i][j-1]==y&&n[i][0]==x){F[i][j-1]=true;F[i][0]=true;}//FF=true;}

}//if(FF)cout<<x<<" "<<y<<endl;
}
*/}
}
}
for(int i=0;i<K;i++)
{for(int j=0;j<N;j++)
	if(F[i][j]==true){c++;//cout<<n[i][j]<<"$"<<i<<"#"<<j;
//cout<<i<<"#"<<j<<"$";
}//cout<<endl;
}
printf("%d\n",c);
return 0;
}

Measured memory_bytes: 1208
#include<iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            if(i * j == N){
                cout << "Yes" << endl;
              return 0;
            }
        }
    }
  cout << "No" << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  cout << ((n < 1200) ? "ABC" : "ARC") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int sosu(int a){
    if(a==2){
        return 1;
    }
    for(int i=2;i<sqrt(a)+1;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}
vector<int> v;
int n,m,cnt=0,ans=0,aa[220000],ab[220000];
pair<int,int> pp[220000];
string s,ss[220000];
char ch;
queue<int> que;
signed main(){
    cin>>n>>m>>cnt;
    cout<<(n+m-1)/m*cnt;
}

Measured memory_bytes: 10472
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N;
    cin>>N;
    vector<int> A(N);
    rep(i,N)cin>>A.at(i);
    int p=0;
    ll money=1000,kabu=0;
    while(p<N-1){
        if(A.at(p)<A.at(p+1)){
            kabu+=money/A.at(p);
            money%=A.at(p);
            money+=kabu*A.at(p+1);
            kabu=0;
        }
        p++;
    }
    cout<<money<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

/*
LV1   BPPPB
LV2  BBPPPBPBPPPBB
LV3 BBBPPPBPBPPPBBPBBPPPBPBPPPBBB
*/
long long count(int N) {
    if (N == 1) return 5;
    else return 3 + 2 * count(N-1);
}
long long countP(int N) {
    if (N == 1) return 3;
    else return 1 + 2 * countP(N-1);
}


long long solve(int N, long long X){
    if (N == 1) {
        if (X == 2) return 1;
        if (X == 3) return 2;
        if (X >= 4) return 3;
    }
    
    long long len = count(N);
    if (X == 1) return 0;
    else if (X <= len / 2) return solve(N-1, X-1);
    else if (X == len / 2 + 1) return  countP(N-1) + 1;
    else return countP(N-1) + 1 + solve(N-1, X - count(N-1) - 2);
}

int main() {
    int N; cin >> N;
    long long X; cin >> X;
    cout << solve(N,X) << endl;
}


Measured memory_bytes: 256