akhauriyash/Code-Regression huggingface dataset:
N = int(input())
t, a = map(int, input().split())

ans = t + a

for _ in range(N - 1):
    T, A = map(int, input().split())

    n = max(t // T + (1 if t % T else 0), a // A + (1 if a % A else 0))

    ans = (T + A) * n

    t, a = T * n, A * n

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;


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

    int n;
    cin >> n;
    vector<int> x(n),y(n);
    vector<int> p(n);
    rep(i,n){
        cin >> x[i] >> y[i];
        p[i] = i;
    }
    auto dist = [&](int i,int j){
        double dx = x[j] - x[i];
        double dy = y[j] - y[i];
        return sqrt(dx*dx+dy*dy);
    };
    double d;
    int cnt=0;
    do{
        rep(i,n-1){
            d += dist(p[i],p[i+1]);
        }
        cnt++;
    }while(next_permutation(all(p)));

    double ans = d/cnt;
    printf("%.10f\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<vector>
#include<cmath>


using namespace std;


int main(){

    string s;
    cin >> s;
    int ans = 0;
    for(int i=0;i<s.length();i++){
        if(i%2==0 && s[i]=='p')ans--;
        else if(i%2==1 && s[i]=='g')ans++;
    }

    cout << ans << endl;

}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int MAX = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<string> seat(MAX);

int main() {
  // 入力
  int N;
  cin >> N;

  string s;
  cout << 0 << endl;
  cin >> s;
  if (s == "Vacant") return 0;
  seat[0] = s;

  cout << N - 1 << endl;
  cin >> s;
  if (s == "Vacant") return 0;
  seat[N-1] = s;

  // 二分法
  int l = 0, r = N - 1;
  for (int i = 0; i < 18; i++) {
    int mid = (l + r) / 2;

    cout << mid << endl;
    cin >> s;
    if (s == "Vacant") return 0;
    seat[mid] = s;

    int diff = mid - l;
    if (((diff & 1) && seat[l] == seat[mid]) || (!(diff & 1) && seat[l] != seat[mid])) {
      r = mid;
    } else {
      l = mid;
    }
  }

  return 0;
}


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

using namespace std;

int binarySearch(vector<int>& A, int N, int key) {
  int left = 0;
  int right = N;
  int mid;

  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid]) {
      return 1;
    }
    if (key > A[mid]) {
      left = mid + 1;
    } else if (key < A[mid]) {
      right = mid;
    }
  }
  return 0;
}

int main() {
  vector<int> A;
  A.reserve(100000);

  int N;
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int M;
  int key;
  int sum = 0;

  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> key;
    if(binarySearch(A, N, key)) {
      sum++;
    }
  }
  cout<< sum << endl;

  return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, p, ans = 0, ten = 1;
string s;

