akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
LL a, b, c, d, ans = -2e18;

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

	cin >> a >> b >> c >> d;
	ans = max(a * c, ans);
	ans = max(a * d, ans);
	ans = max(b * c, ans);
	ans = max(b * d, ans);
	cout << ans << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3640
n, m = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for i in range(2 ** n):
    for mi in range(m):
        on_count = 0
        for ni in range(n):
            if (i & (1 << ni)) and (ni + 1 in s[mi]):
                on_count += 1
        if on_count % 2 != p[mi]:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 200005
#define endl "\n"
#define mod 1000000007
ll n,m,st,des; vector<ll> vc[N]; ll fl[N];
vector<ll> an; ll br[N][3];
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	cin>>n>>m;

	for(i=1;i<=m;i++){
		cin>>k>>l;
		vc[k].ps(l);
	}
	cin>>st>>des;
	for(i=1;i<=n;i++){
		br[i][0]=br[i][1]=br[i][2]=0;
	}

	queue< pair<ll, pair<ll,ll> >> qe;
	qe.push({st,{0,0}});

	while(qe.size()>0){
		pair<ll, pair<ll,ll> > p=qe.front();
	//	cout<<p.fs<<" "<<p.sc.fs<<" "<<p.sc.sc<<endl;
		qe.pop();
		if(p.fs==des&&p.sc.fs==0){
			an.ps(p.sc.sc); continue;
		}
		if(br[p.fs][p.sc.fs]==1) continue;
		br[p.fs][p.sc.fs]=1;

		for(auto it:vc[p.fs]){
			if(p.sc.fs==0){
				qe.push({it,{2,p.sc.sc+1}});
			}
			else{
				qe.push({it,{p.sc.fs-1,p.sc.sc+1}});
			}
		}
	}

	ll mn=1e18;
	for(i=0;i<an.size();i++){
		if(an[i]%3==0){
			mn=min(mn,an[i]/3);
		}
	}
	if(mn==1e18) cout<<"-1";
	else cout<<mn;
	return 0;
}

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

zoro_count = 0
OK = False

for i in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        zoro_count += 1
        if zoro_count >= 3:
            OK = True
    else:
        zoro_count = 0

print("Yes" if OK else "No")


Measured memory_bytes: 62096
#include<iostream>                                        
using namespace std;                                      
                                                          
int main(){                                               
  int n,m,l;                                              
  cin >> n >> m >> l;                                     
  long gyoretu1[n][m] = {};                                
  long gyoretu2[m][l] = {};                                
  long gyoretu3[n][l] = {};                                
                                                          
  for(int i=0;i<n;i++){                                   
    for(int j=0;j<m;j++){                                 
      cin >> gyoretu1[i][j];                              
    }                                                     
  }                                                       
                                                          
  for(int i=0;i<m;i++){                                   
    for(int j=0;j<l;j++){                                 
      cin >> gyoretu2[i][j];                              
    }                                                     
  }                                                       
                                                          
  for(int i=0;i<n;i++){                                   
    for(int j=0;j<l;j++){                                 
      for(int k=0;k<m;k++){                               
        gyoretu3[i][j] += gyoretu1[i][k] * gyoretu2[k][j]\
;                                                         
      }                                                   
    }                                                     
  }                                                       
                                                          
  for(int i=0;i<n;i++){                                   
    for(int j=0;j<l;j++){                                 
      if(j)                                               
        cout << " ";                                      
      cout << gyoretu3[i][j];                             
    }                                                     
    cout << endl;                                         
  }

  return 0;
}            

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string a,b;
    cin>>a>>b;
    string x=a+b;
    int k=stoi(x);
    int y=sqrt(k);
    if(y*y==k)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
int main() 
{
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll n;
     cin>>n;
     ll a[n];
     for(int i=0;i<n;i++)
     cin>>a[i];
     set<int>s;
     for(int i=0;i<n;i++)
     s.insert(a[i]);
     if((int)s.size()==n)
     cout<<"YES"<<endl;
     else
     cout<<"NO"<<endl;
     
      
            
}


Measured memory_bytes: 11264
num = int(input())
address_list = [int(i) for i in input().split()]
meet_address_low = sum(address_list) // num
meet_address_high = meet_address_low + 1

diff_low = 0
diff_high = 0

for address in address_list:
    diff_low += (address - meet_address_low) ** 2
    diff_high += (address - meet_address_high) ** 2

print(min(diff_high, diff_low))

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func allAtoi(num []string) []int {
	conv := make([]int, len(num))
	for i, item := range num {
		conv[i], _ = strconv.Atoi(item)
	}
	return conv
}

