akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int gcd(int x, int y)
{
	while(x != 0){
		y %= x;
		if(y == 0) return x;
		x %= y;
	}
	return y;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for(int i = 0 ; i < n; i++) cin >> a[i];
	int g = a[0], mx = a[0];
	for(int i = 1; i < n; i++) {
		g = gcd(g, a[i]);
		mx = max(mx, a[i]);
	}
	if(n == 1) {
		if(a[0] == k) cout << "POSSIBLE" << endl;
		else cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	else{
		if( k % g == 0 && k <= mx) cout << "POSSIBLE" << endl;
		else cout << "IMPOSSIBLE" << endl;
	}
	return 0;	
}
  

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

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

int main() {
  int n;
  cin >> n;
  int min = 200001;
  int tmp = 0;
  int count = 0;
  rep(i, n) {
    cin >> tmp;
    if (tmp <= min) {
      count++;
      if (tmp < min) min = tmp;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b&&b<c)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 2608
#include <bits/stdc++.h>
#define SIZE 10
#define PI 3.141592653589793

using namespace std;
typedef long long ll;

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

	int i,j;
	int answer=0;
	int counter=0;
	double sum=0;
	double N,M;
	double tmp;
	vector<int> given;

	cin >> N >> M;

	for(i=0;i<N;i++){
		cin >> tmp;
		sum+=tmp;
		given.push_back(tmp);
	}

	for(i=0;i<N;i++)
		if(sum/(4*M) <= given[i]) counter++;

	if(counter<M)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}



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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> is_open(n, vector<int>(10));
    vector<vector<int>> profits(n, vector<int>(11));
    for (auto &v: is_open) {
        for (auto &f: v) cin >> f;
    }
    for (auto &v: profits) {
        for (auto &p: v) cin >> p;
    }
    int ans = - 1e9;
    for (int b = 1; b < 1<<10; b++) {
        int ans_temp = 0;
        for (int i = 0; i < n; i++) {
            int cnt = 0;
            for (int j = 0; j < 10; j++) {
                if ((b>>j & 1) && is_open[i][j]) cnt++;
            }
            ans_temp += profits[i][cnt];
        }
        ans = max(ans, ans_temp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		
		int n; in >> n;

		string str1; 
		string str2; 
		in >> str1 >> str2;


		if (str1 == str2)
		{
			out << n;
			return;
		}


		int mx = 0;

		for (int l = 1; l < str1.size(); l++)
		{
			int idx = 0;
			int cnt = 0;
			for (int i = str1.size() - l; i < str1.size(); i++)
			{
				if (str1[i] == str2[idx])
				{
					idx++;
					cnt++;
				}
				else {
					break;
				}
			}

			mx = max(cnt, mx);
		}

		out << 2*(n - mx) + mx;

    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K:int, S:str):
    for i, s in enumerate(S):
        if i == K-1:
            print(s.lower(), end="")
        else:
            print(s, end="")
    print("")
    return


# Generated by 1.1.4 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()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


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

using namespace std;

int main(){  
    int N; cin>>N;
    int M; cin>>M;
    vector<int> X(M+1);//1~M
    vector<int> DIS(M,0);
    int minus=0;

    if(N<M){
      for(int i=1;i<=M;i++){
          cin>>X[i];
      }

      sort(&(X[1]),&(X[M+1]));

      for(int i=0;i<M-1;i++){
          DIS[i]=-(X[i+2]-X[i+1]);//0~M-2
      }

      sort(&(DIS[0]),&(DIS[M-1]));//DIS2~M
      for(int i=1;i<=N-1;i++){
          minus-=DIS[i-1];
      }

  	  printf("%d",X[M]-X[1]-minus);
    }
    else printf("0");
    return 0;
}

Measured memory_bytes: 1024
N, M, K = map(int, input().split())
#  1回押すと変わるマス = N * M - 1
# 2回目押すと黒になるマス = N * M - 1 - 2
# 3 = N * M - 1 - 4
cnt = 0
for i in range(N + 1) :
    for j in range(M + 1) :
        cnt = i * M + j * N - 2 * i * j
        if cnt == K :
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 2940
#!/usr/bin/env python3
import re
import sys


def solve(N: int, S: str):
    max_length = 1
    found = False
    for i in range(N):
        is_break = False
        if i + max_length > N:
            break
        while not is_break:
            org = S[i:i + max_length]
            rest = S[i + max_length:N]
            # print(org, rest)
            if org in rest:
                max_length += 1
            else:
                is_break = True
    print(max_length - 1)
    return


# Generated by 1.1.5 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()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;




int main(void) {
  ll N, M;
  cin >> N >> M;
  ll i;
  ll x[MAX], y[MAX];
  
  for(i=0; i<N; i++) cin >> x[i];
  for(i=0; i<M; i++) cin >> y[i];
  
  ll A=0, B=0;
  for(i=0; i<N; i++) moC(A, +, x[i]*(i-(N-1-i))%MOD);
  for(i=0; i<M; i++) moC(B, +, y[i]*(i-(M-1-i))%MOD);
  pt(A*B%MOD);
  
}





Measured memory_bytes: 1792
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;


    int dp[100005][3];
    
    int main(){
       int n;cin>>n;
       auto a = vec(int,n);
       auto b = vec(int,n);
       auto c = vec(int,n);
       rep(i,n)cin>>a[i]>>b[i]>>c[i];
       dp[0][0] = a[0];dp[0][1] = b[0];dp[0][2] = c[0];
       REP(i,1,n-1)rep(j,3){
           if(j==0){
               dp[i][j] = max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
           }
           if(j==1){
               dp[i][j] = max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
           }
           if(j==2){
               dp[i][j] = max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
           }
       }
       int res = max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
       cout<<res;
    }
    


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

#define fi first
#define se second

pair<int,int> p[100005];

int main(){
  int n,h,x=0;	cin>>n>>h;
  for(int i = 0; i < n; i++){
	cin>>p[i].se>>p[i].fi;
	x = max(x,p[i].se);
  }
  sort(p,p+n);
  int s = 0, c = 0;
  for(int i = n-1; i >= 0; i--){
	if(p[i].fi < x)	break;
	s += p[i].fi;	c++;
	if(s >= h){
		cout<<c;
		return 0;
	}
  }
  cout<<(h-s-1)/x+1+c;
  return 0;
}

Measured memory_bytes: 1024
N, A, B = [int(i) for i in input().split(" ")]
if (B - A) % 2 == 0:
    print((B-A)//2)
else:
    if A - 1 <= N-B:
        print((A-1+B)//2)
    else:
        print((N-A+N-B+1)//2)

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int n;
string s;
int qn;
set <int> st[30];

int main() { 

  scanf("%d\n", &n);
  getline(cin, s);
  for (int i = 0; i < sz(s); i++) {
    st[s[i] - 'a'].insert(i);
  }

  scanf("%d", &qn);

  while (qn--) {
    int t;
    scanf("%d", &t);
    
    if (t == 1) {
      int pos;
      char c;
      scanf("%d %c\n", &pos, &c);
      pos--;
      st[s[pos] - 'a'].erase(pos);
      s[pos] = c;
      st[c - 'a'].insert(pos);
    } else {
      int l, r;
      scanf("%d %d\n", &l, &r);
      l--; r--;
      int ans = 0;
      for (int i = 0; i < 26; i++) {
        auto it = st[i].lower_bound(l);
        if (it != st[i].end() && *it <= r) {
          ans++;
        }
      }
      printf("%d\n", ans);
    }
  }  

  return 0;
}


Measured memory_bytes: 24196
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define p_b push_back
#define pl pair<ll,ll>

ll MOD = 1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t= 1;
	//cin >> t;
	while(t--)
	{
		ll n;
		cin >> n;

		ll x[n],y[n];
		ll i;
		ll fact = 1;
		for(i=0;i<n;i++)
		{
			cin >> x[i] >> y[i];
			fact *= (i+1);
		}
		fact /= n;
		ll j;
		float ans = 0;
		for(i=0;i<n;i++)
		{
			for(j=i+1;j<n;j++)
			{
				float dist = ((x[i] - x[j])*(x[i]-x[j])) + ((y[i]-y[j])*(y[i]-y[j]));
				dist = sqrt(dist);
				

				ans += dist*fact*2;
			}
		}
		cout <<  fixed << setprecision(7) << ans/(fact*n) << endl;


	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int dp[k+1]={};
	for(int i=0;i<a[0];i++){
		dp[i]=0;
	}
	for(int i=a[0];i<=k;i++){
		int j=0;
		while(j<n && a[j]<=i){
			if(dp[i-a[j]]==0){
				dp[i]=1;
				break;
			}
			j++;
		}
	}
	if(dp[k]==0){
		cout<<"Second";
	}
	else{
		cout<<"First";
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;

int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
        while (a.at(i) % 2 == 0) {
            ans++;
            a.at(i) /= 2;
        }
    }

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


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

bool linearSearch(int a[], int n, int k){
    int i = 0;
    a[n] = k;
    while(k != a[i]){
        i++;
    }
    if(i == n) return false;
    return true;
}

int main(){
   int n;cin >> n;
   int s[n+1];
   for(int i = 0; i < n; i++) cin >> s[i];
   int q;cin >> q;
   set<int> t;
   for(int i = 0; i < q; i++){
       int tmp; cin >> tmp;
       t.insert(tmp);
   }
   set<int>::iterator itr = t.begin();
   int ans = 0;
   for(int i = 0; itr != t.end(); ++itr, i++){
       if(linearSearch(s, n, *itr)) ans++;
   }
   cout << ans << endl;
   return 0;   
}


Measured memory_bytes: 3120
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn calc(a: &[usize]) -> usize {
    let n = a.len();
    let mut fact = vec![1; n + 1];
    for i in 1..(n + 1) {
        fact[i] = i * fact[i - 1];
    }
    let mut ans = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            if a[j] < a[i] {
                ans += fact[n - 1 - i];
            }
        }
    }
    ans
}

fn run() {
    input! {
        n: usize,
        a: [usize; n],
        b: [usize; n],
    }
    let x = calc(&a);
    let y = calc(&b);
    let ans = std::cmp::max(x, y) - std::cmp::min(x, y);
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c)){x=x*10+c-'0';c=getchar();}
    return x*f;
}
const int maxn=5010;
const LL oo=1ll<<60;
int n,K,p[maxn],cnt;
LL c[maxn],ans=-oo,now_ans;
bool vis[maxn];
vector<LL> V;
int main()
{
    n=read();K=read();
    for(int i=1;i<=n;i++)p[i]=read();
    for(int i=1;i<=n;i++)c[i]=read();
    for(int i=1;i<=n;i++)
    {
    	int now=i;
    	LL pre=c[now];
    	V.clear();
    	V.push_back(pre);
    	now=p[now];
    	while(now!=i)pre+=c[now],V.push_back(pre),now=p[now];
    	int sz=V.size();
		for(int j=0;j<sz && K-(j+1)>=0;j++)
            ans=max(ans,V[j]+((K-(j+1))/sz)*max(pre,0LL));
    }
    printf("%lld\n",ans);
    return 0;
}
/*
*/

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

int N;
const int MOD = 998244353;
const long long w = ((long long)1e18)%MOD;
long long wpow[101010];

vector<long long> solve(vector<pair<int, int> > V)
{
    vector<vector<int> > conn(N+1);
    vector<int> sidx(N+1);
    vector<long long> ret(N);
    for(auto x: V)
    {
        int u, v; tie(u, v) = x;
        conn[u].push_back(v);
        conn[v].push_back(u);
    }
    for(int i=N; i>=1; --i)
    {
        set<int> S;
        for(auto x: conn[i])
            S.insert(sidx[x]);
        for(int t=1; t<=N; ++t)
            if(S.count(t) == 0)
            {
                sidx[i] = t;
                ret[t-1] = ret[t-1] + wpow[i];
                if(ret[t-1] >= MOD) ret[t-1] -= MOD;
                break;
            }
    }
    while(ret.back() == 0) ret.pop_back();
    return ret;
}
int main()
{
    scanf("%d", &N);
    wpow[0] = 1;
    for(int i=1; i<=N; ++i)
        wpow[i] = wpow[i-1]*w%MOD;
    vector<vector<long long> > Q;
    for(int i=0; i<3; ++i)
    {
        vector<pair<int, int> > V;
        int M; scanf("%d", &M);
        for(int j=0; j<M; ++j)
        {
            int u, v; scanf("%d%d", &u, &v);
            V.emplace_back(u, v);
        }
        Q.push_back(solve(V));
    }
    int maxi = max({Q[0].size(), Q[1].size(), Q[2].size()});
    vector<vector<bool>> adj(maxi+1, vector<bool>(maxi+1, false));
    long long ans = 0;
    auto add_ans = [&](int a, int b, int c)
    {
        //cerr << a << " " << b << " " << c << endl;
        //printf("%d %d %d\n", a, b, c);
        --a; --b; --c;
        if(a<(int)Q[0].size() && b<(int)Q[1].size() && c<(int)Q[2].size())
            ans += Q[0][a]*Q[1][b]%MOD*Q[2][c]%MOD;
        if(b!=c && a<(int)Q[0].size() && c<(int)Q[1].size() && b<(int)Q[2].size())
            ans += Q[0][a]*Q[1][c]%MOD*Q[2][b]%MOD;
        if(a!=b && b<(int)Q[0].size() && a<(int)Q[1].size() && c<(int)Q[2].size())
            ans += Q[0][b]*Q[1][a]%MOD*Q[2][c]%MOD;
        if(a!=b && b<(int)Q[0].size() && c<(int)Q[1].size() && a<(int)Q[2].size())
            ans += Q[0][b]*Q[1][c]%MOD*Q[2][a]%MOD;
        if(b!=c && c<(int)Q[0].size() && a<(int)Q[1].size() && b<(int)Q[2].size())
            ans += Q[0][c]*Q[1][a]%MOD*Q[2][b]%MOD;
        if(a!=b && b!=c && c<(int)Q[0].size() && b<(int)Q[1].size() && a<(int)Q[2].size())
            ans += Q[0][c]*Q[1][b]%MOD*Q[2][a]%MOD;
        ans %= MOD;
    };
    for(int i=1; i<=maxi; ++i)
    {
        add_ans(1, i, i);
        adj[i][i] = true;
    }
    for(int i=2; i<=maxi; ++i)
    {
        for(int j=i+1; j<=maxi; ++j)
        {
            if(adj[i][j]) continue;
            for(int k=j+1; k<=maxi; ++k)
            {
                if(!adj[j][k] && !adj[i][k])
                {
                    adj[j][k] = adj[k][j] = true;
                    adj[i][j] = adj[j][i] = true;
                    adj[i][k] = adj[k][i] = true;
                    add_ans(i, j, k);
                    break;
                }
            }
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 10668
package main

import "fmt"

func main() {
	var n, m, l int
	fmt.Scan(&n, &m, &l)

	a := make([][]int, n)
	c := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		c[i] = make([]int, l)
		for j := 0; j < m; j++ {
			fmt.Scan(&a[i][j])
		}
	}

	b := make([][]int, m)
	for i := 0; i < m; i++ {
		b[i] = make([]int, l)
		for j := 0; j < l; j++ {
			fmt.Scan(&b[i][j])
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < l; j++ {
			for k := 0; k < m; k++ {
				c[i][j] += a[i][k] * b[k][j]
			}
		}
	}

	for _, cr := range c {
		for j, cc := range cr {
			if j != 0 {
				fmt.Print(" ")
			}
			fmt.Print(cc)
		}
		fmt.Println()
	}
}



Measured memory_bytes: 2588
n = int(input())
if n <= 111:
	print(111)
elif n <= 222:
	print(222)
elif n <= 333:
	print(333)
elif n <= 444:
	print(444)
elif n <= 555:
	print(555)
elif n <= 666:
	print(666)
elif n <= 777:
	print(777)
elif n <= 888:
	print(888)
else:
	print(999)

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Threading.Tasks;

static class Program
{
static void Main()
{
  int nGem = int.Parse(Console.ReadLine());
  var values = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();
  var costs = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();
  var pairs = Enumerable.Range(0, nGem).Select(idx =>
     new
     {
       Value = values[idx],
       Cost =  costs[idx],
       Balance =  values[idx] - costs[idx]
    });
  int result = pairs.Where(p => p.Balance > 0).Sum(p => p.Balance);
  Console.WriteLine(result);
}

}

Measured memory_bytes: 13396
n, y = gets.split.map(&:to_i)

0.upto(n) do |a|
  0.upto(n-a) do |b|
    c = n - a - b
    if 10000*a + 5000*b + 1000*c == y
      puts "#{a} #{b} #{c}"
      exit
    end
  end
end

puts "-1 -1 -1"


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

ll dp[51][51][3000];

int main(){
    
    ll N,A; cin>>N>>A;
    vector<ll> x(N+1);
    REP(i,N)cin>>x[i+1];
    
    for(int i=0;i<=N;i++){
        for(int j=0;j<=i;j++){
            for(int k=0;k<2600;k++){
                if(i==0&&j==0&&k==0)dp[i][j][k]=1;
                if(i>=1&&j>=1&&k-x[i]>=0)dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]];
                if(i>=1&&k-x[i]<0)dp[i][j][k]=dp[i-1][j][k];
            }
        }
    }
    
    ll ans=0;
    for(int i=1;i<=N;i++)ans+=dp[N][i][i*A];
    cout<<ans<<endl;
    
    return 0;
}


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

#define ll long long int

ll f(int h[],int n,int k){

    ll dp[n+1] = {0};
    dp[2] = abs(h[1] - h[0]);

    for(int i=3;i<=n;i++){
        ll inc = INT_MAX;
        for(int j=1;j<=min(i-1,k);j++){
            inc = min(inc,dp[i-j] + (ll)abs(h[i-1] - h[i-j-1]));
        }
        dp[i] += inc;
    }

    return dp[n];
}

int main() {

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    int n,k;
    cin>>n>>k;
    int h[n];
    for(int z=0;z<n;z++) cin>>h[z];

    cout<<f(h,n,k);

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;

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

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

  int sum = 0;
  for(int i = 0; i < n; i++){
    int j = 0;
    int m = a[i];
    while(m % 2 == 0){
      m /= 2;
      ++j;
    }
    sum += j;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  ll t = accumulate(all(B), 0LL) - accumulate(all(A), 0LL);
  if(t < 0) {
    cout << "No\n";
    return 0;
  }
  ll cnt = 0;
  rep(i, N) {
    if(A[i] > B[i]) cnt += A[i]-B[i];
    else if(A[i]%2 != B[i]%2) cnt++;
  }
  cout << (cnt>t ? "No\n" : "Yes\n");
  return 0;
}


Measured memory_bytes: 3764
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  int N, A, B;
  sc.scan(N, A, B);

  write(min(A, B));

  write(" ");

  if (A + B > N)
    writeln(abs((N - A) - B));
  else
    writeln("0");
}


Measured memory_bytes: 256
//ITNOA
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <iomanip>

using namespace std;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;


#define rep(i, s, e) for(int i = s; i < e; i ++)
#define X first
#define Y second

typedef long long ll;
typedef long double ld;

const int maxN = 50 + 5;
const int mod = 1000*1000*1000 + 7;
const int base = 701;
const int SQ = 500;
const int maxL = 20;

ll a[maxN];

int n;
ll get() {
	sort(a,a+n);
	int res = 0;
	while(a[n-1] >= n) {
	   	a[n-1] -= n;
   		for(int i = 0; i < n-1; i ++)
	 		a[i] ++;
		sort(a,a+n);
		res ++;		
	}	
	return res;
}

int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i ++)
		cin >> a[i];
	
	ll ans = 0;
	while(true) {
		sort(a,a+n);
		if(a[n-1] < n) break;
		
		ll sum = 0;
		for(int i = 0; i < n; i ++)
			sum += a[i];
		if(sum <= 100*100) {
			ans += get();
			break;
		}

		ll dif = (a[n-1] - (n-1)) / n;
		//	cout << dif << endl;
	   	a[n-1] -= dif * n;
		for(int i = 0; i < n-1; i ++)
			a[i] += dif;
		
		ans += dif;	
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)

int N, H, A[100009], B[100009], C[100009], D[100009], L[100009], R[100009], deg[100009], col[100009], cnts, cnt; bool used[100009];
vector<int>x[100009];

void dfs1(int pos) {
	if (col[pos] >= 1) return;
	col[pos] = cnts;
	for (int i = 0; i < x[pos].size(); i++) dfs1(x[pos][i]);
}

int main() {
	cin >> N >> H; H++;
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i] >> C[i] >> D[i];
		if (C[i] == 0) { L[i] = -A[i]; cnt++; }
		else { L[i] = C[i]; }
		if (D[i] == 0) { R[i] = -B[i]; cnt++; }
		else { R[i] = D[i]; }
		R[i] *= -1;
	}
	for (int i = 1; i <= N; i++) {
		int a1 = 0, a2 = 0;
		if (L[i] < 0) a1 = H + (-L[i]); else a1 = L[i];
		if (R[i] < 0) a2 = H + (-R[i]); else a2 = R[i];
		deg[a1]++; deg[a2]--; used[a1] = true; used[a2] = true;
		x[a1].push_back(a2); x[a2].push_back(a1);
	}
	bool OK = true; int V = 0;
	for (int i = 0; i < H; i++) { if (deg[i] > 0) OK = false; }
	for (int i = H; i < 2 * H; i++) { if (deg[i] < 0) OK = false; else V += deg[i]; }

	for (int i = 0; i < 2 * H; i++) {
		if (col[i] == 0 && used[i] == true) { cnts++; dfs1(i); }
	}
	if (cnts > (cnt - N - 1) + 1) OK = false;

	if (OK == true) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 7296
n = int(input())
s = input()
S = input()
dp = [1]*(n+1)
if s[0]== S[0]:ans = 3;i = 1;dp[0] = 1
else:ans = 6;i = 2;dp[1] = 2
while i < n:
    if s[i] == S[i]:
        dp[i] = 1
        if dp[i-1] == 1:ans *= 2
        else: ans *= 1
        i += 1
    else:
        if dp[i-1] == 2:ans *= 3
        else: ans *=2
        dp[i+1]= 2
        i += 2
print(ans%1000000007)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
    int N;
    scanf("%d",&N);
    int A[2][N];
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++){
        scanf("%d",&A[i][j]);
        }
    }
    A[1][0] += A[0][0];
    for(int i=1;i<N;i++){
        A[0][i] += A[0][i-1];
        A[1][i] += A[1][i-1]>A[0][i]?A[1][i-1]:A[0][i];
    }

    printf("%d",A[1][N-1]);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main ()
{
    int x[3],y=0,i,z;
    for(i=0;i<3;i++)
        cin >> x[i];
    sort(x,x+3);
    y=((x[2]*10)+x[1])+x[0];
    cout << y;
    return 0;
}


