akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.StringTokenizer;

public class Main  implements Runnable {
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 64 * 1024 * 1024).start();
    }
    public void run() {
    	FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int[] a = new int[n];
		int[] an = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
			an[i] = 0; 
			for (int j = 0; j < i; j++) {
				if(a[i] < a[j])
				{
					an[i]++;
				}
			}
		}
		int[] at = new int[n];
		for (int i = 0; i < n; i++) {
			at[i] = 0;
			for (int j = 0; j < n; j++) {
				if(a[i] < a[j])
				{
					at[i]++;
				}
			}
		}

		long anst = 0;
		for (int i = 0; i < n; i++) {
			anst += at[i];
		}
		long ansn = 0;
		for (int i = 0; i < n; i++) {
			ansn += an[i];
		}
		long ans = 0;
		long kp = ((long)(k-1)*((long)k))/2l;
		kp = kp % 1000000007l;
		//for (int i = 1; i <= k; i++) {
		//	ans += anst*((long)i-1l);
		//	ans += ansn;
		//	ans = ans % 1000000007l;
		//}
		ans += kp*anst;
		ans = ans % 1000000007l;
		ans += k*ansn;
		ans = ans % 1000000007l;
		out.printf("%d\n", ans);
		out.println();
		out.flush();
	}


    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }
        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }
    }
}

Measured memory_bytes: 25424
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;

#define _ cin.tie(0);ios::sync_with_stdio(false);
llong a;
llong mod=1000000007;
int main(){ _;
  cin>>a;
  llong ans=1;
  FOR(i,1,a+1)
    ans=((ans%mod)*(i%mod))%mod;
  cout<<ans<<endl;
	  

  return 0;
}


Measured memory_bytes: 256
import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)
  val req = Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .toArray
    .sortBy(e => e(1))

  def rec(cnt:Int, pos:Int, i:Int):Int = {
    if(i == m) cnt
    else if(pos < req(i)(0)) rec(cnt+1, req(i)(1)-1, i+1)
    else rec(cnt, pos, i+1)
  }

  val ans = rec(0,0,0)
  println(ans)
}

Measured memory_bytes: 66696
# coding: utf-8
# Here your code !

def test():
    line=input().rstrip()
    list=line.split(" ")
    try:
        a=int(list[0])
        b=int(list[1])
    except:
        print("input error")
        return -1 
    
    if(a>b):
        print("a > b")
    elif(a<b):
        print("a < b")
    elif(a==b):
        print("a == b")

test()

Measured memory_bytes: 7692
m, d = map(int, input().split())
count = 0
for i_m in range(m + 1):
    for j_d in range(d + 1):
        d_01 = j_d % 10
        d_10 = j_d // 10
        if d_01 < 2 or d_10 < 2:
            continue
        if i_m == d_01 * d_10:
            count += 1
print(count)

Measured memory_bytes: 2940
using namespace std;
#include <bits/stdc++.h>
#define frr(i, r, l) for(int i = r; i >= l; --i)
#define fr(i, l, r) for(int i = l; i < r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair; 
priority_queue< ll, vector <ll> , greater<ll>>pq1,pq2;
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll ans=0,j;
    string s;
    cin>>s;
    ll l = s.length();
    fr(i,0,l)
    {
        if(s[i]=='R')
        {
            j=i;
            ll cnt=0;
            while(s[j]=='R')
            {cnt++;j++;}

            ans=max(ans,cnt);
            i=j; 
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3656
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 10**9 + 7

    N,X,Y = map(int, input().split())
    X -= 1
    Y -= 1
    res = [0]*(N+1)
    for i in range(N-1):
        for j in range(i+1, N):
            a = min(j-i, abs(X-i)+1+abs(j-Y))
            res[a] += 1
    for k in range(1, N):
        print(res[k])


if __name__ == '__main__':
    main()

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;

int main() {
  vector<vector<ll>> dp(100005, vector<ll>(13,0));
  int l,i,j,k;
  string S;
  cin >> S;
  l = S.size();
  
  dp.at(0).at(0) = 1;
  for(i=0; i<l; i++) {
    int c;
    if(S.at(i) == '?')
      c = -1;
    else
      c = S.at(i) - '0';
    
    for(j=0; j<10; j++)
      if(c==-1 || c==j)
        for(k=0; k<13; k++)
          dp.at(i+1).at((k*10+j)%13) += dp.at(i).at(k);
    
    for(j=0; j<13; j++)
      dp.at(i+1).at(j) %= mod;
  }
  
  cout << dp.at(l).at(5) << endl;
}

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

bool IsPrime(long long num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;  // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (long long i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            // 素数ではない
            return false;
        }
    }
    // 素数
    return true;
}

long long decompositPrime(long long n) {
    long long cnt = 0;
    map<long long, long long> m;

    for (long long p = 2; p * p <= n; p++) {
        if (n % p != 0) continue;
        int num = 0;

        while (n % p == 0) {
            num++;
            n /= p;
        }
        m[p] = num;
    }

    if (n != 1) m[n] = 1;
    
    for (auto itr : m) {
        long long index = 1;
        while (itr.second >= index) {
            cnt++;
            itr.second -= index;
            index ++;
        }
    }

    return cnt;
}

int main() {
    //
    long long num;
    int cnt = 0;

    cin >> num;

    if (IsPrime(num) == true) {
        cout << 1;
        return 0;
    }

    cnt = decompositPrime(num);

    cout << cnt;
    //
}