int main() {
	cin >> n >> p;
	vector<ll> d(n + 1), cnt(p);
	cin >> s;
	if (10 % p == 0) {
		rep(i, n) {
			if ((s[i] - '0') % p == 0)ans += i + 1;
		}
	}
	else {
		cnt[0] = 1;
		for (int i = n - 1; i >= 0; i--) {
			d[i] = (d[i + 1] + ten * (s[i] - '0')) % p;
			ten *= 10;
			ten %= p;
			cnt[d[i]]++;
		}
		rep(i, p)ans += cnt[i] * (cnt[i] - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2304
antennas = [int(input()) for _ in range(5)]
k = int(input())

for i in range(len(antennas)):
  for j in range(len(antennas)):
    if(i != j and abs(antennas[i] - antennas[j]) > k):
      print(":(")
      exit()
print("Yay!")

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

int main() {
    int n, a[100005];
    string ans;
    cin >> n;
    bool flag=true;
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    for(int i=n-1; i>0; i--) {
        if(a[i-1]>=a[i]+2) {
            flag=false;
            break;
        }
        else if(a[i-1]==a[i]+1) {
            a[i-1]--;
        }
    }
    if(flag) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    ll n; cin>>n;
    int ans=0;
    while(n > 0){
        n /= 2;
        ans++;
    }

    cout << ans << endl;
}


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

using namespace std;

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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
	int n;
	while(cin >> n,n){
		int cp=-1,cd=-1;
		rep(i,n){
			int p,a,b,d;
			cin >> p >> a >> b;
			d=a+b;
			if(cd<d) cd=d,cp=p;
		}
		cout << cp << " " << cd << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
    int n, m; cin >> n >> m;
    vector<pair<int, bool>> t(n);
    for(int i = 0; i < n; i++){
        if(i == 0)t[i].second = true;
        else t[i].second = false;
        t[i].first = 1;
    }
    rep(i, m){
        int a, b; cin >> a >> b;
        a--; b--;
        if(t[a].first >= 2){
            if(t[a].second){
                t[b].second = true;
            }
        }
        else{
            if(t[a].second){
                t[b].second = true;
            }
            t[a].second = false;
        }
        t[a].first -= 1;
        t[b].first += 1;
    }
    int ans = 0;
    for(auto p : t){
        if(p.second)ans++;
    }
    cout << ans << endl;
    system("pause");
}

Measured memory_bytes: 1272
#include <stdio.h>
#include <math.h>

int main(int argc,char* argv[]){
  double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
  double a_w,a_h,b_w,b_h;
  
  int i,j;

  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&xa1,&ya1,&xa2,&ya2,&xb1,&yb1,&xb2,&yb2) != EOF){
    if(xb1 > xa2 || xa1 > xb2 || yb1 > ya2 || ya1 > yb2){
      printf("NO\n");
    }else{
      printf("YES\n");
    }
  }
  
  return 0;
  
}

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

typedef long long ll;

typedef pair<ll, ll> P;
struct edge { ll to, cost; };

const int MAX_V = 300000;
const ll INF = 1LL<<60;

int V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i,G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> V;
    int a, b;
    rep(i, V - 1) {
        cin >> a >> b;
        G[a - 1].push_back({b - 1, 1});
        G[b - 1].push_back({a - 1, 1});
    }
    dijkstra(0);
    int dmax = 0;
    a = 0;
    rep(i, V) {
        if (d[i] > dmax) {
            dmax = d[i];
            a = i;
        }
    }
    dijkstra(a);
    dmax = 0;
    rep(i, V) {
        if (d[i] > dmax) {
            dmax = d[i];
        }
    }
    if (dmax % 3 == 1) cout << "Second\n";
    else cout << "First\n";
}


Measured memory_bytes: 25780
// author - shreyanshjn (Shreyansh Jain)
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <ll, ll> PLL;
typedef pair <int,string> PIS;
typedef vector <int> vec;
typedef priority_queue<int> PQ;
/* #define input 1 */
#define INF 100000000000000000
#define endl '\n'
#define debug(x) cout<<#x<<": "<<x<<endl
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define sz(x) (int)(x).size()
#define len(x) (int)x.length()
#define rep(a,b,c) for(int a=b; a<c; a++)
#define fori(z,n)  for(int i=z;i<n;i++)
#define fork(z,n)  for(int k=z;k<n;k++)
#define forii(z,n) for(int i=z;i<=n;i++)
#define forkk(z,n) for(int k=z;k<=n;k++)
const int mod = 1e9 + 7;
int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
string trim(const string& str) {
    size_t first = str.find_first_not_of(' ');
    if (string::npos == first)
    {
        return str;
    }
    int last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}
int main() { 
    #ifdef input
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(15);
    int n; cin >> n;
    int arr[n + 1];
    fori(1, n + 1) cin >> arr[i];
    ll dp[n + 1][n + 1];
    for(int i = n; i >= 1; i--) {
        for(int p = i; p <= n; p++) {
            if(i == p) dp[i][p] = (ll)arr[i];
            else dp[i][p] = max(arr[i] - dp[i + 1][p], arr[p] - dp[i][p - 1]);
        }
    }
    cout << dp[1][n] << endl;
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}

Measured memory_bytes: 49944
import kotlin.math.*
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*