func main() {
	RGBN := allAtoi(strings.Split(nextLine(), " "))
	R := RGBN[0]
	G := RGBN[1]
	B := RGBN[2]
	N := RGBN[3]
	// N = Rr + Gg + Bb
	ans := 0
	for r := 0; r <= N; r++ {
		Rr := R * r
		for g := 0; g <= N; g++ {
			Gg := G * g
			Bb := N - Rr - Gg
			if Bb >= 0 && Bb%B == 0 {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
N = int(input())
l = []
 
def kaijo(n):
    
    if n == 1:
        return n
    elif n == 0:
      return 1
    return n * kaijo(n-1)

for i in range(N):
  a = list(map(int, input().split()))
  l.append(a)
import numpy as np
l = np.array(l)
dist = []
for i in range(N):
  for j in range(i+1, N):
    dist.append(np.linalg.norm(l[i]- l[j]))
print(sum(dist)*2/N)

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

using ll = long long;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N), B(200001, -1), C(N);
    rep(i, N) {
        cin >> A[i];
        if (B[A[i]] == -1) {
            B[A[i]] = i;
        } else {
            C[B[A[i]]] = i;
            B[A[i]] = i;
        }
    }
    rep(i, N) {
        if (B[A[i]] == -1) {
            B[A[i]] = i;
        } else {
            C[B[A[i]]] = i;
            B[A[i]] = i;
        }
    }
    /* /rep(i, N) {
        cout << A[i] << " " << C[i] << endl;
    } */
    ll x = 0, y, d = 1;
    while (true) {
        y = C[x];
        if (y <= x) d++;
        if (y == N - 1) break;
        x = y + 1;
    }
    //cout << d << endl;
    ll l = K % d;
    if (l == 0) {
        cout << "" << endl;
        return 0;
    }
    ll ct = 0;
    x = 0;
    while (ct < l - 1) {
        y = C[x];
        if (y <= x) ct++;
        x = y + 1;
    }
    vector<ll> ans(0);
    while (x < N) {
        y = C[x];
        if (y > x) {
            x = y + 1;
        } else {
            ans.push_back(A[x]);
            x++;
        }
    }
    rep(i, ans.size()) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 7920
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#define rep(i,n) for (int i =0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(int argc, char const *argv[])
{
    /* code */
    int h, w;
    cin >> h >> w;
    int si, sj;
    cin >> si >> sj;
    int ti, tj;
    cin >> ti >> tj;
    --si; --sj; --ti; --tj;
    const int INF = 1e9;
    vector<string> s(h);
    rep(i,h) cin >> s[i];  // ベクターだと横文字一列を1文字ずつ分解してまとめて入れられるのか
    vector<vector<int>> dist(h, vector<int>(w,INF));  // この初期化方法調べる
    
    deque<P> q;
    dist[si][sj] = 0;
    q.emplace_back(si,sj);
    while (!q.empty())
    {
        int i = q.front().first;
        int j = q.front().second;
        q.pop_front();
        int d = dist[i][j];

        rep(v,4) {
            int ni = i+di[v], nj = j+dj[v];
            if (ni < 0|| ni >= h || nj < 0 || nj >= w) continue; // 枠外
            if (s[ni][nj] == '#') continue;
            if (dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(ni, nj); 
        }
        for (int ei = -2; ei <= 2; ++ei) {
            for (int ej = -2; ej <= 2; ++ej) {
                int ni = i+ei, nj = j+ej;
                if (ni < 0|| ni >= h || nj < 0 || nj >= w) continue; // 枠外
                if (s[ni][nj] == '#') continue;
                if (dist[ni][nj] <= d+1) continue;
                dist[ni][nj] = d+1;
                q.emplace_back(ni, nj);
            }
        }
    }
    int ans = dist[ti][tj];
    if (ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9488
//	Sha3ban_El-Bay
#include<bits/stdc++.h>
using namespace std ;
//======================================================
#define El_Bay ios_base::sync_with_stdio(false);cin.tie(NULL);
#define forn(i,n)  for (int i = 0; i < (int)(n); ++i)
#define for1(i,n)  for (int i = 1; i <=(int)(n); ++i)
#define all(v)     (v).begin(),(v).end()
#define ull        unsigned long long
#define PI         3.14159265359
#define ll         long long
#define sz(v)	   v.size()
#define pb         push_back
#define pp         pop_back
#define S          second
#define bgn        begin
#define F          first
#define N	100000+5
#define MOD	1e9+7
#define inf 1e18
//======================================================
int dx[] = { 0,  0, 1, -1 ,  1,  -1,  1,  -1 };
int dy[] = { 1, -1, 0,  0 , -1,   1,  1,  -1 };
//======================================================
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ull a, ull b, ull ret = 1LL) {
	while (b--) ret = (ret * a);
	return ret;}
//======================================================
ll n;
ll a[N];
ll dp[N];
ll Frog(int i)
{
	if(i>=n-1) return 0;
	if(dp[i]!=-1) return dp[i];
	ll c1=inf,c2=inf;
	if(i+1<n)c1=Frog(i+1)+abs(a[i]-a[i+1]);
	if(i+2<n)c2=Frog(i+2)+abs(a[i]-a[i+2]);
	return dp[i]=min(c1,c2);
}

int main()
{
	El_Bay
	cin >> n;
	for(int i=0 ; i<n ; i++)
		cin >> a[i];
	memset(dp,-1,sizeof dp);
	ll ans=Frog(0);
	cout << ans;
	return 0;
}


Measured memory_bytes: 9852
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> deg(n + 1, 0);
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        deg[x]++;
        deg[y]++;
    }
    for(int i = 1; i <= n; i++){
        cout << deg[i] << nl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>

using namespace std;
using ll = long long;
using ld = long double;

namespace NyaGadget
{

#define rep(i, begin, end) for (ll i = begin; i < end; i++)
#define size(collection) ((ll) (collection).size())
#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, v) fori(i, auto& e: v)

	struct Imos2D
	{	// 二次元IMOS法ライブラリ
		vector<vector<ll>> grid;

		Imos2D(ll w, ll h)
		{
			grid.resize(h + 1);
			each(i, e, grid)
				e.resize(w + 1);
		}

		void Add(ll hmin, ll hmax, ll wmin, ll wmax, ll v)
		{
			grid[hmin][wmin] += v;
			grid[hmin][wmax + 1] -= v;
			grid[hmax + 1][wmin] -= v;
			grid[hmax + 1][wmax + 1] += v;
		}

		void Update(void)
		{
			rep(i, 0, size(grid))
			{
				rep(j, 1, size(grid[i]))
					grid[i][j] += grid[i][j - 1];
			}
			rep(i, 1, size(grid))
			{
				rep(j, 0, size(grid[i]))
					grid[i][j] += grid[i - 1][j];
			}
		}
	};

#undef rep
#undef size
#undef fori
#undef each

}

#define all(collection) (collection).begin(), (collection).end()              // begin to end
#define divc(a, b) ceil((ld) a / (ld) b);                                     // div ceiling
#define rep(i, begin, end) for (ll i = begin; i < end; i++)                   // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)                  // repeat reverse
#define size(collection) ((ll) (collection).size())                           // collection size
/********** for each macro **********/
#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, v) fori(i, auto& e: v)
#define forir(i, ...) if(ll i = size(v)) for(__VA_ARGS__) if(i--, true)
#define eachr(i, e, v) forir(i, auto& e: boost::adaptors::reverse(v))

using namespace NyaGadget;

struct Range
{
	ll l;
	ll r;
};

int main(void)
{
	ll N, M, Q; cin >> N >> M >> Q;

	vector<Range> train(M);
	each(i, e, train)
	{
		cin >> e.l >> e.r;
		e.l--; e.r--;
	}

	vector<Range> query(Q);
	each(i, e, query)
	{
		cin >> e.l >> e.r;
		e.l--; e.r--; 
	}

	Imos2D imos(N, N);
	each(i, e, train)
		imos.Add(0, e.l, e.r, N - 1, 1);

	imos.Update();
	each(i, e, query)
		cout << imos.grid[e.l][e.r] << endl;

	return 0;
}


Measured memory_bytes: 7552
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a, x, dp[6000], dpbuf[6000];

int main(){
	cin >> n >> a;
	
	memset(dp, 0, sizeof(dp));
	ll zero = 3000;
	dp[zero] = 1;
	ll ans = 0;
	for(ll i = 1; i <= n; i++){
		cin >> x;
		x -= a;
		
		memset(dpbuf, 0, sizeof(dpbuf));
		for(ll j = 0; j < 6000; j++){
			if(dp[j] != 0){
				dpbuf[j] += dp[j];
				dpbuf[j+x] += dp[j];
			}
		}
		
		for(ll j = 0; j < 6000; j++){dp[j] = dpbuf[j];}
	}
	
	cout << dp[zero]-1 << endl;
	return 0;
}

Measured memory_bytes: 384
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var t string
	fmt.Fscan(read, &t)
	s, _ := strconv.Atoi(t)

	b1, b2 := false, false

	y, m := s/100, s%100
	if 1 <= m && m <= 12 {
		b1 = true
	}
	y, m = m, y
	if 1 <= m && m <= 12 {
		b2 = true
	}

	if b1 {
		if b2 {
			fmt.Fprintln(write, "AMBIGUOUS")
		} else {
			fmt.Fprintln(write, "YYMM")
		}
	} else {
		if b2 {
			fmt.Fprintln(write, "MMYY")
		} else {
			fmt.Fprintln(write, "NA")
		}
	}
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=5e5+10;
const ll MOD=1e9+7;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
ll A(ll n,ll m){
    return factor[n]*qpow(factor[n-m],MOD-2)%MOD;
}
void solve()
{   
    int N,M;
    cin>>N>>M;
    cal_factor();
    ll sgn=1;
    ll ans=0;
    for(int u=0;u<=N;u++){
        ans=(ans+sgn*C(N,u)*A(M,u)%MOD*A(M-u,N-u)%MOD*A(M-u,N-u)%MOD+MOD)%MOD;
        sgn*=-1;
    }
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 7564
k,n = map(int, input().split())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
for i in range(0,n-1):
  b[i] = a[i+1] -a[i]

b[n-1] = k - a[n-1] + a[0]
ans = k - max(b)
print(int(ans))

Measured memory_bytes: 26420
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int ans = 1;
		int a = sc.nextInt();
		if (a == 0 ) System.out.println(ans);
		int b = sc.nextInt();
		ans++;
		if (b == 0 ) System.out.println(ans);
		ans++;
		int c = sc.nextInt();
		if (c == 0 ) System.out.println(ans);
		ans++;
		int d = sc.nextInt();
		if (d == 0 ) System.out.println(ans);
		ans++;
		int e = sc.nextInt();
		if (e == 0 ) System.out.println(ans);


		sc.close();
	}
}


Measured memory_bytes: 27000
#!/usr/bin/env python3
import sys
import fractions, math
from functools import reduce

def solve(K: int):
    counter = 0
    L = [0] * 201
    for i in range(1, K+1):
        for j in range(1, K+1):
            L[math.gcd(i, j)] += 1
    for i in range(1, K+1):
        for j in range(1, K+1):
            counter += math.gcd(i, j) * L[j]
    print(counter)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()

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

int check_S(int n, const char S[200])
{
    int i;
    int check = 0;
    for(i = 0; i < n / 2 - 1; i++){
        if(S[i] != S[n / 2 + i]){
            check = 1;
        }
    }

    return check;
}

void put_ans(int n)
{
    printf("%d\n", n);
}

int main()
{
    char S[200] = {'\0'};
    int n;
    int i;
    int check = 0;

    scanf("%s", S);


    for(i = 0; S[i]; i++){
        ;
    }
    n = i;

    if(n % 2 == 1){
        n--;
    }
    else{
        n -= 2;
    }


    while(check_S(n, S) == 1){
        n -= 2;
    }
    put_ans(n);

    return 0;
}

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

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

  int64_t N;
  cin >> N;
  int64_t A[N];
  rep(i, N){
    cin >> A[i];
  }
  int64_t sum[N], sum1[N];
  sum[0] = A[0];
  sum1[0] = A[0];
  for(int i=1;i<N;i++){
    sum[i] = sum[i-1] + A[i];
    sum1[i] = sum[i];
  }
  int64_t dif = {};
  int64_t val = 1;
  int64_t ans1 = {};
  for(int i=0;i<N;i++){
    val *= -1;
    sum[i] += dif;

    if(sum[i] * val > 0) continue;
    ans1 += abs(val - sum[i]);
    dif += val - sum[i];
  }

  int64_t ans2 = 0;
  dif = 0;
  val = -1;
  for(int i=0;i<N;i++){
    val *= -1;
    sum1[i] += dif;

    if(sum1[i] * val > 0) continue;
    ans2 += abs(val - sum1[i]);
    dif += val - sum1[i];
  }

  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 2560
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

func main() {
	h, n := scanInt(), scanInt()
	a := scanInts(n)
	answer := canWin(h, a)
	fmt.Println(answer)
}

func canWin(h int, a []int) string {
	s := 0
	for _, v := range a {
		s += v
	}
	debug(s)
	if h <= s {
		return "Yes"
	}
	return "No"
}

func debug(a ...interface{}) {
	// fmt.Println(a...)
}


Measured memory_bytes: 1920
// A Naive recursive C++ program to find minimum of coins 
    // to make a given change V 
    #include<bits/stdc++.h> 
    using namespace std; 
    int main()
    {
        int n,d;
        cin>>n>>d;
        int a[n][d];
        
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<d;j++)
            {
                cin>>a[i][j];
            }
        }
        int count1=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                
                    int dis=0;
                    for(int k=0;k<d;k++)
                    {
                        dis+=(a[i][k]- a[j][k]) * (a[i][k]- a[j][k]);
                    }
                    // cout<<dis<<endl;
                    double f=sqrt(dis);
                    if(ceil(f)==floor(f))
                     count1++;
            }
        }
        cout<<count1<<endl;
    }