Measured memory_bytes: 3704
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxn=100000+10;
const ll inf=1000000000000000000;
int a[maxn];
char s[maxn];
ll f0,f1,f2;
int i,j,k,l,t,n,m;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
char get(){
	char ch=getchar();
	while (ch!='+'&&ch!='-') ch=getchar();
	return ch;
}
int main(){
	n=read();a[0]=read();
	n--;
	fo(i,1,n){
		s[i]=get();
		a[i]=read();
	}
	f0=a[0];f1=f2=-inf;
	fo(i,1,n){
		if (s[i]=='-'){
			f0-=(ll)a[i];
			f1+=(ll)a[i];
			f2-=(ll)a[i];
			if (f1>f2) f2=f1;
			if (f0>f1) f1=f0;
		}
		else{
			f0+=(ll)a[i];
			f1-=(ll)a[i];
			f2+=(ll)a[i];
		}
		if (f2>f1) f1=f2;
		if (f1>f0) f0=f1;
	}
	printf("%lld\n",f0);
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

#define int long long
#define double long double
#define endl '\n'
#define gcd __gcd
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(), x.end()
const int inf = __LONG_LONG_MAX__;

using namespace std;

void fast_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

signed main() {
  fast_io();

  int a, b, k;
  cin >> a >> b >> k;

  int t = min(a, k);
  a -= t;
  k -= t;

  // cout << "abk " << a << " " << b << " " << k << "\n";

  t = min(b, k);
  b -= t;
  k -= t;

  cout << a << " " << b << "\n";

  return 0;
}


Measured memory_bytes: 256
def print(str, a, b)
  puts str[a..b]
end

def reverse(str, a, b)
  (a > 0 ? str[0..(a - 1)] : "") << str[a..b].reverse << (b < str.length ? str[(b + 1)..(str.length - 1)] : "")
end

def replace(str, a, b, p)
  (a > 0 ? str[0..(a - 1)] : "") << p << (b < str.length ? str[(b + 1)..(str.length - 1)] : "")
end

str = gets.chomp
q = gets.to_i

(1..q).each {
  inputs = gets.chomp.split(" ")
  op = inputs.first
  a, b = inputs.drop(1).take(2).map(&:to_i)
  case inputs.shift
    when "print"
      print(str, a, b)
    when "reverse"
      str = reverse(str, a, b)
    when "replace"
      str = replace(str, a, b, inputs.last)
  end
}

Measured memory_bytes: 8656
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };

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

	int ans = 0;
	for (int i = a; i <= t; i += a) {
		ans += b;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
_s=[input() for _ in range(h)]
s=[[0]*(w+2) for _ in range(h+2)]
for i in range(1,h+1):
  for j in range(1,w+1):
    if _s[i-1][j-1]=='#':
      s[i][j]=1
f=False
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[1][j]==1 and s[i-1][j]+s[i+1][j]+s[i][j-1]+s[i][j+1]==0:
      f=True
print(['Yes','No'][f])

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

int main(){
  long long n,a,b,ans;
  
  cin >> n >> a >> b;
  ans = a*(n/(a+b));
  n %= (a+b);
  ans += min(n,a);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
//typedef long double ld;
//#define for(i,s,e) for(lli i=s;i<=e;i++)
//#define forr(i,e,s) for(lli i=e;i>=s;i--)
#define pb push_back
#define eq push
#define dq pop
#define f front
#define inf 100000000
int main()
{
lli a,b;
cin>>a>>b;
lli c=max(a+b,a-b);
cout<<max(c,a*b);
 return 0;
}


Measured memory_bytes: 256
package main

import(
    "fmt"
    "bufio"
    "os"
)
func main(){
    stdin := bufio.NewReader(os.Stdin)
    var a,b,d,r int
    var f float64
    fmt.Fscan(stdin,&a,&b)
    d=a/b
    r=a%b
    f=float64(a)/float64(b)
    fmt.Printf("%v %v %.5f\n",d,r,f)
}


Measured memory_bytes: 1204
package main

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

func main() {
	r := bufio.NewScanner(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	r.Split(bufio.ScanWords)
	r.Scan()
	n, _ := strconv.Atoi(r.Text())
	r.Scan()
	m, _ := strconv.Atoi(r.Text())
	r.Scan()
	c, _ := strconv.Atoi(r.Text())

	b := make([]int, m)
	for i := 0; i < m; i++ {
		r.Scan()
		b[i], _ = strconv.Atoi(r.Text())
	}

	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			r.Scan()
			a[i][j], _ = strconv.Atoi(r.Text())
		}
	}

	cnt := 0
	for i := 0; i < n; i++ {
		sum := 0
		for j := 0; j < m; j++ {
			sum += b[j] * a[i][j]
		}
		if sum > -c {
			cnt++
		}
	}

	fmt.Fprint(w, cnt)
}


Measured memory_bytes: 1784
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define sum(n)((n)*((n)+1)/2)

char s[200010];
ll a[300];
int main(){
	scanf("%s",s);
	ll n=strlen(s);
	//#{(l,r)|l<=r}-#{(l,r)|l<=r s[l]==s[r]}+1
	
	ll ans=sum(n)+1;
	rep(i,0,n)a[s[i]]++;
	rep(i,0,300)ans-=sum(a[i]);
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <map>
#include <list>

using namespace std;

#define FOR( i, k, n ) for ( int i = ( k ); i <= ( int )( n ); ++i )
#define REP( i, n ) FOR( i, 1, n )

typedef long long ll;
typedef pair< int, int > P;

bool IsBig( int, int );
int TotalDaysY( int );
int TotalDaysM( int, int );
int Days( int, int, int );

int main()
{
	int mill = Days( 1000, 1, 1 );
	int n;  cin >> n;
	while( n-- ) {
		int y, m, d;  cin >> y >> m >> d;
		cout << mill - Days( y, m, d ) << endl;
	}
	return 0;
}

// 大の月か
bool IsBig( int y, int m ) {
	if( y % 3 == 0 ) { return true; }
	return ( m % 2 == 1 );
}

// 1~y年の全日数
int TotalDaysY( int y ) {
	int res = 0;
	REP( i, y ) res += TotalDaysM( i, 10 );
	return res;
}

// y年における1~m月の全日数
int TotalDaysM( int y, int m ) {
	int res = 0;
	REP( i, m ) res += ( IsBig( y, i ) ? 20 : 19 );
	return res;
}

// 1 1 1からの日数
int Days( int y, int m, int d ) {
	int res = 0;
	res += TotalDaysY( y - 1 );
	res += TotalDaysM( y, m - 1 );
	res += d - 1;
	return res;
}

Measured memory_bytes: 1160
N,K = list(map(int, input().split()))

c1 = N // K

cnt = c1
if c1 >= 2:
  cnt += c1 * (c1 - 1) * 3
  if c1 >= 3:
    cnt += c1 * (c1 - 1) * (c1 - 2)

if K % 2 == 0:
  c2 = (N + K // 2) // K
  cnt += c2
  if c2 >= 2:
    cnt += c2 * (c2 - 1) * 3
    if c2 >= 3:
      cnt += c2 * (c2 - 1) * (c2 - 2)
    
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<ll> A(X);
    rep(i, X) cin >> A[i];
    vector<ll> B(Y);
    rep(i, Y) cin >> B[i];
    vector<ll> C(Z);
    rep(i, Z) cin >> C[i];


    vector<ll> AB;
    rep(i, X) rep(j, Y) AB.push_back(A[i] + B[j]);

    sort(all(AB));
    reverse(all(AB));

    vector<ll> ABC;
    rep(i, min((ll)AB.size(), K)) {
        rep (j, Z) {
            ABC.push_back(AB[i] + C[j]);
        }
    }
    
    sort(all(ABC));
    reverse(all(ABC));    

    rep(i, K) {
        put(ABC[i]);
    }
    
}
signed main(){ Main();return 0;}

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

int main()
{
  int n, x, ans;
  cin >> n >> x;
  int l[n+1], d[n+1];
  int i=1;
  ans = 0;
  d[1]=0;
  for(int i=1; i<n+1; i++)  cin >> l[i];
//  for(int i=1; i<n+1; i++)  cout << l[i] << endl;
  while(d[i]<x+1){
    d[i+1]=d[i]+l[i];
    ans++;
  	  i++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n-1];
        int[] b = new int[n];
        for(int i=0; i<n-1; i++) {
            a[i] = sc.nextInt();
        }
        for(int i=0; i<n-1; i++) {
            b[a[i]-1]++;
        }
        for(int i=0; i<n; i++) {
            System.out.println(b[i]);
        }
    }
}

Measured memory_bytes: 57640
from math import log
n = int(input())
a = 10**5

for i in range(n+1):
    j = n-i
    count = 0
    while i > 0:
        count += i%6
        i //= 6
    while j > 0:
        count += j%9
        j //= 9
    a = min(a, count)
print(a)


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
typedef long long ll;

using namespace std;

int main()
{ll N;
 cin >> N; vector<ll> A(N);
 for(ll i = 0; i < N; i++)
 {cin >> A[i];}
 ll c = 0;
 for(ll j = 0; j < N; j++)
 {c += A[j] - 1;}
 cout << c << endl;
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,answer,n;cin >>N;vector<string> s(N);
  for (int i=0;i<N;i++){
    cin >>s.at(i);
  }
  int M;cin>>M;vector<string> t(M);
  for (int i=0;i<M;i++){
    cin >>t.at(i);
  }
  answer=0;
  for (int i=0;i<N;i++){
    n=0;
    for(int j=0;j<N;j++){
      if (s.at(j)==s.at(i)){n++;}
    }
    for(int k=0;k<M;k++){
      if (t.at(k)==s.at(i)){n--;}
    }
    if (answer<n){answer=n;}
  }
  cout<<answer;
}

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

int const N = 1e5 + 100;
int n, dp[N];

int calc(int a){
    if(a == 0) return 0;
    
    int &ret = dp[a];
    if(ret != -1) return ret;
    
    ret = calc(a - 1);
    
    for(int i = 1;i < 6;++i){
        if(a >= pow(9, i)) ret = min(ret, calc(a - pow(9, i)));
    }
    
    for(int i = 1;i < 7;++i){
        if(a >= pow(6, i)) ret = min(ret, calc(a - pow(6, i)));
    }
    
    ret++;
    return ret;
}

int main(){
    memset(dp, -1, sizeof dp);
    
    cin >> n;
    
    cout << calc(n) << endl;
    return 0;
}

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

int main() {
  int N, R;
  cin >> N >> R;
  if(N >= 10){
    cout << R << endl;
  }
  else{
    cout << R + 100*(10-N) << endl;
  }
  
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));
 
  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
   // }
  //}


