akhauriyash/Code-Regression huggingface dataset:
def buble_sort(seq):
    l = len(seq)
    res = seq[:]
    for i in range(l):
        for j in range(i+1, l)[::-1]:
            if res[j][-1] < res[j-1][-1]:
                res[j], res[j-1] = res[j-1], res[j]
    return res


def selection_sort(seq):
    l = len(seq)
    res = seq[:]
    for i in range(l):
        mi = i
        for j in range(i, l):
            if res[j][-1] < res[mi][-1]:
                mi = j
        if i is not mi:
            res[i], res[mi] = res[mi], res[i]
    return res


def is_stable(seq, sorted_seq):
    card_dic = {s[-1]: [] for s in set(seq)}
    for s in seq:
        key = s[-1]
        card_dic[key].append(s[0])

    for ss in sorted_seq:
        key = ss[-1]
        val = card_dic[key].pop(0)
        if not val == ss[0]:
            return False
    return True


n = int(input())
C = input().split()

b_sorted = buble_sort(C)
print(' '.join(b_sorted))
print('Stable' if is_stable(C, b_sorted) else 'Not stable')

s_sorted = selection_sort(C)
print(' '.join(s_sorted))
print('Stable' if is_stable(C, s_sorted) else 'Not stable')

Measured memory_bytes: 7812
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<vector>
#include<cmath>

using namespace std;

int main(){

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

    sort(a, a+n);
    long long plus_start = 0;
    while(a[plus_start]<0)plus_start++;
    if(plus_start==0)plus_start++;

    long long ansx[n-1], ansy[n-1];
    long long min=a[0], max=a[n-1];

    if(plus_start >= n){
        plus_start = n-1;
    }

    for(int i=1;i<plus_start;i++){
        ansx[i-1] = max;
        ansy[i-1] = a[i];
        max -= a[i];
    }
    for(int i=plus_start;i<n-1;i++){
        ansx[i-1] = min;
        ansy[i-1] = a[i];
        min -= a[i];
    }

    cout << max-min << endl;
    for(int i=0;i<n-2;i++)cout << ansx[i] << " " << ansy[i] << endl;
    cout << max << " " << min << endl;
}


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

int main() {
	// your code goes here
	int n;
	long long count = 0;
	cin>>n;
	vector<string>v;
	string s;
	for(int i=0; i<n; i++)
	{
	    cin>>s;
	    sort(s.begin(), s.end());
	    v.push_back(s);
	}
	sort(v.begin(), v.end());
	for(int i=0; i<v.size()-1;i++)
	{
	    long long temp_count = 1;
	    while(i < v.size()-1 && v[i] == v[i+1])
	        temp_count++, i++;
	    count += (temp_count-1)*temp_count/2;
	}
	cout<<count;
}


Measured memory_bytes: 5748
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  string judge="NO";
  cin>>s;
  bool b=false;
  int n=s.length();
  vector<char> c(n);
  for(int i=0;i<n;i++){
    c[i]=s.at(i);
  }
  reverse(c.begin(),c.end());
  int j=0;
  while(j<=n){
    if(j==n){b=true; break;}
    else if(c[j]=='r'&&c[j+1]=='e'&&c[j+2]=='s'&&c[j+3]=='a'&&c[j+4]=='r'&&c[j+5]=='e'){ j+=6;}
    else if(c[j]=='e'&&c[j+1]=='s'&&c[j+2]=='a'&&c[j+3]=='r'&&c[j+4]=='e'){ j+=5;}
    else if(c[j]=='m'&&c[j+1]=='a'&&c[j+2]=='e'&&c[j+3]=='r'&&c[j+4]=='d'){ j+=5;}
    else if(c[j]=='r'&&c[j+1]=='e'&&c[j+2]=='m'&&c[j+3]=='a'&&c[j+4]=='e'&&c[j+5]=='r'&&c[j+6]=='d'){ j+=7;}
    else{break;}
  }
  if(b){judge="YES";}
  cout<<judge;
}


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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000000
using namespace std;
typedef long long ll;

int calc(int a, int b, int symbol){
  int result;
  switch(symbol){
    case 0:
    result = a+b;
    break;
    case 1:
    result = a-b;
    break;
  }
  return result;
}

char getSymbol(int symbol){
  char c;
  switch(symbol){
    case 0:
    c = '+';
    break;
    case 1:
    c = '-';
    break;
  }
  return c;
}

