akhauriyash/Code-Regression huggingface dataset:
//D - Leaping Tak
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define LL long long
#define Cl(X,Y) memset((X),(Y),sizeof(X))
#define FOR(i,A,B) for(int i=A;i<=B;i++)
#define BOR(i,A,B) for(int i=A;i>=B;i--)
#define Lowbit(X) (X & (-X))
#define INF 0x3f3f3f3f
#define Rson (X<<1|1)
#define Lson (X<<1)
using namespace std;
int read() {
	int x = 0,f = 0;char ch = getchar();
	while(!isdigit(ch)) {if(ch == '-') f = 1;ch = getchar();}
	while(isdigit(ch)) {x = x*10 + ch - '0';ch = getchar();}
	return f?-x:x;
}
const int N = 2e5 + 100,p = 998244353;
#define LL long long 
LL n,m,t[N],A[12],B[12];
LL ask(LL x) {
	LL tot = 0;
	for(LL i = x;i;i-=i&-i) tot = (tot + t[i]) % p;
	return tot;
}
void add(LL x,LL d) {
	for(LL i = x;i <= n;i+=i&-i) t[i] = (t[i] + d + p) % p;
}
int main() 
{
	n = read();m = read();
	for(int i = 1;i <= m;i++) {
		A[i] = read(),B[i] = read();
		if(A[i] > B[i]) swap(A[i],B[i]);
	} 
	add(1,1);add(2,-1);
	for(LL i = 1;i <= n;i++) {
		LL a = ask(i);
		if(!a) continue;
		for(LL j = 1;j <= m;j++) 
		{
			if(i + A[j] <= n) add(i + A[j],a);
			if(i + B[j] + 1 <= n) add(i + B[j] + 1,-a);
		}
	}
	cout << ((ask(n)%p+p)%p) << endl; 
	return 0;
}


Measured memory_bytes: 5156
N = int(input())
A = [int(i) for i in input().split()]
a = sum(A)
i = 1
while i < N:
	a -= A[i] * 2
	i += 2
print(str(a) + ' ', end='')
i = 1
while i < N:
	a = A[i - 1] * 2 - a
	print(str(a) + ' ', end='')
	i += 1

Measured memory_bytes: 14152
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))

# N = 3
# M = 3
# A = [2, 13, 8]

A = [-a for a in A]
heapq.heapify(A)

for i in range(M):
    price = heapq.heappop(A)*(-1)//2
    heapq.heappush(A, -price)
#    print(A)
print(-sum(A))

Measured memory_bytes: 84924
#include <iostream>
using namespace std;
int main() {
	int a[3],b[2],c;
	cin>>a[0]>>a[1]>>a[2]
	>>b[0]>>b[1];
	c=a[0]+b[0];
	for(int i=0;i<3;i++){
		for(int j=0;j<2;j++){
			if(a[i]+b[j]<c)
				c=a[i]+b[j];
			}
		}
	cout<<c-50<<endl;
	return 0;
}

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

int main() {
int n;
cin>>n;
vector<int>A(n),B(n),C(n);
for(int i=0;i<n;i++)
{
    cin>>A[i]>>B[i]>>C[i];
}
  int dp[n][3];
  dp[0][0]=A[0];
  dp[0][1]=B[0];
  dp[0][2]=C[0];
  for(int i=1;i<n;i++)
  {
      dp[i][0]=max(dp[i-1][1],dp[i-1][2])+A[i];
      dp[i][1]=max(dp[i-1][0],dp[i-1][2])+B[i];
      dp[i][2]=max(dp[i-1][0],dp[i-1][1])+C[i];
  }
  cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
	return 0;
}

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

int n, m, q, x;
int A[20];

bool solve(int i, int m)
{
    if (m == 0)
        return true;
    if (i < 0)
        return false;

    bool ret = solve(i - 1, m - A[i]) || solve(i - 1, m);
    return ret;
}

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

    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> x;
        if (solve(n - 1, x))
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
    return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int64_t k, a, b;
	cin >> k >> a >> b;
	++k;
	int64_t ans = k / (a + 2) * b + k % (a + 2);
	int64_t ans2 = 0;
	if (k >= a && b >= a + 2)
		ans2 = a + (b - a) * ((k - a) / 2) + (k - a) % 2;
	cout << max(ans2, max(k, ans)) << "\n";
	return 0;	
}

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

