akhauriyash/Code-Regression huggingface dataset:
N = int(input())
ta = [list(map(int, input().split())) for i in range(N)]

t = 1
a = 1

for i in range(N):
  k = max((t+ta[i][0]-1)//ta[i][0], (a+ta[i][1]-1)//ta[i][1])
  t = ta[i][0]*k
  a = ta[i][1]*k
  
print(t+a)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
 int r,d,x;
  int i=0;
  cin>>r>>d>>x;
  vector<int>vec(10);
 for(i=0;i<10;i++){
   if(i==0){
   vec.at(i)=r*x-d;
      cout<<vec.at(i)<<endl;
   }else{
     vec.at(i)=vec.at(i-1)*r-d;
    cout<<vec.at(i)<<endl;
   }
  }
  

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
using ll = long long int;

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

    ll tmp = K - A;
    if(tmp < 0)
        cout << -tmp << " " << B << endl;
    else
        if(B - tmp < 0)
            cout << 0 << " " << 0 << endl;
        else
            cout << 0 << " " <<  B - tmp << endl;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc152/tasks/abc152_a
n, m = map(int, input().split())
n_total_perm = 1
m_total_perm = 1
for j in range(n,n-2,-1):
    n_total_perm *= j

for k in range(m,m-2,-1):
    m_total_perm *= k

total_even = int((n_total_perm/2) + (m_total_perm/2))
#if n < 2:
#    total_even = 0

print(total_even)




Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

bool compare(const pair<pair<int,string>,int>  &a, const pair<pair<int,string>,int>  &b){
  if(a.first.second!=b.first.second) return a.first.second < b.first.second;
  else return a.first.first > b.first.first;
}


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

	vector<pair<pair<int,string>,int> > sp(n);

	for( int i=0; i<n; ++i ){
		char str[11];
		int p;
		scanf("%s %d",str, &p);
		string str_s = string(str);

		sp[i] = make_pair(make_pair(p, str_s), i+1);
		//cin >> S[i] >> P[i];
	}

	sort(sp.begin(), sp.end(), compare);


	for( int i=0; i<n; ++i ){
		cout << sp[i].second << endl;
		// cerr << sp[i].first.first << " " << sp.first.second << endl;
	}



	return 0;
}


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

using namespace std;

string weather[3] = {"Sunny", "Cloudy", "Rainy"};

int main(){
    string str;
    cin >> str;
    for(int i = 0; i < 3; i++){
        if(str == weather[i]){
            cout << weather[(i + 1) % 3] << endl;
            return 0;
        }
    }
}

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

int main() {
  int k, n;
  cin >> k >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  
  // 最も距離がある2点を求める
  int distance = 0, pos1 = 0, pos2 = 0;
  for (int i = 0; i < a.size(); i++) {
    if (i != a.size() - 1) {
      int pre_dis = distance;
      distance = max(distance, a.at(i + 1) - a.at(i));
      if (pre_dis != distance) {
        pos1 = i;
        pos2 = i + 1;
      }
    }
    else {
      int pre_dis = distance;
      int dis = (k - a.at(i)) + a.at(0);
      distance = max(distance, dis);
      if (pre_dis != distance) {
        pos1 = i;
        pos2 = 0;
      }
    }
  }
  
  //cout << pos2 << " -> " << pos1 << endl;
  
  // pos2 -> pos1 の距離を求める
  int total = 0;
  
  if (pos1 != a.size() - 1) {
    for (int i = pos2; i < a.size(); i++) {
      if (i == a.size() - 1) {
        total += (k - a.at(i)) + a.at(0);
      }
      else {
        total += a.at(i + 1) - a.at(i);
      }
    }
  
    for (int i = 0; i < pos1; i++) {
      total += a.at(i + 1) - a.at(i);
    }
  }
  else {
    for (int i = 0; i < pos1; i++) {
      total += a.at(i + 1) - a.at(i);
    }
  }
  
  cout << total << endl;
}

Measured memory_bytes: 1024
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    string S; cin >> S;

    int ans = 0;
    for(char c : S) {
        if (c == '1') ans++;
    }
    
    cout << ans << endl;

    return 0;
}


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

int main() {
	
	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	int X, A; std::cin >> X >> A;
	if (X < A)std::cout << 0;
	else std::cout << 10;

	return 0;
}

Measured memory_bytes: 256
def printans(n):
    S = Sd[:len(Sd)-n] + T + Sd[len(Sd)-n+len(T):]
    print(S.replace('?','a'))

Sd = input()
T = input()
searching = 1
wilds_seq = 0
for i in range(1,len(Sd)+1):
    if Sd[-i] == T[-searching] or Sd[-i] == '?':
        if searching == len(T):
            printans(i)
            break
        else:
            searching += 1
            if Sd[-i] == '?':
                wilds_seq += 1
            else:
                wilds_seq = 0
    else:
        while wilds_seq > 0:
            wilds_seq -= 1
            searching -= 1
            if Sd[-i] == T[-searching]:
                searching += 1
                wilds_seq = 0
                break
        else:
            searching = 1
            wilds_seq = 0
            if len(T) >= 1:
                if Sd[-i] == T[-1]:
                    searching += 1
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n=5,i,x;
	for(i=0; i<n; ++i){
		std::cin >> x;
		if(!x){
			std::cout << (i+1) << std::endl;
		}
	}
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B;
    cin >> A >> B;
    ll ans = 0;
    if(A > B) ans += A--;
    else ans += B--;
    if(A > B) ans += A--;
    else ans += B--;
    cout << ans << endl;
    return 0;
}


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