private var fs = BufferedReader(InputStreamReader(System.`in`))
private fun readLn() = fs.readLine()!! // string line
private fun readStrings() = readLn().split(" ") // list of strings
private fun readLong() = readLn().toLong()
private fun readLongs() = readStrings().map { it.toLong() } // list of ints
private fun readInt() = readLn().toInt() // single int
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    solveAtc()
}
fun solveAtc() {
    var a = readLn()
    var b = readLn()
    if(a == b.substring(0,b.lastIndex)) println("Yes")
    else println("No")
}


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

using namespace std;

using ll = long long;

const long long MOD = 1e9 + 7;
const int INF = 1e9 + 7;

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

    vector<int> factor(N + 1, 1);
    factor[0] = factor[1] = 0;
    for (int i = 2; i * i <= N; ++i) {
        if (factor[i] != 1) continue;
        for (int j = 2 * i; j <= N; j += i) factor[j] = i;
    }
    
    vector<int> cnt(N + 1, 0);
    for (int i = 2; i <= N; ++i) {
        int n = i;
        while (factor[n] != 0) {
            if (factor[n] == 1) factor[n] = n;
            cnt[factor[n]]++;
            n /= factor[n];
        }
    }
    ll ans = 1;
    for (int i = 2; i < N + 1; i++) ans = (ans * (cnt[i] + 1)) % MOD;
    cout << ans << endl;
}

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

int main()
{
  int i,j,n,m=0,flag,x;
  int *a;
  
  scanf("%d",&n);
  a = (int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  

  flag = 1;
  i = 0;
  while(flag){
    flag = 0;
    for(j = n-1;j>=i+1;j--){
      if(a[j] < a[j-1]){
	x = a[j];
	a[j] = a[j-1];
	a[j-1] = x;
	flag = 1;
	m++;
      }
    }
    i++;
  }
  for(i=0;i<n;i++){
    if(i > 0) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n");
  printf("%d\n",m);
  free(a);
  return 0;
}

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

string t = "SW";
void check(const string& s, vector<int>& ans, ll N){
  //0,1番を元にして2,3,...,N-1番を埋める
  FOR(i,1,N-1){
    if(ans[i] == 0 && s[i]=='o' || ans[i] == 1 && s[i] == 'x'){
      ans[i+1] = ans[i-1];
    }else ans[i+1] = !ans[i-1];
  }
  //s[0], s[N-1]の仮定を満たしているか確認
  bool f = true;
  REP(i,2){
    ll l = (N-2+i)%N;
    ll m = (l+1)%N;
    ll r = (m+1)%N;
    if(ans[m] == 0 && s[m] == 'o' && ans[l] != ans[r]) f = false;
    if(ans[m] == 0 && s[m] =='x' && ans[l] == ans[r]) f =  false;
    if(ans[m] == 1 && s[m] == 'o' && ans[l] == ans[r]) f =  false;
    if(ans[m] == 1 && s[m] =='x' && ans[l] != ans[r]) f =  false;
  }
  if(!f) return;

  REP(i,N){
    cout << t[ans[i]];
  }
  cout << endl;
  exit(0);
}

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

  REP(i,4){
    vector<int> ans(N,-1);
    ans[0] = i%2;
    ans[1] = i/2;
    check(s,ans,N);
  }
  cout << -1 << endl;
}

Measured memory_bytes: 1016
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  string s;cin>>s;
  judge=false;
  rep(i,0,3)if(s[i]=='7')judge=true;
  ans1(judge);
  return 0;
}

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


int main()
{
	map <int, int> mp;
	int	n, m, x;
	cin >> n >> m >> x;
	for(int i = 1; i <= m; i++)
	{
		int num;
		scanf("%d", &num);
		mp[num] = 1;
	}
	int a1 = 0;
	for(int i = x + 1; i <= n; i++)
	{
		if(mp[i] == 1) a1++;
	}
	int a2 = 0;
	for(int i = x - 1; i >= 0; i--)
	{
		if(mp[i] == 1) a2++;
	}
	int ans = min(a1, a2);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        X: i64,
    }
     
    let mut n = vec![0i64; N+1];
    let mut p = vec![0i64; N+1];
    n[0] = 1;
    p[0] = 1;
    for ind in 1..N+1 {
        n[ind] = n[ind - 1] * 2 + 3;
        p[ind] = p[ind - 1] * 2 + 1;
    }

    println!("{}", compute_num_p(N, X, &n, &p));
}