Measured memory_bytes: 256
#input
N = int(input())

#output
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

print(num2alpha(N).lower())

Measured memory_bytes: 9168
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

using ll = long long int;

int main(void){

	ll h,w;
	cin >> h >> w;

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

	ll result = 100010;

	for(int i = 0; i < h; i++){
		ll a = i * w;
		ll b = h*w - a;
		ll c;
		
		if(b % 2 == 0){
		    b /= 2;
		    c = b;
		}else{
		    b = max((h-i),w)/2 * min((h-i),w);
		    c = (max((h-i),w)+1)/2 * min((h-i),w);
		}
		
		//cout << a << " " << b << " " << c << endl;

		result = min(result,max({a,b,c}) - min({a,b,c}));

	}

	for(int i = 0; i < w; i++){
		ll a = i * h;
		ll b = h*w - a;
		ll c;
		
		if(b % 2 == 0){
		    b /= 2;
		    c = b;
		}else{
		    b = max((w-i),h)/2 * min((w-i),h);
		    c = (max((w-i),h)+1)/2 * min((w-i),h);
		}
		result = min(result,max({a,b,c}) - min({a,b,c}));

	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
	int A, B, C;	cin >> A >> B >> C;
	if (A >= B && A >= C) {
		cout << A * 10 + B + C << endl;
		cin >> A;
		return 0;
	}
	if (B >= A && B >= C) {
		cout << B * 10 + A + C << endl;
		cin >> A;
		return 0;
	}
	if (C >= A && C >= B) {
		cout << C * 10 + A + B << endl;
		cin >> A;
		return 0;
	}
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double dur = h + m / 60.0;
    double xa = a * cos(dur/12 * 2 *M_PI);
    double ya = -a * sin(dur/12 * 2 *M_PI);
    double xb = b * cos(dur * 2 *M_PI);
    double yb = -b * sin(dur * 2 *M_PI);
    double ans = sqrt((xa -xb) * (xa -xb) + (ya-yb) * (ya-yb));
    printf("%6.10f\n", ans);
    return 0;
}


Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);

    while(b != 0){
        ll t = a;
        a = b;
        b = t%b;
    }

    return a;
}