int main(){
  string n; cin >> n;
  int a[4];
  rep(i, 0, 4)  a[i] = n[i]-'0';
  rep(i, 0, 2){
    rep(j, 0, 2){
      rep(k, 0, 2){
        string s = to_string(a[0]) + getSymbol(i) + to_string(a[1]) +
              getSymbol(j) + to_string(a[2]) + getSymbol(k) + to_string(a[3]);
        int seven = calc(calc(calc(a[0], a[1], i), a[2], j), a[3], k);
        if(seven == 7){
          cout << s + "=7" << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}

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

int main() {
  int N,A,B; //N:支払う金額, A:持っている1円硬貨の数
  cin >> N >> A;
  B = N/500;
  if (N-500*B <= A) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, a;

	cin >> n;

	map<ll, ll> m;

	REP(i, n) {
		cin >> a;
		m[a]++;
	}

	ll ans = 0;

	for (map<ll, ll>::iterator it = m.begin(), end = m.end(); it != end; ++it) {
		ll x = it->first;
		ll y = it->second;

		if (x > y) {
			ans += y;
		}
		else if (x < y) {
			ans += y - x;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 6272
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt

  let g x = let y = n `div` x
                s = x * y * (1 + y) `div` 2
            in s

      solve i res | i > n = res
                  | otherwise = let res' = res + g i
                                in solve (i+1) res'

  print $ solve 1 0


Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

#include <stdio.h>

int main()
{
	long N, K;

	std::cin >> N >> K;

	long sum;
	for (long n = 1; n <= N; ++n) {
		long c;
		for (c = 0;; ++c) {
			if ((n << c) >= K)
				break;
		}
		sum += 1L << (18 - c);
	}

	double p = (double)sum / (1L << 18) / N;

	printf("%.20f\n", p);
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
double a,b,h,m,deg,cos_deg,dh,dm,c;
const double pi = 3.14159265359;
int main()
{
    cin >> a >> b >> h >> m;
    dh = h * 30 + m * 0.5;
    dm = m * 6;
    deg = (abs(dh - dm) * pi)/180;
    cos_deg = cos(deg);
    c = sqrt(a*a + b*b - 2*a*b*cos_deg);
    cout << fixed << setprecision(9) << c;
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 1e8;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<int, int> P;

P operator -(P p, P q){
  return P(p.first - q.first, p.second - q.second);
}

int distP(P p, P q){
  return abs(p.first - q.first) + abs(p.second - q.second);
}

int inner(P p, P q){
  return p.first * q.first + p.second * q.second;
}
int cross(P p, P q){
  return p.first * q.second - p.second * q.first;
}

bool ok(P p, P q){
  assert(p.first == 0 || p.second == 0);
  assert(q.first == 0 || q.second == 0);
  return (inner(p, q) > 0 && cross(p, q) == 0) || (inner(p, q) == 0 && cross(p, q) > 0);
}

int main(){
  assert(P(3, 1) - P(2, 10) == P(1, -9));
  assert(!ok(P(2, 0), P(0, -2)));
  assert(!ok(P(2, 0), P(-2, 0)));
  assert(ok(P(2, 0), P(2, 0)));
  assert(ok(P(2, 0), P(0, 2)));
  int M, N;
  while(cin>>M>>N && M){
    map<string, int> id_inter;
    vector<P> inter_p(M);
    REP(i, M){
      string inter; int x, y;
      cin>>inter>>x>>y;
      int t = id_inter.size();
      id_inter[inter] = t;
      inter_p[t] = P(x, y);
    }
    vector<int> connect[1000];
    REP(i, N){
      string inter1, inter2;
      cin>>inter1>>inter2;
      int id1 = id_inter[inter1];
      int id2 = id_inter[inter2];
      connect[id1].push_back(id2);
      connect[id2].push_back(id1);
    }
    string src, dst; cin>>src>>dst;
    int from = id_inter[src];
    int to = id_inter[dst];
    P dist[1000][1000];
    REP(i, M)REP(j, M) dist[i][j] = P(-1, -1);
    queue<P> que;
    FORIT(it, connect[from]){
      que.push(P(from, *it));
      dist[from][*it] = P(distP(inter_p[from], inter_p[*it]), 2);
    }
    P ans = P(INF, INF);
    while(!que.empty()){
      P p = que.front(); que.pop();
      P state = dist[p.first][p.second];
      if(p.second == to){
        ans = min(ans, state);
      }
      FORIT(it, connect[p.second]){
        P p1 = inter_p[p.second] - inter_p[p.first];
        P p2 = inter_p[*it] - inter_p[p.second];
        if(ok(p1, p2)){
          P next = P(state.first + distP(P(0, 0), p2), state.second + 1);
          if(dist[p.second][*it] != P(-1, -1) && dist[p.second][*it] <= next){
            continue;
          }
          dist[p.second][*it] = next;
          que.push(P(p.second, *it));
        }
      }
    }
    if(ans != P(INF, INF)) cout<<ans.second<<endl;
    else cout<<"impossible"<<endl;
    assert(id_inter.size() == M);
  }
  return 0;
}

Measured memory_bytes: 9260
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
using namespace std;
#define fi first
#define se second
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 1e5 + 5;
const int maxh = 1e4 + 5;
const int INF = 1e9 + 19;
int n;
int h[maxn];
int dp[maxn];

void ReadInput()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> h[i];
}

void Solve()
{
    fill(begin(dp), end(dp), INF);
    dp[1] = 0;
    for(int i = 1; i < n; ++i)
        for(int j = i + 1; j <= min(i + 2, n); ++j)
            dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
    cout << dp[n] << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


Measured memory_bytes: 1024
from collections import deque
def main():
	N,M,*AB=map(int,open(0).read().split())
	to=[[] for _ in range(N)]
	for a,b in zip(*[iter(AB)]*2):
		to[a-1].append(b-1)
		to[b-1].append(a-1)
	q=deque([0])
	r=[None]*N
	while q:
		x=q.popleft()
		for i in to[x]:
			if r[i] is None:
				q.append(i)
				r[i]=x+1
	print("Yes",*r[1:],sep="\n")
if __name__=='__main__':
	main()

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    LL x;cin >> x;
    for(LL i=1LL;;i++){
        if(x <= i*(i+1)/2){
            cout << i << endl;
            break;
        }
    }
    return 0;
}


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

using namespace std;
#define X first
#define Y second
#define rev(a) reverse(a+1,a+n+1)
typedef long long ll;
typedef pair<int,int> P;
const int N=3e5+5,inf=1e9;
int n,i,a[N];
ll s[N],g[N],l[N],r[N],f[N];
ll sum(int n){return (ll)n*(n+1)/2;}
int t,q[N],x,k;

double cal(int x,int y){return (double)(g[x]-g[y])/(x-y);}
void pop(int x){for (;t>1&&cal(q[t-1],q[t])<=x;t--);}
void push(int x)
{
	for (;t>1&&cal(q[t-1],q[t])<=cal(q[t],x);t--);q[++t]=x;
}
void init_s(){for (int i=1;i<=n;i++) s[i]=s[i-1]+a[i];}
void init(ll *f)
{
	int i;q[t=1]=0;init_s();
	for (i=1;i<=n;i++)
	{
		pop(i);f[i]=max(f[i-1],f[q[t]]+sum(i-q[t])-s[i]+s[q[t]]);
		g[i]=f[i]+sum(i-1)+s[i];push(i);
	}
}
ll w[N];
void work(int x,int y){
	if (x==y) return;int i,m=x+y>>1;t=0;
	for (i=x;i<=m;i++) g[i]=l[i]+sum(i-1)+s[i],push(i);
	for (;i<=y;i++) pop(i),
		w[i]=l[q[t]]+r[i+1]+sum(i-q[t])-s[i]+s[q[t]];
	for (f[y]=max(f[y],w[y]),i=y-1;i>m;i--)
		f[i]=max(f[i],w[i]=max(w[i],w[i+1]));
	work(x,m);work(m+1,y);
}

int main()
{
	for (scanf("%d",&n),i=1;i<=n;i++) scanf("%d",&a[i]),f[i]=-inf;
	init(l);rev(a);init(r);rev(a);rev(r);
	init_s();work(0,n);rev(a);rev(f);rev(l);rev(r);swap(l,r);
	init_s();work(0,n);rev(a);rev(f);rev(l);rev(r);swap(l,r);
	
	for (scanf("%d",&i);i;i--)
	{
		scanf("%d%d",&x,&k);
		printf("%d\n",max(l[x-1]+r[x+1],f[x]+a[x]-k));
	}	
}


Measured memory_bytes: 18944
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
int a,b,c,x,ans;
int main()
{
    scanf("%d %d %d %d",&a,&b,&c,&x);
    for(int i=0;i<=a;i++)
        for(int j=0;j<=b;j++)
            for(int k=0;k<=c;k++)
                if((i*500+j*100+k*50)==x) ans++;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		String S = sc.next();
		String T = sc.next();
		int count = 0;

		for (int i = 0; i < 3; i++) {
			if (S.substring(i, i + 1).equals(T.substring(i, i + 1))) {
				count++;
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 35684
using System;

namespace AOJ.Volume3
{
    public class FrogGoingStraight
    {
        public static int Main()
        {
            var input = Console.ReadLine().Split(' ');
            int dist = int.Parse(input[0]);
            int big = int.Parse(input[1]);

            int answer = dist % big;
            dist -= answer;
            answer += dist / big;

            Console.WriteLine(answer);

            return 0;
        }
    }
}

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n, k;
  cin >> n >> k;
  ll ans = 1;
  n -= k;
  while (n > 0) {
    n -= k-1;
    ++ans;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>

using namespace std;


int main(void){

	int L, A, B, C, D;

	cin >> L >> A >> B >> C >> D;

	cout << L - max(A / C + (A%C != 0), B / D + (B%D != 0)) << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define int                 long long
#define pb                  push_back
#define mp                  make_pair
#define pii                 pair<int,int>
#define vi                  vector<int>
#define vvi				    vector< vi > 
#define vpii                vector< pair<int,int> > 
#define mii                 map<int,int>
#define pqb                 priority_queue<int>
#define pqs                 priority_queue<int,vi,greater<int> >
#define loop(i,a,b)		    for(int i=a;i<b;i++)
#define LOOP(i,a,b)		    for(int i=a;i<=b;i++)
#define looprev(i,a,b)		for(int i=a;i>=b;i--)
#define rloop(it,c)         for(auto& it : c)
#define sz(a)			    a.size()
#define all(c) 			    c.begin(),c.end()
#define tr(c,i) 		    for(auto i = c.begin(); i != c.end(); i++)
#define present(c,x) 	    (c.find(x) != c.end())
#define cpresent(c,x) 	    (find(all(c),x) != c.end())
#define spresent(s,x)       (s.find(x) != s.npos)           //use 'x' while passing to parameters  ||  we can also use cpresent(c,x)
#define setbits(x)          __builtin_popcountll(x)
#define zrobits(x)          __builtin_ctzll(x)
#define SETINT(a,x)         memset(a, x, sizeof(a))
#define SETCHAR(str,x)      memset(str, x, sizeof(str)      //use 'x' while passing to parameters  
#define mod                 1000000007
#define inf                 1e18
#define ps(x,y)             fixed<<setprecision(y)<<x
#define w(x)                int x; cin>>x; while(x--)
mt19937                     rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

 
int raise(int a,int n,int m = mod)
{
    if(n == 0)return 1;
    if(n == 1)return a;
    int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}
 
int floor1(int n,int k)
{
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}
 
int ceil1(int n,int k)
{
    return floor1(n+k-1,k);
}
 
 
void Gur27()
{
    ios::sync_with_stdio(0); cin.tie(0); 

}

int dp[100005];

int frog1rec(int h[],int N,int n,int K)
{
    
    if(N==2)
        return abs(h[1]-h[0]);
    if(dp[N]!=-1)
        return dp[N];
    int mn=inf;
    for(int i=K;i>=1;i--)
    {
        if(N-i>0)
        mn=min(abs(h[n-1]-h[n-1-i])+frog1rec(h,N-i,n-i,K),mn);
    }
    
    dp[N]=mn;
    return dp[N];
    
    

}
int frog1tpdn(int *h,int N,int n)
{
    LOOP(i,3,N)
    {
        dp[i]=min(abs(h[i-1]-h[i-2])+dp[i-1],abs(h[i-1]-h[i-3])+dp[i-2]);
    }
    return dp[N];
}
 
int32_t main()
{
    Gur27();
    int n,k;
    cin>>n>> k;
    int a[n];
    SETINT(dp,-1);
    dp[0]=0;
    dp[1]=0;
    
    loop(i,0,n)
        cin>>a[i];
    
    
    cout<<frog1rec(a,n,n,k);
    
    return 0;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
// #include <boost/multiprecision/mpfr.hpp>  // Defines the Backend type that wraps MPFR
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);

// namespace mp = boost::multiprecision;     // Reduce the typing a bit later...
using namespace std;


int main(){
	long long int n;
	cin >> n;
	long long int a[n],b[n];
	forn(i,0,n) cin >> a[i];
	forn(i,0,n) cin >> b[i];
	long long int ans = 0;
	long long int mxk = 29;
	while(mxk--){
		// checking for mxk bit;
		long long int ca[n],cb[n];
		memcpy(ca,a,sizeof(ca));
		memcpy(cb,b,sizeof(cb));
		long long int t = (1<<mxk);
		forn(i,0,n){
			ca[i] = (a[i]%(2*t));
			cb[i] = (b[i]%(2*t));
		}
		sort(cb,cb+n);
		long long int cnt = 0;
		forn(i,0,n){
			long long int l= 0 ,r = n-1;
			while(l<=r){
				long long int m  = l+r>>1;
				if(ca[i]+cb[m]>=t)
					r = m-1;
				else
					l = m+1;
			}
			// l gives the smallest j s.t. ai + b[j] >= t
			long long int jmin = l;
			l = 0;r = n-1;
			while(l<=r){
				long long int m = l+r>>1;
				if(ca[i]+cb[m]<2*t)
					l = m+1;
				else
					r = m-1;
			} 
			long long int jmax = r;
			if(jmax>=jmin)
				cnt += (jmax-jmin + 1);
			l = 0,r = n-1;
			while(l<=r){
				long long int m  = l+r>>1;
				if(ca[i]+cb[m]>=3*t)
					r = m-1;
				else
					l = m+1;
			}
			// l gives the smallest j s.t. ai + b[j] >= t
			jmin = l;
			l = 0;r = n-1;
			// while(l<=r){
			// 	long long int m = l+r>>1;
			// 	if(ca[i]+cb[m]<4*t)
			// 		l = m+1;
			// 	else
			// 		r = m-1;
			// } 
			jmax = n-1;
			if(jmax>=jmin)
			cnt += (jmax-jmin + 1);
		}
		if(cnt%2==1)
			ans += (1<<mxk);
	}
	cout << ans << endl;

}

Measured memory_bytes: 9748
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
import std.range;

void main(){
	auto Q=readln.split.to!(int[]),A=Q[0],B=Q[1];
	if(A==B)writeln("Draw");
	else if(A==1&&A<B)writeln("Alice");
	else if(B==1&&A>B)writeln("Bob");
	else if(A<B)writeln("Bob");
	else if(A>B)writeln("Alice");	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		// TODO Auto-generated method stub
		System.err.println("starts...");
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a == b && a == c){
			System.out.print("1\n");
		}else if(a == b || b == c || c == a){
			System.out.print("2\n");
		}else{
			System.out.print("3\n");
		}
	}

}

Measured memory_bytes: 9684
def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)

    return fac[n] * inv[n-r] * inv[r] % mod

r1,c1,r2,c2 = map(int,input().split())

mod = 10 ** 9 + 7
fac,inv = modfac(r2+c2+1,mod)
ans = 0

for r in range(r1,r2+1):

    ans += modnCr(r+c2+1,c2,mod,fac,inv) - modnCr(r+c1,c1-1,mod,fac,inv)
    ans %= mod

print (ans)


Measured memory_bytes: 124856
#include <iostream>
#include <string>
#include <map>
#include <tuple>
using namespace std;
main(){
	int i,n,h,a,b;
	string s;
	for(;cin>>n>>h,n;){
		map<tuple<int,int,int>,int>m;
		for(;h;h--)for(cin>>s>>a>>b,i=1;i<=n;i++){
			if(s=="xy")m[make_tuple(a,b,i)]=1;
			if(s=="yz")m[make_tuple(i,a,b)]=1;
			if(s=="xz")m[make_tuple(a,i,b)]=1;
		}
		cout<<n*n*n-m.size()<<endl;
	}
}

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

typedef long long ll;
typedef std::pair<ll, ll> l_l;
typedef std::pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

using namespace std;

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

    cout << N * N * N << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<list>
using namespace std;

int main(){
	string s;
	cin >> s;
	for (int i = 0;i < s.size();i++) {
		if (s[i] == 'A') {
			for (int j = 0;j < s.size();j++) {
				if (s[s.size() - 1 - j] == 'Z') {
					cout << s.size() - i-j  << endl;
					return 0;
				}
			}
		}
		
	}
}


Measured memory_bytes: 640
N,M=map(int,input().split());B=[]
for i in[0]*N:
    s=int(input().replace(" ",""),2)
    for b in B:s=min(s,s^b)
    B+=[s]*(s!=0)
N+=M-1;print((2**N-2**(N-len(B)))%998244353)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 10000
#define PII pair<int,int>
int H,W;
string S[51];
int A[51][51];
int dh[4]={1,0,-1,0},dw[4]={0,1,0,-1};
int bfs(){
  rep(i,H) rep(j,W) A[i][j]=INF;
  queue<PII> Q;
  Q.push(PII(0,0));
  A[0][0]=1;
  while(Q.size()){
    PII P=Q.front();
    Q.pop();
    if(P.first==H-1&&P.second==W-1) break;
    rep(i,4){
      int nh=P.first+dh[i],nw=P.second+dw[i];
      if(nh>=0&&nh<H&&nw>=0&&nw<W&&S[nh][nw]=='.'&&A[nh][nw]==INF){
        Q.push(PII(nh,nw));
        A[nh][nw]=A[P.first][P.second]+1;
      }
    }
  }
 return A[H-1][W-1];
}
int main(){
  cin>>H>>W;
  rep(i,H) cin>>S[i];
  int s=0;
  rep(i,H) rep(j,W) if(S[i][j]=='.') s++;
  cout<<((bfs()!=INF)?s-bfs():-1)<<endl;
}

Measured memory_bytes: 256
from itertools import permutations as per
def check(queen):
    for r1, c1 in queen:
        if not all((r1 == r2 and c1 == c2) or (r1 + c1 != r2 + c2 and r1 - c1 != r2 - c2) for r2, c2 in queen):
            return False
    return True

k = int(input())
R, C = [i for i  in range(8)],[i for i in range(8)]
q = []
for _ in range(k):
    r, c = map(int, input().split())
    q.append((r, c))
    R.remove(r)
    C.remove(c)
for l in per(C):
    q_tmp = q[:]
    for r, c in zip(R, l):
        q_tmp.append((r, c))
    if check(q_tmp):
        for r in range(8):
            print(''.join('Q' if (r, c) in q_tmp else '.' for c in range(8)) )
        break

Measured memory_bytes: 7792
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

constexpr int INF = 1 << 29;
constexpr int LIM = 804040;

class RMQ {
    int arr[LIM];
    int n;
    public:

    RMQ() {}

    RMQ(int n_) {
        n = 1;
        while (n < n_) n *= 2;
        fill(arr, arr+LIM, INF);
    }

    void update(int k, int a) {
        k += n-1;
        arr[k] = a;
        while (k > 0) {
            k = (k-1) / 2;
            arr[k] = min(arr[2*k+1], arr[2*k+2]);
        }
    }

    int query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r == -1) r = n;
        if (r <= a || b <= l) return INF;

        if (a <= l && r <= b) return arr[k];
        else {
            int vl = query(a, b, k*2+1, l, (l+r)/2);
            int vr = query(a, b, k*2 + 2, (l+r)/2, r);
            return min(vl, vr);
        }
    }
};

int N, a[202020];

RMQ rmq[2];

int loc[202020];

struct P {
    int a, b, ll, rr;

    P () {}
    P (int w, int x, int yy, int zz): a(w), b(x), ll(yy), rr(zz) {}

    bool operator <(const P& o) const {
        if (a != o.a) return a > o.a;
        return b > o.b;
    }
};


vector<int> solve() {
    vector<int> ans;

    priority_queue<P> que;

    int v = rmq[0].query(0, N), lv = loc[v];
    int w = rmq[1].query(lv+1, N);

    que.emplace(v, w, 0, N);

    while (!que.empty()) {
        P p = que.top(); que.pop();
        
        ans.push_back(p.a); ans.push_back(p.b);

        int la = loc[p.a], lb = loc[p.b];

        vector<pair<int, int>> z;
        z.emplace_back(p.ll, la); z.emplace_back(la+1, lb); z.emplace_back(lb+1, p.rr);
        for (auto q: z) {
            int l = q.first, r = q.second, b = l%2;
            if (l >= r) continue;
            int v = rmq[b].query(l, r), lv = loc[v];
            int w = rmq[1-b].query(lv+1, r);

            que.emplace(v, w, l, r);
        }
    }

    return ans;
}

int main() {
    scanf("%d", &N);
    rmq[0] = RMQ(N), rmq[1] = RMQ(N);
    for (int j = 0; j < N; ++j) {
        scanf("%d", a+j);
        loc[a[j]] = j;
        rmq[j%2].update(j, a[j]);
    }

    vector<int> ans = solve();
    for (int j = 0; j < N; ++j) {
        if (j > 0) cout << " ";
        cout << ans[j];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 16688
/*
 * c.cc: 
 */

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

using namespace std;

/* constant */

const int MAX_SN = 12;

/* typedef */

typedef long long ll;
typedef set<ll> sll;

/* global variables */

/* subroutines */

ll s2i(string &s) {
  int n = s.size();
  ll bits = 0;
  for (int i = 0; i < n; i++) {
    ll d;
    switch(s[i]) {
    case 'A': d = 1; break;
    case 'C': d = 2; break;
    case 'G': d = 3; break;
    case 'T': d = 4; break;
    }
    bits |= (d << (i * 3));
  }
  return bits;
}

/* main */

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

  sll dict;
  
  while (n--) {
    string op, s;
    cin >> op >> s;

    ll bits = s2i(s);
    if (op == "insert") dict.insert(bits);
    else if (op == "find")
      cout << ((dict.find(bits) != dict.end()) ? "yes" : "no") << endl;
  }
  return 0;
}

Measured memory_bytes: 14128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	int N; cin >> N;
	string s; cin >> s;
	int mam = 0;
	int ss = 0;
	for (int i = 0; i < N; i++) {
		if (s[i] == 'I')mam++;
		else mam--;
		if (ss < mam)ss = mam;
	}
	cout << ss << endl;







	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        if (a == b && a == c) {
            System.out.println("No");
        } else if (a != b && a != c && b != c) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }

    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin>>h>>w;
    string s;
    char C[10][10];
    rep(i,h){
        cin>>s;
        rep(j,w){
            C[i][j]=s[j];
        }
    }

    ans=1;

    rep(i,h){
        rep(j,w){
            rep(k,h){
                rep(l,w){
                    if(C[i][j]=='#'&&C[k][l]=='#'&&i<k&&j>l)ans=0;
                }
            }
        }
    }

    if(ans)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
	string s,s1,s2,sr;
	cin>>s;
	ll n=s.size();
	sr=s;
	reverse(sr.begin(),sr.end());
  	if(sr==s)
  	{
  		s1=s.substr(0,n/2);
  		s2=s.substr(n/2+1,n/2);
  		if(s1==s2)cout<<"Yes\n";
  		else cout<<"No\n";
	  }
	  else cout<<"No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
struct node{
	int to,next;
}e[1000010];
int dp[1000010],h[1000010],tot,du[1000010];
inline void add(int from,int to){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;}
int n;
inline void DFS(int now,int ffa)
{
	int fl=0;
	for(rint i=h[now];i;i=e[i].next)
	{
		int to=e[i].to;
		if(to==ffa) continue;
		DFS(to,now);
		dp[now]+=dp[to];
		if(!dp[to])
		{	if(!fl)
			fl=1;
			else 
			dp[now]++;
		}
	}
}
int main()
{
	n=read();int rt=0;
	for(rint i=1;i<n;++i)
	{
		int u=read()+1,v=read()+1;add(u,v);add(v,u);du[v]++;du[u]++;
	}
	for(rint i=1;i<=n;++i) if(du[i]>2) rt=i;
	if(!rt) 
	{
		cout<<1;return 0;
	}
	DFS(rt,0); 
	cout<<dp[rt]<<"\n";
	return 0;
}




Measured memory_bytes: 14464
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  string n; 
  cin >> n;
  rep(i, 3){
    if(n.at(i)=='7'){
      cout << "Yes" << endl;
	  return 0;
    }
  }

  cout << "No" << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <fstream>

int main(){

    int data_set_num;
    std::string str;
    std::string from = "Hoshino";
    std::string to = "Hoshina";
    std::cin >> data_set_num;
    std::cin.ignore();

    while(data_set_num--){
        std::getline(std::cin,str);
        std::string::size_type pos = str.find(from);
        while(pos != std::string::npos){
            str.replace(pos, from.size(), to);
            pos = str.find(from, pos + to.size());
        }
        std::cout << str << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3148
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;
template<typename T>
T gcd(T a, T b){
    return b ? gcd(b, a % b) : a;
}    

int main(){ 
    int N,res=-1;
    cin >> N;
    VI a(N);
    VI b(N);
    VI c(N);
    rep(i,N){
        cin >> a[i];    
    }

    b[0] = a[0];
    c[N - 1] = a[N - 1];
    for (int i = 1; i < N; i++)
    {
        b[i] = gcd(b[i - 1], a[i]);
        c[N - i - 1] = gcd(c[N - i], a[N - i - 1]);
    }
    int M = 0; //求める最大値 // 1つ選んで好きな数字に変える → 1つ選んでその数字以外のgcd
    for (int i = 0; i < N; i++)
    {
        if (i == 0) {     // 左端
            M = max(M, c[1]);
        }
        else if (i == N - 1) {   // 右端
            M = max(M, b[N - 2]);
        }
        else {
            M = max(M, gcd(b[i - 1], c[i + 1]));
        }
    }
    cout << M << endl;
    return 0;
}


    
    

   


Measured memory_bytes: 1408
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int num = 10*g+b;
        
        String result = "NO";
        if (num % 4 == 0) result = "YES";
        System.out.println(result);
    }
}


Measured memory_bytes: 20820
#include <iostream>
#include <cstdio>

using namespace std;

int n, k, cnt;
string s;

int main()
{
    cin>>n>>k>>s;
    for(int i = 0; i < s.size() - 1; i++)
    {
        if(s[i] == s[i + 1]) cnt++;
    }
    printf("%d", min(cnt + 2 * k, n - 1));
    return 0;
}


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

using namespace std;

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

	int x;

	cin >> x;

	int a = x/2;
	int b = x%2;

	if(b==1)
	{
		if(a==1 || a==2 || a==3)
		{
			cout << "YES" << '\n';
		}
		else
		{
			cout << "NO" << '\n';
		}
	}
	else
	{
		cout << "NO" << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int nen[13][31],moon[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
main(){
  int i,j,l=4,temp;
  for(i=1;i<=12;i++){
    for(j=1;j<=moon[i];j++){
      nen[i][j]=l;
      l++;
      if(l>7){
	l=1;
      }
    }
  }
  while(1){
    scanf("%d %d",&i,&j);
    if(i==0&&j==0){
      break;
    }
    temp=nen[i][j];
    if(temp==1){
      puts("Monday");
    }
    else if(temp==2){
      puts("Tuesday");
    }
    else if(temp==3){
      puts("Wednesday");
    }
    else if(temp==4){
      puts("Thursday");
    }
    else if(temp==5){
      puts("Friday");
    }
    else if(temp==6){
      puts("Saturday");
    }
    else if(temp==7){
      puts("Sunday");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;

int main(){
  mp::cpp_int x=1,a,n;
  std::cin >> n;
  for(int i=0;i<n;i++){
    std::cin >> a;
    x *= a;
    if(x>1000000000000000000LL)x=-1;
    if(x<-1) x = -1;
  }
  std::cout << x << std::endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
int n,x[N],y[N],fa[N],sz[N];
map<int,int>X,Y,cx[N],cy[N];
int find(int x)
{
	if(fa[x]==x)return x;
	fa[x]=find(fa[x]);
	return fa[x];
}
int main()
{
    scanf("%d",&n);
    int fx,fy;
    for(int i=1;i<=n;i++)
	{
        fa[i]=i;
        sz[i]=1;
        scanf("%d%d",&x[i],&y[i]);
        if(!X.count(x[i]))X[x[i]]=i;
        fx=find(X[x[i]]);
        if(!Y.count(y[i]))Y[y[i]]=i;
        fy=find(Y[y[i]]);
        if(fx!=fy)
		{
            if(sz[fx]<sz[fy])swap(fx,fy);
            fa[fy]=fx;
            sz[fx]+=sz[fy];
            X[x[i]]=fx;
            Y[y[i]]=fx;
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
	{
        fx=find(X[x[i]]);
        cx[fx][x[i]]++;
        cy[fx][y[i]]++;
    }
    for(int i=1;i<=n;i++)
        if(fa[i]==i)
            ans=ans+1ll*cx[i].size()*cy[i].size()-sz[i];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 20608
#include <iostream>
#include <cstdio>
#include <cstring>
#define int long long
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;

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

const int N=200055;
const int Mod=1000000007;
int n,m,A,B,ans,jc[N]={1};

inline int fpow(int a,int b){
	int ret=1;
	for(;b;b>>=1,a=a*a%Mod) if(b&1) ret=ret*a%Mod;
	return ret;
}

inline int inv(int x){
	return fpow(x,Mod-2);
}

inline int C(int n,int m){
	return jc[n]*inv(jc[m])%Mod*inv(jc[n-m])%Mod;
}

inline int get(int x1,int y1,int x2,int y2){
	int x=x2-x1+1,y=y2-y1+1;
	return C(x+y-2,y-1);
}

signed main(){
	n=read();m=read();A=read();B=read();
	for(int i=1;i<N;i++) jc[i]=jc[i-1]*i%Mod;
	int x=n-A,y=B+1;
	while(x&&y<=m){
		ans=(ans+get(1,1,x,y)*get(x,y,n,m)%Mod)%Mod;
		x--;y++;
	}
	printf("%lld\n",ans);
	return 0;
}


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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
int nxt[(int)1e5+100][26];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  preprocess();
  string s, t; cin>>s>>t;
  int n1 = (int)s.length(), n2 = (int)t.length();
  memset(nxt, -1, sizeof nxt);
  for(int i = n1-1; i>=0; i--) {
    rep(j,0,26) {
      if(s[i] == (char)('a' + j)) {
        nxt[i][j] = i;
      }
      else {
        if(i<n1-1) nxt[i][j] = nxt[i+1][j];
      }
    }
  }
  int p = 0;
  lli ans = 0;
  int pos;
  rep(i,0,n2) {
    pos = nxt[p][t[i]-'a'];
    if(pos == -1) {
      p = 0;
      pos = nxt[p][t[i]-'a'];
      ans += n1;
      if(pos == -1) {
        cout<<-1<<endl;
        return 0;
      }
    }
    p = pos+1;
    if(p == n1) {
      p = 0;
      pos = -1;
      ans += n1;
    }
  }
  cout<<ans+pos+1<<endl;
}



Measured memory_bytes: 10704
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <cmath>
#include <climits>
using namespace std;

char S[6];

int main()
{
    cin >> S;
    int rt = 0;
    for (int i = 0; i < 6; i++) {
        rt += (S[i] - '0');
    }
    cout << rt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {


		String ans ="Yes";
		String w = nextString();

		int[] alp = new int['z'-'a'+1];
		Arrays.fill(alp,0);
		for(int i=0;i<w.length();i++){
			alp['z'-w.charAt(i)]++;
		}
		for(int i=0;i<alp.length;i++){
			if(alp[i]%2==1){
				ans="No";
				break;
			}
		}
		System.out.println(ans);

	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define forN(n, N) for(int n=0; n<N; n++)
#define res_out(ans) cout << ans << "\n";
#define ll long long

int A[int(1e5)], dp[int(1e5)], p[int(1e6)];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, tmp, c[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    cin >> N >> M;
    forN(m, M)cin >> A[m];
    sort(A, A+M);
    vector<int> dp(N+1, -1); 
    dp[0] = 0;
    for(int n=2; n<=N; n++){
        for(int m=M-1; m>=0; m--){
            if(c[A[m]] <= n && dp[n-c[A[m]]] >= 0){
                tmp = dp[n - c[A[m]]] + 1;
                if(tmp > dp[n]){
                    //cout << n << " " << A[m] << " " << dp[n - c[A[m]]] << "\n";
                    dp[n] = tmp;
                    p[n] = A[m];
                }
            }
        }
    }
    string ans;
    while(N > 0){
        ans += '0' + p[N];
        N -= c[p[N]];
    }
    res_out(ans)
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
	int l[4]={0},r[4]={0},i;
	float a,b;
	while(scanf("%f%f",&a,&b)!=EOF){
		if(a>=1.1) l[0]++;
		if(1.1>a&&a>=0.6) l[1]++;
		if(0.6>a&&a>=0.2) l[2]++;
		if(0.2>a) l[3]++;
		if(b>=1.1) r[0]++;
		if(1.1>b&&b>=0.6) r[1]++;
		if(0.6>b&&b>=0.2) r[2]++;
		if(0.2>b) r[3]++;
	}
	for(i=0;i<4;i++) printf("%d %d\n",l[i],r[i]);
	return 0;
}

Measured memory_bytes: 624
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

struct Song
{
	char s[110];
	int szS;
	int t;
};

Song songs[55];
int n;
char x[110];
int szX;


int main()
{
	scanf("%d\n", &n);
	for (int i = 0 ; i < n ; i++)
		scanf("%s %d\n", songs[i].s, &(songs[i].t));
	scanf("%s\n", x);
		
	int p = 0;
	while (p < n) {
		if (strcmp(songs[p].s, x) == 0) {
			p++;
			break;
		}
		p++;
	}
		
	int duration = 0;
	for (int i = p ; i < n ; i++) {
		duration = duration + songs[i].t;
	}
	
	printf("%d\n", duration);
	
	return 0;
}



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

void solve(long long N, std::vector<long long> a) {
    map<ll, ll> cntmap;
    ll ans = 0;
    rep(i, N) { cntmap[a[i]]++; }
    for (auto i = cntmap.begin(); i != cntmap.end(); i++) {
        if (i->second > i->first) {
            ans += i->second - i->first;
        } else if (i->second < i->first) {
            ans += i->second;
        }
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 10136
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=(s);i<(t);++i)
#define per(i,s,t) for(int i=((t)-1);i>=s;--i)
#define repb(i,s,t) for(int i=(s);i<=(t);++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
#define mst(a,b) memset(a,b,sizeof(a))
#define mcpy(des,sor) memcpy(des,sor,sizeof(sor))
#define dd(x) cout<<#x<<'='<<x<<' '
#define de(x) cout<<#x<<'='<<x<<'\n'
#define fi first
#define se second
#define sq(x) ((x)*(x))
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int inf = 0x3f3f3f3f;
const ll mod = 1e9+7;
const db eps = 1e-8;

char io[1<<15],*is=io,*ie=io+1;
#define rd if(++is==ie)ie=(is=io)+fread(io,1,sizeof(io),stdin)
template<class T>
inline bool Cin(T &a){
	a=0;bool s=0;
	if(is==ie)return 0;
	do{rd;if(*is=='-')s=1;}while(!isdigit(*is)&&is!=ie);
	if(is==ie)return 0;
	do{(a*=10)+=*is&15;rd;}while(isdigit(*is)&&is!=ie);
	if(s)a=-a;;return 1;}

inline int Gets(char a[]){
	int p=0;
	if(is==ie)return 0;
	do rd; while(!isgraph(*is)&&is!=ie);
	if(is==ie)return 0;
	do {a[p++]=*is;rd;}while(isgraph(*is)&&is!=ie);
	a[p]=0;return p;}

#define maxn 100005

char s[maxn];
int v[maxn],f[maxn];

int main()
{
	int n=Gets(s+1),o=0,pre[3];
	repb(i,1,n)
	{
		if(s[i]==s[i+1])o=i;
		v[i]=(v[i-1]+s[i]-'a'+1)%3;
	}
	if(!o)return !printf("1\n");
	f[0]=1;pre[0]=0;pre[1]=pre[2]=-1;
	repb(i,1,n)
	{
		if(v[i]==0&&i!=n)f[i]=1;
		repb(j,1,2)
		{
			o=pre[(v[i]+3-j)%3];
			if(~o)(f[i]+=f[o])%=mod;
		}
		pre[v[i]]=i;
	}
	printf("%d\n",f[n]);
}

Measured memory_bytes: 1152
l=gets.to_i;n=l.bit_length;a=[];b=1;(n-1).times{|i|*q=n+~i,n-i;a<<q+[1<<i]<<q+[0];b&l>0&&a<<[1,n-i,l^=b];b*=2};[[n,a.size],*a].map{|e|puts e*' '}

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

#define pb push_back
#define all(a) (a).begin(), (a).end()

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

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

bool solve(int n) {
	bool can = false;
	while (n > 0) {
		int d = n % 10;
		if (d == 7)
			can = true;
		n /= 10;
	}
	return can;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n; cin >> n;
    bool can = solve(n);

    cout << (can ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3652