akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>//for the sake of memset
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
int N,K,X,Y;
int main(){
	cin >> N >> K >> X >> Y;
	if(K < N)cout << K * X + (N-K) * Y <<endl;
	else cout << N * X <<endl;
	return 0;
}


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 100005
#define ALL(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
    //cin>>tt;
    while(tt--)
    {
		int a,b; cin>>a>>b;
		int i;
		for ( i = 1; i <1e5; i++)
		{
			if((i*8)/100 == a  and (i*10)/100 ==b) 
			{
				cout<<i;
				return 0;
			}				
		}
		cout<<-1;
		
		cout<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
N = int(input())
S = [input() for i in range(N)]
for i in range(N):
    S[i] = ''.join(sorted(S[i]))

dic = {}
for i in range(len(S)):
    if S[i] in dic: dic[S[i]] += 1
    else: dic[S[i]] = 1

ans = 0
for v in dic.values():
    ans += v * (v - 1) // 2
print(ans)


Measured memory_bytes: 19472
import java.util.*;

public class Main {
	static final long MOD = 1000000007;
	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextInt();
		int[] arr = new int[n];
		int[] cArr = new int[n];
		int[] tArr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (arr[i] < arr[j]) {
					tArr[i]++;
					if (i > j) {
						cArr[i]++;
					}
				}
			}
		}
		long total = 0;
		for (int i = 0; i < n; i++) {
			total += cArr[i] * k;
			if (k > 1) {
				total += tArr[i] * ((k - 1) * k / 2 % MOD);
			}
			total %= MOD;
		}
		System.out.println(total);
	}
}


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

using namespace std;

typedef long long ll;

char str[45][45];

ll f[45][45][45],g[45][45][45];

int main() {
  int n;
  scanf("%d",&n);
  n=2*n;
  for(int i=1;i<=n;i++) scanf("%s",str[i]+1);
  for(int i=1;i<n;i++) {
    f[i][i][i]=1;
    for(int j=i+1;j<=n;j++)
      if (str[i][j]=='1') g[i][i][j]=1;
  }
  for(int i=3;i<n;i+=2)
    for(int j=1;i+j<=n;j++) {
    	int k=i+j-1;
    	for(int l=j;l<=k;l+=2)
    	for(int r=k;r>l;r-=2) {
    		ll s=0;
    		for(int t=r;t<=k;t++) s+=g[j][l][t]*f[r][k][t];
    		for(int t=l+1;t<r;t++) f[j][k][t]+=f[l+1][r-1][t]*s;
		}
		for(int t1=j+1;t1<k;t1++)
		for(int t2=k+1;t2<n;t2++)
		  if (str[t1][t2]=='1') g[j][k][t2]+=f[j][k][t1];
	}
  ll ans=0;
  for(int i=1;i<n;i++)
    if (str[i][n]=='1') ans+=f[1][n-1][i];
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int N;
  cin>>N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }
  vector<bool> used(N,false);
  int index = 0;
  bool check = 0;
  int COUNT = 0;
  while(true)
  {

    if(used[index] == false)
    {
      used[index] = true;
      if(index == 1)
      {
        check = 1;
        break;
      }
      else
      {
        index = vec[index] -1;
      }

      COUNT++;
    }
    else
    {
      break;
    }
    
  }

  if(check == 1)
  {
    cout<<COUNT<<endl;
  }
  else
  {
    cout<<-1<<endl;
  }
  
  
  return; 
}


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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 1024
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> graph(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		graph[u].push_back(v);
	}
	int s, t;
	cin >> s >> t;
	s--;
	t--;
	vector<vector<int>> result(n, vector<int>(3, -3));
	result[s][0] = 0;
	queue<pair<int, int>> qu;
	qu.push(make_pair(s, 0));
	while (!qu.empty()) {
		int now = (qu.front()).first;
		int cost = (qu.front()).second;
		qu.pop();
		for (int i = 0; i < graph[now].size(); i++) {
			int next = graph[now][i];
			int nextcost = cost + 1;
			if (result[next][nextcost % 3] >= 0) continue;
			result[next][nextcost % 3] = nextcost;
			qu.push(make_pair(next, nextcost));
		}
	}
	cout << result[t][0] / 3 << endl;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define traceloop(x,a) {for(ll i=0;i<x;i++) cerr<<a[i]<<" "; cerr<<endl;}
