akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

void visit(ll v, vector<ll>& out_costs, vector<ll>& costs, vector<vector<ll>>& graph, vector<bool>& visited) {
	visited[v] = true;
	out_costs.push_back(costs[v]);
	for (ll to : graph[v]) {
		if (visited[to]) {
			continue;
		}
		visit(to, out_costs, costs, graph, visited);
	}
}

int main() {
	ll N, M;
	cin >> N >> M;
	vector<ll> costs(N);
	rep(i,0,N) {
		cin >> costs[i];
	}
	vector<vector<ll>> graph(N);
	rep(i,0,M) {
		ll a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	vector<bool> visited(N);
	vector<vector<ll>> comp_costs;
	rep(v,0,N) {
		if (!visited[v]) {
			vector<ll> out_costs;
			visit(v, out_costs, costs, graph, visited);
			comp_costs.push_back(move(out_costs));
		}
	}
	if (comp_costs.size() == 1) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	vector<ll> costs_removed;
	costs_removed.reserve(N);
	rep(i,0,comp_costs.size()) {
		vector<ll>& costs = comp_costs[i];
		sort(costs.rbegin(), costs.rend());
		if (costs.empty()) {
			cout << "Impossible" << endl;
			return 0;
		}
		ans += costs.back();
		costs.pop_back();
		copy(costs.begin(), costs.end(), back_inserter(costs_removed));
	}
	sort(costs_removed.begin(), costs_removed.end());
	rep(i,0,comp_costs.size()-2) {
		if (i >= costs_removed.size()) {
			cout << "Impossible" << endl;
			return 0;
		}
		ans += costs_removed[i];
	}
	cout << ans << endl;
}



Measured memory_bytes: 10036
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){
int x,y;
  cin>>x>>y;
  int a[13] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  cout<<(a[x]==a[y] ? "Yes" : "No");
      
}
// int *p = new int[N];

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define INF 0x3f3f3f3f 
#define MEM(x,y) memset(x,y,sizeof(x))
#define int long long
#define rep(i , a , b) for(int i = a ; i <= b ; i ++)
#define P pair<int,int>
#define  sc(a) scanf("%lld",&a)
#define pf(a) printf("%lld ",a)
using namespace std;
signed main()
{
	int a, b;
	char c;
	scanf("%lld %c %lld", &a, &c, &b);
	if (c == '+')
		cout << a + b;
	else
		cout << a - b;

}











Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main () {
  string S;
  cin >> S;
  if (S.length() % 2 != 0) {
    printf("No\n");
  } else {
    int count = 0;
    for (int i = 0; i < S.length(); i+=2) {
      if (S[i] != 'h' || S[i+1] != 'i') {
        ++count;
        break;
      }
    }
    if (count == 0) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#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 srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 405;

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

ll add(ll x,ll y)
{
    return (x + y)%MOD;
}

ll sub(ll x,ll y)
{
    return (x+MOD-y)%MOD;
}

ll mul(ll x,ll y)
{
    return x*y%MOD;
}

int sm[MAX_N][MAX_N];
int dp[MAX_N][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,c;
    cin >> n >> c;
    vi a(n),b(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    rep(i,401){
        rep(j,401){
            sm[i+1][j] = add(sm[i][j],mod_pow(i+1,j));
        }
    }
    dp[0][0] = 1;
    rep(i,n){
        rep(j,c+1){
            rep(k,c+1-j){
                dp[i+1][j+k] = add(dp[i+1][j+k],mul(dp[i][j],sub(sm[b[i]][k],sm[a[i]-1][k])));
            }
        }
    }
    cout << dp[n][c] << "\n";
    return 0;
}


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

using namespace std;

#define forn(i, s, f) for(int i = (s); i <= (f); ++i)
#define for1(i, f, s) for(int i = (f); i >= (s); --i)
#define fora(i, x) for (auto i : x)
#define show(x) cout << #x << " = " << x << " ";
#define skip continue;
#define pb push_back
#define _1 first
#define _2 second

typedef long long ll;

const int N3 = 1e3 + 5;
const int N4 = 1e4 + 5;
const int N5 = 1e5 + 5;
const int N6 = 1e6 + 5;
const int N7 = 1e7 + 5;
const int N8 = 1e8 + 5;
const int N9 = 1e9 + 5;
const int mod = N9 + 2;

int n, x, odd;

int main()
{
    cin >> n;
    forn (i, 1, n)
    {
        cin >> x;
        if (x % 2 == 1)
        {
            ++odd;
        }
    }
    cout << (odd % 2 == 0 ? "YES" : "NO");
}


Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int flag = 0;
  char s[110];
  scanf("%s", s);
  for (int i = 0; i < strlen(s); i++)
  {
    if ((i % 2 == 0 && s[i] == 'L') || (i % 2 != 0 && s[i] == 'R'))
      flag = 1;
  }
  puts(flag == 0 ? "Yes" : "No");
}

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

int main()
{
	string str;
	cin>>str;
	for(int i=1;i<str.size();i++)
	{
		if(str[i]==str[i-1])
		{
			cout<<i<<" "<<i+1<<endl; 
			return 0;
		}
	}
	for(int i=2;i<str.size();i++)
	{
		if(str[i]==str[i-2])
		{
			cout<<i-1<<" "<<i+1<<endl;
			return 0;
		}
	}
	cout<<"-1 -1"<<endl;
	return 0;
}

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

bool is_prime(int x) {
  if (x==1) false;
  for (int i=2; i*i<=x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}

int main() {
  int x; cin >> x;
  while(!is_prime(x)) {
    x++;
  }
  cout << x << endl;
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int64_t N;
	cin >> N;

	int64_t result = N-1;
	for( int i = (int)sqrt(N); i > 0; --i ) {
		if( N % i == 0 ) {
			result = N/i-1 + i-1;
			break;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

x=0
p_alice=0
p_bob=0

while (x < n):
    if(x%2==0):
        p_alice += a[x]
    else:
        p_bob += a[x]
    x+=1

print(p_alice-p_bob)

Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e9+1;

int main(){
    ll n;
    cin >> n;
    cout << n/3 << endl;
    return 0;
} 

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

int N;
int A[210];

int main(){
	cin >> N;
  for (int i = 0; i< N ; ++i) cin >> A[i];
  
  int res = 0;
  
  while(true){
  bool exist_odd = false;
  for(int i = 0; i < N;++i){
  	if(A[i]%2!=0) exist_odd = true;
  }
    
    if(exist_odd) break;
    
    for(int i = 0; i<N;++i){
    	A[i]/=2;
    }
  ++res;
  }
  
  cout << res << endl;
  


}

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

#define INF 1e9
using namespace std;

int main() {

    int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
    int k; cin >> k;

    if (e - a <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector< vector<int> > VVI;
typedef vector< vector<int> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VL A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];
  ll ans=0;
  reverse(all(A));
  reverse(all(B));
  rep(i,N){
    A[i]+=ans;
    if(A[i]%B[i]) ans+=B[i]-A[i]%B[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

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

    if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    int a, b, cnt = 0;
    cin >> a >> b;
    for (int i = a; i <= b; ++i) {
        int x = i;
        string s;
        while (x > 0) {
            int t = x % 10;
            x /= 10;
            s.push_back(t+'0');
        }
        string s2 = s;
        reverse(s2.begin(), s2.end());
        if (s == s2) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

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

    vector<int> m(N);

    for (int i = 0; i < N; i++) cin >> m[i];

    int min = *std::min_element(m.begin(), m.end());
    int sum = accumulate(m.begin(), m.end(), 0);

    cout << N + (X - sum) / min << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000000;
const int INF = (1 << 30);

int main()
{
  vector<int> dp(MAX, INF), odddp(MAX, INF);
  dp.at(0) = 0;
  odddp.at(0) = 0;
  for (int i = 1;; i++)
  {
    int num = (i * (i + 1) * (i + 2)) / 6;
    if (num >= MAX)
    {
      break;
    }
    for (int j = num; j < MAX; j++)
    {
      dp.at(j) = min(dp.at(j), dp.at(j - num) + 1);
      if (num & 1)
      {
        odddp.at(j) = min(odddp.at(j), odddp.at(j - num) + 1);
      }
    }
  }
  while (1)
  {
    int n;
    cin >> n;
    if (!n)
    {
      break;
    }
    cout << dp.at(n) << " " << odddp.at(n) << endl;
  }
}


Measured memory_bytes: 10472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	double a,b,n;
	cin>>a>>b>>n;
	double i=min(b-1,n);
	cout<<floor(a*i/b)-a*floor(i/b)<<endl;
	return 0;
}

Measured memory_bytes: 3784
#include <stdio.h>

int main(void) {
  double a,b,c,d,e,f;
  double x,y;
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
  	y=(c*d-a*f)/(b*d-a*e)*1.0;
  	x=1.0*(c-b*y)/a;
  	
 	printf("%.3f ",x+0.0004);
  	printf("%.3f\n",y+0.0004);
  }
  
	return 0;
}

Measured memory_bytes: 656
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (int)3e5 + 17;
const int mod = (int)1e9 + 7;
const int OFFSET = 5;

int n, suff[MAXN];
string s;

void read()
{
	cin >> s;
	n = s.size();
}

int dp[MAXN][10][4];

int rec(int pos, int len, int bd)
{
	if(bd > 2)
	{
		if(bd % 2 == 0) len += (bd - 2), bd = 2;
		if(bd % 2 == 1) len += (bd - 1), bd = 1;
	}

	if(bd < 0) bd = 0;
	if(len > 4) len = 4;

	if(pos == n)
	{
		if(len > 0) return 1;
		return 0;
	}

	int &memo = dp[pos][len + OFFSET][bd];
	if(memo != -1) return memo;
	memo = 0;

	if(s[pos] == '1' || s[pos] == '?') memo = (memo + rec(pos + 1, len + 1, bd - 1)) % mod;
	if(s[pos] == '0' || s[pos] == '?') memo = (memo + rec(pos + 1, len - 1, bd + 1)) % mod; 
	return memo;
}

void solve()
{
	suff[n] = 1;
	for(int i = n - 1; i >= 0; i--)
	{
		suff[i] = suff[i + 1];
		if(s[i] == '?') suff[i] = (2ll * suff[i + 1]) % mod;
	}

	memset(dp, -1, sizeof(dp));
	cout << rec(0, 0, 0) << endl;
}

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

	read();
	solve();
	return 0;
}



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

int main(int argc, const char * argv[]) {
    
    int a=0,b=0,c=0;
    string s;
    
    cin >> s;
    for(int i=0;i<3;i++){
        if(s[i]=='a') a++;
        if(s[i]=='b') b++;
        if(s[i]=='c') c++;
    }
    
    if(a==1 && b==1 && c==1) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var row = input.split('\n');
var finalResult = [];
for(var i=0;i<row.length;i++){
    var result = row[i].split(' ').map(Number);
    var m = result[0];
    var f = result[1];
    var r = result[2];
    if(m === -1 && f === -1 && r === -1){
        break;
    }
    var total = m+f;
    if(m === -1 || f === -1){
        var grade = 'F';
        finalResult.push(grade);
    }
    else if(total >= 80){
        var grade = 'A';
        finalResult.push(grade);
    }
    else if(total >= 65 && total <80){
        var grade = 'B';
        finalResult.push(grade);
    }
    else if(total >=50 && total <65){
        var grade ='C';
        finalResult.push(grade);
    }
    else if(total >=30 && total <50 && r>=50){
        var grade ='C';
        finalResult.push(grade);
    }
    else if(total >=30 && total <50){
        var grade ='D';
        finalResult.push(grade);
    }
    else{
        var grade = 'F';
        finalResult.push(grade);
    }
}
console.log(finalResult.join('\n'));


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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;


const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

int		main(void)
{
	std::ios_base::sync_with_stdio(false);
	int	N;
	std::cin >> N;

	vi	A(N), B(N), C(N);
	for (auto &v : A) std::cin >> v;
	for (auto &v : B) std::cin >> v;
	for (auto &v : C) std::cin >> v;
	std::sort(all(A));
	std::sort(all(B));
	std::sort(all(C));


	ll	dp[3][(int)1e5+1] = {};

	for (int i(1); i <= N; ++i)
		dp[2][i] = i;

	int		p2(0);
	for (int i(0); i < N; ++i)
	{
		while (p2 < N and A[p2] < B[i]) ++p2;
		dp[1][i+1] = dp[1][i] + dp[2][p2];
	}

	p2 = 0;
	for (int i(0); i < N; ++i)
	{
		while (p2 < N and B[p2] < C[i]) ++p2;
		dp[0][i+1] = dp[0][i] + dp[1][p2];
	}
	pnl(dp[0][N]);
}



Measured memory_bytes: 3840
S = input()
T = input()
s_list = []
for i in range(len(S)):
    if i+len(T) > len(S):
        break
    j=0
    for _ in range(len(T)):
        if S[i+j] == '?' or S[i+j] == T[j]:
            j+=1
            continue
        break
    if j==len(T):
        s_list.append(S[:i] + T + S[i+len(T):])
if len(s_list) > 0:
    s_list.sort()
    print(s_list[0].replace('?', 'a'))
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
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;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    string s;cin>>s;
    ll k;cin>>k;
    rep(i,s.size()){
        if(s[i]!='a'){
            ll need='z'-s[i]+1;
            if(need<=k){
                k-=need;
                s[i]='a';
            }
        }
    }
    s[s.size()-1]=(char)((s[s.size()-1]-'a'+k)%26+'a');
    out(s);
}

Measured memory_bytes: 3820
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
ll are[100003]={};
ll rui[100003]={};
int alre[100003]={};
int main(){
	ll N,X,M;
	scan(N>>X>>M);
	ll now=X;
	ll sum=X;
	are[1]=X;
	rui[1]=X;
	alre[X]=1;
	for(int i=2;i<=INF;i++){
		now=now*now%M;
		sum+=now;
		rui[i]=sum;
		are[i]=now;
		if(i==N){
			prin(sum);
			return 0;
		}
		if(alre[now]>0){
			ll inisum=rui[alre[now]-1];
			ll loopnum=(i-1)-(alre[now]-1);
			ll loopsum=rui[i-1]-rui[alre[now]-1];
			ll amarisum=(N-(alre[now]-1))/loopnum*loopsum;
			ll amarinum=(N-(alre[now]-1))%loopnum;
			rep(j,amarinum){
				amarisum+=are[alre[now]+j];
			}
			ll ans=inisum+amarisum;
			prin(ans);
			return 0;
		}
		alre[now]=i;
	}
	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

int N, M, X;
int books[12][13];
ll ans = INF;

void solve() {
    cin >> N >> M >> X;
    for (int i = 0; i < N; i++) {
		for (int j = 0; j < M + 1; j++) {
			cin >> books[i][j];
		}
	}
    
    for (int i = 0; i < (1ll << N); i++) {
		vector<ll> skills(M, 0);
		ll cost = 0;
		for (int j = 0; j < N; j++) {
			if (i & (1 << j)) {
				cost += books[j][0];
				for (int k = 1; k < M + 1; k++) skills[k - 1] += books[j][k];
			}
		}	
		
		// cout << cost << "\n";
		bool pos = true;
		for (int j = 0; j < M; j++) {
			if (skills[j] < X) {
				// cout << "broke on " << j << "\n";
				pos = false;
				break;
			}
		}
		if (pos) chmin(ans, cost);
	}
    
    if (ans == INF) cout << -1;
    else cout << ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 3660
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int sy[4] = { 0,1,0,-1 };

#define atcoder (int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)

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

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

ll dp[100010] = { 0 };

int main(){
	
	string s;
	cin >> s;
	s[3] = '8';
	pr(s);


	return 0;
}

Measured memory_bytes: 256
N=int(input())
X=[int(i) for i in input().split()]
dX=[]
for i in range(N-1):
  dX.append(X[i+1]-X[i])
M,K=map(int,input().split())
A=[int(i)-2 for i in input().split()]
Swap=[list(range(N-1)) for i in range(61)]
for a in A:
  Swap[0][a],Swap[0][a+1]=Swap[0][a+1],Swap[0][a]
for k in range(60):
  for i in range(N-1):
    Swap[k+1][i]=Swap[k][Swap[k][i]]
C=list(range(N-1))
for k in range(61)[::-1]:
  if K&(1<<k):
    for i in range(N-1):
      C[i]=Swap[k][C[i]]
new_dX=[0]*(N-1)
for i in range(N-1):
  new_dX[i]=dX[C[i]]
S=X[0]
print(X[0])
for i in range(N-1):
  S+=new_dX[i]
  print(S)


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


int main(){
  int n,i,z,j;
  long long mod=1000000007;
  z=0;
  long long k;
  cin >> n >> k;
  vector<int> a(n),b(n);
  for(i=0;i<n;++i){
    cin >> a[i];
    b[i]=a[i];
  }
  long long ansp,ansq;
  ansp=ansq=0;
  for(i=0;i<n;++i){
    for(j=i+1;j<n;++j){
      if(a[i]>a[j]){
        ansp++;
      }
    }
  }
  for(i=0;i<n;++i){
    for(j=0;j<n;++j){
      if(a[i]>b[j]){
        ansq++;
      }
    }
  }
  long long ans=0;
  ans +=ansp*k;
  ans %=mod;
  ans +=(((k*(k-1)/2)%mod)*ansq)%mod;

  ans=ans%mod;
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std ;
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
ll in()
{
  ll x = 0 , f = 1 ;
  char ch = getchar() ;
  while(!isdigit(ch)) {if(ch == '-') f = -1 ; ch = getchar() ;}
  while(isdigit(ch)) x = x * 10 + ch - 48 , ch = getchar() ;
  return x * f ;
}
int a[N] ;
unordered_map<int , int> mp ;
int main()
{
  ll n = in() , k = in() ;
  for(int i = 1; i <= n ;i ++ ) a[i] = in() ;
  vector<int> v ;
  v.push_back(1) ;
  mp[1] = 1 ;
  int t = 1 ;
  int pos = 1 ;
  while(1)
   {
     t = a[t] ;
     if(!mp[t]) v.push_back(t) , mp[t] = 1 ;
     else
      {
        pos = t ;
        break ;
      }
   }
  for(int i = 0 ;i < v.size() ;i ++ )
   {
     if(v[i] == pos)
      {
        pos = i ;
        break ;
      }
   }
   int len = v.size() - pos ;
   if(k <= pos)
    cout << v[k] << endl ;
   else
    {
      k -= pos ;
      k %= len ;
      cout << v[k + pos] << endl ;
    }
  return 0 ;
}
/*
*/


Measured memory_bytes: 11900
var cc : array [0..100000] of int64 ;
    n,a,b,c,d,e,f,g : longint;
    h,i,j,k,x,sum : int64 ;
begin
 readln(n,x);
// writeln(sum,cc[1]:2,cc[2]:2,cc[3]:2);
 for a:=1 to n do
  read(cc[a]);
// writeln(sum,cc[1]:2,cc[2]:2,cc[3]:2);
 for b:=1 to n-1 do
  begin
// writeln(j,sum:2,cc[1]:2,cc[2]:2,cc[3]:2);
   j:=x;
   if cc[b]+cc[b+1]>j then
    begin
    if cc[b]>j then
     begin
      sum:=sum+(cc[b]-j);
      cc[b]:=cc[b]-(cc[b]-j) ;
     end;
    if cc[b]+cc[b+1]>j then
    begin
     k:=cc[b]+cc[b+1];
     if k-cc[b+1]<=j then
      begin
       sum:=sum+(k-j);
       cc[b+1]:=cc[b+1]-(k-j);
      end
     else if k-cc[b+1]>j then
      begin
       sum:=sum+cc[b+1];
       k:=k-cc[b+1];
       cc[b+1]:=0;
       sum:=sum+(k-j);
      end;
{    if cc[b+1]-j>=0 then
     begin
      sum:=sum+(cc[b+1]-j);
      writeln('hey',sum);
      cc[b+1]:=j;
     end
    else
     begin

      sum:=sum+cc[b+1];
      j:=j-cc[b+1];
      cc[b+1]:=0;
      sum:=sum+j;
      cc[b]:=cc[b]-j;

     end; }
    end;
//    writeln(sum);
   end;
  end;
 writeln(sum);
end.


Measured memory_bytes: 896
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n, k;
	cin >> n;
	char* s = new char[n];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}

	cin >> k;
	for (int i = 0; i < n; i++) {
		if (s[k - 1] != s[i]) {
			cout << '*';
		}
		else {
			cout << s[i];
		}
	}
	return 0;

}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  // 初期値
  int x, y;
  
  // Main loop
  while(1){
    cin >> x >> y;
    if ( x == 0 && y == 0){
      break;
    }
    if (x <= y){
      cout << x << " " << y << endl;
    } else {
      cout << y << " " << x << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 2948
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string s,t; cin>>s>>t;
  	if(s.at(0)==t.at(2) && s.at(1)==t.at(1) && s.at(2)==t.at(0)){
    	cout<<"YES"<<endl;
    }else{
    	cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
function Main(input) {
  input=input.split("\n");
　const a=input[0]-0;
　const b=input[1]-0;
　const h=input[2]-0;
  
　
  console.log((a+b)*h/2);
  
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


Measured memory_bytes: 29588
a = input()
b = input()
s = 0 
for i in range(len(a)):
    b = b[-1] + b[:-1]
    if a == b:
        s = 1
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')
y(s,1)

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    string S;
    cin >> S;
    int zerocount = 0;
    int onecount = 0;
    REP(i, S.length())
    {
        if(S[i] == '0') zerocount++;
        else onecount++;
    }
    cout << min(zerocount, onecount) * 2 << endl;

}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int N, K;
	cin >>N >>K;
	vector<int> P(N, 0);
	Rep0(i, N)
		cin >>P.at(i);
	int S=0;
	Rep0(i, K)
		S +=P.at(i);
	int S0=S;
	for (int i=K, j=0; i<N; i++, j++) {
		S +=-P.at(j)+P.at(i);
		S0=max(S0, S);
	}
	S0 +=K;
	cout <<fixed <<setprecision(10) << (double)S0/2.0 <<endl;
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include<string>
#include <cassert>
#include <algorithm>
#include <functional>
using namespace std;


int main() {
	int A, B, C;

	cin >> A >> B >> C;
	int sum = A + B + C;
	if (sum >= 22) {
		cout << "bust";
	}
	else if (sum <= 21) {
		cout << "win";
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N, M;
  cin >> N >> M;
  ll macci[10] = {0, 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6};
  vector<ll> as(M);
  set<ll> can;
  for (auto i = 0; i < M; i++) {
    ll x;
    cin >> x;
    can.insert(x);
  }

  vector<string> dp(N+100, "");
  for (auto x : can) {
//    dp[macci[x]] = max(dp[macci[x]], x);
    dp[macci[x]] = to_string(x);
  }
  for (auto i = 0; i < N; i++) {
    if (dp[i] == "") continue;
    ll total_digit = 0;
    ll less_digit = 0;
//    for (ll tmp = dp[i]; tmp > 0; tmp /= 10) total_digit++;
    for (auto x : can) {
      auto leq_idx = 0;
      for (auto leq_idx = 0; leq_idx < dp[i].size(); leq_idx++) {
        if (x <= static_cast<ll>(dp[i][leq_idx] - '0')) break;
      }
      string new_num = dp[i].substr(0, leq_idx) + (char)(x + '0') + dp[i].substr(leq_idx);
//      cout << "dp[" << i << "]=" << dp[i] << ", x=" << x
//           << ", dp[" << i + macci[x] << "]=max(" << new_num << ", " << dp[i + macci[x]] << ")" << endl;
      if (new_num.size() > dp[i+macci[x]].size() || new_num > dp[i + macci[x]]) dp[i + macci[x]] = new_num;
//        dp[i + macci[x]] = max(dp[i + macci[x]], new_num);
//      for (less_digit = total_digit-1; less_digit >= 0; less_digit--) {
//        if (x >= ((dp[i] >> less_digit) % 10)) break;
//      }
//      ll new_num;
//      if (less_digit < 0) new_num = dp[i] * 10 + x;
//      else new_num = (((dp[i] >> less_digit) * 10 + x) << less_digit) + (dp[i] % (1 << (less_digit + 1)));
//      dp[i + macci[x]] = max(dp[i + macci[x]], new_num);
    }
  }

  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 29696
#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string, int> table;
int main()
{
  string /*入力用*/ word, /*最大頻度*/ frequent, /*最長*/ longest;
  size_t N = 0; /*文字列frequentの頻度*/
  while (cin >> word)
  {
    table[word] += 1;
    // table[word] を一つ増やす
    if(table[word] > N){
      N = table[word];
      frequent = word;
    }
    // table[word] がN より大きければ，N とfrequent を更新
    if(word.size() > longest.size()){
      longest = word;
    }
    // word.size() > longest.size() ならlongest を更新
  }
  cout << frequent << " " << longest << endl;
  //frequent とlongest を出力
}


Measured memory_bytes: 3068
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  mapM_ putStrLn . map (map toLEL) . f n $ 0

f :: Int -> Int -> [[Int]]
f n m = concatMap g [0..m]
  where
    g = case n of
          1 -> pure . pure
          _ -> map <$> (:) <*> f (pred n) . max m . succ

toLEL :: Int -> Char
toLEL = toEnum . (fromEnum 'a' +)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 11900
#include<stdio.h>
int main(){

    int n,taka,i,j,temp,sum=0,p;
    scanf("%d%d",&n,&taka);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        sum=sum+a[i];
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(a[i]<a[j]){
                temp=a[j];
                a[j]=a[i];
                a[i]=temp;
            }
        }
    }
    taka=taka-sum;
    p=taka/a[0];
    p=p+n;
    printf("%d\n",p);
}



Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <climits>

//find out the use of the below
#include <list>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
vector<vector<LL> > dp(2, vector<LL>((int)1e5+1,INT_MAX));
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
    char a[3001], b[3001];
    scanf("%s\n%s", a, b);
    int na = strlen(a), nb = strlen(b);
    vector<vector<int> > dp(3001, vector<int>(3001, 0));
    for (int i = 0; i < na; i++){
        for (int j = 0; j < nb; ++j){
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            if (a[i] == b[j]){
                dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j+1]);
            }
        }
    }
    char ans[3001];
    MEM(ans);
    int len = dp[na][nb];
    int ia = na-1, ib = nb-1;
    for(int i = len-1; i >= 0; --i){

        while (1) {
            if (a[ia] == b[ib] && dp[ia+1][ib+1] == dp[ia][ib]+1){
                ans[i] = a[ia];
                ia--;
                ib--;
                break;
            } else if (dp[ia+1][ib+1]  == dp[ia+1][ib]){
               ib--;
            } else {
                ia--;
            }
        }
    }
    printf("%s", ans);
    return 0;
}
/* BEFORE submitting, check for:
 *  1. Integer overflow
 *  2. Float/Double precision errors
 *  3. Array index out of bounds
 *  4. Edge cases.(n=1, n=max, etc.)
 *  5. Time complexity. No TLEs
 */



Measured memory_bytes: 37104
import io,sys
sys.setrecursionlimit(10**6)

def main():
    from collections import Counter
    n = input()
    A = list(map(int,sys.stdin.readline().rstrip().split()))

    C = Counter(A)
    s = 0
    for k,v in C.items():
        s += k*v

    q = int(input())
    for _ in range(q):
        b,c = map(int,sys.stdin.readline().rstrip().split())
        s = s - C[b]*(b-c) 
        C[c]+=C[b]
        C[b]=0

        print(s)
main()

Measured memory_bytes: 24164
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def gcd(a,b):
    while b>0:a,b=b,a%b
    return a

def main():
    a,b=MI()
    print(a*b//gcd(a,b))

main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;


int main() {
	int n; cin >> n;
	vector<ll> a(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) a[i] += a[i - 1];
	sort(a.begin(), a.end());
	ll pos = 0, ans = 0;
	while (pos <= n) {
		ll w = pos + 1;
		while (w <= n && a[pos] == a[w]) w++;
		ans += (w - pos - 1)*(w - pos)/2;
		pos = w;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
typedef long long ll;
const ll MAX=510000;
const ll mod = 1e9 + 7;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll h[101010];
ll y[101010];
ll a[201010];
ll k[101010];
ll b[201010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
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;
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    cin>>P>>Q>>R;
    cout<<P+Q+R-max(P,max(Q,R))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//



//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  vector<int> vec(n) ;
  int ans ;
  
  vector<pair<int,int>> cntk(100001) ;
  vector<pair<int,int>> cntg(100001) ;
  
  REP(i,n){
    cin >>vec.at(i) ;
  }
  
  REP(i,100001){
    cntk.at(i) = MP(0,i) ;
    cntg.at(i) = MP(0,i) ;
  }
    
  
  REP(i,n){
    if(i%2==1){
      cntk.at(vec.at(i)).FI++ ;
    }
    else{
      cntg.at(vec.at(i)).FI++ ;
    }
  }
  
  sort(ALL(cntk)) ;
  sort(ALL(cntg)) ;
  
  reverse(ALL(cntk)) ;
  reverse(ALL(cntg)) ;
  
  if(cntk.at(0).SE!=cntg.at(0).SE){
    ans = n - cntk.at(0).FI - cntg.at(0).FI ;
  }
  
  else{
    int cnt1 = cntk.at(0).FI+cntg.at(1).FI ;
    int cnt2 = cntk.at(1).FI+cntg.at(0).FI ;
    int cnt = max(cnt1,cnt2) ;
    ans = n-cnt ;
  }

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



Measured memory_bytes: 2304
#include <iostream>

using namespace std;

int main(){
    char b;
    cin >> b;
    if(b=='A'){
        cout << 'T' << endl;
    }else if(b=='T'){
        cout << 'A' << endl;
    }else if(b=='C'){
        cout << 'G' << endl;
    }else if(b=='G'){
        cout << 'C' << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// 問題の URL を書いておく
// 

#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

int main(int, const char**)
{
    int n;
    cin >> n;
    vector<int> a(n);
    int mask = 0;
    rep(i, n)
    {
        cin >> a[i];
        mask ^= a[i];
    };
    rep(i, n)
    {
        cout << (a[i] ^ mask) << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3980
all_list = []

for i in range(6):
  a = int(input())
  if i < 5:
    all_list.append(a)
  else:
    k = a

M = max(all_list)
m = min(all_list)

if M - m <= k:
  print('Yay!')
else:
  print(':(')
        
  

Measured memory_bytes: 2940
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 100;
int cost[N][N][4];
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
string op="NESW";
char m[N][N];

void solve(int r,int c,int y,int x,int d,ll step){
  for(int i=0;i<r;i++)
    for(int j=0;j<c;j++)
      for(int k=0;k<4;k++)cost[i][j][k]=-1;
  int now = 0;
  while(true){
    if (cost[y][x][d] != -1){
      step%=(now-cost[y][x][d]);
    }else cost[y][x][d] = now;
    if (step == 0)break;
    step--;now++;
    while(x+dx[d] == -1 || x+dx[d] == c || y+dy[d] == -1 || y+dy[d] == r || 
	  m[y+dy[d]][x+dx[d]] == '#')d=(d+1)%4;
    x+=dx[d];
    y+=dy[d];
  }
  cout << y+1 <<" " << x+1 <<" " << op[d] << endl;
}

main(){
  int r,c;ll step;
  while(cin>>r>>c>>step && r){
    for(int i=0;i<r;i++)cin>>m[i];
    int sy,sx,d;
    for(int i=0;i<r;i++)
      for(int j=0;j<c;j++)
	if (m[i][j] == 'N')sy=i,sx=j,d=0;
	else if (m[i][j] == 'E')sy=i,sx=j,d=1;
	else if (m[i][j] == 'S')sy=i,sx=j,d=2;
	else if (m[i][j] == 'W')sy=i,sx=j,d=3;

    solve(r,c,sy,sx,d,step);
  }
}

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

long long M = 1000000007;

long long mult(long long a, long long b) {
    return (a * b) % M;
}

int main() {
    int t = 1;
    while(t--) {
        int n;
        cin>>n;
        vector<long long> arr(n), sum(n+1, 0);
        
        for(int i=0; i<n; i++) {
            cin>>arr[i];
            sum[i+1] += arr[i] + sum[i];
            sum[i+1] %= M;
        }        
        long long ans = 0;
        for(int i = 0; i<n; i++) {
            long long S = sum[n] - sum[i+1];
            if(S < 0) {
                S += M;
            }
            ans += mult(S, arr[i]);
            ans %= M;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 6424