#define DEBUG 0
#define REP(i, n) for (int i = 0; i < (n); i++) 
typedef long long ll;
typedef pair<int,int> pint;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main() { 
    //a1を0としてぶん回す

    ll c[3][3];
    ll a_i[3];
    ll a_j[3];
    ll b_i[3];
    ll b_j[3];
    a_i[0] = 0;
    REP(i,3)
    {
        REP(j,3)
        {
            cin >> c[i][j];
        }
    }

    //b決める

    REP(i,3)
    {
        b_i[i] = c[0][i] - a_i[0]; 
        //b_0からa_iも求める
        a_i[i] = c[i][i] - b_i[i];
    }

    //負があったらアウト???
    REP(i,3)
    {
        REP(j,3)
        {
            if(a_i[i] +  b_i[j] != c[i][j])
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    cout << "Yes" << endl;

    return 0;

}

Measured memory_bytes: 256
let h = ref 0

let parent i = int_of_float (floor (float_of_int i) /. 2.)

let left i = 2*i

let right i = 2*i + 1

let extract (t : int array) =
  let rec max_heapify i =
    let l = left i in
    let r = right i in
    let m = if l <= !h && t.(l) > t.(i) then l else i in
    let m = if r <= !h && t.(r) > t.(m) then r else m in
    if m <> i then begin
      let tmp = t.(i) in t.(i) <- t.(m); t.(m) <- tmp;
      max_heapify m
    end
  in
  let ret = t.(1) in
  t.(1) <- t.(!h);
  decr h;
  max_heapify 1;
  ret

let insert x (t : int array) =
  incr h;
  t.(!h) <- x;
  let rec doit i =
    if i > 1 && t.(parent i) < t.(i) then begin
      let tmp = t.(i) in
      t.(i) <- t.(parent i);
      t.(parent i) <- tmp;
      doit (parent i)
    end
  in
  doit !h

let () =
  let t = Array.make 2000001 0 in
  let rec doit () =
    let op = Scanf.scanf "%s " (fun i -> i) in
    if op = "extract" then (Printf.printf "%d\n" (extract t); doit ())
    else if op = "end" then ()
    else (insert (Scanf.scanf "%d " (fun i -> i)) t; doit ())
  in
  doit ()

Measured memory_bytes: 20404
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using static System.Math;

class P
{
    static void Main()
    {
        Console.WriteLine((new string[] { "thu", "fri", "sat", "sun", "mon", "tue", "wed" })[int.Parse(Console.ReadLine()) % 7]);
    }
}



Measured memory_bytes: 7836
#include <iostream>
#include <vector>
#include <string>

using ll = long long;

void print(){ std::cout << std::endl; }
template< typename H > void print(H head){std::cout << head << std::endl;}
template< typename H, typename... T > void print(H head, T... tail) {std::cout << head << " ", print(tail...); }

int main()
{
  ll N, M;
  std::cin >> N >> M;

  bool judge = N == M;
  if (judge) print("Yes");
  else print("No");

  return 0;
}


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

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

Measured memory_bytes: 1160
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long w = sc.nextLong();
		int n = sc.nextInt();
		HashMap<Long,Integer> map = new HashMap<>();
		long[] count = new long[10];
		int sum=0;
		for(int k = 0; k<n; k++){
			long a = sc.nextLong();
			long b = sc.nextLong();
			long l = a*w+b;
			for(long i = 0; i<3; i++){
				for(long j = 0; j<3; j++){
					if(a-i>0 && a-i+2<=h && b-j>0 && b-j+2<=w){
						long p = l - i * w - j;
						if(map.containsKey(p)){
							map.put(p,map.get(p)+1);
						}else{
							map.put(p,1);
						}
					}
				}
			}
		}
		for(long p: map.keySet()){
			count[map.get(p)]++;
			sum++;
		}
		count[0]=(h-2)*(w-2)-sum;
		for(int i = 0; i<10; i++){
			System.out.println(count[i]);
		}
	}
}

Measured memory_bytes: 166988
import sys
import heapq
input = sys.stdin.readline

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)


ALL=[0]*K
for a in A:
    for b in B:
        for c in C:
            if a+b+c>ALL[0]:
                heapq.heappush(ALL,a+b+c)
                heapq.heappop(ALL)
            else:
                break
                
ALL.sort(reverse=True)

for k in range(K):
    print(ALL[k])

Measured memory_bytes: 56668
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n,m;
    cin>>n>>m;
    vector< pair<int,int> > p;
    rep(i,0,m){
        int a,b;
        cin>>a>>b;
        p.pb(mp(a,b));
    }
    vector<int> cnt(n+1,0);
    rep(i,0,p.size()){
        int l = p[i].ft;
        int r = p[i].sd;
        // l--;r--;
        cnt[l]++;
        if ( r+1 < n+1 ){
            cnt[r+1]--;
        }
    }
    // rep(i,0,cnt.size()){
    //     out1(cnt[i]);
    // }
    rep(i,1,cnt.size()){
        cnt[i] += cnt[i-1];
    }
    int ans = 0;
    rep(i,1,cnt.size()){
        if ( cnt[i] == m ){
            ans++;
        }
    }
    cout<<ans<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 5580
