akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	int n; cin >> n;
	list<int> li;
	string s;
	int x;
	rep(i, 0, n) {
		cin >> s;
		if(s == "insert") {
			cin >> x;
			li.push_front(x);
		} else if(s == "delete") {
			cin >> x;
			for(list<int>::iterator it = li.begin(); it != li.end(); ++it)
				if(*it == x) {
					li.erase(it);
					break;
				}
		} else if(s == "deleteFirst") {
			li.pop_front();
		} else if(s == "deleteLast") {
			li.pop_back();
		}
	}
	vi v(all(li));
	int len_v = len(v);
	rep(i, 0, len_v) cout << v[i] << (i + 1 == len_v ? "\n" : " ");
	return 0;
}

Measured memory_bytes: 34340
#include<iostream>
using namespace std;
int main(){
    int n,d[100]={0},tmp,ans;
    cin>>n;
    for(int i = 0; i < n; i++){cin>>tmp;d[tmp-1]++;}
    for(int i = 0; i < 100; i++)if(d[i])ans++;
    cout<<ans<<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;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int k;
    cin >> s >> k;
    set<string> se;
    rep(i,s.size()){
        string t = "";
        rep(j,5){
            if(i+j >= s.size()) continue;
            t += s[i+j];
            se.insert(t);
        }
    }
    int cnt = 0;
    for(auto p : se){
        if(++cnt == k){
            cout << p << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1664
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    h = tuple(map(int, input().split()))

    dp = [0] * N
    dp[1] = abs(h[1] - h[0])
    for i in range(2, N):
        h2 = h[i] - h[i - 2]
        if h2 < 0:
            a = dp[i - 2] - h2
        else:
            a = dp[i - 2] + h2
        h1 = h[i] - h[i - 1]
        if h1 < 0:
            b = dp[i - 1] - h1
        else:
            b = dp[i - 1] + h1
        if a < b:
            dp[i] = a
        else:
            dp[i] = b

    ans = dp[-1]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 20536
n = int(input())
A = [int(input()) for i in range(n)]
B = []
for i, a in enumerate(A):
    B.append([i + 1, a])
    
idx = 1
for i in range(n):
    x = B[idx - 1][1]
    if x == 2:
        print(i + 1)
        break
    else:
        idx = x
else:
    print(-1)

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }


struct Sieve { // 篩
    int n;
    vector<int> f, primes;
    Sieve(int n=1):n(n), f(n+1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; ++i) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i*i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x;} // 素数判定
    vector<int> factorList(int x) { // 素因数列挙
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x) { // 素因数分解 int        
        vector<P> res;
        for(int p : primes) {
            int y = 0;
            while(x % p == 0) x /= p, y++;
            if(y != 0) res.emplace_back(p,y);
        }
        return res;
    }
    vector<pair<ll, int>> factorll(ll x) { // 素因数分解 long long 
        vector<pair<ll, int>> res;
        for(int p : primes) {
            int y = 0;
            while(x % p == 0) x /= p, y++;
            if(y != 0) res.emplace_back(p,y);
        }
        if(x != 1) res.emplace_back(x,1);
        return res;
    }
};


int main(){
    ll n;
    cin >> n;
    Sieve s(2000000);
    auto fl = s.factorll(n);
    int ans = 0;
    for(auto p : fl) {
        int c = p.se;
        int b = 1;
        while(b <= c) {
            c -= b;
            b++;
            ans++;
        }
    }
    cout << ans << endl;
}

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

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

using graph = vector< vector<ll> >;

void bfs(const graph& g, ll n) {  

  ll v = (ll)g.size();  
  vector<ll> path;  

  queue<ll> g_que;  
  vector<bool> is_reached(v, false);  

  is_reached[0] = true;  
  g_que.push(0);
  vector<ll> parent(n, -1);

  while(!g_que.empty()) {  

    ll pos = g_que.front();  
    g_que.pop();  

    path.emplace_back(pos);  

    for(auto next : g[pos]) {  
      if (!is_reached[next]) {  
        is_reached[next] = true;  
        g_que.push(next);
        parent[next] = pos;
      }  
    }  
  }  

  for(ll i = 1; i < n; ++i) {
    if (parent[i] == -1) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;

  for(ll i = 1; i < n; ++i) cout << parent[i] + 1 << endl;

  return;  
}  

void solve(void) {
  ll n, m; cin >> n >> m;
  graph g(n);

  rep(m, i) {
    ll a, b; cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }

  bfs(g, n);
}

int main(void) {
  solve();
  return 0;
}


Measured memory_bytes: 14412
#include <iostream>
#include<cstring>
#include<stdio.h>
using namespace std;
#define  M  1046527
#define  L  14
char order[M][L];//存放
int get_data(char x)//将对应的字母转换为对应的数字
{
	if (x == 'A')
		return 1;
	else if (x == 'C')
		return 2;
	else if (x == 'G')
		return 3;
	else if (x == 'T')
		return 4;
	return 0;

}
int sum_data(char *p)//数字求和
{
	int sum = 0;
	int x = 3;
	int j = (int)strlen(p);
	for(int i=0;i<j;i++)
	{
		sum += x*get_data(*p);
		x *= 3;
		p++;
	}
	return sum;
}
int h_1(int  key)//散列函数，将key变为下标
{
	return (key % M);

}
int h_2(int key)//双散列,开放地址法(不懂)
{
	return (1 + key % (M - 1));

}
int insert(char *p)//插入到数组中
{
	int key = 0;
	int h = 0;
	for (int i = 0;; i++)
	{
		key = sum_data(p);//得出关键值；
		h = (h_1(key) + i * (h_2(key))) % M;//散列函数得出对应的下标
		if (strcmp(order[h], p) == 0)//位置已经有了一模一样的数据
			return 0;
		else if (strlen(order[h]) == 0)//这个位置是空的
		{
			strcpy(order[h], p);
			return 1;

		}
		//若关键值一样，但非一样的数据，继续循环或位置已经被占继续循环
	}
}
int find(char *p)//查找
{
		int key = 0;
		int h = 0;
		for(int i=0;;i++)
		{
			key = sum_data(p);
			h = (h_1(key) + i * (h_2(key))) % M;
			if (strcmp(order[h], p) == 0)//找到
				return 1;
			else if (strlen(order[h]) == 0)//关键字对应的下标没有数据
				return 0;
		}
		return 0;
}
int main()
{
	char order_1[10], data_1[10];
	int total = 0;
	for (int i = 0; i < M; i++)
		order[i][0] = '\0';
	scanf("%d", &total);
	for (int i = 0; i < total; i++)
	{
		scanf("%s%s", order_1, data_1);
		if (strcmp("insert", order_1) == 0)//插入
		{
			insert(data_1);
		}
		else if (strcmp("find", order_1) == 0)//查找
		{
			if (find(data_1))
				printf("yes\n");
			else 
				printf("no\n");
			
			
			
		}

	}
	return 0;
}


Measured memory_bytes: 17440
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int num1=sc.nextInt();
        int num2=sc.nextInt();
        int num3=sc.nextInt();
        long mat1[][]=new long[num1][num2];
        long mat2[][]=new long[num2][num3];
        long Grand_mat[][]=new long[num1][num3];
        for(int i=0;i<num1;i++){
            for(int j=0;j<num2;j++){
                mat1[i][j]=sc.nextInt();
            }
        }
        for(int i=0;i<num2;i++){
            for(int j=0;j<num3;j++){
                mat2[i][j]=sc.nextInt();
            }
        }
        for(int i=0;i<num1;i++){
            for(int j=0;j<num3;j++){
                for(int k=0;k<num2;k++){
                    Grand_mat[i][j]+=mat1[i][k]*mat2[k][j];
                }
            }
        }
        for (int i=0;i<num1;i++) { 
            for (int j=0;j<num3;j++) {
                System.out.print(Grand_mat[i][j]); 
                if(j<num3-1)
                 System.out.print(" ");
            }
            System.out.println();
        } 
    }
}


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