Measured memory_bytes: 768
from collections import deque

S = deque(input())
lenq = int(input())
Q = [input() for _ in range(lenq)]

# len(S) <= 100000
# lenq <= 2 * 10 ** 5

# q == '1' のとき、実際に反転すると O(N)かかるので反転しないで、
# どちらが先頭かだけの情報を持っておく
head = 1 # or -1
for q in Q:
    if q == '1':
        head *= -1
    else:
        _, f, c = q.split()
        if f == '1':
            if head == 1:
                S.appendleft(c)
            else:
                S.append(c)
        else:  # f == '2'
            if head == 1:
                S.append(c)
            else:
                S.appendleft(c)
S = ''.join(list(S))
if head == -1:
    S = S[::-1]
print(S)


Measured memory_bytes: 21244
#include<stdio.h>
int main(){
int i, j, num, gyou, kosuu, retu, A[150][150]={0};
scanf("%d", &num);
 for(i=1; i<=num; i++){
   scanf("%d %d", &gyou, &kosuu);
   for(j=0; j<kosuu; j++){
     scanf("%d", &retu);
     A[gyou][retu]=1;
   }
 }
for(i=1; i<=num; i++){
   for(j=1; j<num; j++){
     printf("%d ", A[i][j]);
   }
printf("%d\n", A[i][num]);
 }
 return 0;
}