class Data
{
public:
    int h, w;
    Data(int h, int w){
        this->h = h;
        this->w = w;
    }
    bool operator<(const Data& d) const{
        return make_pair(h*h+w*w, h) < make_pair(d.h*d.h+d.w*d.w, d.h);
    }
};

int main()
{
    vector<Data> d;
    for(int h=1; h<=150; ++h){
        for(int w=h+1; w<=150; ++w){
            d.push_back(Data(h, w));
        }
    }
    sort(d.begin(), d.end());

    for(;;){
        int h, w;
        cin >> h >> w;
        if(h == 0)
            return 0;

        int i = 0;
        while(d[i].h != h || d[i].w != w)
            ++ i;
        ++ i;
        cout << d[i].h << ' ' << d[i].w << endl;
    }
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  long long x, num;
  cin >> x;
  num = (x + 11 - 1) / 11;
  long long ans = 2 * num;
  if (x <= 11 * (num - 1) + 6)
    ans--;
  cout << ans << endl;
  return 0;
}

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

int main() {
	
	string s;
	cin >> s;
	
	if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
	{
		cout << 3;
	}
	else if((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R'))
	{
		cout << 2;
	}
	else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
	{
		cout << 1;
	}
	else
	cout << 0;
}

Measured memory_bytes: 3592
N = int(input())

a = list(str(N))
a = [int(s) for s in a]


Z = 10 ** (len(a) - 1)

Y = N - Z

X = list(str(Y))
X = [int(s) for s in X]
SUM = 0
for i in range(len(X)):
    SUM = SUM + X[i]

if Y != 0:
    print(SUM + 1)
else:
    print(10)

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

int main() {
  int N, C, M = 1e5+1;
  cin >> N >> C;
  vector<vector<int>> V(C, vector<int>(M));
  while (N--) {
    int s, t, c;
    cin >> s >> t >> c;
    s--, c--;
    V.at(c).at(s)++;
    V.at(c).at(t)--;
  }
  for (int i = 0; i < C; i++) {
    for (int j = 1; j < M; j++) {
      V.at(i).at(j) += V.at(i).at(j - 1);
    }
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int sum = 0;
    for (int j = 0; j < C; j++) {
      if (V.at(j).at(i)) sum++;
    }
    ans = max(ans, sum);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 15416
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pb push_back
#define mod 1000000007
using namespace std;

ll ans;

ll fun(string &s, ll pos){
	if(pos >= s.length()){
		return -1;
	}
	if(pos == s.length() - 1){
		ans += 1;
		if(s[pos] == '<'){
			return 0;
		}
		else{
			return 1;
		}
	}
	if(s[pos] == '>'){
		ll cur = fun(s, pos + 1) + 1;
		ans += cur;
		return cur;
	}
	ll i = pos;
	while(i < s.length() && s[i] == '<'){
		ans += i - pos;
		i++;
	}
	if(i != s.length()){
		ll cur = fun(s, i);
		ans += max(0ll, i - pos - cur);
	}
	else{
		ans += i - pos;
	}
	// cout<<pos<<" "<<ans<<endl;
	return 0;
}

int main() {
	// ios::sync_with_stdio(false);
	// cin.tie(0);
	string s;
	cin>>s;
	fun(s, 0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 24324
#include<iostream>
#include<vector>
#include<set>
#include<cassert>
#include<cmath>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<lint,lint>pll;
typedef pair<pll,lint>pplll;

pll fundamental_unit(lint d){
  vi ans;
  lint x=0,z=1;//(x+y*sqrt(d))/z
  lint sqrtd=floor(sqrt(d));
  set<pll>seen;
  while(1){
    if(seen.count(pll(x,z)))break;
    seen.insert(pll(x,z));
    lint q=((x+sqrtd)/z);
    if(0){
      cerr<<"x,z=("<<x<<"+sqrt(d))/"<<z<<endl;
      cerr<<"q="<<q<<endl;
    }
    ans.push_back(q);
    x-=q*z;
    lint norm=x*x-d;
    x=-x;
    z=-norm/z;
  }
  // recover
  lint num=0,den=1;
  for(int i=(int)ans.size()-2;i>=0;--i){
    lint z=num+ans[i]*den;
    num=den;den=z;
  }
  if(den*den-d*num*num==-1){
    lint x=den*den+d*num*num;
    lint y=2*den*num;
    den=x;num=y;
  }
  assert(den*den-d*num*num==1);
  return pll(den,num);
}

pll solve(lint n){
  for(int i=0;i<=200;++i)
    if(i*i==2*n)
      return pll(i,1);
  return fundamental_unit(2*n);
}

int main(){
  for(int t=1;;++t){
    lint n;
    cin>>n;
    if(n==0)break;
    pll ans=solve(n);
    cout<<"Case "<<t<<": "<<ans.first<<" "<<ans.second<<endl;
  }
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<pair<int64_t, int64_t>> p(n);
    for (auto i : irange(0L, n)) {
        int64_t x, l;
        cin >> x >> l;

        p[i] = {x + l, x - l};
    }

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

    vector<int64_t> dp(n + 1);
    for (auto i : irange(0L, n)) {
        auto pp = p[i];
        auto s = pp.second;

        auto idx =
                upper_bound(p.begin(), p.end(), s,
                            [&](int64_t s, const pair<int64_t, int64_t>& pp) {
                                return s < pp.first;
                            }) -
                p.begin() - 1;

        if (idx >= 0) {
            dp[i + 1] = max(dp[i], dp[idx + 1] + 1);
        } else {
            dp[i + 1] = max(dp[i], 1L);
        }
    }

    cout << dp.back() << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>


using namespace std;

using ll = long long int;
using lln = long long unsigned;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()
const long MOD = pow(10, 9) + 7;

char alfa[] = { 'A','B' ,'C','D' ,'E' ,'F' ,'G' ,'H' ,'I' ,'J' ,'K' ,'L' ,'M' ,'N' ,'O' ,'P' ,'Q' ,'R' ,'S' ,'T' ,'U' ,'V' ,'W' ,'X' ,'Y','Z' };

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

unsigned GetDigit(double num) {
	return log10(num) + 1;
}

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

class Mod {
public:
	static inline ll Add(ll a, ll b) {
		return (a + b) % MOD;
	}

	static inline ll Sub(ll a, ll b) {
		ll ans = (a - b) % MOD;
		return (ans < 0) ? (ans + MOD) : ans;
	}

	static inline ll Mul(ll a, ll b) {
		return (a * b) % MOD;
	}

	static inline ll Div(ll a, ll b) {
		return (a % MOD) * modinv(b, MOD) % MOD;
	}
};



template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (ll i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	bool debug = false;
	if (debug) {
		cout << "\x1b[41m" << "Debug Mode " << endl;
	}
	(debug) ? DebugMain() : Main();
	return 0;
}

int parmitation(ll N) {
	ll ans = 1;
	for (ll i = 1; i <= N; i++) {
		ans *= i;
	}

	return ans;
}

int SemiCommonMultiple(ll A, ll ANum, ll B, ll BNum, ll diff, ll max) {
	ll calc;
	calc = diff + B * BNum - A * ANum;

	if (diff + B * BNum > max) {
		return 0;
	}
	else {
		if (calc < 0) {
			SemiCommonMultiple(A, ANum, B, ++BNum, diff, max);
		}
		else if (calc > 0) {
			SemiCommonMultiple(A, ++ANum, B, BNum, diff, max);
		}
		else {
			return A * (ANum + 0.5);
		}
	}
}

ll  CaracalVsMonstor(ll H, ll sum,ll count) {
	if (H == 0) {
		return sum;
	}


	H = H / 2;
	sum = sum + count;

	count = count * 2;

	return CaracalVsMonstor(H, sum,count);

}

inline void Main() {
	ll X, Y, N, M, K;
	vector<bool> A;
	vector<ll> B;
	ll M1 = 1, D1 = 0, M2 = 1, D2 = 0;
	ll ans, temp;
	ll sum = 0, count = 0, a = 0;
	double avg = 0.0;
	string S;
	string T;
	string Ans = "";
	bool b[8];
	bool flag = false;


	cin >> N;

	cout << CaracalVsMonstor(N, sum ,count =1);
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n, i, j, ice[10], a;
	while (1){
		scanf("%d", &n);
		if (n == 0) break;
		for (i = 0; i < 10; i++)
		ice[i] = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &a);
			ice[a] += 1;
		}
		for (i = 0; i < 10; i++){
			if (ice[i] == 0)
				printf("-\n");
			else {
				for (j = 0; j < ice[i]; j++){
					printf("*");
				}
				printf("\n");
			}
		}
	}
	return 0;
}

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

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

const long long INF = 1LL << 60;
long long h[100010];

// DP テーブル
long long dp[100010];

int main ()
{
    int n;  cin >> n ;
    for(int i=1;i<=n;i++){
       cin >> h[i];
       dp[i]=INF;
    }
    dp[1]=0;
    dp[2]=abs(h[1]-h[2]);
    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i]);
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i]);
    }
    cout << dp[n] << endl;

}


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