int main(){
    int N; cin >> N;
    int A[N];
    int B[100010] = {};
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(A[i] != 0) B[A[i]-1]++;
        B[A[i]]++;
        B[A[i]+1]++;
    }
    int maxV = 0;
    for(int i = 0; i < 100010; i++){
        maxV = max(maxV, B[i]);
    }
    cout << maxV << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n,m;
	cin>>n>>m;
	ll x,y;
	set <int> v1;
	set <int > v2;
	while (m--)
	{
	cin>>x>>y;
	if (x==1)
	  v1.insert(y);
	  if (y==n)
	  v2.insert(x);
	}
	set<int>:: iterator it;
	for (it=v1.begin();it!=v1.end();it++)
	{
		if (v2.find(*it)!=v2.end())
		{
			cout<<"POSSIBLE";
			exit(0);
		}
	}
	cout<<"IMPOSSIBLE";
	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<int> primep(56000, 1);
  primep[0] = primep[1] = 0;
  int upper = 55555;
  for (int i = 2; i * i <= upper; ++i) {
    if (not primep[i]) { continue; }
    for (int j = i * i; j <= upper; j += i) {
      primep[j] = 0;
    }
  }
  vector<int> ans(N);
  int ix = 0;
  for (int i = 2; i <= upper; ++i) {
    if (not primep[i]) { continue; }
    if (i % 5 == 2) {
      ans[ix] = i;
      if (++ix == N) { break; }
    }
  }
  printf("%d", ans[0]);
  for (int i = 1; i < N; ++i) {
    printf(" %d", ans[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 512
N = int(input())

ans = 0
for x in range(1, N + 1, 2):
    d = 0
    for y in range(1, int(x ** 0.5 + 0.5) + 1):
        if x % y == 0:
            d += 1
            if y * y != x:
                d += 1
    if d == 8:
        ans += 1

print(ans)


Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val s = (1..n).map {
    sc.next()
  }

  println(abc164c(n, s))
}

private fun abc164c(n: Int, s: List<String>): Int {
  return s.distinct().count()
}


Measured memory_bytes: 76436
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		long b = long.Parse(input[0]);
		long c = long.Parse(input[1]);
		//出力
		Console.WriteLine(bishop(b,c));
	}
  
  	static long bishop(long x,long y){
     if(x == 1 || y == 1) return 1;
     if(x%2 == 0 || y%2 == 0) return x*y/2;
     return (x*y+1)/2;
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
typedef pair<int,int> pii;
typedef pair <long long,long long> pll;
typedef long long ll; 
typedef long double ld; 
const ll mod = 1e9+7;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); 
    int n,w; cin >> n >> w;
    int maxVal = n*1000;
    vector < vector <ll> > item(n+1, vector <ll> (2,0)), dp(n+1,vector <ll> (maxVal+1,mod));
    for(int i = 1; i<=n; i++)
		cin>>item[i][0]>>item[i][1];
	dp[1][0] = 0;	
	dp[1][item[1][1]] = item[1][0];
	for(int i = 2; i <= n ; i++)
	{	for(int j = 0; j <= maxVal; j++ )
		{	dp[i][j] = dp[i-1][j];
			if(item[i][1] <= j)
				dp[i][j] = min(dp[i][j], dp[i-1][j-item[i][1]] + item[i][0]);
		}
	}
	int ans = INT_MIN;
	for(int x = 0; x <= maxVal ; x++)
	{	if(dp[n][x] <= w)
			ans = max(ans, x);
	}	
	cout<<ans ;
    return 0;
}

 


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

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