//{
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//}
const int N = 202020;
int n;
int a[N];
int main(){
	scanf("%d", &n);
	rep(i, 0, n) scanf("%d", a + i);
	vector<pii> cnt[2] = {vector<pii>(N), vector<pii>(N)};
	rep(i, 0, 2) {
		for(int j = i; j < n; j += 2)
			cnt[i][a[j]] = {cnt[i][a[j]].fi + 1, a[j]};
		sort(all(cnt[i]));
	}
	int ans = N;
	rep(i, 0, 2) rep(j, 0, 2) {
		int len = N - 1;
		if(cnt[0][len - i].se != cnt[1][len - j].se)
			ans = min(ans, n - cnt[0][len - i].fi - cnt[1][len - j].fi);
	}
	printf("%d\n", ans);
	return 0;
}



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

int main()
{
	map<int, int> ut;
	string com;
	int k;
	while (cin >> com, com != "end") {
		if (com == "insert") {
			cin >> k;
			ut[k]++;
		}
		else {
			int res = ut.rbegin()->first;
			printf("%d\n", res);
			auto ite = ut.find(res);
			if (ite->second == 1) ut.erase(ite);
			else ut[res]--;
		}
	}
	return 0;
}

Measured memory_bytes: 3796
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(char a,char b){
	return a>b;
}

int main(){
	string a,b;
	cin>>a>>b;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end(),cmp);
	if(a<b)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    char c;
    int m = 0, ans = 0;
    rep(i,0,n) {
        cin >> c;
        if(c == 'I') m++;
        else m--;
        ans = max(ans, m);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for (i=a;i<b;i++)
#define rep2(i,a,b) for (i=a;i>=b;i--)
#define mod 1000000007
#define mod2 998244353
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF  1e9+5
#define f first
#define s second
#define endl '\n'
#define ll long long
#define ii pair <int,int>
#define pll pair <ll,ll>
#define vi vector <int>
#define vl vector <ll>
#define vvi vector < vi >
#define vii vector < ii >
#define vpl vector < pll >
#define vvii vector < vii >
#define vll vector < ll >
#define vb  vector <bool>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define pg priority_queue<ll, vector<ll>, greater<ll>>
#define pq priority_queue<ll>
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define cset(a) __builtin_popcountll(a)
#define FILL(a, b, T) fill_n((T *)a, sizeof(a) / sizeof(T), b)
#define debug(x) cerr << #x << " is " << x << endl;
using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define pis pair<ll,pll>
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// unordered_map<long long, int, custom_hash> safe_map;
// FOR VIEWERS, CODE STARTS HERE
#define N 51
ll a[N], b[N], c[N], d[N];
ll M, no, qo, res = 0;
void dfs(vll &v , ll cur_maxx)
{
  ll i, ans = 0;
  if( sz(v) == no)
  {
    for(i = 0; i < qo; ++i)
    {
      if( v[b[i] - 1] - v[a[i] - 1] == c[i])
        ans += d[i];
    }
    res = max(ans, res);
    return;
  }
  for(i = cur_maxx; i <= M; ++i)
  {
    v.pb(i);
    dfs(v, i);
    v.pop_back();
  }
}
int main()
{
    
    FIO;
    ll t, q, n, m, prev, maxx,  i, j, k1, k2, k3, k, x, y, flag, sum, cnt, ans, minn, cur;
    cin>>no>>M>>qo;
    rep(i,0,qo)
    {
      cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    vll v;
    dfs(v, 1);
    cout<<res<<endl;
    return 0;    
}


Measured memory_bytes: 3640
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int N;
    int a[10000]={};
    int cnt = 0;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> a[i];
        while(a[i] % 2 == 0){
            a[i] /= 2;
            cnt++;
        }
    }
    cout << cnt << endl;
}


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

using namespace std;

char s[500005];

int a[500005];

int main(){
    cin>>s+1;

    int n=strlen(s+1);

    long long res=0;

    vector<int>v;
    for(int i=1;i<=n;++i){
        if(s[i]=='<'&&s[i-1]!='<'){
            a[i]=0;
            v.push_back(i);
        }
    }
    for(auto x:v){
        for(int i=x;;++i){
            if(s[i]=='<'){
                a[i+1]=a[i]+1;
            }else{
                break;
            }
        }
    }

    v.clear();
    for(int i=n;i>=1;--i){
        if(s[i]=='>'&&s[i+1]!='>'){
            a[i+1]=0;
            v.push_back(i);
        }
    }
    for(auto& x:v){
        for(int i=x;;--i){
            if(s[i]=='>'){
                a[i]=max(a[i],a[i+1]+1);
            }else{
                break;
            }
        }
    }


    for(int i=1;i<=n+1;++i)res+=a[i];

    cout<<res;

    return 0;
}


