akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N, A, B;
  cin >> N >> A >> B;

  cout << min(N * A, B) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N, M;
    cin >> N >> M;
    int L = 1;
    int R = N;
    int l, r;
    for (int i = 0; i < M; i++)
    {
        cin >> l >> r;
        if (l > L)
        {
            L = l;
        }
        if (r < R)
        {
            R = r;
        }
    }
    int ans = R - L + 1;
    if (ans < 0)
    {
        ans = 0;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, c;
  cin >> n >> m >> c;
  set<pair<int, int>> s;
  unordered_map<int, int> cx, cy;
  for (int i = 0; i < c; ++i) {
    int x, y;
    cin >> x >> y;
    s.emplace(x, y);
    cx[x]++;
    cy[y]++;
  }

  vector<pair<int, int>> ax, ay;
  for (auto &it : cx) {
    ax.emplace_back(it.second, it.first);
  }
  for (auto &it : cy) {
    ay.emplace_back(it.second, it.first);
  }
  sort(ax.begin(), ax.end(), greater<pair<int, int>>());
  sort(ay.begin(), ay.end(), greater<pair<int, int>>());

  int ans = 0;
  for (auto [x, y] : s) {
    ans = max(ans, cx[x] + cy[y] - 1);
  }

  for (auto &ix : ax) {
    for (auto &iy : ay) {
      if (!s.count({ix.second, iy.second})) {
        ans = max(ans, ix.first + iy.first);
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 52676
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int D,T,S;
signed main(){
    scanf("%lld %lld %lld",&D,&T,&S);
    if(S*T>=D)printf("Yes\n");
    else printf("No\n");
}

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

int main(){
	string s;
	bool f1=false,f2=false;

	cin >>s;
	int n = s.length();

	for(int i=0;i<n;i++){
		if(s[i]=='C')
			f1 = true;
		if(f1==true && s[i]=='F')
			f2 = true;
	}

	if(f1,f2)
		cout<< "Yes" <<endl;
	else
		cout<< "No" <<endl;


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define num_max(p,q)((p)>(q)?(p):(q))
#define num_min(p,q)((p)<(q)?(p):(q))
int cmp(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;//昇順
	 //降順ならreturn *(int*)b - *(int*)a;
}
int main()
{
	int N, K,i,ans=0;
	
	scanf("%d%d", &N, &K);
	int(*h) = (int(*))malloc(N * sizeof(int));
	for (i = 0;i < N;i++)
	{
		scanf("%d", &h[i]);
		if (h[i] >= K)ans++;
	}
	printf("%d\n", ans);
	free(h);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
struct bellford
{
    const ll INF=LONG_LONG_MAX;
    struct edge {int u, v; ll w;};
    int nv, ne;
    vector<ll> d;
    vector<int> p;
    vector<edge> E;
 
    bellford(int nv, int ne) : nv(nv), ne(ne)
    {
        d.resize(nv, INF);
        p.resize(nv,-1);
    }
 
    void relax(int u, int v, ll w)
    {
        if(d[u]!=INF && d[v]>d[u]+w)
        {
            d[v]=d[u]+w;
            p[v]=u;
        }
    }
 
    bool get(int s)
    {
        d[s]=0; 
        for(int i=0; i<nv; i++)
            for(auto &e : E)
                relax(e.u, e.v, e.w);
 
        vector<bool> path(nv, false);
        path[nv-1]=true;
        int v=p[nv-1];
        while(v!=-1 && !path[v])
        {
            path[v]=true;
            v=p[v];
        }
        if(v!=-1) return false;
        return true;
    }
};
 
 
int main()
{
    int N, M;
    scanf("%d%d", &N, &M);
    bellford g(N, M);
    for(int i=0; i<M; i++)
    {
        int a, b;
        ll c;
        scanf("%d%d%lld", &a, &b, &c);
        g.E.push_back({a-1, b-1, -c});
    }
    if(g.get(0)) printf("%lld\n", -g.d[N-1]);
    else printf("inf\n");
    return 0;
}

Measured memory_bytes: 3796
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
if a[0]>x:
    ans=a[0]-x
    a[0]=x
for i in range(1,n):
    if a[i]+a[i-1]>x:
        t=x-a[i-1]
        ans+=a[i]-t
        a[i]=t
        
print(ans)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int X = nextInt();
  int t = 1;
  while (t*(t+1)/2 < X) t++;
  cout << t << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
/** Seek God..Trust God..Praise God..**/

#include<bits/stdc++.h>
using namespace std;


#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>
#define endl            "\n";

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////



/*
long long  Prime[3000000],nPrime;
long long  mark[10000002];

void seive(long long int n)
{
	long long int i,j,limit=sqrt(n*1.0)+2;
	mark[1]=1;
	for(i=4; i<=n ;i+=2)
	mark[i]=1;
	Prime[nPrime++]=2;
	for(i=3; i<=n; i+=2)
	{
		if(!mark[i])
		{
			Prime[nPrime++]=i;
			if(i<=limit)
			{
				for(j=i*i; j<=n ;j+=i*2)
				{
					mark[j]=1;
				}
			}
		}
	}
}
*/


int main()
{
    FASTIO;

    ll a , b , c , d;

    cin >> a >> b >> c >> d;


    ll ans = a*c;

    ll ans1 = a*d;


    ll ans2 = b*c;

    ll ans3 = b*d;


    cout << max(ans,max(ans1,max(ans2,ans3))) << endl;







    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,start,end) for(int i=start; i<=end; i++)
#define repd(i,start,end) for(int i=start; i>=end; i--)
#define all(x) x.begin(),x.end()

void solve() {
	int n;
	cin >> n;
	ll a[n],ans=0;

	rep(i,n)
		cin >> a[i];

	repa(i,1,n-1) {
		if(a[i]<a[i-1]) {
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}

	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--) {
		solve();
	}
}

Measured memory_bytes: 5248
#include "bits/stdc++.h"
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;
bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for (int i = 1; i*i <= n; ++i)
	{
		if (n%i == 0)
		{
			ret.push_back(i);
			if (i != 1 && i*i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

int main()
{
	priority_queue<int> q;
	ll h, w, a, b, ans = 0;
	string s = {};
	cin >> a;
	if (a%2==1)
	{
		cout << a / 2 << endl;

	}
	else
	{
		cout << a/2-1 << endl;

	}
	//cout << a << endl;
	//cin >> a >> b;
	//for (int i = 0; i < a; i++)
	//{
	//	cin >> s[i];
	//	if (s[i] >= b)
	//	{
	//		ans++;
	//	}
	//}

	//cout << ans << endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}


Measured memory_bytes: 256
N = int(input())
Cash = sorted([1]+[6**T for T in range(1,7)]+[9**T for T in range(1,6)])
DPList = [0]*(N+1)
for TN in range(1,N+1):
    DPList[TN] = min(DPList[TN-TC]+1 if TN>=TC else 1000000 for TC in Cash)
print(DPList[N])

Measured memory_bytes: 9444
// Created by ...Lusifer
#include<bits/stdc++.h>
using namespace std;
 
#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void solveTest(){
	int n,k,q;
	cin>>n>>k>>q;
	int a[n+1];
	memset(a,0,sizeof(a));
	for(int i=1;i<=q;i++){
		int x;
		cin>>x;
		a[x]++;
	}
	for(int i=1;i<=n;i++){
		int dif= k-(q-a[i]);
		if(dif>0){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	return ;
}
 
int main(){
	fastio();

	int t=1;
	//cin>>t;
	while(t--){
		solveTest();
 
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

template<class T>
void show_1d_vector(const vector<T> &v){
    for(auto v1: v) {
        cout << v1 << " ";
    }
    cout << endl;
}

int main(){

    ll n;
    cin >> n;
    vector<ll> a(n+1);
    for(int i = 0; i < n+1; i++){
        cin >> a[i];
    }
    vector<ll> maximum_num(n+1);
    maximum_num[0] = 1;
    for(int i = 0; i < n; i++){
        ll next = 2*(maximum_num[i] - a[i]);
        if(next > (1LL<<60)){next = 1LL<<60;}
        maximum_num[i+1] = next;
        if(maximum_num[i+1] < 0){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = 0; i < n+1; i++){
        if(maximum_num[i] < a[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    
    vector<ll> vnum(n+1);
    vnum[n] = a[n];
    for(int i = 0; i < n; i++){
        vnum[n-1-i] = min(a[n-1-i] + vnum[n-i], maximum_num[n-1-i]);
    }
    ll ans = 0;
    for(int i = 0; i < n+1; i++){
        ans += vnum[i];
    }

    cout << ans << endl;
    return 0;

}


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

int main() {
    int r, c, t,i, j;
    int h[101][101];

    cin >> r >> c;
    for(i = 0; i < r; i++) {
        t = 0;
        for(j = 0; j < c; j++) {
            cin >> h[i][j];
            t += h[i][j];
        }
        h[i][c] = t;
    }
    for(j = 0; j <= c; j++) {
        t = 0;
        for(i = 0; i < r; i++) {
            t += h[i][j];
        }
        h[r][j] = t;
    }

    for(i = 0; i <= r; i++) {
        for(j = 0; j < c; j++) {
            cout << h[i][j] << " ";
        }
        cout << h[i][c] << endl;
    }
    return 0;
}




Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  int B[N];
  for (int i = 0; i < N; i++) cin >> B[i];
  reverse(B, B + N);
  int l = N + 1, r = -1;
  for (int i = 0; i < N; i++) {
    if (A[i] == B[i]) l = min(l, i), r = max(r, i);
  }
  if (l == N + 1) {
    cout << "Yes" << '\n';
    for (int i = 0; i < N; i++) cout << (i ? " " : "") << B[i];
    cout << '\n';
    return 0;
  }
  int L = 0, R = N - 1;
  bool isok = true;
  for (int i = l; i <= r; i++) {
    if (L < l && B[i] != A[L] && B[L] != B[i]) {
      swap(B[L++], B[i]);
    } else if (R > r && B[i] != A[R] && B[R] != B[i]) {
      swap(B[R--], B[i]);
    } else {
      isok = false;
      break;
    }
  }
  if (isok) {
    cout << "Yes" << '\n';
    for (int i = 0; i < N; i++) cout << (i ? " " : "") << B[i];
    cout << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 5212
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define int long long
const int N = 1e6;

int n;
int a[N];
int cnt[N];
int used[N];
set<pair<int, int> > mm, mm2;
vector<int> ans;

int get2(int x)
{
    auto it = mm2.lower_bound({x, -1});
    return (*it).second;
}

int ch(int lst, int x, int t)
{
    if (a[lst] == x)
    {
        return 0;
    }
    int cn = get2(x);
    mm.erase({cn, x});
    mm2.erase({x, cn});
    if (t == 0)
    {
        int nxt = a[x];
        if (!used[nxt])
        {
            int cnnxt = get2(nxt);
            mm.erase({cnnxt, nxt});
            mm.insert({cnnxt - 1, nxt});
            mm2.erase({nxt, cnnxt});
            mm2.insert({nxt, cnnxt - 1});
        }
        return 1;
    }
    auto it = mm.end();
    it--;
    if ((*it).first == mm.size())
    {
        mm.insert({cn, x});
        mm2.insert({x, cn});
        return 0;
    }
    mm.insert({cn, x});
    mm2.insert({x, cn});
    return 1;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for (int i = 1; i <= n; i++)
    {
        mm.insert({cnt[i], i});
        mm2.insert({i, cnt[i]});
    }
    for (int i = n; i >= 5; i--)
    {
        int lst = 0, t = n + 1;
        if (ans.size()) lst = ans.back();
        auto it1 = mm.end();
        it1--;
        auto it2 = mm.end();
        it2--;
        it2--;
        auto it3 = mm2.begin();
        auto it4 = mm2.begin();
        it4++;
        pair<int, int> i1 = *it1;
        pair<int, int> i2 = *it2;
        pair<int, int> i3 = *it3;
        pair<int, int> i4 = *it4;
        int w = 0;
        if (ch(lst, i1.second, 1)) t = min(t, i1.second), w = (i1.first + 1 == i);
        if (!w && ch(lst, i2.second, 1)) t = min(t, i2.second), w = (i2.first + 1 == i);
        if (!w && ch(lst, i3.first, 1)) t = min(t, i3.first);
        if (!w && ch(lst, i4.first, 1)) t = min(t, i4.first);
        if (t == n + 1) cout << -1, exit(0);
        ch(lst, t, 0);
        used[t] = 1;
        ans.push_back(t);
    }
    vector<int> p;
    int lst = 0;
    if (ans.size()) lst = ans.back();
    for (int i = 1; i <= n; i++) if (used[i] == 0) p.push_back(i);
    while (1)
    {
        int t = 1;
        if (a[lst] == p[0]) t = 0;
        for (int i = 1; i < p.size(); i++)
            if (a[p[i - 1]] == p[i]) t = 0;
        if (t)
        {
            for (int i = 0; i < p.size(); i++)
                ans.push_back(p[i]);
            break;
        }
        if (!next_permutation(all(p)))
        {
            cout << -1, exit(0);
        }
    }
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}


Measured memory_bytes: 22272
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n = int(input())
    # a, b = list(map(int, input().split()))
    print((1000 - n%1000) if n %1000 else 0)

main()

Measured memory_bytes: 9396
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int
const int lim = (int)2e5 + 5;
vi adj[lim];
int dp[lim][11] = {0};
void dfs(int cur, int dep, int color){
    if(dep < 0)return;
    if(dp[cur][dep])return;
    int i = dep;
    while(i >= 0 && !dp[cur][i]){
        dp[cur][i] = color;
        i--;
    }
    for(int child: adj[cur]){
        dfs(child, dep - 1, color);
    }
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n, m;cin >> n >> m;
    int x, y, a, b, c;
    FOR(i, m){
        cin >>x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int q;cin >> q;
    vector<pair<int, pii>> info;
    FOR(i, q){
        cin >> a >> b >> c;
        info.pb(mp(a, mp(b, c)));
    }
    FOR(i, q){
        dfs(info.back().first, info.back().second.first, info.back().second.second);
        info.pop_back();
    }
    FOR(i, n){
        cout << dp[i+1][0] << endl;
    }
}




Measured memory_bytes: 23916
#include <stdio.h>
#include <string.h>
int main(void)
{
	int i,j,flag;
	flag=0;
	char s[100000];
	scanf("%s",s);
	i=strlen(s);
		if(s[0]==s[i-1]){
			if(i%2==1)
			printf("Second");
			else
			printf("First");}
			else
			{
			if(i%2==1)
			printf("First");
			else
			printf("Second");}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
#define pb push_back
#define PI acos(-1.0)
#define EPS 1e-4
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fout(S,x)            cout<<fixed<<setprecision(x)<<(S)<<endl
#define present(c,x) ((c).find(x) != (c).end())
#define T() ll t;cin>>t;while(t--)
#define mem(input,b) memset(input,b,sizeof(input))
#define ff first
#define ss second
#define fread(input) freopen("input","r",stdin)
#define fwrite(b) freopen("b","w",stdout)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define FOREACH(i,c) for (__typeof ((c).begin()) i = (c).begin() ; i != (c).end() ; i++)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
const int maxn=1e5+5;
const int mod=1e9+7;
int main(){
    fastio;
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    int ans = 0;
    for(int i=0;i<n;++i){
        if(a[i]==i+1 && i!=n-1){
            int tmp = a[i];
            a[i] = a[i+1];
            a[i+1] = tmp;
            ans++;
        }
        else if(a[i]==i+1 && i==n-1){
            int tmp = a[i];
            a[i] = a[i-1];
            a[i-1]=tmp;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}    


Measured memory_bytes: 640
import java.util.Scanner;

import static java.lang.Math.min;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] b = new int[n];
        int ans = 0;

        for (int i = 0; i < n-1; i++) {
            b[i] = sc.nextInt();
        }

        ans += b[0];
        ans += b[n-2];

        for (int i = 1; i < n; i++) {
            ans += min(b[i], b[i - 1]);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x << " "
#define E puts("")
using namespace std;
typedef long long LL;
inline int getint() {
	int a = 0, f = 1; char c = getchar();
	while (c > '9' || c < '0') { if (c == '-') f = -1; c = getchar();}
	while (c <= '9' && c >= '0') { a = a * 10 + c - '0'; c = getchar();}
	return a * f;
}

const int MAXN = 100000 + 2;
struct Node {
	int Y, P, id;
	int ist;
}a[MAXN];
bool cmp(Node a, Node b) {
	if (a.P == b.P) return a.Y < b.Y;
	return a.P < b.P;
}
bool cmp2(Node a, Node b) {
	return a.id < b.id;
}

void print(int x) {
	int cnt = 1, xx = x;
	while (xx /= 10) cnt++;
	cnt = 6 - cnt;
	while (cnt--) printf("0");
	printf("%d", x);
}

int main(int argc, char const *argv[]) {
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	int N = getint(), M = getint();
	for (int i = 1; i <= M; i++) {
		a[i].P = getint(); a[i].Y = getint();
		a[i].id = i;
	}
	sort(a + 1, a + 1 + M, cmp);
	// for (int i = 1; i <= M; i++) cout << a[i].P << " ";
		// E;
	for (int i = 1; i <= M; i++) {
		if (a[i].P == a[i - 1].P) a[i].ist = a[i - 1].ist + 1;
		else a[i].ist = 1;
	}
	sort(a + 1, a + 1 + M, cmp2);
	for (int i = 1; i <= M; i++) {
		print(a[i].P); print(a[i].ist);
		E;
	}
	return 0;
}

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

using namespace std;
using ll = long long;

ll di(vector<ll> &A, int len) {
  ll ret{};
  for (ll &a : A) ret += (a - 1) / len + 1;
  return ret;
}

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll &a : A) cin >> a;
  int lower{0}, upper{1000000001};
  while (upper - lower > 1) {
    auto mid = lower + (upper - lower) / 2;
    if (di(A, mid) <= N + K) {
      upper = mid;
    } else {
      lower = mid;
    }
  }
  cout << upper << endl;
}


Measured memory_bytes: 4752
from fractions import gcd

n,m = map(int,input().split())
s = input()
t = input()
if n==m:
    if s!=t:
        print('-1')
        exit()
    else:
        print(n)
        exit()
elif n<m:
    n,m = m,n
    s,t = t,s
# n>m
if n%m==0:
    k = n//m
    if s[::k]==t:
        print(n)
        exit()
    else:
        print('-1')
        exit()
else:
    g = gcd(n,m)
    if s[::n//g]==t[::m//g]:
        print(n*m//gcd(n,m))
    else:
        print(-1)


Measured memory_bytes: 5856
#include <stdio.h>
#define N 100

int main()
{	
	int n,i,j,u,k,num,out[N][100];

	scanf("%d",&n);

	for(i = 0;i < n;i++)
	{
		for(j = 0;j < n;j++)
		{
			out[i][j] = 0;
		}
	}

	for(i = 0;i < n;i++)
	{
		scanf("%d %d",&u,&k);

		u--;

		for(j = 0;j < k;j++)
		{
			scanf("%d",&num);
			num--;
			out[u][num] = 1;
		}
	}

	for(i = 0;i < n;i++)
	{

		for(j = 0;j < n;j++)
		{
			printf("%d",out[i][j]);
			if(j != n-1)printf(" ");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 20000;
struct Node{
    string city;
    int score;
    int id;
}A[maxn];

bool Cmp(Node a,Node b)
{
    if(a.city == b.city)
        return a.score > b.score;
    return a.city < b.city;
}

int main()
{
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> A[i].city >> A[i].score;
        A[i].id = i;
    }
    sort(A+1,A+1+n,Cmp);
    for(int i = 1;i <= n;i++){
        cout << A[i].id << endl;
    }
}

Measured memory_bytes: 512
#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>
#include<cstdint>

#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))
#define ALL(a)  (a).begin(),(a).end()


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


const ll MOD = INF + 7;
vector<ll> fac(300000);
vector<ll> fac_inv(300000);

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n & 1)ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;

    ll tmp = fac_inv[a - b] * fac_inv[b] % MOD;
    return tmp * fac[a] % MOD;
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    sort(ALL(a));

    fac[0] = 1;
    fac_inv[0] = 1;
    for(ll i = 0; i < 300000; i++){
        fac[i + 1] = fac[i] * (i + 1) % MOD;
        fac_inv[i + 1] = fac_inv[i] * mpow(i + 1, MOD - 2) % MOD;
    }

    ll res = 0;
    vector<ll> cnt_m(n, 0);
    rep(i, n){
        cnt_m[i] = comb(n - i - 1, k - 1);
    }
    vector<ll> cnt_M = cnt_m;
    reverse(ALL(cnt_M));
    rep(i, n){
        //cout << cnt_m[i] << " " << cnt_M[i] << endl;
        res += a[i] * cnt_M[i];
        res %= MOD;
        res -= a[i] * cnt_m[i];
        res %= MOD;
    }
    if(res < 0)res += MOD;
    cout << res << endl;
}



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

int main(){
	int n;
	cin >> n;
	vector<ll> p(n);
	for(int i=0;i<n;i++) {
		ll a;
		cin >> a;
		ll cnt = 0;
		while(1) {
			if(a%2==0) {
				a /= 2;
				cnt++;
			}else {
				break;
			}
		}
		p[i] = cnt;
	}
	sort(p.begin(),p.end());
	cout << p[0] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;
 
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

//最大公約数
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}

//最小公倍数
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}

typedef long long ll;

char str[100001];
int r[100001];

int main(){
	int n, a, b;
	
	cin >> n >> a >> b;
	
	scanf("%s", str);
	
	int k = 0, g = 0;
	
	
	REP(i,n){
		if (str[i] == 'a'){
			if (k+g < a+b){
				k++;
				r[i] = 1;
			}
		}
		else if (str[i] == 'b'){
			if (k+g < a+b && g < b){
				g++;
				r[i] = 1;
			}
		}
		
		if (r[i] == 1) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

int main(){
	int x1, y1, x2, y2, x3, y3, x4, y4, d;
	cin >> x1 >> y1 >> x2 >> y2;
	x3 = x2 + y1 - y2;
	y3 = y2 - x1 + x2;
	x4 = x3 + y2 - y3;
	y4 = y3 - x2 + x3;
	
/*	
	if(x1==y1){
		if(y1 < y2){
			d = y2- y1;
			x3 = x2-d; y3 = y2;
			x4 = x3; y4 = y1;
		}else{
			d = y1- y2;
			x3 = x2+d; y3 = y2;
			x4 = x3; y4 = y1;
		}
	}else{
		if(x1 < x2){
			d = x2- x1;
			x3 = x2; y3 = y2 + d;
			x4 = x1; y4 = y3;
		}else{
			d = x1- x2;
			x3 = x2; y3 = y2 - d;
			x4 = x1; y4 = y3;
		}
	}*/
	cout << x3 << " " << y3 << " "  << x4 << " "  << y4 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    int w, h, n, sx, sy;
    cin >> w >> h >> n >> sx >> sy;

    vector<vector<bool> > grid(h+2, vector<bool>(w+2, true));
    for(int y=1; y<=h; ++y){
        for(int x=1; x<=w; ++x){
            grid[y][x] = false;
        }
    }

    vector<int> len(n);
    vector<vector<int> > px(n), py(n);
    for(int i=0; i<n; ++i){
        cin >> len[i];
        px[i].resize(len[i]);
        py[i].resize(len[i]);
        for(int j=0; j<len[i]; ++j)
            cin >> px[i][j] >> py[i][j];
        grid[py[i][len[i]-1]][px[i][len[i]-1]] = true;
    }

    vector<vector<vector<int> > > dp(h+2, vector<vector<int> >(w+2, vector<int>(1<<n, INF)));
    multimap<int, tuple<int, int, bitset<5> > > mm;
    dp[sy][sx][0] = true;
    mm.insert(make_pair(0, make_tuple(sy, sx, 0)));

    while(!mm.empty()){
        int cost, y, x;
        bitset<5> bs;
        cost = mm.begin()->first;
        tie(y, x, bs) = mm.begin()->second;
        mm.erase(mm.begin());
        if(dp[y][x][bs.to_ulong()] < cost)
            continue;

        for(int i=0; i<n; ++i){
            for(int t=cost; t<len[i]; ++t){
                if(y == py[i][t] && x == px[i][t]){
                    bitset<5> bs2 = bs;
                    bs2[i] = true;
                    if(t < dp[y][x][bs2.to_ulong()]){
                        dp[y][x][bs2.to_ulong()] = t;
                        mm.insert(make_pair(t, make_tuple(y, x, bs2)));
                    }
                }
            }
        }

        for(int i=0; i<9; ++i){
            int y2 = y - 1 + i / 3;
            int x2 = x - 1 + i % 3;
            int cost2 = cost + 1;
            if(!grid[y2][x2] && cost2 < dp[y2][x2][bs.to_ulong()]){
                dp[y2][x2][bs.to_ulong()] = cost2;
                mm.insert(make_pair(cost2, make_tuple(y2, x2, bs)));
            }
        }
    }

    int ans = INF;
    for(int y=1; y<=h; ++y){
        for(int x=1; x<=w; ++x){
            ans = min(ans, dp[y][x][(1<<n)-1]);
        }
    }
    if(ans < INF)
        cout << ans << endl;
    else
        cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 1356
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
const ll MAXN = 1e5;
vector<bool> used(MAXN,false);

int cnt[1000];

int main(){
    int n; cin >> n;
    int a[n+1];
    int b[n+1];
    int c[n+1];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    for(int i = 1; i < n; i++){
        cin >> c[i];
    }
    int sum = 0;
    for(int i = 1; i <= n; i++){
        if(a[i] == a[i+1]-1){
            sum += (b[a[i]]+c[a[i]]);
        }
        else{
            sum += b[a[i]];
        }
    }
    cout << sum << endl;
    return 0;
}


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

int h[100005];

int main(void)
{
  	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
  	int n,k,num=0;
  	cin >> n >> k;
  	for(int i=1;i<=n;i++)
      	cin >> h[i];
  	for(int i=1;i<=n;i++)
      	if(h[i]>=k)
          	num++;
  	cout << num;
  	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pi;
ll cost = 0, A, B;
vector<pi> shops;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N, M;
	cin >> N >> M;
	for (int i = 1; i <= N; ++i){
		cin >> A >> B;
		shops.push_back(pi(A,B));
	}
	sort(shops.begin(),shops.end());
	for (int i = 0; i < shops.size(); ++i){
		if (shops[i].second >= M){
			cost += shops[i].first*M;
			M = 0;
			break;
		}
		else{
			cost += shops[i].first*shops[i].second;
			M -= shops[i].second;
		}
	}
	cout << cost << '\n';
	cout << flush;
	//for (int i = 0; i < 1e9; ++i){for (int j = 0; j < 1e9; ++j){}}
	
}

Measured memory_bytes: 2420
#include <iostream>
#include <cstring>
using namespace std;
const int maxn=2e5+10;
char s[maxn];
int main()
{
    cin>>s;
    int ans=0,len,i;
	len=strlen(s);
    for(i=0;i<len;i++)
	ans+=s[i]-'0';
    if(ans%9==0)
	cout<<"Yes"<<endl;
    else 
	cout<<"No"<<endl;
    return 0;
}

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

int main(){
    int n, x, ans;
    while(1){
        cin >> n >> x;
        if(n == 0 && x == 0){
            break;
        }
        
        ans = 0;
        for(int i = 1; i <= n; i++){
            for(int j = i + 1; j <= n; j++){
                for(int k = j + 1; k <= n; k++){
                    if((i + j + k) == x){
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;        
        
    }
}



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

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i=0;i<n;i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());

  string ans = "";

  for(int i=0;i<n;i++) {
    ans += s[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vl>;
using vii = vector<vi>;
using pii = pair<int, int>;

using vc = vector<char>;
using vcc = vector<vc>;
using vb = vector<bool>;
using vbb = vector<vb>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


const int MOD = 1e9 + 7;

// n は 2以上の素数表を返す
vb Primes(int n){
  vector<bool> res(n + 1, true);
  res.at(0) = false; res.at(1) = false;
  for(int i = 2; i <= sqrt(n); i++){
    if(res.at(i)){
      for(int j = 2 * i; j <= n; j += i){
        res.at(j) = false;
      }
    }
  }
  return res;
}


int main(){
  int x, y, z; cin >> x >> y >> z;
  int sum = x + y + z;
  cout << sum + MAX(MAX(x, y), z) * 9 << endl;
  return 0;
}

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

#define ll long long
#define vi vector<int>
#define vll vector<long long> 
#define str string 
#define ch char
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair

ll dp[3001][3001];
ll sums[3001][3001];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    int n; cin>>n;
    ll ar[n];
    
    for(int i=0; i<n; i++){
        cin>>ar[i];
    }
    if(n==1) {cout<<ar[0]; return 0;}
    sums[0][0] = ar[0];
    for(int i=1; i<n; i++){
        sums[0][i] = sums[0][i-1] + ar[i];
    }
    for(int s=0; s<n; s++){
        for(int i=0; i<n-s; i++){
            if(s==0) sums[i][i] = ar[i];
            else sums[i][i+s] = sums[0][i+s] - sums[0][i-1];
        }
    }
    for (int s=0; s<n; s++){
        for(int i=0; i<n-s; i++){
            int start = i;
            int end = i+s;
            if(s==0){
                dp[start][end] = ar[i];
            }
            else{
                dp[start][end] = max(sums[start+1][end]-dp[start+1][end] + ar[start], 
                                    sums[start][end-1]-dp[start][end-1] + ar[end]);
            }
        }
    }
    cout<<dp[0][n-1]-min(dp[1][n-1], dp[0][n-2]);
}



Measured memory_bytes: 95904
#include<bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define pqb         priority_queue<int>
#define pqs         priority_queue<int,vi,greater<int> >
#define MOD         1000000007
#define PI          3.1415926535897932384626
#define ps(x,y)     fixed<<setprecision(y)<<x
#define sortall(x)  sort(all(x))
#define w(x)        int x; cin>>x; while(x--)
#define fo(i,n)     for(ll i=0;i<n;i++)
#define fastio      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main() {
  fastio;
  string s;
  cin >> s;
  
  ll sum = 0;
  
  for (ll i=0; i<s.size(); i++) {
    sum += s[i] - 48;
  }
  
  if (sum % 9 == 0) {
      cout << "Yes";
  }
  else {
      cout << "No";
  }
  return 0;
}



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

int main() {
  int64_t N,a=2,b=1,c;
  cin>>N;
  for(int i=1;i<N;i++){
    c=a+b;
    a=b;
    b=c;
  }
  cout<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a;
  cin >> n >> a;
  if(n % 500 == 0){
    cout << "Yes";
    return 0;
  }
  if(n-((n/500)*500) <= a){
    cout << "Yes";
  }else{
    cout << "No";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <cstdlib>
#include <cmath>

using namespace std;



int main(void){
    
    int n,t,a;
    cin >> n >> t >> a;
    int i;
    long int h[n+1];
    for(i=1; i<=n; ++i) cin >> h[i];
    
    float cels[i];
    for(i=1; i<=n; ++i){
    cels[i] = t - h[i]*0.006;
    //cout << cels[i] << " ";
    }
    //cout << "\n";
    
    float dif,difmin=1000,ans;
    for(i=1; i<=n; i++){
        dif = abs( a - cels[i] );
        //cout << dif << " " << i << "\n";
        if(dif<difmin){
            ans=i;
            difmin=dif;
            //cout << ans << " "<< difmin << "\n";
        }
    }
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
SA = input()
SB = input()
SC = input()

S = [SA,SB,SC]

i = 0

while True:
    temp = S[i][0]
    S[i] = S[i][1:]
    if temp == 'a':
        i = 0
        res = 'A'
    elif temp == 'b':
        i = 1
        res = 'B'
    else:
        i = 2
        res = 'C'

    if S[i] == '':
        break

print(res)


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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = int64_t;
using ld = long double;
const ld EPS = 1e-9;
//const ll MOD = 924844033;
const ld PI = 3.141592653589793;
const int maxn = 300001;
const ll MOD = 1e9 + 7;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll pw(ll a, ll b) {
    ll res = 1;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = res * a % MOD;
        }
        a = a * a % MOD;
    }
    return res;
}

int used[maxn];
int mt[maxn];
int a[maxn];
array<int, 2> g[maxn];

int kuhn(int v, int i) {
    if (used[v] == i) {
        return 0;
    }
    used[v] = i;
    for (int to:g[v]) {
        if (mt[to] == -1) {
            mt[to] = v;
            return 1;
        }
    }
    for (int to:g[v]) {
        if (kuhn(mt[to], i)) {
            mt[to] = v;
            return 1;
        }
    }
    return 0;
}

ll weight_match(int n, int m, vector<int> order) {
    ll ans = 0;
    fill(mt, mt + m, -1);
    int z = 1;
    for (int v:order) {
        if (kuhn(v, z)) {
            ++z;
            ans += a[v];
        }
    }
    return ans;
}

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    auto solve = [](int _) {
        int n, h, w;
        cin >> n >> h >> w;
        mt19937 mt(123);
        vector<int> r(n), c(n);
        for (int i = 1; i <= n; ++i) {
            for (auto x:{r.data(), c.data(), a}) {
                cin >> x[i - 1];
            }
        }
        for (int i = 0; i < n; ++i) {
            g[i][0] = r[i] - 1;
            g[i][1] = c[i] + h - 1;
            shuffle(g[i].begin(), g[i].end(), mt);
        }
        vector<int> p(n);
        iota(p.begin(), p.end(), 0);
        sort(p.begin(), p.end(), [&](int x, int y) {
            return a[x] > a[y];
        });
        auto ans = weight_match(n, h + w, p);
        cout << ans;
    };


    fast_io();
    cout.precision(9);
    cout << fixed;
    auto start = chrono::steady_clock::now();
    for (int i = 1; i <= 1; ++i)solve(i);
    auto end = chrono::steady_clock::now();

    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);

}


Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define repa(i,a,n) for(int i=a;i<a+n;++i)
#define repb(i,a,n) for(int i=a;i>a-n;--i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef long long ll;
typedef pair<int,int> P;
map<P,ll> mp;
ll N,Q,A,B,C,D,E,F,G;
ll mod=1e9+7;
int row[40001],col[40001];
ll initial(int r,int c){
	return (A*r+B*c)%C;
}
ll value(int r,int c){
	if(mp.find(P(r,c))==mp.end()){
		return initial(r,c);
	}else{
		return mp[P(r,c)];
	}
}
int ro,inv;
void change(int &r,int &c){
	int nr,nc;
	if(inv==0){
		if(ro==0) nr=r,nc=c;
		if(ro==1) nr=c,nc=N+1-r;
		if(ro==2) nr=N+1-r,nc=N+1-c;
		if(ro==3) nr=N+1-c,nc=r;
	}else{
		if(ro==0) nr=N+1-r,nc=c;
		if(ro==1) nr=N+1-c,nc=N+1-r;
		if(ro==2) nr=r,nc=N+1-c;
		if(ro==3) nr=c,nc=r;
	}
	r=row[nr],c=col[nc];
}
void change2(int &r,int &c){
	int nr,nc;
	if(inv==0){
		if(ro==0) nr=r,nc=c;
		if(ro==1) nr=c,nc=N+1-r;
		if(ro==2) nr=N+1-r,nc=N+1-c;
		if(ro==3) nr=N+1-c,nc=r;
	}else{
		if(ro==0) nr=N+1-r,nc=c;
		if(ro==1) nr=N+1-c,nc=N+1-r;
		if(ro==2) nr=r,nc=N+1-c;
		if(ro==3) nr=c,nc=r;
	}
	r=nr,c=nc;
}
void showmat(){
	show(ro);
	show(inv);
	for(int r=D;r<=E;r++){
		for(int c=F;c<=G;c++){
			int tmpr=r,tmpc=c;
			change(tmpr,tmpc);
			cout<<value(tmpr,tmpc)<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
}
int main(){
	cin>>N>>Q>>A>>B>>C>>D>>E>>F>>G;
	rep1(i,N) row[i]=i,col[i]=i;
	int X=E-D+1,Y=G-F+1;
	ro=0,inv=0;
	rep(i,Q){
		string type;
		cin>>type;
		if(type=="WR"){
			int r,c,v;
			cin>>r>>c>>v;
			change(r,c);
			mp[P(r,c)]=v;
		}
		if(type=="CP"){
			int r1,c1,r2,c2;
			cin>>r1>>c1>>r2>>c2;
			change(r1,c1);
			change(r2,c2);
			mp[P(r2,c2)]=value(r1,c1);
		}
		if(type=="SR"){
			int r1,r2,c1=0,c2=0;
			cin>>r1>>r2;
			change2(r1,c1);
			change2(r2,c2);
			// show(r1);
			// show(r2);
			// show(c1);
			// show(c2);
			if(c1==c2) swap(row[r1],row[r2]);
			if(r1==r2) swap(col[c1],col[c2]);
		}
		if(type=="SC"){
			int r1=0,r2=0,c1,c2;
			cin>>c1>>c2;
			change2(r1,c1);
			change2(r2,c2);
			if(c1==c2) swap(row[r1],row[r2]);
			if(r1==r2) swap(col[c1],col[c2]);
		}
		if(type=="RL"){
			ro=(ro+1)%4;
		}
		if(type=="RR"){
			ro=(ro+3)%4;
		}
		if(type=="RH"){
			if(ro%2==0){
				inv=1-inv;
			}else{
				inv=1-inv;
				ro=(ro+2)%4;
			}
		}
		if(type=="RV"){
			if(ro%2==0){
				inv=1-inv;
				ro=(ro+2)%4;
			}else{
				inv=1-inv;
			}
		}
//		showmat();
	}
	ll h=314159265;
	for(int r=D;r<=E;r++) for(int c=F;c<=G;c++){
		int tmpr=r,tmpc=c;
		change(tmpr,tmpc);
		h=h*31+value(tmpr,tmpc);
		h%=mod;
	}
	cout<<h<<endl;
}

Measured memory_bytes: 2164
/**
 * File              : E.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 09.02.2020
 * Last Modified Date: 09.02.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const AL = 26;

int main() {
  	ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    vector<vector<int>> dp(s.size()+1, vector<int>(AL, s.size()));
    for (int i = (int)s.size() - 1; i >= 0; --i) {
        for (int j = 0; j < AL; j++) {
            dp[i][j] = dp[i + 1][j];
        }
        dp[i][s[i] - 'a'] = i;
    }
    ll ans = 0;
    int j = 0;
    while (j < (int)t.size()) {
        int pos = 0;
        if (pos == 0 && dp[pos][t[j] - 'a'] == (int)s.size()) {
            cout << -1;
            return 0;
        }
        while (j < (int)t.size() && pos != (int)s.size()) {
            pos = dp[pos][t[j] - 'a'];
            if (pos != (int)s.size()) {
                j++;
                pos++;
            }
        }
        ans += pos;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 13776