int main(){
    int N; cin >> N;
    vector<ll> t(N);
    for(int i=0; i<N; i++) cin >> t[i];
    ll ans = t[0];

    for(int i=1; i<N; i++){
        ans = t[i]/gcd(t[i], ans)*ans;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int N, K, n = 1;
	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		if (n < K)
			n = n * 2;
		else
			n += K;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
import math
now_r=0
now_x=0
now_y=0

while True:
    n,r=map(int,raw_input().split(","))
    if n==0 and r==0:
        break
    now_x+=n*math.sin((now_r/180.0)*math.pi)
    now_y+=n*math.cos((now_r/180.0)*math.pi)
    now_r+=r
print int(now_x)
print int(now_y)

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

class Vector2{
public:
	Vector2() : x( 0 ), y( 0 ){}
	Vector2( double x, double y ){
		this->x = x;
		this->y = y;
	}

	double dot( Vector2& a ){
		return ( x * a.x ) + ( y * a.y );
	}

	double x, y;
};

int main(){
	Vector2 a, b, c, d;

	while ( cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> d.x >> d.y ){
		Vector2 ab( b.x - a.x, b.y - a.y ), cd( d.x - c.x, d.y - c.y );

		if ( !ab.dot( cd ) ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;

ll f(ll n){
  n++;
  return ((n/2)%2)^((n-1)*(n%2));
}

int main(int argc, const char * argv[]) {
  ll A, B; cin >> A >> B;
  cout << (f(B)^f(A)^A) << endl;
  return 0;
}

Measured memory_bytes: 256
N,K,Q = map(int,input().split())
A_s = {i+1:0 for i in range(N)}
for _ in range(Q):
    A_s[int(input())] += 1
for k,v in A_s.items():
    if K-(Q-v) <= 0:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 56932
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
//#define min(a, b, c) min(a, min(b, c))
//#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
set<ll> s;
vll v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	vector<ll> p(n+2);
	temp=m;
	while(m--)
	{
	    cin>>a>>b;
	    p[a]++;
	    p[b+1]--;
	}
	m=temp;
	for(int i=1;i<=n;i++)
	{
	    p[i]+=p[i-1];
	}
	cout<<count(m,p);
}

Measured memory_bytes: 1024
from collections import deque

N,Q = map(int, input().split())
g,q,s,c,d = [[] for i in range(N)],[0]*N,[False]*N,[0]*N,deque()

for _ in range(N-1):
	a,b = map(lambda x: int(x)-1, input().split())
	g[a].append(b)
	g[b].append(a)

for _ in range(Q):
	p,x = map(int, input().split())
	q[p-1] += x

d.append(0)
while d:
	v = d.popleft()
	s[v] = True
	for x in g[v]:
		if not s[x]:
			d.append(x)
			q[x] += q[v]

print(' '.join(map(str,q)))

Measured memory_bytes: 148536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC177C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] Ainput = Console.ReadLine().Split(' ');
            long[] A = new long[N];
            long sum = 0;
            long mod = 1000000007;
            for(int i = 0; i < N; i++)
            {
                A[i] = long.Parse(Ainput[i]);
                sum += A[i];
                sum %= mod;
            }
            long[] wa = new long[N];
            for(int i = 0; i < N; i++)
            {
                wa[i] = sum + mod - A[i];
                wa[i] %= mod;
            }
            long ans = 0;
            for(int i = 0; i < N; i++)
            {
                ans += A[i] * wa[i];
                ans %= mod;
            }
            if (ans % 2 == 0)
            {
                Console.WriteLine(ans / 2);
            }
            else
            {
                Console.WriteLine((ans+mod) / 2);
            }
            

        }
    }
}