Measured memory_bytes: 1872
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b;
  string op;
  while(true){
    cin>>a>>op>>b;
    if(op=="?")
      break;
    if(op=="+")
      cout<<a+b<<'\n';
    if(op=="*")
      cout<<a*b<<'\n';
    if(op=="-")
      cout<<a-b<<'\n';
    if(op=="/")
      cout<<a/b<<'\n';
  }
  return(0);
}



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

using namespace std;

int NumMine(vector<string> &data,int i,int j){
    int num = 0;
    if (i>0){
        if(j>0){
            if(data[i-1].at(j-1)=='#'){
                num++;
            }
        }
        if(data[i-1].at(j)=='#'){
            num++;
        }
        if(j<(data[i-1].length()-1)){
            if(data[i-1].at(j+1)=='#'){
                num++;
            }
        }
    }
    if(j>0){
        if(data[i].at(j-1)=='#'){
            num++;
        }
    }
    if(j<(data[i].length()-1)){
        if(data[i].at(j+1)=='#'){
            num++;
        }
    }

    if (i<(data.size()-1)){
        if(j>0){
            if(data[i+1].at(j-1)=='#'){
                num++;
            }
        }
        if(data[i+1].at(j)=='#'){
            num++;
        }
        if(j<(data[i+1].length()-1)){
            if(data[i+1].at(j+1)=='#'){
                num++;
            }
        }
    }
    return num;
}

int main(){
    int H, W;
    cin >> H >> W;

    vector<string> data(H);

    for (int i = 0; i < H;i++){
        cin >> data[i];
    }

    for (int i = 0; i < H;i++){
        for (int j = 0; j < W;j++){
            if(data[i].at(j)!='.'){
                continue;
            }else{
                data[i][j] = '0'+NumMine(data, i, j);
            }
        }
    }

    for (int i = 0; i < H;i++){
        cout << data[i] << endl;
    }
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		System.out.printf("%d %d %d", c, a, b);
	}

}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N, K;
    cin >> N >> K;
    cout << min(N % K, K - N % K);
    return 0;
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())
s = input()

for c in s:
  if c =='c':
    print('No')
  elif c=='a':
    if a >0:
      print('Yes')
      a -= 1
    elif b > 0:
      print('Yes')
      b -= 1
    else:
      print('No')
  else:
    if b > 0:
      print('Yes')
      b -= 1
    else:
      print('No')

Measured memory_bytes: 4016
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>

