akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

template <typename T> ostream& operator<<(ostream& out, vector<T> &v){
  for (int i = 0; i < (int)v.size(); i++) {
    out<<v[i]<<' ';
  }
  return out;
}

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

  int n; cin >> n;
  int a = 0, b = 0, c = 0, d = 0;
  string s;
  rep(i, n){
    cin >> s;
    if(s == "AC") a++;
    if(s == "WA") b++;
    if(s == "TLE") c++;
    if(s == "RE") d++;
  }

  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;




  return 0;
}


Measured memory_bytes: 3632
//##MohK
//13/2/2020.... 10,05
#include <bits/stdc++.h>
using namespace std ;
using ll = long long ;
using ld = long double;
int main(){
    ll a,k=0;
    cin>>a;
    ll l[a],t[a];
    for(ll i=0;i<a;i++){
        cin>>l[i]>>t[i];
        k=k+(t[i]-l[i]+1);
    }
    cout<<k<<endl;

 return 0 ;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll k, i, j;
    string s;
    cin >> k >> s;
    if(s.size()<=k){
        cout << s << "\n";
    }
    else{
        for (i = 0; i < k;i++){
            cout << s[i];
        }
        cout << "...\n";
    }
    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  std::cin >> S;
  int N = S.size();
  string F = S.substr(0,(N-1)/2);
  string G = S.substr((N+1)/2);
  std::string A = F;
  std::string B = G;
  std::string X = S;
  std::reverse(S.begin(), S.end());
  std::reverse(A.begin(), A.end());
  std::reverse(B.begin(), B.end());
  if (A == F && B  == G && S == X) {
    std::cout << "Yes" << '\n';
  }
  else{
    std::cout << "No" << '\n';
  }
}


Measured memory_bytes: 256
using System;

class IDONTKNOWCSHARP
{
    public static void Main()
    {
        string mozi = "";
        int aa = int.Parse(Console.ReadLine());
        for (int i = 0; i <aa; i++)
        {
            mozi += "ACL";
        }

        Console.WriteLine(mozi);
    //    Console.ReadLine();
    }


    static int[] Convert(string[] v)
    {
        var temp = new int[v.Length];

        for (int i = 0; i < temp.Length; i++)
        {
            temp[i] = int.Parse(v[i]);
        }

        return temp;
    }




    static string[] GetLines()
    {
        return Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
    }


}

Measured memory_bytes: 27544
h,w,k = map(int,input().split())
s = [tuple(map(int, input())) for _ in range(h)]

sum_w = [[0] * (w+1) for _ in range(h)]
for i in range(h):
    for j in range(1,w+1):
        sum_w[i][j] = sum_w[i][j-1] + s[i][j-1]

# sum_h = [[0] * w for _ in range(h+1)]
# for i in range(1,h+1):
#     for j in range(w):
#         sum_h[i][j] = sum_h[i-1][j] + sum_w[i-1][j+1]

sums = []
for i in range(h):
    sums.append([[0] * w for _ in range(h+1)])

for i in range(h):
    for j in range(i+1,h+1):
        for l in range(w):
            sums[i][j][l] = sums[i][j-1][l] + sum_w[j-1][l+1]

ans = h + w
for i in range(2**(h-1)):
    nums = []
    for j in range(h-1):
        if((i >> j)&1 == 1):
            nums.append(j+1)
    tmp = len(nums)
    nums.append(h)
    # print(nums)
    head = 0
    checks = []
    for j in nums:
        checks.append(sums[head][j])
        head = j
    # print(i)
    # print(checks)

    minus_num = [0] * len(checks)
    w_now = 0
    NG_flag = 0
    cut_flag = 0
    for j in range(w):
        if(NG_flag == 1):
            break
        for l in range(len(checks)):
            check_num = checks[l][j] - minus_num[l]
            if(check_num > k):
                if(w_now == 0):
                    # print('hoge')
                    NG_flag = 1
                    break
                cut_flag = 1
                break


        if(cut_flag==1):
            # print('j={}'.format(j))
            tmp += 1
            for l in range(len(checks)):
                minus_num[l] = checks[l][j-1]
                check_num = checks[l][j] - minus_num[l]
                if(check_num > k):
                    NG_flag=1
                    break
            cut_flag = 0
            w_now = 1
        else:
            w_now += 1

    # print('')
    # print(tmp)
    if(NG_flag==0):
        ans = min(ans, tmp)
        # print('ans = {}'.format(ans))


print(ans)


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

#define SIZE 262144

struct SGT_Max{
	int f[SIZE<<1],l,r;
	void set(int x,int v){
		x+=SIZE;f[x]=v;
		while(x!=1){
			x>>=1;
			f[x]=max(f[x<<1],f[x<<1|1]);
		}
	}
	int _query(int L,int R,int k){
		if(R<l||r<L)return -1e9;
		if(l<=L&&R<=r)return f[k];
		return max(_query(L,L+R>>1,k<<1),_query((L+R>>1)+1,R,k<<1|1));
	}
	int query(int _l,int _r){
		l=_l;r=_r;return _query(0,SIZE-1,1);
	}
}dif,Max;

struct SGT_Min{
	int f[SIZE<<1],l,r;
	void set(int x,int v){
		x+=SIZE;f[x]=v;
		while(x!=1){
			x>>=1;
			f[x]=min(f[x<<1],f[x<<1|1]);
		}
	}
	int _query(int L,int R,int k){
		if(R<l||r<L)return 1e9;
		if(l<=L&&R<=r)return f[k];
		return min(_query(L,L+R>>1,k<<1),_query((L+R>>1)+1,R,k<<1|1));
	}
	int query(int _l,int _r){
		l=_l;r=_r;return _query(0,SIZE-1,1);
	}
}Min;

