akhauriyash/Code-Regression huggingface dataset:
#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 ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
 
const int N = 2e6 + 6;
const int M = 1e9+7;
pii A[N];
int n , m;

void solve()
{
	int n;
	cin >> n;

	loop(i,0,n)cin >> A[i].ff >> A[i].ss;

	int ok = 0;

	loop(i,0,n)
	{
		int f = 1;
		loop(j,0,3)
		{
			if(i+j >= n)
			{
				f = 0;
				break;
			}
			else 
			{
				if(A[i+j].ff == A[i+j].ss)continue;
				else
				{
					f = 0;
					break;
				}
			}
		}
		if(!ok)ok = f;
	}

	if(ok)cout << "Yes";
	else cout << "No";
}			
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	
 
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1000000000000001;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

ll xors(ll a){
    if(a<0) return 0ll;
    ll m = (a+1)/2;
    if(m%2==1 && a%2==0){
        return 1ll^a;
    }
    else if(m%2==1){
        return 1ll;
    }
    else if(m%2==0 && a%2==1){
        return 0;
    }
    else{
        return a;
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    ll ans = xors(a-1);
    ans ^= xors(b);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());




int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    ll a,b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}


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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

const int MOD = 1000000007;


void add_self(int& a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

void sub_self(int& a, int b) {
	a -= b;
	if (a < 0) {
		a += MOD;
	}
}


const ll INF = 1e18L + 5;

int main() {

	// fast input/output
	FAST_IO;

	int n, W;
	cin >> n >> W;
	vector<ll> weight(n), value(n);
	for (int i = 0; i < n; ++i) {
		cin >> weight[i] >> value[i];
	}
	int sum_value = 0;
	for (auto x : value)
		sum_value += x;

	vector<ll> dp(sum_value + 1, INF); // 0....W
	// dp[i] means the minumum total weight with total of values exactly i
	dp[0] = 0;

	for(int item = 0; item <  n; ++item) {
		for(int value_already = sum_value - value[item]; value_already >= 0; --value_already){
			dp[value_already + value[item]] = min(dp[value_already + value[item]], dp[value_already] + weight[item]);
		}
	}
	ll ans = 0;
	for (int i = 0 ; i <= sum_value; ++i) {
		if(dp[i] <= W)
			ans = max(ans, ll(i));
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <vector>
 
using namespace std;
 
const int N_ = 200500;
 
int X[N_];
long long S[N_];
 
int main()
{
    int N, A; scanf("%d%d", &N, &A);
    for(int i = 1; i <= N; i++) scanf("%d", &X[i]);
 
		for(int i = 1; i <= N; i++) {
			S[i] = S[i-1] + X[i];
		}
 
		long long ans = 9e18;
		for(int k = 1; k <= N; k++) {
			// x_1 + 4x_1 + (9-4) x_2 + (16-9)x_3 + (25-16) x_4....
			// 5x_1 + 5x_2 + 7x_3 + 9x_4 + ...
			long long cur = (long long)A * (k + N);
			for(int i = N, c = 1; i > 0; i -= k, c += 1) {
				cur += (S[i] - S[max(i-k, 0)]) * (c == 1 ? 5 : 2 * c + 1);
				cur = min(cur, (long long)9e18);
			}
			ans = min(ans, cur);
		}
 
		printf("%lld\n", ans);
 
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main() {
    int N, ans;
    scanf("%d", &N);

    ans = N % 10;
    
    if(ans == 3) {
        printf("bon");
    } else if (ans == 0 || ans == 1 || ans == 6 || ans == 8) {
        printf("pon");
    } else {
        printf("hon");
    }

    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#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 INF 2e9
#define IMAX 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long llong;

llong getGCM(llong a, llong b) {
	llong mod;
	llong swap;
	if (a < b) {
		swap = a;
		a = b;
		b = swap;
	}
	while (true) {
		mod = a % b;
		if (mod == 0) {
			break;
		}
		swap = b;
		b = a % b;
		a = swap;
	}
	return b;
}

int main()
{
	//142_D
	llong A, B;
	cin >> A >> B;

	// 最小公倍数
	llong gcm = getGCM(A,B);

	llong ans = 1;
	if (gcm > 1) {
		// 最小公倍数を素因数分解して、その素数+1が答え

		bool canDiv = false;
		while (gcm % 2 == 0) {
			canDiv = true;
			gcm = gcm / 2;
		}
		if (canDiv) {
			++ans;
		}
		llong divisor = 3;
		// upper
		llong upper = (llong) sqrt((double) gcm) + 1;
		while (gcm > 1) {
			//
			if (divisor > upper) {
				// 素数判定して終了する
				++ans;
				break;
			}

			canDiv = false;
			while (gcm % divisor == 0) {
				canDiv = true;
				gcm = gcm / divisor;
			}
			if (canDiv) {
				++ans;
				// upper再計算
				upper = (llong) sqrt((double) gcm) + 1;
			}
			divisor += 2;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n,m,k;
  cin>>n>>m>>k;
  long long int a[n+1],b[m+1];
  long long int ta[n+1],tb[m+1];
  ta[0]=0;
  tb[0]=0;
  for(long long int j =1;j<=n;j++){
    cin>>a[j];
    ta[j]=ta[j-1]+a[j];
  }
  for(long long int j=1;j<=m;j++){
cin>>b[j];
    tb[j]=tb[j-1]+b[j];
  }
  long long int mx = 0;
  long long int best = m,v;
  for(long long int j =0;j<=n;j++){
    if(ta[j]<=k){
      for(v = best;v>=0;v--){
        if(ta[j]+tb[v]<=k){best=v;
                           mx=max(mx,j+v);
                           break;
                          }
      }
      if(v==-1){mx=max(mx,j);
                best=0;
               }
    }
  }
    cout<<mx<<endl;
}
      
    


Measured memory_bytes: 9840
n = int(input())
a = []
for i in range(n):
  s, p = input().split()
  a.append([s, int(p), i])
a = sorted(a, key=lambda x:x[1], reverse=True)
a = sorted(a, key=lambda x:x[0])
for b in a:
    print(b[2]+1)

Measured memory_bytes: 3060
h, w, m = map(int, input().split())
a = [0]*h; b = [0]*w; c = {}
for _ in range(m):
    H, W = map(int, input().split())
    H -= 1; W -= 1
    a[H] += 1; b[W] += 1
    c[H*10**6+W] = 0
amaxvalue = max(a); bmaxvalue = max(b)
amaxkey = []; bmaxkey = []
for i in range(h):
    if a[i] == amaxvalue: amaxkey.append(i)
for i in range(w):
    if b[i] == bmaxvalue: bmaxkey.append(i)
d = 0
for i in range(len(amaxkey)):
    for j in range(len(bmaxkey)):
        if amaxkey[i]*10**6+bmaxkey[j] not in c:
            print(amaxvalue+bmaxvalue)
            d = 1
            break
    if d == 1: break
else: print(amaxvalue+bmaxvalue-1)

Measured memory_bytes: 166544
n, d = map(int, raw_input().split())
D = map(int, raw_input().split())
A = [0]*(n+1)
P = [0]*(n+1)

P[0] = pos = d
for i, x in enumerate(D):
    if x <= 2*pos:
        pos = abs(x-pos)
    P[i+1] = pos
    if pos == 0:
        break

for i in xrange(n-1, -1, -1):
    if D[i] <= 2*A[i+1]+1:
        A[i] = A[i+1] + D[i]
    else:
        A[i] = A[i+1]

q = input()
Q = map(int, raw_input().split())
for i in Q:
    if P[i-1] <= A[i] and pos == 0:
        print "NO"
    else:
        print "YES"


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

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
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() ? "\n" : " ");
	return os;
}

template <class T>
ostream &operator<<(ostream &os, const set<T> &st) {
	for (const auto &e : st) os << e << " ";
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
	for (const auto &e : mp) os << e << " ";
	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<class T = lint>
struct Edge {
	int to;
	T cost;
	int tank;
	Edge() {}
	Edge(int to, T cost, int tank = 0) : to(to), cost(cost), tank(tank) {}
	bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

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

	vector<vector<Edge<int>>> edges(N);
	for (int i = 0; i < M; i++) {
		int u, v, len;
		cin >> u >> v >> len;
		u--, v--;
		edges[u].emplace_back(v, len);
		edges[v].emplace_back(u, len);
	}

	auto bfs = [&](int st) {
		vector<pair<int, int>> dp(N, { INF, 0 });
		dp[st] = { 0, -L };
		queue<pair<int, pair<int, int>>> que;
		que.emplace(st, dp[st]);
		while (!que.empty()) {
			auto now = que.front();
			que.pop();
			for (const auto &e : edges[now.first]) {

				if (e.cost > L || now.second> dp[e.to]) continue;

				auto tmp = now.second;
				if (e.cost > -tmp.second) {
					tmp.first++;
					tmp.second = -L + e.cost;
				}
				else tmp.second += e.cost;

				if (tmp < dp[e.to]) {
					dp[e.to] = tmp;
					que.emplace(e.to, tmp);
				}

			}
		}
		return dp;
	};

	vector<vector<pair<int, int>>> memo(N);
	for (int i = 0; i < N; i++) memo[i] = bfs(i);

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int s, t;
		cin >> s >> t;
		s--, t--;
		auto tmp = memo[s][t].first;
		if (tmp != INF) cout << tmp << "\n";
		else cout << -1 << "\n";
	}

	return 0;
}


Measured memory_bytes: 3072
S = input()
lens = len(S)
T = input()
lent = len(T)
if lens < lent:
    print('UNRESTORABLE')
else:
    ii = lens - lent
    while True:
        subs = S[ii:]
        for j in range(lent):
            if subs[j] == '?':pass
            elif subs[j] != T[j]:
                #print('not match',subs,T)
                ii -= 1
                break
        else:
            #print('matched:',ii,subs,T)
            newS = ''
            if ii == 0:newS = T+S[lent:]
            else:newS = S[0:ii] + T + S[ii+lent:]
            print(newS.replace('?','a'))
            break
        if ii < 0:
            print('UNRESTORABLE')
            #print('scan end.','UNRESTORABLE')
            break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60; //const ll mod=1e9+7; const int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
ll p;
ll b[3005];
ll x[3005];
ll mod;

ll power(ll x, ll n, ll MOD=mod){
	if(n == 0) return 1;
	ll res = power(x, n/2, MOD);
	res = res*res%MOD;
	if(n&1) res = res*x%MOD;
	return res;
}

ll inv(ll x, ll MOD=mod){
	return power(x, MOD-2, MOD);
}

int main(){
	cin >> p;
    mod = p;

	//interpolation O(n^{2})
	//Ay = b, A:Vandermonde's matrix 
    for(int i = 0; i <= p; i++) x[i] = i; // x is A's element.
    for(int i = 0; i < p; i++) cin >> b[i];
    int n = p - 1;
    for(int k = 0; k <= n-1; k++) {
        for(int i = n; i >= k + 1; i--) {
            b[i] = (b[i] - b[i-1] + mod) * inv(x[i] - x[i-k-1] + mod);
            b[i] %= mod;
        }
    }
        for(int k = n - 1; k >= 0; k--) {
            for(int i = k; i <= n - 1; i++) {
                b[i] = b[i] - b[i+1] * x[k];
                b[i] += mod * mod;
                b[i] %= mod;
            }
        }
    for(int i = 0; i <= n; i++) {
        cout << b[i] << " ";
    }
    cout << endl;
    return 0;
}


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

const int INF =1e9 + 5;

int main(){
	int n;
	cin>>n;
	int a[n+1],b[n+1],c[n+1];

	for(int i=1;i<n+1;i++)
		cin>>a[i]>>b[i]>>c[i];

	
	int dp[n+1][3];

	for(int i=0;i<=n;i++){
		dp[i][0]=0;
		dp[i][1]=0;
		dp[i][2]=0;
	}
	
	for(int i=1;i<=n;i++){
			dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
			dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
			dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
	}

	cout<<max({dp[n][0],dp[n][1],dp[n][2]});
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>

using namespace std;

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

    string s;
    vector<int> v(26);
    cin >> s;
    for (int i = 0, l = s.length(); i < l; ++i) ++v[s[i]-'a'];
    for (int i = 0; i < 26; ++i){
        if (v[i] == 0) {
            cout << (char)('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define N 105

using namespace std;

int n;

struct vec {
	long long x, y;
	vec (long long tx = 0, long long ty = 0) { x = tx, y = ty; }
	vec operator + (const vec &t) const { return vec(x + t.x, y + t.y); }
	vec operator - (const vec &t) const { return vec(x - t.x, y - t.y); }
	long long lenth() { return x * x + y * y; }
}a[2 * N];

bool cmp(const vec &lhs, const vec &rhs) {
	return atan2(lhs.y, lhs.x) < atan2(rhs.y, rhs.x);
}

inline int read() {
	int x = 0; bool neg = false; char ch = getchar();
	while(!isdigit(ch)) (ch == '-') && (neg = true), ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return neg ? -x : x;
}

int main() {
	n = read();
	for(int i = 1; i <= n; ++i)
		a[i].x = read(), a[i].y = read();
	
	sort(a + 1, a + n + 1, cmp);
	
	for(int i = 1; i <= n; ++i)
		a[n + i] = a[i];
	
	vec cur;
	long long ans = 0;
	for(int l = 1; l <= n; ++l) {
		cur = vec(0, 0);
		for(int r = l; r < l + n; ++r) {
			cur = cur + a[r];
			ans = max(ans, cur.lenth());
		}
	}
	
	printf("%.11lf\n", sqrt(ans));
	return 0;
}

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

typedef long long ll;
typedef pair<int,int> p;



class DTriangles {
public:
    int dy[4]={-1,1,0,0};
    int dx[4]={0,0,1,-1};
    ll N;
    vector<ll> L;

	void solve(std::istream& in, std::ostream& out) {
        in >> N;

        REP(i, N) {
            ll l;
            in >> l;
            L.pb(l);
        }

        sort(L.begin(), L.end());
        ll ans = 0;

        for(ll mid = N - 1; mid >= 0; mid--) {
            for(ll low = mid - 1; low >= 0; low--) {
                auto itr = lower_bound(L.begin(), L.end(), L[mid]+L[low]);
                ll ng_num = distance(itr, L.end());
                ans += (N - 1 - mid) - ng_num;
            }
        }
        out << ans << endl;
	}
};


int main() {
    ios::sync_with_stdio(false);
	DTriangles solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
s = input()
t = input()
q = int(input())

sa_pre = [s[i] == "A" for i in range(len(s))]
ta_pre = [t[i] == "A" for i in range(len(t))]

sa = [0, sa_pre[0]]
ta = [0, ta_pre[0]]

for i in range(1, len(s)):
	sa.append(sa[-1] + sa_pre[i])

for i in range(1, len(t)):
	ta.append(ta[-1] + ta_pre[i])

def check(a, b, c, d):
	xa = sa[b] - sa[a - 1]
	ya = ta[d] - ta[c - 1]
	if (2 * xa - (b - a + 1)) % 3 == (2 * ya - (d - c + 1)) % 3:
		print("YES")
		return
	else:
		print("NO")
		return

for _ in range(q):
	a, b, c, d = map(int, input().split())
	check(a, b, c, d)

Measured memory_bytes: 59772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i, h) cin >> a[i];
  rep(i, w + 2) cout << "#";
  cout << endl;
  rep(i, h){
    cout << "#" + a[i] + "#" << endl;
  }
  rep(i, w + 2) cout << "#";
  cout << endl;
}

Measured memory_bytes: 256
n = int(input())

ans = []

def is_prime(x):
    for y in range(3,int(x**(1/2))+2,2) :
        if x%y == 0 :
            return False
    return True

cur = 11
while len(ans) < n :
    if is_prime(cur) :
        ans.append(cur)
    cur += 10

print(' '.join(map(str,ans)))


Measured memory_bytes: 3064
dice = map(int, raw_input().split())
inst = raw_input()
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
for i in range(len(inst)):
    rolling(inst[i], dice)
print dice[0]

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A == B && B == C && A == C) {
    cout << "No" << endl;
  }
  else if (A == B || B == C || A == C) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
def fact(i):
    global d
    k=0
    while i%2==0:
        i//=2;k+=1
    d[2]+=k
    for p in range(3,33,2):
        k=0
        while i%p==0:
            i//=p;k+=1
        d[p]+=k
    if i>1:
        d[i]+=1

from collections import defaultdict
mod=10**9+7

N=int(input())
d=defaultdict(int)

for i in range(2,N+1):
    fact(i)

ans=1
for k in d.values():
    ans=(ans*(k+1))%mod

print(ans)

Measured memory_bytes: 39152
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

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

    long long shou = n;;
    string ans = "";
    while (shou != 0) {
        long long amari = (shou-1) % 26;
        shou = (shou-1) / 26;
        char c = 'a' + amari;
        ans = c + ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <numeric>
#include <functional>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define INF 1e9
#define MOD 1e9+7
#define ll long long

using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> v(n),vv(m);
    rep(i,0,n)cin>>v[i].first>>v[i].second;
    rep(i,0,m)cin>>vv[i].first>>vv[i].second;
    
    rep(j,0,n){
        ll minn=INF,minnum=0;
        rep(i,0,m){
            
            if(minn>abs(v[j].first-vv[i].first)+abs(v[j].second-vv[i].second)){
                minn=abs(v[j].first-vv[i].first)+abs(v[j].second-vv[i].second);
                minnum=i;
            }
        }
        cout<<minnum+1<<endl;
    }
}


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

using namespace std;

#define N 100000
#define pb push_back

int n, k, len, a[N + 5], d[N + 5], vis[N + 5], ans;
vector<int> G[N + 5];

struct Cmp {
	bool operator () (const int &a, const int &b) const {
		return d[a] < d[b];
	}
};
priority_queue<int, vector<int>, Cmp> pq;

void dfs1(int u) {
	for (int i = 0, v; i < G[u].size(); ++i) {
		v = G[u][i];
		d[v] = d[u] + 1;
		dfs1(v);
	}
}

void dfs2(int u) {
	len++;
	if (u == 1)
		return ;
	dfs2(a[u]);
}

void mark(int u) {
	vis[u] = 1;
	for (int i = 0, v; i < G[u].size(); ++i) {
		v = G[u][i];
		if (vis[v])
			continue;
		mark(v);
	}
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	dfs2(a[1]);
	for (int i = 2; i <= n; ++i)
		G[a[i]].pb(i);
	dfs1(1);
	bool flag = 1;
	for (int i = 1; i <= n; ++i)
		if (d[i] > k || (k - d[i]) % len) {
			flag = 0;
			break;
		}
	if (flag)
		ans = 0;
	else {
		if (a[1] != 1) ans = 1;
		else ans = 0;
		a[1] = 1;
		for (int i = 2; i <= n; ++i)
			pq.push(i);
		while (!pq.empty()) {
			int u = pq.top(), v; pq.pop();
			if (d[u] <= k || vis[u])
				continue;
			ans++;
			v = u;
			for (int i = 1; i <= k - 1; ++i)
				v = a[v];
			a[v] = 1;
//			printf("u:%d v:%d\n", u, v);
			mark(v);
		}
	}
	printf("%d\n", ans);
//	for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
//	printf("\n");
	return 0;
}

Measured memory_bytes: 12152
#include<iostream>
using  namespace  std;
int   main()
{
    int   a,b,c=0,d=0;
    cin>>a>>b; 
    c=a+b;
    if(c%2!=0)
    d=(c+1)/2;
    if(c%2==0)
    d=c/2;
    cout<<d;
    return   0;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define int ll
ll po(ll a, ll x, ll m) { if (x == 0) {return 1;} ll ans = 1; ll k = 1;  while (k <= x) {if (x & k) {ans = ((ans * a) % m);} k <<= 1; a *= a; a %= m; } return ans; }
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE
map<int, vector<int>>tree;
vector<bool>vis;
vector<int>here;
void dfs(int u) {
    vis[u]  = true;
    here[u] = 1;
    int sz = 0;
    for (auto v : tree[u]) {
        if (vis[v]) {
            sz = max(sz, here[v]);
            continue;
        }
        dfs(v);

        sz = max(sz, here[v]);
    }
    here[u] += sz;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m;
    cin >> n >> m;
    forr(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        tree[a].pb(b);
    }
    vis  = vector<bool>(n, false);
    here = vector<int>(n);
    int mx  = 0;
    forr(i, n) {
        if (!vis[i]) {
            dfs(i);
        }
        mx  = max(mx, here[i]);
    }
    cout << mx - 1 << "\n";
    return 0;
}

Measured memory_bytes: 16128
import sys
input = sys.stdin.readline
n=int(input())
AB=[]
append=AB.append
for i in range(n):
  a,b=map(int,input().split())
  append((a+b,a,b))
AB.sort(key=lambda x:x[0],reverse=True)
ans=0
sign=0
for i in range(n):
  ab,a,b=AB[i]
  if sign==0:
    ans+=a
    sign=1
  else:
    ans-=b
    sign=0
print(ans)


Measured memory_bytes: 59100
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };


int main(void) {
	
	long long int k, a, b;
	long long int p;
	long long int total = 1;


	cin >> k >> a >> b;

	if (a+2 >= b) {
		total += k;
	}
	else {
		if (k - 1 < a) {
			total += k;
		}
		else {
			p = k - (a - 1);
			total = a;
			if (p % 2 == 0) {
				total += (p / 2)*(b - a);
			}
			else {
				total += (p / 2)*(b - a) + 1;
			}
		}
	}

	cout << total << endl;


	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int zero=0,one=0;
    string s;
    cin >> s ;
    REP(i,s.size()){
        if(s[i]-'0'){
            one++;
        }else{
            zero++;
        }
    }
    cout << min(one,zero)*2 << endl;

    return 0;
}

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

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

    vector<float> values(num);
    for (int i = 0; i < num; i++) cin >> values[i];

    sort(values.begin(), values.end());

    float result = values[0];
    for (int i = 1; i < num; i++) {
        result = (result + values[i]) / 2;
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

#define N 5

int main(void)
{
    int arg[N];
    int i, count = 0;
    
    for(i=0; i<5; i++) {
        scanf("%d", &arg[i]);
        if(arg[i] == 0) {
            count = i+1;
        }
    }

    printf("%d\n", count);


    return 0;
}

Measured memory_bytes: 1708
#include <cstdio>

using namespace std;

//bus?????°

int bus( int P, int W[], int n, int k ){

    int i, buffer, sum, count, number;

    sum = 0;
    number = 0;
    count = 1;

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

        sum += W[i];

        if( sum > P ){

            sum = W[i];
            count++;

            if( sum > P ) return 0;
            
            if( count > k){

                break;

            }

        }

        number++;

    }

    return number;

}

//binary search

int binary_search( int W[], int sum_weight, int n , int k ){

    int left, j, buffer;
    long long right;

    left = 0;
    right = sum_weight;

    while( left < right ){

        j = ( left + right ) / 2;

        buffer = bus( j, W, n, k);

        if ( buffer >= n ){ 
            
            right = j;

            if( right - left <= 0 ) left--;

        }else{

            left = j + 1;

        }

            if( right - left == 0 ) {left--; break;}

//        printf(" P = %d, number of baggage = %d, left = %d, right = %d\n", j, buffer, left,right);

    }
//        printf(" P = %d, number of baggage = %d, left = %d, right = %d\n", j, buffer, left,right);

    return left+1;

}

//??¬???

int main(){

    int n, k, i, P;
    long long sum_weight = 0;

    scanf("%d %d", &n, &k);

    int W[n];

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

        scanf("%d", &W[i] );

        sum_weight += W[i];

    }

    P = binary_search( W, sum_weight, n, k );

    printf("%d\n", P);



}

Measured memory_bytes: 3144
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() 
{
    int n; cin >> n; 
    int h[n+1];
    h[0]=0;
    int dp[n+1];
    dp[0]=0;
    dp[1]=0;
    for(int i=1;i<=n;i++)
    {
        cin >> h[i];
    }
    dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n];
}


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

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e5;

int w, h;
char bd[22][22];
int d[22][22][22][22]; // d[i][j][k][l] := distance of (i,j) to (k,l)

class P {
public:
	int x, y;
	P() {};
	P(int x, int y): x(x), y(y) {};
	bool operator<(const P &a) {
		return x < a.x || (x == a.x && y < a.y);
	}
};

void init() {
	for (int i=0; i<22; ++i) {
		for (int j=0; j<22; ++j) {
			bd[i][j] = 'x';
		}
	}
}

void calc() {
	for (int i=0; i<22; ++i) {
		for (int j=0; j<22; ++j) {
			for (int k=0; k<22; ++k) {
				for (int l=0; l<22; ++l) {
					d[i][j][k][l] = INF;
				}
			}
		}
	}
	for (int i=1; i<=h; ++i) {
		for (int j=1; j<=w; ++j) {
			if (bd[i][j] == 'x') continue;
			d[i][j][i][j] = 0;
			for (int k=0; k<4; ++k) {
				if (bd[i+dy[k]][j+dx[k]] == 'x') continue;
				d[i][j][i+dy[k]][j+dx[k]] = 1;
			}
		}
	}
	for (int i=1; i<=h; ++i) {
		for (int j=1; j<=w; ++j) {
			for (int k=1; k<=h; ++k) {
				for (int l=1; l<=w; ++l) {
					for (int m=1; m<=h; ++m) {
						for (int n=1; n<=w; ++n) {
							d[k][l][m][n] = min(d[k][l][m][n], d[k][l][i][j]+d[i][j][m][n]);
						}
					}
				}
			}
		}
	}
}

int main() {
	while (cin >> w >> h) {
		if ( ! w) break;
		init();

		P robo;
		vector<P> dirty;
		for (int i=1; i<=h; ++i) {
			for (int j=1; j<=w; ++j) {
				cin >> bd[i][j];
				if (bd[i][j] == 'o') {
					robo.x = j;
					robo.y = i;
				} else if (bd[i][j] == '*') {
					dirty.push_back(P(j, i));
				}
			}
		}

		if (dirty.empty()) {
			cout << 0 << endl;
			continue;
		}

		calc();

		int mn = INT_MAX;
		sort(dirty.begin(), dirty.end());
		do {
			int t = d[robo.y][robo.x][dirty[0].y][dirty[0].x];
			for (int i=0; i+1<(int)dirty.size(); ++i) {
				t += d[dirty[i].y][dirty[i].x][dirty[i+1].y][dirty[i+1].x];
			}
			mn = min(mn, t);
		} while (next_permutation(dirty.begin(), dirty.end()));

		if (mn >= INF) cout << -1 << endl;
		else cout << mn << endl;
	}
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define lld double
#define vi vector<ll>
#define pii pair<int,int>
#define piii pair<pii, ll>
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define ppb pop_back
#define d0(x) cout<<x<<" "
#define d1(x) cout<<(x)<<"\n"
#define d2(x,y) cout<<x<<" "<<y<<"\n"
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"
#define d5(x,y,z,w,s) cout<<x<<" "<<y<<" "<<z<<" "<<w<<" "<<s<<endl
using namespace std;
const ll mod = 1e9+7;


int main()
{
    ll n,a,b;
    cin>>n>>a>>b;

    assert(b>a);

    ll c = (b-a);

    if((c&1LL)==0LL)
    {
        d1(c/2);return 0;
    }

    d1(min(a-1,n-b)+1+c/2);
}


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

using namespace std;

int D, G;
vector<int> P(10), C(10), sum(10);
int ans = 1000000000;

void dfs(int depth, vector<int> v){
    if( depth == D ){
        int resNum = 0, sumScore = 0;
        for(int i=0;i<D;i++){
            if( v[i] == 1 ){
                resNum += P[i];
                sumScore += (i+1) * 100 * P[i];
                sumScore += C[i];
            }
        }
        bool flg = false;
        if( sumScore < G ){
            int j = D-1;
            while( v[j] == 1 )  j--;
            for(int k=0;k<P[j] && j>=0;k++){
                sumScore += (j+1) * 100;
                resNum++;
                if( G <= sumScore ){
                    flg = true;
                    break;
                }
            }
        } else {
            flg = true;
        }
        if( flg ) ans = min(ans, resNum);
        return;
    }

    v[depth] = 0;
    dfs(depth+1, v);
    v[depth] = 1;
    dfs(depth+1, v);

    return;
}

int main() {
    cin >> D >> G;

    for(int i=0;i<D;i++)    cin >> P[i] >> C[i];

    int maxSum=0, maxIndex;
    for(int i=0;i<D;i++){
        sum[i] = (i+1) * 100 * P[i] + C[i];
    }

    vector<int> v(D);
    dfs(0, v);

    cout << ans << endl;
}

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

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

    if(n % 2 == 1){
        cout << "No" << endl;
    }
    else{ string x = s.substr(0, n / 2 );
          string y = s.substr(n / 2 , n - 1);
          if(x == y) {
              cout << "Yes" << endl;
          }else{
              cout << "No" << endl;
          }
        }
    return 0;
}

Measured memory_bytes: 888
memo = {}

def fib_memo(n):
  if n <= 1:
    return 1
  if n in memo:
    return memo[n]
  memo[n] = fib_memo(n - 1) + fib_memo(n - 2)
  return memo[n]

x = int(raw_input())

print fib_memo(x)

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

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

    vector<pair<int,int>> red(n), blue(n);
    for(int i=0; i<n; i++){
        int a, b;
        cin >> a >> b;
        red[i] = make_pair(a,b);
    }
    for(int i=0; i<n; i++){
        int c, d;
        cin >> c >> d;
        blue[i] = make_pair(c,d);
    }

    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());
    
    // solve
    int count = 0;
    vector<int> used(n);// red
    for(int i=0; i<n; i++){
        int p = -1, y = -1;
        for(int j=0; j<n; j++){
            if(used[j] == 0 && red[j].first < blue[i].first && red[j].second < blue[i].second){
                if(red[j].second > y){
                    p = j;
                    y = red[j].second;
                }
            }
        }
        if(p != -1){
            count += 1;
            used[p] = 1;
        }
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;

int main(void)
{
	int t;
	int ar[9];
	char ar2[9];
	vector<int> R(9);
	vector<int> G(9);
	vector<int> B(9);

	cin >> t;

	for(int i= 0; i < t; i++)
	{
		int ar[9];
		char ar2[9];
		vector<int> R(9);
		vector<int> G(9);
		vector<int> B(9);

		int counter = 0;

		for(int i = 0; i < 9; i++)
			cin >> ar[i];

		for(int i = 0; i < 9; i++)
			cin >> ar2[i];

		for(int i = 0; i < 9; i++)
		{
			if(ar2[i] == 'R')
				R[ar[i]-1]++;
			else if(ar2[i] == 'G')
				G[ar[i]-1]++;
			else	//Bのとき
				B[ar[i]-1]++;
		}

		for(int i = 0; i < 9; i++)
		{
			if(R[i] >= 3)
			{
				counter++;
				R[i] -= 3;
			}
			if(G[i] >= 3)
			{
				counter++;
				G[i] -= 3;
			}
			if(B[i] >= 3)
			{
				counter++;
				B[i] -= 3;
			}
		}

		for(int i = 0; i < 7; i++)
		{
			while(R[i] > 0 && R[i+1] > 0 && R[i+2] > 0)
			{
				counter++;
				R[i] -= 1;
				R[i+1] -= 1;
				R[i+2] -= 1;
				if( ( R[i] > 0 && R[i+1] > 0 && R[i+2] > 0 ) != 1)
					break;
			}
			while(G[i] > 0 && G[i+1] > 0 && G[i+2] > 0)
			{
				counter++;
				G[i] -= 1;
				G[i+1] -= 1;
				G[i+2] -= 1;
				if( ( G[i] > 0 && G[i+1] > 0 && G[i+2] > 0 ) != 1)
					break;
			}
			while(B[i] > 0 && B[i+1] > 0 && B[i+2] > 0)
			{
				counter++;
				B[i] -= 1;
				B[i+1] -= 1;
				B[i+2] -= 1;
				if( ( B[i] > 0 && B[i+1] > 0 && B[i+2] > 0 ) != 1)
					break;
			}
		}
		if( counter >= 3)
			cout << 1 << endl;
		else
			cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)

using namespace std;

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> v(H, vector<char>(W));
  REP (i, 0, H) REP (j, 0, W) cin >> v[i][j];
  REP (i, 0, 2 * H) {
    REP (j, 0, W) cout << v[i / 2][j];
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
//Anshul Gupta


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<utility>
#include<climits>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<assert.h>
#include<iomanip>

using namespace std;
	
#define f first
#define s second
#define sz(a) int((a).size()) 
#define pb push_back 
#define mp make_pair
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef long long ll;

typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;

typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef pair<pi,pi > pi2;

typedef pair<ll,ll> pl;
typedef pair<pl,ll> pll;
typedef pair<pl,pl > pl2;

typedef vector<node> vn;

typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
typedef vector<pi2 > vpi2;

typedef vector<ll> vl;
typedef vector<pl> vpl;
typedef vector<pll> vpll;
typedef vector<pl2 > vpl2;

const int M=1000000007;

vi nex[100005];
int val[100005]={0};
bool isprime[1500005];




int main(){

	int n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;

	ll l=1LL*n*m/__gcd(n,m);
	map<int,char> ma;
	for(int i=0;i<n;++i){	
		ma[i*l/n]=s[i];
	}

	for(int i=0;i<m;++i){
		if(present(ma,i*l/m)){
			if(ma[i*l/m]!=t[i])
				return cout<<-1,0;
		}
	}

	cout<<l;








	return 0;
}

Measured memory_bytes: 7040
import sys
import collections
def main():
    n = int(input())
    a = collections.Counter(list(map(int, input().split())))
    s = [0 for i in range(10**5+1)]
    sa = 0
    for i in a:
        s[i] += a[i]
        sa += i*a[i]
    q = int(input())
    for x in sys.stdin.readlines():
        b, c = map(int, x.split())
        s[c] += s[b]
        sa = sa + c*s[b] - b*s[b]
        s[b] = 0
        print(sa)

main()

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


int ds(int x)
{
	int res = 0;
	while(x)
	{
		res += x%10;
		x/=10;
	}
	return res;
}

int main()
{
	int n;
	cin >> n;
	int ans = n;
	for(int i = 1;i<n;i++)
	{
		int now = 0;
		now = ds(i);
		now += ds(n-i);
		ans = min(ans,now);
	}
	cout  << ans << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  int ans=0;
  while(S.size()>0){
    if(equal(S.begin(), S.begin()+6, "resare")) S.erase(S.begin(), S.begin()+6);
    else if(equal(S.begin(), S.begin()+5, "esare")) S.erase(S.begin(), S.begin()+5);
    else if(equal(S.begin(), S.begin()+7, "remaerd")) S.erase(S.begin(), S.begin()+7);
    else if(equal(S.begin(), S.begin()+5, "maerd")) S.erase(S.begin(), S.begin()+5);
    else{
      ans+=1;
      S.erase(S.begin(), S.end());
    }
  }
  if(ans>0) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   ll x,y,z;
   cin>>x>>y>>z;
   cout<<z<<" "<<x<<" "<<y;
   
   
   
   return 0;        
}  
   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int X,ans;
void dfs(int now,int sum){
    if(now==10){
        if(sum<=X){
            int san=0,wu=0,qi=0;
            while(sum){
                if(sum%10==3)san++;
                if(sum%10==5)wu++;
                if(sum%10==7)qi++;
                sum/=10;
            }
            if(san&&wu&&qi)
                ++ans;
        }
        return;
    }
    dfs(now+1,sum*10+3);
    dfs(now+1,sum*10+5);
    dfs(now+1,sum*10+7);
}
int main(){
    cin>>X;
    for(int i=1;i<=9;i++)dfs(i,0);
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	int K , N, sum=0;
	cin >> N >> K;
	vector<int> v(N);
	for (int i = 0 ; i < N ; i++){
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	for (int l = 0; l < K; l++){
		sum += v[l];
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

  deque<ll> d;
  rep(i, n) {
    if (i % 2 == 0) {
      d.pb(a[i]);
    } else {
      d.push_front(a[i]);
    }
  }

  if (n % 2) {
    reverse(all(d));
  }

  while (!d.empty()) {
    cout << d.front() << ' ';
    d.pop_front();
  }
  cout << endl;
}

Measured memory_bytes: 5376
#include<iostream>
using namespace std;
int main(){
  int N,K,X,Y;
  cin>>N;
  cin>>K;
  cin>>X;
  cin>>Y;
  if(N<K){
    cout<<X*N<<endl;
  } else {
    cout<<X*K+Y*(N-K)<<endl;
  }

  return 0;
}


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

int n,a[20];
int solve(int i,int m){
    if(m == 0) return true;
    if(i >= n) return false;
    int res = solve(i+1,m) || solve(i+1,m-a[i]);
    return res;
}
int main(){
    int q,M;    
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    cin>>q;
    int i=0;
    while(q--){
        cin>>M;
        if(solve(0,M))cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
<?php
$abc = [];
fscanf(STDIN, "%d", $N);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d %d", $a, $b, $c);
    $abc[] = [$a, $b, $c];
}

$f[0] = $abc[0];

for ($i = 1; $i < $N; $i++) {
    $fa = max($f[$i-1][1], $f[$i-1][2]) + $abc[$i][0];
    $fb = max($f[$i-1][0], $f[$i-1][2]) + $abc[$i][1];
    $fc = max($f[$i-1][0], $f[$i-1][1]) + $abc[$i][2];
    $f[] = [$fa, $fb, $fc];
}

$res = max($f[$N-1]);
echo $res . "\n";

Measured memory_bytes: 86512