fn compute_num_p(level: usize, eat: i64, layer_num: &[i64], pate_num: &[i64]) -> usize {
    if eat == 0 {
        return 0
    } else if level == 0 {
        return 1
    }
    let new_eat = eat - layer_num[level - 1] - 1;
    if new_eat < 0 {
        compute_num_p(level - 1, eat - 1, layer_num, pate_num)
    } else if new_eat > 1 {
        (pate_num[level - 1] + 1) as usize +
        compute_num_p(level - 1, new_eat-1, layer_num, pate_num) 
    } else {
        (pate_num[level - 1] + new_eat) as usize
    }
}


Measured memory_bytes: 4352
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()
    T = input().strip()

    cnt = float("inf")
    for i in range(len(S) - len(T) + 1):
        tmp = 0
        for j in range(len(T)):
            if S[i + j] != T[j]:
                tmp += 1

        cnt = min(cnt, tmp)

    print(cnt)




if __name__ == '__main__':
    main()



Measured memory_bytes: 9096
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N, Q; cin >> N >> Q;
  vector<int> connect[N];
  rep(i,N-1){
    int a, b;
    cin >> a >> b;
    a--, b--;
    connect[b].push_back(a);
    connect[a].push_back(b);
  }
  
  int cnt[N] = {};
  rep(j,Q){
    int p, x;
    cin >> p >> x;
    p--;
    cnt[p] += x;
  }

  queue<int> q;
  bool passed[N] = {};
  q.push(0);
  while (!q.empty()){
    auto node = q.front(); q.pop();
    passed[node] = true;
    for (auto n : connect[node]){
      if (passed[n]==false) {
        cnt[n] += cnt[node];
        q.push(n);
      }
    }
  }

  rep(i,N) {
    if (i>0) cout << " ";
    cout << cnt[i];
  }
  cout << endl;



  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 16652
from collections import Counter
n = int(input())

c = Counter(x * x + y * y + z * z + x * y + y * z + z * x
        for x in range(1, 100) for y in range(1, 100) for z in range(1, 100))

for i in range(1, n+1):
    print(c[i])


Measured memory_bytes: 11680
#include<bits/stdc++.h>
using namespace std;
#define fin << '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep( i, m, n ) for ( int i = m; i < n; ++i )
typedef long long ll;
typedef vector<int> vi;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

ll gcd( ll x, ll y ) {
  ll r;
  while ( y != 0 ) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

ll lcm( ll x, ll y ) { return x / gcd( x, y ) * y; }

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll C = (b / c) - ((a - 1) / c);
  ll D = (b / d) - ((a - 1) / d);

  ll tmp = lcm( c, d );
  ll CD = (b / tmp) - ((a - 1) / tmp);

  ll all = b - a + 1;

  cout << all - C - D + CD << '\n';

  return 0;
}

Measured memory_bytes: 256
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;
void solve(){
	char c;
	cin >> c;
	cout << (char)(c+1) << endl;
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> t;
		while(t--){
			solve();
		}
	return 0;
}
	


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    S = input()

    wr = S.count('W')
    er = S.count('E')
    # print(wr, er)
    wl = 0
    el = 0
    ans = INF
    for s in S:
        if s == 'W':
            wr -= 1
            ans = min(ans, er+wl)
            wl += 1
        else:
            er -= 1
            ans = min(ans, er+wl)
            el += 1
        # print(wr, er, wl, el)
        # print(s, ans)
    print(ans)

if __name__ == '__main__':
    solve()



Measured memory_bytes: 9868
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var slice []int
	for i := 0; i < n; i++ {
		slice = append(slice, i+1)
	}

	var odd, even []int
	for i := range slice {
		switch slice[i] % 2 {
		case 0:
			even = append(even, slice[i])
		case 1:
			odd = append(odd, slice[i])
		}
	}

	var answer int
	answer = len(odd) * len(even)

	fmt.Println(answer)
}