ll N;
ll A[500];

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    ll c = 0;
    for(int i=0;i<N;i++){
        if(i%2==0 && A[i]%2==1) c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(){
  int a,b;
  scanf("%d%d",&a, &b);
  if(((a-b)<=1 && (a-b)>=-1) || ((b-a)<=1 && (b-a)>=-1))
    printf("Yay!\n");
  else
    printf(":(\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int bc[100005];
struct S {
	long long x;//长度
	long long y;//个数
}s[100005];
long long max(long long a, long long b) {
	return a > b ? a : b;
}
int main()
{
	int n;int num = 0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> bc[i];
	}
	sort(bc, bc + n);
	for (int i = n - 1,j=0;i >= 0;i--) {
		int ans = 1;
		while (bc[i] == bc[i - 1]) {
			ans++;i--;
		}
		num++;
		s[j].x = bc[i];s[j].y = ans;j++;
	}
	int p[2];
	int an = 0;
	int ans = 0;
	long long sss = 0;
	for (int i = 0;i < num;i++) {
		if (an == 2)
			break;
		else if (s[i].y >= 4) {
			long long t = s[i].x*s[i].x;
			sss = max(t, sss);
			p[an] = i;
			an++;continue;
		}
		else if (s[i].y >= 2) {
			p[an] = i;an++;
		}
	}
	if (an == 2) {
		long long t = s[p[0]].x*s[p[1]].x;
		cout << max(sss, t) << endl;
	}
	else
		cout << sss << endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using int64 = int64_t;
#define int int64

// dp[i][j] := ibit目まで見てそこまでの値がk未満で(0:ない, 1:ある)時の最大値
int dp[60][2];

signed main(){
  int n,k;
  cin >> n >> k;
  vector< int > a(n);
  for(int i=0; i<n; ++i) cin >> a[i];
  memset(dp, -1, sizeof(dp));

  dp[45][0] = 0;
  for(int bi=44; bi>=0; --bi){
    int on_bit_num = 0;
    for(int ai=0; ai<n; ++ai){
      if((a[ai] >> bi) & 1) ++on_bit_num;
    }

    int digit = (1LL << bi);
    if(dp[bi+1][1] >= 0){
      dp[bi][1] = max(dp[bi][1], dp[bi+1][1] + digit * max(on_bit_num, n-on_bit_num));
    }     
    if(dp[bi+1][0] >= 0){
      if ((k >> bi) & 1){
        dp[bi][1] = max(dp[bi][1], dp[bi+1][0] + digit * on_bit_num);
        dp[bi][0] = max(dp[bi][0], dp[bi+1][0] + digit * (n-on_bit_num));
      } else {
        dp[bi][0] = max(dp[bi][0], dp[bi+1][0] + digit * on_bit_num);
      }     
    }
  }

  int ans = max(dp[0][0], dp[0][1]);
  cout << ans << endl;
  return 0;
}


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

int main(){
    string S1,S2,S3;
    cin >> S1;
    cin >> S2;
    cin >> S3;
    cout << S1[0];
    cout << S2[1];
    cout << S3[2];
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	n %= 10 ;
	if(n==2||n==4||n==5||n==7||n==9) cout << "hon\n" ;
	if(n==0||n==1||n==6||n==8) cout << "pon\n" ;
	if(n==3) cout << "bon\n" ;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

int32_t main()
{
	IO_OP;
	
	ll a, b, g, ans = 1;
	cin >> a >> b;
	g = __gcd(a, b);
	for(ll i=2;i*i<=g;i++) {
		if(g%i) continue;
		ans++;
		while(g%i == 0) g /= i;
	}
	if(g != 1) ans++;
	cout << ans << endl;	
	
}





Measured memory_bytes: 256
def main():
    S = input()

    dp = [0] * 13
    dp[0] = 1
    MOD = 10**9 + 7

    mul = 1

    for i in range(len(S)-1,-1,-1):
        nextdp = [0] * 13
        for j in range(13):
            if S[i] != '?':
                k = int(S[i])
                nextdp[(j+k*mul)%13] += dp[j]
                nextdp[(j+k*mul)%13] %= MOD
            else:
                for k in range(10):
                    nextdp[(j+k*mul)%13] += dp[j]
                    nextdp[(j+k*mul)%13] %= MOD
        dp = nextdp
        mul *= 10
        mul %= 13


    print(dp[5])


if __name__ == '__main__':
    main()

Measured memory_bytes: 42860
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <unordered_set>
using namespace std;
inline long  toInt(string s) {long  v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define long long long
long  pw(long  x, long  y){long  ans = 1;for(long  i = 0; i < y; i++){ans = ans * x;}return ans;}
long  factorial(long  x){long  ans = 1; for(int i = 1 ;i < x+1; i++){ans = ans *i;}return ans;}
long  combination(long  x,long  y){return factorial(x)/factorial(y)/factorial(x-y);}
long  permutation(long  x, long  y){return factorial(x)/factorial(x-y);}
#define TimeCount1    auto chrono_start = std::chrono::system_clock::now();
#define TimeCount2   auto chrono_end = std::chrono::system_clock::now();std::cout << "Elapsed time(C++):" << std::chrono::duration_cast<std::chrono::milliseconds>(chrono_end - chrono_start).count() << "[ms]" << std::endl;

//#include "./printer.hpp"

int main(){
	string s;
	cin >> s;
	string ans;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == '0'){
			ans = ans + "0";
		}else if(s[i] == '1'){
			ans = ans+ "1";
		}else{
			if(ans.length() > 0){
				ans = ans.substr(0,ans.length()-1);
			}
		}
	}

	cout << ans << endl;
	return 0;


}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))

ans = 0

while True:
    for i in range(len(A)):
        # 2で割り切れない
        if A[i] % 2 != 0:
            print(ans)
            exit()  
        # 2で割れる
        else:
            A[i] = A[i] / 2
    ans += 1        

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

using namespace std;

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

	unsigned int n,m;
	cin >> n >> m;

	vector<unsigned long> h(n);
	vector<unsigned int> hflag(n, true);
	for(unsigned int i=0;i<n;i++) cin >> h[i];

	unsigned int a, b;
	for(unsigned int i=0;i<m;i++){
		cin >> a >> b;
		if(h[a-1] < h[b-1]){
			hflag[a-1] = false;
			// hflag[b-1] = true;
		}
		else if(h[a-1]==h[b-1]){
			hflag[a-1] = false;
			hflag[b-1] = false;
		}
		else{
			// hflag[a-1] = true;
			hflag[b-1] = false;
		}
	}

	unsigned int count = 0;
	for(unsigned int i=0;i<n;i++){
		if(hflag[i]==true) count++;
	}

	cout << count << "\n";
}

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