ll ab(ll x) {return x>0LL?x:-x;}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n,k; 
	cin>>n>>k;
	vector<ll> v(n),dp(n,INT_MAX);
	for(int i=0; i<n; i++)
		cin>>v[i];
	dp[0]=0;
	for(ll i=0; i<n; i++)
	{
		for(ll j=i+1; j<=i+k; j++)
			if(j<n)
				dp[j] = min(dp[j],dp[i] + abs(v[i]-v[j]));
	}
	cout<<dp[n-1];
	return 0;
}
	

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

int main(){
    int n;
    cin>>n;
    vector<int> x(n);
    for (int i = 0; i < n; i++)
    {
        cin>>x[i];
    }
    int minval=10000000;
    for (int i = 0; i < 100; i++)
    {
        int sum=0;
        for (int j = 0; j < n; j++)
        {
            sum+=(x[j]-i)*(x[j]-i);
        }
      //cout<<sum<<endl;
        if (minval>sum)
        {
            minval=sum;
        }
      //cout<<minval<<endl;
        
    }
    cout<<minval;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n, ma, mb, inf = 0x3f3f3f3f, ans = 0x3f3f3f3f;
int a, b, p;
int dp[505][505];
int main() {
	scanf("%d%d%d", &n, &ma, &mb);
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	for(register int i = 1; i <= n; ++i) {
		scanf("%d%d%d", &a, &b, &p);
		for(register int j = 400; j >= a; --j) {
			for(register int k = 400; k >= b; --k) {
				if(dp[j][k] == 0) dp[j][k] = inf;
				dp[j][k] = min(dp[j - a][k - b] + p, dp[j][k]);
			}
		}
	}
	for(register int i = 1; i <= n && ma * i <= 400 && mb * i <= 400; ++i) {
		ans = min(dp[i * ma][i * mb], ans);
	}
	printf("%d", ans == 0x3f3f3f3f ? -1 : ans);
	return 0;
}

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

int insertionSort(int A[], int n, int g)
{
	int cnt = 0;
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
	return cnt;
}

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

	int cnt = 0;
	int m = 0;
	int nn = n;
	int G[100];

	while (nn > 0){
		m++;
		nn = nn/2;
	}

	for (int i = 0; i < m; i++)
	{
		G[i] = pow(2.0, m - i - 1);
		cnt += insertionSort(A, n, G[i]);
	}

	cout << m << endl;
	for (int i = 0; i < m; i++)
		cout << G[i] << " ";
	cout << endl;
	cout << cnt << endl;
	for (int i = 0; i < n; i++)
		cout << A[i] << endl;

	return 0;
}


Measured memory_bytes: 6980
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
vvl G;
vl dp(MAX_N);  // dp[v] : 人vに対応する頂点を根とした部分木のトーナメントの深さの最小値
 
void dfs(ll v) {
    vl x;  // vの子のdp値を入れる
    dp[v] = G[v].size();
    for(auto u : G[v]) {
        dfs(u);
        x.pb(dp[u]);
    }
    sort(rall(x));
    rep(i, G[v].size()) {
        chmax(dp[v], x[i] + i+1);
    }
}
 
int main() {
    ll n;
    cin >> n;
    
    G.resize(n);
    exrep(i, 1, n-1) {
        ll v;
        cin >> v;
        v--;
        G[v].pb(i);
    }

    dfs(0);
    
    out(dp[0]);
    re0;
}

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

int main() {
    std::string S, T;
    std::cin >> S >> T;

    int count = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != T[i]) {
            count++;
        }
    }
    std::cout << count << std::endl;
}


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

int choose2(int const &n) {
  return n * (n - 1) / 2;
}

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

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

  cout << choose2(n) + choose2(m) << endl;
  return 0;
}

Measured memory_bytes: 256
let nil = -1

type node = {
  mutable parent : int;
  mutable left : int;
  mutable right : int;
  mutable depth : int;
  mutable height : int;
}

let make () = { parent = nil; left = nil; right = nil; depth = nil; height = nil }

let search_root t n =
  let rec doit i =
    if i = n then nil
    else if t.(i).parent = nil then i
    else doit (i + 1) in
  doit 0

let set_depth t n =
  let rec doit i d =
    t.(i).depth <- d;
    if t.(i).left <> nil then doit t.(i).left (d + 1);
    if t.(i).right <> nil then doit t.(i).right (d + 1) in
  doit (search_root t n) 0