int n,k;
int p[200005];
int par[200005];
int find(int x){
	if(x==par[x])return x;
	return par[x]=find(par[x]);
}
void unite(int x,int y){
	int nx=find(x),ny=find(y);
	par[nx]=ny;
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)par[i]=i;
	for(int i=1;i<=n;i++){
		scanf("%d",&p[i]);
		dif.set(i,p[i-1]-p[i]);
		Max.set(i,p[i]);
		Min.set(i,p[i]);
	}
	for(int i=2;i+k-1<=n;i++){
		//check i-1 and i
		if(Min.query(i-1,i+k-2)==p[i-1]&&Max.query(i,i+k-1)==p[i+k-1]){
			unite(i,i-1);
		}
	}
	vector<int>Same;
	for(int i=1;i+k-1<=n;i++){
		//check same
		if(dif.query(i+1,i+k-1)<0){
			Same.push_back(i);
		}
	}
	for(int i=1;i<Same.size();i++){
		unite(Same[i-1],Same[i]);
	}
	set<int>fuck;
	for(int i=1;i+k-1<=n;i++)fuck.insert(find(i));
	cout<<fuck.size()<<endl;
	return 0;
}

Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N;
    cin>>N;
    vector<string> S(N);
    rep(i,N){
        cin>>S[i];
    }
    map<string,int> cnt;
    rep(i,N){
        if(cnt.count(S[i])){
            cnt[S[i]]++;
        }else{
            cnt[S[i]]=1;
        }
    }
    int cnts=0;
    for(auto itr : cnt){
        cnts=max(cnts,itr.second);
    }
    vector<string> ans;
    for(auto itr : cnt){
        if(itr.second==cnts){
            ans.push_back(itr.first);
        }
    }
    sort(all(ans));
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 27120
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        int[] ND = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, D) = (ND[0], ND[1]);
        var X = new int[N][];
        for (int i = 0; i < N; i++)
            X[i] = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        bool IsDistanceInteger(int[] y, int[] z)
        {
            var sum = y.Zip(z, (_y, _z) => (_y - _z) * (_y - _z)).Sum();
            var roundedSqrt = Math.Round(Math.Sqrt(sum));

            return (roundedSqrt * roundedSqrt == sum);
        }

        var ans = 0;

        for (int i = 0; i < N; i++)
            for (int j = i + 1; j < N; j++)
                if (IsDistanceInteger(X[i], X[j]))
                    ans++;

        WriteLine(ans);
    }
}


Measured memory_bytes: 28336
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
        ifstream in("input.txt");
        ofstream out("output.txt");
        #define cin in
        #define cout out
#endif
int const MAXN=1100, M=1000000007;
int n, m, dp[MAXN][MAXN];
bool v[MAXN][MAXN];
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++){
			char ch;
			cin>>ch;
			v[i][j]=(ch=='.')?true:false;
		}
	int riga=n-1, colonna=m-1;
	while(riga!=-1){
		if(riga==n-1 && colonna==m-1)
			dp[riga][colonna]=1;
		else{
			int x=riga, y=colonna;
			while(x>=0 && y<m){
				if(!v[x][y])
					dp[x][y]=0;
				else{
					int res=0;
					if(x<n-1) res+=dp[x+1][y];
					if(y<m-1) res+=dp[x][y+1];
					dp[x][y]=res%M;
				}
				x--, y++;
			}
		}
		if(colonna>0) colonna--;
		else riga--;
	}
	cout<<dp[0][0];
} 

Measured memory_bytes: 5632
/*
 * 2589.cc: North North West
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef vector<int> vi;

/* global variables */

/* subroutines */

/* main */

int main() {
  for (;;) {
    string s;
    cin >> s;
    if (s == "#") break;

    vi ds;
    int pos = 0;
    while (pos < s.size()) {
      if (s[pos] == 'n') ds.push_back(0), pos += 5;
      else ds.push_back(1), pos += 4;
    }
    //for (int i = 0; i < ds.size(); i++) printf("%d", ds[i]); putchar('\n');

    int n0 = (ds.back() == 0) ? 0 : 90;
    int d0 = 1;
    for (int i = ds.size() - 2; i >= 0; i--) {
      if (ds[i] == 0) n0 = n0 * 2 - 90;
      else n0 = n0 * 2 + 90;
      d0 <<= 1;
    }

    int g = __gcd(n0, d0);
    n0 /= g, d0 /= g;

    if (d0 == 1) printf("%d\n", n0);
    else printf("%d/%d\n", n0, d0);
  }
  
  return 0;
}

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

using namespace std;

int main(){

	long long int n;
	cin >> n;

	long long int cost = 1000000000007;


	long long int s = (long long int) sqrt(n+1)+1;

	for (int i = 1; i <= s; i++) {
		if (n % i == 0) {
			long long int t = (i-1) + (n / i -1); 

			if (cost < t) 
				break;

			cost = min(cost, t);

		}
	}

	cout << cost << endl;

	return 0;
}



Measured memory_bytes: 256
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
mod = 10**9+7
a_list.sort()
ans = 1
if k % 2 == 1 and a_list[-1] < 0:
    for i in range(k):
        ans *= a_list[n - 1 - i]
        ans %= mod
