akhauriyash/Code-Regression huggingface dataset:
def get_kouyakusu(a, b)
  loop do
    rem = b % a
    return a if rem == 0
    a, b = rem, a
  end
  nil
end

while str = gets
  break if str.nil? || str.empty?
  a, b = str.split(' ').map(&:to_i).sort

  # ????????????????????§?????? / ?????§??¬?´???°
  koyakusu = get_kouyakusu(a, b)
  raise 'No result' unless koyakusu

  kobaisu = (a * b / koyakusu)

  puts "#{koyakusu} #{kobaisu}"
end

Measured memory_bytes: 8628
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int N,W;
int v[120],w[120];
const int INF=0;
int dp[120][11100];
int main(){
	cin>>N>>W;
	for(int i=1;i<=N;i++)cin>>v[i]>>w[i];
	for(int i=0;i<=N;i++)for(int j=1;j<=W;j++)dp[i][j]=INF;
	for(int i=1;i<=N;i++){
		for(int j=0;j<=W;j++){
		if(j<w[i])dp[i][j]=dp[i-1][j];
		else dp[i][j]=max(dp[i-1][j],dp[i][j-w[i]]+v[i]);
		}
	}
	//for(int i=0;i<=N;i++){for(int j=0;j<=W;j++){cout<<dp[i][j]<<" ";}cout<<endl;}
	cout<<dp[N][W]<<endl;
	return 0;
}

Measured memory_bytes: 5528
N = int(input())
array = input().split()
flag = True
lst = [0]
for i in range(1, N+1):
        x = int(array[i-1])
        if len(lst) < x:
            flag = False
            break
        lst.insert(x, x)

if flag:
    for i in lst[1:]:
        print(i)
else:
    print(-1)

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

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