let set_height t n =
  let rec doit i =
    let hl = ref 0 in
    let hr = ref 0 in
    if t.(i).left <> nil then begin
      doit t.(i).left;
      hl := t.(t.(i).left).height + 1
    end;
    if t.(i).right <> nil then begin
      doit t.(i).right;
      hr := t.(t.(i).right).height + 1
    end;
    t.(i).height <- (max !hl !hr) in
  doit (search_root t n)

let print t =
  let sibling i =
    if t.(i).parent = nil then nil
    else if t.(t.(i).parent).left <> i && t.(t.(i).parent).left <> nil then t.(t.(i).parent).left
    else if t.(t.(i).parent).right <> i && t.(t.(i).parent).right <> nil then t.(t.(i).parent).right
    else nil in
  let degree i = 0 + (if t.(i).left <> nil then 1 else 0) + (if t.(i).right <> nil then 1 else 0) in
  t |> Array.iteri (fun i _ ->
    "node " ^ string_of_int i
    ^ ": parent = " ^ string_of_int t.(i).parent
    ^ ", sibling = " ^ string_of_int (sibling i)
    ^ ", degree = " ^ string_of_int (degree i)
    ^ ", depth = " ^ string_of_int t.(i).depth
    ^ ", height = " ^ string_of_int t.(i).height
    ^ (if t.(i).parent = nil then ", root"
       else if t.(i).left = nil && t.(i).right = nil then ", leaf"
       else ", internal node")
    ^ "\n"
    |> print_string)

let () =
  let n = read_int () in
  let t = Array.init n (fun _ -> make ()) in
  for _ = 0 to n - 1 do
    let (id, l, r) = Scanf.scanf "%d %d %d\n" (fun id l r -> (id, l, r)) in
    t.(id).left <- l;
    t.(id).right <- r;
    if l <> nil then t.(l).parent <- id;
    if r <> nil then t.(r).parent <- id;
  done;
  set_depth t n;
  set_height t n;
  print t

Measured memory_bytes: 2340
import java.util.*;

public class Main
{
    private final static Main main = new Main();

    public static void main(String[] args)
    {
        main.contest();
    }

    private void contest()
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(s.substring(0, 4) + " " + s.substring(4));
    }
}


Measured memory_bytes: 10188
// aoj-0003.cpp

#include <cstdio>