Measured memory_bytes: 6092
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<sstream>
#include<algorithm>
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

using namespace std;

struct Data{
  int start,end,onAir,recorded;
  bool operator<(const Data &data) const{
    if(end != data.end) return end < data.end;
    if(start != data.start) return start < data.start;
    return (onAir != data.onAir ) ? onAir < data.onAir : recorded < data.recorded;
  }
};

const int MAX_N = 1100;
int N,dp[2000][2000],h,m;
vector<int> buf;


int toTime(string s){
  rep(i,(int)s.size()) if(s[i] == ':') s[i] = ' ';
  stringstream ss(s);
  ss >> h >> m;
  return h * 60 + m;
}

int main(void){
  while(cin>>N,N){
    vector<Data> vec(N);
    rep(i,N){
      string a,b,c;
      cin>>a>>b>>c>>vec[i].onAir>>vec[i].recorded;
      vec[i].start = toTime(b); vec[i].end = toTime(c); 
    }
    vec.push_back((Data){0,0,0,0});
    rep(i,N+2)rep(j,N+2)dp[i][j] = 0;
    sort(vec.begin(),vec.end());
    buf.clear();
    rep(i,vec.size())buf.push_back(vec[i].end);
    rep(i,vec.size()){
      rep(j,vec.size()){
        if(i==j)dp[i][j] = max((i?dp[i-1][j]:0),(j?dp[i][j-1]:0));
        else if(i<j){
          int prev = upper_bound(buf.begin(),buf.begin()+j,vec[j].start) - buf.begin() - 1;
          dp[i][j] = max(dp[i][j-1],((prev!=-1)?dp[i][prev]:0)+vec[j].recorded);
        }else{
          int prev = upper_bound(buf.begin(),buf.begin()+i,vec[i].start) - buf.begin() - 1;
          dp[i][j] = max(dp[i-1][j],((prev!=-1)?dp[prev][j]:0)+vec[i].onAir);
        }
      }
    }
    cout<<dp[(int)vec.size()-1][(int)vec.size()-1]<<endl;
  }
}

Measured memory_bytes: 9452
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;


#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	string s;
    cin >> s;
    vector<ll> ans(2,0); //tの数,sの数
    if(s[0]=='S'){
        ans[1]++;
    }else{
        ans[0]++;
    }
    for(ll i=1;i<s.size();i++){
        if(s[i]=='S'){
            ans[1]++;
        }else{
            if(ans[1]>0){
                ans[1]--;
            }else{
                ans[0]++;
            }
        }
    }

    cout << ans[0]+ans[1]<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <string.h>
 
#define rep(i,n)    for(ll i=0;i<n;i++)
#define repu(i,k,n) for(ll i=k;i<=n;i++)
#define repd(i,k,n) for(ll i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define endl "\n"
#define INF (ll)ll_MAX
 
typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector<ll> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, ll > > vpp;
 
const ll N = 3*1e5 +5 ;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long inf = 1e18;
 
using namespace std;

 

void solve()
{	
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++) cin>>a[i];
    ll ans = 0;
    sort(a,a+n);
    reverse(a,a+n);
    ll ctr=0;
    for(ll i=0;i<n;i++){
        if(i==0){
            ans += 0;
        }
        else if(i==1){
            ans += a[ctr];
            ctr++;
        }
        else if(i%2==0){
            ans+=a[ctr];
        }
        else{
            ans+=a[ctr];
            ctr++;
        }
    }
    cout<<ans;

    
}
     
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    //cout<<"helo";
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll t = 1;
    // cin>>t;
    ll ctr=0;
    while(t--)
    {   
        ctr++;
        if (ctr==14) cout<<1;
        solve();    
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
 
}

Measured memory_bytes: 5368
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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