/*{
}*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

//constexpr int mod = 1e9+7;
//constexpr int inf = 1<<30;

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

  vi a(n);
  rep(i, 0, n) { cin >> a[i]; }

  vi cnt(101010);
  rep(i, 0, n) cnt[a[i]]++;

  vi tmp(2);
  int ans = 0;
  rep(i, 0, 101010) if(cnt[i]){
    tmp[cnt[i]%2]++;
    ans++;
  }

  if(tmp[0]%2) ans = max(0LL, ans-1);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 2e5 + 10;
inline int Max(int a, int b) { return a > b ? a : b; }
inline int Min(int a, int b) { return a > b ? b : a; }
namespace FastIO {
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
};
using namespace FastIO;
char str[maxn];
signed main()
{
    //freopen("C:\Users\hjw\Downloads\testdata (4).in", "r", stdin);
    scanf("%s", str + 1);
    int N = strlen(str + 1), top = 0;
    int ans = N;
    for (ri i = 1; i <= N; ++i) {
        char now = str[i];
        if (now == 'T' && top) {
            top--, ans -= 2;
        } else if (now == 'S') {
            ++top;
        }
    }
    writeln(ans);   
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long
 
using namespace std;
using P = pair<int,int>;
 
 
unsigned GetDigit(long long num){
    unsigned digit = 0;
    while(num != 0){
        num /= 10;
        digit++;
    }
    return digit;
}
 
int main(){
 
  ll N;
  cin >> N;
  ll ans = 0;
  int digit;
 
  digit = GetDigit(N);
 
  if(digit == 1){
    cout << N << endl;
    return 0;
  }
 
  // 199のような場合を求める
  string num = to_string(N);
  bool flag = false;
  for (int i = 1; i < num.size(); i++) {
    if(num[i] == '9'){
      flag = true;
    }else{
      flag = false;
      break;
    }
  }
 
  if(flag == true){ // 199のような9で詰まる場合は全て足す
    for (int i = 0; i < num.size(); i++) {
      int ni = (int)(num[i]-'0');
      ans += ni;
    }
  }else{ // そうじゃない場合は先頭の桁を切り下げた数値と以下9を足す
    for (int i = 0; i < num.size(); i++) {
      int ni;
      if(i == 0){
        ni = (int)(num[i]-'0') -1;
      } else {
        ni = 9;
      }
      ans += ni;
    }
  }
 
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();//nanido
		int g = sc.nextInt();//mokuhyou
		int p[] = new int[d];//point
		int c[] = new int[d];//comp point
		int cnt = 0;//mondaisu
		int cntmin = 0;
		int sum = 0;
		for (int i = 0; i < d; i++) {
			p[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		for (int bit = 0; bit < (1 << d); bit++) {
			for (int i = 0; i < d; i++) {
				if ((bit & (1 << i)) != 0) {
					sum += p[i] * 100 * (i + 1) + c[i];
					cnt += p[i];
				}
			}
			for (int i = d - 1; i >= 0; i--) {
				if ((bit & (1 << i)) == 0) {
					for (int j = 0; j < p[i] - 1; j++) {
						if (sum >= g) {
							break;
						} else {
							sum += 100 * (i + 1);
							cnt++;
						}
					}
				}
			}
			if (sum >= g && (cntmin == 0 || cnt < cntmin)) {
				cntmin = cnt;
			}
			//System.out.println(cnt);
			cnt = 0;
			sum = 0;
		}
		System.out.println(cntmin);
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = (int)1e9 + 7, INF = (int)1e9;


int main(void) {
	int h, n, i, j, a[1003], b[1003], dp[10003] = {};

	scanf("%d%d", &h, &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &b[i]);
	}

	dp[0] = 0;
	for (i = 1; i <= h; i++) {
		dp[i] = INF;
		for (j = 0; j < n; j++) {
			dp[i] = min(dp[i], dp[max(0, i - a[j])] + b[j]);
		}
	}

	printf("%d\n", dp[h]);

	return 0;
}

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

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

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

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

    vector<int>a(n+2);
    rep2(i,1,n+1){
        cin>>a[i];
    }

    int ans=0;
    rep2(i,1,n+2){
        if(a[i]>a[i+1]){
            ans+=a[i]-a[i+1];
        }
    }

    cout<<ans<<endl;
}


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

char s[65535];
char t[65535];

int main(void)
{
	int n;
	int last, cnt;
	int len;
	int i, j;
	
	while (scanf("%d %s", &n, s) == 2){	
		for (i = 0; i < n; i++){
			last = -1;
			cnt = 0;
			strcpy(t, "");
			strcat(s, "$");
			
			len = strlen(s);
			for (j = 0; j < len; j++){
				if (last != (s[j] - '0')){
					if (last != -1){
						sprintf(t + strlen(t), "%d%d", cnt, last);
					}
					last = s[j] - '0';
					cnt = 1;
				}
				else {
					cnt++;
				}
			}
			
			strcpy(s, t);
		}
		
		printf("%s\n", s);
	}
	
	return (0);
}

Measured memory_bytes: 712
i = int(input()) - 1
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[i])


Measured memory_bytes: 2940
import heapq as h;I=lambda:list(map(int,input().split()));n,k=I();z=[i*2+1for i in range(n)];s=sorted([I()for _ in[0]*n],key=lambda x:-x[1]);q=[];v=T=A=0;l=[0]*-~n
for i,(a,b)in enumerate(s):
 if i<k:
  if l[a]:h.heappush(q,b)
  else:T+=z[v];v+=1
  l[a]=1;T+=b
 elif l[a]^1and q:l[a]=1;T+=b+z[v]-h.heappop(q);v+=1
 A=max(A,T)
print(A)

Measured memory_bytes: 38624
#include<stdio.h>
#include<string.h>
#include<math.h>

int value( char c )
{
	switch( c ){
		case 'I':
			return 1;
			break;
		case 'V':
			return 5;
			break;
		case 'X':
			return 10;
			break;
		case 'L':
			return 50;
			break;
		case 'C':
			return 100;
			break;
		case 'D':
			return 500;
			break;
		case 'M':
			return 1000;
			break;
	}
}

int main()
{
	char str[101];
	while( scanf( "%s", str ) != EOF ){
	
		int ans = 0;
		
		for( int i = 1; i <= strlen( str ); i++ ){
			if( value( str[i-1] ) >= value( str[i] ) ){
				ans += value( str[i-1] );
			}
			else{
				ans += value( str[i] ) - value( str[i-1] );
				i++;
			}
		}
		
		printf( "%d\n", ans );
	}

 	return 0;
}

Measured memory_bytes: 968
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  ll n;
  cin>>n;
  
  ll a=n,ans=n;
  for(int i=2;i*i<=a;i++){
    if(n%i==0){
      ans=ans/i*(i-1);
      while(n%i==0) n/=i;
    }
  }
  if(n!=1) ans=ans/n*(n-1);

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b;
	c=a+b;
	if((a%3==0)||(b%3==0)||(c%3==0)) cout<<"Possible";
	else cout<<"Impossible";
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ld long double
#define pas(v) cout << #v << ' ' << v << endl
using namespace std;
    
ll M = 1234567891;
  
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
  
ll powm(ll a, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 1) return (powm(a, n - 1) * a) % M;
    ll x = powm(a, n / 2);
    return (x * x) % M;
}
 
  
int main() {
    // freopen("common.in", "r", stdin);
    // freopen("common.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cout.precision(20);
      
    int n, k; cin >> n >> k;
    vector<int> a(n);
    int ans = (n - 1) / (k - 1);
    if ((n - 1) % (k - 1) > 0) ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let f a = a * a * a
let _ = Printf.printf "%d\n" @@ f (n / k) + if k mod 2 = 1 || n < k / 2 then 0 else f @@ (n - k / 2) / k + 1

Measured memory_bytes: 384
#include<bits/stdc++.h>
 
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
using namespace std;
 
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
LL w,h,x,y;
int main(){
	ios::sync_with_stdio(false);
	cin>>w>>h>>x>>y;
 
	if(x==0&&y==0){
		cout<<1.0*w*h/2<<' '<<0<<endl;
 
		return 0;
	}
	if(x==0&&y==h){
		cout<<1.0*w*h/2<<' '<<0<<endl;
 
		return 0;
	}
	if(x==w&&y==h){
		cout<<1.0*w*h/2<<' '<<0<<endl;
		return 0;
	}
	if(x==w&&y==0){
		cout<<1.0*w*h/2<<' '<<0<<endl;
		return 0;		
	}
	if(w%2==0&&h%2==0&&x==w/2&&y==h/2){
		cout<<w*h/2<<' '<<1<<endl;
	}else if(w%2==0&&x==w/2){
		cout<<w*h/2<<' '<<0<<endl;
	}else if(h%2==0&&y==h/2){
		cout<<w*h/2<<' '<<0<<endl;
	}else{
		double mx=1.0*w/2,my=1.0*h/2;
		double k=(my-y)/(mx-x);//Y-y=k*(X-x)
		double up=(h-y)/k+x;
		double down=(0-y)/k+x;
		double le=k*(-x)+y;
		double ri=k*(w-x)+y;
		double ans=1e19;
		if(y<my){
			if(x<mx){
				ans=min((down+up)*h/2,(2*w-down-up)*h/2);
			}else{
				ans=min((down+up)*h/2,(2*w-down-up)*h/2);
			}
		}else{
			ans=min((le+ri)*w/2,(2*h-le-ri)*w/2);
		}
		cout<<ans<<' '<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int N;
  cin>>N;
  vector<long>a(N);
  for(int i=0; i<N;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  long h=0;
  int H;
  long w=0;
  for(int i=0; i<N-1;i++){
    if(a.at(i)==a.at(i+1)){
      h=a.at(i);
      H=i+1;
      break;     
    }
  }
  for(int i=H+1; i<N-1;i++){
    if(a.at(i)==a.at(i+1)){
      w=a.at(i);
      break;
    }
  }
  
    cout<<h*w<<endl;
  
    
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
int main() {
	ll x,y;
	int ans=0;
	ios::sync_with_stdio(false);
	cin>>x>>y;
	while (x<=y) {
		x*=2;
		ans++;
	}
	cout<<ans;
	return 0;
}


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

int main(void) {
    int k = 0, n = 0;
    int* a = nullptr;

    scanf("%d %d",&k, &n);
    a = (int*) malloc(sizeof(int) * n);

    for(int i =0; i < n; ++i) scanf("%d", &a[i]);

    int max = a[0] + k - a[n -1];

    for(int i =0; i < n - 1; ++i) {
        int len = a[i + 1] - a[i];
        max = max > len ? max : len; 
    }

    printf("%d", k - max);

    return 0;
}



Measured memory_bytes: 896
num_list = list(map(int,input().split()))
answer = []
num_answer=0
for i in range(num_list[0]+1):
	k = 0
	for j in range(len(str(i))):
		k+=int(str(i)[j])
	if(k >= num_list[1] and k <= num_list[2]):
		answer.append(i)
#print(answer)
for m in range(len(answer)):
	num_answer+=answer[m]
print(num_answer)

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

using namespace std;

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

	int n;
	cin>>n;

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

	for(int i = 1; i < n; i++) {
		dp[i][0] = dp[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = dp[i][1] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = dp[i][2] + max(dp[i-1][0], dp[i-1][1]);
	}

	int ans = max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]);
	cout<<ans;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 10;
typedef long long ll;
ll n,k,dp[maxn][10],sum[maxn][10],tot,sum2[maxn][10];
char t[maxn];
int main() {
	for (int j = 0; j <= 9; j++)
		dp[1][j] = 1;
	for (int i = 2; i <= 18; i++) {
		for (int j = 0; j <= 9; j++) {
			dp[i][j] += dp[i - 1][j];
			if (j < 9) dp[i][j] += dp[i - 1][j + 1];
			if (j > 0) dp[i][j] += dp[i - 1][j - 1];
		}
	}
	for (int i = 1; i <= 18; i++) {
		sum[i][0] = sum[i - 1][9];
		sum[1][0] = 1;
		for (int j = 1; j <= 9; j++) {
			sum[i][j] = sum[i - 1][9];
			for (int k = 1; k <= j; k++)
				sum[i][j] += dp[i][k];
		}
		for (int j = 0; j <= 9; j++) {
			sum2[i][j] = sum2[i - 1][9];
			for (int k = 0; k <= j; k++)
				sum2[i][j] += dp[i][k];
		}
	}
	//printf("%lld\n",sum[2][1]);
	scanf("%lld",&k);
	int p = 0;
	for (int i = 18; i >= 0; i--) {
		if (sum[i][9] < k) {
			p = i + 1;
			k -= sum[i][9]; 
			break;
		}
	}
	bool limit = true;
	for (int i = p; i >= 1; i--) {
		if (limit) {
			for (int j = 1; j <= 9; j++) {
				if (dp[i][j]  < k) {
					k -= dp[i][j];
				} else {
					limit = false;
					t[++tot] = j + '0';
					break;
				}
			}
		} else {
			for (int j = max(0,t[tot] - '0' - 1); j <= t[tot] - '0' + 1; j++) {
				int tmp = t[tot] - '0' - 2;
				if (dp[i][j]  < k) {
					k -= dp[i][j];
				} else {
					t[++tot] = j + '0';
					break;
				}
			}			
		}
	}
	t[++tot] = 0;
	printf("%s\n",t + 1);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            int num = scn.nextInt();
            long sum = 0;
            for(int i = 0; i < num; i++) {
                sum += scn.nextLong();
            }
            System.out.println(sum / num);
        }
    }
}

Measured memory_bytes: 41820
#include <bits/stdc++.h>
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; i++)
#define fornd(i, n) for (int i = n - 1; i >= 0; i--)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define for1d(i, n) for (int i = n; i >= 1; i--)
#define fi first
#define se second
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tuple<int, int, int> iii;

const int maxn = 10;

int main() {
	int n, m, cnt[40] = {0};
	cin >> n >> m;
	forn(i, n) {
		int tmp;
		cin >> tmp;
		while (tmp--) { int ai; cin >> ai; cnt[ai]++; }
	}
	int ans = 0;
	for1(i, m) if (cnt[i] == n) ans++;
	cout << ans;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  init();
  string s, t;
  cin >> s >> t;
  ll s_size = s.size();

  ll ans = 0;
  string::size_type before_f = 0;
  rep(i, t.size()) {
    // debug(i);
    // debug(t[i]);
    string sub = s.substr(before_f, s.size() - before_f);
    // debug(sub);
    string::size_type f = sub.find(t[i]);
    // debug(f);
    if (f == string::npos) {
      if ((ll)sub.size() == s_size) {
        COUT(-1);
        return 0;
      }
      before_f = 0;
      if (ans % s_size != 0) ans += s_size - ans % s_size;
      debug(ans % s_size);
      // もう一回検索
      string::size_type ff = s.find(t[i]);
      if (ff == string::npos) {
        COUT(-1);
        return 0;
      }
      // debug(ans);
      // debug(before_f);
      // debug(ff);
      ans += before_f + ff + 1;
      before_f = ff + 1;

      // debug("not found");
      // debug(ans);
      // ENDL;
      continue;
    }
    // debug(before_f);
    ans += f + 1;
    debug(ans);
    before_f = before_f + f + 1;
    ENDL;
  }
  // ans++;
  COUT(ans);

  return 0;
}

Measured memory_bytes: 3788
s=input()
n=len(s)

def check():
    if s[0]=="0" or s[-1] =="1":
        return False
    for i in range(n):
        if s[i] != s[n-i-2]:
            return False
    return True

if not check():
    print(-1)
    exit()

now=1
for i in range(n-1):
    print(now,i+2)
    if s[i]=="1":
        now=i+2

Measured memory_bytes: 75324
import itertools

N,M=map(int,input().split())
S=list(map(int,input().split()))
miti=[input().split() for i in range(M)]
miti2= [ flatten for inner in miti for flatten in inner ]
miti2 = [int(i) for i in miti2]
miti3=N-len(set(miti2))

count2=[int(i) for i in range(1,N+1)]

for j in range(0,2*M,2):
  if S[miti2[j]-1]>S[miti2[j+1]-1]:
    count2[miti2[j+1]-1]=0
  elif S[miti2[j]-1]<S[miti2[j+1]-1]:
    count2[miti2[j]-1]=0
  else:
    count2[miti2[j+1]-1]=0
    count2[miti2[j]-1]=0
print(len(set(count2))-1)





Measured memory_bytes: 60832
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 





int main()
{
     int n;cin>>n;
     string s;
     cin>>s;
     ll res=0;
     for(int i=0;i<1000;i++){
          int c[3]={i/100,(i/10)%10,i%10};
          int f=0;
          for(int j=0;j<s.length();j++){
               if(s[j]==('0'+c[f]))f++;
               if(f==3)break;
          }
          if(f==3){res++;}
     }
     cout<<res;
     
}




































Measured memory_bytes: 3684
#include<bits/stdc++.h>
using   namespace      std;
typedef long long      LL;
typedef vector<int>    VI;
typedef pair<int,int>  PII;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n, k;
	cin >> n >> k ;
	int ar[n + 5] , dp[n + 5];

	for(int i=1 ; i<= n; i++){
		cin >> ar[i] ;
		dp[i] = 0 ;
	}

	for(int i = 2 ; i <= n ; i++){
		int minm = INT_MAX ;
		for(int j = 1 ; j <= k ; j++){
			if(i - j < 1)	break ;
			minm = min(minm , abs(ar[i] - ar[i-j]) + dp[i-j]) ;
		}
		dp[i] = minm ;
	}

	cout << dp[n] << endl ;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int n;
    ll c, x[112345], v[112345];

    cin >> n >> c;
    REP(i, n)
    cin >> x[i + 1] >> v[i + 1];

    x[0] = 0;
    x[n + 1] = c;
    v[0] = 0;
    v[n + 1] = 0;

    ll sumR[112345], mxR[112345], sumL[112345], mxL[112345];

    ll res = 0;

    sumR[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        sumR[i] = sumR[i - 1] + v[i];
    }

    mxR[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        sumR[i] -= x[i];
        mxR[i] = max(mxR[i - 1], sumR[i]);
    }

    sumL[n + 1] = 0;
    for (int i = n; i > 0; i--)
    {
        sumL[i] = sumL[i + 1] + v[i];
    }

    mxL[n + 1] = 0;
    for (int i = n; i > 0; i--)
    {
        sumL[i] -= c - x[i];
        mxL[i] = max(mxL[i + 1], sumL[i]);
    }

    for (int i = 0; i <= n; i++)
        res = max(res, sumR[i] + mxL[i + 1] - x[i]);

    for (int i = n + 1; i > 0; i--)
        res = max(res, sumL[i] + mxR[i - 1] - (c - x[i]));

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a);  a = (a * a);  b/=2;  }  return res; }
#define rs resize
long long readLI(){  register char c;  for(c = getchar(); !(c>='0' && c<='9'); c = getchar());  register long long a=c-'0';
    for(c = getchar(); c>='0' && c<='9'; c = getchar())
        a = (a<<3)+(a<<1)+c-'0';
    return a;
}
const ll N = 59;
ll a = 2,b = 1,i,n,t;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,0,n - 1){
        t = a + b;
        a = b;
        b = t;
    }
    cout<<b;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#ifdef ONLINE_JUDGE
#define getchar gc
inline char gc(){
	static char buf[1<<16],*p1=buf,*p2=buf;
	if(p1==p2){
		p2=(p1=buf)+fread(buf,1,1<<16,stdin);
		if(p2==p1) return EOF;
	}
	return *p1++;
}
#endif
template<class t> inline t read(t &x){
    char c=getchar();bool f=0;x=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return x;
}
template<class t> inline void write(t x){
    if(x<0) putchar('-'),write(-x);
    else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const double eps=1e-9;
const double pi=acos(-1);


struct point{
	double x,y;
	inline void read(){
		scanf("%lf%lf",&x,&y);
	}
	inline point operator + (const point &nt) const {
		return (point){x+nt.x,y+nt.y};
	}
	inline point operator - (const point &nt) const {
		return (point){x-nt.x,y-nt.y};
	}
	inline point operator * (const double &nt) const {
		return (point){x*nt,y*nt};
	}
	inline double length(){
		return sqrt(x*x+y*y);
	}
}x,y,o;

double DJ(point x,point y){ //点积 
	return x.x*y.x+x.y*y.y;
}

double CJ(point x,point y){ //叉积 
	return x.x*y.y-x.y*y.x;
}

double distance(point x,point y){ //距离 
	return sqrt((y.x-x.x)*(y.x-x.x)+(y.y-x.y)*(y.y-x.y));
}

struct segment{
	point x,y;
	inline void read(){
		x.read();y.read();
	}
	inline double length(){ //线段长度 
		return distance(x,y);
	}
};

point trpoint(segment x){ //将有向线段转成向量点 
	return x.y-x.x;
}

double prolen(point x,segment a){ //点在有向线段上的投影长度 
	return DJ(trpoint((segment){a.x,x}),trpoint(a))/a.length();
}

point propoint(point x,segment a){ //点在直线上的投影点 
	return a.x+trpoint(a)*(prolen(x,a)/a.length());
}

point refpoint(point x,segment a){ //点在直线上的投影点 
	point y=propoint(x,a);
	return x+(y-x)*2;
}

void doit(){
	y.read();y=y-o;
	if(CJ(x,y)>0) puts("COUNTER_CLOCKWISE");
	else if(CJ(y,x)>0) puts("CLOCKWISE");
	else if(DJ(x,y)<0) puts("ONLINE_BACK");
	else if(y.length()>x.length()) puts("ONLINE_FRONT");
	else puts("ON_SEGMENT");
}

signed main(){
	o.read();x.read();x=x-o;
	int t;
	read(t);
	while(t--) doit();
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

// アルメリアさんのを参考に
// https://atcoder.jp/contests/abc141/submissions/8551806

// vの most significant bit のみが立った数を返す
// やってることは，v の msb 以下の bit が全て立った数 w を作って，w^(w>>1)を返す
ll msb(ll v){
  v = v | (v >>  1);
  v = v | (v >>  2);
  v = v | (v >>  4);
  v = v | (v >>  8);
  v = v | (v >> 16);
  v = v | (v >> 32);
  return v ^ (v >> 1);
}

vector<ll> elimination_F2(vector<ll> &A){
    vector<ll> V;
    for(ll a: A){
        for(ll v: V){
            if(msb(v)&a) a ^= v;
        }
        if(a>0){
            for(ll& v: V){
                if(msb(a)&v) v ^= a;
            }
            V.push_back(a);
            sort(V.rbegin(), V.rend());
        }
    }
    return V;
} 

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll res = 0;
    REP(b, 60){
        ll cnt = 0;
        ll val = (1ll<<b);
        REP(i, N){
            if(A[i]>>b & 1) cnt++;
        }
        if(cnt&1){
            res += val;
            REP(i, N){
                if(A[i]>>b & 1) A[i] ^= val;
            }
        }
    }

    auto V = elimination_F2(A);
    ll tmp = 0;
    for(auto v: V){
        tmp ^= v;
    }
    cout << res+2*tmp << endl;

    return 0;
}

Measured memory_bytes: 3972
#include <stdio.h>

#define MAX	100

int main(void)
{
	int n, k, x;
	int i, sum;
	
	scanf("%d", &n);
	scanf("%d", &k);
	
	if(k == 1)
		sum = 0;
	else{
		for(sum=0,i=0; i<n; i++){
			scanf("%d", &x);
			
			if(x < k-x)
				sum += 2*x;
			else
				sum += 2*(k-x);
		}
	}
	
	printf("%d", sum);	// Ans
	
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

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

  if (R < 1200) {
    printf("ABC\n");
  } else if (R < 2800) {
    printf("ARC\n");
  } else {
    printf("AGC\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>

using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

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

vector<vector<ll>> grid;

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

	ll N, M;
	cin >> N >> M;

	vector<ll> a (N + 3);

	rep (i, M) {
		ll hoge;
		cin >> hoge;

		a[hoge] = -1;
	}

	rep (i, 2) {
		if (a[i] == -1) {
			continue;
		}
		a[i] = 1;
	}

	for (ll i = 2; i <= N; ++i) {
		if (a[i] == -1) {
			continue;
		}

		int sum = 0;

		if (a[i - 1] != -1) {
			sum += a[i - 1];
		}
		// sum += a[i - 1] == -1 ? 0 : a[i - 1];

		if (a[i - 2] != -1) {
			sum += a[i - 2];
		}

		a[i] = sum % static_cast<ll>(1e9 + 7);
	}   //1e9+7

	cout << a[N] << "\n";
}

Measured memory_bytes: 1024
a,b,c,d = 0,0,0,0
while 1:
	lng=list(map(int,input().split()))
	lng.sort()
	if lng[0] + lng[1] <= lng[2]:
		print('%d %d %d %d' % (a,b,c,d))
		break
	else:
		a += 1
		if lng[0]**2 + lng[1]**2 == lng[2]**2:
			b += 1
		elif lng[0]**2 + lng[1]**2 <= lng[2]**2:
			d += 1
		else:
			c += 1


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a == 1){
		a += 13;
	}
	if(b == 1){
		b += 13;
	}
	if(a > b){
		printf("Alice");
	}
	else if(a < b){
		printf("Bob");
	}
	else{
		printf("Draw");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  vector<int> b(N);
  vector<bool> comp(N);
  int dupall = 0;
  for (int j = 0; j < N - dupall; j++) {
    //まだbに入っていない数字で一番大きい数字を調べる
    for (int k = 0; k < N; k++) { 
      if (comp.at(k) == true) {
        continue;
      }
      if (b.at(j + dupall) < a.at(k)) {
        b.at(j + dupall) = a.at(k);
      }
    }
    //一番大きい数字が何個あるかを調べる
    int dup = 0;
    for (int l = 0; l < N; l++) {
      if (b.at(j + dupall) == a.at(l)) {
        dup++;
        comp.at(l) = true;
      }
    }
    //重複を反映
    for (int n = 0; n < dup; n++) {
      b.at(j + dupall + n) = b.at(j + dupall);
    }
    dupall += (dup - 1); 
  }      
  int score = 0;
  for (int m = 0; m < N; m++) {
    if (m % 2 == 0) {
      score += b.at(m);
    }
    if (m % 2 == 1) {
      score -= b.at(m);
    }
  }
  cout << score << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll s,w;
    cin >> s >> w;
    if(w>=s)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int a, b;
    cin >> a >> b;
    cout << max({2 * a - 1, a + b, 2 * b - 1}) << "\n";
    return 0;
}

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

int main() {
	string s;
	ll k;
	cin >> s >> k;
	/*5000*10000*10000*10000
	 * 2^10 = 10^3
	 * 2^5000*10000*10000*10000 = 10^3*5000*10000*10000*1000			
	 */
	char t;
	int iter_stop_1 = s.size()+1;
	for(int i=0; i<s.size(); i++) {
		if(s[i] != '1'){
			t = s[i];
			iter_stop_1 = i+1;
			break;
		}
		if(i == s.size()-1)
			t = '1';
	}
	if(iter_stop_1 > k) {
		cout << '1' << endl;
	}
	else 
		cout << t << endl;
	return 0;
}
	


