akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 100003  //N idhar hai
#define inf 1e10
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define sumall(v) accumulate(all(v),(ll)0)
#define suma accumulate
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a*b)/gcd(a,b))
#define bitcount( x ) __builtin_popcountll( x )
#define br "\n"
#define sp " "
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double k , long long n ){double res = 1;while(n){if(n%2!=0){res = (res*k) ;}k = (k*k) ;n = n/2 ;}return(res) ;}
double distance(pll a , pll b){return((db)(sqrt( sqr(a.fi-b.fi) + sqr(a.se-b.se))));}
const ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
void call(){dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1));}
ll n,m,k,h;
bool ok = false;
int main()
{
    FastIO;
    PRECISION(10);
    //FileIO;
    ll a,b,c,d,i,j,t,x,y,z;//,x1,y1,z1,e,f;
    ll p,q,r,u,w ;
    char ch,chr ;
    string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU +  Graph Theory + Math + DP + Bitmasks + Geometry + Brute Force + Greedy + Implementation + Binary Search
    //LIS->https://ideone.com/Vzvbyu
	cin>>a>>b>>c>>k;
	if(a>=k)
	{
	    cout<<min(a,k);
	}
	else if(a<k && b+a>=k)
	{
	    cout<<a;
	}
	else
	{
	    cout<<a-(k-a-b);
	}
}

Measured memory_bytes: 3676
#include<iostream>
    #include<math.h>
    #include<string>
    #include<algorithm>
    using namespace std;
    int ans[60];
    int found;
    int main(){
    	
    	for(int i=2;found<=60;i+=5){
    		bool b=true;
    		for(int j=2;j<=sqrt(i);j++){
    			if(i%j==0)
				   b=false;
    		}
    		if(b){
    			ans[found]=i;
    			found++;
    		}
    	}
    	int n;
		  cin>>n;
    	for(int i=0;i<n;i++)
		   cout<<ans[i]<<" ";
    	return 0;
    }

Measured memory_bytes: 256
#include <iostream>

int main() {
    while( true ) {
        int h , w ;
        std::cin >> h >> w ;
        if( ! ( h | w ) ) {
            break ;
        } else {
            for( int i = 0 ; i < h ; i++ ) {
                for( int ii = 0 ; ii < w ; ii++ ) {
                    if( ( i + ii ) % 2 == 0 ) {
                        std::cout << "#" ;
                    } else {
                        std::cout << "." ;
                    }
                }
                std::cout << std::endl ;
            }
            std::cout << std::endl ;
        }
    }
}




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

namespace ddcc2020_qual_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var AL = (Console.ReadLine().Split().Select(x => long.Parse(x))).ToList();
            var AS = new List<long>();
            long s = 0;
            long rm = long.MaxValue;

            // 累積和
            for(int i = 0; i < N; i++) 
            {
                s += AL[i];
                AS.Add(s);
            }

            //累積和から左右に分割
            for (int i = 0; i < N - 1; i++)
            {
                long r = Math.Abs(2 * AS[i] - AS[N - 1]);
                if (r < rm) rm = r;
            }

            Console.WriteLine(rm);

        }
    }
}


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

ll n,x[100010],y[100010],used_x[100010]={},used_y[100010]={},ans=0;
vector<ll> a[100010],b[100010];

void init(){
	cin>>n;
	rep(i,n){
		cin>>x[i]>>y[i];
		a[x[i]].push_back(y[i]);
		b[y[i]].push_back(x[i]);
	}
}