int main() {
	int i, j, temp;
	int sets, x, y, z;

	// read numbers of data sets
	scanf("%d", &sets);
	
	// read data set
	for (i=0; i<sets; ++i) {
		scanf("%d %d %d", &x, &y, &z);
		
		// sort x, y, z in ascending order
		if (x > y) {
			temp = x;
			x = y;
			y = temp;
		}
		if (y > z) {
			temp = y;
			y = z;
			z = temp;
		}
		
		if (((x * x) + (y * y)) == (z * z)) {
			puts("YES");
		} else {
			puts("NO");
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
def fun(n):
    if n%2 == 0:
        return n/2
    else:
        return 3 * n + 1

n = int(input())

m = 2
a = [n, ]

while fun(n) not in a:
    n = fun(n)
    a.append(n)
    m += 1
print(m)

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B;
    ll ans = 0;
    cin >> A >> B;
    repi2(i, A, B) {
        string temp = to_string(i);
        string temp2 = temp;
        reverse(temp2.begin(), temp2.end());
        if(temp == temp2) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3660
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    int n; LL k; int q; cin >> n >> k >> q;
    map<int, int> m;
    rep(i, q) {
        int a; cin >> a;
        a--;
        m[a]++;
    }
    vector<int> human(n, k);
    rep(i, n) {
        human[i] = human[i] - q + m[i];
    }
    rep(i, n) {
        if (human[i] <= 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }

    }
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define fi first
#define se second

using namespace std;

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

int main() {

  int H, W, N;
  cin >> H >> W >> N;

  vector< vector<char> > field(H, vector<char> (W));
  vector< pair<int, int> > factory(10, make_pair(-1, -1));
  
  rep(h, H) {
    rep(w, W) {
      cin >> field[h][w];
      if(field[h][w] == 'S') factory[0] = (make_pair(h, w));
      if(field[h][w] == '1') factory[1] = (make_pair(h, w));
      if(field[h][w] == '2') factory[2] = (make_pair(h, w));
      if(field[h][w] == '3') factory[3] = (make_pair(h, w));
      if(field[h][w] == '4') factory[4] = (make_pair(h, w));
      if(field[h][w] == '5') factory[5] = (make_pair(h, w));
      if(field[h][w] == '6') factory[6] = (make_pair(h, w));
      if(field[h][w] == '7') factory[7] = (make_pair(h, w));
      if(field[h][w] == '8') factory[8] = (make_pair(h, w));
      if(field[h][w] == '9') factory[9] = (make_pair(h, w));
    }
  }

  int res = 0;
  rep(cur, N) {
    int sh = factory[cur].fi;
    int sw = factory[cur].se;
    int gh = factory[cur+1].fi;
    int gw = factory[cur+1].se;

    queue< pair<int, int> > que;
    vector< vector<int> > dist(H, vector<int> (W, -1));
    dist[sh][sw] = 0;
    que.push({sh, sw});

    while(!que.empty()) {
      int vh = que.front().fi;
      int vw = que.front().se;
      que.pop();

      rep(dir, 4) {
        int nvh = vh + dy[dir];
        int nvw = vw + dx[dir];

        if(nvh < 0) continue;
        if(nvw < 0) continue;
        if(nvh >= H) continue;
        if(nvw >= W) continue;
        if(dist[nvh][nvw] != -1) continue;
        if(field[nvh][nvw] == 'X') continue;

        dist[nvh][nvw] = dist[vh][vw]+1;
        que.push({nvh, nvw});
      }
    }
    res += dist[gh][gw];
  }
  
  cout << res << endl;
}


Measured memory_bytes: 7772
#include<bits/stdc++.h>
using namespace std;
 
using lint = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a;
  	string s;
  	cin >> a;
  	cin >> s;
  	cout << (a < 3200 ? "red\n" : s);
}

Measured memory_bytes: 384
X, N = map(int, input().split())
P = [int(x) for x in input().split()]
cand = 1000
ans = -100
for t in range(-100, 121):
    if not(t in P):
        if abs(t-X) < cand:
            cand = abs(t-X)
            ans = t
print(ans)


Measured memory_bytes: 9176
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_9 1000000000
#define INF (numeric_limits<int>::max()/2)
#define int long long

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

int K, A, B;

int Ans() {
  if (B - A <= 2) {
    return 1 + K;
  }
  return 1 + (A - 1) + ((K - (A - 1))/2)*(B - A) + ((K - (A - 1))%2);
}

signed main() {
  cin >> K >> A >> B;

  int ans = Ans();

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


Measured memory_bytes: 256
///
// File:  dpl_1_c.cpp
// Author: ymiyamoto
//
// Created on Fri Dec 22 01:56:21 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main()
{
  int32_t N, W;
  cin >> N >> W;

  vector<pair<int32_t, int32_t>> items(N + 1);
  for (int32_t i = 1; i <= N; i++) {
    cin >> items[i].first;
    cin >> items[i].second;
  }

  vector<vector<uint32_t>> dp(N + 1, vector<uint32_t>(W + 1, 0));

  for (int32_t i = 1; i <= N; i++) {
    int32_t v = items[i].first;
    int32_t w = items[i].second;
    for (int32_t j = 0; j <= W; j++) {
      if (j - w >= 0) {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - w] + v);
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }

  cout << dp[N][W] << endl;

  return 0;
}

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

int n;
int a[200][200];

int sum(int x, int y, int X, int Y) {
  return a[y][x] - a[Y][x] - a[y][X] + a[Y][X];
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> a[i][j];
    }
  }

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

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

  int ans = -1001001001;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 0; k < i; ++k) {
        for (int l = 0; l < j; ++l) {
          ans = max(ans, sum(i, j, k, l));
        }
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3208
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
  
int main(){
  ll x;cin>>x;
  for(ll i=x;i<=1e10;i++)
  {
    if( IsPrime(i)==true)
    {
      cout<<i;
      break;
    }
  }
}

  

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

using namespace std;

const int MAX_N = 1000;

int n, h, w;

pair <int, int> a[MAX_N];

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> h >> w;
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i].first >= h && a[i].second >= w) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from math import gcd
A, B, C, D = map(int,input().split())

lcm = C*D // gcd(C,D)
a = (A-1)//C + (A-1)//D - (A-1)//lcm
b = B//C + B//D - B//lcm

print(B-A+1-b+a)

Measured memory_bytes: 62124
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    int temp1,temp2,i;
    for(i = 0;i < n;++i){
        cin >> temp1 >> temp2;
        ans += temp2-temp1+1;
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    string s; cin >> s;
    bool f = true;
    rep(i, s.size()) {
        if (s.substr(i, 2) != "hi") f = false;
        i++;
    }
    if (f) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    M = 61
    for i, a in enumerate(A):
        A[i] = list(map(int, str(format(a, 'b')).zfill(M)[::-1]))

    csum = [[0] * M for _ in range(N)]
    csum[0] = A[0]
    for i in range(1, N):
        for j in range(M):
            csum[i][j] = csum[i - 1][j] + A[i][j]

    p2 = [0] * M
    p2[0] = 1
    for i in range(M - 1):
        p2[i + 1] = p2[i] * 2 % MOD

    B = [0] * M
    for i, a in enumerate(A[1:], 1):
        for j in range(M):
            B[j] += csum[i - 1][j] if a[j] == 0 else i - csum[i - 1][j]

    ans = 0
    for j in range(M):
        ans = (ans + B[j] * p2[j]) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main() {
 string s;
  cin>>s;
  bool z=true;
  for(int i=0;i<s.size();i++){
    if((i+1)%2==1){
      if(s.at(i)=='L'){
        z=false;
      }
    }
    else{
      if(s.at(i)=='R'){
        z=false;
      }
    }
  }
  if(z){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int n;
int main(){
    while(true){
        cin >> n;
        if(!n) break;
        int num[n + 1];
        double avg = 0, a = 0;
        for(int i = 1; i <= n; ++i){
            cin >> num[i];
            avg += num[i];
        }
        avg /= n;
        for(int i = 1 ; i <= n; ++i){
            a += (num[i] - avg) * (num[i] - avg);
        }
        a /= n;
        a = sqrt(a);
        cout << fixed << setprecision(8) << a << endl;
    }
    return 0;
}


Measured memory_bytes: 3292
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};

in gcd(in a, in b) {return b != 0 ? gcd(b, a % b) : a;}//最大公約数

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in n,x;
    cin>>n>>x;
    vector<in> a(n);
        rep(i,n) cin>>a.at(i);
    vector<in> b(n);
        rep(i,n) b[i]=abs(x-a[i]);
    in ans=b[n-1];
    rep(i,n-1){
        ans=gcd(ans,b[i]);
    }
    cout<<ans<<endl;
}

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

int main() {
	int n,m;
	cin>>n>>m;
	if(n>=m)
	{
	    for(int i=0;i<n;i++)
	    {
	        cout<<m;
	    }
	}

	else
	{
	    for(int i=0;i<m;i++)
	    cout<<n;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int num,mx,mi;
    long long su = 0;
    cin >> num;
    for(int i = 0; i<num; i++) {
        int tmp;
        cin >> tmp;
        if(mi > tmp || i == 0) mi = tmp;
        if(mx < tmp || i == 0) mx = tmp;
        su += tmp;
    }
    cout << mi << " " << mx << " " << su << endl;

    return 0;
}



Measured memory_bytes: 3100
/*
g++ --std=c++17 A.cpp
*/

#include <iostream>
#include <iomanip> //! for setprecision(20)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;
using mint = static_modint<MOD>;

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

    int n, q;
    cin >> n >> q;
    dsu d(n);

    rep(i, q) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            d.merge(u, v);
        } else if (t == 1) {
            cout << (d.same(u, v) ? 1 : 0) << endl;
        }
    }

    return 0;
}


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

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);

    int a=Integer.parseInt(scan.next());
    int b=Integer.parseInt(scan.next());

    int s=a*b;
    int l=2*a+2*b;

    System.out.println(s+" "+l);
  }
}