using ll = long long;
#define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int a, b, k;
  cin >> a >> b >> k;
  int ans = a-k;
  if(ans >= 0) {
    cout << ans << " " << b;
  } else if(b+ans <= -1){
    cout << 0 <<  " " << 0;
  } else {
    cout << 0 <<  " " << b+ans;
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

int main() {
  std::string S;
  std::cin >> S;

  // 字符串 S 必须满足如下三个条件:
  //  1. 第一个字符必须是 'A'
  //  2. 在 S 中只出现一次 'C', 且他必须是在第三个与倒数第二个字符之间
  //  3. 所有除了 'A' 和 'C' 之外的字符必须都是小写.
  //  e. 如果满足所有条件, 打印 "AC"; 否则, 打印 "WA"

  // -------- Test1 --------
  if (S[0] != 'A') {
    puts("WA");
    return 0;
  }

  // -------- Test2 --------
  if (S[1] == 'C' || S.back() == 'C') {
    puts("WA");
    return 0;
  }
  int count_c = 0;
  for (int i = 2; i < S.length() - 1; i++)
    if (S[i] == 'C') count_c++;
  if (count_c != 1) {
    puts("WA");
    return 0;
  }

  // -------- Test3 --------
  S = S.substr(1);  // Exclude Test2
  for (char c : S) {
    if (c == 'C') continue;  // Exclude Test2
    if (isupper(c)) {
      puts("WA");
      return 0;
    }
  }

  // Pass all test
  puts("AC");

  return 0;
}


Measured memory_bytes: 256
def f c
  c.map!{|d|
    m = d.min
    d.map{|t|t-=m}
  }
end

c = 3.times.map{gets.split.map &:to_i}

c = f c
c = f c.transpose

puts (c.all?{|d|d.all?{|t|t==0}})? 'Yes':'No'

Measured memory_bytes: 1788
//{{{
#include <bits/stdc++.h>
using namespace std;
//types
typedef long long ll;
typedef pair<int,int> pii;
//input
bool SR(int &_x){return scanf("%d",&_x)==1;}bool SR(ll &_x){return scanf("%lld",&_x)==1;}
bool SR(double &_x){return scanf("%lf",&_x)==1;}bool SR(char *_s){return scanf("%s",_s)==1;}
bool RI(){return true;}
template<typename I,typename... T>bool RI(I &_x,T&... _tail){return SR(_x) && RI(_tail...);}
//output
void SP(const int _x){printf("%d",_x);}void SP(const ll _x){printf("%lld",_x);}
void SP(const double _x){printf("%.16lf",_x);}void SP(const char *s){printf("%s",s);}
void PL(){puts("");}
template<typename I,typename... T>void PL(const I _x,const T... _tail)
{SP(_x);if(sizeof...(_tail)) putchar(' ');PL(_tail...);}
//macro
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<int(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=int(b);i++)
#define pb push_back
#define mkp make_pair
#define F first
#define S second
//debug
#ifdef darry140
template<typename I>
void _DOING(const char *_s,I&& _x){cerr<<_s<<"="<<_x<<endl;}//without ','
template<typename I,typename... T>
void _DOING(const char *_s,I&& _x,T&&... _tail)//with ','
{
    int _c=0;
    static const char _bra[]="({[";
    static const char _ket[]=")}]";
    while(*_s!=',' || _c!=0)//eg. mkp(a,b)
    {
        if(strchr(_bra,*_s)) _c++;
        if(strchr(_ket,*_s)) _c--;
        cerr<<*_s++;
    }
    cerr<<"="<<_x<<", ";
    _DOING(_s+1,_tail...);
}
#define debug(...) do{\
    fprintf(stderr,"%s:%d - ",__PRETTY_FUNCTION__,__LINE__);\
    _DOING(#__VA_ARGS__,__VA_ARGS__);\
}while(0)
template<typename It>
ostream& _OUTC(ostream &_s,It _b,It _e)//container
{
    _s<<"{";
    for(auto _it=_b;_it!=_e;_it++) _s<<(_it==_b?"":" ")<<*_it;
    _s<<"}";
    return _s;
}
template<typename A,typename B>
ostream& operator <<(ostream&_s, const pair<A,B> &_p){return _s<<"("<<_p.F<<","<<_p.S<<")";}
template<typename A,typename B>
ostream& operator <<(ostream&_s, const map<A,B> &_c){return _OUTC(_s,ALL(_c));}
template<typename T>
ostream& operator <<(ostream&_s, const set<T> &_c){return _OUTC(_s,ALL(_c));}
template<typename T>
ostream& operator <<(ostream&_s, const vector<T> &_c){return _OUTC(_s,ALL(_c));}
#else
#define debug(...)
#endif
//}}}

int main()
{
    int n;RI(n);
    vector<int> v(2*n);
    REP(i,2*n) RI(v[i]);
    int ans=0;
    sort(ALL(v));
    REP(i,2*n) if(i%2==0)
        ans+=v[i];
    PL(ans);
    return 0;
}




































/*End Of File*/




Measured memory_bytes: 256
#include <stdio.h>

int
main(void)
{
	int time;
	int h;
	int m;
	int s;
	
        scanf("%d", &time);

	h = time / 3600;
	m = (time - h * 3600) / 60;
	s = time % 60;
	
	printf("%d:%d:%d\n", h, m, s);

	return 0;
}



Measured memory_bytes: 2092
#include<iostream>
#include<algorithm>
using namespace std;
int t[10];
int main(){
  for(int i=0;i<10;i++)cin>>t[i];
  sort(t,t+10);
  for(int i=9;i>=7;i--)cout<<t[i]<<endl;
  
  return 0;
}


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

using namespace std;

int main()
{
    int l,e,i,c=0;
    string s;
    cin>>l>>s;
    e=l-3;
    for(i=0;i<=e;++i){

        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')++c;

    }
    cout<<c<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int H,W;
char S[400][400] = {0};
int visited[400][400] = {0};
int black = 0;
int white = 0;
int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};

void f(int i, int j, char pre){
    if(!(0<=i && i<H && 0<=j && j<W))return;
    if(visited[i][j])return;
    char now = S[i][j];
    if(now == pre)return;
    visited[i][j] = 1;
    if(now == '#')black++;
    if(now == '.')white++;
    f(i+1, j, now);
    f(i-1, j, now);
    f(i, j+1, now);
    f(i, j-1, now);
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>H>>W;
    REP(i,H)REP(j,W)cin>>S[i][j];
    LL ans = 0;
    REP(i,H)REP(j,W){
        black = 0;
        white = 0;
        f(i, j, 'X');
        ans += (LL)black * white;
    }
    PUTS(ans);
}

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

//#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int main()
{
    int N;
    cin>>N;
    double a[N];
    double mx=0.0;
    for (int i=0; i<N; i++){
        cin>>a[i];
    }

    for (int i=0; i<N; i++){
        mx+=(1/a[i]);
    }
    cout << 1/(mx) <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <iomanip>
using namespace std;
int n;
int cnt[3]={0};
vector<vector<vector<double>>>dp;
double cal(int a,int b,int c)
{
  if(a+b+c==0)return 0;
  double res=0;
  if(a>0){res+=dp[(a+b+c+1)%2][b][c]*a;}
  if(b>0){res+=dp[(a+b+c)%2][b-1][c]*b;}
  if(c>0){res+=dp[(a+b+c)%2][b+1][c-1]*c;}
  res+=n;
  res=res/(a+b+c);
  //cout<<res;
  return res;
}
int main()
{
  ios::sync_with_stdio(false);
  std::cout<<fixed<<setprecision(10);
  cin>>n;

  for(int i=0;i<n;i++)
  {
    int tmp;
    cin>>tmp;
    cnt[tmp-1]++;
  }
  dp=vector<vector<vector<double>>>(2,vector<vector<double>>(n+1,vector<double>(n+1,-1)));
  for(int i=0;i<n+1;i++)
  {
    for(int j=i;j>=0;j--)
    {
      for(int k=j;k>=0;k--)
      {
        dp[i%2][j-k][i-j]=cal(k,j-k,i-j);
      }
    }
  }
  cout<<dp[n%2][cnt[1]][cnt[2]]<<endl;
  return 0;

}


Measured memory_bytes: 2432
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ls = []
    for i in range(n-1, -1, -2):
        ls.append(a[i])
    for i in range(0 if n % 2 == 0 else 1, n, 2):
        ls.append(a[i])
    print(*ls)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 26180
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
int n;
stack<int> si;
while (cin >> n){
	if (n == 0){
		cout<<si.top()<<endl;
		si.pop();
	}
	else{
		si.push(n);
	}
}
}

Measured memory_bytes: 3000
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    long long n;
    cin >> n;
    vector<long long> a(n);

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

    sort(a.begin(), a.end(), greater<long long>());
    long long sum = 0;
    if(n % 2 != 0){
        long long sum1 = 0;

        for(long long i = 0; i < n; i++){
            if(i < (n-1)/2){
                sum1 += 2*a[i];
            }
            else if((n-1)/2 <= i and i <= (n+1)/2){
                sum1 -= a[i];
            }
            else{
                sum1 -= 2*a[i];
            }
        }
        long long sum2 = 0;
        for(long long i = 0; i < n; i++){
            if(i < (n-3)/2){
                sum2 += 2*a[i];
            }
            else if((n-3)/2 <= i and i <= (n-1)/2){
                sum2 += a[i];
            }
            else{
                sum2 -= 2*a[i];
            }
        }
        sum = max(sum1, sum2);
    }
    else{
        for(long long i = 0; i < n; i++){
            if(i < (n-2)/2){
                sum += 2*a[i];
            }
            else if((n-2)/2 == i ){
                sum += a[i];
            }
            else if(n/2 == i){
                sum -= a[i];
            }
            else{
                sum -= 2*a[i];
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4036
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;

int main() {
	LL N, A, B;
	cin >> N >> A >> B;
	if (N == 1) {
		if (A == B) {
			cout << 1 << endl;
		}
		else {
			cout << 0 << endl;
		}
		return 0;
	}
	if (B < A) cout << 0 << endl;
	else cout << (B - A)*(N - 2) + 1 << endl;
}

Measured memory_bytes: 256
import queue

def solve():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    dist = [[h*w*100 for i in range(w)] for j in range(h)]
    dist[0][0] = 1

    q = queue.Queue()
    q.put((0,0))

    dx = [-1,1,0,0]
    dy = [0,0,1,-1]
    while not q.empty() :
        (x,y) = q.get()
        for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)] :
            nx = x + dx
            ny = y + dy
            if nx < 0 or nx >= h or ny < 0 or ny>= w :
                continue
            if field[nx][ny] == '#' :
                continue
            if dist[nx][ny] > dist[x][y] + 1 :
                dist[nx][ny] = dist[x][y] + 1
                q.put((nx,ny))

    if dist[h-1][w-1] >= h*w :
        return -1

    # print(dist)

    ans = h*w - dist[h-1][w-1]
    for v in field:
        for c in v:
            if c == '#':
                ans -= 1

    return ans

if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 45160
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    while(1){
        C-=B;
        if(C<=0){
            cout<<"Yes"<<endl;
            break;
        }
        A-=D;
        if(A<=0){
            cout<<"No"<<endl;
            break;
        }

    }
    return 0;
}


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

#define ll long long

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll n, d, ans=0;
	cin >> n >> d;
	for(int i=0; i<n; ++i) {
		ll x, y;
		cin >> x >> y;
		ll dfo=x*x+y*y;
		if(dfo<=d*d)
			++ans;
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3596
N, M = map(int, input().split())

AB = []
for i in range(N):
  AB.append(list(map(int, input().split())))

AB.sort(reverse=True)

m = 0
ans = 0
while True:
  a, b = AB.pop()
  if m + b < M:
    ans += a*b
    m += b
  else:
    c = M - m
    ans += a*c
    break

print(ans)

Measured memory_bytes: 27760
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'

const int MAXN=10;
const int MOD=10000000;

int main(){
	SIS;
	ll n;cin>>n;
	ll x,y;
	for(ll i=-400;i<400;i++){
		for(ll j=-450;j<=450;j++){
			if(i*i*i*i*i - j*j*j*j*j == n){
				x=i;y=j;break;
			}
		}
	}
	cout<<x<<" "<<y<<endl;
	
	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((a&&b&&!c)||(!a&&!b&&c))cout<<"Open"<<endl;
	else cout<<"Close"<<endl;

}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    
    sort(p.rbegin(), p.rend());
    int sum = p[0] / 2;
    REP(i, N) sum += p[i];
    cout << sum << endl;
    return 0;
}


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

const int INF = 1E9;

int main()
{
    long long s;
    cin >> s;
    int x = (INF - s % INF) % INF, y = (s + x) / INF;
    cout << "0 0 " << INF << " 1 " << x << " " << y << '\n';
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define c cout<<"#"<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 2000000000

const double EPS = 1e-10;
const double PI  = acos(-1.0);
////////////////////////////////////////////////
int n,a[101][101],d[101],p[101];
QI q;
int main()
{
	cin>>n;
	FOR(i,1,n+1)
	{
		int k,m;cin>>k>>m;
		a[k][0]=m;
		FOR(j,1,m+1)
		{	
			int x;cin>>x;
			a[k][j]=x;
		}
	}
	REP(i,101)p[i]=1;
	for(q.push(1);SZ(q)!=0;)
	{
		int u=q.front();
		q.pop();
		for(;p[u]<=a[u][0];)
		{
			int v=a[u][p[u]];p[u]++;
			if(v!=1&&d[v]==0)
			{
				d[v]=d[u]+1;
				q.push(v);
			}
		}
	}
	FOR(i,2,n+1)
	{
		if(d[i]==0)d[i]--;
	}
	FOR(i,1,n+1)
	{
		cout<<i<<" "<<d[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3108
c=[]
for _ in range(3):
    c.append(list(map(int,input().split())))

s=0
for i in range (3):
    for j in range(3):
        if i==j:
            s+=c[i][j]*2
        else:s-=c[i][j]

if s==0:print("Yes")
else:print("No")


Measured memory_bytes: 9004
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps=1e-8;
int d1[4] = { 1,0,-1,0 };
int d2[4] = { 0,1,0,-1 };
int d3[4] = { 0,-1,0,1 };
int main() {
	int w, h;
	while (cin >> w >> h, w) {
		char fi1[52][52]; char fi2[52][52];
		rep(i, 52) {
			rep(j, 52) {
				fi1[i][j] = fi2[i][j] = '#';
			}
		}
		string s, t;
		P s1, s2, g1, g2;
		rep1(i, h) {
			cin >> s >> t;
			rep1(j, w) {
				fi1[i][j] = s[j - 1];
				if (fi1[i][j] == '%') {
					g1 = { i,j };
				}
				else if (fi1[i][j] == 'L') {
					s1 = { i,j };
				}
			}
			rep1(j, w) {
				fi2[i][j] = t[j - 1];
				if (fi2[i][j] == '%') {
					g2 = { i,j };
				}
				else if (fi2[i][j] == 'R') {
					s2 = { i,j };
				}
			}
		}
		int used[52][52][52][52] = {};
		queue<pair<P, P>> v;
		bool f = false;
		v.push({ s1, s2 });
		used[s1.first][s1.second][s2.first][s2.second] = 1;
		while (!v.empty()) {
			pair<P, P> now = v.front();
			P n1 = now.first; P n2 = now.second; v.pop();
			if (n1 == g1 && n2 == g2) {
				f = true; break;
			}
			else if (n1 == g1 || n2 == g2) {
				continue;
			}
			rep(i, 4) {
				P nex1 = { n1.first + d1[i],n1.second + d2[i] };
				P nex2 = { n2.first + d1[i],n2.second + d3[i] };
				if (fi1[nex1.first][nex1.second] == '#') {
					nex1 = n1;
				}
				if (fi2[nex2.first][nex2.second] == '#') {
					nex2 = n2;
				}
				if (!used[nex1.first][nex1.second][nex2.first][nex2.second]) {
					used[nex1.first][nex1.second][nex2.first][nex2.second] = 1;
					v.push({ nex1,nex2 });
				}
			}
		}
		if (f) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 32496
#include <stdio.h>
int main(void){
int a,b,c,d,e,f,g,h,i,j;
scanf("%d",&a);
b = a % 10;
c = a / 100000000;
d = a / 10000000 - c * 10;
e = a / 1000000 - (c * 100 + d * 10);
f = a / 100000 - (c * 1000 + d * 100 + e * 10);
g = a / 10000 - (c * 10000 + d * 1000 + e*100 +f * 10);
h = a / 1000 - (c * 100000 + d * 10000 + e*1000 +f * 100 + g * 10);
i = a / 100 - (c * 1000000 + d * 100000 + e*10000 +f * 1000 + g * 100 + h * 10);
j = a / 10 - (c * 10000000 + d * 1000000 + e*100000 +f * 10000 + g * 1000 + h * 100 + i * 10);
if(a % (b + c + d + e + f + g + h + i + j) == 0){
printf("Yes");
}else{
printf("No");
}
return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	int x,y;
	for(;;){
			scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}else if(x>y){
			printf("%d %d\n",y,x);
		}else if(x<=y){
			printf("%d %d\n",x,y);
		}else if(x==0&&y==0){
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 596
from sys import stdin
import math

def main():

    input = stdin.readline

    N,D = map(int,input().split())

    ans = 0

    for _ in range(N):
        X,Y = map(int,input().split())

        distance = math.sqrt(X ** 2 + Y ** 2)

        if distance <= D:
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9132
#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	int flag = 0;
	for (int i = 1; i < 10; i++)
	{
		for (int j = 1; j < 10; j++)
		{
			if (i * j == n)
			{
				flag = 1;
				break;
			}
		}
		if (flag == 1)
		{
			std::cout << "Yes\n";
			break;
		}
	}
	if (flag == 0)
		std::cout << "No\n";
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
int n,m;
LL mn,ans,x;
const int N=2010,mod=1000000007;
int fa[N];
LL tans[N];
struct bian
{
	int x,y,z;
	friend bool operator <(const bian &a,const bian &b)
		{return a.z<b.z;}
}e[N];
void Init(){for(int i=1;i<=n;++i)fa[i]=i;}
int find(int x){return x==fa[x]?fa[x]:fa[x]=find(fa[x]);}
LL ksm(LL a,LL b,LL mod)
{
	LL res=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)res=res*a%mod;
	return res;
}
LL get(int c)
{
	LL res=0;
	for(int i=1,x,y;i<=m;++i)
	{
		x=find(e[i].x);y=find(e[i].y);
		if(x==y)continue;
		res+=e[i].z;++c;fa[x]=y;
		if(c==n-1)break;
	}
	return res;
	return res;
}
int main()
{
	cin>>n>>m>>x;
	for(int i=1;i<=m;++i)scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].z);
	sort(e+1,e+1+m);Init();mn=get(0);
	if(mn>x)return puts("0")==2333;
	if(mn==x)(ans+=(ksm(2,n-1,mod)-2)*ksm(2,m-n+1,mod))%=mod;
	for(int i=1;i<=m;++i)
		Init(),fa[e[i].x]=fa[e[i].y],tans[i]=get(1)+e[i].z;
	sort(tans+1,tans+1+m);
	for(int i=n;i<=m;++i)
		if(tans[i]==x)(ans+=ksm(2,m-i+1,mod))%=mod;
	cout<<ans;
	return 0;
}

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

int main(int argc, char *argv[])
{
  int n, k, i;
  int *w;
  int max = 0, sum = 0;
  int P_st, P_ed, P_center, k_st, k_ed, k_center, p[3];

  scanf("%d", &n);
  scanf("%d", &k);
  w = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) {
    scanf("%d", &w[i]);
    sum += w[i];
    if (max < w[i]) max = w[i];
  }

  P_st = max - 1;
  P_ed = sum;
  p[0] = 0;
  p[1] = 0;
  k_st = 1;
  k_ed = 1;
  for (i = 0; i < n; i++) {
    if (p[1] + w[i] > P_ed) {
      k_ed++;
      p[1] = 0;
    }
    p[1] += w[i];
  }
  k_st = 100001;

  while (1) {
    P_center = (P_st + P_ed) / 2;
    p[2] = 0;
    k_center = 1;
    for (i = 0; i < n; i++) {
      if (p[2] + w[i] > P_center) {
	if (p[2] == 0) {
	  k_center = 100001;
	  break;
	}
	k_center++;
	p[2] = 0;
      }
      p[2] += w[i];
    }
    if (k_center > k) {
      P_st = P_center;
      k_st = k_center;
    } else {
      P_ed = P_center;
      k_ed = k_center;
    }
    if (P_ed - P_st <= 1) break;
  }

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

  free(w);

  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <map>

using namespace std;

map<pair<int, int>, long long> mp[18][18];

long long solve(const vector<long long>& A, int src, int dst, int m1, int m2){
    if(dst < src) return 0;
    if(mp[src][dst].count(make_pair(m1, m2))) return mp[src][dst][make_pair(m1, m2)];
    long long res = (1LL << 60);
    for(int i=src;i<=dst;i++){
        res = min(res, (m1+m2)*A[i] + solve(A, src, i-1, m1, m1+m2) + solve(A, i+1, dst, m1+m2, m2));
    }
    return mp[src][dst][make_pair(m1, m2)] = res;
}

long long solve(const vector<long long>& A){
    return A.front() + A.back() + solve(A, 1, A.size()-2, 1, 1);
}

int main(){
    int N; cin >> N;
    vector<long long> A(N);
    for(auto& t : A) cin >> t;
    cout << solve(A) << endl;
}

Measured memory_bytes: 16512
X = int(input())

result = [0, 0]
powers = [x**5 for x in range(1001)]

end_flag = False
for i in range(1001):
    a5 = powers[i]
    for j in range(i, 1001):
        b5 = powers[j]
        x = a5 - b5
        if (x == X):
            result[0] = i
            result[1] = j
            end_flag = True
            break
        elif (-x == X):
            result[0] = -i
            result[1] = -j
            end_flag = True
            break
        x = a5 + b5
        if (x == X):
            result[0] = i
            result[1] = -j
            end_flag = True
            break
        elif (-x == X):
            result[0] = -i
            result[1] = j
            end_flag = True
            break
    if end_flag:
        break

A, B = result
print(f"{A} {B}")


Measured memory_bytes: 9240
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int n;
int main(int argc,char const* argv[])
{
  int a[5];
  int k;
  for(int i=0;i<5;i++)
    {
      cin >> a[i];
    }
  cin >> k;
  for(int i=0;i<5;i++)
    {
      for(int j=i+1;j<5;j++)
	{
	  if(a[j]-a[i]>k)
	    {
	      cout << ":(" << endl;
	      return 0;
	    }
	}
    }
  cout << "Yay!" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
   
#define N 36
   
typedef struct{
  char a;
  int value;
}Card;
   
int main(){
   
  int i,j,n,min,flag=0;
  Card c[N],b[N],n1,n2;
     
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&c[i].a,&c[i].value);
    b[i].a=c[i].a;
    b[i].value=c[i].value;
  }
   
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(c[j].value<c[j-1].value){
  
    n1=c[j];
    n2=c[j-1];
      c[j]=n2;
    c[j-1]=n1;
      }
    }
  }
   
       
   
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(b[j].value<b[min].value){
    min=j;
      }
    }
  
  
    n1=b[i];
    n2=b[min];
    b[i]=n2;
    b[min]=n1;
  }
   
   
  for(i=0;i<n-1;i++){
    printf("%c%d ",c[i].a,c[i].value);
  }
  printf("%c%d\n",c[n-1].a,c[n-1].value);
  printf("Stable\n");
    
  for(i=0;i<n-1;i++){
    printf("%c%d ",b[i].a,b[i].value);
  }
  printf("%c%d\n",b[n-1].a,b[n-1].value);
      
  for(i=0;i<=n-1;i++){
    if(c[i].a!=b[i].a){
      flag=1;
    }
  }
    
  if(flag==1) printf("Not stable\n");
  else printf("Stable\n");
     
  return 0;
}

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

ll dp[(1<<13)];

int main(void){
    int n;
    cin >> n;
    ll x[n],y[n];
    
    vector<ll> num,num2;
    
    
    rep(i,n){
        cin >> x[i] >> y[i];
        
        num.push_back(x[i]+y[i]);
        num2.push_back(x[i]-y[i]);
    }
    sort(num.begin(),num.end());
    sort(num2.begin(),num2.end());
    
    cout << max(num[n-1]-num[0],num2[n-1]-num2[0]) << endl;
}

Measured memory_bytes: 9744
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long LL;
const int MAXN = 3e5+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
int cnt[100];
signed main(){
    LL n;LL res=0; scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        LL x; scanf("%lld",&x);
        for(int j=0;j<=61;j++) cnt[j] += x&(1LL<<j) ? 1:0;
    }
    for(int i=0;i<=61;i++)
        res=(res+(((cnt[i]%MOD*((n-cnt[i])%MOD))%MOD)*((1LL<<i)%MOD))%MOD)%MOD;
    printf("%lld\n",res%MOD);
    return 0;
}

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