using namespace std;
using ll = long long int;



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

  //vector<int> a(q);
  vector<int> piv(n);

  for(int i=0;i<n;i++) piv[i] = 0;

  for(int i=0;i<q;i++){
    int x;
    cin>>x;
    //a[i] = x;
    piv[x-1]++;
  }

  for(int i=0;i<n;i++){
    if((k-(q-piv[i]))<=0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define fr first
using namespace std;
typedef long long ll;
const int N = 5e5+1;

int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x;
}

int n,k,x[N],y[N],cnt[6001][6001],s[6001][6001];
char o[5];

int sum(int x,int y){
	int x1=x+k-1;int y1=y+k-1;
	x=max(x,0);y=max(y,0);
	if(x1<0||y1<0)return 0;
	return s[x1][y1]-(x?s[x-1][y1]:0)-(y?s[x1][y-1]:0)+(x&&y?s[x-1][y-1]:0);
}

int main(){
	n=read();k=read();
	for(int i=1;i<=n;++i){
		x[i]=read();y[i]=read();
		scanf("%s",o);
		if(o[0]=='W')x[i]+=k;
	}
	for(int i=1;i<=n;++i)x[i]%=2*k,y[i]%=2*k,cnt[x[i]][y[i]]++;
	s[0][0]=cnt[0][0];
	for(int i=1;i<6*k;++i)s[i][0]=s[i-1][0]+cnt[i][0],s[0][i]=s[0][i-1]+cnt[0][i];
	for(int i=1;i<6*k;++i)
	for(int j=1;j<6*k;++j)
	s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+cnt[i][j];
	int ans=0;
	for(int i=0;i<2*k;++i)
	for(int j=0;j<2*k;++j){
		int ret=0;
		ret+=sum(i-k,j-k);
		ret+=sum(i,j);
		ret+=sum(i+k,j+k);
		ret+=sum(i+2*k,j+2*k);
		ret+=sum(i-2*k,j-2*k);
		ret+=sum(i-2*k,j);ret+=sum(i+2*k,j);
		ret+=sum(i,j-2*k);ret+=sum(i,j+2*k);
		ret+=sum(i+k,j-k);
		ret+=sum(i-k,j+k);
		ret+=sum(i-2*k,j+2*k);
		ret+=sum(i+2*k,j-2*k);
		ans=max(ans,ret);
	}
	cout<<ans;
}

Measured memory_bytes: 192768
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, x[100], y[100];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    for(int i = 0; i < n; i++){
        cin >> y[i];
    }

    double a[4];
    for(int i = 0; i < 4; i++)a[i] = 0.0;
    for(int p = 1; p <= 3; p++){
        for(int i = 0; i < n; i++){
            a[p] += pow(fabs(x[i] - y[i]), p);
        }
        a[p] = pow(a[p], 1.0/p);
    }

    for(int i = 0; i < n; i++){
        a[0] = (a[0] < fabs(x[i] - y[i])?fabs(x[i] - y[i]):a[0]);
    }
    printf("%lf\n",a[1]);
    printf("%lf\n",a[2]);
    printf("%lf\n",a[3]);
    printf("%lf\n",a[0]);
    return 0;
}


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

using namespace std;

int main()
{
    long long N;
    long long d = 26;
    string name = "";

    cin >> N;

    while(N != 0){
        char c;
        long long r = N % d;
        r = (r == 0) ? d : r;
        N -= r;
        N /= d;
        c = (char)('a' + (int)r - 1);
        name += c;
    }

    reverse(name.begin(), name.end());
    cout << name << endl;
}


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

using namespace std;

int main() {
	int N, K; cin >> N >> K;
	
	auto counts = array<int, 211111>{};
	auto vals = array<int, 211111>{};
	auto numVals = 0;
	while (N--) {
		int A; cin >> A;

		if (counts[A] == 0) {
			vals[numVals++] = A;
		}
		counts[A]++;
	}

	auto countsFixed = vector<int>(numVals);
	for (auto i = 0; i < numVals; ++i) {
		countsFixed[i] = counts[vals[i]];
	}

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

	auto minBalls = 0;
	for (auto i = 0; i < numVals - K; ++i) {
		minBalls += countsFixed[i];
	}

	cout << minBalls << endl;
}

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

int main() {

  int N;
  cin >> N;

  vector<int> A(N), B(N), C(N);

  rep(i, 2) {
	rep(j, N) {
	  if (i==0) cin >> A[j];
	  else if (i==1) cin >> B[j];
	}
  }

  rep(i, N-1) cin >> C[i];



  int ans = 0;
  rep(i, N) {
	ans+=B[A[i]-1];

	if (A[i]-1 == A[i-1]) {
	  ans+=C[A[i-1]-1];
	}
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
using namespace std;
const int Max= 2e5;
long long t[Max+1];
int main()
{
	int n,T,sum;
	scanf("%d%d",&n,&T);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&t[i]);
	}
	sum=T;
	if(n>1)
	{
	for(int i=1;i<n;i++)
		{
			if(t[i+1]-t[i]>=T)
				sum=sum+T;
			
			else 
				sum=sum+t[i+1]-t[i];
		
}
		printf("%d\n",sum);
}
if(n==1){
	printf("%d\n",T);
}
}


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

using namespace std;

/*

    bottom up.

*/

const int MAXN = 100 + 5 , MAXW = 1e5 + 5;

int n , W;
long long v[MAXN] , w[MAXN];
long long dp[MAXW][MAXN];

main(){

    scanf("%d %d" , &n , &W);

    for(int i = 1 ; i <= n ; i ++){
            scanf("%lld %lld" , &w[i] , &v[i]);
    }


    long long ans = 0;
    for(int current_w = 0 ; current_w <= W ; current_w ++){
            for(int item = 1 ; item <= n ; item ++){

                    int prv_w = current_w - w[item];
                    if(prv_w < 0) { 
                            dp[ current_w ][item] = max(dp[current_w][item] , dp[current_w][item-1]);
                            continue;
                    }

                    dp[current_w][item] = max({dp[current_w][item] , dp[current_w][item-1] , dp[prv_w][item-1] + v[item]});

                    ans = max(ans , dp[current_w][item]);
            }
    }

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

    return 0;
}