Measured memory_bytes: 25996
#include<iostream>
#include<cstdlib>
#include<vector>
using namespace std;


class union_find{
    vector<int> set;
public:
    union_find(int size){ for(int i=0; i<size; i++)set.push_back(-1); }
    int find(int x);
    void unite(int x, int y);
    void printV();
    int getTreeSize(int x);
};
/* rootには木の高さに-1を掛けた値が入っている */


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

    union_find uf(n);

    int com, x, y;
    for(int i=0; i<q; i++){
        cin >> com >> x >> y;

        switch(com){
        case 0 :
            uf.unite(x, y);
            break; 
        case 1 :
            uf.find(x) == uf.find(y) ? cout << "1" : cout << "0";
            cout << endl;
            break;
        }
        // uf.printV();
    }

     return 0;
 }

 int union_find::find(int x)
 {
     if( !(x >= 0 && x < set.size()) ) exit(1);

     if( set.at(x) < 0){
         return x;
     }else{
         return (set.at(x) = find(set.at(x)));
     }

     // while( set.at(x) >= 0 ){
     //     x = set.at(x);
     // }
     // return x;
 }

 void union_find::unite(int x, int y)
 {
     int rootX, rootY;
     rootX = find(x);
     rootY = find(y);

     if( rootX == rootY ) return;

     if( set.at(rootX) < set.at(rootY) ){
         set.at(rootX) += set.at(rootY);
         set.at(rootY) = rootX;
     }else{
        set.at(rootY) += set.at(rootX);
        set.at(rootX) = rootY;
    }
 }

