akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
 
 
 
int main(){
 
  string s,t;
  cin >> s >> t;
  map<char,char> mp;
  rep(i,s.size())mp[s[i]] = t[i];
  for(char c = 'a';c <= 'z';c++){
    for(char ch = 'a';ch <= 'z';ch++){
      if(mp.count(c) == 0 || mp.count(ch) == 0 || c == ch)continue;
      if(mp[c] == mp[ch]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  rep(i,s.size())s[i] = mp[s[i]];
  cout << (s == t ? "Yes" : "No") << endl;
 
 
 
 
 
  return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 100000000000000

int main(){
  int K;
  cin>>K;
  vector<int> A(K);
  for(int i=0;i<K;i++){
    cin>>A.at(i);
  }
  reverse(A.begin(),A.end());
  bool flag=true;
  if(A.at(0)!=2){
    flag=false;
  }
  ll left=2;
  ll right=3;
  for(int i=1;i<K;i++){
    if(right<A.at(i)){
      flag=false;
    }
    ll x=right/A.at(i);
    if(x*A.at(i)<left){
      flag=false;
    }
    right=A.at(i)*(x+1)-1;
    left=((left-1)/A.at(i)+1)*A.at(i);
  }
  if(flag){
    cout<<left<<" "<<right<<endl;
  }else{
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 640
//
//  main.cpp
//  Chokudai_Contest_004
//
//  Created by tolemy on 2019/08/31.
//  Copyright © 2019 tolemy. All rights reserved.
//

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef pair<int, int> job;

#define rep(i, start, end) for (int i = (int)(start); i < (int)(end); i++)

int main(int argc, const char *argv[])
{

    string s = "";
    cin >> s;

    rep(i, 0, s.length())
    {
        if (i % 2 == 0)
        {
            switch (s[i])
            {
            case 'L':
                cout << "No" << endl;
                return 0;
            default:
                break;
            }
        }
        else
        {
            switch (s[i])
            {
            case 'R':
                cout << "No" << endl;
                return 0;
            default:
                break;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  ll a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  ll ans = 1ll<<61;
  ll po[3] = {0,x,y};
  REP(_i,3){
    ll i = po[_i];
    ll tmp = c*i*2ll;
    tmp += max(0ll,x-i)*a;
    tmp += max(0ll,y-i)*b;
    CHMIN(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define syakkin 100000
int main(void){
  int n,a,i;
  scanf("%d",&n);
  for(i=0,a=syakkin;i<n;i++){
    a *= 1.05;
    if(a%1000!=0)  a=a-a%1000+1000;
  }
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 592
N = int(input())
s = [[0 for i in range(N)] for j in range(26)]
for i in range(N):
    t = input()
    for j in range(len(t)):
        s[ord(t[j])-ord('a')][i] += 1
ans = ''
for j in range(26):
    ans += chr(j+ord('a')) * min(s[j])
print(ans)

Measured memory_bytes: 9176
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<size_t N> struct solve {

	lint lun[N + 5];

	constexpr solve() : lun() {

		for (int i = 1; i <= 9; i++) lun[i] = i;

		for (int st = 1, idx = 10; idx <= N; st++) {

			bool m_ok = (lun[st] % 10 != 0);
			lun[idx*m_ok] = lun[st] * 10 + lun[st] % 10 - 1;
			idx += m_ok;

			lun[idx++] = lun[st] * 10 + lun[st] % 10;

			bool p_ok = (lun[st] % 10 != 9);
			lun[idx*p_ok] = lun[st] * 10 + lun[st] % 10 + 1;
			idx += p_ok;

		}

	}

};

solve<100000> S;

int main() {

	int N;
	scanf("%d", &N);
	printf("%lld", S.lun[N]);

	return 0;
}


Measured memory_bytes: 256
N, M, C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(N)]

ans = 0
for i in range(N):
    SUM = 0
    for j in range(M):
        SUM += A[i][j]*B[j]
    SUM += C
    if SUM > 0:
        ans += 1
print(ans)

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

int count(int64_t num)
{
  int ret = 0;
  while (num % 2 == 0)
  {
    num /= 2;
    ++ret;
    if (num % 2 != 0)
      break;
  }
  return ret;
}

int main()
{
  int n, ans = 0;
  int64_t a;
  cin >> n;
  for (int i = 0; i < n; ++i)
  {
    cin >> a;
    ans += count(a);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
if __name__ == '__main__':
    N = int(input())
    for n in range(N, 1000):
        flag = True
        num = n
        d = n%10
        n = n//10
        while n != 0:
            if d == n%10:
                n = n//10
            else:
                flag = False
                break
        if flag:
            break
    print(num)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdint>
#include <vector>
#include <algorithm>
using namespace std;
static const long long MOD = 1000000007LL;
typedef long long ll;

int main()
{
	string a;
	cin>>a;
	for(int i=0;i<4;i++)
		cout<<a[i];
	cout<<" ";
	for(int i=4;i<12;i++)
		cout<<a[i];
	cout<<endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
// int const mod = 998244353;
long long const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            // res = res*a;
            res = (res*a)%m;
        }
        a=(a*a)%m;
        // a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x , int m){
    return power(x,m-2,m);
}

int const N = 5e5+5;
int const inf = 2e9;

void solve(){  
    int i,j;   
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans = 0;

    while(a >= b){
        b = b*2;
        ans++;
    }
    while(b >= c){
        c = c*2;
        ans++;
    }
    if(ans <= k){
        cout<<"Yes"<<endl;

    }
    else{
        cout<<"No"<<endl;
    }
}        



int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;  
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


/*


*/

Measured memory_bytes: 3656
// F - Strings of Eternity
#include <bits/stdc++.h>

using namespace std;

vector<int> z_func(const string &p)
{
	vector<int> z(p.size());
	for (int l = 0, r = 0, i = 1, n = p.size(); i < n; i++)
		if (r >= i && z[i - l] < r - i + 1) {
			z[i] = z[i - l];
		} else {
			if (i > r) r = i;
			for (l = i; r < n && p[r - l] == p[r]; ) r++;
			z[i] = r - l;
			r--;
		}
	return z;
}

int find(const string &s, const string &t)
{
	int m = t.size();
	string r = t + "|" + s;
	vector<int> z = z_func(r);
	vector<int> dp(z.size() + 1);
	for (int i = m; i < z.size(); i++)
		if (z[i] == m) dp[i + m] = max(dp[i + m], dp[i] + 1);
	return *max_element(dp.begin(), dp.end());
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	string s, t;
	cin >> s >> t;
	string r = s;
	while (r.size() <= s.size() + t.size() * 2) r += s;

	int ans = find(r, t);
	if (ans > 0 && find(r + r, t) != ans)
		ans = -1;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 49668
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes(){
  cout << "Yes" << endl;
  exit(0);
}

void no(){
  cout << "No" << endl;
  exit(0);
}

int main(){
  string s; cin >> s;
  REP(i,SZ(s)){
    //kisu
    if(i%2==0 && s[i] == 'L') no();
    //gusu
    if(i%2==1 && s[i] == 'R') no();
  }
  yes();
}

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

using ll = long long;

template <typename T> T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A == B && B == C) {
        if(A % 2 == 0) {
            cout << -1 << endl;
        } else {
            cout << 0 << endl;
        }
        return 0;
    }
    int res = 0;
    while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
        res++;
        int na = (B + C) / 2;
        int nb = (A + C) / 2;
        int nc = (A + B) / 2;
        A = na;
        B = nb;
        C = nc;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld  = long double;
using pll = pair<ll, ll> ;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=1LL<<60;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）
 
#define gcd __gcd //llは受け取ってくれない
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define ALL(a) a.begin(),a.end() //sort(ALL(vec));
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define PB push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに
 
//最大値、最小値を更新する。aよりbのが大きい（小さい）か等しければaを更新してtrueを返す。そうでなければ何もせずfalseを返す chmax(nowmax,x);
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
// ----- template end ---- //
 
// ------- library ------- //



// ----- library end ----- //


int main() {
    
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  
  ll ans;
  if (K % 2 == 0){
    ans = A-B;
  }
  else{
    ans = B-A;
  }
  
  if (abs(ans)>pow(10, 18)){
    cout << "Unfair" << endl;
    return 0;
  }
  else{
    cout << ans << endl;
  }

  
// -- main() end -- //
}


 


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

int main(void)
{
	int N,i,tmp=0;
	int ans=0;
	cin >> N;

	for(i=1;i<=9;i++)
	{
		if(N%i!=0)
			continue;

		tmp=N/i;
		
		if(tmp>=1 && tmp<=9)
			ans++;
	}
	

	if(ans>0)
		cout << "Yes" << endl;
	
	else
		cout << "No" << endl;

}



Measured memory_bytes: 256
#33 2020/07/14
A, B = input().split(' ')
A = int(A)
B = int(B)
S = input()
if not '-' in S:
  print('No')
else:
  S = S.split('-')
  if '-' in S[0] or '-' in S[1]:
    print('No')
  elif len(S[0]) == A and len(S[1]) == B:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 9092
N,K = map(int,input().split())
L = list(map(int,input().split()))
#dp[i][is_small]  =: i桁目までみた is_small? の中での最大

d = format(K,'b')
dp = [[-1 for _ in range(2)] for _ in range(len(d) +1)]
dp[0][0] = 0
for i in range(len(d))[::-1]:
    if K == 0: break
    index = len(d) - i - 1
    cnt = 0
    for x in L:
        if x & (1 << i):
            cnt += 1
    #上からindex桁目に着目
    tmp = 2 ** i 
    if dp[index][1] != -1:
        dp[index+1][1] =max(dp[index+1][1], dp[index][1] + max(cnt,N-cnt) * tmp)
    #確定していない
    if d[index] == '1':
        #確定
        if dp[index][0] != -1:
            dp[index+1][1] = max(dp[index+1][1],dp[index][0] + cnt * tmp)
        #確定させない
        if dp[index][0] != -1:
            dp[index+1][0] = max(dp[index+1][0],dp[index][0] + (N-cnt)*tmp)
    else:
        #確定させない(0にする)
        if dp[index][0] != -1:
            dp[index+1][0] = max(dp[index+1][0],dp[index][0] + cnt*tmp)
ans = 0
for i in range(len(d),50):
    tmp = 2 ** i
    cnt = 0
    for x in L:
        if x & (1 << i):
            cnt += 1
    ans += cnt * tmp
print(ans + max(dp[len(d)][0],dp[len(d)][1],0))


Measured memory_bytes: 68696
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N;
  cin >> N;

  vector<int> P(N),Q(N),num(N);
  for(int i = 0;i < N;i++) cin >> P.at(i);
  for(int i = 0;i < N;i++) {
    cin >> Q.at(i);
    num.at(i) = i+1;
  }

  int p = -1,q = -1,a = 1;
  do {
    bool sp = true,sq = true;
    for(int i = 0;i < N;i++) {
      if(num.at(i) != P.at(i)) sp = false;
      if(num.at(i) != Q.at(i)) sq = false;
    }
    if(sp) p = a;
    if(sq) q = a;
    a++;
  }while(next_permutation(num.begin(),num.end()));

  cout << abs(p-q) << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define ll long long

unordered_map<ll,list<pair<ll,ll>>> graph;
void add(ll a, ll b,ll dist)
{
    graph[a].push_back({b,dist});
    graph[b].push_back({a,dist});
}


ll dijkstra(ll src,ll n)
{
    unordered_map<ll,ll> dist;
    for(auto i:graph)
    {
        dist[i.first]=INT_MAX;
    }
    dist[src]=0;
    set<pair<ll, ll> > s;
    s.insert({0,src});
    
    while(!s.empty())
    {
        auto p = *(s.begin());
        
        ll d = p.first;
        ll node = p.second;
        
        s.erase(p);
        for(auto i:graph[node])
        {
            if((i.second + d) < (dist[i.first]))
            {
                if(s.find({dist[i.first],i.first})!=s.end())
                {
                    s.erase({dist[i.first],i.first});
                }
                
                dist[i.first] = d + i.second;
                s.insert({dist[i.first],i.first});
            }
        }
        
    }
    
    return dist[n];
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    // ll t;cin>>t;while(t--)
    {
    
        ll a,b;cin>>a>>b;
        if(a>=1 && b>=1 && a<=9 && b<=9)
            cout<<a*b<<endl;
        else
            cout<<-1;
            
    }
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<iostream>

using namespace std;


const int N = 222;

int main(){
	
	
	int n;
	
	cin>>n;
	
	int board[N][3] = {0};
	
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>board[i][j];
		}
	}
	
	
	int ans[N] = {0};
	
	for(int i=0;i<3;i++){
		map<int,int> memo;
		
		for(int j=0;j<n;j++){
			memo[board[j][i]]++;
		}
		
		for(int j=0;j<n;j++){
			int t = board[j][i];
			int k = (memo[t]==1) ? t : 0;
			
			ans[j] += k; 
		}
	}
	
	
	for(int i=0;i<n;i++){
		printf("%d\n",ans[i]);
	}
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  ll k;
  cin >> k;
  if(k%2==0){
    print(k / 2 * k / 2);
  }
  else{
    print(k / 2 * (k + 1) / 2);
  }
}

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

a_list = sorted(a_list, reverse=True)
b_list = sorted(b_list, reverse=True)
a_list.append(-1)
b_list.append(-1)
ans = 1
a_i = 0
b_i = 0
for i in range(N*M, 0, -1):
    if i == a_list[a_i] and i == b_list[b_i]:
        a_i += 1
        b_i += 1
    elif i == a_list[a_i]:
        a_i += 1
        ans *= b_i
        ans %= mod
    elif i == b_list[b_i]:
        b_i += 1
        ans *= a_i
        ans %= mod
    else:
        ans *= (a_i*b_i - (N * M - i))
        ans %= mod
print(ans % mod)



Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

string S;

int main() {
    cin >> S;

    if (S[1] > S[0] || (S[1] == S[0] && S[2] > S[0])) S[0]++;

    for (int i = 0; i < S.length(); i++) {
        S[i] = S[0];
    }

    cout << S << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    long long n,min,max,sum=0,a;
    cin>>n;
    cin>>max;
    min=max;
    sum=max;
    for (int i=0;i<n-1;i++){
        cin>>a;
        sum+=a;
        if (a>max)
            max=a;
        if (a<min)
            min=a;
    }
    cout<<min<<" "<<max<<' '<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int main(){
	fast
	int n;
	cin>>n;
	lli a[N];
	mem(a,0);
	int x;
	lli sm=0;
	FOR0(n){
		cin>>x;
		a[x]++;
		sm+=x;
	}
	int q,from,to;
	cin>>q;
	while(q--){
		cin>>from>>to;
		lli smf=a[from]*from;
		sm-=smf;
		lli smt=a[from]*to;
		sm+=smt;
		a[to]+=a[from];
		a[from]=0;
		cout<<sm<<endl;
	}
}



Measured memory_bytes: 4440
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NXY = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, X, Y) = (NXY[0], NXY[1] - 1, NXY[2] - 1);

        var list = new List<int>[N];

        for (int i = 0; i < N; i++)
        {
            list[i] = new List<int>();
            if (i < N - 1)
                list[i].Add(i + 1);
            if (0 < i)
                list[i].Add(i - 1);
        }
        list[X].Add(Y);
        list[Y].Add(X);

        var ans = new int[N];

        for (int i = 0; i < N; i++)
        {
            var dist = Enumerable.Repeat(-1, N).ToArray();
            dist[i] = 0;

            var q = new Queue<int>();
            q.Enqueue(i);

            while (q.Count > 0)
            {
                var v = q.Dequeue();

                foreach (var next in list[v])
                {
                    if (dist[next] < 0)
                    {
                        dist[next] = dist[v] + 1;
                        q.Enqueue(next);
                    }
                }
            }

            for (int j = 0; j < N; j++)
                ans[dist[j]]++;
        }

        for (int i = 0; i < N; i++)
            ans[i] /= 2;

        for (int i = 1; i < N; i++)
            WriteLine(ans[i]);
    }
}


Measured memory_bytes: 44412
import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))
lis=[]
for i in range(n):
    heapq.heappush(lis,-a[i])
for i in range(m):
    b=(heapq.heappop(lis)*(-1)//2)*(-1)
    heapq.heappush(lis,b)
    #print(lis)
ans=0
#print(lis)
for i in range(n):
    ans+=lis[i]
print(-ans)

Measured memory_bytes: 14180
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

int main(){
  string s,t;
  cin>>s>>t;
  int n=sz(s),m=sz(t);
  vector<vector<int>>is(26);
  rep(i,n)is[s[i]-'a'].push_back(i);
  rep(i,n)is[s[i]-'a'].push_back(i+n);
  ll ans=0;
  int p=0;//after p
  rep(i,m){
    int c=t[i]-'a';
    if(sz(is[c])==0){
      puts("-1");
      return 0;
    }
    p=*lower_bound(is[c].begin(),is[c].end(),p)+1;
    if (p>=n){
      p-=n;
      ans+=n;
    }
  }
  ans+=p;
  cout<<ans<<endl;
  return 0;
}


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

int main(){
  int64_t N,M;
  std::cin >> N >> M;
  std::vector<int64_t> S_arr(N), T_arr(M);
  for(int64_t i = 0; i < N; i++){
    std::cin >> S_arr[i];
  }
  for(int64_t i = 0; i < M; i++){
    std::cin >> T_arr[i];
  }

  std::vector<int64_t> dp((N+1)*(M+1));
  for(int64_t n = 0; n < N+1; n++){
    dp[n*(M+1)] = 1;
  }
  for(int64_t m = 0; m < M+1; m++){
    dp[m] = 1;
  }

  const int64_t mod = 1000000007;
  for(int64_t n = 0; n < N; n++){
    const auto s = S_arr[n];
    for(int64_t m = 0; m < M; m++){
      const auto t = T_arr[m];
      if(s == t){
        dp[(n+1)*(M+1)+m+1] = (dp[(n+1)*(M+1)+m]+dp[n*(M+1)+m+1]) % mod;
      }else{
        dp[(n+1)*(M+1)+m+1] = (dp[(n+1)*(M+1)+m]+dp[n*(M+1)+m+1]-dp[n*(M+1)+m]) % mod;
      }
    }
  }
  auto ans = dp[(N+1)*(M+1)-1];
  while(ans < 0){
    ans += mod;
  }
  std::cout << ans % mod << std::endl;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define N 300005
int seg[4*N];
int mul(int a, int b)
{
    return a*b%mod;
}
int mypower(int a, int b)
{
    int ans = 1;
    while(b)
    {
        if(b%2)
            ans = mul(ans, a);
        b=b/2;
        a=mul(a,a);
    }
    return ans;
}
void update(int st, int l, int r, int idx,  int val)
{
    if(l == r)
    {
        seg[st] = val;
        return;
    }
    int mid = (l+r)/2;
    if(idx <= mid)
        update(2*st+1, l, mid, idx, val);
    else
        update(2*st+2,mid+1, r, idx, val);
    seg[st] = max(seg[2*st+1],seg[2*st+2]);    
}
int query(int st, int l, int r, int ql, int qr)
{
    if(l > qr || r < ql)
    {
        return 0;
    }
    if(l >= ql && r <= qr)
        return seg[st];
    int mid = (l+r)/2;
    return max(query(2*st+1, l, mid, ql, qr), query(2*st+2, mid+1, r, ql, qr));
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> vec(n);
    int i;
    for(i=0;i<n;i++)
        cin >> vec[i];
    
    int dp[n];
    dp[0] = 1;
    int ans = 1;
    update(0, 0, 300001, vec[0], 1);
    for(i=1;i<n;i++)
    {
        int up = min(k + vec[i], (int)300001);
        int down = max((int)0, vec[i] - k);
        int val = query(0, 0, 300001, down, up);
        dp[i] = 1;
        dp[i] = max(dp[i], 1 + val);
        ans = max(ans, dp[i]);
        update(0, 0, 300001, vec[i], dp[i]);
    }
    cout << ans;
}

Measured memory_bytes: 16204
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input!(n: i64);
    let mut cur = 1;
    let mut sum = 0;
    let mut len = 0;
    while sum < n {
        cur *= 26;
        sum += cur;
        len += 1;
    }
    sum -= cur;
    let mut idx = n - sum - 1;
    let mut ans = vec!['+'; len];
    for i in 0..len {
        ans[len - 1 - i] = (b'a' + (idx % 26) as u8) as char;
        idx /= 26;
    }
    for i in 0..len {
        puts!("{}{}", ans[i], if i + 1 == len { "\n" } else { "" });
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

char str[100001];

int main(void){
    register int i,j;
    scanf("%s",str);
    int sl = strlen(str);
    int ans[sl];
    int rc = 0,lc = 0;
    for(i = 0;i < sl;i++)ans[i] = 0;
    for(i = 0;i < sl;i++){
        j = sl - i - 1;
        if(str[i] == 'R')rc++;
        else{
            int add = (rc + 1) / 2;
            ans[i] += rc - add;
            ans[i-1] += add;
            rc = 0;
        }
        if(str[j] == 'L')lc++;
        else{
            int add = (lc + 1) / 2;
            ans[j] += lc - add;
            ans[j+1] += add;
            lc = 0;
        }
    }
    for(i = 0;i < sl;i++)printf("%d ",ans[i]);
    return 0;
}

Measured memory_bytes: 896
import java.util.*;

class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int count = 0;
        int[] balls = new int[n];
        for (int i = n; i > 0; i--) {
            int flg = 0;
            for (int j = i * 2; j <= n; j += i) {
                flg ^= balls[j - 1];
            }
            balls[i - 1] ^= a[i - 1] == flg ? 0 : 1;
            if(balls[i-1]>0){
                count++;
            }
        }
        System.out.println(count);
        for (int i = 0; i < balls.length; i++) {
            if (balls[i] > 0) {
                System.out.print((i + 1) + " ");
            }
        }
        sc.close();
    }
}


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

int main() {
 int a , b , c;
  cin >> a >> b >> c;
  if (a==b && b==c) {
  cout << 1 << endl;
}
  else if (a==b && a!=c) {
  cout << 2 << endl;
}
    else if (a==c && a!=b) {
  cout << 2 << endl;
}
    else if (c==b && c!=a) {
  cout << 2 << endl;
}
    else {
  cout << 3 << endl;
}
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

signed main(){
  int N,M;
  cin >> N >> M;
  ll ans = 0;
  ll Sgn[] = {1,-1};
  ll x[N],y[N],z[N];
  FOR(i,0,N){
    cin >> x[i] >> y[i] >> z[i];
  }
  vector<vector<ll>> v(8);
  FOR(i,0,2)FOR(j,0,2)FOR(k,0,2){
    FOR(l,0,N){
      v[i*4+j*2+k].pb(Sgn[i]*x[l]+Sgn[j]*y[l]+Sgn[k]*z[l]);
    }
  }
  FOR(i,0,8)sort(ALL(v[i]),greater<ll>());
  FOR(i,0,8){
    ll SUM = 0;
    FOR(j,0,M){
      SUM += v[i][j];
    }
    ans = max(ans,SUM);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
//B - Counting Roads
int main() {
  int n, m;
  cin >> n >> m;
  
  int a = 0, b= 0;
  vector<int> nrods(n);
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    //cout << a << "=" << i+1 <<"=" << b << endl;
    nrods.at(a-1) ++;
    nrods.at(b-1) ++;
  }
  for (int i = 0; i < nrods.size(); i++)
    cout << nrods.at(i) << endl;
}


Measured memory_bytes: 256
from itertools import product

N = int(input())
S = input()

cnt = 0
for i, j, k in product("0123456789", repeat=3):
    T = [i, j, k]
    cur = 0
    for s in S:
        if s == T[cur]:
            cur += 1
            if cur == 3:
                cnt += 1
                break

print(cnt)


Measured memory_bytes: 42716
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9

int main(){
	string in;
	while(getline(cin,in),in!="END OF INPUT"){
		int cnt;
		for(int i=0; i<in.size();i++){
			cnt = 0;
			for(;i<in.size() && in[i]!=' ';i++,cnt++);
			//if( i==in.size() )cnt--;
			printf("%d",cnt);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextStr(), sc.nextInt()
	keta := len(N)
	dp0 := make([][]int, keta+1)
	dp1 := make([][]int, keta+1)
	for i := 0; i < keta+1; i++ {
		dp0[i] = make([]int, K+1)
		dp1[i] = make([]int, K+1)
	}
	dp1[0][0] = 1
	for i := 0; i < keta; i++ {
		n, _ := strconv.Atoi(string(N[i]))
		// N未満確定で1~9のとき
		for j := 0; j < K; j++ {
			dp0[i+1][j+1] += dp0[i][j] * 9
		}
		// N未満確定で0のとき
		for j := 0; j < K+1; j++ {
			dp0[i+1][j] += dp0[i][j]
		}

		// N未満確定でないとき
		if n == 0 {
			for j := 0; j < K+1; j++ {
				dp1[i+1][j] += dp1[i][j]
			}
			continue
		}
		// 0のとき
		for j := 0; j < K+1; j++ {
			dp0[i+1][j] += dp1[i][j]
		}
		// 1~nのとき
		for j := 0; j < K; j++ {
			// 1~(n-1)
			dp0[i+1][j+1] += dp1[i][j] * (n - 1)
			// n
			dp1[i+1][j+1] += dp1[i][j]
		}
	}

	fmt.Fprintln(wtr, dp0[keta][K]+dp1[keta][K])
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] s = new String[n];

    for(int i = 0;i<n;i++){
        String ss = sc.next();
        int num = sc.nextInt();
        int num2 = i+1;
        s[i] = ss + " " + 1/(double)num + " " + num2;
    }

    Arrays.sort(s);

    for(String j:s){
        System.out.println(j.split(" ")[2]);
    }
  }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;
const int INF = 1e9;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


void solve(){
	string t;
	cin >> t;
	string s =t;
	int n =t.length();
	for(int i =0;i<n;i++)
		if(t[i]=='?')
			t[i] = 'D';
	// for(int i =0;i<n;i++){
	// 	char ch = t[i];
	// 	if(t[i]=='?'){
	// 		int j = i;
	// 		while(j<n && t[j]=='?')
	// 			j++;
	// 		j--;
	// 		if((i-j+1)%2==0){
	// 			int start = i;
	// 			int end = j;
	// 			char  c= 'P';
	// 			while(start<=end){
	// 				t[start] = c;
	// 				if(c=='P')
	// 					c='D';
	// 				else
	// 					c='P';
	// 				start++;
	// 			}
	// 		}
	// 		else{
	// 			int start = i;
	// 			int end = j;
	// 			char  c= 'D';
	// 			while(start<=end){
	// 				t[start] = c;
	// 				if(c=='P')
	// 					c='D';
	// 				else
	// 					c='P';
	// 				start++;
	// 			}
	// 		}
	// 	}
	// }
	// if(s[n-1]=='?' && t[n-1]=='P')
	// 	t[n-1] = 'D';
	cout << t << endl;
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 3776
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i]-=(i+1)
# print(a)
a.sort()
# print(a)
s = 0
for i in a:
    s += abs(i)
if abs(a[(n-1)//2]) > abs(a[n//2]):
    t = a[(n-1)//2]
else:
    t = a[n//2]
ans = 0
for i in a:
    ans += abs(i-t)
# print(t)
print(ans)

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n;
  string s[2];

  cin >> n >> s[0] >> s[1];
  ll ans = 1;
  ll x = 0;
  ll pre = -1;
  while(x < n) {
    if(s[0][x] == s[1][x]) { // パターン0の場合
      if(pre < 0) ans = 3;
      else if(pre == 0) ans *= 2; // 左がパターン0の場合
      else ans *= 1;
      ans %= mod;
      x++;
      pre = 0;
    } else {
      if (pre < 0) ans = 6;
      else if(pre == 0) ans *= 2;
      else ans *= 3;
      ans %= mod;
      x += 2;
      pre = 1;
    }
  }
  cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int a, b, c;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> a >> b >> c;
    cout << min(min(a + b, a + c), b + c) << endl;
}


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

using namespace std;
const string YES = "Yes";
const string NO = "No";

void solve(int N, int M, vector<string> A, vector<string> B) {
  bool include = false;
  rep(i, N - M + 1) {
    // find left top
    const int offset = A[i].find(B[0]);
    if (offset == string::npos || offset > N - M)
      continue;
    // check all row
    bool match = true;
    rep(j, M)
      if (A[i + j].substr(offset, M) != B[j]) {
	match = false;
	break;
      }
    if (!match)
      continue;
    // all row is equal !!
    include = true;
    break;
  }
  cout << (include ? YES : NO) << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  vector<string> A(N);
  for(int i = 0 ; i < N ; i++)
    cin >> A[i];

  vector<string> B(M);
  for(int i = 0 ; i < M ; i++)
    cin >> B[i];

  solve(N, M, move(A), move(B));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<double, P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)10000000000000000

int main() {
  string L;
  cin>>L;
  ll N;
  N=L.size();
  ll dp[N+1][2];
  rep(i,N+1){dp[i][0]=0ll;dp[i][1]=0ll;}
  dp[0][0]=1ll;
  rep(i,N){
    if(L[i]=='1'){
      dp[i+1][0]=2ll*dp[i][0];
      dp[i+1][1]=dp[i][0]+3ll*dp[i][1];
      dp[i+1][0]%=MOD;
      dp[i+1][1]%=MOD;
    }
    else{
      dp[i+1][0]=dp[i][0];
      dp[i+1][1]=3ll*dp[i][1];
      dp[i+1][0]%=MOD;
      dp[i+1][1]%=MOD;
    }
  }
  cout<<(dp[N][0]+dp[N][1])%MOD<<endl;
}

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

template<int MOD>
class mod_int {
	unsigned x;
public:
	mod_int() : x(0) { }
	mod_int(int sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	mod_int(long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	mod_int &operator+=(mod_int that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	mod_int &operator-=(mod_int that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	mod_int &operator*=(mod_int that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	mod_int &operator/=(mod_int that) { return *this *= that.inverse(); }

	mod_int operator+(mod_int that) const { return mod_int(*this) += that; }
	mod_int operator-(mod_int that) const { return mod_int(*this) -= that; }
	mod_int operator*(mod_int that) const { return mod_int(*this) *= that; }
	mod_int operator/(mod_int that) const { return mod_int(*this) /= that; }

	bool operator==(const mod_int& that) const { return x == that.x; }

	mod_int inverse() const {
		long long a = x, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		return mod_int(u);
	}
};

template<int MOD>
istream& operator >> (istream& is, mod_int<MOD>& val) {
	long long x;
	is >> x; val = x;
	return is;
}

template<int MOD>
ostream& operator << (ostream& os, const mod_int<MOD>& val) {
	os << val.get();
	return os;
}

const int mod = 998244353;
using mint = mod_int<mod>;

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int sum = accumulate(a.begin(), a.end(), 0), all = 0;
	vector<mint> dp(sum + 1);
	dp[0] = 1;
	for (int i = 0; i < N; i++) {
		auto tmp = dp;
		for (int j = 0; j <= all; j++) {
			dp[j] *= 2;
		}
		for (int j = 0; j <= all; j++) {
			dp[j + a[i]] += tmp[j];
		}
		all += a[i];
	}
	mint res = 1;
	for (int i = 0; i < N; i++) res *= 3;
	for (int i = sum / 2 + 1; i <= sum; i++) {
		res -= dp[i] * 3;
	}
	if (sum % 2 == 0) {
		vector<mint> dp2(sum + 1);
		dp2[0] = 1;
		all = 0;
		for (int i = 0; i < N; i++) {
			auto tmp = dp2;
			for (int j = 0; j <= all; j++) {
				dp2[j + a[i]] += tmp[j];
			}
			all += a[i];
		}
		res -= (dp[sum / 2] - dp2[sum / 2]) * 3;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1312
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int64_t n,m;
    cin >> n>> m;
    string s,t;
    cin >> s>>t;
    int64_t l = n*m/__gcd(n,m);
    if(s[0]!=t[0]){
        cout<<-1<<endl;
    }
    else{
        if(l==m*n){
        cout<<l<<endl;
        }
        else{
            int i=0;
            while(i*l/m<n){
                if(s[i*l/m]!=t[i*l/n]){
                    cout<<-1<<endl;
                    return 0;
                }
                i++;
            }
            cout<<l<<endl;
        }
    }
}

Measured memory_bytes: 512
s = list(input())
flg=0
for i in range(1,len(s)+1):
    if(i%2!=0):
        if s[i-1] not in ["R","U","D"]:
            flg=1
    elif(i%2==0):
        if s[i-1] not in ["L","U","D"]:
            flg=1
if(flg==1):
    print("No")
else: print("Yes")

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        long K = sc.nextLong();
        
        int[] Kdigits = new int[41];
        int t = 0;
        while( K > 0 ){
            if( (K & 1) == 1 ) Kdigits[t]++;
            K = K >> 1;
            t++;
        }
        
        int[] numOnes = new int[41];
        for(int i = 0; i < N; i++){
            long A = sc.nextLong();
            int j = 0;
            while( A > 0 ){
                if( (A & 1) == 1 ) numOnes[j]++;
                A = A >> 1;
                j++;
            }
        }
        
        long[][] dp = new long[42][2];
        for(int i = 40; i >= 0; i--){
            long d = 1L << i;
            int ones = numOnes[i];
            int zeros = N - ones;
            if( Kdigits[i] == 0 ){
                dp[i][0] = dp[i+1][0] + d * ones;
                if( dp[i+1][1] > 0 ) dp[i][1] = dp[i+1][1] + d * Math.max(ones, zeros);
            } else {
                dp[i][0] = dp[i+1][0] + d * zeros;
                dp[i][1] = dp[i+1][0] + d * ones;
                if( dp[i+1][1] > 0 ) dp[i][1] = Math.max(dp[i][1], dp[i+1][1] + d * Math.max(ones, zeros)); 
            }
        }
        
        System.out.println( Math.max(dp[0][0], dp[0][1]) );
        
    }
}


Measured memory_bytes: 48496
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	int N, A, B, C;
	cin >> N >> A >> B >> C;

	int kei = A + B + C;

	if (kei != 2) {
		int OK = 1;

		vector<char> kotae;
		rep(i, N) {
			string S;
			cin >> S;

			if (S == "AB") {
				if (A == 0 && B == 0) OK = 0;
				if (A <= B) {
					kotae.pb('A');
					A++;
					B--;
				}
				else {
					kotae.pb('B');
					B++;
					A--;
				}
			}
			else if (S == "BC") {
				if (C == 0 && B == 0) OK = 0;
				if (C <= B) {
					kotae.pb('C');
					C++;
					B--;
				}
				else {
					kotae.pb('B');
					B++;
					C--;
				}
			}
			else {
				if (A == 0 && C == 0) OK = 0;
				if (A <= C) {
					kotae.pb('A');
					A++;
					C--;
				}
				else {
					kotae.pb('C');
					C++;
					A--;
				}
			}
		}
		if (OK) {
			co("Yes");
			for (auto C : kotae) co(C);
		}
		else co("No");
	}
	else {
		int OK = 1;

		vector<char> kotae;
		string S[100001];
		rep(i, N) cin >> S[i];

		rep(i, N) {

			if (S[i] == "AB") {
				if (A == 0 && B == 0) OK = 0;
				if (A == 1 && B == 1) {
					if (i == N - 1 || S[i + 1] == "BC") {
						kotae.pb('B');
						B++;
						A--;
					}
					else {
						kotae.pb('A');
						A++;
						B--;
					}
				}
				else if (A <= B) {
					kotae.pb('A');
					A++;
					B--;
				}
				else {
					kotae.pb('B');
					B++;
					A--;
				}
			}
			else if (S[i] == "BC") {
				if (C == 0 && B == 0) OK = 0;
				if (C == 1 && B == 1) {
					if (i == N - 1 || S[i + 1] == "AC") {
						kotae.pb('C');
						C++;
						B--;
					}
					else {
						kotae.pb('B');
						B++;
						C--;
					}
				}
				else if (C <= B) {
					kotae.pb('C');
					C++;
					B--;
				}
				else {
					kotae.pb('B');
					B++;
					C--;
				}
			}
			else {
				if (A == 0 && C == 0) OK = 0;
				if (A == 1 && C == 1) {
					if (i == N - 1 || S[i + 1] == "BC") {
						kotae.pb('C');
						C++;
						A--;
					}
					else {
						kotae.pb('A');
						A++;
						C--;
					}
				}
				else if (A <= C) {
					kotae.pb('A');
					A++;
					C--;
				}
				else {
					kotae.pb('C');
					C++;
					A--;
				}
			}
		}
		if (OK) {
			co("Yes");
			for (auto C : kotae) co(C);
		}
		else co("No");
	}


	Would you please return 0;
}

Measured memory_bytes: 6912