akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
	for (int i = 0; i < 4; i++) {
		int t, n;

		cin >> t >> n;

		if(t == 1)
			cout << 6000 * n << endl;
		else if(t == 2)
			cout << 4000 * n << endl;
		else if (t == 3)
			cout << 3000 * n << endl;
		else if (t == 4)
			cout << 2000 * n << endl;
	}

	return 0;
}



Measured memory_bytes: 3120
s=list(input())
ss=s[:2]
sss=s[2:]
x=int("".join(ss))
y=int("".join(sss))

if 1<=x<=12 and 1<=y<=12:
    print("AMBIGUOUS")
elif 1<=x<=12 :
    print("MMYY")
elif 1<=y<=12:
    print("YYMM")
elif x==0 and y==0:
    print("NA")
elif x>=13 and y==0:
    print("NA")
elif x==0 and y>=13:
    print("NA")
elif x>=13 and y>=13:
    print("NA")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;

const long long MOD = 1000000007;

int main(){
    int x, a;
    cin >> x >> a;
    if(x < a){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define eb emplace_back

typedef long long ll;
using namespace std;

ll ans = 0;
multiset<int> sr;//right
multiset<int,greater<int>> sl;//left

void add(int a,int b){
    ans += b;
    if(sr.empty()){
        sr.insert(a);
        sl.insert(a);
        return;
    }
    int r = *sr.begin();
    int l = *sl.begin();
    if(r < a){
        ans += a - r;
        sl.insert(r);
        sr.erase(sr.begin());
        sr.insert(a);
        sr.insert(a);
    }
    else if(a < l){
        ans += l - a;
        sr.insert(l);
        sl.erase(sl.begin());
        sl.insert(a);
        sl.insert(a);
    }
    else{
        sr.insert(a);
        sl.insert(a);
    }
}
void answer(){
   cout << *sl.begin() << " " << ans << '\n';
}
int main(void){
    int query;cin >> query;
    REP(_,query){
        int q;cin >> q;
        if(q == 1){
           int a,b;cin >> a >> b;
           add(a,b);
        }else{
            answer();
        }
    }
    return 0;
}


Measured memory_bytes: 18944
import java.util.*;
	import java.math.*;
	import java.io.*;

	class Main
	{

		public static void main(String[] args)

		{
			new Main().run();
		}

		void run(){
			Scanner sc=new Scanner(System.in);
			int Q=sc.nextInt();
			long base=0;
			PriorityQueue<Long> left=new PriorityQueue<>();
			PriorityQueue<Long> right=new PriorityQueue<>();
			for(int i=0;i<Q;++i){
				int type=sc.nextInt();
				if(type==1){
					long a=sc.nextLong();
					long b=sc.nextLong();
					base+=b;
					if(left.isEmpty()&&right.isEmpty()){
						left.add(-a);
						right.add(a);
					}else if(-left.peek()==a&&right.peek()==a){
						left.add(-a);
						right.add(a);
					}else if(a<-left.peek()){
						left.add(-a);
						left.add(-a);
						base+=Math.abs(-left.peek()-a);
						right.add(-left.poll());
					}else{
						right.add(a);
						right.add(a);
						base+=Math.abs(right.peek()-a);
						left.add(-right.poll());
					}
				}else{
					System.out.println(-left.peek()+" "+base);
				}
			}
		}


		void tr(Object...objects){
			System.out.println(Arrays.deepToString(objects));
		}
	}


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

struct UnionFind{
  Int n;
  vector<Int> r,p;
  UnionFind(Int x,Int y):n(x+y),r(x+y,1),p(x+y,0){
    iota(p.begin(),p.end(),0);
    for(Int i=0;i<x;i++) r[i]=1;
    for(Int i=0;i<y;i++) r[x+i]=0;
  }
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};


template<typename T> 
map<T, Int> factorize(T x){
  map<T, Int> res;
  for(Int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;
  return res;
}

//INSERT ABOVE HERE
Int cop[2020][2020];
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end());

  vector<Int> ans(n),used(n,0),post(n,0);

  memset(cop,0,sizeof(cop));
  
  for(Int i=0;i<n;i++)
    for(Int j=0;j<n;j++)
      cop[i][j]=__gcd(a[i],a[j])>1;

  Int m=0;
  map<Int, Int> r;

  vector<vector<Int> > G(n);
  for(Int i=0;i<n;i++){
    auto x=factorize(a[i]);
    for(auto p:x){
      if(!r.count(p.first)) r[p.first]=m++;
      G[i].emplace_back(r[p.first]);
    }
  }
  
  for(Int t=0;t<n;t++){
    UnionFind uf(n,m);
    for(Int i=0;i<n;i++)
      if(!used[i]) for(Int j:G[i]) uf.unite(i,n+j);
    
    Int idx=-1;
    for(Int i=0;i<n;i++){
      if(used[i]||post[i]) continue;
      idx=i;
      break;
    }
    
    used[idx]=1;
    ans[t]=idx;
    
    for(Int i=0;i<n;i++){
      if(!uf.same(idx,i)) continue;
      if(cop[idx][i]) post[i]=0;
      else if(a[idx]<a[i]) post[i]=1;
    }
  }


  vector<Int> b(n);
  for(Int i=0;i<n;i++) b[i]=a[ans[i]];
  
  vector<vector<Int> > H(n);
  for(Int i=0;i<n;i++)
    for(Int j=i+1;j<n;j++)
      if(__gcd(b[i],b[j])>1) H[i].emplace_back(j);

  vector<Int> indeg(n);
  for(Int i=0;i<n;i++)
    for(Int j:H[i]) indeg[j]++;
  
  using P = pair<Int, Int>;
  priority_queue<P> pq;
  for(Int i=0;i<n;i++)
    if(!indeg[i]) pq.emplace(b[i],i);

  vector<Int> c;
  while(!pq.empty()){
    P p=pq.top();pq.pop();
    c.emplace_back(p.first);
    for(Int u:H[p.second]){
      indeg[u]--;
      if(!indeg[u]) pq.emplace(b[u],u);
    }
  }
  
  assert((Int)c.size()==n);
  for(Int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<c[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 46208
#include<stdio.h>

int A[20];
int n, q;

bool solve(int p, int t)
{
    if(p == n) return false;
     if(t == 0 || A[p] == t) return true;

    if(A[p] > t) return solve(p + 1, t);
    return solve(p + 1, t) || solve(p + 1, t - A[p]);
}

int main()
{
    int i, m;
    scanf("%d", &n);
    for(i = 0; i < n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &m);
        if(solve(0, m)){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = 1e9+7;
const double EPS = 1e-9;

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

  map<int, vl> G;
  int t, d;

  rep(i,n) {
    cin >> t >> d;
    G[t].push_back(d);
  }

  for (auto &p : G) sort(ALL(p.second), greater<ll>());

  priority_queue<P> next;  // P(d,t)
  for (auto &p : G) next.push(P(p.second[0], p.first));

  map<int, int> eat;  // <t, number>
  ll satisfaction = 0;

  rep(i,k) {
    tie(d,t) = next.top(); next.pop();
    ++eat[t];
    satisfaction += d;

    if (eat[t] < G[t].size()) next.push(P(G[t][eat[t]], t));
  }

  int variety = eat.size();
  satisfaction += (ll)pow(variety, 2);

  map<int, ll> bonus;
  bonus[variety] = 0;

  priority_queue<P, vector<P>, greater<P>> twice;  // P(d,t)
  int num;

  for (auto p : eat) {
    tie(t,num) = p;
    if (num != 1) twice.push(P(G[t][num-1], t));
  }

  int nt, nd;

  while (!next.empty() && !twice.empty()) {
    tie(nd,nt) = next.top(); next.pop();

    if (!eat.count(nt)) {
      tie(d,t) = twice.top(); twice.pop();
      bonus[variety+1] = bonus[variety] + (nd - d) + (variety*2 + 1);
      ++variety;
      --eat[t];

      if (eat[t] != 1) twice.push(P(G[t][eat[t]-1], t));
    }
  }

  ll increase = 0;
  for (auto p : bonus) increase = max(increase, p.second);

  ll ans = satisfaction + increase;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14324
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const ll INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

int main(){
	ll k, a, b;
	cin >> k >> a >> b;
	if(b-a>3){
		ll sum = 1;
		ll d = min(k, a-1);
		k -= d;
		sum += d;
		sum += k / 2 * (b-a);
		if(k&1)++sum;
		cout << sum << endl;
	}else{
		cout << k + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;
int a[200010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int pos[200010];
  for (int i = 0; i < N; i++) {
    pos[a[i] - 1] = i;
  }
  set<int> st;
  st.insert(-1);
  st.insert(N);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    int L = pos[i] - *(--st.lower_bound(pos[i]));
    int R = *(st.upper_bound(pos[i])) - pos[i];
    ans += (ll)L * R * (i + 1);
    st.insert(pos[i]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11264
#include <cstdio>
#include <vector>

using namespace std;

int n;
int a[400000];
int b[200001];
int nxt[400000];
vector <int> ans;

int get() {
    int p = 0, c = 0;
    
    while (1) {
        int np = nxt[p] + 1;
        
        while (np >= n) {
            np -= n;
            c++;
        }
        
        p = np;
        
        if (p == 0) return c;
    }
}

void calc(long long k) {
    int p = 0, c = 0, i;
    vector <int> ans;
    
    while (c <= k) {
        int np = nxt[p];
        int nc = c;
        
        while (np >= n) {
            np -= n;
            nc++;
        }
        
        if (nc > k) {
            ans.push_back(a[p]);
            p++;
        } else {
            p = nxt[p] + 1;
        }
        
        while (p >= n) {
            p -= n;
            c++;
        }
    }
    
    for (i = 0; i < ans.size(); i++) {
        if (i > 0) putchar(' ');
        printf("%d", ans[i]);
    }
    puts("");
}

int main() {
    int i;
    long long k;
    
    scanf("%d %lld", &n, &k);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    for (i = n; i < n * 2; i++) a[i] = a[i - n];
    
    for (i = 1; i <= 200000; i++) b[i] = -1;
    for (i = n * 2 - 1; i >= 0; i--) {
        nxt[i] = b[a[i]];
        b[a[i]] = i;
    }
    
    k %= get();
    
    calc(k - 1);
    
    return 0;
}


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

int main(){
    string s; cin >> s;
    char p = 'x';
    for(auto t : s){
        if(p == t) {
            cout << "Bad" << endl;
            return 0;
        }
        p = t;
    }
    cout << "Good" << endl;
}

Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/05/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  bool e[4] = {false,false,false,false};
  string s; cin>>s;
  for (auto c : s) {
    if (c=='N') {
      e[0]=true;
    } else if (c=='W') {
      e[1]=true;
    } else if (c=='S') {
      e[2]=true;
    } else if (c=='E') {
      e[3]=true;
    }
  }
  cout << (!(e[0]^e[2]) and !(e[1]^e[3]) ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int a,b,d,r;

double f;


scanf("%d %d",&a,&b);

if(1<=a,b<=1E+9){

d=a/b;


r=a%b;


f=(double)a/(double)b;


printf("%d %d %lf\n",d,r,f);

}

return 0;

}

Measured memory_bytes: 1064
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

# 整数の入力
#n = int(input())

# スペース区切りの整数の入力
#a = [x for x in map(int, input().split())]
n, a, b, c, d = map(int, input().split())
#print("sp", n, q, file=sys.stderr)

# 改行区切りの整数の入力
#a = []
#for x in range(m):
#  a.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]

# 文字列の入力
s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

a -= 1
b -= 1
c -= 1
d -= 1

def canswap(s, b, d):
  print("canswap", s, file=sys.stderr)
  for x in range(b, d + 1):
    #print(x, file=sys.stderr)
    prev = s[x - 1] != '#'
    curr = s[x] != '#'
    post = s[x + 1] != '#'
    print(prev, post, file=sys.stderr)
    if post and prev and curr:
      return True
  return False

def canmove(s, a, c):
  print(s, file=sys.stderr)
  if a + 1 == c:
    return s[a + 1] != '.'
  prev = s[a + 1] != '.'
  for x in range(a + 2, c):
    #print(x, file=sys.stderr)
    post = s[x] != '.'
    if post and prev:
      return False
    prev = post
      
  return True

def doit():  
  s2 = list(s)
  print(s2, file=sys.stderr)
  s2[a] = 'A'
  s2[b] = 'B'
  print('s2 ', s2, file=sys.stderr)

  res = list(s)
  res[c] = 'A'
  res[d] = 'B'
  print('res', res, file=sys.stderr)
  
  if c < d:
    if not canmove(s2, b, d):
      return False
    s2[b] = '.'
    s2[d] = 'B'
    return canmove(s2, a, c)
  else:
    if not canmove(s2, a, c):
      if not canswap(s2, b, d):
        return False
      else:
        s2[b] = '.'
        return canmove(s2, a, c)
    s2[a] = '.'
    s2[c] = 'A'
    return canmove(s2, b, d)

#print(doit([0] * 4))
#doit()
try:
  print('Yes' if doit() else 'No')
    
except Exception as e:
  print("e", e, file=sys.stderr)


Measured memory_bytes: 10128
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;

#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(10);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        if (i < n - 1) {
            cout << A[i] << " ";
        } else {
            cout << A[i] << endl;
        }
    }
}

inline void solve() {
    int n, x, t;
    cin >> n >> x >> t;

    int cur = 0;
    int res = 0;

    while (cur < n) {
        cur += x;
        res += t;
    }

    cout << res << endl;
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    int t = 1;
    // cin >> t;

    for (int _ = 0; _ < t; _++) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
//#include <algorithm>
//#include <vector>
//#include <string>
using namespace std;
//#include <stdio.h>

 
int main(void)
{
    long long k, n, sum = 0, i;
    cin >> n >> k;
    for(i = k; i <= n + 1; i++) {
        sum += ((long long)((i * (2 * n + 1 - i)) / 2) - (long long)((i * (i - 1)) / 2) + 1);
        sum = (sum % 1000000007);
    }

    cout << sum << endl;
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(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;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

int main()
{
	cout << setprecision(10);
	int n ;
	cin >> n ;
	double ans = 0 ;
	double bit = 380000;
	rep(i,n){
		double x ;
		cin >> x ;
		string u;
		cin >> u;
		if(u == "BTC"){
			ans += x * bit ;
		} else {
			ans += x;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var ab = ReadLine().Split().Select(int.Parse).ToArray();
        var a = ab[0];
        var b = ab[1];
        var c = 0;
        for (int i = 1; i <= a; i++)
        {
            for (int j = 1; j <= 12; j++)
            {
                if (i == a && j > b) break;
                if (i == j) c++;
            }
        }
        WriteLine(c);
    }
}


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

int main()
{
	int N, Q;
	scanf("%d%d", &N, &Q);
	std::string S;
	std::cin >> S;
	std::vector<int> AC(N);
	for (int i{1}; i < N; i++)
		if (S[i - 1] == 'A' && S[i] == 'C')
			AC[i] = 1;
	for (int i{}; i < N - 1; i++)
		AC[i + 1] += AC[i];
	for (int i{}; i < Q; i++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		r--; l--;
		printf("%d\n", AC[r] - AC[l]);
	}

	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 100000000000000009
#define int long long
using P = pair<int,int>;
signed main(){
  map<int,int> IN{};
  map<int,int> OUT{};
  int n;
  cin >> n;
  rep(i,n){
    int d;
    cin >> d;
    IN[d]++;
  }
  int m;
  cin >> m;
  rep(i,m){
    int t;
    cin >> t;
    OUT[t]++;
  }
  bool flag = true;
  for(auto p: OUT){
    int key = p.first;
    int value = p.second;
    if(value > IN[key]) flag = false;
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 25216
import sys

sys.setrecursionlimit(100000)
input=lambda : sys.stdin.readline().rstrip('\n')

n=int(input())
g=[[]for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    g[a-1].append((c,b-1))
    g[b-1].append((c,a-1))

def dijkstra(g,st):
    from heapq import heappush, heappop, heapify
    inf=10**18
    dist=[inf for i in range(len(g))]
    visited=[False for i in range(len(g))]
    dist[st]=0
    que=[]
    heappush(que,(0,st))
    while que:
        c,v=heappop(que)
        if visited[v]:
            continue
        visited[v]=True
        for x in g[v]:
            tmp=x[0]+c
            if tmp<dist[x[1]] and not visited[x[1]]:
                dist[x[1]]=tmp
                heappush(que,(tmp,x[1]))
    return dist

q,k=map(int,input().split())
dist=dijkstra(g,k-1)

for i in range(q):
    x,y=map(int,input().split())
    print(dist[x-1]+dist[y-1])


Measured memory_bytes: 82184
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
ans = 0
if 1 in A:
    num = A.index(1)
    ans += num
    A = A[num:]
else:
    print(-1)
    exit()
f = 0
#print(A,ans)
for i in range(2,n+1):
    try:
        d = A.index(i,f)
    except ValueError:
        ans += len(A[f+1:])
        print(ans)
        exit()
    ans += d - f - 1
    f = d
print(ans)

Measured memory_bytes: 26140
import sys
#import time
#import copy
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
import heapq
import time

start = time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

n = ri()
a=[rl() for _ in range(n)]
c=[[0]*n for _ in range(n)]



for k in range(n):
    for i in range(n):
        for j in range(n):
            if k==i or k==j or i==j:
                continue
            if a[i][j]==a[i][k]+a[k][j]:
                c[i][j]+=1
            if a[i][j]>a[i][k]+a[k][j]:
                print(-1)
                sys.exit()
            a[i][j]=min(a[i][j], a[i][k]+a[k][j])
ans=0
for i in range(n):
    for j in range(i+1,n):
        if c[i][j]==0:
            ans+=a[i][j]
print(ans)

Measured memory_bytes: 46552
import heapq

N, M = map(int, input().split())
cards = list(map(int, input().split()))
ops = [tuple(map(int, input().split())) for i in range(M)]
cards = sorted(cards)
ops = sorted(ops, key=lambda x:-x[1])
comp = []
for b, c in ops:
    if(len(comp)>=N):
        break
    comp += [c]*b
comp += [0] * (N-len(comp))
ans = 0
for i in range(N):
    if(comp[i]>=cards[i]):
        ans += comp[i]
    else:
        ans += cards[i]

print(ans)

Measured memory_bytes: 26472
n, m = map(int, input().split())
dat = [0] * (n+10)
for _ in range(m):
    a,b = map(int, input().split())
    dat[a] += 1
    dat[b] += 1
can = True
for i in range(n):
    if dat[i] % 2 == 1:
        can = False
print("YES" if can else "NO")

Measured memory_bytes: 75264
#include <stdio.h>
#include <stdlib.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node *NODE;
#define NIL NULL
NODE root;
NODE min(NODE);
NODE max(NODE);
NODE search(NODE,int);
NODE successor(NODE);
void delete(NODE);
void insert(int);
void inorder(NODE);
void preorder(NODE);
int main(){
  int n, i, x;
  char com[20];
  NODE t;
  scanf("%d", &n);

  for (i=0;i<n;i++){
    scanf("%s", com);
    if (com[0]=='f'){
      scanf("%d", &x);
      t = search(root, x);
      if (t != NIL) printf("yes\n");
      else printf("no\n");
    } else if (com[0]=='i'){
      scanf("%d", &x);
      insert(x);
    } else if (com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if (com[0]=='d'){
      scanf("%d", &x);
      delete(search(root, x));
    }
  }
  return 0;
}
NODE min(NODE x){
}
NODE max(NODE x){
}
NODE search(NODE x,int k){
}
NODE successor(NODE x){
}
void delete(NODE x){
}
void insert(int k){
  NODE y = NIL;
  NODE x = root;
  NODE z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key)x=x->left;
    else x=x->right;
  }
    z->parent=y;
    if(y==NIL)root=z;
    else if(z->key < y->key)y->left=z;
    else y->right=z;
}
void inorder(NODE x){
if(x->left!=NIL && x->right!=NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  
  }
  if(x->left!=NIL && x->right==NIL){
   inorder(x->left);
     printf(" %d",x->key);  
  }
  
  if(x->right!=NIL && x->left==NIL){
  printf(" %d",x->key);
  inorder(x->right); 
  
  }
  if(x->left==NIL && x->right==NIL)printf(" %d",x->key);
}
void preorder(NODE x){
printf(" %d",x->key);
  if(x->left!=NIL){
    preorder(x->left);
  }
  if(x->right!=NIL){
    preorder(x->right);
  }
}



Measured memory_bytes: 25220
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let coffee: Vec<char> = s.trim().chars().collect();

    if coffee[2] == coffee[3] && coffee[4] == coffee[5] {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import java.io.InputStreamReader;
import java.util.Scanner;

import static java.lang.Math.max;


public class Main {


    int MAXN = (int) (2 * 1e5 + 10);

    int N;
    long[] bit = new long[MAXN];
    int[] h = new int[MAXN];
    int[] a = new int[MAXN];
    long[] dp = new long[MAXN];

    int LSOne(int S) {
        return S & -S;
    }

    void update(int x, long val) {
        while (x <= N) {
            bit[x] = max(bit[x], val);
            x += LSOne(x);
        }
    }

    long query(int x) {
        long ans = 0;
        while (x > 0) {
            ans = max(ans, bit[x]);
            x -= LSOne(x);
        }
        return ans;
    }


    int go() {
        Scanner scanner = new Scanner(new InputStreamReader(System.in));
        N = scanner.nextInt();


        for (int i = 1; i <= N; i++) {
            h[i] = scanner.nextInt();
        }
        for (int i = 1; i <= N; i++) {
            a[i] = scanner.nextInt();
        }
        for (int flower = 1; flower <= N; flower++) {
            dp[flower] = query(h[flower] - 1) + a[flower];
            update(h[flower], dp[flower]);
        }
        long best = 0;
        for (int i = 0; i <= N; i++) {
            best = max(best, dp[i]);

        }
        System.out.printf("%d\n", best);
        return 0;
    }


    public static void main(String[] args) {

        Main f = new Main();
        f.go();

    /*
    4
3 1 4 2
10 20 30 40
answer : 60

     */
    }
}

Measured memory_bytes: 110600
import java.util.Scanner;
public class Main
{
	double[][] dp;
	boolean[][] used;
	int N,T,L,B;
	int[] LB;
	public void solve()
	{
		Scanner cin = new Scanner(System.in);
		while(true)
		{
			N = cin.nextInt();
			T = cin.nextInt();
			L = cin.nextInt();
			B = cin.nextInt();
			if(N + T + L + B == 0)break;
			LB = new int[N + 1];
			dp = new double[T + 1][N + 1];
			used = new boolean[T + 1][N + 1];
			for(int i = 0;i < L;i++)LB[cin.nextInt()] = 'L';
			for(int i = 0;i < B;i++)LB[cin.nextInt()] = 'B';
			dp[0][0] = 1.0;
			for(int i = 0;i < T;i++)
			{
				for(int j = 0;j < N;j++)
				{
					for(int k = 1;k <= 6;k++)
					{
						int next = j + k;
						if(next > N)next = N - (next - N);
						if(LB[next] == 'L')
						{
							if(i + 2 <= T)dp[i + 2][next] += dp[i][j] * 1.0 / 6.0;
							else dp[i + 1][next] += dp[i][j] * 1.0 / 6.0;
						}else if(LB[next] == 'B')
						{
							dp[i + 1][0] += dp[i][j] * 1.0 / 6.0;
						}else
						{
							dp[i + 1][next] += dp[i][j] * 1.0 / 6.0;
						}
					}
				}
			}
			double ans = 0.0;
			for(int i = 0;i <= T;i++)
			{
				ans += dp[i][N];
			}
			System.out.println(String.format("%.6f",ans));
		}
	}
	public static void main(String[] args)
	{
		new Main().solve();
	}
}

Measured memory_bytes: 30108
def main():
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = 10**9
    for i in range(N):
        cnt = 0
        while A[i] % 2 == 0:
            A[i] = A[i] >> 1
            cnt+=1
        ans = min(ans, cnt)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
#[allow(dead_code)]
struct Main {}

#[allow(dead_code)]
impl Main {}

fn main() {
    let n = read::<usize>();
    let mut m = HashMap::new();
    for _ in 0..n {
        let s = read::<String>();
        m.insert(s, "");
    }
    println!("{}", m.len());
}


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

int main(){
  int a,b; cin >> a >> b;
  if (a > b){
    for(int i = 0; i < a; i++){
    cout << b;
    }
  }
  else {
    for(int i = 0; i < b; i++){
    cout << a;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
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(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    ll r,D,x;
    cin >> r >> D >> x;
    rep(i,10){
        x = r * x - D;
        cout << x << endl;
    }
    return 0;
}

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

int main() {
		/* 変数の定義 */
	char s[5];
	char *p;
		scanf("%s", &s,5);
		p = strchr(s, 'B');
		if (p == NULL)printf("ABC");
		else printf("ARC");

		return 0;
}

Measured memory_bytes: 1732
#include <cstdio>

int main(){
    int H,W;
    for(int x = 0;;x++){
        scanf("%d%d",&H,&W);
        if(H != 0&&W != 0){
            for(int i = 0;i < W;i++){
                printf("#");
            }
            printf("\n");
            for(int j = 0;j < H - 2;j++){
                printf("#");
                for(int k = 0;k < W - 2;k++){
                    printf(".");
                }
            printf("#\n");
            }
            for(int i = 0;i < W;i++){
                printf("#");
            }
        printf("\n\n");
        continue;
        }
        break;
    }
    return 0;
}    


Measured memory_bytes: 2592
from itertools import accumulate
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**10
from functools import reduce

N, W = map(int, input().split())
w, v = [], []
for _ in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

memo = {}

def nap(i, j):# // i番目までの品物から重さの和がj以下なるように選んだときの、取りうる価値の総和の最大値を返す関数
    if i == 0:
        return 0

    if (i, j) in memo:
        return memo[i, j]
    elif j < w[i-1]:
        temp = nap(i-1, j)
    else:
        temp = max(nap(i-1, j), nap(i-1, j-w[i-1]) + v[i-1])

    memo[i,j] = temp

    return memo[i,j]

print(nap(N, W))

Measured memory_bytes: 59224
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <ll, pair <ll, ll>>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 1e6 + 10;

ll n, m, k, t;

ll A[maxn];

vector <ll> bad;

bool good(ll i) {
    ll x = lower_bound(all(bad), i - k + 2) - bad.begin();
    ll y = lower_bound(all(bad), i + 1) - bad.begin();
    return x == y;
}

int main() {
    pyshnapyshnakaa;
    ll q, w, e, a, b, c;
    cin >> n >> k;
    for (q = 0; q < n; q++) {
        cin >> A[q];
    }
    for (q = 1; q < n; q++) {
        if (A[q] < A[q - 1]) {
            bad.pb(q);
        }
    }
    set <ll> S;
    for (q = 0; q < k; q++) {
        S.insert(A[q]);
    }
    bool found_good = good(k - 1);
    ll ans = 1;
    for (q = k; q < n; q++) {
        S.insert(A[q]);
        S.erase(A[q - k]);
        if (good(q)) {
            // cout << q << endl;
            if (!found_good) {
                found_good = 1;
                ans++;
            }
            continue;
        }
        // cout << (*S.begin()) << " " << (*(--S.end())) << endl;
        if ((*S.begin()) < A[q - k] || (*(--S.end()--) != A[q])) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 15056
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

	int N, K;
	cin >> N >> K;
	vector<int> x(N);
	int res = 0;
	REP(i, N) {
		cin >> x[i];
		res += 2 * min(x[i], abs(x[i] - K));
	}
	cout << res << "\n";


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void) {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if((0 <= x - r) && (x + r <= W)) {
        if((0 <= y - r) && (y + r <= H))
            cout << "Yes" << endl;
        else
            cout << "No" <<endl;
    } else
        cout << "No" <<endl;

    return 0;

}


Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>

int main () {
    int k, s;
    std::cin >> k >> s;

    int z;
    int ans = 0;
    for (int x = 0; x <= k; x++)
    {
        for (int y = 0; y <= k; y++) {
            z = s - x - y;

            if(z >= 0 && z <= k) {
                ans++;
            }
        }
    }

    std::cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve() {
    str s;
    ll k;
    cin >> s >> k;
    vector<str> valids;
    for (int l = 1; l <= k; l++)
    {
        for (int st = 0; st <= (ll)s.size() - l; st++)
        {
            str t = s.substr(st, l);
            valids.push_back(t);
        }
    }
    UNIQ(valids);
    cout << valids[k - 1] << endl;
}

int main() {
    FIO;
    solve();
    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int cnt=0;
	string ans="No"s;
	for(int i=0;i<n;++i){
		int d1,d2; cin>>d1>>d2;
		if(d1==d2)++cnt;
		else cnt=0;
		if(cnt==3){
			ans="Yes"s;
			break;
		}
	}
	cout<<ans<<"\n"s;
}


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

int main() {
    int n;cin >> n;
    int H[n];
    rep(i,n) cin >> H[i];
    int max = H[0];
    int ans = 0;
    repd(i,1,n){
        if(H[i]>=max){
            max = H[i];
            ans++;
        }
    }
    cout << ans + 1 << endl;
}

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

if a[0] == 0:
    print(0)
    exit()
    
x = 10 ** 18
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > x:
        print(-1)
        exit()
        
print(ans)

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

const int maxn = 200009;
LL s[maxn], ans = 1e18;
int n, a;

int main(){
	scanf("%d", &n);
	for (int i=1; i<=n; i++){
		scanf("%d", &a);
		s[i] = s[i-1] + a;
	}
	for (int i=1; i<=n-1; i++)
		ans = min(ans, abs(s[n]-2*s[i]));
	printf("%lld\n", ans);
	return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;
vector<int> prime;
vector<int> isPrime(1e6+1, 1);
void make_prime(){
  int maxp = 1e6;
  FOR(i, 2, 1e6+1){
    if(!isPrime[i]) continue;
    prime.push_back(i);
    for(int j = 2; j * i <= maxp; j++){
      isPrime[j*i] = 0;
    }
  }
}
int main(){
  make_prime();
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
  }
  int all_gcd = A[0];
  REP(i, N){
    all_gcd = gcd(all_gcd, A[i]);
  }
  map<int, int> l;
  bool isPair = true;
  REPR(i, N-1){
    for(int x = 0; prime[x] * prime[x] <= A[i]; x++){
      int p = prime[x];
      if(A[i] % p == 0 && l[p]){
        isPair = false;
      }
      while(A[i] % p == 0){
        l[p]++;
        A[i]/=p;
      }
    }
    if(A[i] != 1){
      if(l[A[i]]){
        isPair = false;
      }
      // cout << A[i] << endl;
      assert(isPrime[A[i]]==1);
      l[A[i]]++;
    }
    if(!isPair) break;
  }
  if(isPair){
    assert(all_gcd==1);
    cout << "pairwise coprime" << endl;
  }
  else if(all_gcd ==  1){
    cout << "setwise coprime" << endl;
  }
  else{
    cout << "not coprime" << endl;
  }
  return 0;
}


Measured memory_bytes: 11628
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

void solve() {
	
	LL n;inl(n);
	LL a[n];
	for(LL i=0;i<n;i++) inl(a[i]);
	
	LL m = 1000;
	for(LL i=1;i<n;i++) {
		if(a[i] > a[i-1]) {
			LL t = m / a[i-1];
			m = m % a[i-1];
			m += t*a[i];
		}
	}
	cout<<m<<en;
}

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


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

int main() {
    vector<int> ab(2);
    cin >> ab[0] >> ab[1];
    for (int i = 1; i <= 3; i++) {
        auto res = find(ab.begin(), ab.end(), i);
        if (res == ab.end()) {
            cout << i << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
ll N;
ll ans = 0;
void dfs(ll a,int u3,int u5,int u7){
	if (a > N)return;//はみ出した時
	if (u3 == 1 && u5 == 1 && u7 == 1){
		ans++;//はみ出さずに3,5,7のすべてを使った
	}
	dfs(a*10+7,u3,u5,1);
	dfs(a*10+5,u3,1,u7);
	dfs(a*10+3,1,u5,u7);
}

int main(){
	cin >> N;
	dfs(0,0,0,0);
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define  ff first
#define  ss second

int main(){
    int a,b,x;
    cin>>a>>b>>x;
    if(a+b>=x&&a<=x)
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
w,h,n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
W = [0,w]
H = [0,h]
for x,y,a in xya:
    if a == 1:
        W[0] = max(W[0],x)
    elif a == 2:
        W[1] = min(W[1], x)
    elif a == 3:
        H[0] = max(H[0],y)
    else:
        H[1] = min(H[1], y)

print((W[1]-W[0])*(H[1]-H[0]) if W[0]<W[1] and H[0]<H[1] else 0)

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

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

using namespace std;


int main(){
	int n;
	string s;
	cin>>n>>s;
	rep(i,s.size()){
		int x=(s[i]-'A'+n)%26;
		s[i]='A'+x;
		cout<<s[i];
	}
	cout<<endl;
	return 0;
}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60, lmod = 1e9+7;

const int MAX_N = 2003;
int a[MAX_N],dp[MAX_N];

int main(){
  int N,Z,W; cin >> N >> Z >> W;
  rep(i,N) scanf("%d",a+i);
  if(N!=1) cout << max(abs(a[N-1]-W),abs(a[N-1]-a[N-2])) << endl;
  else cout << abs(a[0]-W) << endl;
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int mod = 998244353, maxn = 3010;
int dp[maxn][maxn];

void solve(){
	
	int n, s;
	cin >> n >> s;
	
	vector<int> a(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];
	
	
	dp[0][0] = 1;
	for(int pos = 0; pos < n; pos++){
		for(int soma = 0; soma <= s; soma++){
			if(soma + a[pos] <= s){
				dp[pos+1][soma+a[pos]] += dp[pos][soma];
				dp[pos+1][soma+a[pos]] %= mod;
			}
			
			dp[pos+1][soma] += 2*dp[pos][soma];
			dp[pos+1][soma] %= mod;
		}
	}
	
	cout << dp[n][s] << endl;
}

int32_t main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	int tc = 1;
	//cin >> tc;
	while(tc--)
		solve();
}


Measured memory_bytes: 74164
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
#include <stdio.h>
#include <math.h>
int main(){
  int N;
  cin >> N;
  int w[N];
  int M = 0;
  int ans = 10000000;
  rep(i,N){
    cin >> w[i];
    M+=w[i];
  }
  int temp = 0;
  int ave = M/2;
  rep(i,N){
    temp += w[i];
    ans = abs(min(ans,abs(M - temp - temp)));
  }
  cout << ans << endl;
  return 0;
}



// ./compile.sh main


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

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

int main(){
  int n;
  cin >> n;
  ll t;
  ll ans=1;
  rep(i,n){
    cin >> t;
    ans = ans*(t/gcd(t,ans));
  }
   
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 256
N,Q=map(int,input().split())
S=input()
L=[0]*N
p=S[0]
for i in  range(1,N):
  L[i]+=L[i-1]
  if p+S[i]=='AC':
    L[i]+=1
  p=S[i]
for _ in range(Q):
  i,j=map(int,input().split())
  print(L[j-1]-L[i-1])


Measured memory_bytes: 77552
// In the name of God

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define Size(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<int , int>pii;
const int INF = 1e9 + 10;

int main(){
	ios_base :: sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	int q;cin>>q;
	while(q--){
		int L , R;cin>>L>>R;
		if(L > R) swap(L , R);
		if(L * R == 1){
			cout << 0 << '\n';
			continue;
		}
		int ans = L-1;
		
		int bl = 0, br = INF;
		while(bl ^ br){
			int mid = bl+br+1>>1;
			if(1ll * min(R-1 , (L+mid+1)/2) * (L+mid+1-min(R-1 , (L+mid+1)/2)) < 1ll * L * R)
				bl = mid;
			else br = mid-1;
		}
		ans += bl;
		cout << ans << '\n';
	}
	return 0;
}


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

typedef long long int ll;

int main(void){
    // Your code here!
    int n;
    cin>>n;
    int p[10][10];
    for(int i=0;i<10;i++){
        for(int k=0;k<10;k++){
            p[i][k]=0;
        }
    }
    for(int i=1;i<=n;i++){
        int ci=i;
        int tmp=ci%10;
        while(ci>=10){
            ci/=10;
        }
        p[ci][tmp]++;
    }
    int sum=0;
    for(int i=0;i<10;i++){
        for(int k=0;k<10;k++){
            sum+=p[i][k]*p[k][i];
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const ll INF = (1LL << 31) - 1;
const double pi=acos(-1);

int main(){
  ll x,y;
  cin >> x >> y;
  if(abs(x-y)<=1)cout<<"Brown"<<endl;
  else cout<<"Alice"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
pair<vl,vb> eratosthenes_sieve(ll n){
  vb is_prime(n+1,true);
  vl prime;
  is_prime[0] = false;
  is_prime[1] = false;
  FOR(i,2,sqrt(n)+1){
    if(!is_prime[i]) continue;
    for(ll j=2*i;j<=n;j+=i) is_prime[j] = false;
    prime.eb(i);
  }
  return {prime,is_prime};
}
signed main(){
  int n;
  cin >> n;
  vb isp = eratosthenes_sieve(1e8).second;
  int ans = 0;
  REP(i,n){
    int a;
    cin >> a;
    if(isp[a]) ans++;
  }
  cout << ans << endl;
}




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

using namespace std;
typedef long long ll;
typedef long double ld;
#define X first;
#define Y second;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 2e5 + 10;
const int maxK = 1e4+10;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 998244353;

ll a[maxN];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);	
	}
	ll ans = 0;
	for(int i=2;i<=n;i++)
	{
		if(a[i-1] > a[i])
		{
			ans += abs(a[i]-a[i-1]);
			a[i] = a[i-1];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5320
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>
#include <utility>

typedef long long Int;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
#define REPS(a,i,n) for(int i = a ; i < n ; ++i)
using namespace std;

int dosu[6];

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

	REP(i, n){
		double a;
		cin >> a;
		if (a < 165)
			dosu[0]++;
		else if (a < 170)
			dosu[1]++;
		else if (a < 175)
			dosu[2]++;
		else if (a < 180)
			dosu[3]++;
		else if (a < 185)
			dosu[4]++;
		else
			dosu[5]++;
	}

	REPS(1, i, 7){
		cout << i << ":";
		REP(j, dosu[i - 1]){
			cout << "*";
		}
		cout << endl;
	}


	return 0;
}

Measured memory_bytes: 1236