akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int N;
  ll A, ans = 1;

  scanf("%d", &N);

  ll e18 = 1'000'000'000'000'000'000LL;

  for (int i = 0; i < N; i++) {
    scanf("%lld", &A);
    if (A == 0) {
      ans = 0;
      break;
    }
    if (e18 / A < ans) ans = -1;
    if (ans != -1) ans *= A;
  }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 3836
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if (A == 7 && B == 5 && C == 5)cout << "YES" << endl;
    else if (B == 7 && A == 5 && C == 5)cout << "YES"<<endl;
    else if (C == 7 && B == 5 && A == 5)cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
import Data.List

main :: IO ()
main = do
  n <- read <$> getLine :: IO Int
  ns <- map read . words <$> getLine :: IO [Int]
  print $ solve ns

solve :: [Int] -> Int
solve ns = foldl (\acc a -> acc + (snd a - fst a)) 0 lss
  where
    ls = sort ns
    lss = zip ls (tail ls)


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

int main(){ 
double R, l;
cin >> R;

l = 2 * R * 3.1415926535;

std::setprecision(4);

cout << l << endl;
}

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

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0); //cinとcoutの同期切り
    ios::sync_with_stdio(false); //iostreamとstdioの同期切り

    int N;
    string S;
    cin >> N >> S;
    int ans = 0;

    for(int spl = 1; spl < N; ++spl){   //区切りを1つずつずらす(後半が始まる場所)
        bool alpha1[30] = {false}, alpha2[30] = {false};
        
        for(int c = 0; c < N; ++c){
            if(c < spl){
                alpha1[0 + (S[c]-'a')] = true;
            }
            else{
                alpha2[0 + (S[c]-'a')] = true;
            }
        }
        int cnt = 0;
        for(int i = 0; i < 30; ++i){
            if(alpha1[i] && alpha2[i]) cnt++;
        }
        ans = max(ans, cnt);
    }

    cout << ans << endl;

    return 0;
}

/*****************************************************************************/
/*****   1秒間で処理できるfor文ループの回数                                 *****/
/*****   → 10^8 = 100,000,000 回程度                                      *****/
/*****                                                                   *****/
/*****   sort(a, a+N, greater<int>()); // a[0:N) を大きい順にソート        *****/
/*****                                                                   *****/
/*****                                                                   *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3"                *****/
/*****   std::cout << std::fixed;                                        *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3.00"             *****/
/*****                                                                   *****/
/*****************************************************************************/

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    string s;
    cin >> s;
    ll n = s.size();
    if(s.front() != '1' || s.back() != '0'){
        cout << -1 << endl;
        return 0;
    }
    s = '.' + s;
    for(i = 1;i < n;++i){
        if(s.at(i) != s.at(n-i)){
            cout << -1 << endl;
            return 0;
        }
    }
    s.at(n) = '1';
    queue<ll> que;
    for(i = 1;i <= n;++i){
        if(s.at(i) == '1') que.push(i);
    }
    for(i = 1;i < n;++i){
        if(i == que.front()) que.pop();
        cout << i << " " << que.front() << endl;
    }

    return 0;
}

Measured memory_bytes: 4552
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    int j;
    for(int i = 0; i < N; i++){
        if(a[i] == 1) j = i;
    }
    int count = 0;
    int t;
    if(j % (K - 1) == 0){
        count += j / (K - 1);
        t = j;
    } 
    else{
        count += j / (K - 1) + 1;
        t = count * (K - 1);
    }
    if(t < N){
        if((N - 1 - t) % (K - 1) == 0) count += (N - 1 - t) / (K - 1);
        else count += (N - 1 - t) / (K - 1) + 1;
    }
    cout << count << endl;
}

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

typedef long LONG;

LONG memo[10][1001][101];

LONG comb(int n, int s, int m)
{
	int i;
	LONG c;

// printf("<%d %d %d>\n", n, s, m);
    
	if (memo[n][s][m] != -1){
		return (memo[n][s][m]);
	}
	
	if (n == 1){
    	if (0 <= s && s <= 100 && s >= m){
//			printf("[");
//			for (i = 0; i <= 100; i++){
//				printf("%d ", i);
//			}
//			printf("%d]", s);

			memo[n][s][m] = 1;
			return (1);
		}
		memo[n][s][m] = 0;
		return (0);
	}
	
	c = 0;
	for (i = m; i <= 100; i++){
		if (s - i >= 0){
			c += comb(n - 1, s - i, i + 1);
		}
	}
	
	memo[n][s][m] = c;
	return (c);
}