Measured memory_bytes: 48524
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n;cin>>n;
	vector<int> a(1<<n),ma(n),ans(n);
	vector<pair<int,int>> max(1<<n,make_pair(0,0));
	for(int i=0;i<(1<<n);i++){
		cin>>a[i];
		max[i].first=a[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<(1<<n);j++){
			if(j&(1<<i)){
				vector<int> v(4);
				v[0]=max[j].first;
				v[1]=max[j].second;
				v[2]=max[j^(1<<i)].first;
				v[3]=max[j^(1<<i)].second;
				sort(v.begin(),v.end(),greater<int>());
				max[j].first=v[0];
				max[j].second=v[1];
			}
		}
	}
	int summax=0;
	for(int i=1;i<(1<<n);i++){
		int sum=max[i].first+max[i].second;
		if(summax<sum)summax=sum;
		cout<<summax<<endl;
	}

	return 0;
}

Measured memory_bytes: 6144
#include <stdio.h>

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;

void CAttackSurvival(std::istream& in, std::ostream& out) {
  int n, k, q;
  in >> n >> k >> q;
  vector<int> score;
  for (int i = 0; i < n; ++i) {
    score.push_back(k - q);
  }
  for (int i = 0; i < q; ++i) {
    int x;
    in >> x;
    score[x - 1]++;
  }
  for (int i = 0; i < n; ++i) {
    out << ((score[i] > 0) ? "Yes\n" : "No\n");
  }
}