int main(void) {
	int a, b, c;
	bool flag = false;

	cin >> a >> b >> c;

	if (a == b + c || b == a + c || c == a + b) {
		flag = true;
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int maxn = 1e4 + 5;
int f[maxn];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int x = 1; x <= 100; x++)
		{
			if ((x + 2) * (x + 2) - (x + x + 1) > i)
				break;
			for (int y = 1; y <= 100; y++)
			{
				if ((x + y + 1) * (x + y + 1) - (x * y + x + y) > i)
					break;
				for (int z = 1; z <= 100; z++)
				{
					if ((x + y + z) * (x + y + z) - (x * y + x * z + y * z) > i)
						break;
					else if ((x + y + z) * (x + y + z) - (x * y + x * z + y * z) == i)
						f[i]++;
				}
			}
		}
	}
	for (int i = 1; i <= n; i++)
		printf("%d\n", f[i]);
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stdio.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    string a,b;
    cin >> a >> b;
    a += b;
    int tmp = atoi(a.c_str());
    for (int i = 1; i <= tmp; ++i) {
        if(i*i == tmp){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main()
{
    int n;
    cin>>n;
    if(n>=400 && n<=599) cout<<8<<endl;
    if(n>=600 && n<=799) cout<<7<<endl;
    if(n>=800 && n<=999) cout<<6<<endl;
    if(n>=1000 && n<=1199) cout<<5<<endl;
    if(n>=1200 && n<=1399) cout<<4<<endl;
    if(n>=1400 && n<=1599) cout<<3<<endl;
    if(n>=1600 && n<=1799) cout<<2<<endl;
    if(n>=1800 && n<=1999) cout<<1<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int n;
vector<pair<int,int> > edge[1000];
int c[1000];

int dfs(int u,int p=-1){
	int res=0;
	rep(i,edge[u].size()){
		pair<int,int> &e=edge[u][i];
		if(p==e.first)continue;
		if(c[e.first])res+=e.second;
		else res+=min(e.second,dfs(e.first,u));
	}
	return res;
}


int main(){
	cin>>n;
	rep(i,n-1)cin>>c[i+1];
	rep(i,n-1){
		int u,v,p;
		cin>>u>>v>>p;
		edge[u].push_back(make_pair(v,p));
		edge[v].push_back(make_pair(u,p));
	}
	cout<<dfs(0)<<endl;
	return 0;
}

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

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double limtheta = atan(b / a);
  double ans;
  ans = a * b * b / (2 * x);
  if (atan(ans) <= limtheta)  ans = 2 * (a * a * b - x) / (a * a * a);
  ans = atan(ans);
  double rad = ans * 180 / M_PI;
  printf("%.12lf", rad);
}

Measured memory_bytes: 256
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
using namespace std;
inline int rd(){
	int res=0,sign=1;char ch;
	while((ch=getchar())<'0'||ch>'9')if(ch=='-')sign=-1;res=res*10+ch-48;
	while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;
	return res*sign;
}
int a,b,c,n;
int sum,ans;
int main(){
    cin>>a>>b>>c>>n;
    for(int i=0;i<=a;i++)
     for(int j=0;j<=b;j++)
      for(int k=0;k<=c;k++){
      	sum=i*500+j*100+k*50;
      	if(sum==n)
      		ans++;
      	if(sum>n)break;
	  }
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Sum AND Subarrays
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_M = MAX_N * (MAX_N + 1) / 2;

/* typedef */

typedef long long ll;

/* global variables */

ll asums[MAX_N + 1], ss[MAX_M];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    asums[i + 1] = asums[i] + ai;
  }

  int m = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j <= n; j++) ss[m++] = asums[j] - asums[i];

  //printf("m=%d\n", m);
  //for (int i = 0; i < m; i++) printf("%lld ", ss[i]); putchar('\n');

  ll x = 0;
  for (ll bi = 1LL << 39; bi > 0; bi >>= 1) {
    ll y = x | bi;
    int c = 0;
    for (int i = 0; c < k && i < m; i++)
      if ((y & ss[i]) == y) c++;
    if (c >= k) x = y;
  }

  printf("%lld\n", x);
  return 0;
}


Measured memory_bytes: 4224
// Q - Flowers

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

int N;
vector<int> h;
vector<ll> a, tree;

void update(int i, ll v) {
    i += N;
    tree[i] = v;
    i >>= 1;
    while(i > 0) {
        tree[i] = max(tree[i<<1], tree[i<<1|1]);
        i >>= 1;
    }
}

ll max(int r) {
    int l;
    ll sum = 0;
    l = N, r += N;
    while(l<=r) {
        if(l&1) sum = max(sum, tree[l++]);
        if(!(r&1)) sum = max(sum, tree[r--]);
        l >>= 1;
        r >>= 1;
    }
    return sum;
}

int main(int argc, char **argv) {
    scanf("%d", &N);
    h.assign(N, 0);
    a.assign(N, 0LL);
    tree.assign(4*N, 0LL);
    REP(i,N) {
        scanf("%d", &h[i]);
    }
    REP(i,N) {
        scanf("%lld", &a[i]);
    }

    ll res = 0LL;
    for(int i = 0; i < N; i++) {
        ll sum = max(h[i]-1);
        update(h[i]-1, a[i]+sum);
        res = max(res, sum+a[i]);
    }

    printf("%lld\n", res);
}


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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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; }

