akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
    int n;
    cin>>n;
    vector<vector<int> > match(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++)
            cin>>match[i][j];
    }
    vector<int> dp(1<<n, 0);
    dp[0] = 1;
    for (int mask = 0; mask < (1<<n) - 1; mask++) {
        int man = __builtin_popcount(mask);
        for (int woman = 0; woman < n; woman++) {
            if (match[man][woman] && !(mask & (1<<woman))) {
                int nextMask = mask ^ (1<<woman);
                dp[nextMask] = (dp[nextMask] + dp[mask]) % mod;
            }
        }
    }
    cout<<dp[(1<<n)-1]<<"\n";
    return 0;
}


Measured memory_bytes: 11464
#include <iostream>
#include <vector>

using namespace std;

int main() {

	int inputA, inputB;
	char operate;

	cin >> inputA >> operate >> inputB;

	if (operate == '+'){

		cout << inputA + inputB;
	}
	else {

		cout << inputA - inputB;
	}

	return 0;
}

Measured memory_bytes: 256
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,k,num[200010],x,ans=0;
vector <int> v;

int main()
{
	cin>>n>>k;
	rep(i,n)
	{
		scanf("%d",&x);
		num[x]++;
	}
	repn(i,n) if(num[i]>0) v.pb(num[i]);
	sort(v.begin(),v.end());
	rep(i,(int(v.size()))-k) ans+=v[i];
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int MN = 100100;
vvi g;
map<int,int> mo;
bitset<MN> bs;
void dfs(int u) {
	for(int i=0;i<g[u].size();i++) {
		int v = g[u][i];
		if(!bs[v]) {bs.set(v);dfs(v);}
	}
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	vi wa[2];
	for(int id=0;id<2;id++) {
		int xo = 0;
		for(int i=0;i<n;i++) {
			int t;
			cin >> t;
			xo ^= t;
			wa[id].push_back(t);
		}
		wa[id].push_back(xo);
	}
	vi wb[2];
	wb[0] = wa[0];
	sort(wb[0].begin(),wb[0].end());
	wb[1] = wa[1];
	sort(wb[1].begin(),wb[1].end());
	bool poss = true;
	for(int i=0;i<wb[0].size();i++) {
		if(wb[0][i] != wb[1][i]) {
			poss = false;break;
		}
	}
	if(!poss) {
		cout << -1 << '\n';
		return 0;
	}
	int ct = 0;
	int no = 0;
	for(int i=0;i<wa[0].size();i++) {
		if(i < n && wa[0][i] == wa[1][i]) {continue;}
		no++;
		for(int id=0;id<2;id++) {
			int u = wa[id][i];
			if(!mo.count(u)) {
				mo[u] = ct;
				wa[id][i] = ct;
				ct++;
			} else {
				wa[id][i] = mo[u];
			}
		}
	}
	g.assign(mo.size(),vi());
	for(int i=0;i<wa[0].size();i++) {
		int a = wa[0][i];
		int b = wa[1][i];
		if(i < n && a == b) {continue;}
		g[a].push_back(b);
	}
	int num = 0;
	for(int i=0;i<g.size();i++) {
		if(!bs[i]) {
			bs.set(i);
			num++;
			dfs(i);
		}
	}
	cout << no+num-2 << '\n';
}


Measured memory_bytes: 19520
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<pair<int,int> > r(n),b(n);
	for(int i=0;i<n;i++)
		cin >> r[i].first >> r[i].second;
	for(int i=0;i<n;i++)
		cin >> b[i].first >> b[i].second;
	

	sort(r.begin(),r.end());
	reverse(r.begin(),r.end());

	for(int i=0;i<n;i++)
		swap(b[i].first,b[i].second);
	sort(b.begin(),b.end());
	for(int i=0;i<n;i++)
		swap(b[i].first,b[i].second);

	vector<bool> used(n,false);
	int count=0;

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(b[i].first>r[j].first and b[i].second>r[j].second and used[j]==false)
			{
//				cout << b[i].first << " " << b[i].second << " : " << r[j].first << " " <<  r[j].second << endl;
				count++;
				used[j]=true;
				break;
			}
		}
	}

	cout << count << endl;
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
  int i=0,j=0;
  char s[110],key[]="keyence";
  scanf("%s",s);
  int len=strlen(s);
  while(i<7&&s[i]==key[i])i++;
  while(j<7&&s[len-1-j]==key[6-j])j++;
  if(i+j>=7) puts("YES");
  else puts("NO");
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
using namespace std;
const int MAX = 1e5 + 10;
const ll MOD = 1e9 + 7;
int N, M, K, Q;