int main(int argc, char** argv) { CAttackSurvival(cin, cout); return 0; }


Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  bool p = (abs(a-b)<=d)&&(abs(b-c)<=d);
  bool q = abs(a-c)<=d;
  if(p||q){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int A, B, check[4];

int main(void) {

	cin >> A >> B;

	check[A] = 1;
	check[B] = 1;

	for (int i = 1; i <= 3; i++) {
		if (check[i] == 0) { cout << i << endl; }
	}

	return 0;
}

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

int main(){
	double x1,y1,x2,y2;
	scanf("%lf %lf %lf %lf", &x1,&y1,&x2,&y2);
	printf("%.8lf\n", sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}


Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N;
	cin >> N;
	vector<int> card(N);
	ll sunu = 0, arai = 0;
	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		card[i] = a;
		arai += a;
	}
	ll dif = 1e18;
	for (int i = 0; i < N-1; i++)
	{
		sunu += card[i];
		arai -= card[i];
		dif = min(dif, abs(sunu-arai));
	}
	cout << dif << endl;
}


Measured memory_bytes: 1024
surface = gets.split.map(&:to_i)
throw = {E: [3, 2, 6, 1, 5, 4], N: [5, 1, 3, 4, 6, 2],
         S: [2, 6, 3, 4, 1, 5], W: [4, 2, 1, 6, 5, 3]}