int main() {
    int N,H;
    cin >> N >> H;
    
    vector<int> a(N), b(N);
    REP(i,N) cin >> a[i] >> b[i];
    
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    
    sort(a.begin(),a.end());
    int A = a[N-1];
    int count = 0;
    REP(i,N){
        int B = b[i];
        if ( B > A and H > 0 ) {
            H -= B;
            ++count;
        } else {
            break;
        }
    }
    
    int sho = 0, amari = 0;
    if ( H > 0 ) {
        amari = H % A;
        sho = H / A;
        if ( amari != 0 ) ++sho;
    }
    count += sho;
    
    cout << count  << endl;
    
    
    return 0;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
 
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define N 2000001
#define M 1000000007
#define INF 1000000000000000
 
 
int main()
{
	string s;
	ll ans=0;
	cin>>s;
	ll i;
	for(i=0;i<(ll)s.length();i++)
	{
		ans=ans+(ll)s[i]-'0';
	}
	if(ans%9)cout<<"No";
	else cout<<"Yes";
 
}

Measured memory_bytes: 3724
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
#include <list>
#include <iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
typedef pair<string,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
const ll MODatc = 1000000007;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
bool pairCompare2(P firstElof,P secondElof){
    return (firstElof.second)%1000>(secondElof.second)%1000;
}
bool less_mod1000(int lhs, int rhs) {
  if ((lhs - rhs) % 1000 != 0)
    return lhs % 1000 < rhs % 1000;
  else // 5で割った余りが等しいなら普通に大小比較する
    return lhs < rhs;
}
string A="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string a="abcdefghijklmnopqrstuvwxyz";
ll dp[107000];
ll jump(ll start,ll goal){
  if(dp[start]>=0)return dp[start];
  if(start==goal){
    return 1;
  }elif(start>goal){
    return 0;
  }
  return dp[start]=(jump(start+1,goal)+jump(start+2,goal))%MODatc;
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    sort(all(s));
    if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	if k > n && (k- n) > n {
		fmt.Println(n)
	}else{
		t1 := n % k
		t2 := k - t1
		if t1 > t2 {
			fmt.Println(t2)
		}else{
			fmt.Println(t1)
		}
	}
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

constexpr int mod = 1e9 + 7;
constexpr int32_t inf = 1001001001;
constexpr int64_t infll = 1001001001001001001ll;
constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

// clang-format off
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }

template <typename T> void sort(vector<T> &v) { sort(all(v)); }
template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  cout << in() / 3 << endl;
}


Measured memory_bytes: 256
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p_x = []
for i in range(m):
    p_x.append(list(map(int, input().split())))
for i in range(m):
    t_sub = t.copy()
    t_sub[p_x[i][0]-1] = p_x[i][1]
    print(sum(t_sub))

Measured memory_bytes: 3060
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <climits>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <math.h>

using namespace std;

int gcd(int a, int b)
{
	if (b == 0) {
		return a;
	} else if (a == 0) {
		return b;
	}
	return gcd(b, a%b);
}

int main(void)
{
	int n;
	cin >> n;
	int a[n];
	int l[n+1], r[n+1];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	l[0] = 0;
	r[n] = 0;

	for (int i = 1; i < n+1; i++) {
		l[i] = gcd(l[i-1], a[i-1]);
	}
	for (int i = n-1; i >= 0; i--) {
		r[i] = gcd(r[i+1], a[i]);
	}

	int m = 1;
	for (int i = 1; i < n+1; i++) {
		int d = gcd(l[i-1], r[i]);
		m = max(m, d);
	}

	cout << m << endl;


	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);  \
  cout.tie(NULL);									
 
ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}
 
ll binpow(ll a, ll b) {ll res = 1;while (b > 0) {if (b & 1) res = res * a;a = a * a;b >>= 1;}return res;}
 
//jabardasti bfs

vector<ll> adj[100005];
bool vis[100005];
ll d[100005];
ll ie[100005]; 
ll ans;
 
 void dfs(ll u){
	vis[u] = true;
	for(auto v : adj[u]){
		ie[v]--;
		d[v] = max(d[v],d[u]+1);
		ans = max(ans,d[v]);
		if(ie[v]==0) dfs(v);
	}
	
	
 }
 
 
int main(){
	adiii
	ll n,m;cin>>n>>m;
	rep(i,0,m){
		ll u,v;cin>>u>>v;
		adj[u].pb(v);
		ie[v]++;
	}
	
	rep(i,1,n+1){
		if(vis[i] == false && ie[i]==0){
			dfs(i);
		}
	
	}
	cout<<ans<<endl;
	
}


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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int div(int n){
    int cnt=0;
    for(int i=1;i*i<=n;i++){
        if(n%i==0)++cnt;
        if(n/i!=i)++cnt;
    }
    return cnt;
}
vector<ll> v(10000001);