else:
    l = 0
    r = -1
    mlt1 = a_list[0] * a_list[1]
    mlt2 = a_list[-2] * a_list[-1]
    count = 0
    while True:
        if count == k:
            break
        elif count == k - 1:
            ans *= a_list[r] % mod
            ans %= mod
            break
        if mlt1 >= mlt2:
            ans *= mlt1 % mod
            l += 2
            count += 2
            if l <= n - 2:
                mlt1 = a_list[l + 1] * a_list[l]
        else:
            ans *= a_list[r] % mod
            r -= 1
            count += 1
            if r >= - n + 1:
                mlt2 = a_list[r - 1] * a_list[r]
        ans %= mod
print(ans)

Measured memory_bytes: 104888
n, k = map(int, input().split())
x =list(map(int, input().split()))

ans = 300000000
for i in range(0, n-k+1):
    if x[i] >= 0:
        t = x[i+k-1]
    elif x[i+k-1] <= 0:
        t = -x[i]
    else:
        t = min(-x[i], x[i+k-1]) + x[i+k-1] - x[i]
    ans = min(t, ans)

print(ans)

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

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    int A[100001];
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> A[i];
    }
    
    int x = A[n - 1];
    int i =  -1;
    
    for(int j = 0; j < n - 1; ++j){
        if(A[j] <= x){
            ++i;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[n - 1]);
    
    for(int j = 0; j < n; ++j){
        if(j != 0) cout << ' ';
        if(j == i + 1) cout << '[';
        cout << A[j];
        if(j == i + 1) cout << ']';
    }
    cout << endl;
}

Measured memory_bytes: 1592
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[100100];

int solve() {
    vector<int> b(n);
    for (int i = 0; i < n; i++) b[i] = a[i];
    sort(ALL(b));
    set<int> even;
    for (int i = 0; i < n; i++) {
        if (i%2 == 0) {
            even.insert(b[i]);
        }
    }

    int res = 0;
    for (int i = 0; i < n; i+=2) {
        if (even.count(a[i]) == 0) {
            res++;
        }
    }
    return res;
}

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

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 6336
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std; using ll=long long; const ll LNF=1e18; const int INF = 1e9+1; const ll M = 1e9+7;
typedef pair<int,int> P;
ll gcd(ll x, ll y) {if (y==0) return x; else return gcd(y, x%y);}
int main() {
  int n; cin>>n;
  P p[n]; for(int i=0;i<n;i++) cin>>p[i].second>>p[i].first;
  sort(p,p+n);
  int nw = 0; bool ok = true;
  for(int i=0;i<n;i++) {
    if (nw + p[i].second <= p[i].first) nw += p[i].second;
    else ok = false;
  }
  if (ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt[26] = {};
    REP(i,n) cnt[ int(s[i] - 'a')] ++;
    int res = 1;
    REP(i,26){
        res *= cnt[i] + 1;
        res %= MOD;
    }
    cout << res - 1<< endl;

}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
using namespace std;
typedef pair<int,int> P;
const int INF = ~(1<<31) / 2;
 
int c[100][100];
int t[100][100];
int n,m,k;
 
int main(){
    while(1){
        scanf("%d %d",&n,&m);
        if(n==0) break;
        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                c[i][j] = 1000000;
                t[i][j] = 1000000;
            }
        }
        for(int i=0;i<n;i++){
            int a,b,co,ti;
            scanf("%d %d %d %d",&a,&b,&co,&ti);
            a--;b--;
            c[a][b] = co;
            c[b][a] = co;
            t[a][b] = ti;
            t[b][a] = ti;
        }
 
        for(int k=0;k<m;k++){
            for(int i=0;i<m;i++){
                for(int j=0;j<m;j++){
                    c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
                    t[i][j] = min(t[i][j],t[i][k]+t[k][j]);
                }
            }
        }
 
        scanf("%d",&k);
        for(int i=0;i<k;i++){
            int p,q,r;
            scanf("%d %d %d",&p,&q,&r);
            p--;q--;
            if(r)printf("%d\n",t[p][q]);
            else printf("%d\n",c[p][q]);
        }
    }
    return 0;
}

Measured memory_bytes: 1264
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;

/*
1
2 0
3
*/

string s;
int x,y;