th = {}
throw.each_key {|k| th[k] = throw[k].map(&:pred)}
gets.to_i.times do
  top, front = gets.split.map(&:to_i).map {|x| surface.find_index(x)}
  stack = []
  dice = [*0..5]
  loop do
    [:E, :N, :S, :W].each {|d| stack << [dice, d]}
    dice, dir = stack.shift
    next_dice = Array.new(6, 0)
    dice.each_with_index do |d, i|
      next_dice[th[dir][i]] = d
    end
    if next_dice[0] == top and next_dice[1] == front
      puts surface[next_dice[2]]
      break
    else
      dice = next_dice
    end
  end
end



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

long long A, B, C;
long long K;

int main(){
	cin >> A >> B >> C >> K;

	while(B <= A) {
		B *= 2;
		K--;
	}

	while(C <= B) {
		C *= 2;
		K--;
	}

	if(K >= 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

}



Measured memory_bytes: 3592
#include <stdio.h>

struct DICE{      // struct
    int ue;
    int temae;
    int migi;
    int hidari;
    int oku;
    int shita;
};

void fancDice(char *direct, struct DICE *diceStr) {     // original_function
    int temp;
    switch (*direct) {
        case 'E':
            temp = diceStr->ue;
            diceStr->ue = diceStr->hidari;
            diceStr->hidari = diceStr->shita;
            diceStr->shita = diceStr->migi;
            diceStr->migi = temp;
            return;
        case 'S':
            temp = diceStr->ue;
            diceStr->ue = diceStr->oku;
            diceStr->oku = diceStr->shita;
            diceStr->shita = diceStr->temae;
            diceStr->temae = temp;
            return;
        case 'W':
            temp = diceStr->ue;
            diceStr->ue = diceStr->migi;
            diceStr->migi = diceStr->shita;
            diceStr->shita = diceStr->hidari;
            diceStr->hidari = temp;
            return;
        case 'N':
            temp = diceStr->ue;
            diceStr->ue = diceStr->temae;
            diceStr->temae = diceStr->shita;
            diceStr->shita = diceStr->oku;
            diceStr->oku = temp;
            return;
    }
    return;
}

int main() {            // main
    char *directStr;
    int jud = 0;        // 0:No 1:Yes
    
    struct DICE diceStr1;
    scanf("%d", &diceStr1.ue);
    scanf("%d", &diceStr1.temae);
    scanf("%d", &diceStr1.migi);
    scanf("%d", &diceStr1.hidari);
    scanf("%d", &diceStr1.oku);
    scanf("%d", &diceStr1.shita);
    
    struct DICE diceStr2;
    scanf("%d", &diceStr2.ue);
    scanf("%d", &diceStr2.temae);
    scanf("%d", &diceStr2.migi);
    scanf("%d", &diceStr2.hidari);
    scanf("%d", &diceStr2.oku);
    scanf("%d", &diceStr2.shita);
    
    for (int i=0; i<6; i++) {
        if (i % 2 == 0) {
            directStr = "W";
        } else {
            directStr = "S";
        }
        fancDice(directStr, &diceStr2);
        
        for (int j=0; j<4; j++) {
            if (diceStr1.ue == diceStr2.ue) {
                if (diceStr1.temae == diceStr2.temae) {
                    if (diceStr1.migi == diceStr2.migi) {
                        if (diceStr1.hidari == diceStr2.hidari) {
                            if (diceStr1.oku == diceStr2.oku) {
                                if (diceStr1.shita == diceStr2.shita) {
                                    jud = 1;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (diceStr1.ue == diceStr2.ue) {
                directStr = "WSE";
                for (int k=0; directStr[k]!='\0'; k++) {
                    fancDice(&directStr[k], &diceStr2);
                }
            }
        }
        if (jud == 1) {break;}
    }
    if (jud == 1) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}


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

using namespace std;

#define ll long long
#define ld long double
#define ii pair<int ,int>
#define vi vector<ll>
#define vii vector<ll, ll>
#define fo(i,a,n) for(int i = (a); i < (n); i++)
#define pb push_back
#define newl cout<<"\n"
#define mp make_pair
#define f first
#define s second
#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);


const ll MOD=1e+9+7;
const ll MAXN=1e+5+7;
const ll INF=1e+18;
const ll MINF=-1e+18;
//ll t;

//vector<ll> adj[MAXN];
//set<ll> adj[MAXN];
//int visited[MAXN]={};
//int st[4*MAXN + 7]={};


//------Program Start------//

char s[MAXN], t[MAXN];
ll ns, nt, hold, res=0;
vector<int> a[26];

int main(){
	fastio

	cin>>s>>t;
	ns=strlen(s); nt=strlen(t);

	fo(i,0,ns) a[s[i]-'a'].pb(i+1);

	fo(i,0,nt){
		if(a[t[i]-'a'].size()==0){
			cout<<-1;
			return 0;
		}
	}

	ll prev=0;
	fo(i,0,nt){
		hold=upper_bound(a[t[i]-'a'].begin(), a[t[i]-'a'].end(), prev)-a[t[i]-'a'].begin();

		if(hold!=a[t[i]-'a'].size()){
			res+=a[t[i]-'a'][hold]-prev;
			prev=a[t[i]-'a'][hold];
		}
		else{
			res+=ns-prev;
			prev=0;
			i--;
		}
	}

	cout<<res;



}


Measured memory_bytes: 1148
n,m = gets.split.map &:to_i; a = Array.new(n); k = 0
n.times do |i|
  a[i] = gets.split.map &:to_i
  a[i].shift
end
1.upto(m) do |i|
  k += 1 if a.all?{|e| e.include?(i)}
end
puts k


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <string>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char const *argv[])
{
    int n, m; cin >> n >> m;
    vector<tuple<long long, int, int> > ward(m);
    int p; long long y; int idx;
    for(int i=0;i<m;++i) {
        cin >> p >> y;
        ward[i] = make_tuple(y, p, i);
    }

    vector<int> pcount(n+1, 0);
    vector<string> z(m);
    sort(ward.begin(), ward.end());

    std::ostringstream sout;
    sout << std::setfill('0') << std::setw(6);

    for(int i=0;i<m;++i) {
        std::string s = sout.str();        
        p = get<1>(ward[i]);
        idx = get<2>(ward[i]);
        pcount[p] += 1;
        //cout << idx << " " << p << " " << pcount[p] << endl;


        sout.str(""); sout << std::setfill('0') << std::setw(6);
        sout << p;
        z[idx] = sout.str();
        sout.str(""); sout << std::setfill('0') << std::setw(6);
        sout << pcount[p];
        z[idx] += sout.str();
    }

    for(auto s: z) {
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 8960
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e7+2;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    int n;
    cin>>n;
    ll a[n],x=1,y=0;
    lp(i,0,n){
        cin>>a[i];
    }
    sort(a,a+n);
    if(a[0]==0)
        return cout<<0,0;
    lp(i,0,n){
        if(log10(a[i])+log10(x)+1>19){
            return cout<<-1,0;
        }
        x*=a[i];
    }
    if(x>(ll)1e18)
        x=-1;
    cout<<x;
}

Measured memory_bytes: 4700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    ll n,m;
    cin >> n >> m;
    
    vector<vector<ll>> cake(n,vector<ll>(3));
    REP(i,n){
        REP(j,3){
            cin >> cake[i][j];
        }
    }

    uint send = pow(2,3)-1;
    ll ans = 0;
    for(uint i = 0; i <= send ;i++){
        vector<ll> tmplist;
        ll tmp_max = 0;
        REP(j,n){
            ll tmp = 0;
            for(uint k = 1,idx = 0; k <= send; k*= 2){
                if( i & k){
                    tmp -= cake[j][idx];
                }
                else{
                    tmp += cake[j][idx];
                }
                idx++;
            }
            tmplist.push_back(tmp);
        }
        sort(all(tmplist),greater<ll>());
        REP(j,m){
            tmp_max += tmplist[j];
        }
        if(tmp_max >= ans){
            ans = tmp_max;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}



/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n,m;
  	ci(n>>m);
  ll ans=0;
  FOR(i,n,m+1){
    ll a=i;
    if(a%10==a/10000){
     
	a/=10;
    a=a%1000;
      
    if(a%10==a/100){
      ans++;
    }
    }
  }
  co(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main()
{
    ll ans = 1;
    ll a;
    double b;
    cin >> a >> b;
    // ll ib = b * 100;としてしまうと、llへのキャストが行われ(キャストが行われると切り捨てられる)、bが1.17999のような値だった場合117になる
    ll ib = b * 100 + 0.5;
    ans = a * ib / 100;
    cout << ans << endl;
}

Measured memory_bytes: 3724