int main(void){
	init();
	reg(i,0,100000){
		if(used_x[i]==0){
			ll size[2]={1,0},sum=0;
			used_x[i]=1;
			queue<pair<ll,ll>> Q;
			Q.push({i,0});
			while(not Q.empty()){
				pair<ll,ll> p=Q.front();Q.pop();
				if(p.second==0){
					sum+=a[p.first].size();
					for(ll q:a[p.first]){
						if(used_y[q]==0){
							used_y[q]=1;
							Q.push({q,1});
							size[1]++;
						}
					}
				}else{
					sum+=b[p.first].size();
					for(ll q:b[p.first]){
						if(used_x[q]==0){
							used_x[q]=1;
							Q.push({q,0});
							size[0]++;
						}
					}
				}
			}
			ans+=size[0]*size[1]-sum/2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

static const int N = 100;
static const int INF = (1<<21);

int n, M[N][N], d[N];

void bfs(int s){
    queue<int> q;
    q.push(s);
    rep(i,n) d[i] = INF;
    d[s] = 0;
    
    int u;
    while( !q.empty() ) {
        u = q.front();
        q.pop();
        rep(i,n){
            if(M[u][i] == 0) continue;
            if(d[i] != INF) continue;
            d[i] = d[u] + 1;
            q.push(i);
        }
    }
    
    rep(i,n) cout << i + 1 << " " << ((d[i] == INF)? -1 : d[i]) << endl; 
}

int main(){
    cin >> n;
    int u,k,v;
    rep(i,n) rep(j,n) M[i][j] = 0;
    rep(i,n){
        cin >> u >> k;
        rep(j,k){
            cin >> v;
            M[u-1][v-1] = 1;
        }
    }
    bfs(0);
    return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<climits>
#include<cstdio>
#include<cmath>
using namespace std;
const int M=1e5+5;
const long  MN=LONG_MAX;
long pos[M];
int main()
{
     int n,k;
     long ans;
     while(cin>>n>>k)
     {
           pos[0]=0;
         int s=0,bound=0,flag=0;
         for(int i=1;i<=n;++i)
         {
             scanf("%lld",&pos[i]);
             if(pos[i-1]<0&&pos[i]>=0)s=i-1;
             if(s!=0)bound++;
         }
        // cout<<s<<endl;
         if(s==0)
         {
             if(pos[1]>=0)cout<<pos[k]<<endl;
             else if(pos[1]<=0)cout<<-pos[n-k+1]<<endl;
         }
         else
         {
           //  cout<<s<<" "<<bound<<endl;
             if(bound>k)bound=k;
             bound+=s;
             ans=MN;
            // cout<<s<<" "<<bound<<endl;
             for(int i=bound;i-k+1>=1&&i>=s;--i)
             {
                 int t=i-k+1;
               // cout<<t<<" "<<i<<endl;
                 if(t>s)ans=min(ans,pos[i]);
                 else if(i==s)ans=min(ans,-pos[t]);
                 else ans=min(ans,min(pos[i]+pos[i]-pos[t],-pos[t]+pos[i]-pos[t]));
               // cout<<ans<<endl;
             }
             cout<<ans<<endl;
          }
     }

}

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

#define ll long long

using namespace std;

const int MAXN = 200010;
const int MAXM = 100010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, m, k;
int tot, cnt;

int a[MAXN], f[MAXN], ans[MAXN];
int head[MAXN];

struct edge {
	int to, next;
}e[MAXN * 2];

void add_edge(int x, int y) {
	e[++tot].to = y;
	e[tot].next = head[x];
	head[x] = tot;
	return;
}

void Dfs(int x, int fa) {
	int last;
	int l = 1, r = ans[fa], mid;
	if (!fa) f[1] = a[x], ans[1] = 1;
	else {
		while (l <= r) {
			mid = (l + r) >> 1;
			if (a[x] <= f[mid]) r = mid - 1;
			else l = mid + 1;
		}
		last = f[l];
		f[l] = a[x];
		ans[x] = ans[fa];
		if (l > ans[fa]) ++ans[x];
	}
	for (int i = head[x]; i; i = e[i].next) {
		int v = e[i].to;
		if (v != fa) Dfs(v, x);
	}
	f[l] = last;
	return;
}

int main(){
	int t;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d%d", &u, &v);
		add_edge(u, v);
		add_edge(v, u);
	}
	
	Dfs(1, 0);
	
	for (int i = 1; i <= n; i++) {
		printf("%d\n", ans[i]);
	}
	return 0;
}

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

public class Main {

  static long[][] dp;
  static long[] arr;
  
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    arr = new long[n];
    dp = new long[n][n];
    for(int i = 0; i < n; ++i) arr[i] = in.nextInt();

    System.out.println(dp(0, n - 1));
  }

  static long dp(int i, int j) {
    if (i > j) return 0;
    if (dp[i][j] != 0) return dp[i][j]; // check this shit 
    return dp[i][j] = Math.max(arr[i] - dp(i + 1, j), arr[j] - dp(i, j - 1));
  }
}

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

ll arr[100009][3];
int dp[100009][2][2][2];

long long VAC1(int n,int a, int b, int c)
{

    if(!n && a) return arr[n][0];
    else if(!n && b) return arr[n][1];
    else if(!n && c) return arr[n][2];
    else if(dp[n][a][b][c]!=-1)return dp[n][a][b][c];

    else
    {

        ll x,y,z;
        if(a)
        {
            x = VAC1(n-1,0,1,0)+arr[n][0];
            y = VAC1(n-1,0,0,1)+arr[n][0];

        }

        else if(b)
        {
            x = VAC1(n-1,1,0,0)+arr[n][1];
            y = VAC1(n-1,0,0,1)+arr[n][1];
        }

        else if(c)
        {
            x = VAC1(n-1,1,0,0)+arr[n][2];
            y = VAC1(n-1,0,1,0)+arr[n][2];
        }

        dp[n][a][b][c] = max(x,y);;
        return dp[n][a][b][c];


    }
}

int main()
{
   // freopen("in.txt","r",stdin);
    int n;
    memset(dp,-1,sizeof(dp));
    cin >> n;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<3; j++)
        {
            cin >> arr[i][j];
        }
    }
    ll res = VAC1(n-1,1,0,0);
    res= max(res, VAC1(n-1,0,1,0));
    res = max(res,VAC1(n-1,0,0,1));

    cout << res << endl;
}