int main(){
	cin >> s;
	cin >> x >> y;

	vector<int> len;
	for(size_t i = 0; i < s.length(); ++i){
		int cnt = 0;
		while(i<s.length()&&s[i] == 'F'){
			++i;
			++cnt;
		}
		len.push_back(cnt);
	}

	vector<int> lenx,leny;
	for(size_t i = 0; i < len.size(); ++i){
		if(i % 2==0){
			lenx.push_back(len[i]);
		} else{
			leny.push_back(len[i]);
		}
	}

	vector<set<int>> dpx(lenx.size()+1),dpy(leny.size()+1);//i回目の移動後の座標の配列

	dpx[0] = {0};
	dpx[1] = {lenx[0]};
	for(size_t i = 2; i <= lenx.size(); ++i){
		for(auto&& memo : dpx[i - 1]){
			dpx[i].insert(memo - lenx[i - 1]);
			dpx[i].insert(memo + lenx[i - 1]);
		}
	}

	dpy[0] = {0};
	for(size_t i = 1; i <= leny.size(); ++i){
		for(auto&& memo : dpy[i - 1]){
			dpy[i].insert(memo - leny[i - 1]);
			dpy[i].insert(memo + leny[i - 1]);
		}
	}

	for(auto&& resx : *(dpx.end()-1)){
		if(resx == x){
			for(auto&& resy : *(dpy.end()-1)){
				if(resy == y){
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 232192
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
using ll=long long;
int main(){
  string s, t;
  cin >> s;
  cin >> t;
  int ss=s.size();
  int ts=t.size();
  
  if ((s==t.substr(0, s.size()))&(ts-ss==1)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
import math
A, B, N = list(map(int, input().split()))
ans = 0
if B+1 < N:
    C = B+1
else:
    C = N
if B//A == 0:
    D = 1
elif B//A > 1:
  	D = B//A-1
else:
    D = B//A
for i in range(1, C+1, D):
    val = math.floor(A*i/B) - A*math.floor(i/B)
    #print("i", i, "val", val)
    ans = max(ans, val)

print(ans)

Measured memory_bytes: 67760
#include <algorithm>
#include <utility>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb std::push_back
using std::set; 
using std::map; 
using std::pair; 
using std::vector; 
using std::string; 
using std::priority_queue; 
int main()
{
	// freopen("ARC089-C.in", "r", stdin); 
	int x = 0, y = 0, lst = 0, n;
	scanf("%d", &n); 
	for (int i = 0; i < n; i++)
	{
		int t, xx, yy; 
		scanf("%d%d%d", &t, &xx, &yy); 
		int d = my_abs(x - xx) + my_abs(y - yy); 
		if (d > t - lst || (d ^ (t - lst)) & 1)
		{
			puts("No");
			return 0; 
		}
		lst = t; 
		x = xx; 
		y = yy; 
	}
	puts("Yes"); 
	return 0; 
}


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

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

map<int, int> compress(vector<int>& unzip) {
  map<int, int> zip;
  for (auto x : unzip) zip[x] = -1;
  int idx = 0;
  unzip = vector<int>();
  for (auto& p : zip) {
    unzip.push_back(p.first);
    p.second = idx;
    idx++;
  }
  return zip;
}

vector<vector<int>> color;

void dfs(int sy, int sx, int c) {
  color[sy][sx] = c;
  REP(k, 4) {
    int ty = sy + dy[k];
    int tx = sx + dx[k];
    if (ty < 0 || M < ty || tx < 0 || M < tx) continue;
    if (color[ty][tx] > 0) continue;
    dfs(ty, tx, c);
  }
}

int main() {
  for (int n; cin >> n, n;) {
    vector<int> x(4 * n + 1, -1), y(4 * n + 1, -1);
    REP(i, n) {
      int l, t, r, b;
      cin >> l >> t >> r >> b;
      x[4 * i + 0] = 2 * l;
      x[4 * i + 1] = 2 * l + 1;
      x[4 * i + 2] = 2 * r;
      x[4 * i + 3] = 2 * r + 1;
      y[4 * i + 0] = 2 * b;
      y[4 * i + 1] = 2 * b + 1;
      y[4 * i + 2] = 2 * t;
      y[4 * i + 3] = 2 * t + 1;
    }
    auto tmpx = x;
    auto tmpy = y;
    auto X = compress(tmpx);
    auto Y = compress(tmpy);

    color = vector<vector<int>>(M + 1, vector<int>(M + 1, 0));
    REP(i, n) {
      int l = X[x[4 * i + 0]];
      int r = X[x[4 * i + 2]];
      int b = Y[y[4 * i + 0]];
      int t = Y[y[4 * i + 2]];
      color[b][l]++;
      color[b][r + 1]--;
      color[b + 1][l]--;
      color[b + 1][r + 1]++;
      color[t][l]++;
      color[t][r + 1]--;
      color[t + 1][l]--;
      color[t + 1][r + 1]++;
      color[b][l]++;
      color[b][l + 1]--;
      color[t + 1][l]--;
      color[t + 1][l + 1]++;
      color[b][r]++;
      color[b][r + 1]--;
      color[t + 1][r]--;
      color[t + 1][r + 1]++;
    }
    REP(i, M) REP(j, M + 1) color[i + 1][j] += color[i][j];
    REP(i, M + 1) REP(j, M) color[i][j + 1] += color[i][j];

    int c = 0;
    REP(i, M + 1) REP(j, M + 1) {
      if (color[i][j] > 0) continue;
      dfs(i, j, ++c);
    }
    cout << c << endl;
  }
}



Measured memory_bytes: 9224
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int ll;
const ll mod=1e5;
int main(){
    int n,m;
    cin>>n>>m;
    ll dp[100001]={0};
    for(int i=2;i<=n;i++){
        int latte;
        cin>>latte;
        dp[i]=latte+dp[i-1];
        dp[i];
    }
    int cafe=1;
    ll sum=0;
    for(int i=0;i<m;i++){
        int to;
        cin>>to;
        ll a=dp[cafe]-dp[cafe+to];
        if(a<0)a*=-1;
        sum+=a;
        cafe+=to;
    }
    sum%=mod;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1944
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,j,k) for(int (i)=(j);(i)<(k);++(i))

int main(){
    vector<vector<int>> C(3,vector<int>(3));
    rep(i,0,3){rep(j,0,3){cin>>C[i][j];}}
    bool ok = false;

    rep(i,0,101){
        vector<int> a;
        vector<int> b{C[0][0]-i,C[0][1]-i,C[0][2]-i};
        rep(j,1,3){
            rep(k,0,3){
                a.push_back(C[j][k]-b[k]);
            }
        }
        int a1=a[0],a2=a[3];
        bool f=true;
        rep(j,0,6){
            if(j<3&&a1!=a[j]) f=false;
            else if(j>3&&a2!=a[j]) f=false;
        }
        ok=(f?1:0);
    }
    puts(ok?"Yes":"No");
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=1000005;
int n,h,i,j,k,l,ans,A,B,C,D,g[405][405],u[N],p[N],ind[N],outd[N];
bool vis[N],ok[N];
int find(int x)
{
	return p[x]==-1?x:p[x]=find(p[x]);
}
int main()
{
	scanf("%d%d",&n,&h);
	for(i=1;i<=n;++i)
	{
		scanf("%d%d%d%d",&A,&B,&C,&D);
		if(C)
			A=C+h;
		if(D)
			B=D+h;
		g[A][B<=h?B+h:B-h]++;
		vis[A]=vis[B<=h?B+h:B-h]=true;
	}
	for(i=1;i<=2*h;++i)
		for(j=1;j<=2*h;++j)
			ind[j]+=g[i][j],outd[i]+=g[i][j];
	for(i=1;i<=h;++i)
		if(outd[i]<ind[i])
		{
			puts("NO");
			return 0;
		}
	for(i=h+1;i<=2*h;++i)
		if(outd[i]>ind[i])
		{
			puts("NO");
			return 0;
		}
	for(i=1;i<=2*h;++i)
		p[i]=-1;
	for(i=1;i<=2*h;++i)
		for(j=1;j<=2*h;++j)
			if(g[i][j]&&find(i)!=find(j))
				p[find(i)]=find(j);
	for(i=1;i<=2*h;++i)
		if(outd[i]!=ind[i])
			ok[find(i)]=true;
	for(i=1;i<=2*h;++i)
		if(find(i)==i&&!ok[i]&&vis[i])
		{
			puts("NO");
			return 0;
		}
	puts("YES");
	return 0;
}

Measured memory_bytes: 4864
n = int(input())
c, b = map(int, input().split())
k = int(input())
A = [int(input()) for _ in range(n)]
A.sort(reverse=True)
r = k/c
for i in A:
	k += i
	c += b
	if k/c<=r:
		break
	else:
		r = k/c
print(int(r))



Measured memory_bytes: 5600
#include <stdio.h>
int main (){
    int a, b, c, sum = 0;
    scanf ("%d %d %d", &a, &b, &c);
    
    if (a >= b && a >= c){
        sum = b + c;
    }
    else if (b >= a && b >= c){
        sum = a + c;
    }
    else if (c >= a && c >= b){
        sum = a + b;
    }
    
    printf ("%d", sum);
    return 0;
}

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

using namespace std;

bool is_palindrome(string s)
{
	string t(s.rbegin(), s.rend());
	return s == t;
}

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(3 * n);
  long long lsum = 0, rsum = 0;
  priority_queue<long long, vector<long long>, greater_equal<long long>> l;
  priority_queue<long long, vector<long long> ,less_equal<long long>> r;
  for (int i = 0; i < 3*n; i++) {
    cin >> a[i];
    if (i < n) {
      lsum += a[i];
      l.push(a[i]);
    }
    if (i >= 2 * n) {
      rsum += a[i];
      r.push(a[i]);
    }
  }
  
  vector<long long> lsuma;
  lsuma.push_back(lsum);
  for (int i = n; i < 2 * n; i++) {
    if (lsum < lsum - l.top() + a[i]) {
      lsum += a[i] - l.top();
      l.pop();
      l.push(a[i]);
    }
    lsuma.push_back(lsum);
  }
  long long rsumr = rsum;
  vector<long long> rsuma;
  for (int i = 2 * n - 1; i >= n; i--) {
    if (rsum > rsum - r.top() + a[i]) {
      rsum += a[i] - r.top();
      r.pop();
      r.push(a[i]);
    }
    rsuma.push_back(rsum);
  }
  reverse(rsuma.begin(), rsuma.end());
  rsuma.push_back(rsumr);
  
  long long ans = -1e18;
  
  for(int i = 0; i <= n; i++) {
    ans = max(ans, lsuma[i] - rsuma[i]);
  }
  
  cout << ans << endl;
  
  return 0;
}


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

using namespace std;
using namespace std;
typedef long long ll;
#define endl "\n";
#define MAX 10000001+9   //Maximum array size;
#define loop(n) for(ll i=0;i<n;i++)
#define loop2(n) for(ll i=0;i<n;i+=2)
#define all(v) v.begin(),v.end()
#define sz(v)  v.size()
typedef vector<ll> vi;
typedef set<ll> si;

void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}

int pow(int a, int b) {
    int pow = 1;
    loop(b)pow *= a;
    return pow;
    //thanks m7md :)
}

int main() {
    fast();
  //freopen("input.txt","r",stdin);
    int a,b,c;cin>>a>>b>>c;
    if((c>a&&c<b)||(c>b&&c<a))cout<<"Yes";
    else cout<<"No";


}



Measured memory_bytes: 256
for a in $(tail -1); do
    c=0
    while (( $(( a % 2 == 0 )) )); do
        a=$(( a / 2 ))
        c=$(( c + 1 ))
    done
    echo $c
done |
awk '
BEGIN { ans = 100000 }
{ ans = ans < $1 ? ans : $1 }
END {print ans}'  # take minimum


Measured memory_bytes: 1024
#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

template<class T>
inline bool chmax(T& a, const T b) { return a < b && (a = b, true); }

int main() {

	lint N;
	cin >> N;
	
	vector<lint> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	lint sum = 0, num = 1;
	for (int i = 0; i < N; i++) {
		if (A[i] > num) {
			int a = (A[i] - 1) / num;
			sum += a;
			A[i] -= a * num;
			if (A[i] == num && A[i] != 1) A[i]--;
		}
		chmax(num, A[i] + 1);
		DMP(sum, num);
	}
	cout << sum << "\n";

	return 0;
}


Measured memory_bytes: 3852
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[][] F = new int[N][10 + 1];
        int[][] P = new int[N][10 + 1];

        for (int i = 0; i < N; i++) {
            for (int j = 1; j <= 10; j++) {
                F[i][j] = sc.nextInt();
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= 10; j++) {
                P[i][j] = sc.nextInt();
            }
        }

        int max = Integer.MIN_VALUE;
        for (int i = 1; i < (1 << 10); i++) {
            int a = 0;
            for (int j = 0; j < N; j++) {
                int c = 0;
                for (int k = 0; k < 10; k++) {
                    if ((i & (1 << k)) != 0 && F[j][10 - k] == 1) {
                        c++;
                    }
                }
                if (j == 0) {
                    a = P[j][c];
                } else {
                    a += P[j][c];
                }
            }
            max = Math.max(max, a);
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 26348
N, M = map(int, input().split())
A = list(map(int, input().split()))

dp = [[-1 for i in range(10)] for j in range(N+1)]

B = [0 for i in range(10)]
C = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
for i in range(10):
    if i in A:
        B[i] = C[i]

for i in range(10):
    dp[N][i] = 0
    
for i in range(N, -1, -1):
    for j in range(10):
        for k in range(j+1):
            if B[k] > 0 and i+B[k] <= N:
                # print(i, j, k, i+B[k])
                dp[i][k] = max(dp[i][k], dp[i+B[k]][j] * 10 + k)

# print(dp)
                
ans = 0
for i in range(10):
    ans = max(ans, dp[0][i])

print(ans)

Measured memory_bytes: 109148
from typing import List, Deque
from collections import deque

INF = 1 << 89

# 重み付き枝（隣接リストで表現）
class Edge:
	def __init__(self, t: int, w: int) -> None:
		self.t = t # to vertex t
		self.w = w # weight w

# Treeに対してbfs（閉路を気にしなくてよい）
def bfs(s: int) -> List[int]:
	d: List[int] = [INF for _ in range(n)]
	Q: Deque[int] = deque()
	Q.append(s)
	d[s] = 0
	while len(Q) > 0:
		u = Q.popleft()
		for e in G[u]:
			if d[e.t] == INF:
				d[e.t] = d[u] + e.w
				Q.append(e.t)
	return d

def solve() -> int:
	d: List[int] = bfs(0)
	maxv: int = 0
	tgt: int = 0
	for i in range(n):
		if d[i] == INF:
			continue
		if maxv < d[i]:
			maxv = d[i]
			tgt = i
	d = bfs(tgt)
	maxv = 0
	for i in range(n):
		if d[i] == INF:
			continue
		maxv = max(maxv, d[i])
	return maxv

if __name__ == "__main__":
	n = int(input())
	G: List[Edge] = [[] for _ in range(n)]
	for _ in range(n - 1): # 木の枝数は（節点数 - 1）
		s, t, w = map(int, input().split())
		G[s].append(Edge(t, w))
		G[t].append(Edge(s, w))
	ans = solve()
	print(ans)


Measured memory_bytes: 67728
from math import atan, degrees

def main():
    a, b, x = map(int, input().split())
    # xが多い場合：水が三角形になる前に溢れるパターン
    if (a**2*b) / 2 < x:
        # 水じゃないところが三角形 を area
        area = a * b - x/a
        c = 2 * area / a 
        # thetaが逆だから
        t = c / a
        ans = degrees(atan(t))
    else:
        # 面積で考えるので水の量/奥行き
        area = x / a
        c = 2 * area / b
        t = b / c
        ans = degrees(atan(t))
    print(ans)

if __name__ == '__main__':
    main()

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

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

    int a, b, k;
    cin >> a >> b >> k;

    int cnt = 0;
    for(int i = min(a, b); i >= 1;i--){
        if(a % i == 0 and b % i ==0) cnt++;
        if(cnt == k){
            cout << i << endl;
            return 0;
        }
    }



    return 0;
}

Measured memory_bytes: 256
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
ll dp[3001][3001];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	vi v(n);
	rep(i,n){
		cin>>v[i];
	}
	repr(i,n){
		repa(j,i,n){
			if(i == j){
				dp[i][j] = v[i];
 			}
 			else{
 				dp[i][j] = max(v[i] - dp[i+1][j],v[j] - dp[i][j-1]);
 			}
		}
	}
	cout<<dp[0][n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    string s;cin >>s;
    string w[3]={"Sunny","Cloudy","Rainy"};
    int key=-1;
    for (int i = 0; i < 3; ++i) {
        if(s==w[i]){
            key=i;
        }
    }
    key++;
    key%=3;
    cout <<w[key]<<endl;
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        String s = "E" + sc.next() + "E";

        long result = 0;
        String[] arrS = s.split("><");

        if (arrS.length > 1) {
            for (int i = 0; i < arrS.length; i++) {
                if (i == 0) {
                    arrS[i] += ">";
                } else if (i == arrS.length - 1) {
                    arrS[i] = "<" + arrS[i];
                } else {
                    arrS[i] = "<" + arrS[i] + ">";
                }
                result += getCount(arrS[i]);
            }

        } else {
            result += getCount(arrS[0]);
        }

        System.out.println(result);
    }

    public static long getCount(String s) {
        s = "E" + s + "E";
        String[] countS = s.split("<>");

        long result = 0;
        if (countS.length < 2) {
            s = s.replace("E", "");
            for (long i = 1; i <= s.length(); i++) {
                result += i;
            }

        } else {

            long left = countS[0].replace("E", "").length() + 1;
            long right = countS[1].replace("E", "").length() + 1;

            long max = Math.max(left, right);
            long min = Math.min(left, right);
            for (long i = 1; i <= max; i++) {
                result += i;
                if (i < min) {
                    result += i;
                }
            }
        }

        return result;
    }

}

Measured memory_bytes: 150116
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

A = ri()
B = ri()
print('GREATER' if A > B else 'LESS' if A < B else 'EQUAL')

Measured memory_bytes: 9180
#include <stdio.h>

char str[2][3];

int main(void){
  for(int i = 0; i < 2; ++i) scanf("%s", str[i]);
  int cnt = 0;
  for(int i = 0; i < 3; ++i) if(str[0][i] == str[1][i]) cnt++;
  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define all(o) o.begin(), o.end()
#define IOS ios::sync_with_stdio(0), cin.tie(0)
const int inf = 2e9 + 100;
int d(int x,int y){
    if(x <= y) return y - x;
    return inf;
}
int main(){
    int x, y;
    cin >> x >> y;
    int t1 = min(d(x, y), d(-x, y) + 1);
    int t2 = min(d(x, -y) + 1, d(-x, -y) + 2);
    cout << min(t1, t2) << endl;
}


Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A[base10_6];
ll maxN[base10_6];
ll minN[base10_6];
//long double ldvMin;
//long double ldvMax;
long double ldvMax;
long double ldvMin;
ll B;
ll C;
ll N;
ll M;
ll K;
ll cntans = 0;
ll realMax = 2;

ll cnt;
ll getPower(ll value,ll shisu){
    ll ans = 1;
    cnt = shisu;
    while(cnt>0){
        if(cnt%2==1){
            ans = ans * value;
        }
        value = value * value;
        cnt = cnt/2;
    }
    return ans;
}

int main(){

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

    bool flag=true;
    maxN[N] = A[N];
    minN[N] = A[N];
    ldvMin  = minN[N];
    //cout << ldvMin << endl;
    if(log2(ldvMin) > N){
        flag = false;
    }


    if(flag){

        //cout << cntans << endl;
        for( int ni = N-1 ; ni >=0 ; ni-- ){
            maxN[ni] = A[ni] + maxN[ni+1];
            minN[ni] = A[ni] + minN[ni+1]/2 + minN[ni+1]%2;
            ldvMin  = minN[ni];
            //cout << ldvMin << endl;
            if(log2(ldvMin) > ni){
                flag = false;
                break;
            }
            ldvMax  = maxN[ni];
            //cout << ldvMax << endl;
            if(log2(ldvMax) > ni){
                //cout << "getpower " << ni << " : " << getPower(2,ni)<< endl;
                maxN[ni] = getPower(2,ni);
            }
        }
    }
    if(flag){
        cntans = 1;
        realMax = 2;
        for( int ni = 1 ; ni <=N ; ni++ ){
            if(realMax > maxN[ni]){
                realMax = maxN[ni];
            }
            else if(minN[ni]>realMax){
                flag = false;
                break;
            }
            cntans+=realMax;
            realMax = realMax - A[ni];
            realMax = realMax * 2;
        }
        cout << cntans << endl;
    }else{
        cout << -1 << endl;
    }
    

}

Measured memory_bytes: 6008
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	string temp;
	getline(cin, temp);
	int q = stoi(temp);
	deque<int>a;
	REP(i, q)
	{
		getline(cin, temp);
		stringstream query(temp);
		vector<string>querys;
		while (query)
		{
			query >> temp;
			querys.push_back(temp);
		}
		switch (static_cast<int>(querys[0][0] - '0'))
		{
		case 0:
			switch (stoi(querys[1]))
			{
			case 0:
				a.push_front(stoi(querys[2]));
				break;
			case 1:
				a.push_back(stoi(querys[2]));
				break;
			}
			break;
		case 1:
			cout << a[stoi(querys[1])] << endl;
			break;
		case 2:
			switch (stoi(querys[1]))
			{
			case 0:
				a.pop_front();
				break;
			case 1:
				a.pop_back();
				break;
			}
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 4656
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n,p;
  while(cin>>n>>p,n||p){
    vector<int> v(n);
    for(int i=0,x=p;;i=(i+1)%n){
      if(x){
        --x;++v[i];
        if(v[i]==p){cout<<i<<endl;break;}
      }else{
        x=v[i];v[i]=0;
      }
    }
  }
  return 0;
}

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


int main()
{
	int n, d;
	cin >> n >> d;
	
	int ans;
	if (n % (2 * d + 1) == 0) {
		ans = n / (2 * d + 1);
	} else {
		ans = n / (2 * d + 1);
		ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define lson root<<1
#define rson root<<1|1
#define FREI freopen("in.txt","r",stdin)
#define FREO freopen("out.txt","w",stdout)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define MAXN 100100
using namespace std;
int h,w;
int ans[120][120];
int pox,poy;
int cnt;
void draw(int x,int id){
    while(x--){
        ans[pox][poy]=id;
        if(poy==w&&cnt==1){
            cnt=-cnt;
            pox++;
        }
        else if(poy==1&&cnt==-1){
            cnt=-cnt;
            pox++;
        }
        else poy+=cnt;
    }
}
int main() {
    //FREI;
    scanf("%d%d",&h,&w);
    int n;
    pox=poy=1;
    cnt=1;
    int id=1;
    scanf("%d",&n);
    while(n--){
        int x;
        scanf("%d",&x);
        draw(x,id++);
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++) printf("%d ",ans[i][j]);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	float x, sum = 0.0;
	string u;
	for(int i = 0; i < N; i++){
		cin >> x >> u;
		if(u == "BTC")
			sum += x*380000.0;
		else
			sum += x;
	}
	cout << sum << endl;
}

Measured memory_bytes: 384
import Control.Applicative
import Numeric
main = do{
    [a,b,c] <- map (read::String->Double) . words <$> getLine;
    putStrLn $ (show (a*b*sin(c*pi/180)/2)) ++ "\n" ++ (show (a+b+sqrt(a*a+b*b-2*a*b*cos(c*pi/180)))) ++ "\n" ++ (show (b*sin(c*pi/180)));
}

Measured memory_bytes: 4128
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
const int MX = 100 + 10, MD = 1e9 + 7;
int n, m, a[MX], b[MX], c[MX], d[MX], ans, tmp, x, y;
vector <pair <int, int>> adj[MX], red;
int main(){
    ios::sync_with_stdio(0) ; cin.tie(0) ;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        red.push_back({a[i], b[i]});
    }
    sort(red.begin(), red.end());
    reverse(red.begin(), red.end());
    for(int i = 0; i < n; i++){
        a[i] = red[i].F;
        b[i] = red[i].S;
    }
    for(int i = 0; i < n; i++){
        cin >> c[i] >> d[i];
        for(int j = 0; j < n; j++){
            if(a[j] < c[i] && b[j] < d[i]){
                adj[j].push_back({c[i], d[i]});
            }
        }
    }
    for(int i = 0; i < n; i++){
        int mn = 1e9;
        for(int j = 0; j < adj[i].size(); j++){
            x = adj[i][j].F;
            y = adj[i][j].S;
            if(x == -1)continue;
            if(mn == 1e9){
                mn = y;
                ans++;
                continue;
            }
            mn = min(mn, y);
        }
        //cout << mn << " ";
        if(mn != 1e9){
            for(int j = 0; j < n; j++){
                for(int k = 0; k < adj[j].size(); k++){
                    x = adj[j][k].F;
                    y = adj[j][k].S;
                    if(x == -1)continue;
                    if(y == mn){
                        adj[j][k].F = -1;
                        adj[j][k].S = -1;
                        break;
                    }
                }
            }
        }
    }
    cout << ans;

}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1 << 29;
int N, MA, MB;
int A[40], B[40], C[40];
int dp[41][401][401];
int ans = INF;
int main(void) {
    cin >> N >> MA >> MB;
    fill((int*)dp, (int*)dp + (N + 1) * 401 * 401, INF);
    for (int n = 0; n < N; ++n) cin >> A[n] >> B[n] >> C[n];
    dp[0][0][0] = 0;
    for (int n = 0; n < N; ++n) for (int a = 0; a <= 400; ++a) for (int b = 0; b <= 400; ++b) {
        if (dp[n][a][b] == INF) continue;
        dp[n + 1][a][b] = min(dp[n + 1][a][b], dp[n][a][b]);
        dp[n + 1][a + A[n]][b + B[n]] = min(dp[n + 1][a + A[n]][b + B[n]], dp[n][a][b] + C[n]);
    }
    for (int i = 1; MA * i <= 400 && MB * i <= 400; ++i) {
        ans = min(ans, dp[N][MA * i][MB * i]);
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25984
def search(a):
    x=0
    a="".join(["0"*(3-len(a)),a])
    for i in range(n):
        if a[x]==s[i]:
            x+=1
            if x==3:
                return True
    return False
n=int(input())
s=input()
ans=0
k=[False]*1000
for i in range(1000):
    k[i]=search(str(i))
for i in k:
    if i:
        ans+=1
print(ans)

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

int isPrime(int x)
{
    int i;
    if(x < 2)   return 0;
    else if(x == 2)    return 1;
    if(x%2 == 0)       return 0;
    for(i=3; i*i<=x; i+=2)
    {
        if(x%i == 0)
            return 0;
    }
    return 1;
}
int main()
{
    int n, a, sum = 0;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> a;
        if(isPrime(a))
            sum++;
    }
    cout << sum << endl;
    return 0;
}

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


int main() {
    map<char, int> mark_id = {{'S', 0}, {'H', 1}, {'C', 2}, {'D', 3}};
    
    int n;
    cin >> n;
    vector<vector<bool>> card(4, vector<bool>(13, false));
    for(int ii=0; ii<n; ii++){
        char m;
        int v;
        cin >> m >> v;
        v--;
        card[mark_id[m]][v] = true;
    }
    vector<char> mark = {'S', 'H', 'C', 'D'};
    for(auto& m : mark){
        for(int v=0; v<13; v++){
            if(card[mark_id[m]][v] == false){
                cout << m << " " << v+1 << endl;
            }
        }
    }
    return 0;
}


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

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	vector<int>P(N);
	for (int i = 0; i < N; i++) cin >> P.at(i);
	int E = 0, M = 0, D = 0;
	for (int i = 0; i < N; i++) {
		if (P.at(i) <= A) E++;
		else if (P.at(i) > A && P.at(i) <= B) M++;
		else D++;
	}
	cout << min({ E, M, D }) << endl;
}

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

int main() {
  int N;
  int x;
  int i,j;
  int tmp;
  i = 0;
  tmp = 2;
  
  cin >> N >> x;
  while ((x % tmp) == 0) {
    tmp *= 2;
    i++;
  }
  tmp /=2;
  for (j = 1; j <= N; j++){
    cin >> x;
    if (i != 0){
      while ((x % tmp) != 0) {
        tmp /= 2;      
        i--;
      }
    }
  }
  
  cout << i;
}


Measured memory_bytes: 256