void seive(){
    for(int i=1;i<=10000000;i++){
        // if(v[i])continue;
        v[i]++;
        for(int j=i*2;j<=10000000;j+=i)v[j]++;
    }
}

void solve()
{
    seive();
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        sum+=1LL*i*v[i];
    }
    cout<<sum<<"\n";
}

int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 81252
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#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 = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int a, n,s, b[114514] = {}, ans = 0;
	cin >> n >> s;
	REP(i, n) cin >> b[i];
	sort(b, b + n);
	REP(i, n) {
		if (s < b[i]) break;
		else {
			s -= b[i];
			if (i == n - 1) {
				if (s == 0)ans++;
			}
			else ans++;
		}
	}
	cout << ans << endl;
}








Measured memory_bytes: 768
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, n, a) for (int i = (n)-1; i >= (a); i--)
#define repit(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define sortt(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define co(x) cout << (x)
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define mkp make_pair
#define mkt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
// inline void fastio() { ios::sync_with_stdio(false), cin.tie(0); }
/******* Variable ************************************/
const int maxn = 1e6 * 50;
const int inf = 1e9 + 7;
const double pi = 3.141592653589;
/******* Function ************************************/
/******* Main ****************************************/
void Main() {
  int n, h;
  string s;
  while (cin >> s) {
    if (s == "-") break;
    int ls = s.size();
    cin >> n;
    rep(i, 0, n) {
      int h;
      cin >> h;
      s = s.substr(h, s.size()) + s.substr(0, h);
    }
    cout << s << "\n";
  }
}

/******************************************************
  Smaile!
▕▔╲┊┊┊┊┊┊┊┊┊╱▔▏
┊╲┈╲╱▔▔▔▔▔╲╱┈╱┊
┊┊╲┈╭╮┈┈┈╭╮┈╱┊┊
┊┊╱┈╰╯┈▂┈╰╯┈╲┊┊
┊┊▏╭╮▕━┻━▏╭╮▕┊┊
┊┊╲╰╯┈╲▂╱┈╰╯╱
                      How`s it going?
                              |＼
                      　／￣＼　ヽ
                      ／　　　ヽ |_
                      ￣＼　　　　 ＼
                      ／￣　/|/| /ﾚ､ ヽ＿
                      ￣＼ Yヘ |/ヘ幺　∠
                      　＜_|(･> <･) 6) ／
                      　　 (ﾞ　_　ﾞ／＜
                      　　　＞､ーイ￣￣
                      　　／厂ヽ／￣/＼
                      　 ( ｜　(亀)(>　)▏

                            Take a rest before getting tired!
                                        　　 ●
                                        　　/⌒ヽ
                                        　 ｜ 　|/⌒ヽ(ヽ
                                        　 (｀　∥ー⌒) |
                                        　|￣||￣￣￣￣￣|
                                        　|―||―――――|
                                        　|　Ｕ　　　　　|
                                        　|￣￣￣￣￣￣￣|
                                        　|＿＿＿＿＿＿＿|
                                        　　|―――――|
                                        　　|―――――|
                                        ｗｗＷｗｗＷｗＷＷｗ

******************************************************/
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end(), greater<ll>());
  ll m = N / 2;
  ll sum = A[0];
  for (ll i = 1; i < m; i++) sum += 2 * A[i];
  if (N % 2 == 1) sum += A[m];
  cout << sum << endl;

  return 0;
}



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

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

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

int main() {
	string S; cin >> S;
	int num1 = atoi(S.substr(0, 2).c_str());
	int num2= atoi(S.substr(2).c_str());
	if (num1 > 12 || num1 == 0) {
		if (num2 > 12)cout << "NA";
		else if (num2 > 0)cout << "YYMM";
		else cout << "NA";
	}
	else if (num1 > 0) {
		if (num2 > 12)cout << "MMYY";
		else if (num2 > 0)cout << "AMBIGUOUS";
		else cout << "MMYY";
	}
}

Measured memory_bytes: 256
#include <cstdio>
typedef long long LL;

const int mod = 1e9 + 7;
LL p[1010];

void getp(int x) {
	for(int i = 2; i * i <= x; ++i) {
		if(x % i == 0) {
			while(x % i == 0) {
				p[i]++;
				x /= i;
			}
		}
	}
	if(x > 1) p[x]++;
}