void union_find::printV()
{
    for(int i=0; i<set.size(); i++) cout << set.at(i) << " ";
    cout << endl;
}

int union_find::getTreeSize(int x)
{
    return set.at(find(x));
}

Measured memory_bytes: 1320
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
 

int main() {
  string s1 = "CODEFESTIVAL2016";
  string s2;
  cin >> s2;
  int cnt = 0;
  for (int i = 0; i < s1.size(); i++) {
    if (s1[i] != s2[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import collections
N,M = list(map(int,input().split()))
L=[]
def flatten(nested_list):
    return [e for inner_list in nested_list for e in inner_list]


for i in range(N):
  K = list(map(int,input().split()))
  K=K[1:]
  L.append(K)
# print(flatten(L))
cnter=collections.Counter(flatten(L))
print(len([i[0] for i in cnter.items() if i[1] >= N]))


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

#define MOD 1000000007
using namespace std;
using ll = long long;

vector<ll> fac, finv, inv;
void COMinit(int max, ll mod){
    fac.resize(max);
    finv.resize(max);
    inv.resize(max);

    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;
    }
}

ll COM(int n, int k, ll mod){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}


int main(void)
{
    ll X, Y;
    cin >> X >> Y;

    ll m = 2*Y - X;
    ll n = 2*X - Y;

    if(m <0 || m%3 != 0){
        cout << 0 << endl;
        return 0;
    }

    if(n <0 || n%3 != 0){
        cout << 0 << endl;
        return 0;
    }

    m = m/3;
    n = n/3;

    COMinit(2e6, MOD);

    cout << COM(m+n, n, MOD) << endl;

    return 0;
}


Measured memory_bytes: 50176
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	long long int n;
	cin >> n;
	vector<long long int> a(n);

	long long int MAX = 0;

	long long int ans = 0;

	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
		ans += a[i] - 1;
	}
	
	cout << ans << endl;
	return 0;
}

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

constexpr int INF = 1 << 29;

int N, M;
string d[10101];

int main() {
    cin >> N >> M;
    for (int j = 0; j < M; ++j) {
        cin >> d[j];
    }

    int w[10101];

    for (int j = 0; j < N; ++j) {
        int count = 0;
        for (int k = 0; k < M; ++k) {
            count += d[k][j] == 'W' ? 1 : 0;
        }
        w[j] = count;
    }


    int errs = 0; for (int j = 0; j < N; ++j) { errs += w[j]; }

    int ret = 0;
    int min_errs = errs;

    for (int j = 0; j < N; ++j) {
        errs += M-2*w[j];
        if (errs < min_errs) {
            min_errs = errs;
            ret = j+1;
        }
    }
    cout << ret << ' ' << ret+1 << endl;
    return 0;
}

Measured memory_bytes: 4716
#include<iostream>
#include<vector>
#include<cmath>

int main() {
	int n;
	int count;
	std::vector<int> d;

	std::cin >> n;

	int tmp;
	for(int i=0;i<n;i++){
		std::cin >> tmp;
		d.push_back(tmp);
	}
	count=0;
	int f;
	for(auto it=d.begin();it!=d.end();++it){
		f=0;
		for(int i=2;i<=(int)std::sqrt(*it) && f==0;i++){
			if(*it%i==0) f=1;
		}
		if(f==0) count++;
	}

	std::cout << count << std::endl;

	return 0;
}



Measured memory_bytes: 3188
#include<iostream>

using namespace std;

int main()
{
    int a,b,c;
    
    cin >> a >> b >> c;
    
    if (a < b && b <c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>
int main(void){
	int n,m,i,k,num,sum;
	scanf("%d %d",&n,&m);
	int a[n][m],b[m];
	for(i=0;i<n;i++){
		for(k=0;k<m;k++){
			scanf("%d",&a[i][k]);
		}
	}
	for(i=0;i<m;i++){
		scanf("%d",&num);
		b[i]=num;
	}
	for(i=0;i<n;i++){
		for(k=0;k<m;k++){
			a[i][k]*=b[k];
		}
	}
	for(i=0;i<n;i++){
		sum=0;
		for(k=0;k<m;k++){
			sum+=a[i][k];
		}
		printf("%d\n",sum);
	}
	return 0;
}


Measured memory_bytes: 1896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;


int main(){
  string s,t;
  cin >> s >> t;
  int len_s = s.size(); 
  int len_t = t.size();
  vector<vector<int>> dp(len_s+1,vector<int>(len_t+1,-1));
  for(int i=0;i<len_s;i++){
    for(int j=0;j<len_t;j++){
      if(s[i] == t[j]) dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+1);
      dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j]);
      dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j+1]);
    }
  }
  string ans;
  //復元
  while(len_s > 0 && len_t>0){
    //(i,j) -> (i-1,j)
    if(dp[len_s][len_t] == dp[len_s-1][len_t]) --len_s;
    //(i,j) -> (i,j-1)
    else if(dp[len_s][len_t] == dp[len_s][len_t-1]) --len_t;
    //(i,j) -> (i-1,j-1) 復元
    else/*if(dp[len_s][len_t] == dp[len_s-1][len_t-1])*/ {
      ans+=s[len_s-1];
      --len_s;
      --len_t;
    }
  }

  reverse(ans.begin(),ans.end());
  cout << ans.c_str() << endl;
}

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define FOR_EX(i, a, b) for (int i = a; i < b; i++)
#define FOR_IN(i, a, b) for (int i = a; i <= b; i++)