typedef long long LL;
 
const int OO = 1e9;
const int MOD = 1e9 + 7;

class Task {
public:

	int n, m;
	
	bool in_bound(int x, int y) {
		return x >= 0 && y >= 0 && x < n && y < m;
	}

	void solve() {
		cin >> n >> m;
		vector<string> g(n);
		for (int i = 0; i < n; ++i)
			cin >> g[i];
		
		vector<vector<int>> dist(n, vector<int>(m, -1));
		
		queue<pair<int,int>> q;
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				if (g[i][j] == '#') {
					q.push({i, j});
					dist[i][j] = 0;
				}
		
		int dx[4] = {0, 0, 1, -1};
		int dy[4] = {1, -1, 0, 0};
		
		int diam = 0;
		
		while (!q.empty()) {
			int x = q.front().first;
			int y = q.front().second;
			q.pop();
			for (int i = 0; i < 4; ++i) {
				int nx = x + dx[i];
				int ny = y + dy[i];
				if (in_bound(nx, ny) && dist[nx][ny] == -1) {
					dist[nx][ny] = dist[x][y] + 1;
					q.push({nx, ny});
					diam = max(diam, dist[nx][ny]);
				}
			}
		}
		
		cout << diam << '\n';
	}
};
 
int32_t main() {
//~ #ifndef ONLINE_JUDGE
	//~ freopen("input.txt", "r", stdin);
//~ #endif
 
	Task *task = new Task();
	task->solve();
	return 0;
}


Measured memory_bytes: 13568