int main() {
    string S; cin >> S;
    if (S == "RRR") {
        cout << 3 << endl;
    } else if (S == "RRS" || S == "SRR") {
        cout << 2 << endl;
    } else if (S == "RSS" || S == "SRS" || S == "SSR" || S == "RSR"){
        cout << 1  << endl;
    } else {
        cout << 0 << endl;
    }
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int s;cin>>s;

    int a = s/100;
    int b = s%100;

    bool am,bm;

    if(a>=1 && a<=12){
        am = true;
    }
    else{
        am = false;
    }
    if(b>=1 && b<=12){
        bm = true;
    }
    else{
        bm = false;
    }

    if(am && bm){
        cout<<"AMBIGUOUS"<<endl;
    }
    else if(am){
        cout<<"MMYY"<<endl;
    }
    else if(bm){
        cout<<"YYMM"<<endl;
    }
    else{
        cout<<"NA"<<endl;
    }
    
	return;
}

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

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM = 1000000007;

int main()
{
    // 整数の入力
    ll max_diff = 0;
    ll N,K;
    cin >> K >> N;
    vector<ll> A(N);
    for(int i = 0;i < N;i++){

        cin >> A[i];
    }
    for(int i = 0;i < N;i++){
        max_diff = max(max_diff,(K + A[(i+ 1)% N] - A[i]) % K);
    }

    cout << K - max_diff << endl;
   return 0;
}

Measured memory_bytes: 1792
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define ll long long
#define int long long
#define pb push_back
using namespace std; 

const ll N = 1e6 + 100, OO = 1e10 + 10, M = 1e9 + 7, lg = 769;
typedef pair <int, int> pii;
int a[N], pw[N], n;
map <int, int> m;