#define ALL(a) a.begin(), a.end()

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    string s, t;
    cin >> s >> t;
    s += s;
    cout << (s.find(t) != string::npos ? "Yes\n" : "No\n");
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    char s[130203];
    char t[130203];

    Scs(s);
    Scs(t);

    int N = strlen(s);
    int M = strlen(t);

    vector<set<int>> ss(2566);
    Rep(i,N){
        ss[s[i]].insert(i);
    }

    int tmp = 0;
    ll ans = 0;

    Rep(i,M){
        char tt = t[i];
        // printf ("%c\n", tt );
        auto it = ss[tt].upper_bound(tmp-1);
        // printf ("%d\n", *it );
        if( it == ss[tt].end() ){
            it = ss[tt].upper_bound(-1);
            ans += N;
            if( it == ss[tt].end() ){
                ans = -1;
                tmp = 0;
                break;
            }
        }
        tmp = *it;
        tmp++;
    }

    printf ("%lld\n", ans+tmp );


    return 0;
}



Measured memory_bytes: 5248
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
const ld RATE = 380000.0;
/*
*/
ll a,b,q;
vl s,t,xx;

ll findLowerShrineBoundary(ll val, ll l, ll r){
  if(l >= r) return -1;
  if(r-l == 1) {
    if(s[l] <= val) return l;
    else return -1;
  }
  if(s[(r+l)/2] == val) return (r+l)/2;
  if(s[(r+l)/2] < val) return findLowerShrineBoundary(val,(r+l)/2,r);
  if(s[(r+l)/2] > val) return findLowerShrineBoundary(val,l,(r+l)/2);
}