Measured memory_bytes: 82304
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
const int N = 1e5+1;
struct node
{
	int val;
	char c;
}ST[2][4*N],non;
string a[2];
int n,m;
node operator + (node l,node r)
{
	node res;
	if(l.c == r.c)
	{
		res.c = l.c;
		res.val = l.val + r.val;
	}
	else
	{
		int t = min(l.val,r.val);
		res.val = l.val - t + r.val - t;
		if(l.val > r.val)	res.c = l.c;
		else				res.c = r.c;
	}
	res.val %= 3;
	return res;
}
void build(int pos,int begin,int end,int num)
{
	if(begin==end)
	{
		ST[num][pos].c = a[num][begin];
		ST[num][pos].val = 1;
		return;
	}
	int mid = (begin+end)/2;
	build(pos*2,begin,mid,num);
	build(pos*2+1,mid+1,end,num);
	ST[num][pos] = ST[num][pos*2] + ST[num][pos*2+1];
}
node find(int pos,int begin,int end,int l,int r,int num)
{
	if(begin>r||end<l)			return non;
	if(begin>=l&&end<=r)		return ST[num][pos];
	int mid = (begin+end)/2;
	return find(pos*2,begin,mid,l,r,num) + find(pos*2+1,mid+1,end,l,r,num);
}
int main()
{
	int q;
	non.c = 'A';
	non.val = 0;
	cin >> a[0];
	cin >> a[1];
	n = a[0].size();
	m = a[1].size();
	build(1,0,n-1,0);
	build(1,0,m-1,1);
	scanf("%d",&q);
	int i,j,k,l;
	while(q--)
	{
		scanf("%d %d %d %d",&i,&j,&k,&l);
		i--;j--;k--;l--;
		node w = find(1,0,n-1,i,j,0);
		node e = find(1,0,m-1,k,l,1);
		if(w.c == e.c)
		{
			if(w.val == e.val)
			{
				printf("YES\n");
			}
			else
			{
				printf("NO\n");
			}
		}
		else
		{
			if((w.val+e.val)%3==0)
			{
				printf("YES\n");
			}
			else
			{
				printf("NO\n");
			}
		}
	}
}


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

int main()
{
  int N,ans=0;
  cin >> N;
  rep(i,N)
  {
    int a,b;
    cin >> a >> b;
    ans+=b-a+1;  
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  long long c;
  cin >> n >> m >> c;
  long long b[m];
  for(int i = 0; i < m; i++) cin >> b[i];
  int res = 0;
  for(int i = 0; i < n; i++){
    long long cnt = c;
    for(int j = 0; j < m; j++){
      long long a;
      cin >> a;
      cnt += a*b[j];
    }
    if(cnt > 0) res++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int A, B;
    cin >> A >> B;
    cout << (A + B) % 24 << endl;

    return 0;
}

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

int main (){
  int n;
  int a[200000];
  set <int> S;
  cin >> n;

  for(int i=0;i<n;i++) cin >>a[i];

  int ans=0;
  set <int> :: iterator it;
  S.insert(0);
  it=--S.end();
  for(int i=0;i<n;i++){ 
    if(S.count(a[i]) ) ans++;
    else S.insert(a[i]);
    while( *--S.end()>a[i] ) S.erase(--S.end());; 
  }

  cout<<n-ans<<endl;


  return 0;
}

Measured memory_bytes: 11340
#include <iostream>
#define fto(i,a,b) for (int i=a; i<=b; i++)
using namespace std;

int main()
{
    int n, m, s=0, a[1000];
    cin >> n >> m;
    fto (i, 1, n) cin >> a[i], s+=a[i];
    int res=0;
    fto (i, 1, n) if (a[i]*4*m>=s) ++res;
    if (res < m) cout << "No" << endl; else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
int a,i;
scanf("%d",&a);
int x[a];
for(i=0;i<a;i++){
	scanf("%d",&x[i]);
}
for(i=0;i<a;i++){
	printf("%d",x[a-i-1]);
	if(i!=a-1){
	printf(" ");
	}else{
	printf("\n");
	} 
}
}


Measured memory_bytes: 2692
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;
int main(void){
    
    while(1){
        int h, w;
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cout << "#" << (j != w-1 ? "" : "\n");
            }
        }cout << endl;
    }
    
    
    
}



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

int main() {
    int n;
    double ans;
    cin >> n;
    for(int i = 0; i < n; i++) {
        double x;
        string u;
        cin >> x >> u;
        ans += (u == "JPY" ? x : x * 380000.0);
    }
    cout << ans << endl;
}

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

typedef long long int ll;
typedef vector<int> vi;			
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> 	pii;
typedef vector<bool> vb;
// #define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#ifdef LOCAL
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}

class SegmentTreeSum{
// 0-Indexed
// update(index, val) 
// query(l, r)
public:
	vector<int> a;
	vector<int> t;
	int n;

	SegmentTreeSum(vector<int> &inp){
		a = inp;
		n = a.size();
		t.resize(4*n);
		build(1, 0, n-1);
	}

	SegmentTreeSum(){ }
	SegmentTreeSum(int len){
		n = len; a.resize(n, 0);
		t.resize(4*n, 0);
	}
	SegmentTreeSum(int len, int val){
		n = len;
		a.resize(n, val);
		t.resize(4*n);
		build(1, 0, n-1);
	}

	int left(int p){ return p<<1;}

	int right(int p){ return (p<<1)+1;}
	
	void build(int v, int tl, int tr){
		if(tl==tr)
        	t[v]=a[tl];
    	else{
        	build(left(v),tl,(tl+tr)/2);
        	build(right(v),(tl+tr)/2+1,tr);
        	t[v] = t[left(v)] + t[right(v)];
    	}
	}