Measured memory_bytes: 256
L = int(input())
B = []
for i in range(20):
    L, b = divmod(L, 2)
    B.append(b)
B.reverse()
f = False
E = []
s = 0
for i, b in enumerate(B[:19]):
    E.append([i+1, i+2, 0])
    if b==1:
        f = True

    if f:
        E.append([i+1, i+2, 2**(18-i)])

for i, b in enumerate(B):
    if b==1:
        if s!=0:
            E.append([1, i+1, s])
        s += 2 ** (19-i)

print(20, len(E))
for e in E:
    print(" ".join(map(str, e)))


Measured memory_bytes: 3064
def ans(N): # N:foat
    n=int(N)
    d=N-n
    ans_l=bin(n)[2:]
    ans_r=''
    for _ in range(4):
        ans_r+=str(int(d*2))
        d=d*2-int(d*2)
    if n>=256 or d!=0:
        return 'NA'
    else:
        return '0'*(8-len(ans_l))+ans_l+'.'+ans_r

while True:
    INP=float(input())
    if INP<0: break
    print(ans(INP))


Measured memory_bytes: 5580
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
using namespace std;

int main(){
    int n; cin >> n;
    rep(i,9)rep(j,9){
        if((i+1)*(j+1)==n){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

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

	int x[n], y[n], h[n];
	int sx, sy, sh;
	for(int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
		if(h[i] >= 1) sx = x[i], sy = y[i], sh = h[i];
	}

	bool find_ans = false;

	int ansx, ansy, ansh;

	for(int i = 0; i <= 100; i++) {
		if(find_ans) break;
		for(int j = 0; j <= 100; j++) {
			if(find_ans) break;

			int cx = i, cy = j, H = sh + abs(sx - cx) + abs(sy - cy);

			bool find = true;
			for(int k = 0; k < n; k++) {
				if(h[k] != max(H - abs(x[k] - cx) - abs(y[k] - cy), 0)) {
					find = false;
					break;
				}
			}
			
			if(find) ansx = cx, ansy = cy, ansh = H;

			find_ans = find;
		}
	}

	cout << ansx << " " << ansy << " " << ansh << endl;

	return 0;
}

Measured memory_bytes: 256
word = {}

cnt = int(input())

for i in range(0,cnt):
    w = input()
    if w not in word:
        word[w] = 1
    else:
        word[w] += 1

m = max(word.values())
search = [i for i in word.keys() if word[i] == m]
[print(i) for i in sorted(search)]


Measured memory_bytes: 34012
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, num, a1, a2;
  cin >> A;
  a1 = A%10;
  a2 = ((A-a1)%100)/10;
  num = a1 + a2 + (A - 10*a2 -a1)/100;
  cout << num <<endl;
}

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

ll gcd(ll a, ll b){
  if(b==0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}

int main(){
  int vec[5];
  for(int i=0;i<5;i++){
    cin>>vec[i];
    if(vec[i]==0){
      cout<<i+1<<endl;
    }
  }
}

Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

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

void solve(){
	string s;
    cin>>s;
    int cnt=0;
    char t[5]={'K','I','H','B','R'};
    rep(i,9){
        if(!i||i==4||i==6||i==8){
            if(s[i]!='A')s.insert(s.begin()+i,'A');
        }
        else {
            if(t[cnt]!=s[i]){
                cout<<"NO\n";
                return;
            }
            ++cnt;
        }
    }
    if(s=="AKIHABARA")cout<<"YES\n";
    else cout<<"NO\n";
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;


int main() {
  int a,b,k; cin>>a>>b>>k;
  for(int i=a; i<=min(b, a+k-1); i++) cout << i << endl;
  for(int i=max(b-k+1, a+k); i<=b; i++) cout << i << endl;
}


Measured memory_bytes: 3172
N, Y = map(int, input().split())
x_out, y_out, z_out = -1, -1, -1
for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        xyz_sum = x*10000 + y*5000 + z*1000
        if xyz_sum == Y:
            x_out, y_out, z_out = x, y, z
            break
print(x_out, y_out, z_out)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef vector<ll> row;
typedef vector<row> mat;

ll N, M, K, P[10000];

row mul(row &A, row &B) {
  row C(N);
  REP(i, 0, N)
    REP(j, 0, N)
      C[i] = (C[i] + A[j] * B[(i - j + N) % N]) % MOD;
  return C;
}

row pow(row A, ll n) {
  row B(N);
  B[0] = 1;
  while(n > 0) {
    if(n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}


int main(void) {
  cin >> N >> M >> K;
  REP(i, 0, M) cin >> P[i];

  row A(N);
  A[0]++;
  REP(i, 0, M) A[(N - P[i] % N) % N]++;
  A = pow(A, K);

  REP(i, 0, N) cout << A[(N - i) % N] << endl;
}

Measured memory_bytes: 3236
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
ll dx[4]={0,-1,0,1};
ll dy[4]={1,0,-1,0};
/****************************/
string s;
ll n,m,k;
int a[100010];
vi v;
vi uni(vi v)
{
	vi ans=v;
	sort(ans.begin(),ans.end());
	ans.erase(unique(ans.begin(),ans.end()),ans.end());
	return ans;
}
int quickpower(int m,int n)
{
    if(n==1) return m;
    int temp=quickpower(m,n/2);
    return (n%2==0 ? 1 : m)*temp*temp;
}
int main()
{
	ios::sync_with_stdio(0);
	ll ans=100;
	ll x;
	cin>>x;
	int i;
	for(i=0;ans<x;i++)
	{
		ans+=double(0.01*ans);
	}
	cout<<i;
	return 0;
}

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

using namespace std;

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

    if (N % 2)
        cout << setprecision(7) << (N+1.0) / (2.0*N);

    else
        cout << setprecision(7) << 0.5;

    return 0;
}


Measured memory_bytes: 3756
#include <iostream>
using namespace std;
int main(){
	int n,a,b,c,x;
	while(cin>>n>>a>>b>>c>>x){
		if(n==0) break;
		int y[n];
		for(int i=0;i<n;i++){
			cin>>y[i];
		}
		int k=0;
		for(int i=0;i<=10000;i++){
			if(y[k]==x){
				k++;
			}
			if(k==n){
				cout<<i<<endl;
				break;
			}
			x=(a*x+b)%c;
		}
		if(k<n){
			cout<<-1<<endl;
		}
	}
    return 0;
}

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

signed main() {
	string r,s,t;
	cin>>r; s=r+r;
	cin>>t;

	vector<vector<ll>> s_position(26,vector<ll>());
	vector<ll> t_num(26,0);
	rep(i,s.size()){
		ll alphabet=s[i]-'a';
		s_position[alphabet].push_back(i);
	}
	rep(i,t.size()){
		ll alphabet=t[i]-'a';
		t_num[alphabet]++;
	}
	rep(i,26){
		if(s_position[i].size()==0 && t_num[i]>0){
			cout<<-1<<endl;
			return 0;
		}
	}

	ll ans=0;
	ll position=0;
	rep(i,t.size()){
		ll alphabet=t[i]-'a';
		auto it=lower_bound(s_position[alphabet].begin(), s_position[alphabet].end(), position);
		ans+=*it-position+1;
		position=*it+1;
		if(position>=r.size())position-=r.size();
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3000
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n,m;cin >> n >> m;
  priority_queue<int> que;
  for(int i=0;i<n;i++){
    int x;cin >> x;
    que.emplace(x);
  }
  while(m--){
    auto p = que.top();
    que.pop();
    que.emplace(p/2);
  }
  Int ret = 0;
  while(que.size()){
    auto p = que.top();
    que.pop();
    ret += p;
  }
  cout << ret << endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

//https://atcoder.jp/contests/abc082/tasks/abc082_b

int main() {
    string s, t; cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if (s < t) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }

    return 0;
}

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

typedef long long ll;
const ll MOD = 1000000007;
ll mod;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k, x;
    cin >> k >> x;
    for (int i = x - k + 1; i < k + x; i++) cout << i << " ";
    return 0;
}


Measured memory_bytes: 384
N, M = map(int, input().split())
mod = 10**9+7

def f(n):
    ret = 1
    for i in range(1, n+1):
        ret = (ret * i) % mod
    return ret

if abs(N-M) > 1:
    print(0)
elif N == M:
    print(f(N)**2*2 % mod)
else:
    a = N if N > M else M
    print(f(a)*f(a-1) % mod)


Measured memory_bytes: 38384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var a,b []int
func main() {
	sc.Split(bufio.ScanWords)
	N := scanInt()
	K := scanInt()
	a = make([]int, N)
	for i:= 0; i<N; i++ {
		a[i] = scanInt()
	}
	// 前の状態とあとの状態を維持する必要がある
	if K > 500 {
		K = 500
	}
	for i:= 0; i<K; i++ {
		//愚直にやる -> 多分無理
		b = make([]int, N)
		mapNext := make([]int,N) //どこで-1なるか調べる
		count := 0
		for j := 0; j < N; j++ {
			//next方向
			light := a[j]
			if !(b[j] >= N) {
				b[j] += count+1
			}
			if light > 0 {
				count += 1
				if N > light + j {
					mapNext[light+j] += 1
				}
			}
			count -= mapNext[j]
		}
		mapPrev := make([]int,N)
		count = 0
		for j:= N-1; j>=0; j-- {
			light := a[j]
			if !(b[j] >= N) {
				b[j] += count
			}
			if light > 0 {
				count += 1
				if j - light >= 0 {
					mapPrev[j-light] +=1
				}
			}
			count -= mapPrev[j]
		}
		a = b
	}
	for i:= 0; i<N; i++ {
		fmt.Print(a[i])
		fmt.Print(" ")
	}
}
var sc = bufio.NewScanner(os.Stdin)
func scanInt () int{
	sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}

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

int main()
{
    int H, W, N;
    cin >> H >> W >> N;

    if (H < W) {
        int tmp = W;
        W = H;
        H = tmp;
    }

    int ans = 0;
    while (N > 0) {
        N -= H;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.CodeDom;
using System.Linq;
using System.Text;

namespace paizaTest
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var oneLine = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var count = 0;

            for (int i = oneLine[0]; i <= oneLine[1]; i++)
            {
                count = oneLine[2] % i == 0 ? ++count : count;
            }
            Console.WriteLine(count.ToString());
        }
    }
}

Measured memory_bytes: 9540
#include <stdio.h>
int main()
{
  int L;
  int R;
  int d;
  int i;
  int t=0;
  scanf("%d%d%d",&L,&R,&d);
  for(i=1;i<=R;i++)
  {
    if(i*d>=L&&i*d<=R)
		t++;
	if(i*d>R)
		break;
  }
  printf("%d",t);
}

Measured memory_bytes: 1704
#include<bits/stdc++.h>
using namespace std;
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; }
#define ll long long
 
const ll INF= 1LL << 60;
 
//入力
ll N,M;
vector<vector<ll>> vec(100010);
 
//dp
ll dp[100010];
 
ll lg(ll v){
  //頂点vからの最も長い矢印の長さ
  if(dp[v]!=-1){
    return dp[v];
  }else{
    if(vec[v].size()==0){
    	chmax(dp[v],0LL);
    }else{
        for(ll i:vec[v]){
          chmax(dp[v],lg(i)+1);
        }
    }
    //cout<<v<<endl;
    return dp[v];
  }
}
 
int main(){
  cin>> N >> M;
  ll x,y;
  for(int i=0;i<M;i++){
    cin>>x>>y;
    vec[x-1].push_back(y-1);
  }
  for(int i=0;i<=N;i++) dp[i]=-1;
  
  ll res=0;
  for(ll i=0;i<N;i++){
    chmax(res,lg(i));
  }
  
  cout << res << endl;
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>A(3);
    for(int i=0;i<3;++i){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    if(A[0]==A[1]+A[2])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
	#define lb lower_bound 
	#define ub upper_bound
	#define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
	#define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
	#define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
	#define all(c) (c).begin(),(c).end()
	#define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
	
	 const int N =1e5+5;
	
	 int mod= 1e9+7;
	 int dx[4]={0,0,+1,-1};
	 int dy[4]={+1,-1,0,0};  
	 
	 
	int po(int a, int b) {
		a %= mod;
		int res = 1;
		while (b > 0) {
			if (b & 1)
				res = (res * a) % mod;
			a =(a*a) % mod;
			b >>= 1;
		}
		 return res;	
	   }

	
	 int sm,x,y,a,b,c;
	 
	 void solve() {		 
	  	 
	   cin>>x>>y>>a>>b>>c;
	   vi p(a,0),q(b,0),r(c,0);
	   
	   rep(i,0,a) cin>>p[i];
	   sort(p.rbegin(),p.rend());
	   
	   rep(i,0,b) cin>>q[i];
	   sort(q.rbegin(),q.rend());
	   
	   rep(i,0,c) cin>>r[i];
	   sort(r.rbegin(),r.rend());
	   
	   vi v;
	   
	   rep(i,0,x) v.pb(p[i]);
	   rep(i,0,y) v.pb(q[i]);
	   rep(i,0,c) v.pb(r[i]);
	   
	   sort(v.rbegin(),v.rend());
	   rep(i,0,x+y) sm+=v[i];
	   cout<<sm<<endl;	 
	   
	 }
	
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	   solve();
	   
	   
	   return 0;	   
}


Measured memory_bytes: 8816
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin>>a>>b;
  int gcd;
  
    for(int i=1;i<=a;i++){
      if(a%i==0 &&b%i==0){
        gcd=i;
      }
    }
  
  long long ans=(long long)(a)*b/gcd;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
List=list(map(int,input().split()))#n個
s=[]

for i in range(m):
    a,b=list(map(int,input().split()))
    if List[a-1]>List[b-1]:
        s.append(b)
    elif List[a-1]<List[b-1]:
        s.append(a)
    else:
        s.append(a)
        s.append(b)
    
t=set(s)       
print(n-len(t))

Measured memory_bytes: 20088