Measured memory_bytes: 384
#include <stdio.h>
int main (void){
	int a,b;
	scanf("%d %d",&a, &b);
	if(a+b>a-b && a+b>a*b)printf("%d\n",a+b);
	else if(a-b>a+b && a-b>a*b)printf("%d\n",a-b);
	else if(a*b>a+b && a*b>a-b)printf("%d\n",a*b);
	else if(a-b>a+b && a-b>a*b)printf("%d\n", a-b);
	else if(a+b==a-b && a+b>a*b)printf("%d\n",a+b);
	else if(a+b==a*b && a+b>a-b)printf("%d\n",a+b);
	else if(a-b==a+b && a-b>a*b)printf("%d\n",a-b);
	else if(a-b==a*b && a-b>a+b)printf("%d\n",a-b);
	else if(a*b==a-b && a*b>a+b)printf("%d\n",a*b);
	else if(a*b==a+b && a*b>a-b)printf("%d\n",a*b);
	else if (a==0){
		if(b==0){printf("%d\n",a);}
		else printf("%d\n",b);}
	else if (b==0){
		if(a==0){printf("%d\n",b);}
		else printf("%d\n",a);}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int x;
  cin>>x;
  set<Int> s;
  s.emplace(1);
  for(Int i=2;i<=1000;i++){
    Int t=i*i;
    while(t<=1000){
      s.emplace(t);
      t*=i;
    }
  }
  cout<<*--s.upper_bound(x)<<endl;
  return 0;
}


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(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    string k;
    rep(i,q){
        int t;
        cin >> t;
        if(t==1) swap(s,k); //reverse
        if(t==2){
            int f; char c;
            cin >> f >> c;
            if(f==1){
                k+=c;
            }
            if(f==2){
                s+=c;
            }
        }
    }
    reverse(k.begin(),k.end());
    k+=s;
    cout << k << endl;
    return 0;
}