int main(void)
{
	int n, s;
	int c;
	int i;
	
    
	while (1){
		scanf("%d%d", &n, &s);
		if (n == 0 && s == 0){
			break;
		}
		memset(memo, -1, sizeof(memo));

		printf("%ld\n", comb(n, s, 0));
	}
	
	return (0);
}

Measured memory_bytes: 8504
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int r, c, k;
    cin >> r >> c >> k;

    vector<vector<int>> g(r + 1, vector<int>(c + 1, 0));
    for (int i = 0; i < k; i++) {
        int ri, ci, v;
        cin >> ri >> ci >> v;
        g[ri - 1][ci - 1] = v;
    }

    vector<vector<vector<long long>>> dp(r + 1, vector<vector<long long>>(c + 1, vector<long long>(4, 0)));
    for (int i = 0; i <= r; i++) {
        for (int j = 0; j <= c; j++) {
            for (int l = 0; l <= 3; l++) {
                if (j + 1 <= c) {
                    dp[i][j + 1][l] = max(dp[i][j + 1][l], dp[i][j][l]);
                }
                if (j + 1 <= c && l + 1 <= 3) {
                    dp[i][j + 1][l + 1] = max(dp[i][j + 1][l + 1], dp[i][j][l] + g[i][j]);
                }
                if (i + 1 <= r) {
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][l]);
                }
                if (i + 1 <= r && l + 1 <= 3) {
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][l] + g[i][j]);
                }
            }
        }
    }

    cout << *max_element(dp[r][c].begin(), dp[r][c].end()) << endl;
}


Measured memory_bytes: 671816
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

int main(){

    int N;
    cin >> N;
    vector<int> x(N);
    rep(i, N)cin >> x[i];
    int L, Q;
    cin >> L >> Q;

    vector<vector<int>> canmove(N, vector<int>(20));
    rep(i, N)canmove[i][0] = upper_bound(all(x), x[i] + L) - x.begin() - 1;
    rep(j, 19)rep(i, N)canmove[i][j + 1] = canmove[canmove[i][j]][j];

    rep(loop, Q){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if(a > b)swap(a, b);
        int ans = 0;
        for(int i = 19; i >= 0; i--){
            if(canmove[a][i] < b){
                ans += 1 << i;
                a = canmove[a][i];
            }
        }
        if(a != b)ans++;
        cout << ans << endl;
    }

}

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

long long max(long long a, long long b) {
  if (a < b) return b;
  else return a;
}

int main() {
  int N;
  long W;
  cin >> N >> W;
  long w[N], v[N];
  vector<vector<long long>> dp(N+1, vector<long long>(W+1));
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
    for (long j = 0; j <= W; j++) {
      if (j - w[i] >= 0) dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
      else dp[i+1][j] = dp[i][j];
    }
  }
  
  cout << dp[N][W];
  
  return 0;
}

Measured memory_bytes: 82992
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define double long double
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1e5+10
#define mod 1e9 + 7
#define pii pair<int,int>
using namespace std;
const int N = 1e5 + 1;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
double dp[(int)3e3+10][(int)3e3+10];
bool visit[(int)3e3+10][(int)3e3+10];
double v[(int)3e3+10];
double brute(int indx,int head){
	if(indx == n){
		if(2*head >= n){
			return 1;
		}
		return 0;
	}
	double &ans = dp[indx][head];
	if(visit[indx][head]){
		return ans;
	}
	visit[indx][head] = 1;
	ans = (brute(indx+1,head+1)*v[indx])+(brute(indx+1,head)*(1-v[indx]));
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	double ans = brute(0,0);
	cout<<fixed<<setprecision(10)<<ans;
    return 0;
}
//.........

Measured memory_bytes: 150400
#include <iostream>
using namespace std;
int main(void){
    int e1, e2, e3, e4; //４本の棒の長さ

    cin >> e1 >> e2 >> e3 >> e4;
    if((e1 == e2 && e3 == e4) || (e1 == e3 && e2 == e4) || (e1 == e4 && e2 == e3) || (e1 == e2 && e2 == e3 && e3 == e4 && e4 == e1))
        cout << "yes" << endl;
    else
        cout << "no" << endl;
}



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