	int rsq(int v, int tl, int tr, int l, int r){
	    if((l>tr)||(r<tl)) return 0;
	    if((tl>=l)&&(tr<=r)) return t[v];
	    int p1=rsq(left(v),tl,(tl+tr)/2,l,r);
	    int p2=rsq(right(v),(tl+tr)/2+1,tr,l,r);
	    return p1 + p2;
	}

	void update(int v,int tl,int tr,int pos){
	    if(tl==tr)
	        t[v]=a[tl];
	    else{
	        if(pos<=(tl+tr)/2)
	            update(left(v),tl,(tl+tr)/2,pos);
	        else
	            update(right(v),(tl+tr)/2+1,tr,pos);
	        t[v] = t[left(v)] + t[right(v)];
	    }
	}

	void update(int pos,int val){
	     a[pos] = val;
	     update(1,0,n-1,pos);
	}

	int query(int l,int r){ 
		return rsq(1,0,n-1,l,r);
	}

	int val(int pos){
		return a[pos];
	}
};

void solve(){
	int n, k; cin>>n>>k;
	vvi positions(n+1);
	vi c(n); for(auto &e: c) cin>>e;
	for(int i = 0; i<n; i++) positions[c[i]].pb(i);
	for(auto &e: positions) reverse(all(e));

	SegmentTreeSum tree(n);
	for(auto &e: positions) if(!e.empty()) tree.update(e.back(), 1), e.pop_back();

	vector<pair<pii, int> > query(k);
	for(int i = 0; i<k; i++) cin>>query[i].F.F>>query[i].F.S, query[i].S = i;
	for(auto &e: query) e.F.F--, e.F.S--;
	sort(all(query));
	
	vi answer(k);	
	int prev = 0;
	for(auto &e: query){
		while(prev<e.F.F){
			if(!positions[c[prev]].empty()) 
				tree.update(positions[c[prev]].back(), 1), positions[c[prev]].pop_back();
			prev++;
		}
		answer[e.S] = tree.query(e.F.F, e.F.S);
	}

	for(auto &e: answer) cout<<e<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef LOCAL
		freopen(".inp.txt", "r", stdin);
    	freopen(".out.txt", "w", stdout);
    	freopen(".err.txt", "w", stderr);
	#endif
	int t=1;
	while(t--)
		solve();
}

Measured memory_bytes: 50648
// D - Powerful Discount Tickets
#include <bits/stdc++.h>
using namespace std;

int in(){int x;scanf("%d",&x);return x;}

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

	priority_queue<int> A;
	while(N--) A.push(in());

	for(;M--; A.pop()) A.push(A.top() / 2);

	long long ans = 0;
	for(;A.size(); A.pop()) ans += A.top();
	cout<< ans <<endl;
}

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