bool god(int x) {
	if(x == 0)
		return true;
	bool u = false;
	set <int> s;
	for(int i = x; i <= n; i++) {
		int j = i - x;
		int t = a[j] * pw[x];
		t %= M;
		t = a[i] - t;
		t += M;
		t %= M;
		if(s.find(t) == s.end()) {
			m[t] = i;
			s.insert(t);
		}
		else {
			if(m[t] <= j) {
				u = true;
				break;
			}
		}
	}
	for(auto u : s)
		m[u] = 0;
	return u;
}

int32_t main() {
	cin >> n;
	pw[0] = 1;
	string s;
	cin >> s;
	for(int i = 1; i <= n; i++) {
		pw[i] = pw[i - 1] * lg;
		pw[i] %= M;
	}
	for(int i = 1; i <= n; i++) { 
		a[i] = a[i - 1] * lg + (s[i - 1] - 'a');
		a[i] %= M;
	}
	int l = 1, r = n + 1;
	while(l < r) {
		int mid = (l + r) / 2;
		if(god(mid)) 	
			l = mid + 1;
		else
			r = mid;	
	}
	cout << l - 1 << endl;
	return 0;
}

Measured memory_bytes: 6144
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        c = max((a-1)//x+1, (b-1)//y+1)
        a, b = x*c, y*c
    print(a+b)

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

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define ALL(v) v.begin(), v.end()

const int MAX = 1e5+10;
int N;
ll A[MAX], diff[MAX];

vi solve() {
    ll sum = 0, dsum = 0;
    diff[0] = 0;
    REP (i, N-1) diff[(i+1)*2%N] = diff[i*2%N] + 2*(A[(2*i+1)%N] - A[2*i%N]);
    REP (i, N) {
        sum += A[i];
        dsum += diff[i];
    }
    vi ans(N);
    ans[0] = (sum-dsum) / N;
    FOR (i, 1, N) ans[i] = diff[i] + ans[0];
    return ans;
}

int main() {
    cin >> N;
    REP (i, N) {
        cin >> A[i];
    }
    vi ans = solve();
    cout << ans[0];
    FOR (i, 1, N) cout << " " << ans[i];
    cout << endl;
}

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

int main() {
  ll n;
  cin >> n;
  vector<int> vc(n);
  rep(i, n) { cin >> vc.at(i); }

  ll ans = 0;
  for (int i = 1; i < n; i++) {
    if (vc[i - 1] > vc[i]) {
      ans += vc[i - 1] - vc[i];
      vc[i] = vc[i - 1];
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N, M; cin >> N >> M;
  int l, r;
  int MIN=1, MAX=100000;
  rep(i,M) {
    cin >> l >> r;
    MIN = max(MIN, l);
    MAX = min(MAX, r);
  }

  cout << max(MAX-MIN+1,0) << endl;





  // cout << fixed << setprecision(6);
  return 0;
}


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

# print("Yes")
# print("No")

# print("YES")
# print("NO")


X,Y,Z = map(int,input().split())
X,Y = Y,X
X,Z = Z,X

print(X,Y,Z)








Measured memory_bytes: 2940
#include<iostream>

int main() {
	int a, b,total,truss;
	while (std::cin >> a >> b) {
		total = a + b;
		for (truss = 0; total != 0; truss += 1) {
			total = int(total / 10);
		}
		std::cout << truss << std::endl;



	}
	return 0;
}


Measured memory_bytes: 3004
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(i,p,q) for(int i = p;i < q;++i)
#define ll long long

using namespace std;

//E
ll d[300000];
int main(void) {
	ll n, m;
	cin >> n >> m;
	vector<vector<ll>> edge = vector<vector<ll>>(3 * n);
	rep(i, 0, m) {
		ll u, v;
		cin >> u >> v;
		rep(j, 0, 3) {
			ll u0 = (u - 1)*3;
			ll v0 = (v - 1)*3;
			edge[u0 + j].push_back(v0 + (1+j) % 3);
		}	
	}
	ll s, t;
	cin >> s >> t;
	s = (s-1)*3;
	t = (t-1)*3;
	rep(i, 0, 300000) {
		d[i] = 1e8;
	}
	d[s] = 0;
	queue<ll> q = queue<ll>();
	q.push(s);
	ll ans = -1;
	while (q.size() > 0) {
		ll v = q.front();
		q.pop();

		for (auto& nv : edge[v]) {
			if (d[nv] > d[v] + 1) {
				d[nv] = d[v] + 1;
				if (nv == t) break;
				q.push(nv);
			}
		}
		if (d[t] != 1e8) {
			ans = d[t] / 3;
			break;
		}

	}
	
	cout << ans << endl;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int n, Q;
    cin >> n >> Q;
    vector<int> a(n), b(n),c(n+1);
    vector<vector<int>> e(n + 1); //v(n, vector<lint>);
    REP(i, n-1)
    {
        cin >> a[i] >> b[i];
        int a1 = a[i], b1 = b[i];
        //cin >> a >> b;
        e[a1].push_back(b1);
        e[b1].push_back(a1);
    }
    REP(i,Q){
        int  p,x;
        cin >> p >> x;
        c[p] += x;
    }
    int ans = 0;

    queue<int> q;
    q.push(1);
    vector<int> seen(n + 1);
    seen[1] = 1;
    while (!q.empty())
    {
        int next = q.front();
        q.pop();
        //count++;
        for (auto next_v : e[next])
        {
                if (seen[next_v] == 0)
                {
                    q.push(next_v);
                    c[next_v] += c[next];
                    seen[next_v] = 1;
                }
        }
    }

    FOR(i,1,n){
        cout << c[i] << " ";
    }
    cout << c[n] << "\n";

    return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
int x[6];
void run_case()
{
    int ans = 0;
    for (int i = 1; i <= 5; i++)
    {
        cin >> x[i];
        if (x[i] == 0)
        {
            ans = i;
        }
        //cout << ans << "\n";
    }
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int[][] A = new int[n][m];
		int[] c = new int[n];
			
		for(int i=0; i<n; i++){
			for(int j=0; j<m; j++){
					A[i][j] = sc.nextInt();
				}
			}
			for(int i=0; i<m; i++){
				int b = sc.nextInt();
				for(int j=0; j<n; j++){
					c[j] += A[j][i] * b;
				}
			}
			for(int i=0; i<n; i++){
				System.out.println(c[i]);
			}
	}
}


Measured memory_bytes: 40376
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
#define forn(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define FORR(i,a,b) for(int i = a; i >= b; i--)

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;


void solve(){
    int n, k;
    cin >> n >> k;
    string str;
    cin >> str;
    str[k-1] -= (int)'A' - (int)'a';
    cout << str << endl;
}

int main(){
    //int t; cin >> t;
    //while(t--) solve();

    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int a[100000+10];
pair<int,int> bc[100000+10];
bool comp(pair<int,int> a,pair<int,int> b)
{
    return a.second>b.second;
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)    cin>>a[i];
    for(int i=0;i<m;i++)    cin>>bc[i].first>>bc[i].second;
    sort(a,a+n);
    sort(bc,bc+m,comp);
    ll ctrl=0,sum=0,j=0;
    for(ll i=0;i<n;)
    {
        if(ctrl==bc[j].first)
        {
            j++;
            ctrl=0;
            continue;
        }
        if(a[i]<bc[j].second)
        {
            sum+=bc[j].second;
            ctrl++;
        }
        else    sum+=a[i];
        i++;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

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

  int A, B; cin >> A >> B;
  string  S; cin >> S;
  auto f=[&](string a){
    rep(i,0,a.size())if(!isdigit(a[i]))return false;
    return true;
  };

  cout<<(S[A]=='-'&&f(S.substr(0,A))&&f(S.substr(A+1,B))?"Yes":"No")<<endl;
    return 0;
}


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

const int P = 1e9 + 7;
const int N = 400;
int dp[N][N][150][4], cnt[N][N], C[N][N];
int a[N], b[N], posa[N], posb[N];
pair<int, int> nxt[N][N];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			if (j) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % P;
			else C[i][j] = 1;
		}
	}
	for (int i = 1; i <= n; i++) cin >> a[i], posa[a[i]] = i;
	for (int i = 1; i <= n; i++) cin >> b[i], posb[b[i]] = i;
	dp[0][0][0][0] = 1;
	for (int i = 1; i <= n; i++) cnt[0][i] = i, cnt[i][0] = i;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			nxt[i][j].first = nxt[i][j].second = -1;
			for (int k = i; k <= n; k++) {
				if (posb[a[k]] >= j) {
					nxt[i - 1][j - 1].first = k;
					break;
				}
			}
			for (int k = j; k <= n; k++) {
				if (posa[b[k]] >= i) {
					nxt[i - 1][j - 1].second = k;
					break;
				}
			}
			if (posb[a[i]] > j) {
				cnt[i][j] = cnt[i - 1][j] + 1;
			}
			else cnt[i][j] = cnt[i - 1][j];
		}
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n / 3; k++) {
				int ii = nxt[i][j].first, jj = nxt[i][j].second;
				if (ii == -1 || jj == -1) {
					assert(ii == -1 && jj == -1);
					continue;
				}
				
				if (a[ii] != b[jj]) {
					dp[ii][jj][k][0] = ((long long)dp[ii][jj][k][0] + dp[i][j][k][1] + dp[i][j][k][2] + dp[i][j][k][0]) % P;
					int mul = (cnt[i][j] - k) / 2 - k;
					if ((cnt[i][j] - k) / 2 >= k + 1) {
						dp[ii][j][k + 1][2] = (dp[ii][j][k + 1][2] + 1LL * mul * (dp[i][j][k][0] + dp[i][j][k][2])) % P;
					}
					if ((cnt[i][j] - k) / 2 >= k + 1) {
						dp[i][jj][k + 1][1] = (dp[i][jj][k + 1][1] + 1LL * mul * (dp[i][j][k][0] + dp[i][j][k][1])) % P;
					}
					if ((cnt[i][j] - k) / 2 >= k + 2) {
						dp[ii][jj][k + 2][0] = (dp[ii][jj][k + 2][0] + 1LL * mul * (mul - 1) % P * dp[i][j][k][0]) % P;
					}
				}
				else {
					int mul = (cnt[i][j] - k) / 2 - k;
					if ((cnt[i][j] - k) / 2 >= k + 1) dp[ii][jj][k + 1][0] = (dp[ii][jj][k + 1][0] + 1LL * mul * dp[i][j][k][0]) % P;
				}
			}
		}
	}