Measured memory_bytes: 512
//
// Created by Daiki Kuyoshi on 2020/05/26.
//

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <set>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

map<ll, ll>  prime_factor_map(ll n){
    map<ll, ll> ans;
    ans[1] = 1;
    for(ll i=2; i*i <= n; i++){
        while(n%i == 0){
            ans[i]++;
            n /= i;
        }
    }
    if(n!= 1) ans[n] = 1;

    return ans;
}

int main(){
    ll N;
    cin >> N;
    if(IsPrime(N)){
        cout << 1 << endl;
        return 0;
    }
    map<ll, ll> ma = prime_factor_map(N);
    set<ll> sump;
    for(auto c : ma){
        if(c.first == 1){
            continue;
        }
        ll count = 1;
        ll i = 1;
        while(count <= c.second){
            sump.insert(pow(c.first, i));
            i++;
            count += i;
        }
    }

    cout << sump.size() << endl;
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    const lint MOD = 1e9 + 7;
    lint N, K; cin >> N >> K;
    lint ans = 0;
    range(k, K, N + 1 + 1) {
        // cout << k << "\n";
        lint min_value = k * (k - 1) / 2;
        lint max_value = (2 * N - k + 1) * k / 2;
        ans += max_value - min_value + 1;
        ans %= MOD;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

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

int main(){

    int n, x;
    scanf("%d %d", &n, &x);
    vector<int> v(n);
    
    REP(i,n){
        scanf("%d", &v[i]);
        v[i] -= x;
    }
    

   
    int result = gcd(v[0],v[1]);
    FOR(i,2,n){
        result = gcd( v[i],result);
    }
    cout << abs(result) << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main{
	public static void main(String[] argv){
		ManyFormals.run();
	}
}

class ManyFormals{
	public static void run(){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		boolean[] flag = new boolean[s.length()-1];
		System.out.println(bits(flag, 0, s));
	}
	//flagがtrueの場所には+を挿入する．どこを見ているかをindex, 
	public static long bits(boolean[] flag, int index, String s){
		if(flag.length == index)
			return getSum(flag, s);
		else{
			long sum = 0;
			flag[index]=true;
			sum += bits(flag, index+1, s);
			flag[index]=false;
			sum += bits(flag, index+1, s);
			return sum;
		}
	}
	public static long getSum(boolean[] flag, String s){
		long sum=0;
		int start = 0;
		for(int i=0;i<flag.length;i++){
			if(flag[i]){
				sum += Long.parseLong(s.substring(start, i+1));
				start = i+1;
			}
		}
		sum += Long.parseLong(s.substring(start, s.length()));
		return sum;
	}
}

Measured memory_bytes: 21844
# coding: utf-8
# Your code here!


S = input()

a = int(S[:2])
b = int(S[2:])

if a > 12 and b <= 12 and b > 0:
    print("YYMM")
elif a <= 12 and b > 12 and a > 0:
    print("MMYY")
elif a <= 12 and b <= 12 and a > 0 and b > 0:
    print("AMBIGUOUS")
elif a == 0 and b <= 12 and b > 0:
    print("YYMM")
elif b == 0 and a <= 12 and a > 0:
    print("MMYY")
else:
    print("NA")



Measured memory_bytes: 3060
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int ai = Integer.parseInt(sc.next());
    int bi = Integer.parseInt(sc.next());
    int xi = Integer.parseInt(sc.next());

    double a = (double) ai;
    double b = (double) bi;
    double x = (double) xi;
    
    double theta = 0;
    double ans = 0;
    
    // over half
    if (x >= a*a*b*0.5d) {
      theta = Math.atan( (a*a*a)/(a*a*b*2.0d-x*2.0d) );
      ans = 90.0d - Math.toDegrees(theta);
    } else { // under half
      theta = Math.atan( (x*2.0d)/(a*b*b) );
      ans = 90.0d - Math.toDegrees(theta);
    }
    
    System.out.println(ans);
  }
}


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



int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    char c; cin >> c;
    if (c == 'A') {
        cout << "T\n";
    } else if (c == 'T') {
        cout << "A\n";
    } else if (c == 'G') {
        cout << "C\n";
    } else {
        cout << "G\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 100005;
int n;
char s[MAXN];
int main () {
	scanf("%d", &n);
	scanf("%s", s+1); int ans = 0;
	for(int i = 1; i <= n; ++i)
		if(s[i] != s[i-1]) ++ans;
	printf("%d\n", ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define to second
#define cost first
typedef long long ll;
typedef long double ld;
using namespace std;

ll num[3005];
ll dp[3005][3005];

ll answer(int i, int j, int turn) {
	if(dp[i][j] != -1) return dp[i][j];
	if(i == j) return turn? num[i] : 0;

	if(turn) return dp[i][j] = max(num[i]+answer(i+1, j, turn^1), num[j]+answer(i, j-1, turn^1));
	else return dp[i][j] = min(answer(i, j-1, turn^1), answer(i+1, j, turn^1));
}

int main()
{	
	ll n, i;
	ll sum = 0;

	cin >> n;
	for(i = 0; i < n; i++) cin >> num[i], sum += num[i];
	memset(dp, -1, sizeof dp);
	cout << 2LL * answer(0, n-1, 1) - sum << endl;

    return 0;
}

Measured memory_bytes: 71040
import java.util.*;
import java.util.HashSet;
import java.util.Set;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        Set<String>colors=new HashSet<String>();
        for(int i=0;i<N;i++){
        colors.add(sc.next());}
        if(colors.size()==3){
            System.out.println("Three");
        }else{
            System.out.println("Four");
        }

        }
       
        
    }

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

using namespace std;

int main()
{
	int n, k, d[10];
	cin >> n >> k;
	for (int i = 0; i < k; i++)
		cin >> d[i];
	for (int i = n;; i++)
	{
		bool ok = true;
		int now = i;
		while (now)
		{
			for (int j = 0; j < k; j++)
				if (now % 10 == d[j])
					ok = false;
			now /= 10;
		}
		if (ok)
		{
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
	int n;
	double avg;
	int s[1000];
	double ss;
	while(1){
		cin >> n;
		if(n == 0) break;
		avg = 0;
		for(int i = 0;i < n;i++){
			cin >> s[i];	
			avg +=s[i];
		}
		
	    avg /= n;
		ss = 0;
		for(int i = 0;i < n;i++){
			ss += (s[i] - avg) * (s[i] - avg);
		}
		
		ss /= n;
		
		printf("%4lf\n",sqrt(ss));
	}
	return 0;
}

Measured memory_bytes: 3196
(let* ((nstores (read))
       (ndrinks (read))
       (table (loop for i below nstores
                 collect (list (read) (read)))))
  (setq table (sort table #'< :key #'first))
  (loop with cost = 0
     for row in table
     while (> ndrinks 0)
     finally (format t "~A~%" cost)
     do
       (destructuring-bind (unit-cost nunits) row
         (let ((n (min ndrinks nunits)))
           (incf cost (* n unit-cost))
           (decf ndrinks n)))))


Measured memory_bytes: 61800
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const int inf=1e9;
int main() {
	int n;
	cin>>n;
	ll dp[n+1][2]={};
	ll a[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];

    ll cm=1000;
	for(int i=1;i<=n;i++) {
		dp[i][0]=cm;

		for(int j=i;j>0;j--) {
			ll c=dp[j][0]/a[j];
		
			dp[i][1]=max(dp[i][1],c*a[i]+(dp[j][0]%a[j]));
			cm=max(cm,dp[i][1]);
		}

		

	}

	cout<<max(dp[n][0],dp[n][1])<<endl;
	
}

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

static const int A_MAX = 1000;

int main() {
	int N; //??°????????????
	int A[A_MAX]; //??°?????????

	//??\???
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}


	//?¨????
	for (int i = 1; i < N; i++) {
		//?????????
		for (int j = 0; j < N-1; j++) {
			cout << A[j] << " ";
		}
		cout << A[N-1] << endl;

		int temp = A[i]; //??????????????????????????°?????????????????????
		int j = i - 1; //????????????????????°?????????????°?
		
		//?????????
		while (j >= 0 && A[j] > temp) {
			A[j + 1] = A[j];
			j--;
		}
		//j--??????????????§????????????????????????
		A[j + 1] = temp;
	}

	//??????
	for (int j = 0; j < N - 1; j++) {
		cout << A[j] << " ";
	}
	cout << A[N - 1] << endl;

	return 0;
}

Measured memory_bytes: 3072
/*#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int n;
    cin >> n;
    vector<int> s(n,0);
    int res = 0;
    rep(i,n){cin >> s[i];}
    for(int bit = 0;bit < (1<<n);bit++){
        int sum = 0;
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                sum += s[i];
            }
        }
        if(sum%10 != 0)res = max(res,sum);
    }
    cout << res << endl;
    return 0;
}
*/
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n;
    cin >> n;
    vector<int> s(n,0);
    int res = 0;
    bool can = false;
    int memo = 0;
    vector<int> not_ten;
    rep(i,n){
        cin >> s[i];res+= s[i];
        if(s[i]%10 != 0){
            can = true;
            not_ten.push_back(s[i]);
        }
    }
    sort(not_ten.begin(),not_ten.end());
    if(can){
        if(res%10 == 0)cout << res - not_ten[0] << endl;
        else cout << res << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(N)]
B=[]
for x,y,z in A:
  a=x+y+z
  b=x+y-z
  c=x-y+z
  d=x-y-z
  e=-x+y+z
  f=-x+y-z
  g=-x-y+z
  h=-x-y-z
  B.append([a,b,c,d,e,f,g,h])
ans=0
for i in range(8):
  D=sorted(B,reverse=True,key=lambda x:x[i])
  d=0
  for j in range(M):
    d+=D[j][i]
  ans=max(ans,d)
print(ans)

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

#define int long long

using namespace std;



int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N, K;
    cin >> N >> K;

    vector<int> vect;

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;
    	vect.push_back(n);
    }

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

    int sum = 0;

    for(int i = 0 ; i < K ; i++)
    {
    	sum += vect[i];
    }

    cout << sum << '\n';

    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int count = 0;
  
  for (int a = 1; a <= 9; a++) {
    for (int b = 0; b <= 9; b++) {
      for (int c = 0; c <= 9; c++) {
        int S = 10001 * a + 1010 * b + 100 * c;
        if (A <= S && S <= B) {
          count++;
        }
      }
    }
  }
  
  
  cout << count << endl;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	std::string s[n];
	for (auto &i : s) std::cin >> i;
	auto calc = [&] (const std::string &s) -> std::pair<int, int> {
		int n = s.size();
		int res = 0, cur = 0;
		for (auto i : s) {
			if (i == '(') cur++;
			else cur--;
			res = std::min(res, cur);
		}
		int first = -res;
		res = cur = 0;
		for (int i = n; i--; ) {
			if (s[i] == ')') cur++;
			else cur--;
			res = std::min(res, cur);
		}
		return {first, -res};
	};
	std::vector<std::pair<int, int> > pos, neg;
	for (int i = 0; i < n; i++) {
		auto tmp = calc(s[i]);
		if (tmp.second >= tmp.first) pos.push_back(tmp);
		else neg.push_back(tmp);
	}
	std::sort(pos.begin(), pos.end());
	std::sort(neg.begin(), neg.end(), [] (auto i, auto j) { return i.first + (j.first - j.second) > j.first + (i.first - i.second); });
	int cur = 0;
	for (auto i : pos) {
		if (i.first > cur) {
			puts("No");
			return 0;
		}
		cur += i.second - i.first;
	}
	for (auto i : neg) {
		if (i.first > cur) {
			puts("No");
			return 0;
		}
		cur += i.second - i.first;
	}
	puts(cur ? "No" : "Yes");
	
	return 0;
}


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

typedef long long ll;
#define mp make_pair
#define pb push_back
#define pi pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	int t=1;
	//cin>>t;
	while(t--){
	 ll n,x;
	 cin>>n>>x;
	 ll sum=0;
	 ll a[n];
	 for(int i=1;i<=n;i++) cin>>a[i];
	 if(a[1]>x)
	 {
	 	sum+=a[1]-x;
	 	a[1]=x;
	 }
	 for(int i=2;i<=n;i++)
	 {
	 	ll t=a[i]+a[i-1];
	 	if(t<=x) continue;
	 	t-=x;
	 	sum+=t;
	 	
	 	//ll mintake=min(a[i],t);
	 	a[i]-=t;
	 	 
	 }
	 cout<<sum<<endl;
	}		
}

Measured memory_bytes: 4344
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int read() {
	int x=0, f=1; char ch=' ';
	while(!isdigit(ch)) {ch=getchar(); if(ch=='-') f=-1;}
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48), ch=getchar();
	return x*f;
}
int n;
ll ans;
int main() {
	cin>>n;
	ans=0;
	for(int i=1;i<=n;i++) {
		ll h=n/i*i;
		ans+=(i+h)*(n/i)/2;
	}
	cout<<ans;
}


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

g = [[] for _ in range(n)]

for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        x -= 1
        g[i].append((x, y))

ans = 0
for i in range(2**n):
    temp = [-1]*n
    for j in range(n):
        if (i >> j) & 1:
            temp[j] = 1
        else:
            temp[j] = 0
    flag = True
    for j in range(n):
        if temp[j] == 1:
            for x, y in g[j]:
                if temp[x] != y:
                    flag = False
    if flag:
        ans = max(ans, sum(temp))
print(ans)


Measured memory_bytes: 74216
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
  int n;cin >> n;
  int t, a;cin >> t >> a;
  int h[n];rep(i, n) cin >> h[i];
  int mi = 1000000;
  int ans = 0;

  rep(i,n){
    int tem = abs(1000*a-(1000 * t - h[i] * 6));
    if (mi >tem)
    {
      mi=tem;
      ans = i + 1;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# 整数の入力
n = int(input())

def f(a, b):
    #print("a: {}, b:{}".format(a, b))
    digit_a = 0
    while(a > 0):
        digit_a += 1
        a //= 10
    #print("digit_a:{}".format(digit_a))
    digit_b = 0
    while(b > 0):
        digit_b += 1
        b //= 10
    #print("digit_b:{}".format(digit_b))
    if digit_a < digit_b:
        return digit_b
    else:
        return digit_a

#約数列挙
def resolve(n):
    min = 10 ** 10
    for i in range(1, int(n ** 0.5)+1):
        if n % i == 0:
            if i != n//i:
                b = n//i
            else:
                b = i
            temp = f(i, b)
            if min > temp:
                min = temp

    print(min)

#print("n: {}".format(n))
resolve(n)

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; ll K; cin >> N >> K;
  map<int, int> to;
  rep(i, N) {
    int A; cin >> A;
    to[i + 1] = A;
  }
  int c = 1;
  map<int, int> dist, mod;
  dist[1] = 0;
  while (1) {
    int to_c = to[c];
    if (dist.find(to_c) != dist.end()) {
      mod[to_c] = dist[c] + 1 - dist[to_c];
      break;
    }
    dist[to_c] = dist[c] + 1;
    c = to_c;
  }

  int curr = 1;
  int modK = 0;
  rep(i, (int)min((ll)inf, K)) {
    if (mod.find(curr) != mod.end()) {
      modK = (K - i) % mod[curr];
      break;
    }
    curr = to[curr];
  }
  if (modK) {
    rep(i, modK) {
      curr = to[curr];
    }
  }
  cout << curr << "\n";
}


Measured memory_bytes: 22048
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
using namespace std;
using ll = long long;
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; }

long long a[100100];

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

  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a,a+N);
  a[N] = 1000000001;

  int count = 1;
  int ans = 0;
  FOR(i,1,N){
    if(a[i]!=a[i-1]){
      if(a[i-1]>count) ans += count;
      else if(a[i-1]<count) ans += count - a[i-1];
      count = 0;
    }
    ++count;
  }

  cout << ans << endl;

}



Measured memory_bytes: 1024