Measured memory_bytes: 1128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>

int main()
{
    long M1,M2,D1,D2;
    std::cin >> M1 >> D1;
    std::cin >> M2 >> D2;
    if(M2-M1==1){
        std::cout << 1 << std::endl;
    }else{
        std::cout << 0 << std::endl;
    }
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
map<int, int> ma;

int main() {
    scanf("%d", &n);
    forn(i, n) {
        int x;
        scanf("%d", &x);
        ma[x] ^= 1;
    }
    int ans = 0;
    for (PII p : ma) {
        ans += p.second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4864
// Vicfred
// https://atcoder.jp/contests/dp/tasks/dp_a
// dynamic programming
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    const long n = readln.chomp.to!long;
    const long[] h = 0~readln.split.map!(to!long).array;

    long[] dp = new long[n+1];
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for(int i = 3; i <= n; ++i)
        dp[i] = min(dp[i-1] + abs(h[i] - h[i - 1]),
                    dp[i-2] + abs(h[i] - h[i - 2]));
    dp[n].writeln;
}



Measured memory_bytes: 6412
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define v vector
#define ALL(x) x.begin(),x.end()
#define rALL(x) x.rbegin(),x.rend()
#define endl '\n'
#define DEBUG

template<typename T> void DBG(const char* name, T&& H) {
	cerr << name << " = " << H << ')' << endl;
}

template<typename T, typename... Args> void DBG(const char* names, T&& H, Args&&... args) {
	const char* NEXT = strchr(names+1, ',');
	cerr.write(names, NEXT-names) << " = " << H << " |";
	DBG(NEXT+1, args...);
}

#ifdef DEBUG
	#define dbg(...) cerr << __FUNCTION__ << ' ' <<__LINE__ << " : (", DBG(#__VA_ARGS__, __VA_ARGS__)
#else
	#define dbg(...)
#endif

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

const ll mod = 1e9 + 7;
const ld PI = acos(-1.0);

struct DSU {
	using T = int;
	vector<T> parent;
	vector<T> size;
	T numComponents = 0;
	DSU(T n = 0) {
		if(n >= 0)
			init(n);
	}
	void init(T n = 0) {
		parent.resize(n);
		size.assign(n, 1);
		numComponents = n;
		for (T i = 0; i < n; i++)
			parent[i] = i;
	}
	T getParent(T x) {
		return (x == parent[x]) ? x : parent[x] = getParent(parent[x]);
	}
	bool merge(T x, T y) {
		x = getParent(x);
		y = getParent(y);
		if (x == y) {
			return false;
		} 
		if (size[x] < size[y]) {
			swap(x, y);
		}
		parent[y] = x;
		size[x] += size[y];
		numComponents--;
		return true;
	}
};

void Solve() {
	int n, k, l;
	cin >> n >> k >> l;
	DSU road(n), railway(n);
	for(int i = 0; i < k; i ++) {
		int a, b;
		cin >> a >> b;
		a -= 1; 
		b -= 1;
		road.merge(a, b);
	}
	for(int i = 0; i < l; i ++) {
		int a, b;
		cin >> a >> b;
		a -= 1; 
		b -= 1;
		railway.merge(a, b);
	}
	map<pair<int, int>, int> count;
	for(int i = 0; i < n; i ++) {
		count[{road.getParent(i), railway.getParent(i)}] ++;
	}
	for(int i = 0; i < n; i ++) {
		cout << count[{road.getParent(i), railway.getParent(i)}] << " ";
	}
	cout << endl;
}

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

	int tt = 1;
	while(tt --) {
		Solve();
	}
	
	return 0;
}

Measured memory_bytes: 15104
#include <stdio.h>

int main(void)
{
	int a;
	int b;

	scanf("%d %d", &a, &b);

	if (a<b)
	{
		printf("a < b\n" );
	}
	
	else if (a>b)
	{
		printf("a > b\n");
	}

	else if (a==b)
	{
		printf("a == b\n");
	}

	return 0;
}

Measured memory_bytes: 580
from collections import*
from heapq import*
import sys
input=sys.stdin.readline
 
def BFS(point,d):
    cost=[1e18]*(n+1)
    cost[point]=0
    Q=deque()
    Q.appendleft((0,point))
    
    while Q:
        c,p=Q.pop()
        for np,co in d[p]:
            if cost[np]==1e18:
                cost[np]=c+co
                Q.appendleft((c+co,np))
    return cost

n=int(input())
d=[[]for i in range(n+1)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    d[a].append([b,c])
    d[b].append([a,c])
#print(d)
q,k=map(int,input().split())
y=BFS(k,d)
 
for i in range(q):
    a,b=map(int,input().split())
    print(y[a]+y[b])


Measured memory_bytes: 56308
/*input
32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5
*/
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define mod 998244353
#define int long long
#define N 200005

int H[N];
map<int, int> ok;
signed main() {
	int n,m,ans = 0;
	cin>>n; //>>m;
	//memset(ok,1,sizeof(ok));
	for(int i=1;i<=n;i++) {
		cin>> H[i];
		int reqd = i-H[i];
		
		ok[i+H[i]]++;
		if(reqd>=0) 
		ans += ok[reqd];
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 18944
#include<iostream>

using namespace std;

int main(){
  int n;
  string s, ans="Yes";
  cin >> n >> s;
  
  if(n%2==1) ans="No";
  for(int i=0;i<n/2;i++){
    if(s[i]!=s[i+n/2]){
      ans="No";
      break;
    }
  }
  cout << ans;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    int a[n];
    rep(i, n)   cin >> a[i];
    sort(a, a+n);
    
    int f = 0;
    rep(i, n){
        int temp = a[i] - 1;
        f += temp;
    }
    cout << f << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );

int n,a[105];
int m,p,x,sum=0;
int main()
{
    int i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }

    scanf("%d",&m);
    int temp;
    for(i=1;i<=m;i++)
    {
        temp=sum;
        scanf("%d%d",&p,&x);
        temp=temp-a[p]+x;
        printf("%d\n",temp);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

class input
{
public:
    input()
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var) { return std::cin >> var, *this; }
    template <class T>
    inline input& operator,(T& var) { return *this >> var; }

    template <class T>
    inline T read()
    {
        T var;
        std::cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            std::cin >> *head;
            ++head;
        }
    }

    template <class T>
    inline std::vector<T> read(std::size_t n)
    {
        std::vector<T> res;
        res.reserve(n);

        for (std::size_t i = 0; i < n; ++i) {
            T tmp;
            std::cin >> tmp;
            res.emplace_back(tmp);
        }
        return res;
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            std::cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

    template <class T, class... Args>
    void impl(T&& v, Args&&... args)
    {
        cout << std::forward<T>(v) << ' ';
        impl(std::forward<Args>(args)...);
    }
    template <class T>
    void impl(T&& v)
    {
        cout << std::forward<T>(v);
    }

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class... Args>
    void operator()(Args&&... args)
    {
        impl(std::forward<Args>(args)...);
        cout << '\n';
    }
    template <class... Args>
    void noreturn(Args&&... args)
    {
        impl(std::forward<Args>(args)...);
    }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
            }
            cout << x;
            first = false;
        }
        cout << '\n';
    }
};

void prog()
{
    input in;
    output out;
    out(std::array<int, 32>{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}.at(in.read<int>() - 1));
}

int main()
{
    prog();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans=0;
long long a[300010];

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(i%2==1)
			ans+=a[i];
		else
			ans-=a[i];
	}
	cout<<ans<<" ";
	long long now=2*a[1]-ans;
	for(int i=2;i<=n;i++)
	{
		cout<<now<<" ";
		now=2*a[i]-now;
	}
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int main(){
  long N[90];
  N[0] = 2;
  N[1] = 1;
  int K;
  cin >> K;
  for(int i = 2;i <= K; i++){
    N[i] = N[i-1]+N[i-2];
  }
  cout << N[K] << endl;
}


Measured memory_bytes: 256