int main()
{
	int i, j, k;
	string ret;
	scanf("%d", &N);
	printf("0\n");
	cin >> ret;
	if (ret == "Vacant") {
		return 0;
	}
	string first = ret;
	int l = 1;
	int h = N - 1;
	while (l < h) {
		int mid = (l + h) >> 1;
		printf("%d\n", mid);
		cin >> ret;
		if (ret == "Vacant") {
			return 0;
		}
		if (first == ret) {
			if (mid % 2) h = mid - 1;
			else l = mid + 1;
		}
		else {
			if (mid % 2) l = mid + 1;
			else h = mid - 1;
		}
	}
	printf("%d\n", l);
	cin >> ret;
	if (ret == "Vacant") {
		return 0;
	}

}

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,m,top,tim,ans,go[N],nex[N],low[N],dfn[N],head[N];
void add(int u,int v){nex[++top]=head[u];head[u]=top;go[top]=v;}
void tarjan(int u,int fa)
{
	dfn[u]=low[u]=++tim;
	for (int i=head[u];i;i=nex[i])
	{
		int v=go[i];
		if (!dfn[v])
		{
			tarjan(v,u);
			low[u]=min(low[u],low[v]);
			if (low[v]>dfn[u]) ++ans;
		}
		else
		if (v!=fa) low[u]=min(low[u],dfn[v]);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int u,v,i=1;i<=m;++i) scanf("%d%d",&u,&v),add(u,v),add(v,u);
	tarjan(1,0),printf("%d",ans);
	return 0;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {
 
  ll X;
  cin >> X;
  ll start = 100;
  ll i = 0;

  for(i = 0; ;i++){
    if(start >= X)break;
    double tmp = start * 0.01;
    start += (ll)tmp;
    // cout << start << endl;
  }

  cout << i << endl;
  return 0;


}


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=1e5+5;
#define int long long
int a[50]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
signed main(){
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;
	return 0;
}

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

//mod逆元を使ったnCkの計算(速)
const int64_t MAX = 510000;
const int64_t MOD = 1000000007;

int64_t fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
int64_t COM(int64_t n, int64_t k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int S;
  cin >> S;
  int64_t ans = 0;
  COMinit();
  for(int i=1; i<S; i++){
    int s = S - 3*i;
    if(s < 0){
      break;
    }
    ans += COM(i+s-1,s);
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 15580
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int M = sc.nextInt(), D = sc.nextInt();
    int count = 0;
    int first, second;
    for (int i = 4; i <= M; i++)
      for(int j = 22; j <= D; j++) {
        first = j % 10;
        second = j / 10;
        if(first >= 2 && second >= 2 && first * second == i)
          count++;
      }
    System.out.println(count);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int S[10005];
int T[505];

int main()
{
	int N;
	cin >> N;
	REP(i, N)
	{
		cin >> S[i];
	}
	int q;
	cin >> q;
	REP(i, q)
	{
		cin >> T[i];
	}

	int sum = 0;
	REP(i, q)
	{
		REP(j, N)
		{
			if (T[i] == S[j])
			{
				sum++;
				break;
			}
		}
	}
	cout << sum << endl;
	return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << endl;
  } else {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int n;

int main(){
    scanf("%d", &n);
    printf("%d\n", n * n * n);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;

int main(){
  ll h ,w;
  cin >> h >> w;

  if(h == 1 || w == 1){
    cout << 1 << endl;
    return 0;
  }

  ll ans;
  if(h % 2 == 0 || w % 2 == 0){
    ans = (h * w) / 2;
  }
  else{
    ans = (h * w + 1) / 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int main(){
	int x,y;
	cin >> x >> y;
	if(x<=5)cout << 0 << endl;
	else if(x<=12)cout << y/2 << endl;
	else cout << y << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    int h,w;
    cin >> h >> w;
    char s[h][w];
    repi(i,h,0){
        repi(j,w,0){
            cin >> s[i][j];
        }
    }
    repi(i,h,0){
        repi(j,w,0){
            int cnt = 0;
            if(s[i][j] == '#')continue;
            repi(k,3,0){
                repi(l,3,0){
                    if(i-1+k < 0 || i - 1 + k >= h)continue;
                    if(j-1+l < 0 || j - 1 + l >= w)continue;
                    if(s[i-1+k][j-1+l] == '#')cnt++;
                }
            }
            s[i][j] = cnt + '0';
        }
    }
    repi(i,h,0){
        repi(j,w,0){
            cout << s[i][j];
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize, t: usize,
        mut ct: [(usize, usize); n],
    }
    let mut cost = 10000;

    for &(c_, t_) in &ct {
        if t_ <= t {
            cost = min(cost, c_);
        }
    }
    if cost == 10000 {
        println!("TLE");
    } else {
        println!("{}", cost);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())


//INT_MAX
//INT_MIN
//LLONG_MAX
//LLONG_MIN
//DBL_MIN
//DBL_MAX
//LDBL_MIN
//LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    vector<int> v(3);
    for (int i = 0; i < 3; i++) {
        cin >> v[i];
    }
    vsort(v);
    if (v[0] == 5 && v[1] == 5 && v[2] == 7) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,m;cin>>n>>m;
  vector<bool>AC(n,false);
  vector<ll>WA(n);
  rep(i,m){
    ll p;string s;
    cin>>p>>s;
    if(s=="AC")AC[p-1]=true;
    else{
      if(AC[p-1]==false)WA[p-1]++;
    }
  }
  ll countAC=0;
  rep(i,n){
    if(AC[i])countAC++;
  }
  ll countWA=0;
  rep(i,n){
    if(AC[i])countWA+=WA[i];
  }
  cout<<countAC<<" "<<countWA<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int binpow(int a, int b, int mo) {
  int ans = 1;
  do {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
const int FACTSIZE = 100100;
int fact[FACTSIZE];
int revfact[FACTSIZE];

int ncr(int n, int r) {
  if (n < r)
    return 0;
  int rs = fact[n] * revfact[r];
  if (rs >= MOD)
    rs %= MOD;
  rs *= revfact[n - r];
  if (rs >= MOD)
    rs %= MOD;
  return rs;
}
void init() {
  fact[0] = 1, revfact[0] = 1;
  for (int i = 1; i < FACTSIZE; ++i) {
    fact[i] = fact[i - 1] * i % MOD;
    revfact[i] = binpow(fact[i], MOD - 2, MOD);
  }
}

signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  init();
  int N;
  cin >> N;
  vec< int > pos(N, -1);
  int ans = 0;
  REP(i, N + 1) {
    int p;
    cin >> p;
    p--;

    if (pos[p] != -1) {
      ans = pos[p] + N - i;
    }
    pos[p] = i;
  }

  // N+1 C i - ans C i-1

  REPS(i, N + 1) {
    int tmp = ncr(N + 1, i);
    if (i <= ans + 1) {
      int tmp2 = ncr(ans, i - 1);
      tmp -= tmp2;
      tmp += MOD;
      tmp %= MOD;
    }
    print(tmp);
  }
}

Measured memory_bytes: 3584
import sys,os,math
from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import Queue


# sys.stdin = open('input')
# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())


def main():
    s = raw_input().strip()
    t = raw_input().strip()
    d = defaultdict(list)
    for idx, c in enumerate(s):
        d[c].append(idx)
    i, offset = 1, -1
    for c in t:
        idx = bisect.bisect_right(d[c], offset)
        if not d[c]:
            print -1
            return
        if idx == len(d[c]):
            i+=1
            offset = d[c][0]
        else:
            offset = d[c][idx]
    print (i-1)*len(s)+offset+1






main()


Measured memory_bytes: 38552
N = [[int(i) for i in input().split()] for j in range(3)]

if N[0][0]-N[0][1]==N[1][0]-N[1][1]==N[2][0]-N[2][1] and N[0][1]-N[0][2]==N[1][1]-N[1][2]==N[2][1]-N[2][2] and N[0][0]-N[1][0]==N[0][1]-N[1][1]==N[0][2]-N[1][2] and N[1][0]-N[2][0]==N[1][1]-N[2][1]==N[1][2]-N[2][2]:
        print('Yes')
else:
        print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define inf 999999
int aa[100050];
int bb[100050];
int main()
{
	int a,b,m;
	int min1=inf;
	int min2=inf;
	scanf("%d %d %d",&a,&b,&m);
	for(int i=1;i<=a;i++){
		scanf("%d",&aa[i]);
		if(min1>aa[i]){
			min1=aa[i];
		}
	}
	for(int i=1;i<=b;i++){
		scanf("%d",&bb[i]);
		if(min2>bb[i]){
			min2=bb[i];
		}
	}
	int minn=min1+min2;
	int x,y,z;
	for(int i=0;i<m;i++){
		scanf("%d %d %d",&x,&y,&z);
		if(minn>(aa[x]+bb[y]-z)){
			minn=aa[x]+bb[y]-z;
		}
	}
	printf("%d\n",minn);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

long max(long a,long b){
  if(a > b){
    return a;
  }
  return b;
}

int main(void){
  int N,x;
  scanf("%d%d",&N,&x);

  int a[N];
  for(int i = 0;i < N;i++) scanf("%d",&a[i]);
  long sum;
  long ans = 0;

  if(a[0] > x){
    ans += a[0]-x;
    a[0] = x;
  }
  for(int i = 0;i < N-1;i++){
    sum = a[i]+a[i+1];
    if(sum > x){
      ans += sum-x;
      a[i+1] -= sum-x;
    }
  }

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

  return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  string ans;
  int end = (int)'Z';
  int tmp;
  for (int i = 0; i < s.length(); i++)
  {
    tmp = (int)(s[i] + n);
    if (tmp > end) ans += (s[i] + n - 26);
    else ans += s[i] + n;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

int r[11][10001];

int main() {
	int R, C;

	while (scanf("%d%d", &R, &C), R!=0 && C!=0) {
		for (int i = 0; i < R; i++) {
			for (int j = 0; j < C; j++) {
				scanf("%d", &r[i][j]);
			}
		}

		int sum, ans = 0;
		for (int i = 0; i < (1 << R); i++) {
			sum = 0;
			for (int j = 0; j < C; j++) {
				int cnt = 0;
				for (int l = 0; l < R; l++) {
					if ((i >> l) & 1 ^ r[l][j]) {
						cnt++;
					}
				}
				sum += std::max(cnt, R - cnt);
			}
			ans = std::max(ans, sum);
		}
		printf("%d\n", ans);
	}

	return 0;
}


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

int main(){

  string s;
  cin >> s;
  char a,b,c,d;
  a = s[0];
  b = s[1];
  c = s[2];
  d = s[3];
  if((a == b && c == d && a != c )|| (a == c && b == d && a != b) || (a == d && b == c && a != b)){
   cout << "Yes" << endl; 
  }else{
   cout << "No" << endl; 
  }
}

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

using namespace std;

int main()
{
    string first;
    string second;
    int i, flag;
    flag = 0;
    cin >> first >> second;
    if (first.size() > 10)
    {
        flag = 1;
    }

    if (second.size() != first.size() + 1)
    {
        flag = 1;
    }



    for (i = 0; i < first.size(); i++)
    {
        if (first[i] != second[i])
        {
            flag = 1;
        }
    }

    if (flag)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    
    return 0;
}



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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

const ll MAX = 2000000; //テーブルの数
const ll MOD = 1e9+7; //mod宣言

long long fac[MAX], finv[MAX], inv[MAX];
// finv ->階乗割り算
// fac ->階乗掛け算

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}

int main(){
    COMinit();
    ll n, k; cin >> n >> k;
    vector<ll> lis(n);
    REP(i, 0, n){
        cin >> lis[i];
    }
    sort(ALL(lis));
    ll mi = 0;
    ll ma = 0;
    REP(i, 0, n-k+1){
        if(lis[i] >= 0){
            mi = (mi + (lis[i] * COM(n-(i+1), k-1))%MOD) % MOD;
        }else{
            ma = (ma + ((-1 * lis[i]) * COM(n-(i+1), k-1))%MOD) % MOD;
        }
    }
    sort(ALL(lis), greater<>());
    
    REP(i, 0, n-k+1){
        if(lis[i] >= 0){
            ma = (ma + (lis[i] * COM(n-(i+1), k-1))%MOD) % MOD;
        }else{
            mi = (mi + ((-1 * lis[i]) * COM(n-(i+1), k-1))%MOD) % MOD;
        }
    }
    cout << (ma - mi + MOD) % MOD << endl;
    return 0;
}

Measured memory_bytes: 47872
N,M,C=map(int,input().split())
B=[int(x) for x in input().split()]
A=[[int(x) for x in input().split()] for i in range(N)]
count=0
for i in range(N):
  d=0
  for j in range(M):
    d=A[i][j]*B[j]+d
  if d+C>0:
    count=count+1
print(count)

Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
static const int64_t INF=10000000000000;
struct edge{int64_t from,to,cost;};
int main(){
  int64_t N,M;cin>>N>>M;
  vector<edge>es(M);
  for(int i=0;i<M;i++){
  int64_t a,b,c;cin>>a>>b>>c;
    a--;b--;
    es[i].from=a;
    es[i].to=b;
    es[i].cost=c;
  }vector<vector<int64_t>>dp(N,vector<int64_t>(N,INF));
  for(int64_t i=0;i<N;i++)
    dp[i][i]=0;
  for(int i=0;i<M;i++){
  int64_t a=es[i].from;
    int64_t b=es[i].to;
    int64_t c=es[i].cost;
    dp[a][b]=c;
    dp[b][a]=c;
  }for(int64_t k=0;k<N;k++)
    for(int64_t i=0;i<N;i++)
      for(int64_t j=0;j<N;j++)
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
  int64_t ans=0;
  for(int i=0;i<M;i++){
  int64_t a=es[i].from;
    int64_t b=es[i].to;
    int64_t c=es[i].cost;
    bool x=false;
    for(int j=0;j<N;j++){
    if(x)break;
      if(dp[j][a]+c==dp[j][b] || dp[j][b]+c==dp[j][a])
        x=true;
    }if(x)ans++;
  
  }ans=M-ans;
cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 3688
#include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	int i = 1;
	do{
		int x = i;
		if ( x % 3 == 0 ){
			cout << " " << i;
		} else {
		 	do{
				if ( x % 10 == 3 ){
					cout << " " << i;
					break;
				}
				x /= 10;
			}while( x );
		}
	}while( ++i <= n );

  cout << endl;
  return 0;
}

Measured memory_bytes: 1168
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main() {
    int S;
    cin >> S;
    int h = S / 3600;
    int m = (S - h * 3600) / 60;
    int s = S - h * 3600 - m * 60;
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3092
def resolve():
    n, t = map(int, input().split())
    foods = []
    limit = 0
    tt = []
    for i in range(n):
        a, b = map(int, input().split())
        foods.append((a,b))
        limit += a
        tt.append(a)
    c = max(tt) * 2
    foods.sort(key=lambda x:(x[0], -x[1]))
    limit = min(limit * 2, t * 2)
    time = [0 for _ in range(limit+c)]
    used = [0] * (limit + c)
    used[0] = 1

    for a,b in foods:
        for i in range(limit+c)[::-1]:
            if used[i] and i+a*2 < limit + c and time[i+a*2] < time[i] + b:
                time[i+a*2] = time[i] + b
                if i+a*2 < limit:
                    used[i+a*2] = 1

    print(max(time))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 45060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {


	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
			int x = in.nextInt(), y = in.nextInt();

			long ans = 0;
			if (a + b > 2 * c) {
				if (x < y) {
					ans += x * 2 * c;
					y -= x;
					if (b < 2 * c) {
						ans += y * b;
					} else {
						ans += y * 2 * c;
					}
				} else {
					ans += y * 2 * c;
					x -= y;
					if (a < 2 * c) {
						ans += x * a;
					} else {
						ans += x * 2 * c;
					}
				}
			} else {
				ans += x * a;
				ans += y * b;
			}

			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 20948
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#ifndef ONLINE_JUDGE
    freopen("A.in", "r", stdin);
#endif
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(6);
}
///////////////////////////
const int N = 5 + 2e5;

int n;
int tot, a[N];
LL ans;
int main() {
    
    cin >> n;
    rep(i, 1, n) {
        cin >> a[i];
    }
    if(a[1]!=0){cout<<-1;return 0;}
    rep(i,2,n)
    {
        if(a[i]>a[i-1]+1){cout<<-1;return 0;}
        if(a[i]==a[i-1]+1)ans++;
        else ans+=a[i];

    }
    cout <<ans;
    return 0;
}



Measured memory_bytes: 1024
# 2 6   n m
require 'prime'

n, m = gets.split.map(&:to_i)
divisor = 10**9 + 7

array_prime_division = m.prime_division
array_b = []
array_prime_division.each do |p, b|
  array_b << b
end

ans = 1
array_b.each do |b|
  comb = 1
  (b-1).downto(0) do |j|
  # b.times do |j|
    comb = (b+n-1-j) * comb / (b-j)
  end

  ans *= comb
end

p ans % divisor


Measured memory_bytes: 14348
def main():
    """"ここに今までのコード"""
    H = int(input())
    Count, atk = 1,1

    while H > atk * 2 - 1:
        atk = atk * 2
        Count = Count * 2 + 1
    
    print(Count)


if __name__ == '__main__':
    main()

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

using namespace std;
using ll = long long;

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

int main() {
  int n, d;
  cin >> n >> d;
  int x[n][d];
  rep(i, n) rep(j, d) cin >> x[i][j];

  int ans = 0;
  rep(i, n) rep(j, i) {
    int dist = 0;
    rep(k, d) { dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); }

    bool ok = false;
    for (int k = 1; k * k <= dist; ++k) {
      if (k * k == dist) {
        ok = true;
        break;
      }
    }
    if (ok) ++ans;
  }

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


Measured memory_bytes: 3656
use std::io::{self, BufRead};

pub fn find_divisors(n: i64) -> Vec<i64> {
  let mut res = Vec::new();
  let mut i = 1;
  while i * i <= n {
    if n % i == 0 {
      res.push(i);
      if i != n / i {
        res.push(n / i);
      }
    }
    i += 1
  }
  res
}

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let n: i64 = lines.next().unwrap().unwrap().parse().unwrap();

  let num_divs_n = find_divisors(n-1).len() - 1;
  let divs = find_divisors(n);
  let mut num_divs_n_1 = 0;
  for k in divs {
    if n % k != 0 {
      continue
    }
    let mut m = n;
    while k != 1 && m != 1 && m % k == 0 {
      m /= k;
    }
    if m % k == 1 {
      num_divs_n_1 += 1;
    }
  }

  println!("{}", num_divs_n_1 + num_divs_n);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {

    ll n;

    while (cin >> n, n) {

        vector<ll> p(n), j(n-1);

        for (ll i = 0; i < n  ; i++) cin >> p[i];
        for (ll i = 0; i < n-1; i++) cin >> j[i];

        ll psum = 0;
        for (ll i = 0; i < n  ; i++) psum += p[i];

        sort(j.begin(), j.end(), greater<ll>());
        vector<ll> imos(n, 0);
        for (ll i = 0; i < n-1; i++) {
            imos[i+1] = imos[i] + j[i];
        }

        ll ans = 0;
        for (ll m = 1; m <= n; m++) {
            ll cand = (psum + imos[n-m]) * m;
            ans = max(ans, cand);
        }
        cout << ans << endl;

    }

}


Measured memory_bytes: 4408
#include<iostream>
#include <cstdio>
#include<cstring>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) {if (x % y == 0) return y;else return LGCD(y, x % y);}
ll LLCM(ll x, ll y) {return x * y / LGCD(x, y);}

int GCD(int x, int y) {if (x % y == 0) return y;else return GCD(y, x % y);}
int LCM(int x, int y) {return x * y / GCD(x, y);}

int main() {
	int n;
	int ans = 0;
	cin >> n;
	vector<int>p(n);
	for (int i = 0;i < n;i++) {
		cin >> p.at(i);
		if (i > 1) {
			if ((p[i - 2] < p[i - 1] && p[i - 1] < p[i]) || (p[i - 2] > p[i - 1] && p[i - 1] > p[i])) {
				ans++;
			}
		}
	}
		cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
var main = function main(input) {
    var N = +input

    for (var x = 2; x < 100; x = x * 2) {
        if (x > N) break; 
    }
    
    console.log(x/2)
   
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf-8'))


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

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try{
	    boolean flag, flag2=true;
	    while(true){
		String[] xt = sc.readLine().split(" ");
		int a = Integer.valueOf(xt[0]);
		int b = Integer.valueOf(xt[1]);
		if(a==0 && b==0)
		    break;
		flag = false;
		if(!flag2) System.out.println();
		for(int i=a; i<=b; i++)
		    if(i%4==0){
			if(i%400==0){
			    System.out.println(i);
			    flag = true;
			}
			else if(i%100==0)
			    ;
			else{
			    System.out.println(i);
			    flag = true;
			}
		    }
		if(!flag)
		    System.out.println("NA");
		flag2=false;
	    }
	}catch (Exception e){
	    System.out.println("Error");
	}
    }
}

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

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

    int n;
    cin>>n;
    int P[n];
    for(int i = 0 ; i < n ; i++)
        cin>>P[i];
    
    int m = P[0];
    int cnt = 1;
    for(int i = 1 ; i < n ; i++)
    {
        if(m>P[i]){
            cnt++;
            m = P[i];
        }
    }

    cout<<cnt;
}

Measured memory_bytes: 1024
#include <stdio.h>

void call(int n);

int main() {
    int n;

    scanf("%d", &n);

    call(n);
    
    printf("\n");

    return 0;
}


void call(int n) {
    int i, j;

    for (i = 1; i <= n; i++) {
        j = i;
        if (i % 3 == 0) printf(" %d", i);
        
        else {
            while(1) {    
                if (j % 10 == 3) {
                    printf(" %d", i);
                    break;
                }
                else if (j < 10) break;
                j = j / 10;
            }
        }
    }
}



Measured memory_bytes: 2060
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int n,k;
vector<bool> a(10,true);
int ans;
int digits;

void rec(string s){
  //cout <<"s="<<s<<endl;
  if(stoi(s) >= n){
    chmin(ans,stoi(s));
    return;
  }
  if(digits+1 <= s.size()){
    return;
  }
  rep(i,10){
    if(a[i]){
      rec(s+to_string(i));
    }
  }
}

int main(){
  cin >> n >> k;
  rep(i,k){
    int tmp;
    cin >> tmp;
    a[tmp] = false;
  }
  digits = to_string(n).size();
  //printf("digits=%d\n",digits);
  ans = 1 << 30;
  
  rep(i,10){
    if(a[i]){
      rec(to_string(i));
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int A,B,C;
    scanf("%d%d%d", &A,&B,&C);
    if (((A == B) && (A != C)  && (B != C)) || ((A == C) && (A != B) && (C != B)) || ((B == C) && (B != A) && (C != A)))
    {
        printf("Yes");
    }
    else {
        printf("No");
    }
    return 0;
}

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

#define ll long long int
#define vi vector<int> 
int main() {
   ll a,b,k;
   cin >> a >>b >>k;
   if(k>=a+b)a=0,b=0;
   else{
       if(k<=a)a-=k;
       else{
           k-=a;
           a=0;
           b-=k;
       }
    
       
   }
   
   cout << a <<" "<<b;
}


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

const int END = -1;
const int MAX_SIZE = 1010;

int main() {
  int n,m;
  int A[MAX_SIZE], B[MAX_SIZE];
  
  for (int i = 0; i < MAX_SIZE; ++i) {
    A[i] = END;
    B[i] = END;
  }

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

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

  int ans = -1;
  for (int i = 0; i < MAX_SIZE && ans < 0; ++i) {
    if (A[i] == B[i]) {
      if (A[i] == END) {
        ans = 0;
      }
      continue;
    }
    if (A[i] == END || A[i] < B[i]) {
      ans = 1;
    } else {
      ans = 0;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3132
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

const long INF = long.max / 2;

void main() {
    int N, M; scanf("%d %d\n", &N, &M);
    auto S = new int[N],
         T = new int[N],
         P = new long[M + 1];
    foreach (i; 0 .. N) scanf("%d %d\n", &S[i], &T[i]);
    foreach (i; 1 .. M + 1) scanf("%d\n", &P[i]);
    P ~= INF;
    
    P = P.sort.uniq.array;

    auto X = new long[][](2, M + 2);
    foreach (i; 0 .. M + 1) {
        X[0][i + 1] = X[0][i];
        X[1][i + 1] = X[1][i];
        X[i & 1][i + 1] += P[i + 1] - P[i];
    }

    const DEBUG = false;

    long Ans = 0;
    foreach (i; 0 .. N) {
        int s = S[i], t = T[i];
        bool swapped = s > t;
        if (s > t) swap(s, t);
        auto us = P.assumeSorted.lowerBound(s).length;
        auto lt = P.assumeSorted.lowerBound(t).length;
        if (us == lt) { Ans += t - s; continue; }
        lt--;
        auto flag = us % 2 == 0;
        long L = 0;
        static if (DEBUG) writeln("\t", [s, t, us, lt]);
        L += X[flag][lt] - X[flag][us];
        static if (DEBUG) writeln("ADD ", X[flag][lt] - X[flag][us]);
        L += P[us] - s;
        static if (DEBUG) writeln("ADD ", P[us] - s);
        if ((lt - us) % 2 == 1) {
            L += t - P[lt];
            static if (DEBUG) writeln("ADD ", t - P[lt]);
        }
        Ans += (!swapped || (lt - us) % 2 == 1) ? L : (t - s) - L;
    }
    writeln(Ans);
}

Measured memory_bytes: 6188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll n;cin>>n;
    vector< pair<ll,ll> > a(n);
    for(ll i=1;i<=n;i++){
        ll x;cin>>x;
        a[i-1]=make_pair(x,i);
    }
    sort(a.begin(),a.end());
    for(auto &ele:a)cout<<ele.second<<" ";
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a;
    string s;
    cin>>a;
    cin>>s;
    if(a<3200)
    {
        cout<<"red\n";
    }
    else
    {
        cout<<s<<endl;
    }
}


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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


int main(){
  fastIO;
  int n;
  cin >> n;
  if(n == 3){
    cout << "2 5 63\n";
    return 0;
  }
  vector<int> t;
  int sum = 3;
  int id = 6;
  t.push_back(2);
  t.push_back(3);
  t.push_back(4);
  while(t.size() < n){
    if(id % 6 == 0 || id % 6 == 2 || id % 6 == 3 || id % 6 == 4){
      t.push_back(id);
      sum = (sum + id) % 6;
    }
    id++;
  }
  if(sum == 2){
    while(id % 6 != 4){
      id ++ ;
    }
    t[3] = id;
  }
  else if(sum == 3){
    while(id % 6 != 3){
      id ++ ;
    }
    t[3] = id;
  }
  else if(sum == 5){
    if(id % 6 == 4){
      t[1] = id;
    }
    else{
      while(id % 6 != 3){
        id ++ ;
      }
      t[0] = id;
    }
  }
  for(auto x : t)
    cout << x << " ";
  return 0;
}


Measured memory_bytes: 640
from collections import deque

n = int(input())
a = list(map(int, input().split()))
b = deque()

for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])

if n % 2 == 1:
    b.reverse()

print(*b)


Measured memory_bytes: 25412
from collections import defaultdict
n=int(input())
d={}
w=list(input())
d1=defaultdict(int)
num=len(w)
for i in range(num):
  d1[w[i]]+=1
for i in d1:
  d[i]=d1[i]
for i in range(n-1):
  w=list(input())
  d1=defaultdict(int)
  num=len(w)
  for i in range(num):
    d1[w[i]]+=1
  for j in d:
    if d[j]>d1[j]:
      d[j]=d1[j]
l=[]
for i in d:
  l.append(d[i]*i)
if l==[]:
  print("")
else:
  l=sorted(l)
  ans=""
  for i in l:
    ans+=i
  print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<string> s;
    for(int i=0; i<n; i++){
        string t;
        cin >> t;
        s.push_back(t);
    }
    sort(s.begin(),s.end());
    vector<pair<int,string>> pair;
    for(int i=0; i<n; ){
        string t = s[i];
        int cnt = 0;
        for(; i<n; i++){
            if(s[i] != t) break;
            cnt++;
        }
        pair.push_back(make_pair(cnt,t));
    }
    sort(pair.begin(),pair.end());
    int r = pair.size();
    int m = pair[r-1].first;
    int k=0;
    for(; k<r; k++){
        if(pair[k].first == m){
            break;
        }
    }
    for(; k<r; k++){
        cout << pair[k].second << endl;
    }

    return 0;
}


Measured memory_bytes: 18544
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
 
 
typedef long double ld;
typedef long long ll;
 
using namespace std;
 
ll MOD = ((ll)1e9 + 7);
 
struct mod {
	ll x;
 
	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}
 
	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}
 
	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}
 
	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}
 
	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}
 
	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}
 
	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}
 
	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}
 
	mod inv() const {
		return mypow(MOD - 2);
	}
 
	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}
 
	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}
 
	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};
 
ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}
 
/* TEMPLATE ENDS HERE */
 
#define MAXN (1 << 12)
#define INF (1 << 29)
 
int mem[MAXN];
int c[MAXN];
int u[MAXN];
int n, m;
 
int solve(int mask) {
	//cerr << mask << endl;
	if (mask == 0) {
		return 0;
	}
	int & ret = mem[mask];
	if (ret <= INF) {
		return ret;
	}
	ret = INF;
	for (int i = 0; i < m; i++) {
		int next = mask & (~u[i]);
		if (next == mask) {
			continue;
		}
		int nextcost = c[i] + solve(next);
		if (nextcost < ret) {
			ret = nextcost;
		}
	}
	return ret;
}
 
int main() {
	memset(mem, 63, sizeof(mem));
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int t;
		cin >> c[i];
		cin >> t;
		for (int j = 0; j < t; j++) {
			int tt;
			cin >> tt;
			tt--;
			u[i] |= (1 << tt);
		}
	}
	int ret = solve((1 << n) - 1);
	if (ret < INF) {
		cout << ret << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long int;

int main(){

    ll n;
    cin >> n;

    ll val = n / 1000;
    if (n % 1000 == 0){
        cout << 0 << endl;
    } else {
        cout << ((val + 1) * 1000 - n) << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())),reverse=True)
q=sorted(list(map(int,input().split())),reverse=True)
r=sorted(list(map(int,input().split())),reverse=True)
all=sorted(p[:x]+q[:y]+r,reverse=True)
print(sum(all[:x+y]))

Measured memory_bytes: 29360
def calc_sunuke(as, b)
  sum = 0
    as.length.times{|i|
      sum += (as[i]-(b+i+1)).abs
    }
  sum
end
n = gets.to_i
as = gets.split.map(&:to_i)

left = -as.max
right = as.max

while left+1 != right
  middle = (right + left)/2
  if calc_sunuke(as, middle) > calc_sunuke(as, middle+1)
    left = middle
  else
    right = middle
  end
end
puts [calc_sunuke(as, right), calc_sunuke(as, left)].min



Measured memory_bytes: 15884
#include<stdio.h>
#include<cstdlib>
#include<fstream>
#include<iostream>
#include<math.h>
#include<string>
#include<sstream>

using namespace std;

int main(){
    long N;
    cin >> N;
    long ans=N*(N-1)/2;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define Q int t, q; scanf("%d", &t); for(q=1; q<=t; q++)
typedef long long int lli;
#define pi pair<int, int>

int main()
{
    string s, t;
    cin >> t >> s;

    cout << s+t << "\n";


    return 0;
}


Measured memory_bytes: 256