akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int dp[41][401][401];

int main(){
    int n,A,B;cin >> n >> A >> B;
    vector<int> a(n),b(n),c(n);
    rep(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }
    rep(i,n+1){
        rep(j,401){
            rep(k,401){
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0]=0;
    rep(i,n){
        rep(j,401){
            rep(k,401){
                if(dp[i][j][k]==INF) continue;
                dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
                dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k] + c[i]);
            }
        }
    }
    int ans = INF;
    for(int i=1;i<=400;i++){
        for(int j=1;j<=400;j++){
            if(i*A==j*B) ans = min(ans,dp[n][j][i]);
        }
    }
    if(ans == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 25984
// Doing Some Optimization

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#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 <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int

const int hell=1000000009;


int power(int a,int b)
{
  if(b==0)return 1;
  if(b==1)return a;
  int t=power(a,b/2);
  t%=hell;
  t*=t;
  t%=hell;
  if(b%2)return (t*a)%hell;
  else
     return t;
}

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

int digitsum(int x)
{
  while(x>9)
    {  int ans=0;
       while(x!=0)
       {
        ans+=x%10;
        x/=10;
       }
       x=ans;
    }
    return x;
}

int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;}
  return a;
}

int solve( ){

int n;
cin>>n;
n-=2;
cout<<n*180LL;

return 0;
}

signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);                                                                    

 

  clock_t time_req;

    // Without using pow function
                                                                                                                   

   // cin>>t;

    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }

         time_req = clock() - time_req;
    //cout <<endl<< "Processor time taken is "
      //<< (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
} 


Measured memory_bytes: 256
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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




// ***************************************

vector<ll> calc_K(ll N){
    vector<ll> vec;

    for(ll k = 1; k * k <= N; k++){
        if (N % k == 0) {
            vec.push_back(k);
            ll j = N / k;
            if (j != k) vec.push_back(j);
        }
    }

    sort(ALL(vec));

    return vec;
}