ll findLowerTempleBoundary(ll val, ll l, ll r){
  if(l >= r) return -1;
  if(r-l == 1) {
    if(t[l] <= val) return l;
    else return -1;
  }
  if(t[(r+l)/2] == val) return (r+l)/2;
  if(t[(r+l)/2] < val) return findLowerTempleBoundary(val,(r+l)/2,r);
  if(t[(r+l)/2] > val) return findLowerTempleBoundary(val,l,(r+l)/2);
}


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;
    cin >> a >>b >> q;
    ll temp;
    F0R(i,a) {cin >> temp; s.pb(temp);}
    F0R(i,b) {cin >> temp; t.pb(temp);}
    F0R(i,q){cin >> temp; xx.pb(temp);}
    F0R(i,q) {
      ll x;
      x = xx[i];
      ll slb = findLowerShrineBoundary(x,0,sz(s));
      ll tlb = findLowerTempleBoundary(x,0,sz(t));
      ll ans = INF;
      if(slb != -1 && tlb != -1){
        ans = min(ans,max(abs(x-s[slb]),abs(x-t[tlb])));
      }
      if(slb+1!=a && tlb+1!=b){
        ans = min(ans,max(abs(x-s[slb+1]),abs(x-t[tlb+1])));
      }
      if(slb != -1 && tlb+1!=b){
        ans = min(ans,abs(t[tlb+1]-x)+abs(s[slb]-t[tlb+1]));
      }
      if(slb+1 != a && tlb!=-1){
        ans = min(ans,abs(s[slb+1]-x)+abs(t[tlb]-s[slb+1]));
      }
      if(tlb != -1 && slb+1!=b){
        ans = min(ans,abs(t[tlb]-x)+abs(t[tlb]-s[slb+1]));
      }
      if(tlb+1 != a && slb!=-1){
        ans = min(ans,abs(s[slb]-x)+abs(s[slb]-t[tlb+1]));
      }
      cout << ans << endl;
    }


    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 3828
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

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

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
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
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	x, y := scanInt(), scanInt()
	if (4*x-y) >= 0 && (y-2*x) >= 0 && (4*x-y)%2 == 0 && (y-2*x)%2 == 0 {
		fmt.Fprintln(wr, "Yes")
	} else {
		fmt.Fprintln(wr, "No")
	}
}


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

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

typedef long long lint;

using namespace std;

int main(){
  lint N,K;
  cin>>N>>K;
  map<int,int> m;
  REP(i,N){
    int a,b;
    cin>>a>>b;
    m[a]+=b;
  }
  lint k=0;
  auto i=m.begin();
  while(k<K){
    // cout<<i->first<<" "<<i->second<<endl;
    k+=i->second;
    i++;
  }
  i--;
  cout<<i->first<<endl;
  return 0;
}


Measured memory_bytes: 3200
N, M = map(int, input().split())
root_list = [ [] for i in range(N) ]
check_list = [0 for i in range(N)]
ans_list = [0 for i in range(N)]

check_list[0] = 1

for m in range(M):
  A, B = map(int, input().split())
  A,B = A-1,B-1

  root_list[A].append(B)
  root_list[B].append(A)





this_order_check = [0]
this_order_check_next = []

now_ok = 0

def check(now_ok):
  for able in root_list[now_ok]:
    if check_list[able] == 0:
      check_list[able] = 1
      ans_list[able] = now_ok + 1
      this_order_check_next.append(able)

cnt = 0
while 0 in check_list:
  cnt += 1
  for now_ok in this_order_check:
    check(now_ok)
    this_order_check = this_order_check_next
  if cnt >= M:
    break

if 0 not in check_list:
  print('Yes')
  [print(i) for i in ans_list[1:]]
else:
  print('No')

Measured memory_bytes: 39816
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main(){
  int n; cin >> n;
  map<lint, lint> p, q;
  rep(i, n){
    lint m; cin >> m;
    p[m+i+1]++; q[i+1-m]++;
  }
  lint s = 0;
  for(auto r: p) if(q.count(r.fi)) s += r.se*q[r.fi];
  
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 26692
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
//int p = 998244353;
//int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
signed main() {
	int h, w, a, b; cin >> h >> w >> a >> b;
	rep(i, h + 1) {
		rep(j, w + 1) {
			if (a*i + (w - a)*(h - i) == b * j + (h - b)*(w - j)) {
				vel ex(w);
				rep(ind, j) { ex[ind] = b; }
				rep(ind, w - j) { ex[j + ind] = h - b; }
				vvel ans(h, vel(w,0));
				int count = 0;
				rep(ind, h) {
					int now_ex = a;
					if (i <= ind) { now_ex = w-a; }
					while (now_ex > 0) {
						if (ex[count] > 0) { ex[count]--; now_ex--; ans[ind][count] = 1; }
						count++;
						count %= w;
					}
				}
				rep(ind1, h) {
					rep(ind2, w) {
						cout << ans[ind1][ind2];
					}
					cout << endl;
				}
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 9088