int main() {
	int n;
	scanf("%d", &n);
	for(int i = 2; i <= n; ++i) {
		getp(i);
	}
	LL sum = 1;
	for(int i = 1; i <= n; ++i) {
		sum = (sum * (p[i] + 1)) % mod;
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 128
def s_sort(A,N):
   global count

   for i in range(N):
       min_j = i
       for j in range(i,N):
           if A[j] < A[min_j]:
               min_j = j

       if i != min_j:
           temp = A[i]
           A[i] = A[min_j]
           A[min_j] = temp
           count += 1

   return A
  
if __name__=='__main__':
    n = int(input())
    R = list(map(int,input().split()))
    count = 0
    R = s_sort(R,n)
    print(" ".join(map(str,R)))
    print(count)



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

int main(){
    long long A,B,C,D,N;
    scanf("%lld %lld %lld %lld %lld",&A,&B,&C,&D,&N);
    long long pa,pb,pc,pd;
    pa=A*8;
    pb=B*4;
    pc=C*2;
    pd=D;
    long long PL[4]={pa,pb,pc,pd};
    long long PL2[3]={pa/2,pb/2,pc/2};
    sort(PL,PL+4);
    sort(PL2,PL2+3);
    long long ans=0;
    if(N%2==0){
        ans=(N/2)*PL[0];
        cout << ans << endl;

        return 0;

    }else{
        ans=(N/2)*PL[0]+PL2[0];
        cout << ans << endl;

        return 0;

    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int h,w;
    scanf("%d %d",&h,&w);
    char a[101][101];
    int i;
    for(i=0;i<h;i++){
        scanf("%s",a[i]);
    }
    for(i=0;i<h;i++){
        printf("%s\n%s\n",a[i],a[i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  
  vector<int> A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  int min=10000;
  for(int tmp : A){
    int num=0;
    while(true){
      if((tmp%2)==1){break;}
      else{tmp/=2; num++;}
    }
    if(num<min)min=num;
  }
  cout << min << endl;
}



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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);i++)
#define FOR2(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MP make_pair
#define FAST ios_base::sync_with_stdio(false); cin.tie(0)

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

template<class T>
ostream &operator<<(ostream &os,const vector<T> &x) {
    os << '[';
    if ( !x.empty() ) {
        std::copy (x.begin(), x.end(), std::ostream_iterator<T>(os, ","));
        os << "\b";
    }
    os << "]";
    return os;
}
template<class T>
ostream &operator<<(ostream &os,const vector<vector<T> > &x) {
    os << '[';
    if ( !x.empty() ) {
        for (auto v: x) os << v << ",";
        os << "\b";
    } else os << "[]";
    os << "]";
    return os;
}



int main() {
    FAST;
   // freopen("in.txt", "r", stdin);
    int n;
    cin >> n;
    vi a(n),f(n);
    FOR(i,n) cin>>a[i];
    int l=n-2,r=n-1;
    ll x=0;
    f[n-1]=1;
    while (l>=0){
        while((x & a[l]) && r>l) x -= a[--r];
        x += a[l];
        while((x & a[r]) && r>l) x -= a[--r];
        f[l] = r-l+1;
        l--;
    }
    ll ret=0;
    for (int ff:f) ret += ff;
    cout << ret;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    cout << fixed << setprecision(10) << double(w * h) / 2 << " ";

    if (x * 2 == w  && y * 2 == h) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}

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

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

    if (A == B)
    {
        cout << C;
    }
    else if (B == C)
    {
        cout << A;
    }
    else
    {
        cout << B;
    }
}

Measured memory_bytes: 256
def howmanytwo(m):
  ret=0
  while m%2==0:
    ret+=1
    m=m//2
  return ret

N=int(input())
A=[int(i) for i in input().split()]
evn=[howmanytwo(a) for a in A]
od=evn.count(0)
evev=0
for x in evn:
  if x>=2:
    evev+=1
if od+evev!=N:
  evev+=1
else:
  evev+=2
print('Yes' if od+1<=evev else 'No')

Measured memory_bytes: 14252
n = int(input())
h = input().split()
h = [int(i) for i in h]
sum,sub = 0,0
for i in range(1,n):
	if h[i-1] > h[i]:
		sum += h[i-1] - sub
		sub = h[i]
if h[len(h)-2] <= h[len(h)-1]:
	sum += h[len(h)-1] - sub
print(sum)

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

const int IINF = 2002002002;
const ll LINF = 9009009009009009009LL;

//===



int main()
{
	int M, D;
	cin >> M >> D;

	int ans = 0;
	for (int m = 1; m <= M; ++m) {
		for (int d = 1; d <= D; ++d) {
			int d1, d10;
			d10 = d / 10;
			d1 = d % 10;

			if (d1 >= 2 && d10 >= 2) {
				if (d1 * d10 == m) {
					++ans;
				}
			}
		}
	}

	cout << ans << endl;

}

Measured memory_bytes: 256