int main(){

    ll N;
    cin >> N;

    ll ans = 0;
    // 割った余りが１
    const auto& vec = calc_K(N - 1);
    ans += vec.size() - 1;

    // 割り切れる
    const auto& vec2 = calc_K(N);

    for(auto& K: vec2){
        if (K == 1) continue;
        ll NN = N;
        while(NN % K == 0){
            NN = NN / K;
        }
        if ((NN-1) % K == 0) ans++;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    int n;
    string* str;
    cin >> n;
    str = new string[n];

    for(int i = 0; i < n; i++) {
        cin >> str[i];
    }

    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(str[i] == str[j]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    for(int i = 0; i < n - 1; i++) {
        if(str[i][str[i].size() - 1] != str[i + 1][0]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    delete [] str;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())
A = [0] * N
same = False
import math
for i in range(1, N):
  if S[i] == S[i-1]:
    same = True
  elif same and S[i] != S[i-1]:
    A[i] = 1
    same = False
  else:
    same = False
    A[i] = 1
    
print(sum(A)+1)

Measured memory_bytes: 10424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    for (int n; cin >> n && n;) {
        vector<VI> cal(n, VI(5));
        FOR(i, 0, n) {
            FOR(j, 0, 4)cin >> cal[i][j];
            cal[i][4] = cal[i][1] * 4 + cal[i][2] * 9 + cal[i][3] * 4;
        }

        VI bor(4);
        cin >> bor;
        int cnt = 0;
        FOR(i, 0, n) {
            bool ng = false;
            FOR(j, 0, 4)if (cal[i][j + 1] > bor[j]) {
                ng = true;
            }
            if (ng)continue;
            cout << cal[i][0] << "\n";
            cnt++;
        }
        if (cnt == 0)cout << "NA\n";
    }
}


Measured memory_bytes: 3212
#include <iostream>
#include <algorithm>
#define mod 1000000007

using namespace std;

int N, W;
int w[205];
int sum[205];
int dp[205][10005];

int main(void)
{
	cin >> N >> W;
	for(int i = 0; i < N; i++) cin >> w[i];
	sort(w, w+N);
	reverse(w, w+N);
	
	int s = 0;
	for(int i = N-1; i >= 0; i--){
		s += w[i];
		sum[i] = s;
	}
	
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= W; j++){
			dp[i][j] = 0;
		}
	}
	dp[0][W] = 1;
	
	for(int i = 1; i <= N; i++){
		for(int j = 0; j <= W; j++){
			if(w[i-1] <= j){
				dp[i][j-w[i-1]] += dp[i-1][j];
				dp[i][j-w[i-1]] %= mod;
			}
			if(j < sum[i-1]){
				dp[i][j] += dp[i-1][j];
				dp[i][j] %= mod;
			}
		}
	}
	
	int ans = 0;
	for(int i = 0; i <= W; i++){
		ans += dp[N][i];
		ans %= mod;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10964
#include<map>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;
long long const MOD = 1000000007;
long long const MAX = 1005;

//ax+by = (gcd of x and y)となるようにa,bを変更する
long long extgcd(long long x, long long y, long long &a, long long &b) {
	if (y == 0) {
		a = 1; b = 0;
		return x;
	}
	else {
		long long q = x / y; long long r = x % y;
		long long s;
		long long d = extgcd(y, r, s, a);
		b = s - a * q;
		return d;
	}
}

long long mod_inverse(long long x) {
	x %= MOD;
	long long a, b;
	a = b = 0;
	if (extgcd(x, MOD, a, b) != 1) {
		return -1;
	}
	else {
		return (MOD + a % MOD) % MOD;
	}
}

ll mod_pow(ll x, ll n) {
	if (n == 0) {
		return 1;
	}
	else {
		ll t = mod_pow(x, n / 2);

		if (n % 2 == 1) {
			return t * t%MOD*x%MOD;
		}
		else {
			return t * t%MOD;
		}
	}
}

//階乗をここに記憶
long long mod_fact[MAX];
long long mod_inv_fact[MAX];
ll mod_pow_inv_fact[MAX][MAX];

void prep_fact(long long n) {
	mod_fact[0] = 1;
	for (long long i = 1; i <= n; i++) {
		mod_fact[i] = (mod_fact[i - 1] * i) % MOD;
	}
}
void prep_inv(long long n) {
	for (long long i = 0; i <= n; i++) {
		mod_inv_fact[i] = mod_inverse(mod_fact[i]);
	}
	REP(i, 0, n) {
		REP(j, 0, n) {
			mod_pow_inv_fact[i][j] = mod_inverse(mod_pow(mod_fact[i], j));
		}
	}
}

long long nCr(long long n, long long r) {
	return (((mod_fact[n] * mod_inv_fact[r]) % MOD)*mod_inv_fact[n - r]) % MOD;
}


ll dp[MAX][MAX];

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

ll mod_p(ll x, ll y) {
	return (x + y) % MOD;
}
int main() {	
	ll n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	prep_fact(MAX - 1);
	prep_inv(MAX - 1);
	REP(i, 1, n) {
		dp[i][a-1] = 0;
	}
	dp[0][a-1] = 1;
	REP(j, a, b) {
		REP(i, 0, n) {
			ll dpij = dp[i][j-1];
			REP(k, c, min(d, i / j)) {
				ll cnt = dp[i - k * j][j - 1];
				cnt = mod_m(cnt, nCr(i, k*j));
				cnt = mod_m(cnt, mod_fact[k*j]);
				cnt = mod_m(cnt, mod_pow_inv_fact[j][k]);
				cnt = mod_m(cnt, mod_inv_fact[k]);
				dpij = mod_p(dpij, cnt);
			}
			dp[i][j] = dpij;
		}
	}
	cout << dp[n][b] << endl;
	/*
	REP(i, 0, n) {
		REP(j, a - 1, b) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/
	
}

Measured memory_bytes: 16000
#include<iostream>
using namespace std;
int main(){
  int  A[5];
  int k = 10, l = 0, m = 0, ans = 0;
  for (int i = 0; i < 5; ++i){
    cin >> A[i];
    if(k > A[i]%10 && A[i]%10 != 0) {
      k = A[i]%10;
      l = A[i];
    }
  m += (A[i] + 9)/10;
  }
  ans = (m - (l + 9)/10)*10 + l;
  cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int c[][]=new int[3][3];
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				c[i][j]=sc.nextInt();
			}
		}
		int s1=c[0][1]+c[0][2]+c[1][2];
		int s2=c[1][0]+c[2][0]+c[2][1];
		int s=c[0][0]+c[1][1]+c[2][2];
		if(s1+s2==2*s){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N;
	cin >> N;
	vec(A)
		fx(N) {
		vecp(A)
	}
	bool flag = false;
	int ans = 0;
	fz(N - 1) {
		if (A.at(z)<A.at(z + 1)) {
			ans++;
		}
	}
	if (ans == N - 1) {
		flag = true;
	}
	fx(N) {
		for (int y = x + 1; y < N;y++) {
		
			ans = 0;
			A.at(x) ^= A.at(y);
			A.at(y) ^= A.at(x);
			A.at(x) ^= A.at(y);
	
			fz(N-1) {
				if (A.at(z)<A.at(z+1)) {
					ans++;
				}
			}
			if (ans == N - 1) {
				x = N; y = N;
				flag = true;
			}
			else {
				A.at(x) ^= A.at(y);
				A.at(y) ^= A.at(x);
				A.at(x) ^= A.at(y);
			}
	
		}
	}
	if (flag) {
		ce("YES")
	}
	else {
		ce("NO")
	}
    return 0;
}



Measured memory_bytes: 256
import sys
x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()
p = [int(x) for x in input().split()]


diff = 0
while(True):
    if not x + diff in p:
        print(x+diff)
        sys.exit()

    if diff < 0:
        diff *= -1
    else:  # 0以上
        diff *= -1
        diff -= 1


Measured memory_bytes: 9176
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::min;
using std::max;
using std::fill;

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

namespace MySpace{
    ll ds(ll x)
    {
        ll y = 0;
        while (x > 0)
        {
            y += x % 10;
            x /= 10;
        }
        return y;
    }
    ll inq(ll x, ll y, ll mod)
    {
        if (y == 0) return 1;
        ll l = inq(x, y / 2, mod);
        if (y % 2) return l * l % mod * x % mod;
        return l * l % mod;
    }
    ll inq(ll x, ll y)
    {
        if (y == 0) return 1;
        ll l = inq(x, y / 2);
        if (y % 2) return l * l * x;
        return l * l;
    }
    
};

using namespace MySpace;

#define F(i, n) for (int (i) = 0; (i) <= (n); i++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

const long long MOD = 1e9 + 7;

const long long inf = 1e18;
const long long infsmart = 1e12;

ll n;
S s;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    for (int i = 0; i < 4; i++)
    {
        if (s[i] == '+') n++;
        else n--;
    }
    cout << n;
}






























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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MAX 1000010
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  ll a,b; cin>>a>>b;
  set<ll> factorial;
  for(ll i = 1; i <= min(sqrt(a),sqrt(b)); i++){//1e6
    if(a%i==0&&b%i==0)factorial.insert(i);
    ll j = min(a,b)/i;
    if(a%j==0&&b%j==0)factorial.insert(j);
  }
  vector<ll> P(MAX,-1);
  P.at(1) = 1;
  for(ll i = 2; i < MAX; i++){
    if(P.at(i)!=-1)continue;
    for(ll j = 1; j*i < MAX; j++){
      P.at(i*j)=i;
    }
  }
  set<ll> prime;
  for(auto i = 2; i < MAX; i++){
    if(P.at(i)==i)prime.insert(i);
  }
  ll res = 0;
  for(auto num: factorial){
    if(num<MAX){
      if(P.at(num)==num)res++;
    }else{
      int flag = 0;
      for(auto i: prime){
        if(num%i==0){
          flag = 1;
          break;
        }
      }
      if(!flag)res++;
    }
  }
  cout<<res<<endl;
}

Measured memory_bytes: 12032
#include <iostream>
using namespace std;
int main(){
	long long l,r;
	long long k;
	cin>>l>>r;
	cin>>k;
	long long save=l;
	while(l<=r)
	{
		cout<<l<<endl;
		if(r-l+1>k)
		{
		if(l-save+1==k)
		{
			l=r-k;
		}
		}
		l++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
	int n;
	cin>>n;
	int dp[n+1];
	for(int i=0;i<n+1;i++) dp[i]=INT_MAX;
	dp[n]=0;
	for(int i=n;i>=0;i--){
		int nine=1,six=1;
		while(nine<=i){
			dp[i-nine]=min(dp[i]+1,dp[i-nine]);
			nine*=9;
		}
		while(six<=i){
			dp[i-six]=min(dp[i]+1,dp[i-six]);
			six*=6;
		}
	}
	cout<<dp[0]<<endl;
    return 0;
}


Measured memory_bytes: 640
def print_func(s, order):
    print(s[order[1]:order[2]+1])


def reverse_func(s, order):
    ans = list(s[order[1]:order[2]+1])
    ans.reverse()
    s = s[:order[1]]+''.join(ans)+s[order[2]+1:]
    return s


def replace_func(s, order):
    cnt = 0
    s = list(s)
    for i in range(order[1], order[2]+1):
        s[i] = str(order[3])[cnt]
        cnt += 1
    s = ''.join(s)
    return s


if __name__ == '__main__':
    s = input()
    for i in range(int(input())):
        order = input().split()
        order[1] = int(order[1])
        order[2] = int(order[2])
        if order[0] == 'print':
            print_func(s, order)
        elif order[0] == 'reverse':
            s = reverse_func(s, order)
        else:
            s = replace_func(s, order)

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

void Shuffle(char[]);

int main ()
{
	while(1)
	{
    	char word[201];
        char end[] = "-";       //??????????????¨
        int i = 0 ;
        int N = 0 ;				//???????????°
        int sum = 0 ;
        int num = 0 ;
        
    	scanf("%s",word);		//??????????????????
        
        if(!strcmp(word,end))
        {
        	return 0;
        }
        
        scanf("%d",&N);			//?????????????????????
        sum = 0 ;				//????¨????????????????
        
        for( i = 0 ; i < N ; i++ )
        {
        	scanf("%d",&num);
            sum += num ;
        }
        
        for( i = 0 ; i < sum ; i++)
        {
         	Shuffle(word);			//sum???shuffle??????
        }
        
        printf("%s\n", word);				//????????¨???
        
    }

	return 0;
}
























void Shuffle(char line[])
{
	char tmp = line[0];
    int i = 0 ;
    
    for( i = 0 ; i < strlen(line)-1 ; i++)
	{
    	line[i] = line[i+1];
    }
    
    line[strlen(line)-1] = tmp;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define f first
#define s second
#define mset(m,v) memset(m,v,sizeof(m))
#define mod 1000000007
const int N = 2e5 + 5, INF = 1E9 + 7;
#define PI acos(-1.0)
long double EPS = 1e-9;
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
void solve() {
	int n;
	cin >> n;
	map<int, int>m;
	vi v(n);
	in(v);
	int sum = 0;
	rep(i, n) {
		m[v[i]]++;
		sum += v[i];
	}
	int q;
	cin >> q;
	while (q--) {
		int a, b;
		cin >> a >> b;
		sum -= m[a] * a;
		int prev = m[b];
		m[b] += m[a];
		sum += (m[b]-prev) * b;
		m[a] = 0;
		cout << sum << endl;
	}
}
signed main()
{
	fastio;
	//cout<<fixed<<setprecision(15);
	//clock_t begin = clock();
	int tc;
	tc = 1;
	//cin >> tc;
	while (tc--) {
		solve();
	}
	//clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs;
}


//Error?
// clear lists for every test case
// print new line for each tc
// check for int or ll
// check if problem can be solved without any heavy DS like priority_queue or map



Measured memory_bytes: 9968
def resale(n, vli, cli):

    ans = 0

    for i in range(len(vli)):
        if vli[i]-cli[i] > 0:
            ans += vli[i]-cli[i]

    return ans

def main():
    n = int(input())
    vli = list(map(int, input().split()))
    cli = list(map(int, input().split()))
    print(resale(n, vli, cli))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>

int main()
{
	int n, c[510], s[510], f[510];
	std::cin >> n;
	
	for (int i = 0; i < n - 1; ++i)
	{
		std::cin >> c[i] >> s[i] >> f[i];
	}
	
	for (int i = 0; i < n - 1; ++i)
	{
		int t = 0;
		for (int j = i; j < n - 1; ++j)
		{
			if (t < s[j])
			{
				t = s[j];
				t += c[j];
				continue;
			}
			else
			{
				if (t % f[j] == 0)
				{
					t += c[j];
				}
				else
				{
					t += (f[j] - (t % f[j]));
					t += c[j];
				}
			}
		}
		
		std::cout << t << "\n";
	}
	std::cout << 0;
}

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

int main() {
	
	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	for(auto &i : p) cin >> i;
	int m=0;
	int m2=0;
	for(int j=0; j<k; j++) m2 += p.at(j);
	m = m2;
	for(int i=1; i<n; i++){
		if(n==k) break;
		m2 -= p.at(i-1);
		m2 += p.at(i+k-1);
		m = max(m,m2);
		if(i+k==n) break;
	}
	cout << fixed;
	cout << setprecision(10) << (double)(m+k)/2 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n + 1), c(n + 1), d(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[a[i]]++;
    }
    vector<int> v;
    for (int i = 1; i <= n; i++) {
        c[b[i]]++;
        d[b[i]] += b[i];
    }
    for (int i = n - 1; i >= 0; i--) {
        c[i] += c[i + 1];
    }
    for (int i = 1; i <= n; i++) {
        d[i] += d[i - 1];
    }
    for (int k = 1; k <= n; k++) {
        int ok = 0, ng = n + 1;
        while (ng - ok > 1) {
            int mid = (ok + ng) / 2;
            int t = c[mid];
            if (mid > 0) {
                t += d[mid - 1] / mid;
            }
            if (t >= k) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        cout << ok << endl;
    }
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

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


int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    sort(all(a));
    int ans = a[0];
    
    for(int i = 0; i < n-1; i++)
    {
        if(abs(a[n-1]/2-a[i])<=abs(a[n-1]/2-ans))
        {
            ans=a[i];
        }
    }
    cout<<a[n-1]<<" "<<ans<<endl;

    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;

int n,d,cnt;

int main(){
	cin>>n>>d;
	for(int i=1;i<=n;++i){
		int x,y;
		cin>>x>>y;
		if(sqrt(1LL*x*x+1LL*y*y)<=d)
			cnt++;
	}
	cout<<cnt<<endl;
}

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

using namespace std;

double EPS=1e-10;

double add(double a,double b){
  if(abs(a+b)<EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x,y;
  point(){}
  point(double x,double y) : x(x) , y(y) {}

  point operator + (point p) {
    return point(add(x,p.x),add(y,p.y));
  }
  point operator - (point p) {
    return point(add(x,-p.x),add(y,-p.y));
  }
  point operator * (double d) {
    return point(x*d,y*d);
  }
  point operator / (double d) {
    return point(x/d,y/d);
  }
  bool operator == (const point &p)const{
    return abs(x-p.x)<EPS && abs(y-p.y)<EPS;
  }
};

struct circle{
  point p;
  double r;
  circle(){}
  circle(point p,double r):p(p),r(r){}
};

double dist(point a, point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

vector<point> circle_cross_point(circle a, circle b){
  vector<point>ret;

  double x=a.p.x-b.p.x,y=a.p.y-b.p.y;
  double L=x*x+y*y;

  if(L>pow(a.r+b.r,2))return ret;

  L=sqrt(L);
  double C=atan2(b.p.y-a.p.y,b.p.x-a.p.x);
  double alpha=acos((L*L+a.r*a.r-b.r*b.r)/(2*L*a.r));

  point r1,r2;
  r1.x=a.p.x+cos(C+alpha),r1.y=a.p.y+sin(C+alpha);
  r2.x=a.p.x+cos(C-alpha),r2.y=a.p.y+sin(C-alpha);

  ret.push_back(r1),ret.push_back(r2);
  return ret;
}

int main(void){
  int n;
  point a;
  vector<point>P;
  vector<circle>C;

  while(cin >> n,n){
    P.clear();
    C.clear();
    for(int i=0;i<n;i++){
      cin >> a.x >> a.y;
      P.push_back(a);
    }

    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	if(dist(P[i],P[j])>2.0+EPS)continue;
	vector<point>res=circle_cross_point(circle(P[i],1.0),circle(P[j],1.0));
	for(int k=0;k<res.size();k++)
	  C.push_back(circle(res[k],1));
      }
    }

    int ans=1;
    for(int i=0;i<C.size();i++){
      int cnt=0;
      for(int j=0;j<P.size();j++)
	if(dist(C[i].p,P[j])<1.0+EPS)cnt++;

      ans=max(ans,cnt);
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 2216
A, B, K = map(int, input().strip().split())

if A - K <= 0:
    K = K - A
    A = 0
else:
    A = A - K
    K = 0

if B - K <= 0:
    K = K - B
    B = 0
else:
    B = B - K
    K = 0

print(A, B)

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

using namespace std;

using ll = long long;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int L, R; cin >> L >> R;
    unordered_set<int> remset;
    vector<int> rems;
    for (int i = L; i <= R; i++) {
        if (remset.find(i % 2019) != remset.end()) break;
        remset.insert(i % 2019);
        rems.push_back(i % 2019);
    }
    
    int ans = 2020;
    for (int i = 1; i < rems.size(); i++) {
        for (int j = 0; j < i; j++) {
            ans = min(ans, (rems[i] * rems[j]) % 2019);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 512
w = gets.chomp.split('').map(&:to_s)

def f(str, arr)
    len = arr.reduce(1) do |memo, item|
        item == str ? memo + 1 : memo
    end
    if(len%2 == 0) 
        arr = arr.select do |item|
            item != str
        end
        return arr.length == 0 ? true : f(arr.shift, arr)
    else 
        return false
    end
end

puts f(w.shift, w) ? "Yes" : "No"

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

int main() {
    long long A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    long long mincost = 1e9;
    for (long long i = 0; i <= 100000; i++) {
        long long c = i*2LL*C + max(0LL, X-i)*A + max(0LL, Y-i)*B;
        if (c < mincost) {
            mincost = c;
        }
    }
    cout << mincost << endl;
    return 0;
}

Measured memory_bytes: 256
def actual(n, W):
    # 重複があればアウト
    if len(set(W)) != len(W):
        return 'No'

    for i in range(len(W) - 1):
        word_now, word_next = W[i], W[i + 1]

        tail = word_now[-1]
        head = word_next[0]

        if tail != head:
            return 'No'

    return 'Yes'

N = int(input())
W = [input() for _ in range(N)]

print(actual(N, W))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}


int main(){
	char A, B;
	cin >> A >> B;
	if(A == B) Cout('H');
	else Cout('D');
}


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



int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,a,b;
    cin>>n;
    vector<pair<int,int> > arr,ans;
    for(int i=0;i<n;i++)
    {
    	cin>>a>>b;
    	arr.push_back({a,b});
	}
	
	for(int i=0;i<n;i++)
	{
ans.push_back({arr[i].first+arr[i].second,arr[i].first-arr[i].second});

	}
	sort(ans.begin(),ans.end());
	
	int maxi=1;
	int p=0;
	for(int i=1;i<n;i++)
	{
		if(ans[i].second>=ans[p].first)
		{
			p=i;
			maxi++;
		}
	}

	cout<<maxi<<endl;
    
	return 0;

	
	
}

Measured memory_bytes: 2548
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in(),x=in(),y=in();
    vector<ll>ans(n);
    for(ll i=1;i<=n;++i){
        for(ll j=i+1;j<=n;++j){
            ++ans[min(j-i,abs(x-i)+1+abs(y-j))];
        }
    }
    for(int i=1;i<n;++i)cout<<ans[i]<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+7;
int n,w[N],f[N],q[N];
inline int read(){
    int num=0; char g=getchar(); while(g<48||57<g) g=getchar();
    while(47<g&&g<58) num=(num<<1)+(num<<3)+g-48,g=getchar(); return num;
}
inline bool check(int u){
	int sx=0;
	for(int i=2;i<=n+1;i+=2){
		if(sx+f[i]-q[i-1]>=u){
			sx=max(sx,q[i+1]-f[i]);
			if(i==n+1) return true;
		}
	}
	return false;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++) w[i]=read();
	if(n%2==0){
		int a=0,b=0;
		for(int i=1;i<=n;i++) if(i&1) a+=w[i]; else b+=w[i];
		cout<<max(a,b)<<' '<<min(a,b)<<endl;
	}
	else{
		int sum=0;
		for(int i=1;i<=n+1;i++){
			sum+=w[i]; f[i]+=f[i-1],q[i]+=q[i-1];
			if(i&1) f[i]+=w[i]; else q[i]+=w[i];
		}
		int l=0,r=sum,c=0;
		while(l<=r){
			int d=(l+r)>>1; if(check(d)) c=d,l=d+1; else r=d-1;
		}
		cout<<c+q[n+1]<<' '<<sum-c-q[n+1]<<endl;
	}
}

Measured memory_bytes: 3712
// BROWNIE TK
 
#include <bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
 
#define forz(i, n) for (int i = 0; i < n; i++)
#define forzm(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
 
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define osetlli tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order

using namespace std;
 
/*STD fucntions*/
lli power(lli x,lli y,lli p)
{
    lli res=1;
    x=x%p;
    while(y>0)
    {
        if(y&1)
            res=(res*x)%p;
        //y must be even now
        y=y>>1; //y=y/2
        x=(x*x)%p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{ return a * b / gcd(a, b); }
lli modi(lli a,lli m)
{
// fermat little thm where m is prime
return power(a,m-2,m);
}
/*CODE BEGINS*/
int main()
{
 kira;
 lli n,k;
 cin>>n>>k;
 lli a[n+1];
 for(int i=1;i<=n;i++)cin>>a[i];
 lli dp[n+1][k+1];
 memset(dp,0,sizeof(dp));
 forz(i,n+1)dp[i][0]=1;
 for(int i=1;i<=n;i++)
 {
   for(int j=1;j<=k;j++)
   {
     dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
     if(j>=a[i]+1)
     {
       dp[i][j]=(dp[i][j]+mod-dp[i-1][j-(a[i]+1)])%mod;
     }
   }
 }
 cout<<dp[n][k];
 return 0;
}


Measured memory_bytes: 79104
const main = (input) => {
  var inputs = input.trim();
  var a = inputs.split(" ")[0]-0;
  var b = inputs.split(" ")[1]-0;
  var ans = ~~((a*3+b)/2);
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()

vector<int> order(vector<int>A){
    vector<int> o;
    while(A.size()!=0){
        int n = A.size();
        int a = A[0];
        int more = 0;
        FOR(i,1,n){
            if(A[i]>a)more ++;
        }
        o.push_back(n-more-1);
        A.erase(A.begin());
    }
    return o;
}


int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    int frac[8] = {1,2,6,24,120,720,5040,40320};
    REP(i,N)cin >> P[i];
    REP(i,N)cin >> Q[i];
    vector<int> OA = order(P);
    vector<int> OB = order(Q);
    int a = 1;
    int b = 1;
    REPR(i,N-2){
        a += frac[i]*OA[N-i-2];
        b += frac[i]*OB[N-i-2];
    }
    cout << abs(a-b) << endl;
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[100];
int r[9];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	inc(i, n) {
		if(a[i] < 3200) { r[ a[i] / 400 ]++; } else { r[8]++; }
	}
	
	int s = 0;
	inc(i, 8) { if(r[i]) { s++; } }
	
	int mi = max(s, 1);
	int ma = s + r[8];
	
	cout << mi << " " << ma << endl;
	
	return 0;
}


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

using namespace std;

int main(){
	
	int n,m;
	
	cin>>n>>m;
	
	string s="";
	
	for(int i=0;i<n;++i)s+='0';
	
	bool c[n];
	
	for(int i=0;i<n;++i)c[i]=false;
	
	bool f=true;
	
	for(int i=0;i<m;++i){
		int a;
		
		char x;
		
		cin>>a>>x;
		
		if(a==1&&x=='0')f=false;
		
		if(c[a-1]!=false&&s[a-1]!=x){
			cout<<-1;
			return 0;
		}
		
		c[a-1]=true;
		
		s[a-1]=x;
	}
	
	if(s.size()>1&&s[0]=='0'){
		
		if(f)s[0]='1';
		else{
			cout<<-1;
			
			return 0;
          
		}
		
	}
	
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define in freopen("input.txt", "r" ,stdin)
#define out freopen("output.txt", "w" , stdout)
#define ll long long
#define inf 100005
#define fr first
#define  sc second
#define pb push_back
#define p_b pop_back
#define mp make_pair
using namespace std;
ll n , p;
vector<ll> v;
map <ll,ll> m;
int main (){
//in;out;
ios_base::sync_with_stdio(0);

cin >> n >> p;
ll j = 2;
while (j*j <= p){
    if (p%j==0){
        p/=j;
        if (m[j] == 0){
            v.pb (j);
        }
        m[j]++;
    }
    else j++;
}

if (p > 0){
    if (m[p] == 0) v.pb (p);
    m[p]++;
}
ll ans = 1;
for (int i = 0; i < v.size();i++){
ans *= pow (v[i], m[v[i]] / n);
}
cout << ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int		n, m;
	while(scanf("%d%d", &n, &m)==2)
	{
		vvi s(m);
		vi p(m);

		for(int i=0;i<m;i++)
		{
			int k;

			scanf("%d", &k);
			s[i].resize(k);
			for(int j=0;j<k;j++)
			{
				scanf("%d", &s[i][j]);
			}
		}
		for(int i=0;i<m;i++)
		{
			scanf("%d", &p[i]);
		}

		int ans=0;
		for(int i=0;i<(1<<n);i++)
		{
			int c=0;
			for(int j=0;j<m;j++)
			{
				int t=0;
				for(int k=0;k<s[j].size();k++)
				{
					t^=(i>>(s[j][k]-1))&1;
				}
				if(t==p[j]) c++;
			}
			if(c==m) ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    set<string> dic;

    for(int i=0; i<n; i++){
        string s;
        cin>>s;
        dic.insert(s);
    }

    cout<<dic.size()<<endl;
    
    return 0;
}

Measured memory_bytes: 19228
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;

char s[55][55],t[55][55];

int main()
{
	int N,M,pos;
	bool ok;
	while(~scanf("%d%d",&N,&M)){
		ok = false;
		for(int i = 1;i <= N;i++) scanf("%s",s[i] + 1);
		for(int i = 1;i <= M;i++) scanf("%s",t[i] + 1);
		for(int i = 1;i <= N - M + 1;i++){
			for(int j = 1;j <= N - M + 1;j++){
				pos = 0;
				for(int k = 0;k < M;k++){
					for(int l = 0;l < M;l++){
						if(s[i + k][j + l] == t[k + 1][l + 1]) pos++;
						else{
							pos = 0;
							break;
						}
					}
					if(!pos) break;
				}
				if(pos == M * M){
					ok = true;
					break;
				}
			}
			if(ok) break;
		}
		if(ok) printf("Yes\n");
		else printf("No\n");
	}
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 3008;
typedef vector<int> vec;
typedef vec::iterator it;

char s[N*2];
int d[N], c[N], *L[N], *R[N];

int Lyndon(int i) {
	while (d[i]) {
		int j = i, k = i + 1;
		for (; d[k] && d[j] >= d[k]; k++)
			if (d[j] > d[k]) j = i;
			else j++;
		if (!d[k]) return i;
		k -= j;
		while (i <= j) i += k;
	}
	return i;
}

void out(int *l, int *r) {
	int *t = c;
	while (l < r) {
		putchar('b');
		t[*l++]++;
		while (*t) putchar('a'), --*t;
		t++;
	}
}

int main() {
	scanf("%*d%s",s);
	int a = 0, b = 0, n = 0;
	for (int i = 0; s[i]; i++) {
		if (s[i] == 'b') b++;
		else d[a++] = b;
		if (a < b) n = b;
	}
	int l = 0, top = -1;
	for (int i = 0; i < n; i++)
		if (!(d[i] -= i + 1)) {
			int t = Lyndon(l); l = i + 1;
			while (~top && lexicographical_compare(L[top], R[top], d+t, d+l)) top--;
			L[++top] = d+t; R[top] = d+l;
		}
		else if (d[i] < 0) l = i + 1;
	for (int i = 0; i <= top; i++)
		out(L[i], R[i]);
	for (int i = n; i < b; i++)
		if (d[i] >= n) n = i+1, printf("ab");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
ll A, B, C, ans = 0;
ll aa, bb, cc;
int main()
{
    cin >> A >> B >> C;
    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0)
    {

        if (A == B && B == C)
        {
            ans = -1;
            cout << ans << endl;
            return 0;
        }
        aa = A / 2;
        bb = B / 2;
        cc = C / 2;
        A = bb + cc;
        B = aa + cc;
        C = bb + aa;
        // cout << A << "," << B << "," << C << endl;

        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100050],b[100050],c[100050];
int main(){
	int n,m,i;
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%d",a+i);
		b[i]=a[i];
	}
	sort(b+1,b+n+1);m=unique(b+1,b+n+1)-b-1;
	for(i=1;i<=n;++i)++c[lower_bound(b+1,b+m+1,a[i])-b];
	if(b[1])puts(m==3&&c[1]==c[2]&&c[2]==c[3]&&(b[1]^b[2])==b[3]?"Yes":"No");
	else if(m==1)puts("Yes");
	else if(m==2)puts((c[1]<<1)==c[2]?"Yes":"No");
	else puts("No");
	return 0;
}

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

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

template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
struct Unionfind {
    vector<int> par;

    Unionfind(int n) : par(n) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] =ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    int n;
    cin >> n;

    const int num = 1000000;
    vector<int> cnt(num+1, 0);
    vector<int> a(n);

    int a_1_cnt = -1;
    rep(i, n) {
        cin >> a[i];
        if(a[i] == 1) ++a_1_cnt;
        if(a_1_cnt >= 2) {
            cout << 0 << endl;
            return 0;
        }

        for(int j = a[i]; j <= num; j += a[i]) ++cnt[j];
    }

    int ans = 0;
    rep(i, n) {
        if(cnt[a[i]] == 1) ++ans;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
   int h,n,a;
   cin>>h>>n;
   long long sum=0;
   for(int i=0;i<n;i++)
   {
       cin>>a;
       sum+=a;
   }
   if(sum>=h)cout<<"Yes\n";
   else cout<<"No\n";
	return 0;
}


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

using namespace std;

const int N = 2e3 + 5;

int res[N];

int n, x, y;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> x >> y;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int d1 = j - i;
            int d2 = abs(i - x) + abs(j - y) + 1;
            int d3 = abs(i - y) + abs(j - x) + 1;
            int w = min({d1, d2, d3});
            res[w] += 1;
        }
    }
    for (int i = 1; i < n; i++)
        cout << res[i] << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main() {
	int a[] = { 0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1 };
	int x, y;
	cin >> x >> y;
	cout << (a[x] == a[y] ? "Yes" : "No") << endl;
}

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

int calc(int a, int b, string op){
    if(op == "+") return (a + b) % 256;
    if(op == "-") return (a - b + 256) % 256;
    if(op == "*") return (a * b) % 256;
    if(op == "/") return (a / b) % 256;
    return -1;
}

int main(){
    int m;
    cin >> m;
    map<string, bitset<256> > v;
    for(int i=0; i<m; i++){
        string name;
        int lb, ub;
        cin >> name >> lb >> ub;
        bitset<256> r;
        for(int j=lb; j<=ub; j++){
            r[j] = 1;
        }
        v[name] = r;
    }
    map<string, bool> number;
    for(int i=0; i<256; i++){
        bitset<256> a;
        a[i] = 1;
        v[to_string(i)] = a;
        number[to_string(i)] = true;
    }   

    int n;
    cin >> n;
    stack<string> s;
    bool success = true;
    for(int i=0; i<n; i++){
        string str;
        cin >> str;
        if(!success) continue;
        if(str == "+" || str == "-" || str == "*" || str == "/"){
            string b = s.top();
            s.pop();
            string a = s.top();
            s.pop();
            if(str == "/" && v[b][0]==1){
                success = false;
                continue;
            }
            if(number.count(a)!=0 && number.count(b)!=0){
                s.push(to_string(calc(stoi(a), stoi(b), str)));
            }else{
                bitset<256> newrange;
                string newname;
                if(number.count(a)==0) newname = a;
                else newname = b;
                for(int j=0; j<256; j++){
                    for(int k=0; k<256; k++){
                        if(v[a][j]==1 && v[b][k]==1){
                            newrange[calc(j, k, str)] = 1;
                        }
                    }
                }
                v[newname] = newrange;
                s.push(newname);
            }
        }else{
            s.push(str);
        }   
    }

    if(success){
        cout << "correct" << endl;
    }else{
        cout << "error" << endl;
    }
    return 0;
}



Measured memory_bytes: 3340