//	cout << dp[3][5][1] << '\n';
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (nxt[i][j].first == -1 && nxt[i][j].second == -1) {
//				if (dp[i][j][n / 3][0]) cout << i << ' ' << j << ' ' << dp[i][j][n / 3] << '\n';
				ans = (ans + dp[i][j][n / 3][0]) % P;
			}
		}
	}
	int mul = 1;
	int cnt = n;
	for (int i = 1; i <= n / 3; i++) {
		mul = 1LL * mul * (cnt - 1) % P * (cnt - 2) % P;
		cnt -= 3;
	}
	cout << 1LL * ans * mul % P << '\n';
	return 0;
}

Measured memory_bytes: 345576
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
String s =sc.next();
int n=s.length();
String res="";
for(int i =0;i<n;i++){
	res=res+"x";
}
System.out.println(res);
}
}

Measured memory_bytes: 23124
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A,B,ans;
    A = sc.nextInt();
    B = sc.nextInt();
    if(A>=13)
      ans = B;
    else if((A>=6)&&(A<=12))
      ans = (B/2);
    else
      ans = 0;
    System.out.println(ans);
  }
}
    


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <unordered_map>

int main() {
  std::string s;
  std::cin >> s;
  std::vector<unsigned long long> xo(s.size() + 1, 0);
  for (unsigned i = 1; i <= s.size(); ++i) {
    xo[i] = xo[i - 1] ^ (1ull << (unsigned) (s[i - 1] - 'a'));
  }
  std::unordered_map<unsigned long long, unsigned> map;
  for (auto i = s.size() + 1; i-- > 0;) {
    if (map.find(xo[i]) != map.end()) {
      map.find(xo[i])->second = (unsigned int) i;
    } else {
      map.emplace(xo[i], i);
    }
  }
  std::vector<unsigned long long> dp(s.size() + 1, 0);
  for (unsigned i = 1; i <= s.size(); ++i) {
    auto aa = map.find(xo[i]);
    if (aa == map.end()) {
      map.emplace(xo[i], i);
      aa = map.find(xo[i]);
    }
    auto a = aa->second;
    if (a >= i) {
      dp[i] = dp[i - 1] + 1;
    } else {
      dp[i] = std::min(dp[i - 1] + 1, dp[a] + 1);
    }
    for (auto c = 0u; c < (unsigned) ('z' - 'a' + 1); ++c) {
      auto bb = map.find(xo[i] ^ (1ull << c));
      if (bb == map.end()) { continue; }
      auto b = bb->second;
      if (b >= i) { continue; }
      dp[i] = std::min(dp[i], dp[b] + 1);
    }
    if (dp[map.find(xo[i])->second] > dp[i]) {
      map.find(xo[i])->second = i;
    }
  }
  std::cout << dp.back() << std::endl;
  return 0;
}