int main() {
  int K,S,ans=0;
  cin >> K >> S;

  if(3*K < S){  cout << 0 << endl; return 0;}
  for (int i = 0; i <= K; i++) {
    if(2*K >= S-i){
        for (int j = 0; j <= K; j++) {
              if(K >= S-i-j && S-i-j >= 0){ans++;}
        }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    ll N, K, h, cnt = 0;
    cin >> N >> K;
    rep(i, N)
    {
        cin >> h;
        if (K <= h)
            cnt++;
    };
    cout << cnt << endl;

    return 0;
}


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

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	for(int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	long long normal = 0, pairs = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < i; j++) {
			if(a[i] < a[j]) {
				normal++;
			}
			if(a[i] != a[j]) {
				pairs++;
			}
		}
	}
	const int MOD = 1e9 + 7;
	std::cout << (normal * k + pairs * k % MOD* (k-1) % MOD * ((MOD+1)/2)) % MOD << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define pint pair<lli,lli>
#define Lower(v,X) lower_bound(v.begin(),v.end(),X)-v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
map<lli,int>prime_factor(lli n){
  map<lli,int>res;
  for(lli i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}
int main(){
  lli A,B,C,D,E,L,R,X,Y,W,H,N,M,K,sum=0,num=0,flag=0;string S,T;
  cin >> N >> X;
  sum=1;
  auto P=prime_factor(X);
  for(pint v:P){
    //if(v.second>N-1)cout << v.first << " " << v.second << endl;
    if(v.second>N-1)sum*=pow(v.first,(v.second/N));
  }
  Out(sum);
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

uint32_t gcd(uint32_t x, uint32_t y) {
  if (!y)
    return x;

  uint32_t new_x = y;
  y = x % y;
  return gcd(new_x, y);
}

uint32_t tuple_gcd(uint32_t x, uint32_t y, uint32_t z) {
  return gcd(gcd(x, y), z);
}

int main() {
  uint32_t K;
  cin >> K;

  uint32_t sum = 0;
  unordered_map<string, uint32_t> dp;
  for (uint32_t i = 1; i <= K; ++i) {
    for (uint32_t j = 1; j <= i; ++j) {
      for (uint32_t k = 1; k <= j; ++k) {
        uint32_t m = 6;
        if (i == j && i == k)
          m = 1;
        else if (i == j || i == k || j == k)
          m = 3;

        sum += m * tuple_gcd(i, j, k);
      }
    }
  }

  cout << sum;
  return 0;
}


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

int main( void )
{
	vector <bool> is_prime(10001, false);
	for ( int i = 3; i < 10001; i += 2 )
		is_prime[i] = true;
	for ( int i = 3; i < 10001; i += 2 )
	{
		if ( is_prime[i] )
		{
			for ( int j = i + i; j < 10001; j += i )
			{
				is_prime[j] = false;
			}
		}
	}

	int n;
	while ( cin >> n && n )
	{
		if ( n % 2 == 0 )
			n--;
		for ( int i = n; i >= 5; i -= 2 )
		{
			if ( is_prime[i] && is_prime[i-2] )
			{
				cout << i-2 << " " << i << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a;
    cin>>a;
    cout<<a+(a*a)+(a*a*a);
    return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	while(true) {

		int n;
		vector<pair<int, int> > pos;
	
		scanf("%d", &n);
		if(n == 0)
			break;

		pos.resize(n);
		for(int i = 0; i < n; ++i)
			scanf("%d%d", &pos[i].first, &pos[i].second);

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

		int ans = 0;

		for(int a = 0; a < n; ++a) {
			for(int b = 0; b < a; ++b) {

				int x1 = pos[a].first, y1 = pos[a].second;
				int x2 = pos[b].first, y2 = pos[b].second;
				int dx = x2 - x1, dy = y2 - y1;

				int x3 = x2 + dy, y3 = y2 - dx;
				int x4 = x1 + dy, y4 = y1 - dx;

				bool c = binary_search(pos.begin(), pos.end(), make_pair(x3, y3));
				bool d = binary_search(pos.begin(), pos.end(), make_pair(x4, y4));

				if(c && d)
					ans = max(ans, dx * dx + dy * dy);
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 1052
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    private static int[] path;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        path = new int[1 << n];
        if (Integer.bitCount(a ^ b) % 2 != 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
            return;
        }
        path(a, b, 0, (1 << n) - 1);
        PrintWriter pw = new PrintWriter(System.out);
        for (int i = 0; i < path.length; i++) {
            pw.print(path[i] + " ");
        }
        pw.println();
        pw.flush();
    }

    private static void path(int a, int b, int st, int mask) {
        int diffBit = Integer.highestOneBit(mask & (a ^ b));
        mask = mask ^ diffBit;
        int size = Integer.bitCount(mask);
        if (size == 0) {
            path[st] = a;
            path[st + 1] = b;
        } else {
            int otherBit = Integer.highestOneBit(mask);
            path(a, a ^ otherBit, st, mask);
            path(a ^ diffBit ^ otherBit, b, st + (1 << size), mask);
        }
    }
}


Measured memory_bytes: 42320
nk_list = list(map(int, input().split()))
n,k = nk_list[0], nk_list[1]

keta_lst = list()
for i in range(50):
    if i == 0:
        keta = 1
        keta_lst.append(keta)
    else:
        keta = 2*keta + 3
        keta_lst.append(keta)

paty_lst = list()
for i in range(50):
    if i == 0:
        paty = 1
        paty_lst.append(paty)
    else:
        paty = 2*paty+1
        paty_lst.append(paty)

def eat_paty(n,k):
    
    if n == 0 and k == 1:
        return 1
    
    keta_before = keta_lst[n-1]
    
    if k == 1:
        return 0
    elif k <= keta_before + 1:
        return eat_paty(n-1, k-1)
    elif k == keta_before + 2:
        return paty_lst[n-1]+1
    elif k <= 2*keta_before + 1:
        return paty_lst[n-1] + 1 + eat_paty(n-1, k-keta_before-2)
    elif k > 2*keta_before + 1:
        return 2 * paty_lst[n-1] + 1

print(eat_paty(n,k))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	ll n,x,y;
	cin>>n;
	vector<pair<int,int>> a(n);
	for(int i=0;i<n;i++){
		cin>>x>>y;
		a[i]={x,y};
	}
	int flag=0;
	for(int i=1;i<=n-2;i++){
		if(a[i].first==a[i].second&&a[i-1].first==a[i-1].second&&a[i+1].first==a[i+1].second)
		flag=1;
	}
	if(flag)
	cout<<"Yes"<<endl;
	else 
	cout<<"No"<<endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;


#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 2e5 + 20;
int a[maxn];
vector<int>da;
void work() {
    int n;
    LL sum = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    LL add = 1LL * n * (n + 1) / 2;
    if (sum % add != 0) {
        cout << "NO" << endl;
        return;
    }
    for (int i = 2; i <= n; ++i) {
        da.push_back(a[i] - a[i - 1]);
    }
    da.push_back(a[1] - a[n]);
    LL k = sum / add;
    for (int i = 0; i < da.size(); ++i) {
        LL t = k - da[i];
//        LL t = da[i] + k * (n - 1);
        if (t % n != 0 || t < 0) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    work();
    return 0;
}


Measured memory_bytes: 1276
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int value[1000];
int sp=0;


void push(int n){
	value[sp++] = n;
}

int pop(){
	if(sp > 0) {
		return value[--sp];
	}else{
		return 0;
	}
}


int main(void){
	int a,b,n;
//	int sp=0;
	char s[100];
	
	while(scanf("%s",s)!=EOF){
		if(s[0]=='+'){
			a=pop();
			b=pop();
			n=a+b;
			push(n);
		}
		else if(s[0]=='-'){
			a=pop();
			b=pop();
			n=b-a;
			push(n);			
		}
		else if(s[0]=='*'){
			a=pop();
			b=pop();
			n=a*b;
//			printf("%d*%d",a,b);
			push(n);			
		}
		else {
			n = atoi(s);
			push(n);
		}
	}
	n=pop();
	printf("%d\n",n);
	return 0;
	
}

Measured memory_bytes: 548
#include <iostream>
#include <cmath>
#include <vector>
#include <tuple>
typedef long long ll;

using namespace std;

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

  int act[N][3];
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> act[i][j];
    }
  }
  int dp[N][3];
  dp[0][0] = 0;
  dp[0][2] = 0;
  dp[0][2] = 0;

  for (int i = 0; i < N; i++) {
    if (i == 0) {
      dp[i + 1][0] = act[i][0];
      dp[i + 1][1] = act[i][1];
      dp[i + 1][2] = act[i][2];
    }
    else {
      dp[i + 1][0] = max(dp[i][1], dp[i][2]) + act[i][0];
      dp[i + 1][1] = max(dp[i][0], dp[i][2]) + act[i][1];
      dp[i + 1][2] = max(dp[i][0], dp[i][1]) + act[i][2];
    }
  }
  cout << max(max(dp[N][0], dp[N][1]), dp[N][2]) << endl;
  
}


Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ll n;

string solve() {
    string res = "";
    while (n > 0) {
        int d = (n-1) % 26;
        char c = (char)('a'+ d);
        res += c;
        n = (n-1) / 26;
    }
    reverse(ALL(res));
    return res;
}

void input() {
    cin >> n;
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3664
lst = []
for i in range(5):
    time = int(input())
    lst.append(time)

counter = 0
lst_wait = []
for k in range(5):
    time_wait = lst[k] % 10
    if time_wait % 10 == 0:
        wait_time = 0
        lst_wait.append(wait_time)
    else:
        wait_time = 10 - time_wait
        lst_wait.append(wait_time)
    
lst_com = list(zip(lst_wait,lst))
lst_com_ch = sorted(list(lst_com))
total_time = 0

for i in range(4):
    total_time = total_time + list(lst_com_ch)[i][0] +list(lst_com_ch)[i][1]

total_time += list(lst_com_ch)[4][1]

print(total_time) 

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

int main() {
  long x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  long c = x / d;
  long dist = x - d * min(c, k);
  if (k < c || (k - c) % 2 == 0) {
    cout << abs(dist) << endl;
  } else {
    cout << abs(dist - d) << endl;
  }
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		int one = 1900 * m + 100 * (n - m);
		System.out.println(one * (int) Math.pow(2, m));
	}
}


Measured memory_bytes: 21844
N, K = map(int, input().split(' '))
S = input()

if len(S) != N:
    print("error")

Ans = []
for i in range(N):
    if i == K-1:
        Ans.append(S[i].lower())
    else:
        Ans.append(S[i])
Ans_str = "".join(Ans)
print(Ans_str)

Measured memory_bytes: 3060
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

# 10 -> n
def ten2n(a,n):
  x=a//n
  y=a%n
  if x:
    return ten2n(x,n)+str(y)
  return str(y)

def main():
  n=I()

  l=[]
  for i in range(pow(4,9)):
    l.append(ten2n(i,4).replace('3','7').replace('2','5').replace('1','3'))

  cnt=0
  for x in l:
    if int(x)<=n:
      if '3' in x and '5' in x and '7' in x and '0' not in x:
        cnt+=1
    else:
      break

  return cnt

print(main())


Measured memory_bytes: 24156
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int m, d;
    cin >> m >> d;
    int ans = 0;  
    for (int i = 22; i <= d; i++) {
        int x = i / 10 * (i % 10);
        if (x <= m && i / 10 >= 2 && i % 10 >= 2) {
            ans++;
        }
    }  
    cout << ans;
    return 0;
}


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


namespace AtCoder
{
    partial class Program
    {
        static void Main(string[] args)
        {
			//↓

            var s = Console.ReadLine();
            var t = Console.ReadLine();

            var sset = new HashSet<char>(s);
            var tset = new HashSet<char>(t);

            if (!tset.All(tc => sset.Contains(tc)))
            {
                Console.WriteLine(-1);
                return;
            }


            var cd = new Dictionary<char, List<int>>();
            for (int i = 0; i < s.Length; i++)
            {
                var c = s[i];
                List<int> l;
                if (cd.TryGetValue(c, out l))
                {
                    l.Add(i);
                }
                else
                {
                    l = new List<int>();
                    l.Add(i);
                    cd[c] = l;
                }
            }

            var d = new Dictionary<char, int[]>();
            foreach (var kv in cd)
            {
                d[kv.Key] = kv.Value.ToArray();
            }


            long count = 0;
            int j = -1;
            for (int i = 0; i < t.Length; i++)
            {
                var c = t[i];
                var l = d[c];
                
                var ji = Array.BinarySearch(l, j);
                if (ji < 0)
                {
                    ji = ~ji;

                    if (ji < l.Length)
                    {
                        j = l[ji];
                    }
                    else
                    {
                        count += s.Length;
                        j = l[0];
                        continue;
                    }
                }
                else
                {
                    if (ji + 1 >= l.Length)
                    {
                        count += s.Length;
                        j = l[0];
                        continue;
                    }

                    j = l[ji + 1];
                }
                
                if (j > -1)
                {
                    continue;
                }
                else
                {
                    

                    count += s.Length;
                    j = l[0];
                }
            }
            count += j + 1;

            Console.WriteLine(count);


			//↑
        }
	}
}

Measured memory_bytes: 15840
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int x[10],y[10];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>x[i]>>y[i];
    int sum=1;
    for(int i=2;i<=n;++i)
        sum*=i;
    sum*=(n-1);
    int num=n*(n-1)/2;
    int time=sum/num;
    double ans=0;
    for(int i=1;i<=n;++i){
        for(int j=i+1;j<=n;++j){
            int tamp=(x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]);
            double t=sqrt(1.0*tamp);
            ans+=t*1.0*time;
        }
    }
    sum/=(n-1);
    ans/=sum;
    printf("%.10lf",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
signed main(){
	ll n, i;
	cin>>n;
	ll a[n], b[n];
	for(i=1; i<=n; i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b+1, b+n+1);
	ll res[n];
	for(i=1; i<=n; i++){
		if(a[i]!=b[n]){
			res[i]=b[n];
		}
		else{
			res[i]=b[n-1];
		}
	}
	for(i=1; i<=n; i++){
		cout<<res[i]<<"\n";
	}
}

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

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

  int ans = 0;

  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }

  cout << ans << endl;
}


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

template<typename T>
struct Dinic {
	struct Edge {
		// cap := 容量
		// rev := 逆辺のID
		const int to;
		T cap;
		const int rev;
		Edge(const int to, const T cap, const int rev) :
			to(to),
			cap(cap),
			rev(rev)
			{}
	};
	const int V;
	static constexpr T INF = numeric_limits<T>::max();
	// G[from][num] := fromから出るnum番目の辺
	vector<vector<Edge>> G;
	Dinic(const int V) :
		V(V),
		G(vector<vector<Edge>>(V, vector<Edge>()))
		{}
	void addEdge(const int from, const int to, const int cap) {
		G[from].emplace_back(to, cap, (int)G[to].size());
		G[to].emplace_back(from, 0, (int)G[from].size() - 1);
	}
	T flow(const int start, const int goal) {
		T ans = 0;
		vector<int> level(V);
		while(bfs(start, goal, level)) {
			vector<int> checked(V);
			while(1) {
				T fmax = dfs(start, goal, level, checked, INF);
				if(fmax <= 0) break;
				ans += fmax;
			}
		}
		return ans;
	}
	bool bfs(const int start, const int goal, vector<int> &level) {
		for(int i = 0; i < V; ++i) level[i] = -1;
		queue<int> que;
		level[start] = 0;
		que.push(start);
		while(que.size() and level[goal] == -1) {
			int from = que.front();
			que.pop();
			for(Edge e : G[from]) {
				if(e.cap > 0 and level[e.to] == -1) {
					level[e.to] = level[from] + 1;
					que.push(e.to);
				}
			}
		}
		return level[goal] != -1;
	}
	T dfs(const int from, const int goal, const vector<int> &level, vector<int> &checked, T fmax) {
		if(from == goal) return fmax;
		for(int &id = checked[from]; id < (int)G[from].size(); ++id) {
			Edge &e = G[from][id];
			if(level[e.to] <= level[from]) continue;
			if(e.cap <= 0) continue;
			T f = dfs(e.to, goal, level, checked, min(e.cap, fmax));
			if(f <= 0) continue;
			e.cap -= f;
			G[e.to][e.rev].cap += f;
			return f;
		}
		return 0;
	}
};

int main(){
    int V, E; cin >> V >> E;
    Dinic<int> dinic(V);
    for(int i = 0; i < E; ++i) {
        int u, v, c; cin >> u >> v >> c;
        dinic.addEdge(u, v, c);
    }
    cout << dinic.flow(0, V - 1) << endl;
    return 0;
}



Measured memory_bytes: 3116
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, T: int, A: "List[int]"):

    amin, amin_i = (INF, -1)
    gmax = 0
    cand = []

    for i, a in enumerate(A):
        if a < amin:
            amin = a
            amin_i = i
        else:
            if a-amin > gmax:
                gmax = a-amin
                cand = [(gmax, amin_i, i)]
            elif a-amin == gmax:
                cand.append((gmax, amin_i, i))
    print(len(cand))
    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
    T = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, T, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22320
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b && b == c)Yes;
    else No;
    
    
	return  0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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;
}
vector<bool> seen;
void dfs(const Graph &G, int v){
    seen[v] = true; // vを訪問済みにする
    
    for(auto next_v: G[v]){
        if(seen[next_v]) continue; // next_vが探索済みならスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int get_digit(ll n){
    int digit = 0;
    if(n == 0){
        return 1;
    }
    while(n != 0){
        digit++;
        n /= 10;
    }
    return digit;
}
bool is_junretu(ll n){
    int digit = get_digit(n);
    string s;
    s = to_string(n);
    bool flg= true;
    for(int i = 1; i <= digit; i++){
        if(s.find(i) == string::npos){
            flg = false;
            break;
        }
    }
    return flg;
}

int main(){

    int n;
    cin >> n;
    int first_i, first_v;
    int second_i, second_v;
    first_v = second_v = 0;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        if(first_v < t){
            first_v = t;
            first_i = i;
        }
        else if(second_v < t){
            second_v = t;
            second_i = i;
        }
    }
    for(int i = 0; i < n; i++){
        if(i != first_i) cout << first_v << endl;
        else cout << second_v << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin>>n;
	int XorSumEx[n];
	int AllSum=0;
	for(int i=1;i<=n;i++){
		cin>>XorSumEx[i];
		AllSum=AllSum^XorSumEx[i];
	}
	for(int i=1;i<=n;i++)
		cout<<(AllSum^XorSumEx[i])<<' ';
	return 0;
}

Measured memory_bytes: 5156
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long a[3][3];
long n;

int main(){
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            scanf("%ld", &a[i][j]);
        }
    }
    scanf("%ld", &n);
    for(int i = 0; i < n; i++){
        long b;
        scanf("%ld", &b);
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(a[j][k] == b){
                    a[j][k] = 0;
                }
            }
        }
    }
    for(int i = 0; i < 3; i++){
        bool flag = true;
        for(int j = 0; j < 3; j++){
            if(a[i][j]){
                flag = false;
            }
        }
        if(flag){
            printf("Yes\n");
            return 0;
        }
    }
    for(int j = 0; j < 3; j++){
        bool flag = true;
        for(int i = 0; i < 3; i++){
            if(a[i][j]){
                flag = false;
            }
        }
        if(flag){
            printf("Yes\n");
            return 0;
        }
    }
    for(int i = 0; i < 3; i++){
        if(a[i][i]){
            break;
        }else if(i == 2){
            printf("Yes\n");
            return 0;
        }
    }
    for(int i = 0; i < 3; i++){
        if(a[i][2-i]){
            break;
        }else if(i == 2){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
}


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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    vector<vector<ll> > lis(n, vector<ll>(2, 0));
    REP(i, 0, n){cin >> lis[i][0] >> lis[i][1];}
    sort(ALL(lis), [](auto &x, auto &y){return x[1] < y[1];});
    ll time = 0;
    REP(i, 0, n){
        if(lis[i][1] >= time+lis[i][0]){
            time += lis[i][0];
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  string s;
  cin >> s;
  ll q;
  cin >> q;
  vector<vector<char>> t(2);
  int rev = 0;
  while (q--) {
    ll type;
    cin >> type;
    if (type == 1) {
      rev ^= 1;
      continue;
    }
    int f;
    char c;
    cin >> f >> c;
    if (f == 1) {
      t[0 ^ rev].push_back(c);
    } else {
      t[1 ^ rev].push_back(c);
    }
  }

  if (rev) {
    IREP(i, SZ(t[1])) { cout << t[1][i]; }
    reverse(ALL(s));
    cout << s;
    REP(i, SZ(t[0])) { cout << t[0][i]; }
    cout << endl;
  } else {
    IREP(i, SZ(t[0])) { cout << t[0][i]; }
    cout << s;
    REP(i, SZ(t[1])) { cout << t[1][i]; }
    cout << endl;
  }
}

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


int main() {
    ll A, B, X;
    cin >> A >> B >> X; 

    if (A <= X && A + B >= X) cout << "YES" << endl;
    else cout << "NO" << endl;
}




Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    int a,b;
    cin>>a>>b;
    int minv=2147483647;
    int sum=0;
    for(int i=1;i<=a;i++)
    {
        int x;
        cin>>x;
        if(x<minv)
        {
            minv=x;
            sum=1;
        }
        else if(x==minv)
            sum++;
    }
    if((a-sum)%(b-1)==0)
        cout<<(a-sum)/(b-1);
    else
        cout<<(a-sum)/(b-1)+1;
    return 0;
}

Measured memory_bytes: 256
hight, width = map(int, input().split())

ans = 10 ** 18


def F(H, W):
    global ans
    for h in range(1, H):
        sa = h * W
        # 1
        h2 = (H - h) // 2
        sb = h2 * W
        sc = (H - h - h2) * W
        ans = min(ans, max(sa, sb, sc) - min(sa, sb, sc))

        # 2
        w = W // 2
        sb = (H - h) * w
        sc = (H - h) * (W - w)
        ans = min(ans, max(sa, sb, sc) - min(sa, sb, sc))


F(hight, width)
F(width, hight)
print(ans)

Measured memory_bytes: 3064
n=int(input())
a=[i for i in map(int,(input().strip().split()))]
cnt=0
r=0
s=0
for l in range(n):
    while r<n:
        if s & a[r] == 0:
            s += a[r]
            r += 1
        else:
            break
    cnt += r-l
    s -= a[l]
print(cnt)

Measured memory_bytes: 23560
from collections import Counter

h,w,m=map(int,input().split())
hw=[list(map(int,input().split())) for _ in range(m)]

hlst=[x for x,_ in hw]
wlst=[x for _,x in hw]

hcnt=Counter(hlst)
wcnt=Counter(wlst)

_,hmax=hcnt.most_common(1)[0]
_,wmax=wcnt.most_common(1)[0]
hcand=set([k for k,v in hcnt.items() if v==hmax])
wcand=set([k for k,v in wcnt.items() if v==wmax])

ng=[(hh,ww) for hh,ww in hw if ((hh in hcand) and (ww in wcand))]

if len(hcand)*len(wcand)>len(ng):
    print(hmax+wmax)
else:
    print(hmax+wmax-1)

Measured memory_bytes: 228556
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    b = LI()
    ans = []
    for j in range(n):
        for i in range(len(b))[::-1]:
            if b[i] == i+1:
                x = b.pop(i)
                ans.append(x)
                break
    if b:
        print(-1)
    else:
        print(*ans[::-1],sep = "\n")
    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<< "\n"


int main(){
    int x;
    cin >> x;
    COUT(x/500*1000+(x%500)/5*5);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
//#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-8
#define mii map<int,int>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define N 500005
//#define M 1000005
#define pi 3.14159265358979323846 
#define cpdd const pdd
#define hash Hash
#define list List
using namespace std;
typedef long long LL;
using namespace std;
int main(){
	char a[2005];
	char b[2005];
	scanf("%s",a);
	scanf("%s",b);
	int noans=0;
	for(int i=0;a[i]!=0;i++){
		if(a[i]=='1'){
			noans=1;
		}	
	}
	for(int i=0;b[i]!=0;i++){
		if(b[i] =='1'){
			noans=0;
		}
	}
	if(noans){
		printf("-1\n");
		return 0;
	}
	int len=strlen(b);
	int opt=1e9;
	vector<int> v;
	v.pb(-1);
	for(int j=0;b[j]!=0;j++){
		if(b[j]=='1'){
			v.pb(j);
		}
	} 
	v[0]=v.back()-len;
	v.pb(v[1]+len);
	for(int i=0;i<len;i++){
		int l=0,r=0;
		pii p[2005];
		int cnt=0;
		for(int j=0;a[j]!=0;j++){
			if(a[j]!=b[j]){
				vector<int>::iterator it=lower_bound(v.begin(),v.end(),j);
				int r=*it-j;
				int l;
				if(*it-j==0)
				l=0;
				else
				{
					it--;
					l=j-*it;
				}
				p[cnt++]=mp(l,r);
			//	printf("%d %d %d\n",j,l,r);
			} 
		} 
		sort(p,p+cnt);
		reverse(p,p+cnt);
		int Max=0,ans=1e9;
		for(int j=0;j<cnt;j++){
		//	printf("%d %d\n",p[j].x,p[j].y);
		//	printf("%d %d %d?\n",i,p[j].x+Max+min(Max+min(abs(len-i-p[j].x),p[j].x+i),p[j].x+min(abs(i-Max),len-i+Max)),cnt);
			//ans=min(ans,(p[j].x+Max)*2);
			opt=min(p[j].x+Max+min(Max+min(abs(len-i-p[j].x),p[j].x+i),p[j].x+min(abs(i-Max),len-i+Max))+cnt,opt);
			Max=max(p[j].y,Max);
		}
		opt=min(Max+min(Max+min(abs(len-i),i),min(abs(i-Max),len-i+Max))+cnt,opt);
//		ans=min(ans,Max*2);
//		opt=min(ans+cnt+min(i,len-i),opt);
	//	printf("%d %d?\n",ans,cnt);
		char temp=b[0];
		for(int j=0;j<len-1;j++)
		b[j]=b[j+1];
		b[len-1]=temp;
	//	printf("%s",b);
	}
	printf("%d\n",opt);
}

Measured memory_bytes: 256