akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }

const int MAXN = 300000;
const int MOD = 998244353;

int n, va, vb; ll vwant;

int inv[MAXN + 1];
int ways[MAXN + 1];

void run() {
	scanf("%d%d%d%lld", &n, &va, &vb, &vwant);

	inv[1] = 1; FORE(i, 2, n) inv[i] = (ll)(MOD - MOD / i)*inv[MOD%i] % MOD;
	ways[0] = 1; FORE(i, 1, n) ways[i] = (ll)ways[i - 1] * (n - i + 1) % MOD*inv[i] % MOD;

	int ret = 0;
	REPE(a, n) {
		ll rem = vwant - (ll)a*va; if (rem<0 || rem>(ll)n*vb || rem%vb != 0) continue;
		int b = rem / vb;
		ret = (ret + (ll)ways[a] * ways[b]) % MOD;
	}
	printf("%d\n", ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main()
{
  int n,x;
  scanf("%d%d",&n,&x);
  int l[n];
  int i;
  i = 0;
  int dim1;
  dim1 = 0;
  while (i < n)
  {
    scanf("%d",&l[i]);
    i++;
  }
  i = 0;
  int di;
  di = dim1;
  while (di <= x)
  {
    di = dim1 + l[i];
    dim1 = di;
    i++;
  }
  if (i <= n)
  {
  	printf("%d",i);
  }
  else
  {
    printf("%d",n+1);
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if(a < b) rep(i, b) cout << a;
	else rep(i, a) cout << b;
	cout << endl;
	return 0;
}

Measured memory_bytes: 3732
#include<stdio.h>
#include<string.h>
int main()
{
char s[110]={0};
int i,c,d;
c=0;
d=0;
gets(s);
int l=strlen(s);
for(i=0;i<l;i++)
{
	if(s[i]=='C') c++;
	if(c>=1&&s[i]=='F') d++;
	if(d==1) break;
}

if(d) printf("Yes\n");
else printf("No\n");
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e5+100;
vector<PII> ad[sz];
ll n;
ll ans[sz];
ll len[sz];
void DFS(ll p,ll parent,ll sum)
{
    len[p]=sum;
    for(auto xx: ad[p])
    {
        if(xx.s != parent){
            if(((sum+xx.f) & 1ll) == (len[p] &1ll) ){
                ans[xx.s]=ans[p];
            }
            else{
                ans[xx.s]=(ans[p] ^ 1ll );
            }
            DFS(xx.s,p,sum+xx.f);
        }
    }
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n)
    {
        for(i=0;i<=n;i++) ad[i].clear();
        for(i=1;i<n;i++){
            cin>>p>>q>>x;
            ad[p].pb({x,q});
            ad[q].pb({x,p});
        }

        ans[1]=0;
        DFS(1,-1,0);
        for(i=1;i<=n;i++){
            cout<<ans[i]<<endl;
        }
    }


}

Measured memory_bytes: 10880
n,k,q = map(int,input().split())
a_n = [int(input()) for i in range(q)]

p_n = [k-q for i in range(n)]

for a_i in a_n:
    p_n[a_i-1] += 1

[print("Yes") if p_i > 0 else print("No") for p_i in p_n]


Measured memory_bytes: 62168
#include<cmath>
#include<queue>
#include<iostream>
#include<algorithm>
#define debug(ARGS) cout << #ARGS << ": " << ARGS << endl;
#define ll long long
using namespace std;

bool dfs(queue<int> &v, int l, int r){
  if(v.size() == 0) return true;
  
  int ball = v.front(); v.pop();
    
  if(ball > l) return dfs(v, ball, r);
  if(ball > r) return dfs(v, l, ball);
  
  return false;
}

int main(){
  int n; cin >> n;
  int size = 10;

  for(int c = 0; c < n; c++){
    queue<int> v;
    for(int i = 0; i < size; i++){
      int tmp; cin >> tmp;
      v.push(tmp);
    }

    if(dfs(v, 0, 0)) cout << "YES" << endl;
    else cout << "NO" << endl;  
  }

  return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> pass;

signed main()
{
    pass.resize(5);
    cin >> N;
    REP(i, 5) { cin >> pass[i]; }

    SORT(pass);
    ll ans = N / pass[0];
    if(N % pass[0] == 0) { ans--; }
    ans += 5;
    printf("%lld\n", ans);

    return 0;
}


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

template<typename T>
istream &operator >> (istream &istr, vector<T> &v){
    for(T &x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream &operator >> (istream &istr, pair<T,U> &p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream &operator << (ostream &ostr, vector<T> &v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

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

template<typename T>
ostream &operator << (ostream &ostr, vector<vector<T>> &vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream &operator << (ostream &ostr, vector<pair<T,U>> &vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll v(n); v[i]=x;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll v(m,vll(n)); v[i][j]=x;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll v(n); v[i]=make_pair(x,y); v[i].first/second;
// v.front() : v[0]
// v.back()  : v[v.size()-1]

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF ((ll)1e+12)
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<=(b); i++)
#define FORR(i,a,b) for(ll i=(b); i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T> &v){return accumulate(all(v), (T)0);}
template<typename T> inline void sort(vector<T> &v){sort(all(v));}
template<typename T> inline void rsort(vector<T> &v){sort(all(v), greater<T>());}
template<typename T> inline void chmin(T &a, T b){if(a>b) a=b;}
template<typename T> inline void chmax(T &a, T b){if(a<b) a=b;}

int main(){
    ll a, b, c, k, ans=0;
    cin >> a >> b >> c >> k;
    if(k <= a){
        ans += k;
    }
    else{
        ans += a;
        k -= a;
        if(k > b){
            k -= b;
            ans -= k;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
"use strict";
function main(input) {
  let args = input.split('\n');
  let nums = args[0].split(' ');
  let N = parseInt(nums[0], 10);
  let M = parseInt(nums[1], 10);
  let items = [];
  for (let i = 1; i <= M; i++) {
    let switches = [];
    let values = args[i].split(' ');
    let num = parseInt(values[0], 10);
    for (let j = 1; j <= num; j++) {
      switches.push(parseInt(values[j], 10));
    }
    items.push(switches);
  }
  let pList = args[M + 1].split(' ').map(function(v) { return parseInt(v, 10) });
/*  console.log(N);
  console.log(M);
  console.log(items);
  console.log(pList);*/

  const patterns = pattern([], N);
  let count = 0;
  loop: for (let i = 0; i < patterns.length; i++) {
    let p = patterns[i];
    for (let j = 0; j < M; j++) {
      let sum = 0;
      for (let k = 0; k < items[j].length; k++) {
//        console.log('items[j][k]=' +items[j][k]);
        sum += p[items[j][k] - 1];
//        console.log('sum=' + sum);
      }
//      console.log('(' + p + ') ' + sum + ' ' + pList[j]);
      if (sum % 2 !== pList[j]) {
        continue loop;
      }
    }
    count++;
  }
  console.log(count);
}

function pattern(values, N) {
  if (values.length == N) {
    return [values];
  }
  let patterns = [];
  patterns = patterns.concat(pattern(values.concat(0), N));
  patterns = patterns.concat(pattern(values.concat(1), N));
  return patterns;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 11724
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#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 all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

constexpr int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); }

const int mod = TEN(9) + 7;

struct SegTree { // 区間sum
	int n;
	vector<int> Sum;
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		Sum.resize(2 * n);
		for (int i = 0; i < 2 * n - 1; ++i) {
			Sum[i] = 0;
		}
	}
	void update(int idx, int val) {
		idx += n - 1;
		Sum[idx] += val;
		while (idx > 0) {
			idx = (idx - 1) / 2;
			Sum[idx] = Sum[idx * 2 + 1] + Sum[idx * 2 + 2];
		}
	}
	int get_sum(int a, int b, int k = 0, int l = 0, int r = -1) { // [a, b)のmax
		if (r == -1) r = n;
		if (r <= a || b <= l) return 0;
		if (a <= l && r <= b) return Sum[k];
		int vl = get_sum(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = get_sum(a, b, k * 2 + 2, (l + r) / 2, r);
		return (vl + vr);
	}
};

signed main()
{
	int N; cin >> N;
	vi A(N), B(N), C(N - 1);

	int ans = 0;

	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i], ans += B[i];
	rep(i, N - 1) cin >> C[i];

	rep(i, N - 1) {
		if (A[i] + 1 == A[i + 1]) {
			ans += C[A[i] - 1];
		}
	}

	cout << ans << endl;
}



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

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> p(N + 1);
  for (int i = 1; i <= N; ++i)
    cin >> p[i];
  for (int i = 1; i <= N; ++i)
    p[i] = (1 + p[i]) * p[i] / 2 / p[i];
  for (int i = 1; i <= N - 1; ++i)
    p[i + 1] += p[i];
  double ans = -1;
  for (int i = K; i <= N; ++i)
    ans = max(p[i] - p[i - K], ans);
  cout << fixed << ans << endl;
}

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

#define int long long

using namespace std;



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

    string cad;
    cin >> cad;

    if(cad.back() == 's')cad += "es";
    else cad += "s";

    cout << cad << '\n';

    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

bool does_fit(string &s, string &t, int i) {
	int sz = t.size();
	for (int j = i; j < i + sz; ++j) {
		if (s[j] != '?' && t[j - i] != s[j]) {
			return false;
		}
	}

	return true;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string s, t;
	cin >> s >> t;

	int sz = s.size();
	int tz = t.size();

	if (tz > sz) {
		cout << "UNRESTORABLE\n";
		return 0;
	}

	bool fit = false;
	for (int i = sz - tz; i >= 0; --i) {
		if (does_fit(s, t, i)) {
			fit = true;
			for (int j = i; j < i + tz; ++j) {
				s[j] = t[j - i];
			}

			break;
		}
	}

	if (!fit) {
		cout << "UNRESTORABLE\n";
	} else {
		for (int i = 0; i < sz; ++i) {
			if (s[i] == '?') {
				s[i] = 'a';
			}
		}

		cout << s << "\n";
	}

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

int main() {
    long a, b, k, ans = 0;
    cin >> k;
    vector<int> as{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << as[k - 1] << endl;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 自作プログラムテスト
{
    class Program
    {
        const int mod = 100000007;

        static void Main(string[] args)
        {
            string[] Reader_Line0 = ReadLine().Split(' ');
            int N = int.Parse(Reader_Line0[0]);
            int M = int.Parse(Reader_Line0[1]);
            int TotalAC = 0;
            bool[] ACed = new bool[N];
            int[] WAed = new int[N];
            int TotalWA = 0;

            for (int loop = 0; loop < ACed.Length; loop++) 
            {
                ACed[loop] = false;
                WAed[loop] = 0;
            }

            for (int loop = 0; loop < M; loop++) 
            {
                string[] Reader_Answer = ReadLine().Split(' ');

                int P = int.Parse(Reader_Answer[0]);
                if (ACed[P - 1]) continue;

                switch (Reader_Answer[1]) 
                {
                    case "AC":
                        if (!ACed[P - 1]) TotalAC++;
                        ACed[P - 1] = true;
                        break;

                    case "WA":
                        WAed[P - 1]++;
                        break;
                }
            }

            for (int loop = 0; loop < WAed.Length; loop++) 
            {
                if (ACed[loop]) TotalWA += WAed[loop];
            }

            WriteLine(TotalAC + " " + TotalWA);
        }
    }
}


Measured memory_bytes: 17216
#include<stdio.h>
int main(){
  char a;
  int alp[26] = {0}, i;

  while(scanf("%c",&a) != EOF){
	for(i = 0; i < 26; i++)
	  if(a == 'a'+i || a == 'A'+i) alp[i]++;
  }
  for(i = 0; i < 26; i++){
    printf("%c : %d\n", 'a' + i,alp[i]);
  }
  return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
using namespace std;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<vector<int>> dp(N,vector<int>(N))
                        ,check(N,vector<int>(N,1));
    for (int i=0;i<N;++i){
        for (int j=0;j<N;++j){
            dp[i][j]=min(min(i,N-1-i),min(j,N-1-j));
        }
    }
    int ans=0;
    queue<pair<int,int>> que;
    for (int i=0;i<N*N;++i){
        int P; cin >> P; --P;
        int sx=P/N,sy=P%N;
        ans+=dp[sx][sy];
        check[sx][sy]=0;
        que.emplace(sx,sy);
        while(!que.empty()){
            auto p=que.front(); que.pop();
            int x=p.first,y=p.second;
            for (int i=0;i<4;++i){
                int nx=x+dx[i],ny=y+dy[i];
                if (nx<0||N<=nx||ny<0||N<=ny) continue;
                if (dp[nx][ny]<=dp[x][y]+(check[x][y])) continue;
                dp[nx][ny]=dp[x][y]+check[x][y];
                que.emplace(nx,ny);
            }
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  string s;
  ll k;
  cin >> s >> k;
  int siz = s.length();
  if (s[0] != s[siz-1]) { //先頭と末尾が異なる
    ll ans = 0, cnt = 1;
    rep(i,siz-1) {
      if (s[i] == s[i+1]) cnt++;
      else {
        ans += cnt / 2;
        cnt = 1;
      }
    }
    ans += cnt / 2; //余りを足す
    ans *= k;
    cout << ans << endl;
    return 0;
  }
  ll cnt1 = 1, cnt2 = 1;
  rep(i,siz-1) {
    if (s[i] == s[i+1]) cnt1++;
    else break;
  }
  for (int i = siz-1; i >= 1; --i) {
    if (s[i] == s[i-1]) cnt2++;
    else break;
  }
  debug(cnt1, cnt2);
  ll ans = 0;
  if (cnt1 == siz) { //全ての文字が同じ
    ans = cnt1 * k / 2;
  }
  else {
    ll cnt = 1;
    for (int i = cnt1; i < siz-cnt2; ++i) { //内側のカウント
      if (s[i] == s[i+1]) cnt++;
      else {
        ans += cnt / 2;
        cnt = 1;
      }
    }
    ans += cnt / 2; //余りを足す
    ans *= k;
    ans += (k-1)*((cnt1+cnt2)/2) + cnt1/2 + cnt2/2; //先頭と末尾だけ分けて考える
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

ans = sum(p[:x]) + sum(q[:y])
x -= 1
y -= 1
#print(ans)
for z in r:
    if y >= 0 and x >= 0:
        if p[x] >= q[y]:
            if z > q[y]:
                #print(z, q[y], y)
                ans += z - q[y]
                y -= 1
            else:
                break
        else:
            if z > p[x]:
                ans += z - p[x]
                x -= 1
            else:
                break
    elif x >= 0:
        if z > p[x]:
            ans += z - p[x]
            x -= 1
        else:
            break
    elif y >= 0:
        if z > q[y]:
            ans += z - q[y]
            y -= 1
        else:
            break
    else:
        break

print(ans)

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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;

#define abs(a) ((a) < (0)? -(a):(a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define pb push_back

int main() {
    int n;
    cin >> n;
    
    double ans = 0;
    rep(_, n) {
        double x;
        string u;
        cin >> x >> u;
        ans += u=="JPY"? x:x*380000.0;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  long long N, A, B;
  cin>>N>>A>>B;
  long long r=(A+B);
  long long times=N/r;
  long long rest=N%r;
 long long opai;
opai=min(rest,A);
  cout<<times*A+opai<<endl;
}

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

#define REP(i,N) for(int (i)=0; i<(int)(N); i++)

long long a[300010],b[70][2],ans;

int main(void){
	int N;
	cin >> N;
	for(int i=1; i<=N; i++)
	cin >> a[i];
	for(int i=1; i<=N; i++){
		int raod = 0;
		while(a[i]){
			raod++;
			b[raod][a[i]%2]++;
			a[i] = a[i]/2;	 
		}
		for(int j=raod+1; j<=60; j++)
			b[j][0]++;
	}
	long long j = 1;
	for(int i=1; i<=63; i++){
		ans += ((b[i][1]%1000000007)*(b[i][0]%1000000007))%1000000007*(j%1000000007);
		ans %= 1000000007;
		j *= 2; 
	}
	cout << ans%(1000000007) << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++)
    cin >> d[i];
  
  sort(d.begin(), d.end());
  cout << d[n/2] - d[n/2-1];
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

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

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

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

  auto f = [&](ll x){
    return b/x - (a-1)/x;
  };

  ll ans = (b-a+1) - (f(c)+f(d)-f(lcm(c, d)));

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {
    long long x;
    cin >> x;
    long long sum = 0;
    string aux = to_string(x);
    for(int i = 0; i < aux.size(); i++) {
        sum += int(aux[i] - '0');
    }
    if(x % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define mod 1000000007
using namespace std;
int a[1000006], s[1000006];
int fpw(int x, int y){
	int ans = 1;
	for (int i = 1; i <= y; i <<= 1, x = 1LL * x * x % mod)
		if (y & i)
			ans = 1LL * ans * x % mod;
	return ans;
}
int add(int x, int y){
	x += y;
	if (x >= mod)
		return x - mod;
	return x;
}
int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++ i)
		cin >> a[i];
	for (int i = 1; i <= n; ++ i)
		s[i] = add(s[i - 1], fpw(i + 1, mod - 2));
	int ans = 0;
	for (int i = 1; i <= n; ++ i)
		ans = (ans + 1LL * add(s[i - 1], s[n - i] + 1) * a[i] % mod) % mod;
	for (int i = 1; i <= n; ++ i)
		ans = 1LL * ans * i % mod;
	cout << ans << endl;
}


Measured memory_bytes: 4736
import sys

readline = sys.stdin.buffer.readline


def solver(A):
    c = 0
    for a in A:
        c ^= a

    ans = [a ^ c for a in A]
    return ans


def run():
    N = int(readline())
    A = list(map(int, readline().split()))

    ans = solver(A)

    print(*ans)


run()


Measured memory_bytes: 29088
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var s = Console.ReadLine().Trim();
            if (s == ".") break;
            var p = Console.ReadLine().Trim();
            var ph = getHash(s, p);
            getAns(s, p, ph);
        }
    }
    static void getAns(string s, string p, int ph)
    {
        var count = 0;
        for (int i = 0; i <= 9999; i++)
        {
            var t = i.ToString();
            var z = 4 - t.Length;
            t = new string('0', z) + t;
            if (getHash(s, t) == ph) count++;
        }
        Console.WriteLine("{0} {1}",ph,count);
    }
    static int getHash(string s, string p)
    {
        var a = p[0] - '0';
        var b = p[1] - '0';
        var c = p[2] - '0';
        var d = p[3] - '0';
        var st = new Stack<int>();
        var sL = s.Length;
        for (int i = 0; i < sL; i++)
        {
            if (s[i] == 'a') st.Push(a);
            else if (s[i] == 'b') st.Push(b);
            else if (s[i] == 'c') st.Push(c);
            else if (s[i] == 'd') st.Push(d);
            else if (s[i] == '+') st.Push(100);
            else if (s[i] == '*') st.Push(101);
            else if (s[i] == '^') st.Push(102);
            else if (s[i] == ']')
            {
                var x = st.Pop();
                var y = st.Pop();
                var z = st.Pop();
                if (z == 100) st.Push(x | y);
                else if (z == 101) st.Push(x & y);
                else st.Push(x ^ y);
            }
        }
        return st.Pop();
    }
}


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

bool is_palindrome(string s) {
    bool result = true;
    int length = s.size();
    for (int i = 0; i < length; i++) {
        if (s[i] != s[length - i - 1]) {
            result = false;
            break;
        }
    }
    return result;
}

int main() {
    string S;
    cin >> S;
    int length = S.size();
    if (is_palindrome(S) and is_palindrome(S.substr((length + 1) / 2)) and is_palindrome(S.substr(0, (length - 1) / 2))) {
        cout << "Yes" << endl;
    } else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,W = map(int, input().split())
l = [dict() for i in range(n+1)]
l[0][0] = 0
for i in range(1,n+1):
  w,v = map(int, input().split())
  l[i] = l[i-1].copy()
  l[i][w] = max(l[i].get(w,0),v)
  for x in l[i-1]:
    if x+w <= W:
      l[i][x+w] = max(l[i].get(x+w,0),l[i-1][x] + v)
print(max(l[n].values()))


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

ll rec(ll x){
  if(x == 1) return 1;
  ll y = x/2;
  return 1 + 2 * rec(y);
}

int main(){
  ll h; cin >> h;
  cout << rec(h) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	bool r=false;
	while(n--){
	if(r)cout<<endl;
	r=true;
	int a[9][9];
	bool d[9][9]={0};
	for(int i=0;i<9;i++){
		for(int j=0;j<9;j++){
			cin>>a[i][j];
			a[i][j]--;
		}
	}
	int t[9];
	for(int i=0;i<9;i++){
		for(int j=0;j<9;j++)t[j]=0;
		for(int j=0;j<9;j++)t[a[i][j]]++;
		for(int j=0;j<9;j++)if(t[j]>1)for(int k=0;k<9;k++)if(a[i][k]==j)d[i][k]=true;
	}
	for(int i=0;i<9;i++){
		for(int j=0;j<9;j++)t[j]=0;
		for(int j=0;j<9;j++)t[a[j][i]]++;
		for(int j=0;j<9;j++)if(t[j]>1)for(int k=0;k<9;k++)if(a[k][i]==j)d[k][i]=true;
	}
	for(int f=0;f<9;f+=3){
		for(int g=0;g<9;g+=3){
			for(int i=0;i<9;i++)t[i]=0;
			for(int i=0;i<3;i++)for(int j=0;j<3;j++)t[a[i+f][j+g]]++;
			for(int k=0;k<9;k++)if(t[k]>1){
				for(int i=0;i<3;i++)for(int j=0;j<3;j++){
					if(a[i+f][j+g]==k)d[i+f][j+g]=true;
				}
			}
		}
	}
	for(int i=0;i<9;i++){
		for(int j=0;j<9;j++){
			if(d[i][j])cout<<"*";
			else cout<<" ";
			cout<<a[i][j]+1;
		}
		cout<<endl;
	}
	}
	return 0;
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
int main()
{
  double  n,a;
  cin>>n;
  a=n;
	double count=0;
 	double ans=log(n)/log(2.000);
  	if(floor(ans)==ceil(ans))
      cout<<(long long int)pow(2,ans+1)-1<<endl;
  else
  	cout<<(long long int)pow(2,ceil(ans))-1<<endl;
      
  
  


}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
  int N = inputValue();
  int A[100001];
  int B[100000];
  REP(i,N+1)
    A[i] = inputValue();
  REP(i,N)
    B[i] = inputValue();
  ll c = 0;
  int f1 = 0;
  int f2 = 0;
  REP(i,N){
    f1 = min(A[i]-f2,B[i]);
    c += f1;
    f2 = min(A[i+1],B[i]-f1);
    c += f2;
  }
  cout << c << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
//#define endl '/n'
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}

string myrev(string s){
	string t=s;
	reverse(t.begin(),t.end());
	return t;
}


int main(){
	init();
	ll N;cin>>N;
	ll ans=0; 
	for(int i=0;i<N;i++){
		ll l,r;cin>>l>>r;
		r++;
		ans+=(r-l);
	}
	cout<<ans<<endl;
}


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

edges = {i : [] for i in range(1, N+1)}
visited = [False for _ in range(N+1)]

for _ in range(M):
  a, b = map(int, input().split())
  edges[a].append(b)
  edges[b].append(a)

def dfs(n, count):
  # 定期便2つでは行けない
  if count == 3:
    return False
  if n == N:
    return True
  visited[n] = True
  
  for edge in edges[n]:
    if visited[edge]:
      continue
    if dfs(edge, count + 1):
      return True
  
  return False

print("POSSIBLE" if dfs(1, 0) else "IMPOSSIBLE")

Measured memory_bytes: 59292
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	char c;cin >> c;
	if(isupper(c))cout << "A" << endl;
	else cout << "a" << endl;

	return 0;
}


Measured memory_bytes: 3600
function main()
    n, m, q = parse.(Int, split(readline()))
    a = Vector{Int}(undef, q)
    b = Vector{Int}(undef, q)
    c = Vector{Int}(undef, q)
    d = Vector{Int}(undef, q)
    for i in 1:q
        a[i], b[i], c[i], d[i] = parse.(Int, split(readline()))
    end

    As = Vector{Int}[]
    rec!(As, 1, ones(Int, n), m, n)
    res = 0
    for A in As
        tmp = 0
        for i in 1:q
            tmp += ifelse(A[b[i]] - A[a[i]] == c[i], d[i], 0)
        end
        res = max(res, tmp)
    end

    println(res)

end

function rec!(a, d, val, m, n)
    if d == n+1
        push!(a, val)
        return nothing
    end

    local s
    if d == 1
        s = 1
    else
        s = val[d-1]
    end
    for v in s:m
        tmp = copy(val)
        tmp[d] = v
        rec!(a, d+1, tmp, m, n)
    end
end

main()


Measured memory_bytes: 206524
class SWAG():
    def __init__(self,unit,f):
        self.fold_r=[unit]
        self.fold_l=[unit]
        self.data_r=[]
        self.data_l=[]
        self.f=f
    def __refill_right(self):
        temp=[]
        n=len(self.data_l)
        for _ in range(n//2):
            temp.append(self.popleft())
        for _ in range(n//2,n):
            self.append(self.popleft())
        for t in temp[::-1]:
            self.appendleft(t)
    def __refill_left(self):
        temp=[]
        n=len(self.data_r)
        for _ in range(n//2):
            temp.append(self.pop())
        for _ in range(n//2,n):
            self.appendleft(self.pop())
        for t in temp[::-1]:
            self.append(t)
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.__refill_right()
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.__refill_left()
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=map(int,open(0).read().split())
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min)
s_max=SWAG(0,max)
*_,=map(s_min.append,p[:k-1])
*_,=map(s_max.append,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print(x+f)

Measured memory_bytes: 121148
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>	
using namespace std;
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
typedef long long         ll;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
#define pb					push_back
#define P(x)				cout<<#x<<" = { "<<x<<" }\n"
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
void GOAT()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("output.txt", "w	", stdout);
#else
#endif

}
ll v[100007], w[100007], we, n, mxwe;
ll mem[101][100005];
ll knap(int i, ll rem)
{
	if (i > n) {
		return rem == 0 ? 0 : 1e10;
	}
	if (!rem)return 0;
	ll& ret = mem[i][rem];
	if (~ret)return ret;
	ll choice1 = knap(i + 1, rem);
	ll choice2 = 1e10;

	if (rem - v[i] >= 0)
		choice2 = knap(i + 1, rem - v[i]) + w[i];

	return ret = min(choice1, choice2);
}
int main()
{
	//GOAT();
	clr(mem, -1);
	cin >> n >> we;
	for (int i = 0; i < n; i++)
		cin >> w[i] >> v[i];
	//cout << knap(0, we) << endl;
	for (int i = 100001; i >= 0; i--)
	{

		ll mx = i, ans = knap(0, mx);
		if (ans <= we)
		{
			return cout << mx << endl, 0;
		}
	}




}


Measured memory_bytes: 80256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll H, W; cin >> H >> W;
	char m[51][51];
	char c[51][51];
	rep(i, 0, H) {
		rep(j, 0, W) {
			cin >> m[i][j];
			c[i][j] = m[i][j];
		}
	}

	int y[8] = { 0,1,-1,1,-1,0,1,-1 };
	int x[8] = { 1,1,1,0,0,-1,-1,-1 };

	rep(i, 0, H) {
		rep(j, 0, W) {
			if (c[i][j] != '#') {
				ll cnt = 0;
				rep(s, 0, 8) {
						if (i >= 0 && i < H && j >= 0 && j < W) {
							if (m[i + y[s]][j + x[s]] == '#') {
								cnt++;
							}
						}
				}
				m[i][j] = (char)(cnt + '0');
			}
		}
	}

	rep(i, 0, H) {
		rep(j, 0, W) {
			cout << m[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <set>
#include <map>
using namespace std;

void solve(vector<string> arr) {
    /*
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
            cout << arr[i][j];
            if ((j+1)%3 == 0) {
                cout << " ";
            }
        }
        cout << endl;
        if ((i+1)%3 == 0) {
            cout << endl;
        }
    }
    */

    int i = 0;
    for (int k = 0; k < 3; k++) {
        int tmp = k;
        for (int j = 1; j <= 3; j++) {
            arr[i][tmp] = arr[i][tmp] == '1' ? '2' : '1';
            tmp+=3;
            i+=1;
        }
    }


    /*
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
            cout << arr[i][j];
            if ((j+1)%3 == 0) {
                cout << " ";
            }
        }
        cout << endl;
        if ((i+1)%3 == 0) {
            cout << endl;
        }
    }
    */
    for (string s : arr) {
        cout << s << endl;
    }

}
long long int num(long long int n) {
    long long int toRet = 0;
    for (long long int i = 1; i <= (long long int)sqrt(n); i++) {
        if (n%i == 0) {
            toRet += i == n/i ? 1 : 2;
        }
    }

    return toRet;
}
int main()
{
    long long int n,i,j;
   cin>>n;
   vector<long long int> divs(n+1);
   long long ans=0;
   for(i=1;i<=n;i++){
    for(j=i;j<=n;j+=i){
        divs[j]++;
    }
   }
   for(i=1;i<=n;i++)
    ans+=i*divs[i];
   cout<<ans<<endl;



}


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

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

purchase_price = price_list[0]
profit = price_list[1] - purchase_price
for price in price_list[1:]:
    if profit < price - purchase_price:
        profit = price - purchase_price
    if price < purchase_price:
        purchase_price = price

print(profit)


Measured memory_bytes: 15096
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    int ans = 0;
    rep(i, 1, 40101) {
        if (i*i <= N) ans = max(ans, i*i);
        else break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())


while True:
    N = inp()
    if N == 0:
        break
    else:
        stack_numbers = [[] for _ in range(20)]
        stack_symbols = ['' for _ in range(20)]
        bL = -1
        for _ in range(N):
            S = input()
            L = len(S)
            #print(stack_symbols)
            #print(stack_numbers)
            if L < bL:
                for i in reversed(range(L,bL)):
                    if stack_symbols[i] == '+':
                        for j in range(1,len(stack_numbers[i])):
                            stack_numbers[i][j] += stack_numbers[i][j-1]
                    else:
                        for j in range(1,len(stack_numbers[i])):
                            stack_numbers[i][j] *= stack_numbers[i][j-1]
                    stack_numbers[i-1].append(stack_numbers[i][-1])
                    stack_numbers[i] = []
                    stack_symbols[i] = ''
                    #print(stack_numbers)

            s = S[-1]
            if 48 <= ord(s) <= 57:
                s = int(s)
                stack_numbers[L-1].append(s)
            else:
                stack_symbols[L] = s
            bL = L

        L = 0
        for i in reversed(range(L,bL)):
            if stack_symbols[i] == '+':
                for j in range(1,len(stack_numbers[i])):
                    stack_numbers[i][j] += stack_numbers[i][j-1]
            else:
                for j in range(1,len(stack_numbers[i])):
                    stack_numbers[i][j] *= stack_numbers[i][j-1]
            stack_numbers[i-1].append(stack_numbers[i][-1])
            stack_numbers[i] = []
            stack_symbols[i] = ''

        print(stack_numbers[-1][0])



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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

    while(true) {
        int n, k;
        cin >> n >> k;
        if (n == 0 or k == 0) {
            break;
        }

        vector<bool> card(n + 10);
        FOR(i, 0, k) {
            int c;
            cin >> c;
            card[c] = true;
        }

        int ans = 0;
        vector<int> dp1(n + 100, 0);
        FOR(i, 1, dp1.size()) {
            if (card[i]) {
                dp1[i] += dp1[i - 1] + 1;
            }
            else {
                dp1[i] = 0;
            }
            ans = max(ans, dp1[i]);
        }

        vector<int> dp2(n + 100, 0);
        for(int i = dp2.size() - 2; i > 0; --i) {
            if (card[i]) {
                dp2[i] += dp2[i + 1] + 1;
            }
            else {
                dp2[i] = 0;
            }
            ans = max(ans, dp2[i]);
        }

        if (card[0]) {
            FOR(i, 1, n + 10) {
                ans = max(ans, dp1[i - 1] + 1 + dp2[i + 1]);
            }
        }

        print(ans);
    }

	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define pr pair<int,int>
#define all(x) x.begin(),x.end()
#define mod 1000000007

ll power(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
          res=res*x;
        x=(x*x);
        y>>=1;
    }
    return (res);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll k; cin>>k;
	for(ll i=-200;i<=200;i++)
		for(ll j=-200;j<=200;j++)
			if((power(i,5)-power(j,5))==k)
				return cout<<i<<" "<<j<<"\n" , 0;


	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define il inline
#define ri register int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 200050
#define MAXM
#define mod
#define inf (1<<30)
#define eps (1e-6)
#define alpha 0.75
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define repd(i, x, y) for(ri i = x; i >= y; --i)
#define file(s) freopen(s".in", "r", stdin), freopen(s".my", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
template <typename T> il bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> il bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
template <typename T> il void read(T &x) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
}
template <typename T, typename... Args> il void read(T &x, Args &...args) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
	read(args...);
}
int n, q, val[MAXN], fa[MAXN], tot;
ll ans;
struct node {
	int u, v, w;
	bool operator < (const node &x) const {
		return w < x.w;
	}
} E[MAXN<<2];
int get(int u) {
	return u == fa[u] ? u : fa[u] = get(fa[u]);
}
bool merge(int u, int v) {
	u = get(u), v = get(v);
	if(u == v) return 0;
	return fa[u] = v, 1;
}
int main() {
	read(n, q);
	int u, v, w;
	rep(i, 1, n) val[i] = 2e9, fa[i] = i;
	while(q--) {
		read(u, v, w), ++u, ++v;
		E[++tot] = node {u, v, w};
		chkmin(val[u], w+1), chkmin(val[v], w+2);
	}
	rep(j, 0, 2)
		rep(i, 1, n) val[i] = min(val[i], val[i==1 ? n : i-1]+2);
//	rep(i, 1, n) cout<<val[i]<<' ';
	rep(i, 1, n) E[++tot] = node {i, i==n ? 1 : i+1, val[i]};
	sort(E+1, E+tot+1);
	rep(i, 1, tot) 
		if(merge(E[i].u, E[i].v)) ans += E[i].w;
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 12288