akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		//END data stand by
		
		int temp;
		
		for(int i=0;i<n;i++) {
			for(int k=i;k<n;k++) {
				if(a[i] > a[k]) {
					temp = a[i];
					a[i] = a[k];
					a[k] = temp;
				}
			}
		}
		//END sort a[i]
		
		for(int i=0;i<n-1;i++) {
			if(a[i]<=x) {
				x -= a[i];
			}else {
				sc.close();
				System.out.println(i);
				return;
			}
		}
		
		if(x == a[n-1]) {
			System.out.println(n);
		}else {
			System.out.println(n-1);
		}
		
		sc.close();
	}

}

Measured memory_bytes: 22100
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,i=1; cin>>n; 
    vector <int> res;
    int l=1,r=n;
    while (l<=r){
      int m=(l+r)>>1;
      if ((m*(m+1))>>1>=n){
          i=m; r=m-1;
      } else l=m+1;
    }
    int sum = (i*(i+1))>>1;
    for (int j=1;j<=i;j++)
        if (sum-n != j) cout << j << endl;
}

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


Measured memory_bytes: 3548
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,m,u,l,a;cin>>n>>m>>l>>u;
  REP(i,n){
    cin>>a;
    l = max(l, a);
  }
  REP(i,m){
    cin>>a;
    u = min(u, a);
  }
  if(u-l>=1){
    P("No War");
  }else{
    P("War");
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String qube = scan.next();
		char[] mozi = qube.toCharArray();

		int count0 = 0;
		int count1 = 0;

		for(int i=0;i<qube.length();i++) {
		if(mozi[i] == '0') {
			count0++;
		}else {
			count1++;
		}
		}

		System.out.println(Math.min(count0, count1)*2);
		scan.close();

	}

}


Measured memory_bytes: 31668
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define print(x) cout << x << endl;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, K;
    cin >> K;
    cin >> X;
    string tmp = "";
    FOR(i, X - K + 1, X + K){
        if(i != X - K + 1){
            tmp += " ";
        }
        tmp += to_string(i);
    }
    print(tmp);
    
    
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
D = set(map(int, input().split()))
safe = set(range(10)) - D

def test(N):
    return set((int(x) for x in str(N))) <= safe

def F(N):
    while N % 10:
        if test(N):
            return N
        N += 1
    N //= 10
    x = F(N)
    y = min(safe)
    return 10 * x + y

answer = F(N)
print(answer)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  int n, d;
  cin >> n >> d;
  vector<vector<int> > x(n, vector<int>(d));
  rep(i, n) rep(j, d) cin >> x[i][j];

  int ans = 0;
  rep(i, n) {
    rep3(j, i + 1, n) {
      int sum = 0;
      rep(k, d) {
        sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      if (abs((int)sqrt(sum) * (int)sqrt(sum) - sum) < 1e-8) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

struct edge{
    int a,b,c;
};

int main(){

    int N,M;
    cin>>N>>M;
    int mindis[N][N];
    fill(mindis[0],mindis[N],1000000000);
    REP(i,N)mindis[i][i]=0;

    vector<edge> es;

    REP(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        edge e={a-1,b-1,c};
        es.push_back(e);
        mindis[a-1][b-1]=c;
        mindis[b-1][a-1]=c;
    }

    REP(k,N){
        REP(i,N){
            REP(j,N){
                mindis[i][j]=min(mindis[i][j],mindis[i][k]+mindis[k][j]);
            }
        }
    }

    int ans=0;
    REP(i,M){
        if(mindis[es[i].a][es[i].b]!=es[i].c){
            ans++;
        }
    }

    cout<<ans<<endl;





    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    
    ArrayList<Double> list= new ArrayList<>();
    for(int i = 0; i < n; i++)
      list.add(sc.nextDouble());
    
    while(list.size() > 2){
    	Collections.sort(list);
      	double a = (list.get(0) + list.get(1))/2.0;
      	list.remove(0);
      	list.remove(0);
      	list.add(a);
    }
    System.out.println((list.get(0) + list.get(1))/2.0);
  }
}

Measured memory_bytes: 23380
import java.util.Scanner;
import java.util.Collections;

class Main{
    static int[][] map;

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int N = scan.nextInt();
        int K = scan.nextInt();
        map = new int[4*K+1][4*K+1];
        for(int i=0;i<N;++i){
            int x = scan.nextInt();
            int y = scan.nextInt();
            if(scan.next().equals("W"))x+=K;
            y%=2*K;x%=2*K;
            map[y+1][x+1]++;
        }
        for(int i=0;i<2*K;++i)for(int j=0;j<2*K;++j)map[i+1][j+2*K+1]=map[i+1][j+1];
        for(int i=0;i<2*K;++i)for(int j=0;j<2*K;++j)map[i+2*K+1][j+1]=map[i+1][j+1];
        for(int i=0;i<2*K;++i)for(int j=0;j<2*K;++j)map[i+2*K+1][j+2*K+1]=map[i+1][j+1];
        for(int i=0;i<4*K;++i)for(int j=0;j<4*K;++j){
            map[i+1][j+1]+=map[i][j+1]+map[i+1][j]-map[i][j];
        }

        int ans = 0;
        for(int i=1;i<=2*K;++i)for(int j=1;j<=2*K;++j){
            ans = Math.max(ans, map[i+2*K-1][j+2*K-1]-map[i+K-1][j+2*K-1]-map[i+2*K-1][j+K-1]+map[i+K-1][j+K-1]
                               +map[i+K-1][j+K-1]    -map[i-1][j+K-1]    -map[i+K-1][j-1]    +map[i-1][j-1]);
        }
        System.out.println(ans);


    }

}

Measured memory_bytes: 162980
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);