Measured memory_bytes: 14584
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

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

  vector<int> o(N);
  iota(ALL(o), 0);

  sort(ALL(o), [&](int const & l, int const & r){
      return A[l] > A[r];
      });

  multiset<int> s;
  s.insert(-1); s.insert(-1);
  s.insert(N); s.insert(N);


  int ans = 0;
  REP(i, N){
    int I = o[i];

    auto it = s.upper_bound(I);

    int r1 = *it; it++;
    int r2 = *it; it--; it--;
    int l2 = *it; it--;
    int l1 = *it;


    ans += ((r2-r1)*(I-l2)+(r1-I)*(l2-l1))*A[I];
    s.insert(I);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    while(cin>>n){
        int ans=0;
        for(int a=0;a<10;a++){
            for(int b=0;b<10;b++){
                for(int c=0;c<10;c++){
                    for(int d=0;d<10;d++){
                        if(a+b+c+d==n)ans++;
                    }
                }
            }
        }
            
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>	
#include <time.h>
#include <vector>
#include <stdio.h>
#include <memory.h>
#include <string>
#include <string.h>
#include <map>
#include <algorithm>
#include <queue>
#include <set>
#include <time.h>
#include <assert.h>
#include <sstream>
//#include <unordered_map>
#include <bitset>
#include <utility>
#include <iomanip>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <math.h>
#include <cmath>
#include <complex>
#ifdef MYDEF
#include "inc.h"
#endif
using namespace std;
typedef long long ll;
typedef complex<double> point;
 
int n, k;
char s[330];
int dp[330][330][330];
int calc(int i, int j, int rem) {
	if(i >= j)
		return i == j;
	int &ret = dp[i][j][rem];
	if(~ret)
		return ret;
	ret = max(calc(i + 1, j, rem), calc(i, j - 1, rem));
	if(s[i] == s[j])
		ret = max(ret, 2 + calc(i + 1, j - 1, rem));
	else if(rem)
	  ret = max(ret, 2 + calc(i + 1, j - 1, rem - 1));
	return ret;
}
 
int main() {
#ifdef MYDEF
	// sandstone
	HEAD
		freopen("a.txt", "r", stdin);
	//freopen("a.txt", "w", stdout);
	decTime;
#endif
 
	scanf("%s%d", s, &k);
	n = strlen(s);
	memset(dp, -1, sizeof dp);
	printf("%d\n", calc(0, n - 1, k));
 
 
#ifdef MYDEF
	printTime;
#endif
	return 0;
}

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

int main()
{
	int N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	int num = 0;
	vector<int> ary(S.size());
		
	ary[0] = 0;
	for (int i = 1; i < S.size() ; i++) {
		if (S[i-1] == 'A' && S[i] == 'C') {
			num++;
        }
        ary[i] = num;
	}
	
	for (int i = 0; i < Q; i++) {
		int l, r, ans;
		cin >> l >> r;
		ans = ary[r-1] - ary[l-1];
		cout << ans << endl;
	}
}

Measured memory_bytes: 1408
S=str(input())
l=len(S)
d=[0]*l

R,L=0,0
for i in range(l):
    if S[i]=='R':
        R+=1
        if R==1 and L>0:
            L-=1
            p=L//2
            d[i-L-2]+=L-p#R
            d[i-L-1]+=p#L
            L=0
    else:
        L+=1
        if R>0 and L==1:
            R-=1
            p=R//2
            d[i-1]+=p+1#R
            d[i]+=R-p+1#L
            R=0
if L>1:
    L-=1
    p=L//2
    d[-L-2]+=L-p
    d[-L-1]+=p
print(*d)

Measured memory_bytes: 10816
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    long long L[86];
    L[0] = 2;
    L[1] = 1;
    for (int i = 2; i <= N; i++)
    {
        L[i] = L[i - 1] + L[i - 2];
    }

    cout << L[N] << endl;
    
    return 0;
}

Measured memory_bytes: 888
//make sure to make new file!
import java.io.*;
import java.util.*;
//replace treeset with arraylist
public class Main{

   public static int[] values;
   public static ArrayList<ArrayList<Integer>> adj;
   public static ArrayList<ArrayList<Integer>> lis;
   public static int[] answer;
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      int n = Integer.parseInt(f.readLine());
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      values = new int[n+1];
      for(int k = 1; k <= n; k++){
         values[k] = Integer.parseInt(st.nextToken());
      }
      
      adj = new ArrayList<ArrayList<Integer>>(n+1);
      for(int k = 0; k <= n; k++) adj.add(new ArrayList<Integer>());
      
      for(int k = 0; k < n-1; k++){
         st = new StringTokenizer(f.readLine());
         int a = Integer.parseInt(st.nextToken());
         int b = Integer.parseInt(st.nextToken());
         
         adj.get(a).add(b);
         adj.get(b).add(a);
      }
      
      
      lis = new ArrayList<ArrayList<Integer>>();
      answer = new int[n+1];
      
      dfs(1, -1);
      
      StringJoiner sj = new StringJoiner("\n");
      for(int k = 1; k <= n; k++){
         sj.add(""+answer[k]);
      }
      out.println(sj.toString());
      
      
      
      out.close();
   }
   
   public static void dfs(int v, int p){
      int loc = -1;
      //get answer for itself
      if(lis.isEmpty()){
         lis.add(new ArrayList<Integer>());
         lis.get(0).add(values[v]);
         loc = 0;
      } else if(values[v] <= lis.get(0).get(lis.get(0).size()-1)){
          //add to first list
         lis.get(0).add(values[v]);
         
         loc = 0;
      } else if(values[v] > lis.get(lis.size()-1).get(lis.get(lis.size()-1).size()-1)){
         //add
         lis.add(new ArrayList<Integer>());
         lis.get(lis.size()-1).add(values[v]);
         loc = lis.size()-1;
      } else {
         int l = 0;
         int r = lis.size()-1;
         int ans = r;
         
         while(l <= r){
            int mid = l + (r-l)/2;
            
            if(values[v] <= lis.get(mid).get(lis.get(mid).size()-1)){
               r = mid-1;
               ans = mid;
            } else {
               l = mid+1;
               
            }
         }
         
         
         lis.get(ans).add(values[v]);
         
         loc = ans;
      }
      
      answer[v] = lis.size();
      
      for(int nei : adj.get(v)){
         if(nei == p) 
            continue;
         dfs(nei,v);
      }
      
      //remove
      lis.get(loc).remove(lis.get(loc).size()-1);
      if(lis.get(loc).isEmpty()){
         lis.remove(lis.size()-1);
      }
      
      
   }
}

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

int main()
{
  int k, n;
  cin >> k >> n;
  valarray<int> va(n);
  for (auto&& e : va)
    cin >> e;
  valarray<int> d = va.shift(1) - va;
  d[n - 1] = va[0] + k - va[n - 1];
  cout << k - d.max() << endl;
}


Measured memory_bytes: 2560