Measured memory_bytes: 13568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String input = br.readLine();
		
		int k = Integer.parseInt(br.readLine());

		PriorityQueue<String> pq = new PriorityQueue<String>();
		
		int n = input.length();
		
		HashSet<String> set = new HashSet<String>();
		for(int i = 0; i < n; i++){
			for(int j = 1; j <= k && i + j <= n; j++){
				String sub = input.substring(i, i + j);
				
				if(!set.contains(sub)){
					set.add(sub);
					pq.add(sub);
//					System.out.println("add "+sub);
				}
			}
		}
		
		for(int i = 0; i < k - 1; i++){
//			System.out.println("poll " +pq.poll());
			pq.poll();
		}
		
		System.out.println(pq.poll());
	}

}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  string s;cin>>s;
  REP(i,3) {
    if(s[i]=='7') {
      pr("Yes");
      return 0;
    }
  }
  pr("No");
  return 0;
}


Measured memory_bytes: 3628
fun main(args: Array<String>) {
    val input = readLine() ?: ""
    val input_list = input.split(" ")
        .map(String::toInt) 
    val sum = input_list.sum()
    when (sum % 2) {
        0 -> println( sum / 2 )
        else -> println( "IMPOSSIBLE" )
    }
}

Measured memory_bytes: 37892
#include <bits/stdc++.h>
using namespace std;
int N, K;
string S;
int main(void)
{
	cin >> N >> K >> S;
	int same = 0, dif = 0;
	for (int i = 0; i < N - 1; i++)
	{
		if (S[i] == S[i + 1]) same++;
		if (S[i] != S[i + 1]) dif++;
	}
	cout << same + min(dif, K * 2) << endl;
	return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

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

  vi a(n), b(n), c(n-1);
  rep(i, 0, n) cin >> a[i], a[i]--;
  rep(i, 0, n) cin >> b[i];
  rep(i, 0, n-1) cin >> c[i];

  int ans = b[a[0]];
  rep(i, 1, n){
    ans += b[a[i]];
    if(a[i-1] + 1 == a[i]){
      ans += c[a[i-1]];
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

/*
thx
http://arc059.contest.atcoder.jp/submissions/961467
*/
void solve(){
	int N,C;
	cin >> N >> C;
	vector<int> A(N),B(N);
	for(int i=0;i<N;++i){
		cin >> A[i];
	}
	for(int i=0;i<N;++i){
		cin >> B[i];
	}
	
	//ppow[x][c] := x^cのテーブル
	vector< vector<LL> > ppow(401,vector<LL>(401,0));
	for(int x=1;x<=400;++x){
		LL temp = 1;
		ppow[x][0] = temp;//x^0;
		for(int c=1;c<=400;++c){
			temp = (temp * x ) % MOD;
			ppow[x][c] = temp;
		}
	}
	//ppow[x][c]のxについての累積和をとる
	vector< vector<LL> > sumpow(401,vector<LL>(401,0));
	for(int c=0;c<=400;++c){
		for(int x=1;x<=400;++x){
			sumpow[x][c] = (sumpow[x-1][c] + ppow[x][c])%MOD;
		}
	}

	vector< vector<LL> > dp(N+1,vector<LL>(C+1,0));
	dp[0][0] = 1;
	
	for(int i=0;i<N;++i){
		for(int now=0;now<=C;++now){//now個までくばった
			//dp[i][now]
			const int saMAX = C-now;//配れる残り個数
			for(int sa=0; sa<=saMAX; ++sa){//これからsa個くばる
				LL temp = (sumpow[B[i]][sa]-sumpow[A[i]-1][sa]+MOD)%MOD;
				dp[i+1][now+sa] = (
					dp[i+1][now+sa] + 
					dp[i][now] * temp
					)%MOD;
			}
		}
	}
	cout << dp[N][C] << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 4096
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type key struct {
	a int
	c int
}

const inf = 1 << 60

func main() {
	n, m := getInt(), getInt()
	ks := make([]key, m)
	for i := range ks {
		ks[i].a = getInt()

		b := getInt()
		for j := 0; j < b; j++ {
			tmp := uint(getInt()) - 1
			ks[i].c |= 1 << tmp
		}
	}

	if !checker(ks, n) {
		fmt.Println(-1)
		return
	}

	dp := make([]int, (1 << uint(n)))
	for i := range dp {
		dp[i] = inf
	}
	dp[0] = 0

	for _, k := range ks {
		dp[k.c] = min(dp[k.c], k.a)
		for j := range dp {
			dp[k.c|j] = min(dp[k.c|j], dp[k.c]+dp[j])
		}
	}

	fmt.Println(dp[len(dp)-1])
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func checker(ks []key, n int) bool {
	x := (1 << uint(n)) - 1
	y := 0
	for _, k := range ks {
		y |= k.c
	}

	if x == y {
		return true
	}
	return false
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin>>n>>k;
  vector<pair<int,int>>su(n);
  rep(i,n)
  {
    ll a,b;
    cin>>a>>b;
    su[i]={b,a};
  }
  sort(all(su),greater<pair<int,int>>());
  vector<bool>used(n+1);
  int syurui=0;

  vector<int>id;
  rep(i,n)
  {
    if(!used[su[i].second]){used[su[i].second]=1;id.push_back(i);syurui++;}
  }
  int inid=upper_bound(all(id),k-1)-id.begin();
  ll tres=(ll)inid*inid;
  rep(i,k)tres+=su[i].first;
  ll res=tres;
  inid--;
  int idx=k-1;
  int maid=1+min(k,syurui);
  repi(i,inid+2,maid)
  {
    tres+=i*2-1;
    while(idx==id[inid])
    {
      inid--;
      idx--;
    }
    idx--;
    tres-=su[idx+1].first;
    tres+=su[id[i-1]].first;
    //cout<<" "<<idx<<" "<<i<<endl;
    //cout<<tres<<endl;
    chmax(res,tres);
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 1660
def merge(A, left, mid, right):
    L = A[left:mid] 
    R = A[mid:right]
        
    L.append(float("inf"))
    R.append(float("inf"))
    
    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global count
    count += right - left
            
def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

n = int(input())
A = list(map(int, input().split(" ")))
count = 0
mergeSort(A, 0, len(A))
print(*A)
print(count)

Measured memory_bytes: 63696
#include<iostream>
using namespace std;
typedef long long int ll;
int main(void){
	ll n,m;
	cin>>n>>m;
ll ans=0;
if(n>2&&m>2){
	ans+=(n-2)*(m-2);
}else if(n==2||m==2){
	ans=0;
}else{
	ans+=n+m-3;
	if(ans<0)ans*=-1;
}
cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int N = in.nextInt();
		int K = in.nextInt();
		
		if(N%K==0) {
			System.out.println("0");
		}else {
			System.out.println("1");
		}
		in.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  int n;
  cin >> n;
  while(n--){
    int H,N,D;
    cin >> H >> N >> D;
    int hday = 0;
    int mday = 0;
    int total = 0;
    hday = (1000-H+1)/3 * 200 + ((1000-H-1) - (1000-H+1)/3) * 195;
    if(H%3){
      if(N%2){
	mday = 20 * (4-N/2) + 19 * (5-N/2) + 20 - D;
      }else{
	mday = 20 * (5-N/2) + 19 * (5-N/2) + 19 - D;
      }
    }else{
      mday = 20 * (10-N) + 20 - D;
    }
    total = hday + mday + 1 ;
    cout << total << endl;
  }
   
  return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define int long long
using namespace std;
int n,A[105];
double cev;
main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&A[i]);
		double t=A[i];
		cev+=1/t;
	}
	cev=1/cev;
	printf("%lf\n",cev);
	return 0;
}




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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const ll MOD = 1000000007;
const int MX = 200010;
const ll i2 = (MOD + 1) / 2;

ll inv[MX], fact[MX], ifact[MX];

void init() {
	inv[1] = 1;
	for (int i = 2; i < MX; ++i) {
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
	}
	fact[0] = ifact[0] = 1;
	for (int i = 1; i < MX; ++i) {
		fact[i] = fact[i-1] * i % MOD;
		ifact[i] = ifact[i-1] * inv[i] % MOD;
	}
}

ll comb(int n, int r) {
	if (n < 0 || r < 0 || r > n) return 0;
	return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}

ll solve_mini(int N, int M, int K) {
	int num = N * M;
	ll ans = 0;
	rep(i, 1<<num) {
		if (__builtin_popcount(i) != K) continue;
		int s = 0;
		rep(j, num) {
			for (int k = j+1; k < num; ++k) {
				if (((i >> j) & 1) && ((i >> k) & 1)) {
					int a = j / M, b = j % M, c = k / M, d = k % M;
					s += abs(a - c) + abs(b - d);
				}
			}
		}
		ans += s;
		ans %= MOD;		
	}
	return ans;
}

ll solve(int N, int M, int K) {
	ll s = 0;
	for (int i = 1; i < N; ++i) {
		s = (s + (ll)(N-i) * i) % MOD;
	}
	ll t = 0;
	for (int i = 1; i < M; ++i) {
		t = (t + (ll)(M-i) * i) % MOD;
	}

	ll a = s * M % MOD * M % MOD;
	ll b = t * N % MOD * N % MOD;
	return (a + b) * comb(N * M - 2, K - 2) % MOD;
}

int main() {
	init();
	int N, M, K; cin >> N >> M >> K;

	ll ans = solve(N, M, K);
	if (N * M <= 20) {
		assert(ans == solve_mini(N, M, K));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

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

//static const ll MOD = 1000000007;
//static const ll INF = 1000000000000000000;
//#define PI 3.14159265358979323846
//
//int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
//
//int findSumDigits(int s) {
//    int num = 0;
//    int temp = 0;
//    while (s) {
//        temp = s % 10;
//        num += temp;
//        s = s / 10;
//    }
//    return num;
//}
//
//int countDivisorNum(int n) {
//    int count = 0;
//    for (int i = 1; i <= n; i++) {
//        if (n % i == 0) {
//            count++;
//        }
//    }
//    return count;
//}

int main() {
    ll n, x, t;
    cin >> n >> x >> t;
    ll temp = 0;

    rep(i, 1001, 1) {
        if (n <= x * i) {
            temp = i;
            break;
        }
    }

    ll ans = t * temp;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		final long STACK_SIZE=8*1024*1024;
		new Thread(null, new AOJ1180(), "RUN!", STACK_SIZE).start();
		//new Live5015();
	}
	
	class AOJ1180 implements Runnable{
		AOJ1180(){}
		@Override public void run(){
			while(sc.hasNext()){
				int a=sc.nextInt(),L=sc.nextInt();
				if((a|L)==0)	break;
				solve(a,L);
			}
		}
		void solve(int A,int L){
			HashMap<Integer,Integer> a=new HashMap<Integer, Integer>();
			a.put(A,0);
			int i=1,last=A;
			while(true){
				int b=biggest(last,L)-smallest(last,L);
				if(a.containsKey(b)){
					int j=a.get(b);
					System.out.println(j+" "+b+" "+(i-j));
					break;
				}
				a.put(b,i++);
				last=b;
			}
		}
		
		int[] split(int n,int l){
			int[] a=new int[l];
			for(int i=0; i<l; i++){
				a[i]=n%10;
				n/=10;
			}
			Arrays.sort(a);
			return a;
		}
		int biggest(int n,int l){
			int[] a=split(n,l);
			int ret=0;
			for(int i=0; i<l; i++)	ret+=a[i]*(int)pow(10,i);
			return ret;
		}
		int smallest(int n,int l){
			int[] a=split(n,l);
			int ret=0;
			for(int i=0; i<l; i++)	ret+=a[l-i-1]*(int)pow(10,i);
			return ret;
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 1; i < (n); i++) 
#define out(n) cout << n << endl;

int main() {
    string s,t;
    bool flg=true;
    cin >> s >> t;

    int t_size = t.size();

    for (int i = 0; i < t_size-1; i++)
    {
        if(s[i] != t[i]){
            flg = false;
        }
    }
    

    if(flg ==true){
        out("Yes");
    }else{
        out("No");
    }
}

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


int main() 
{
    int K, A, B;
    cin >> K >> A >> B;
    
    for (int i = A; i <= B; i++) {
        if (i % K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
ll A[MAX_N];

int main()
{
	int N;
	cin >> N;
	ll sum = 0;
	int cnt = 0;
	ll absmin = 1e9+5;
	rep(i,N)
	{
		cin >> A[i];
		if (A[i] <= 0) 
		{
			cnt++;
		}
		absmin = min(absmin,abs(A[i]));
		sum += abs(A[i]);
	}

	if (cnt % 2 == 0)
	{
		cout << sum << endl;
	}
	else
	{
		cout << sum - absmin*2 << endl;
	}
	return 0;
}

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

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

using namespace std;
using lint=long long;

inline int popcount(int x){
	x=((x>>1)&0x55555555)+(x&0x55555555);
	x=((x>>2)&0x33333333)+(x&0x33333333);
	x=((x>>4)+x)&0x0f0f0f0f;
	x+=(x>>8);
	x+=(x>>16);
	return x&0x3f;
}

int main(){
	int n,k,s,t; scanf("%d%d%d%d",&n,&k,&s,&t);

	if((s&t)!=s) return puts("0"),0;

	lint choose[51][51]={1};
	rep(i,n){
		choose[i+1][0]=1;
		rep(j,i+1) choose[i+1][j+1]=choose[i][j]+choose[i][j+1];
	}

	lint coef[51]={};
	rep(i,n+1) for(int j=1;j<=k;j++) coef[i]+=choose[i][j];

	vector<int> a;
	rep(i,n){
		int x; scanf("%d",&x);
		bool ok=true;
		rep(i,18){
			if((s>>i&1)==0 && (t>>i&1)==0){
				if((x>>i&1)!=0) ok=false;
			}
			if((s>>i&1)==1 && (t>>i&1)==1){
				if((x>>i&1)!=1) ok=false;
			}
		}
		if(ok) a.emplace_back(x);
	}
	n=a.size();

	vector<int> D;
	rep(i,18) if((s>>i&1)!=(t>>i&1)) D.emplace_back(i);
	int m=D.size();
	{
		vector<int> b(n);
		rep(i,n){
			rep(j,m) if(a[i]>>D[j]&1) b[i]|=1<<j;
		}
		a=b;
	}

	lint ans=0;
	rep(S,1<<m){
		lint tmp=0;
		map<int,int> f;
		rep(i,n) ++f[a[i]&S];
		for(auto p:f) tmp+=coef[p.second];
		if(popcount(S)%2==0) ans+=tmp;
		else                 ans-=tmp;
	}
	printf("%lld\n",ans);

	return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;




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

    int n, m;
    cin>>n>>m;
    dsu d(n);
    for (int i=0; i<m; i++) {
	int u,v;
	cin>>u>>v;
	--u; --v;
	d.merge(u,v);
    }

    auto g = d.groups();
    int cc = g.size();
    cout<<cc-1<<endl;
    
    
    return 0;
}


Measured memory_bytes: 8912
//AtCoder ABC078 A - HEX
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    string a,b;
    cin>>a>>b;    
    if (a[0]==b[0]) cout<<"="<<endl;
    else if(a[0]>b[0]) cout<<">"<<endl;
    else cout<<"<"<<endl;
    return 0;
}

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

int a[10000];
int main() {

    int n;

    cin >> n;

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

        cin >> a[i];
    }

    int cnt = 0;

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

        if(a[i] == a[i - 1]) {

            cnt++;
            i++;
        }
    }

    cout << cnt << endl;


}


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

int main()
{
	int N, A;
	cin >> N >> A;
	vector<vector<vector<long long>>> dp(N + 1, vector<vector<long long>>(2501, vector<long long>(51, 0)));
	dp[0][0][0] = 1;
	for (int i = 1, x; i <= N; i++) {
		cin >> x;
		for (int j = 0; j <= 2500; j++) {
			for (int k = 0; k <= 50; k++) {
				if (dp[i - 1][j][k] > 0) {
					dp[i][j][k] += dp[i - 1][j][k];
					dp[i][j + x][k+1] += dp[i - 1][j][k];
				}
			}
		}
	}
	long long res = 0;
	for (int i = 1; i <= N; i++) {
		res += dp[N][A * i][i];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 56064
h = gets.to_i
as = gets.split.map(&:to_i)
cs = as.group_by { |a| a / 400 }
ans = 0
free = 0
for i in 0..12
  unless cs[i].nil?
    if i < 8
      ans += 1
    else
      free += cs[i].size
    end
  end
end
ans_min = [ans, 1].max
ans_max = ans+free
puts "#{ans_min} #{ans_max}"

Measured memory_bytes: 1788
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] d = new int[N];
		for(int i = 0; i < N; i++) d[i] = sc.nextInt();
		Arrays.sort(d);
		System.out.println(d[N / 2] - d[N / 2 - 1]);
	}
}

Measured memory_bytes: 50876
#include <iostream>

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
	ll N, A[100005], B[100005];

	cin >> N;

	for (int i = 0; i < N + 1; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	ll c = 0;
	for (int i = 0; i < N; i++) {
		ll a = B[i] - A[i];
		if(a >= 0) {
			c += A[i];
			ll b = a - A[i + 1];
			if (b >= 0) {
				c += A[i + 1];
				A[i + 1] = 0;
			} else {
				c += a;
				A[i + 1] = A[i + 1] - a;
			}
		} else {
			c += B[i];
		}
	}

	cout << c << endl;

	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
	
#define MAX 100
#define INF 1000000
#define white 0
#define gray 1
#define black 2
	 
int n,u,M[MAX][MAX];
	 
void dijkstra(void);
	 
int main(){
	int i,j,k,v,c;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			M[i][j] = INF;
		}
	}
	
	for(i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		for(j=0;j<k;j++){
			scanf("%d %d",&v,&c);
			M[u][v] = c;
		}
	}
 
	dijkstra();
 
	return 0;
}
 
void dijkstra(){
	int i,min,d[MAX],color[MAX];
 
	for(i=0;i<n;i++){
		d[i] = INF;
		color[i] = white;
	}
	
	d[0] = 0;
	color[0] = gray;
	
	while(1){
		min = INF;
		u = -1;
		for(i=0;i<n;i++){
			if(min > d[i] && color[i] != black){
				u = i;
				min = d[i];
			}
		}
		
		if(u == -1)break;
		color[u] = black;
		
		for(i=0;i<n;i++){
			if(color[i] != black && M[u][i] != INF){
				if(d[i] > d[u] + M[u][i]){
					d[i] = d[u] + M[u][i];
					color[i] = gray;
				}
			}
		}
	}
	
	for(i=0;i<n;i++){
		printf("%d ",i);
		if( d[i] == INF ){
			d[i] = -1;
		}
		printf("%d\n", d[i]);
	}
 
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 100000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
      int n,m,a[1001];
      while(cin>>n>>m&&(n||m)){
            int ans=0;
            vector<int>V;
            a[0]=0;
            REP(i,n)cin>>a[i+1];
            n++;
            REP(i,n)REP(j,n)V.PB(a[i]+a[j]);
            sort(ALL(V));
            REP(i,n)REP(j,n){
                  int b=a[i]+a[j];
                  if(b>m)continue;
                  ans=max(ans,*(lower_bound(V.begin(),V.end(),m-b)-1)+b);
            }
            cout<<ans<<endl;
      }
      return 0;
}

Measured memory_bytes: 9192
import math
n=int(input())
l1=math.floor(math.log(n,6))
l2=math.floor(math.log(n,9))
dp=[i for i in range(n+1)]
for i in range(1,l1+1):
    for j in range(n):
        if j+6**i<n+1:
            dp[j+6**i]=min(dp[j]+1,dp[j+6**i])
for i in range(1,l1+1):
    for j in range(n):
        if j+9**i<n+1:
            dp[j+9**i]=min(dp[j]+1,dp[j+9**i])
print(dp[-1])

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

long long n;
long long t[5];

int main(){
    cin>>n;
    long long min=1000000000000000;
    for(int i=0;i<5;i++){
        cin>>t[i];
        if(t[i]<min)min=t[i];
    }
    long long ans;
    if(min>=n)ans=5;
    else if(n%min==0)ans=n/min+4;
    else ans=n/min+5;
    cout<<ans<<endl;
    return 0;
}

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

for i in range(m):
    a[i] -= 1

for i in a:
    if i == n-1:
        x[i] = min(x[i]+1, 2019)
    else:
        x[i] = min(x[i]+1, x[i+1]-1)

for i in x:
    print(i)



Measured memory_bytes: 5608
N = int(input())
L = list(map(int,input().split()))

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            a = L[i]
            b = L[j]
            c = L[k]
            if (a != b and b != c and c != a) and (a+b>c and b+c>a and c+a>b):
                ans += 1
print(ans)

Measured memory_bytes: 68128
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

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

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

    }
}

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

int main(void){
  int a,b;
  cin >> a >> b;
  int ans = (a + b) / 2;
  ans += (a + b) % 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# Christmas Eve

q = [1]
for i in range(50):
    q.append(q[i] * 2 + 1)

def n_down(n, x, s):
    global q

    if n == 1:
        s.append('bpppb'[:x].count('p'))
        return(0, 0, s)

    if x < q[n]:
        return(n - 1, x - 1, s)
    elif x == q[n]:
        s.append(q[n - 1] + 1)
        return(0, 0, s)
    else:
        s.append(q[n - 1] + 1)
        return(n - 1, x - q[n], s)

n, x = [int(x) for x in input().split()]
s = []

while n:
    n, x, s = n_down(n, x, s)

print(sum(s))


Measured memory_bytes: 3064
data = list(input())
ans = []

def affect(target):
    global ans
    left_count = 0
    right_count = 0
    index = 0
    for i in range(len(target)):
        if target[i] == 'R' and target[i+1] == 'L':
            index = i
            left_now = i+1
            right_now = (len(target)-1) - i
            if left_now%2 == 0:
                left_count += left_now//2
                right_count += left_now//2
            else:
                left_count += (left_now+1)//2
                right_count += left_now//2

            if right_now%2 == 0:
                left_count += right_now//2
                right_count += right_now//2
            else:
                right_count += (right_now+1)//2
                left_count += right_now//2
            break

    for i in range(index):
        ans.append(0)
    ans.append(left_count)
    ans.append(right_count)
    for i in range(len(target) - 2 - index):
        ans.append(0)

index = 0
note = 0
while index < len(data) - 1:
    if data[index] == 'L' and data[index+1] == 'R':
        focus = data[note:index+1]
        affect(focus)
        note = index+1
        index = note
    index += 1

affect(data[note:])

print(" ".join(map(str,ans)))

Measured memory_bytes: 11356
#include <bits/stdc++.h> 
using namespace std;
const int maxn=10e5+5;
const long long sg=1e10;
long long a,b,c,d,e,f,g,n,m,i,j,sdg[maxn],lili,t;
long long  x[maxn][10],z[maxn],v[101][101],h[maxn];
string p[maxn],s[maxn];
queue<int>q;
bool mark[maxn];
vector<long long> o[maxn],sgd;
map<long long,long long> mp;
char l[10][10],y;
int main(){
ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
cin>>a>>b;
if(b==1||b==2*a-1){
	cout<<"No"<<endl;
}
else{
	cout<<"Yes"<<endl;
	for(i=1;i<2*a;i++){
		z[i]=i;
	}
	swap(z[a],z[b]);
	swap(z[b-1],z[a-1]);
	swap(z[b+1],z[a+1]);
	if(b==a-1){
		swap(z[a],z[a+1]);
	}
	if(b==a+1){
		swap(z[a],z[a-1]);
	}
	for(i=1;i<2*a;i++){
		cout<<z[i]<<endl;
	}
}
return 0;}


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

int main(){
  int a,b,k,ans=-1;
  cin>>a>>b;
  for (int i = 0; i < 1000000001; i++) {
    if(a+b==i+i) {

      ans=i;
      break;
    }
  }
  if(ans==-1) cout<<"IMPOSSIBLE"<<endl;
  else cout<<ans<<endl;
}


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

int main(){
  string str;
  char work;
  int h,n;

  while(true){
    cin >> str;

    if(str == "-") break;

    
    cin >> n;

    for(int l = 0; l<n ; ++l){
      cin >> h;
      
      for(int i=0 ; i<h ; ++i){
	work = str[0];
	for(int k = 0; k<(int)str.size() - 1 ; ++k){
	  str[k] = str[k + 1];
	}
	str[(int)str.size() - 1] = work;
      }
      
    }
    
    cout << str << endl;
  }

  return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
        using namespace std;
         
        int n;
        int cnt[110];
        int tot[2100];
         
        int f(int l, int r)
        {
            int res = 0;
            for (int i = l; i <= r; ++i) res += tot[i];
            return res;
        }
         
        int main()
        {
            while (scanf("%d", &n) != EOF)
            {
                memset(cnt, 0, sizeof cnt); 
                memset(tot, 0, sizeof tot);
                for (int i = 2; i <= n; ++i)
                {
                    int tmp = i;
                    for(int j = 2; ; ++j) 
                    {
                        while (tmp % j == 0) 
                        {
                            ++cnt[j];
                            tmp /= j; 
                        }
                        if (tmp == 1) break; 
                    }
                }
                for (int i = 2; i <= 100; ++i) ++tot[cnt[i] + 1];  
                int res = f(75, 2000);    
                res += f(25, 2000) * f(3, 24);
                res += f(25, 2000) * (f(25, 2000) - 1);
                res += f(15, 2000) * f(5, 14);
                res += f(15, 2000) * (f(15, 2000) - 1);
                res += (f(5, 2000) * (f(5, 2000) - 1) / 2) * f(3, 4);    
                res += ((f(5, 2000) * (f(5, 2000) - 1) / 2) * (f(5, 2000) - 2));
                printf("%d\n", res);
            }    
            return 0;
        }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>


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; }

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;

using namespace std;
typedef long long ll;

int main()
{

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

	string s; cin >> s;
	ll sum = 0;
	for (int i = 0; i < s.size(); i++) {
		sum += s[i] - '0';
		sum %= 9;
	}
	if (sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


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

    vector<ll> nines(1,9);
    vector<ll> sixes(1,6);
    while( nines[nines.size()-1]*9 <= N )
    {
        nines.push_back(nines[nines.size()-1]*9);
    }
    while( sixes[sixes.size()-1]*6 <= N )
    {
        sixes.push_back(sixes[sixes.size()-1]*6);
    }

    vector<ll> keys(1,1);
    rep(i,nines.size()) keys.push_back(nines[i]);
    rep(i,sixes.size()) keys.push_back(sixes[i]);
    sort(all(keys),greater<ll>());

    vector<vector<ll> > dp(keys.size()+1, vector<ll>(N+1, INF_LL));
    dp[0][0] = 0; 

    rep(i, keys.size())
    {
        rep(j,N+1)
        {
            if( keys[i] <= j )
            {
                chmin(dp[i+1][j], dp[i][j-keys[i]]+1);
                chmin(dp[i+1][j], dp[i+1][j-keys[i]]+1);
            }
            chmin(dp[i+1][j], dp[i][j]);
        }
    }
    
    /*
    rep(i, dp.size())
    {
        rep(j, dp[i].size()) cout << dp[i][j] << " ";
        cout << endl;
    }
    */

    cout << dp[keys.size()][N] << endl;
}


Measured memory_bytes: 11264
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int a, b;

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


Measured memory_bytes: 256
"""1, 2, 3, 4, 5, 6, 7, 8, 9, 
10, 11, 12, 21, 22, 23, 32, 33, 34, 43, 44, 45, 54, 55, 56, 65, 66, 67, 76, 77, 78, 87, 88, 89, 98, 99, 
100, 101, 110, 111, 112, 121, 122, 123, 210, 211, 212, 221, 222, 223, 232, 233, 234, 321, 322, 323, 33

1 -> 10,11,12 -> 100,101 ,110,111,112, 121,122,123

2 -> 21,22,23 -> 210,211,212, 221,222,223, 232,233,234"""
def main():
    n = int(input())
    
    queue = [i for i in range(1,10)]
    if n < 10:
        print(queue[n-1])
        return
    n -= 9
    while True:
        if n <= 0:
            print(queue[n-1])
            return
        tmp = queue.pop(0)
        if tmp%10 == 0:
            queue += [tmp*10 + tmp%10, tmp*10 + tmp%10 + 1]
            n -= 2
        elif tmp%10 == 9:
            queue += [tmp*10 + tmp%10 - 1, tmp*10 + tmp%10]
            n -= 2
        else:
            queue += [tmp*10 + tmp%10 - 1, tmp*10 + tmp%10, tmp*10 + tmp%10 + 1]
            n -= 3

main()

Measured memory_bytes: 42736
#include <bits/stdc++.h>
using namespace std;
int a[10004];
int b[10004];
int main()
{
	//freopen("in.txt", "rt", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	for (int i = 0; i < n; ++i)
		scanf("%d", b + i);
	long long u = 0, d = 0;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] > b[i])
		{
			d += a[i] - b[i];
		}
		else if (b[i] > a[i])
		{
			u += (b[i] - a[i]) / 2;
			if (b[i] % 2 != a[i] % 2){
				++u;
				++d;
			}
				
				
		}
	}

	if (u >= d)
		puts("Yes");
	else
		puts("No");
	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
    string s;
    cin >> s;
    int counter = 0;
    // 全部一致
    if (s[0] == s[1] && s[0] == s[2] && s[0] == s[3]) {
        cout << "Yes";
    }
    // 0だけ違う
    else if (s[1] == s[2] && s[1] == s[3]) {
        cout << "Yes";
    }
    // 3だけ違う
    else if (s[0] == s[1] && s[0] == s[2]) {
        cout << "Yes";
    } else {
        cout << "No";
    }

}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 100000
i64 N;
i64 d[MAX_N];

int main() {
  cin >> N;
  REP(i, N) cin >> d[i];
  sort(d, d + N);


  i64 cnt = 0;
  if (N % 2 == 0) {
    cnt = d[N/2] - d[N/2 - 1];
  } else {
    cnt = 0;
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1024