int main()
{
    int a,b;
    cin >> a >> b;
    cout << (a&1 && b&1 ? "Yes" : "No") << endl;
    return 0;
}

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

#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 all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int,int> P;
const int INF=1<<29;



int main(){
    string S;
    cin>>S;
    int ans=INF;
    rep(i,0,S.size()-2){
        int a=(S[i]-'0')*100+(S[i+1]-'0')*10 + (S[i+2]-'0');
        ans=min(ans,abs(a-753));
    }
    cout<<ans<<endl;
    
    return 0;
}

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

int main() {
	string S;
	cin >> S;
	int ss = S.size();
	ll aj = 0, ans = 0;
	for (int i = 0;i < ss - 2;i++) {
		if (S[i] == 'A')
			aj++;
		else
			aj = 0;
		if (S[i] == 'A'&&S[i + 1] == 'B'&&S[i + 2] == 'C') {
			ans += aj;
			S[i + 2] = 'A';
			aj--;
			i++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import scala.io.StdIn._
object Main extends App {
  @scala.annotation.tailrec
  def next(diff: Int, maxValue: Int, num: Int, as: Seq[Int]): Int = {
    as match {
      case Nil => num
      case _ => 
        val targetValue = as.head
        val newDiff = maxValue - targetValue
        if (newDiff > diff) next(newDiff, maxValue, 1, as.tail) // must be (targetValue < maxValue)
        else if (newDiff == diff) next(diff, targetValue, num + 1, as.tail) // must be (targetValue > maxValue)
        else next(diff, targetValue max maxValue, num, as.tail)
    }
  }

  /*
  val n = readLine.split(" ").head map {_.toInt}
  val as = (readLine.split(" ") map {_.toInt}).toList.reverse
  */
  import java.io._
  val br = new BufferedReader(new InputStreamReader(System.in));
  val n = br.readLine.split(" ").head map {_.toInt}
  val as = (br.readLine.split(" ") map {_.toInt}).toList.reverse

  println(next(0, as.head, 0, as.tail))
}

Measured memory_bytes: 36796
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
 
int main(){
 int a,b,C;
 double pi=acos(-1);
 cin >> a >> b >> C;
 
 double S=0.5*a*b*sin(C*pi/180);
 double c=sqrt((a*a+b*b)-2*a*b*cos(C*pi/180));
 double L=a+b+c;
 double h=2*S/a;
 
 cout << fixed << setprecision(8);
 cout << S << endl << L << endl << h << endl;
 return 0;
}

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

using namespace std;

int main(){
  long long a,b,x;
  cin >> a >> b >> x;
  long long s=b/x;
  if(a==0){
    cout << s+1 << endl;
    return 0;
  }
  long long t=(a-1)/x;
  cout << s-t << endl;
  
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int h, w;
	long long int count;
  cin >> h >> w;
  if(h == 1 || w == 1){
    cout << 1 << endl;
    return 0;
  }
	count = ((w + 1) / 2 * ((h + 1) / 2) + (w / 2) * (h / 2));
	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void name (int i)
{
  if(i==0)
    cout << "a";
  if(i==1)
    cout << "b";
  if(i==2)
    cout << "c";
  if(i==3)
    cout << "d";
  if(i==4)
    cout << "e";
  if(i==5)
    cout << "f";
  if(i==6)
    cout << "g";
  if(i==7)
    cout << "h";
  if(i==8)
    cout << "i";
  if(i==9)
    cout << "j";
  if(i==10)
    cout << "k";
  if(i==11)
    cout << "l";
  if(i==12)
    cout << "m";
  if(i==13)
    cout << "n";
  if(i==14)
    cout << "o";
  if(i==15)
    cout << "p";
  if(i==16)
    cout << "q";
  if(i==17)
    cout << "r";
  if(i==18)
    cout << "s";
  if(i==19)
    cout << "t";
  if(i==20)
    cout << "u";
  if(i==21)
    cout << "v";
  if(i==22)
    cout << "w";
  if(i==23)
    cout << "x";
  if(i==24)
    cout << "y";
  if(i==25)
    cout << "z";
}

int main()
{
  long N;
  cin >> N;
  int size=1;
  long A=N/26;
  while(A > 0)
    {
      A/=26;
      size++;
    }
  int str[size]={0};
  A=N;
  for(int i = 0 ; i < size; i++)
    {
      str[i] = (A-1) % 26;
      A = ( A - str[i] ) /26;
    }
  for(int i = size-1 ; i >= 0; i--)
    {
      name(str[i]);
    }
  cout << endl;
  return 0 ;
}


Measured memory_bytes: 3592
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>

using namespace std;
typedef long long int ll;

int main()
{
	int wn[300001]={};
	int n;
	char s[300000];
	scanf("%d", &n);
	scanf("%s", s);
	for(int i=1; i<=n; i++){
		if(s[i-1]=='W'){
			wn[i]=wn[i-1]+1;
		}else{
			wn[i]=wn[i-1];
		}
	}
	int ans=10000000;
	for(int i=1; i<=n; i++){
		if(ans>wn[i-1]+n-i-(wn[n]-wn[i])) ans=wn[i-1]+n-i-(wn[n]-wn[i]);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  while(n>0){
if(n%4==0){
  n-=4;
}
else if(n%7==0){
  n-=7;
}
else n-=11;
}
if(n==0)cout<<"Yes";
else cout<<"No";
return 0;
}


Measured memory_bytes: 256
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    s= str(input())
    ls=len(s)
    cur=ls//2
    i=0
    while True:
        i+=1
        cur-=1
        if s[:cur]==s[cur:ls-i*2]:
            print(ls-i*2)
            break


    
resolve()

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

namespace AOJ2
{
    class Program
    {
        static void Main()
        {

            var param = Console.ReadLine().Split(' ');
            while (param[0] != "0")
            {
                var map = Enumerable.Range(0, int.Parse(param[0]))
                .Select(x => Console.ReadLine().Split(' '))
                .Aggregate(new int[int.Parse(param[1])], (a, ca) => a.Select((x, i) => x += int.Parse(ca[i])).ToArray());
                Console.WriteLine(string.Join(" ", map.Select((x, i) => new int[] { x, i }).OrderByDescending(x => x[0]).Select(x => (x[1] + 1).ToString()).ToArray()));
                param = Console.ReadLine().Split(' ');
            }

        }
    }
}

Measured memory_bytes: 6788
#include <iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
using namespace std;
int main(void){
   
string s,t;
cin>>s>>t;


int sl= s.length();
int tl= t.length();
int i=0,j=0,l=-1;
for( i=0;i<(sl-tl+1);i++){
  //  cout<<s[i];
  bool ok=true;
    for( j=0;j<tl;j++){
        if(s[i+j]!='?' && s[i+j]!=t[j])
            ok=false;
        
    }
    if(ok){
        l=i;
    }
    
}
if(l!=-1)
    {
        for(int k=0;k<tl;k++){
            s[l+k]=t[k];
        }
        for(int i=0;i<sl;i++){
            if(s[i]=='?')
                s[i]='a';
        }
        cout<<s<<endl;
        return 0;
    }
cout<<"UNRESTORABLE";
    
}


Measured memory_bytes: 3020
def warshall_floyd(n, d):
    #d[i][j]: iからjへの最短距離
    for k in range(n): #経由する頂点
        for i in range(n): #始点
            for j in range(n): #終点
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d

h,w=map(int,input().split())
c=[list(map(int,list(input().split()))) for _ in range(10)]
a=[list(map(int,list(input().split()))) for _ in range(h)]
e=[x[1] for x in warshall_floyd(10,c)]

ans=0
for i in range(h):
    for j in range(w):
        if a[i][j]!=-1:
            ans+=e[a[i][j]]
print(ans)

Measured memory_bytes: 3444
# coding: utf-8
import math


def prime(X):
    if X == 1:
        return False
    
    for i in range(2, int(math.sqrt(X)) + 1):
        if X % i == 0:
            return False
    return True


X = int(input())
while prime(X) == False:
    X += 1
print(X)


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli dp[410][410];

signed main(){

	lli n;
	cin>>n;
	vector<lli> a(n);
	lli sum[500];
	REP(i,0,500)sum[i]=0;
	REP(i,0,n){
		cin>>a[i];
		sum[i+1] += sum[i]+a[i];
	}

	REP(i,0,410)REP(j,0,410)dp[i][j]=INF;

	REP(i,0,410){
		dp[i][i]=0;
		dp[i][i+1]=0;
	}

	for(lli w=2;w<=n;w++){
		for(lli i=0;i+w<=n;i++){
			for(lli j=i+1;j<i+w;j++){
				dp[i][i+w] = min(dp[i][i+w],dp[i][j]+dp[j][i+w]+sum[i+w]-sum[i]);
			}
		}
	}
	cout<<dp[0][n]<<endl;

}

Measured memory_bytes: 1536
n,m = map(int,input().split())
if n >= m:
  print(0)
  exit()
l = list(map(int,input().split()))
l.sort()
ans = []
for i in range(m-1):
  ans.append(l[i+1]-l[i])
  
ans.sort()
mi = 0
for i in range(m-2,m-1-n,-1):
  mi += ans[i]
print(sum(ans)-mi)

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

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

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } 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.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(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

void solver() {
  string S = input<string>();
  string fr, bc;
  bool rev = false;

  i32 Q = input();
  while (Q--) {
    i32 q = input();

    if (q == 1)
      rev = !rev;
    else {
      i32 f = input() - 1;
      (rev == f ? fr : bc) += input<char>();
    }
  }

  whole(reverse, fr);
  string ans = fr + S + bc;
  if (rev)
    whole(reverse, ans);

  cout << ans << endl;
}

signed main(int argc, char *argv[]) { solver(); }

Measured memory_bytes: 1300
def check v
	return true if (v&v).count == 1
	return true if v[0]+1==v[1] && v[1]+1==v[2]
	return false
end

gets.to_i.times{
	an=gets.split(" ").map{|e|e.to_i}
	ac=gets.split(" ")
	count=0
	c=[[],[],[]]
	ac.each_with_index{|v,i|
		c[0].concat [an[i]] if v == "R"
		c[1].concat [an[i]] if v == "G"
		c[2].concat [an[i]] if v == "B"
	}
	max=0
	3.times{|i|
		maxCount=0
		c[i].permutation{|pset|
			count=0
			(pset.length/3).times{|t|
				#break if !check(pset[3*t..3*t+2])
				count += 1 if check(pset[3*t..3*t+2])
				#count += 1
			}
			maxCount = count if maxCount < count
		}
		max += maxCount
		break if max >= 3
	}
	p 1 if max >= 3
	p 0 if max < 3
}

Measured memory_bytes: 6116
#include<bits/stdc++.h>
using namespace std;
#define double long double
#define int long long 
#define f(z) for(int i=1;i<=z;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
int cl(int n ,int m) { if(n%m)return n/m + 1 ;else return n/m ;}
int pw(int a,int b,int M){a%=M;int r=1;while(b>0){if(b&1)r=r*a%M;a=a*a%M;b>>=1;}return r;}
#define mod  1000000007
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 1e6 + 5  ;

signed main(){
	int n ;
	cin >> n;
	int s =0 ;
	f(n) {
		if( i%3 !=0 && i%5!=0) s+=i;
	}
	cout << s ;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
	int k, s;
	scanf("%d%d", &k, &s);
	int ans = 0;
	rep(i, k + 1) {
		rep(j, k + 1) {
			int l = s - i - j;
			if (0 <= l and l <= k) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> zero;
  vector<int> nonzero;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int s;
    cin >> s;
    sum += s;
    if (s % 10 == 0) {
      zero.push_back(s);
    }
    else {
      nonzero.push_back(s);
    }
  }
  sort(nonzero.begin(), nonzero.end());
  if (sum % 10 == 0) {
    if (nonzero.size() != 0) {
      cout << sum - nonzero[0] << endl;
    }
    else {
      cout << 0 << endl;
    }
  }
  else {
    cout << sum << endl;
  }
}

    

Measured memory_bytes: 256
import scala.util.control.Breaks

object Main extends App {
  val abInput = scala.io.StdIn.readLine()
  val abArray = abInput.split(" ").map(_.toInt).toSeq
  val a = abArray(0)
  val b = abArray(1)
  val break = new Breaks

  var result = -1
  break.breakable {
    (10 to 10000).foreach { i =>
      val aResult = (i * 0.08).toInt
      val bResult = (i * 0.1).toInt

      if(a == aResult && b == bResult) {
        result = i
        break.break()
      }
    }
  }
  println(result)
}

Measured memory_bytes: 27196
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
using ull = unsigned long long;
using P = pair<int, int>;

static constexpr ull MOD = 1000000007;
static constexpr double pi = 3.14159265359;

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

    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    map<int, tuple<int, int>> e, o;
    for (int i = 0; i < v.size(); ++i) {
        if (i % 2 == 0) {
            e[v[i]] = {get<0>(e[v[i]]) + 1, v[i]};
        } else {
            o[v[i]] = {get<0>(o[v[i]]) + 1, v[i]};
        }
    }
    tuple<int, int> E1 = {-1, -1};
    for (auto i : e) {
        E1 = max(E1, i.second);
    }
    tuple<int, int> E2 = {-1, -1};
    for (auto i : e) {
        if (i.second == E1) continue;
        E2 = max(E2, i.second);
    }
    tuple<int, int> O1 = {-1, -1};
    for (auto i : o) {
        O1 = max(O1, i.second);
    }
    tuple<int, int> O2 = {-1, -1};
    for (auto i : o) {
        if (i.second == O1) continue;
        O2 = max(O2, i.second);
    }
    if (E1 != O1) {
        vector<int> v2 = v;
        for (int i = 0; i < n; ++i) {
            if (i % 2 == 0) {
                v2[i] = get<1>(E1);
            } else {
                v2[i] = get<1>(O1);
            }
        }
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            ans += (v[i] != v2[i]);
        }
        cout << ans << endl;
    } else {
        vector<int> v2 = v;
        for (int i = 0; i < n; ++i) {
            if (i % 2 == 0) {
                v2[i] = get<1>(E1);
            } else {
                v2[i] = get<1>(O2);
            }
        }
        int ans1 = 0;
        for (int i = 0; i < n; ++i) {
            ans1 += (v[i] != v2[i]);
        }
        vector<int> v3 = v;
        for (int i = 0; i < n; ++i) {
            if (i % 2 == 0) {
                v3[i] = get<1>(E2);
            } else {
                v3[i] = get<1>(O1);
            }
        }
        int ans2 = 0;
        for (int i = 0; i < n; ++i) {
            ans2 += (v[i] != v3[i]);
        }
        cout << min(ans1, ans2) << endl;
    }
}


Measured memory_bytes: 6008
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
string s,forb;
string ss="";
map<int,bool> mp;
int main()
{
	cin >>s;
	for (int i=0;i<26;i++) forb+=(char)(i+'a');
	reverse(forb.begin(),forb.end());
	if (s==forb)
	{
		cout <<"-1";
		return 0;
	}
	if (s.size()!=26)
	{
		for (int i=0;i<s.size();i++) mp[s[i]-'a']=1;
		for (int i=0;i<26;i++)
		{
			if (!mp[i])
			{
				cout <<s<<(char)(i+'a');
				break;
			}
		}
		return 0;
	}
	for (int i=0;i<s.size();i++)
	{
		string st=s.substr(i);
		int t=0;
		while (next_permutation(st.begin(),st.end()))
		{
			t++;
			break;
		}
		if (!t)
		{
			mp[ss[ss.size()-1]]=0;
			for (int i=ss[ss.size()-1]-'a'+1;i<26;i++)
			{
				if (!mp[i])
				{
		        	ss.erase(ss.size()-1);
					cout <<ss<<(char)(i+'a');
					break;
				}
			}
			return 0;
		}
		else ss+=s[i],mp[s[i]-'a']=1;
	}
	return 0;
}

Measured memory_bytes: 256
import math
n,d = map(int,input().split())
x = []
for i in range(0,n):
    x.append(list(map(int,input().split())))
def f(a,b):
    s = 0
    for l in range(0,d):
        s+=(a[l]-b[l])**2
    return math.sqrt(s)
count = 0
for j in range(0,n):
    for k in range(0,n):
        if not (j==k):
            if f(x[j],x[k])%1==0:
                count = count + 1

print(int(count/2))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
using namespace std;
int get(int x){
    int res = 0;
    while (x){
        res += x%10;
        x/=10;
    }
    return res;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 1e9;
    for (int i=1; i < n; i++) ans = min(ans, get(i) + get(n-i));
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
def soin(n):
	ans=[]
	l=int(n**0.5)+1
	for i in range(2,l+1):
		if n%i==0:
			a=[i,0]
			while n%i==0:
				n//=i
				a[1]+=1
			ans+=[a]
	if n>1:
		ans+=[[n,1]]
	return ans
d={}
n=int(input())
for i in range(2,n+1):
	a=soin(i)
	for j in a:
		if j[0] in d:
			d[j[0]]+=j[1]
		else:
			d[j[0]]=j[1]
k=1
for i in d.values():
	k*=(i+1)
print(k%(10**9+7))

Measured memory_bytes: 74824
#include <stdio.h>

#define N 200

int min(int x,int y){
  if(x>=y){
    return y;
  }
  else return x;
}

int main(){
  int n,i,j,k,l,p[N+1],m[N+1][N+1];

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&p[i-1]);
    scanf("%d",&p[i]);
  }
  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n;i++){
      j=i+l-1;
      m[i][j]=(1<<22);
      for(k=i;k<=j-1;k++){
        m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
typedef queue<ll> qll;
typedef queue<pll> qp;
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(ll i = ll(a - 1); i >= ll(b); i--)
#define rev(...) _overload3(__VA_ARGS__, revi, _rev,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll factorial(ll a){return a < 2 ? 1 : factorial(a - 1) * a;}
ll summation(ll a){return a < 1 ? 0 : (a * a + a) / 2;}
const ll INF = 1e16, MOD = 1e9 + 7;
const string ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
//ll dx[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
ll N, M, X, Y, Z, W, H;
string S, T;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> M){
        ll res = 0, cnt = 0, mx = -INF, mn = INF, a[] = {}, b[] = {}, c[] = {};
        vll v;
        pll p;
        qll q;
        print(N % M ? N : -1);
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
typedef unordered_map<int,int> mp;

const int mod = 1e9+7;
const int inf = 1e17+21;

bool check(string &s){
    int l = 0 , r = s.size() -1;
        while(l < r)
            if(s[l++] != s[r--])    return 0;

    return 1;
}

int32_t main(){
    FAST;

    int a,b;    cin >> a >> b;
    int ans = 0;

    for(int x=a;x<=b;x++){
        string s = to_string(x);
        if(check(s)) ans++;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	var N, i int
	fmt.Fscanf(in, "%d%d", &N, &i)

	fmt.Fprintln(out, N-i+1)
}


Measured memory_bytes: 512
/**
 *    Author: "Robin Singh" !!
 *    rob_in_1
**/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 
template <typename A>
string to_string(A v) {
  bool first = true; 
  string res = "{";
  for (const auto &x : v) {
    if (!first) res += ", ";
    first = false;
    res += to_string(x);
  }
  res += "}"; 
  return res;
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", dbg_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

const long double eps = 1e-9;
const int mod = 1e9+7;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

//===================================================================================================!!

const int nn = 2e5+5;

void solve(){
  int n;
  cin >> n;
  int a[n+1], b[n], ans = 0;
  fr(i, 0, n+1) cin >> a[i];
  fr(i, 0, n) cin >> b[i];

  for(int i = 0; i < n; i++){
    if(b[i] >= a[i]){
      ans += a[i];
      b[i] -= a[i];
      ans += min(a[i+1], b[i]);
      a[i+1] = max(0LL, a[i+1]-b[i]);
    }
    else{
      ans += b[i];
    }
  }
  cout << ans;
}

int32_t main(){
  #ifdef LOCAL 
    // freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
  #endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


#solve
def solve():
    N, a, b = LI()
    ans = pow(2, N, mod) - 1
    dp = [0] * (max(a, b) + 1)
    dp[0] = 1
    for i in range(max(a, b)):
        dp[i + 1] = (dp[i] * (N - i)) * pow(i + 1, mod - 2, mod)
        dp[i + 1] %= mod
    print((ans-dp[a]-dp[b]) % mod)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 56992
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	int ans = 0;
	for (int C = 1; C <= N; C += 2) {
		int count = 0;
		for (int X = 1; X <= C; ++X) {
			if (C % X == 0) {
				++count;
			}
		}
		if (count == 8) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    int n,w;
    cin >> n >> w;
    vector<vector<int>> items(n);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        items.at(i).push_back(a);
        items.at(i).push_back(b);
    }
    vector<ll> dp(w+1), p(w+1);
    rep(i,n){
        swap(dp,p);
        int cw = items.at(i).at(0);
        int cv = items.at(i).at(1);
        // cout << "i:" << i << " " << cw << " " << cv << endl;
        rep(j,p.size()){
            // j 次の重さ
            if(j+cw<=w){
                // cout << j << ":ok" << endl;
                p[j] = max(dp[j], dp[j+cw] + cv);
            }else{
                // cout << j << ":ng" << endl;
                p[j] = dp[j];
            }
        }

        // for(ll x : p) cout << x << " ";
        // cout << endl;
    }

    ll res = 0;
    for(ll x : p){
        res = max(res,x);
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
//const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
const int dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,-1,0,1,-1,1,-1,1};

const int N=16;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int h,w;
		cin>>h>>w;
		if(h==0) break;
		vs a(h);
		for(auto &i:a) cin>>i;
		map<string,int> mp;
		for(int i=0;i<h;i++) for(int j=0;j<w;j++){
			for(int k=0;k<8;k++){
				vvi b(h,vi(w));
				int x=i,y=j;
				string s;
				while(!b[x][y]){
					b[x][y]=1;
					s+=a[x][y];
					x+=dx[k],y+=dy[k];
					if(x>=h) x=0;
					if(x<0) x=h-1;
					if(y>=w) y=0;
					if(y<0) y=w-1;
					mp[s]++;
				}
//				cout<<i<<' '<<j<<' '<<k<<' '<<s<<endl;
//				mp[s]++;
			}
		}
		string res="";
		for(auto p:mp) if(p.second>1&&p.first.size()>res.size()){
			res=p.first;
		}
		if(res.size()<=1) res="0";
		cout<<res<<endl;
//		cout<<mp["ABRACADABRA"]<<endl;
	}
}


Measured memory_bytes: 37940
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    ll h,w;cin>>h>>w;
    ll ans=0;
    if(h%3==0||w%3==0){
        cout<<0<<endl;
        return 0;
    }
    else ans=min(h,w);
    rep2(i,1,h)ans=min(ans,max(i*w,max((h-i)*(w/2),(h-i)*(w-w/2)))-min(i*w,min((h-i)*(w/2),(h-i)*(w-w/2))));
    rep2(i,1,w)ans=min(ans,max(i*h,max((w-i)*(h/2),(w-i)*(h-h/2)))-min(i*h,min((w-i)*(h/2),(w-i)*(h-h/2))));
    cout<<ans<<endl;
}


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

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int sum = 0, ans = 1;
    rep(i, n)
    {
        sum += l[i];
        if (sum <= x)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define MOD 1000000007
#define MAX 510000

long int FAC[MAX],FINV[MAX],INVE[MAX];
long int SUM(long int a,long int b){return (a%MOD+b%MOD+MOD)%MOD;}//a+b
long int PROD(long int a,long int b){return a%MOD*(b%MOD)%MOD;}//a*b
long int POW(long int a,long int b){//a^b
  long int c=1;
  for(a%=MOD;b;a=PROD(a,a),b>>=1)if(b&1)c=PROD(a,c);
  return c;
}
long int INV(long int a){return a<MAX?INVE[a]:POW(a,MOD-2);}//a^-1
long int QUOT(long int a,long int b){return PROD(a,INV(b));}//a/b
void init_inv(long int a){//make inv list
  INVE[1]=1;
  for(long int i=2;i<=a;i++)INVE[i]=SUM(0,-PROD(INVE[MOD%i],MOD/i));
}
void init_com(long int a){//make fac and facinv list
  FAC[0]=FAC[1]=1;
  FINV[0]=FINV[1]=1;
  init_inv(a);
  for(long int i=2;i<=a;i++){
    FAC[i]=PROD(FAC[i-1],i);
    FINV[i]=PROD(FINV[i-1],INV(i));
  }
}
long int COM(long int a,long int b){return PROD(PROD(FAC[a],FINV[a-b]),FINV[b]);}

int main(){
  long int n,i;
  long int dp[64][3];
  scanf("%ld",&n);
  dp[63][0]=1;dp[63][1]=dp[63][2]=0;
  for(i=62;i>=0;i--){
    if((n>>i)&1){
      dp[i][0]=dp[i+1][0];
      dp[i][1]=SUM(dp[i+1][0],dp[i+1][1]);
      dp[i][2]=SUM(PROD(dp[i+1][1],2),PROD(dp[i+1][2],3));
    }
    else{
      dp[i][0]=SUM(dp[i+1][0],dp[i+1][1]);
      dp[i][1]=dp[i+1][1];
      dp[i][2]=SUM(dp[i+1][1],PROD(dp[i+1][2],3));
    }

  }
  printf("%ld",SUM(SUM(dp[0][0],dp[0][1]),dp[0][2]));
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;


int main(){
    int n; cin>>n;
    string s; cin>>s;
    rep(i,s.size()){
        s[i]+=n;
        if('A'<=s[i]&&s[i]<='Z'){
            cout<<s[i];
        }
        else{
            s[i]-=26;
            cout<<s[i];
        }
    }
    cout<<endl;
}








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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

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

int main(){
  int n;
  int l;
  vector <int> v;

  scanf("%d",&n);
  n = 2 * n;
  REP (i, n) {
    scanf("%d",&l);
    v.push_back(l);
  }

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

  int sum = 0;
  for (int i = 0; i < n; i += 2) {
    sum += v.at(i);
  }

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


Measured memory_bytes: 256
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(int N){
    int count = 0;
    for (int i = 1; i <= N; i += 2) {
        int count2 = 0;
        for (int j = 1; j <= N; j++) {
            if (i % j == 0) count2++;
        }
        if (count2 == 8) count++;
    }
    cout << count << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  input = input.split('\n');
  var str = input[1].split('').sort();
  var firstR = str.indexOf('R');

  if (parseInt(input[0]) * .5 - firstR <= 0){
    console.log('No')
  } else {
    console.log('Yes')
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function arrayIn(){
		$buf = explode(" ", fgets(STDIN));
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->arrayIn();
		
		$n = $s[0];
		$m = $s[1];
		$c = $s[2];

		$i = array();

		$i = $this->arrayIn();

		$ans = 0;
		$buf = 0;
		$j = array();
		for($k = 0; $k < $n; $k++){
			$j = $this->arrayIn();
			for($ii = 0; $ii < $m; $ii++){
				$buf += ($i[$ii] * $j[$ii]);
			}
			$buf += $c;
			if(0 < $buf){
				$ans++;
			}
			$buf = 0;
		}

		echo $ans . "\n";

	}
}
?>


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



int main(){
    int x, a, b;
    cin >> x >> a >> b;
    
    if(abs(x-a)<abs(x-b)){
        cout << 'A' <<endl;
    }
    else{
        cout << 'B' <<endl;
        }
}
    
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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; }
 
ll MOD = 1000000007;
ll INF =1<<30;



int main(){
   int n,a,b;
   cin >> n >> a>>b;
   string s;
   cin >> s;
   int cnta = 0,cntb = 0;
   rep(i,n){
       if(s[i]=='c') cout << "No" <<endl;
       else if(s[i]=='a'){
           if(cnta<a+b) {
               cnta++;
               cout << "Yes" <<endl;}
           else cout << "No" <<endl;
       }
       else{
           cntb++;
           if(cnta<a+b&&cntb<=b) {
               cnta++;
               cout << "Yes" <<endl;}
           else cout << "No" <<endl;
       }
   }
}

Measured memory_bytes: 3644
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int a, b;
  cin >> a >> b;
  cout << "a " << (a < b ? "<" : a > b ? ">" : "==") << " b" << endl;
}

Measured memory_bytes: 3084
# include <bits/stdc++.h>
# define int long long
# define endl "\n"
using namespace std;

void solve() {

	int n;
	cin >> n;

	vector <int> rem;
	while (n > 0) {
		n--;
		rem.push_back(n % 26);
		n /= 26;
	}
	for (int i = rem.size() - 1; i >= 0; i--) {
		cout << (char)(rem[i] + 'a');
	}
	cout << endl;
}

signed main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif

	solve();

	return 0;
}

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

typedef long long ll;
#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 LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second
#define P pair<ll,ll>


ll n,ans,cnt;
vector<P> vec[15];
ll type[15];

int main(){
    ll n;
    cin >> n;
    ll cnt_4 = 0,cnt_2 = 0,cnt_1 = 0;
    ll a[n] = {};
    rep(i,0,n){
        cin >> a[i];
        if(a[i] % 4 == 0) cnt_4++;
        else if(a[i] % 2 == 0) cnt_2++;
        else cnt_1++;
    }

    if(cnt_1 > cnt_4+1) cout << "No" << endl;
    else if(!cnt_4 && cnt_1) cout << "No" << endl;
    else if(cnt_1 == cnt_4+1 && cnt_2) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(void){
	long long int n,i,ans=0,j,temp;
	string stone;
	cin >> n;
	cin >> stone;
	temp = n-1;
	i = 0;
	j = n-1;
	for (i=0;i<temp;i++) {
		//cout << 'i' << i << '\n';
		if (stone[i] == 'W') {
			for (j=temp;j>=0;j--) {
				//cout << 'j' << j << '\n';
				if (stone[j] == 'R') {
					if (i<j) {
						ans++;
						temp = j-1;
					}
					break;
				}
			}
		}
		if (i>j) {
			break;
		}
		//cout << i << temp << '\n';
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3708