int main() {

  std::string str;
  std::string s;
  bool b;

  std::cin >> str >> s;
  for(int i = 0; i < str.size(); ++i) {
    b = true;
    for(int j = i; j < i+s.size(); ++j) {
      if( str[j%str.size()] != s[j-i] ) {
	b = false;
	break;
      }
    }
    if( b ) {
      std::cout << "Yes" << std::endl;
      return 0;
    }
  }
  std::cout << "No" << std::endl;
  
  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
//#include <algorithm>
//#include <cmath>
//#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int n, k;
    int h;
    int ans = 0;

    cin >> n >> k;
    for(int i=0; i<n; i++){
        cin >> h;
        if(h>=k){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
int main(){
    string s, t;
    vector<int> s2, t2;
    cin>>s>>t;
    rep(i, s.size()){
        s2.push_back(s[i]);
    }
    rep(i, t.size()){
        t2.push_back(t[i]);
    }
    bool c=1;
    if(s.size()==t.size()){
        rep(i, s.size()){
            if(s2[i]!=t2[i])
                c=0;
        }
        if(c==1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    sort(s2.begin(), s2.end());
    sort(t2.begin(), t2.end(), greater<int>());
    bool b;
    rep(i, max(s.size(), t.size())){
        if(t.size()<=i){
            b=1;
            break;
        }
        if(s.size()<=i){
            b=0;
            break;
        }
        if(s2[i]<t2[i]){
            b=0;
            break;
        }
        if(s2[i]>t2[i]){
            b=1;
            break;
        }
    }
    if(b==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


int main(){
    ll n,p;cin >>n>>p;
    ll co1=0,co0=0;
    for (int i = 0; i < n; ++i) {
        ll a;cin >>a;
        if(a%2==0)co0++;
        else co1++;
    }
    ll ans=0;
    if(co1==0){
        if(p==0) {
            ans = pow(2, n);
        }
    }
    else {
        ans=pow(2,n-1);
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 囲む文字 */
	private static final char BORDER = '#';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt(), w = scanner.nextInt();
			String[] a = IntStream.range(0, h).mapToObj(i -> scanner.next()).toArray(String[]::new);
			char[] border = new char[w + 2];
			Arrays.fill(border, BORDER);
			System.out.println(border);
			IntStream.range(0, h).forEach(i -> System.out.println(BORDER + a[i] + BORDER));
			System.out.println(border);
		}
	}
}


Measured memory_bytes: 39720
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int m = sc.nextInt();
    int d = sc.nextInt();
    
    if(m > d){
      System.out.println(m-1);
    }else{
      System.out.println(m);
    }
  }
}


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

using namespace std;

const int N = 1234567;

int a[N], b[N], c[N], d[N];
map <int, int> p;

inline int find_set(int x) {
  if (p.find(x) == p.end()) {
    p[x] = x;
    return x;
  }
  if (x != p[x]) {
    p[x] = find_set(p[x]);
  }
  return p[x];
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", b + i);
  }
  a[n] = b[n] = 0;
  for (int i = 0; i < n; i++) {
    a[n] ^= a[i];
    b[n] ^= b[i];
  }
  n++;
  {
    for (int i = 0; i < n; i++) {
      c[i] = a[i];
      d[i] = b[i];
    }
    sort(c, c + n);
    sort(d, d + n);
    for (int i = 0; i < n; i++) {
      if (c[i] != d[i]) {
        printf("%d\n", -1);
        return 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans += (a[i] != b[i]);
  }           
  if (ans == 0) {
    printf("%d\n", 0);
    return 0;
  }
  vector < pair <int, int> > e;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i] || i == n - 1) {
      e.emplace_back(a[i], b[i]);
    }
  }
  p.clear();
  for (int i = 0; i < (int) e.size(); i++) {
    int x = e[i].first;
    int y = e[i].second;
    int xx = find_set(x);
    int yy = find_set(y);
    if (xx != yy) {
      p[xx] = yy;
    }
  }
  set <int> all;
  for (auto &z : p) {
    all.insert(find_set(z.first));
  }
  ans += (int) all.size();
  ans--;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 16884
A = list(map(int, input().split()))
import fractions
def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)

count_c = 0
count_d = 0
count_cd = 0
cd = lcm(A[2], A[3])
count_c = A[1] // A[2] - (A[0]-1) // A[2]
count_d = A[1] // A[3] - (A[0]-1) // A[3]
count_cd= A[1] // cd - (A[0]-1) // cd

print(A[1] - A[0] + 1 - (count_c + count_d - count_cd))

Measured memory_bytes: 5304
def answer(n, m, taro, hanako):
    for t in sorted(taro):
        for h in sorted(hanako):
            if sum(taro) - t + h == sum(hanako) - h + t:
                return f'{t} {h}'
    return -1


while True:
    n, m = map(int, input().split()) # 組み込み関数input()は標準入力から読み込まれた1行を返す．
    if n == 0 and m == 0:
        break
    taro = []
    hanako = []
    for i in range(n):
        taro.append(int(input()))
    for i in range(m):
        hanako.append(int(input()))
    print(answer(n, m, taro, hanako))




Measured memory_bytes: 5608
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// https://qiita.com/asksaito/items/76b71602dd956b79dbf7
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int main() {
    ll n;
    ll count[110];
    Fill(count,0);
    std::cin >> n;
    for (int i = 2; i <= n; i++) {
        if(!IsPrime(i)){
            continue;
        }
        ll now = n;
        ll res = 0;
        while(now>0){
            res += now/i;
            now/=i;
        }
        count[i] = res;
        // std::cout << i<<" "<<res << std::endl;
    }
    ll result = 0;
    for (int i = 2; i <= n; i++) {
        if( count[i] >=74){
            result++;
        }
    }
    
    for (int i = 2; i <= n; i++) {
        for (int j = 2; j <= n; j++) {
            if(i==j)continue;
            if( count[i] >=2 && count[j] >= 24 ){
                // std::cout << i<<" - "<<j << std::endl;
                result++;
            }
        }
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 2; j <= n; j++) {
            if(i==j)continue;
            if( count[i] >=4 && count[j] >= 14 ){
                // std::cout << i<<" - "<<j << std::endl;
                result++;
            }
        }
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 2; j <= n; j++) {
            for (int k = j+1; k <= n; k++) {
                if(i==j || i==k)continue;
                if( count[i] >=2 && count[j] >= 4 && count[k] >= 4 ){
                    // std::cout << i<<" "<<j<<" "<<k << std::endl;
                    result++;
                }
            }
        }
    }
    std::cout << result << std::endl;
}


Measured memory_bytes: 256
integer N
integer,allocatable,dimension(:)::a
integer ans,kouho
read*,N
allocate(a(N))
read*,a
ans=huge(ans)
do i=minval(a),maxval(a)
  kouho=0
  do j=1,N
    kouho=kouho+(i-a(j))**2
  end do
  ans=min(ans,kouho)
end do
print"(i0)",ans
end

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N;
vi A;
ll sum = 0, W, B, res;

void solve0() { res = max(W,B); }

bool test(int mid) {
    int csum = A[0];
    for (int i = 1; i < sz(A); i += 2) {
        if (csum < mid) csum += A[i+1]-A[i];
        else csum = A[i+1]+max(0,csum-A[i]);
    }
    return csum >= mid;
}

void solve1() {
    int lo = 0, hi = 1e9;
    while (lo < hi) {
        int mid = (lo+hi+1)/2;
        if (test(mid)) lo = mid;
        else hi = mid-1;
    }
    res = W+lo;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N; A.resize(N); F0R(i,N) cin >> A[i];
    F0R(i,N) {
        if (i&1) W += A[i];
        else B += A[i];
    }
    sum = W+B;
    if (N % 2 == 0) solve0();
    else solve1();
    cout << res << " " << sum-res;
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/

Measured memory_bytes: 1408