akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <time.h>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define hoge cout << hoge << endl;
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,sum,ans;
ll a,b,c,d,e,f,g,h,w;
ll x[1000005],y[1000005],z[1000005];
bool flag,dame;
char s[500005];

void solve(ll a,ll b,ll c,ll d){
	if(n >= a){
		if(d >= 1 && b >= 1 && c >= 1)ans++;
		a *= 10;
		solve(a+3,b+1,c,d);
		solve(a+5,b,c+1,d);
		solve(a+7,b,c,d+1);
	}else{
		return;
	}
}


int main(){	
	cin >> n;
	solve(3,1,0,0);
	solve(5,0,1,0);
	solve(7,0,0,1);

	p(ans);
	return 0;
}

Measured memory_bytes: 25088
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define MINS(a,b) a = min(a,(decltype(a))(b))
#define MAXS(a,b) a = max(a,(decltype(a))(b))



int main() {
	ll N;
	cin >> N;
	vector<pair<ll, ll>> P(N);
	vector<pair<ll, ll>> v[2][2];
	ll a[2][2];
	REP(i, 0, N) {
		cin >> P[i].first >> P[i].second;
		if (i == 0) {
			REP(j, 0, 2)REP(k, 0, 2) {
				v[j][k].push_back(P[i]);
				a[j][k] = (j == 0 ? 1 : -1) * P[i].first + (k == 0 ? 1 : -1) * P[i].second;
			}
		}
		else {
			REP(j, 0, 2)REP(k, 0, 2) {
				ll tmp = (j == 0 ? 1 : -1) * P[i].first + (k == 0 ? 1 : -1) * P[i].second;
				if (tmp > a[j][k]) {
					v[j][k].clear();
					v[j][k].push_back(P[i]);
					a[j][k] = tmp;
				}
				else if (tmp == a[j][k]) {
					v[j][k].push_back(P[i]);
				}
			}
		}
	}
	auto cmp = [&](pair<ll, ll> a, pair<ll, ll> b) {
		if (a.first == b.first)return a.second < b.second;
		return a.first < b.first;
	};
	REP(j, 0, 2)REP(k, 0, 2)sort(v[j][k].begin(), v[j][k].end(), cmp);
	auto dist = [](pair<ll, ll> a, pair<ll, ll> b) {
		return abs(a.first - b.first) + abs(a.second - b.second);
	};
	ll ans = 0;
	REP(i, 0, N) {
		REP(j, 0, 2)REP(k, 0, 2) {
			MAXS(ans, dist(P[i], v[j][k][0]));
			MAXS(ans, dist(P[i], v[j][k].back()));
		}
	}
	PRI(ans);
	return 0;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(long long i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

  
int main() {
ll X, Y;
cin >> X >> Y;
ll cnt = 0;
  for(ll i = X;i  <= Y;i*=2){
    cnt++;
  }

print(cnt);
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int a[125];

int main(){
  cin>>n;
  REP(i,n)cin>>a[i];
  int s = accumulate(a,a+n,0);
  int id = 0;
  REP(i,n)if(abs(n*a[i]-s) < abs(n*a[id]-s)){
    id = i;
  }
  cout<<id<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;


 void test_cases()
{

ll n;
cin>>n;
string s;
cin>>s;
ll ans=0,x=0;
for(ll i=0;i<n;i++)
{
	if(s[i]=='I')x++;
	else
	x--;
	
	ans=max(ans,x);
}

cout<<ans;
}


int main()
{
    fast;
  ll t;
 // cin>>t;
 t=1;
  while(t--)
  test_cases();

  	
}

		
	
	
	
	


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

int main() {
	int n;
	cin>>n;
	int arr[n];
	int arr1[100005];
	int arr2[100005];

	memset(arr1,0,sizeof(arr1));
	memset(arr2,0,sizeof(arr2));
	for(int i=0;i<n;i++)
	{
		cin>>arr[i]; 
		if(i%2==0){arr1[arr[i]]++;}
		else {arr2[arr[i]]++; }
		
	}
	int a,b,x=-1,y=-1,z=-1,w=-1;
	for(int i=0;i<n;i++)
	{
		if(i%2==0)
		{
			if(arr1[arr[i]]>x)
			{
				x=arr1[arr[i]];
				a=i;
			}
		}
		else 
		{
			if(arr2[arr[i]]>y)
			{
				y=arr2[arr[i]];
				b=i;
			}
		}
	}
	if(arr[a]!=arr[b]){
        cout<<n-x-y;
    }
    else 
    {
    	for(int i=0;i<n;i++)
    	{
    		if(i%2==0)
    		{
    			if(arr1[arr[i]]>z&&arr[i]!=arr[a])
    			{
    				z=arr1[arr[i]];
    			}
    		}
    		else
    		{
    			if(arr2[arr[i]]>w&&arr[i]!=arr[b])
    			{
    				w=arr2[arr[i]];
    			}
    		}
    	}
    	if(z<=0 && w <=0){
            cout<<n/2;
        }
        else 
        {
        	 if(x+w>=y+z){
                cout<<n-x-w;
            }else{
                cout<<n-y-z;
            }
        }
    }
	return 0;
}

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

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

ll pr[N];

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    map<int, int> cnt;
    ll ans = 0;
    cnt[0]++;
    for (int i = 1, a; i <= n; i++){
        if (i >= k){
            cnt[pr[i-k]-(i-k)]--;
        }
        cin >> a;
        pr[i] = (pr[i-1]+a) % k;
        ans += cnt[pr[i]-i] + cnt[pr[i]-i+k];
        cnt[pr[i]-i]++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 20608
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
  int h, n;
  cin >> h >> n;
  int a[100010];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }

  if (sum >= h) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <functional>
#include <cstring>
#include <queue>
#include <cmath>
#include <deque>
#include <list>
#include <iomanip>
#include <fstream>
#include <string>
#include <iterator>
#include <set>
#include <bitset>
using namespace std;

typedef long double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const int MAXN = 100007;
const int MOD = 1000000007;
const int INF = 1000000000;
const LL LINF = INF * (LL)INF;
const LD PI = acos(-1.0);

int A[MAXN];

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	//freopen("hear.in", "r", stdin);
	//freopen("hear.out", "w", stdout);
	int n, l, p = -1;
	LL s = 0, s1;
	cin >> n >> l;
	REP(i, n)
		cin >> A[i];
	REP(i, n - 1) if (A[i] + A[i + 1] >= l) p = i;
	if (p == -1)
	{
		cout << "Impossible";
		return 0;
	}
	cout << "Possible" << endl;
	REP(i, p) cout << i + 1 << endl;
	RFOR(i, n - 1, p) cout << i + 1 << endl;
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n==25){
		cout<<"Christmas"<<endl;
	}else if(n==24){
		cout<<"Christmas Eve"<<endl;
	}else if(n==23){
		cout<<"Christmas Eve Eve"<<endl;
	}else{
		cout<<"Christmas Eve Eve Eve"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int a,b;
int main()
{
	string s,t,u;
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if(s==u) a--;
	else b--;
	cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 500;
const ll INF = ll(1E18);
int A[MAXN + 5][MAXN + 5], B[MAXN + 5][MAXN + 5], n;
ll SA[MAXN + 5][MAXN + 5], SB[MAXN + 5][MAXN + 5];
ll dp[2][MAXN + 5][MAXN + 5], f[2][MAXN + 5], g[2];
int main() {
    scanf("%d", &n);
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=i-1;j++) scanf("%d", &B[j][i-1]); // i -> j (i > j)
        for(int j=i+1;j<=n;j++) scanf("%d", &A[i][j-1]);
    }
    for(int j=1;j<=n;j++)
        for(int i=1;i<=n;i++)
            SA[i][j] = A[i][j] + SA[i-1][j], SB[i][j] = B[i][j] + SB[i-1][j];
    n--;
    for(int j=1;j<=n;j++) {
        for(int k=j+1;k<=n;k++)
            dp[0][j][k] = INF;
        f[0][j] = INF;
    }
    g[0] = 0;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<i;j++) {
            for(int k=j+1;k<i;k++)
                dp[1][j][k] = dp[0][j][k], dp[0][j][k] = INF;
            f[1][j] = f[0][j], f[0][j] = INF;
        }
        g[1] = g[0], g[0] = INF;
        for(int j=1;j<i;j++) {
            for(int k=j+1;k<i;k++) {
                dp[0][j][k] = min(dp[0][j][k], dp[1][j][k] + SA[i][i] - SA[k][i] + SB[j][i]);
                dp[0][k][i] = min(dp[0][k][i], dp[1][j][k] + SB[k][i]);
            }
            f[0][j] = min(f[0][j], f[1][j] + SA[i][i] - SA[j][i]);
            dp[0][j][i] = min(dp[0][j][i], f[1][j] + SB[j][i]);
        }
        g[0] = min(g[0], g[1] + SA[i][i]);
        f[0][i] = min(f[0][i], g[1]);
    }
    ll mn = INF;
    for(int j=1;j<=n;j++) {
        for(int k=j+1;k<=n;k++)
            mn = min(mn, dp[0][j][k]);
        mn = min(mn, f[0][j]);
    }
    mn = min(mn, g[0]);
    printf("%lld\n", mn);
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int& x: h) cin >> x;
    vector<ll> dp(n, LLONG_MAX);
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
	for(int j = i+1; j <= i + k; j++) {
	    if(j < n) {
		dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
	    }
	}
    }
    cout << dp[n-1] << endl;
    return 0;
}


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

const int N = 110000;
const long long INF = 1LL << 60;

int L[N], R[N], C[N];
long long val[N];

vector<int> st[N], en[N];

set<pair<long long, int>> S;

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n, m; cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> L[i] >> R[i] >> C[i];
		st[L[i]].push_back(i);
		en[R[i]].push_back(i);
	}
	
	for (int i = 1; i <= n; i++) val[i] = INF;
	val[1] = 0;
	for (int i = 1; i <= n; i++) {
		if (S.size()) val[i] = min(val[i], S.begin() -> first);
		for (auto it : st[i]) S.emplace(val[L[it]] + C[it], it);
		for (auto it : en[i]) S.erase(make_pair(val[L[it]] + C[it], it));
	}
	if (val[n] == INF) cout << "-1\n";
	else cout << val[n] << "\n";
	
	return 0;
}


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

ll place[6];

int main(void){
    ll n;
    ll a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    ll ans = max({(n-1)/a,(n-1)/b,(n-1)/c,(n-1)/d,(n-1)/e})+ 5;
    cout << ans <<endl;
    
    return 0;
}






































Measured memory_bytes: 256
#ABC087-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())

class WeightedUnionFind:
    def __init__(self, size):
        """
        :param collections.Iterable nodes:
        """
        self._parents = [i for i in range(size)]
        self._ranks = [0 for _ in range(size)]
        self._sizes = [1 for _ in range(size)]
        # 直近の親からの重み。root なら 0
        self._weights = [0 for _ in range(size)]
 
    def unite(self, x, y, w):
        """
        x が属する木と y が属する木を併合
        :param x:
        :param y:
        :param w: x と y の重みの差; (重み y) - (重み x)
        :return:
        """
        rx = self.find(x)
        ry = self.find(y)
        if rx == ry:
            return
 
        # rank が小さい方が下
        if self._ranks[rx] > self._ranks[ry]:
            # x が root
            self._parents[ry] = rx
            self._sizes[rx] += self._sizes[ry]
            # root 間の重みに変換
            self._weights[ry] = w + self._weights[x] - self._weights[y]
        else:
            # y が root
            self._parents[rx] = ry
            self._sizes[ry] += self._sizes[rx]
            # root 間の重みに変換
            self._weights[rx] = -w + self._weights[y] - self._weights[x]
            if self._ranks[rx] == self._ranks[ry]:
                self._ranks[ry] += 1
 
    def find(self, x):
        """
        x が属する木の root
        :param x:
        :return:
        """
        if self._parents[x] == x:
            return x
        root = self.find(self._parents[x])
        self._weights[x] += self._weights[self._parents[x]]
        self._parents[x] = root
        return root
 
    def size(self, x):
        """
        x が属する木のノード数
        :param x:
        :return:
        """
        return self._sizes[self.find(x)]
 
    def weight(self, x):
        """
        :param x:
        :return:
        """
        # 経路圧縮
        self.find(x)
        return self._weights[x]
 
    def diff(self, x, y):
        """
        (y の重み) - (x の重み)
        :param x:
        :param y:
        :return:
        """
        if self.find(x) == self.find(y):
            return self._weights[y] - self._weights[x]
        return float('inf')
    
    def is_same(self,x,y):
        if self.find(x) == self.find(y):
            return True
        else:
            return False
        
n,m=IL()
UF=WeightedUnionFind(n)
for i in range(m):
    l,r,d=IL()
    if UF.is_same(l-1,r-1) and UF.diff(l-1,r-1)!=d:
        print("No")
        break
    UF.unite(l-1,r-1,d)
else:
    print("Yes")

Measured memory_bytes: 10812
n = int(input())
t, a = map(int,input().split())
h = list(map(int,input().split()))
b = []
for i in range(n):
    d = abs((t - 0.006 * h[i]) - a)
    b.append(d)
j = min(b)
print((b.index(j)) + 1)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
  int n;
  int a[2][109];
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[0][i]);
  }
  for(int i=0;i<n;i++){
    scanf("%d",&a[1][i]);
  }

  int g=0;
  int h[109];
  for(int i=0;i<n;i++){
    g=g+a[0][i];
    h[i]=g;
  }

  int gx=0;
  int hx[109];
  for(int i=n-1;0<=i;i--){
    gx=gx+a[1][i];
    hx[i]=gx;
  }


  int ans=0;
    
  for(int i=0;i<n;i++){
    if(h[i]+hx[i]>ans){
      ans=h[i]+hx[i];
    }
  }
  printf("%d\n",ans);
  
  return 0;
}
  

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

using namespace std;
using ll = long long;
const int INF = 1001001001;

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

    vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));

    for (int i=0;i<n;++i) {
        for (int j=0;j<=k;++j) {
            if (w[i] > j) dp[i + 1][j] = dp[i][j];
            else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
        }
    }
    cout << dp[n][k] << endl;
}

Measured memory_bytes: 80256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    int n, a, x = -1, y = -1;
    map<int, int> A;

    cin >> n;
    for (int i=0; i<n; i++) {
        scanf("%d", &a);
        if (A[a] < 5)   A[a]++;
        //cout << a << " " << A[a] << endl; 
        if (A[a] >= 2) {
            if (a > x) {
                y = x;
                x = a;
                A[a] -= 2;
            }
            else if (a > y) {
                y = a;
                A[a] -= 2;
            }
        }
    }

    if (y == -1)    cout << 0 << endl;
    else            cout << (long long int)x * (long long int)y << endl;

    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int, int>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}


int main() {
  int Q; cin >> Q;
  vector<int> l(Q), r(Q); REP(i, Q) cin >> l[i] >> r[i];
  vector<int> ans(100000, 0);
  for(int i = 1; i < 100000; i += 2) {
    int k = (i + 1) / 2;
    if(IsPrime(i) && IsPrime(k)) ans[i] = 1;
  }
  REP(i, 100000) ans[i] += ans[i - 1];
  REP(i, Q) {
    cout << ans[r[i]] - ans[l[i] - 1] << endl;
  }
}

Measured memory_bytes: 4588
// AOJ 2825: Quiz
// 2017.12.7 bal4u@uu

#include <stdio.h>
#include <string.h>

int max[10002], min[10002];

char buf[60000], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int n, m, s, k, c, i, pmin, pmax;

	while (fgets(p=buf, 20, stdin) && *p != '0') {
		n = getint(), m = getint();
		memset(min, 0, sizeof(min));
		memset(max, 0, sizeof(max));

		for (i = 0; i < m; i++) {
			fgets(p=buf, 60000, stdin);
			s = getint();
			k = getint();
			if (k == 1) min[c = getint()] += s, max[c] += s;
			else while (k--) max[getint()] += s;
		}

		pmax = -1;
		for (i = 1; i <= n; i++) if (max[i] > pmax) pmax = max[i], c = i;

		pmin = 0x7fffffff;
		for (i = 1; i <= n; i++) if (i != c && min[i] < pmin) pmin = min[i];

		printf("%d\n", pmax - pmin + 1);
	}
	return 0;
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string s; cin >> s;
    int k; cin >> k;

    set<string> st;
    vector<vector<string>> v(5);

    REP(i,min((int)s.size(),5)) {

        if (i == 0) {
            char c = 'a';
            while(c <= 'z' && v[i].size() < 5) {
                string tmp(1,c);
                if (s.find(tmp) != string::npos) {
                    v[i].push_back(tmp);
                    st.insert(tmp);
                }
                c++;
            }
        } else {
            for(auto ss:v[i-1]) {
            char c = 'a';
                while(c <= 'z' && v[i].size() < 5) {
                    string tmp = ss + c;
                    if (s.find(tmp) != string::npos) {
                        v[i].push_back(tmp);
                        st.insert(tmp);
                    }
                    c++;
                }
            }
        }
        //cerr << st.size() << endl;
    }

    auto it = st.begin();
    REP(i,k-1) it++;
    OUT(*it);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i, n) for(int i = 1; i <= (n); i ++)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar();bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
const int N = 5000 + 233;
int n, k, a[N], sum = 0, t;
int b[N][N];
inline bool check(int up, int mid) {
  if(mid <= 0) return 0;
  if(mid > n) return 1;
  memset(b, 0, sizeof b);
  b[0][0] = 1;
  for(int i = 1; i <= n; i ++) {
    memcpy(b[i], b[i - 1], sizeof b[i]);
    if(i != mid) {
      for(int v = 0; v < k; v ++)
	if(v + a[i] < k && b[i - 1][v])
	  b[i][v + a[i]] = 1;
    }
  }
  for(int i = max(k - up, 0); i < k; i ++)
    if(b[n][i])
      return 1;
  return 0;
}

main(void) {
  read(n); read(k);
  fo(i, n) read(a[i]);
  sort(a + 1, a + n + 1);
  for(int i = n; i >= 1; i --) {
    if(sum + a[i] < k) sum += a[i], t ++;
    else t = 0;
  }
  cout << t << "\n";;
}


Measured memory_bytes: 256
/*************************************************************************

       Author:            palayutm
       Created Time :     Sat 18 Feb 2017 08:08:19 PM CST

       File Name:         d.cc
       Description:       new style, new life

 ************************************************************************/
#include <bits/stdc++.h>

using namespace std;

int a[100005];
string s;

bool check (int n)
{
  for (int i = 2; i < n; i ++) {
    a[i] = (a[i-1] ^ (s[i-1] == 'o') ^ a[i-2]);
  }
  return a[0] == (a[n-1] ^ (s[n-1] == 'o') ^ a[n-2])
    && a[1] == (a[0] ^ (s[0] == 'o') ^ a[n-1]);
}

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;
  cin >> s;
  for (int i = 0; i < 2; i ++) {
    for (int j = 0; j < 2; j ++) {
      a[0] = i, a[1] = j;
      if (check(n)) {
        for (int i = 0; i < n; i++) {
          putchar(a[i] ? 'S' : 'W');
        }
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}



Measured memory_bytes: 896
let n, k = stdin.ReadLine().Split() |> fun array -> int array.[0], int array.[1]
let pArray = stdin.ReadLine().Split() |> Array.map int

// まずは一列ごとに期待値を求め、その後chunkごとの足し算（畳みこんで、計算量を節約する）を行い、最後にmaxをもとめる
let expArray =
    pArray
    |> Array.map (fun p -> float (1 + p) / 2.0 )

let totalSeq =
    Seq.unfold (
            fun (i,totalBefore) ->
                if i = 0 then
                    let total = Seq.sum expArray.[0..k-1]
                    Some( total, (i + 1, total) )
                elif i = n - k + 1 then
                    None
                else
                    let total = totalBefore - expArray.[i-1] + expArray.[i+k-1]
                    Some( total, (i+1, total))
        )
        (0, 0.0)

totalSeq
|> Seq.max
|> stdout.WriteLine


Measured memory_bytes: 34396
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 998244353, N = 1e5 + 10; 

int val[N];

ll power(ll x, ll y){
   ll ans=1;
   if(y==1) return x%MOD;
   x=x % MOD,y=y % (MOD-1);
   while(y){
      if(y & 1) ans = (ans*x) %MOD;
      x *= x;
      x = x % MOD;
      y >>= 1;
   }
   return ans;
}
 
ll inv(ll x){
   return power(x,MOD-2);
}

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   int mx = 0;
   map<int,int> cnt;
   f(i,1,n+1){
      cin >> val[i];
      mx = max(mx,val[i]);
      cnt[val[i]]++; 
   }
   f(i,0,mx+1){
      if(!cnt[i]){
         cout << "0\n";
         return 0;
      }
   }
   if(cnt[0]!=1){
      cout << "0\n";
      return 0;
   }
   if(val[1]!=0){
      cout << "0\n";
      return 0;
   }
   int ans = 1;
   f(i,1,mx+1){
      // cout << val[i-1] << ' ' << val[i] << '\n';
      ans = ans*power(cnt[i-1],cnt[i]);
      ans = ans%MOD;
   }
   cout << ans << '\n';
   return 0;
}


Measured memory_bytes: 7296
S = input()

acgt = ["A","C","G","T"]

ans = 0
ok = False
tmp = 0
for s in S:
    if not ok:
        if s in acgt:
            ok = True
            tmp += 1
        else:
            pass
    elif ok:
        if s in acgt:
            tmp += 1
        else:
            ok = False
            ans = max(tmp,ans)
            tmp = 0
ans = max(tmp,ans)
print(ans)

Measured memory_bytes: 38256
var max = "";
var map = {};

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(input) {
  input = input.replace("\n", "");
  var arr = input.split(" ");
  for (var i in arr) {
    if (map[arr[i]] === undefined || map[arr[i]] === null) {
      map[arr[i]] = 0;
    } else {
      map[arr[i]]++;
    }
    if(max.length<arr[i].length) max = arr[i];
  }
});
process.stdin.on('end', function() {
  var keys = Object.keys(map);
  var m = keys.pop();
  for (var k in keys) {
    k = keys[k];
    if(map[m]<map[k]) m = k;
  }
  console.log(m, max);
});

Measured memory_bytes: 7644
N,S = map(int,input().split())
A = list(map(int,input().split()))

MOD = 998244353

dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += dp[i][j] * 2 % MOD
        if j - A[i] >= 0:
            dp[i+1][j] += dp[i][j-A[i]]
        dp[i+1][j] %= MOD
        
print(dp[N][S])

Measured memory_bytes: 132632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, w;
  cin >> n >> w;
  vll ww(n), v(n);
  for (ll i = 0; i < n; i++) cin >> ww[i] >> v[i];

  vector<vll> dp(n, vll(w + 1));
  for (ll i = 0; i <= w; i++) {
    if (i < ww[0]) dp[0][i] = 0;
    else dp[0][i] = v[0];
  }
  for (ll i = 1; i < n; i++) {
    dp[i] = dp[i - 1];
    for (ll j = 1; j <= w; j++) {
      if (j >= ww[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j - ww[i]] + v[i]);
    }
  }
  cout << dp[n - 1][w] << endl;
}

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//

void solve(long long N) {
  cout << ceil((double)(N)/2) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long N;
  std::cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 3772
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;
#define y1        y114514
#define pb        push_back
#define mkp       make_pair
#define fi        first
#define se        second
#define all(a)    a.begin(), a.end()
#define add(a, b) a = (a + b) % M
#define del(a, b) a = (a - (b) + M) % M

typedef pair<int, int>     pii;
typedef unsigned long long ull;
typedef long long          ll;

const int M = 998244353;

int dp[3005][3005];

int main() {
    int A, B, C, D;
    scanf("%d%d%d%d", &A, &B, &C, &D);
    dp[A][B] = 1;
    for (int i = A; i <= C; ++i)
        for (int j = B; j <= D; ++j) {
            if (i > A) add(dp[i][j], (ll)dp[i - 1][j] * j);
            if (j > B) add(dp[i][j], (ll)dp[i][j - 1] * i);
            if (i > A && j > B) del(dp[i][j], (ll)dp[i - 1][j - 1] * (i - 1) % M * (j - 1) % M);
        }
    printf("%d\n", dp[C][D]);
    return 0;
}


Measured memory_bytes: 36852
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

ll n;
int p2=0,p4=0;

int main(){
	cin>>n;
	REP(i,n){
		int t;
		cin>>t;
		if(t%4==0){
			p4++;
		}else if(t%2==0){
			p2++;
		}
	}
	if(n/2<=p4){
		cout<<"Yes"<<endl;
		return 0;
	}
	n-=p4*2;
	if(n<=p2){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,d,x;
    cin >> n >> d >>x ;
    ll a[n];
    F0R(i,n) cin >> a[i];
    ll sum = 0;
    F0R(i,n){
      sum += (d-1)/a[i] + 1;
    }
    cout << sum + x<<endl;


    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

string edit(char x, string y)
{
    if (x == '0' || x == '1')
    {
        y += x;
    }
    else if (y.size() > 0)
    {
        y.erase(y.size() - 1);
    }

    return y;
}

int main()
{
    string s;
    cin >> s;
    string ans = "";
    for (int i = 0; i < s.size(); i++)
    {
        char c;
        c = s.at(i);
        ans = edit(c, ans);
    }

    cout << ans << endl;
    return 0;
}

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

int main() {
  string s,t;
  cin >> s >> t;
  vector<vector<int>> dp(s.size()+1,vector<int>(t.size()+1));
  dp.at(0).at(0)=0;
  for(int i=0;i<s.size();i++) {
    for(int j=0;j<t.size();j++) {
      dp.at(i+1).at(j+1)=max(dp.at(i+1).at(j+1),dp.at(i).at(j+1));
      dp.at(i+1).at(j+1)=max(dp.at(i+1).at(j+1),dp.at(i+1).at(j));
      if(s.at(i)==t.at(j)) {
        //cout << i+1 << " " << j+1 << " " << dp.at(i+1).at(j+1) << endl;
        dp.at(i+1).at(j+1)=max(dp.at(i+1).at(j+1),dp.at(i).at(j)+1);
      }
    }
  }
  //cout << dp.at(s.size()).at(t.size()) << endl;
  string ans="";
  int i=s.size(),j=t.size();
  while(i>0&&j>0) {
    if(dp.at(i).at(j)==dp.at(i-1).at(j)) {
      i--;
    }
    else if(dp.at(i).at(j)==dp.at(i).at(j-1)) {
      j--;
    }
    else {
      ans=s.at(i-1)+ans;
      i--;
      j--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 35584
import java.util.Scanner;

public class Main {
    public Scanner in=new Scanner(System.in);
    public int[] inputNum=new int[4];
    public String outputNum;

    public static void main(String args[]){
        Main m=new Main();

        int iii=m.in.nextInt();

        m.inputNum[0]=iii/1000;
        m.inputNum[1]=(iii/100)%10;
        m.inputNum[2]=(iii/10)%10;
        m.inputNum[3]=iii%10;


        if(m.inputNum[0]+m.inputNum[1]+m.inputNum[2]+m.inputNum[3]==7){
            System.out.println(m.inputNum[0]+"+"+m.inputNum[1]+"+"+m.inputNum[2]+"+"+m.inputNum[3]+"=7");
            return;
        }
        if(m.inputNum[0]+m.inputNum[1]+m.inputNum[2]-m.inputNum[3]==7){
            System.out.println(m.inputNum[0]+"+"+m.inputNum[1]+"+"+m.inputNum[2]+"-"+m.inputNum[3]+"=7");
            return;
        }
        if(m.inputNum[0]+m.inputNum[1]-m.inputNum[2]+m.inputNum[3]==7){
            System.out.println(m.inputNum[0]+"+"+m.inputNum[1]+"-"+m.inputNum[2]+"+"+m.inputNum[3]+"=7");
            return;
        }
        if(m.inputNum[0]+m.inputNum[1]-m.inputNum[2]-m.inputNum[3]==7){
            System.out.println(m.inputNum[0]+"+"+m.inputNum[1]+"-"+m.inputNum[2]+"-"+m.inputNum[3]+"=7");
            return;
        }
        if(m.inputNum[0]-m.inputNum[1]+m.inputNum[2]+m.inputNum[3]==7){
            System.out.println(m.inputNum[0]+"-"+m.inputNum[1]+"+"+m.inputNum[2]+"+"+m.inputNum[3]+"=7");
            return;
        }
        if(m.inputNum[0]-m.inputNum[1]+m.inputNum[2]-m.inputNum[3]==7){
            System.out.println(m.inputNum[0]+"-"+m.inputNum[1]+"+"+m.inputNum[2]+"-"+m.inputNum[3]+"=7");
            return;
        }
        if(m.inputNum[0]-m.inputNum[1]-m.inputNum[2]+m.inputNum[3]==7){
            System.out.println(m.inputNum[0]+"-"+m.inputNum[1]+"-"+m.inputNum[2]+"+"+m.inputNum[3]+"=7");
            return;
        }
        if(m.inputNum[0]-m.inputNum[1]-m.inputNum[2]-m.inputNum[3]==7){
            System.out.println(m.inputNum[0]+"-"+m.inputNum[1]+"-"+m.inputNum[2]+"-"+m.inputNum[3]+"=7");
            return;
        }
    }
}


Measured memory_bytes: 25172
#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * ceil_(a, b)); }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

signed main() {
  int n;
  cin >> n;
  while (n != 0) {
    int ans = 0;
    n = 1000 - n;
    ans += n / 500;
    n -= (n / 500) * 500;
    ans += n / 100;
    n -= 100 * (n / 100);
    ans += n / 50;
    n -= 50 * (n / 50);
    ans += n / 10;
    n -= 10 * (n / 10);
    ans += n / 5;
    n -= 5 * (n / 5);
    ans += n;
    cout << ans << endl;
    cin >> n;
  }
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define N 114514
#define mod 1000000007
ll gya(ll n,ll p,ll m){
	ll b=1;
	while(p){
		if(p%2)b=(b*n)%m;
		n=(n*n)%m;
		p/=2;
	}
	return b;
}

ll per[N],be[N];
void init(ll n){
	per[0]=per[1]=be[0]=be[1]=1;
	for(int i=2;i<=n;i++){
		per[i]=i*per[i-1];
		per[i]%=mod;
		be[i]=gya(per[i],mod-2,mod);
	}
}
ll comb(ll n,ll r){
	ll x=per[n]*be[r]%mod*be[n-r]%mod;
	return x;
}

int main(){
	ll n,l,r;
	cin>>n;
	init(n+1);
	map<ll,ll>mp,num;
	for(int i=1;i<=n+1;i++){
		ll a;
		cin>>a;
		mp[a]++;
		if(mp[a]==2){
			l=num[a];
			r=i;
		}
		num[a]=i;
	}
	for(int i=1;i<=n+1;i++){
		ll x=0;
		if(n-r+l>=i-1)x=mod-comb(n-(r-l),i-1);
		ll ans=(comb(n+1,i)+x)%mod;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 17592
N,X = map(int, input().strip().split(' '))
A = [0] + list(map(int, input().strip().split(' ')))
cost = 0
for i in range(N):
  if A[i] + A[i+1] > X:
    cost += A[i+1]-(X-A[i])
    A[i+1] = X-A[i]
print(cost)

Measured memory_bytes: 63708
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{ 
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nm = Input.ar;
        var ks = Input.ar2D(nm[1]);
        var p = Input.ar;var res = 0;
        for(var i = 0; i < (1 << nm[0]); i++)
        {
            var q = new bool[nm[0]];
            for (var j = 0; j < nm[0]; j++)
                if ((1 & i >> j) == 1)
                    q[j] = true;
            for (var k = 0; k < nm[1]; k++)
            {
                var ct = 0;
                for (var h = 1; h <= ks[k][0]; h++)
                {
                    if (q[ks[k][h] - 1])
                        ct++;
                }
                if (ct % 2 != p[k]) goto END;
            }
            res++;
                        END:;
        }
        WriteLine(res);
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13524
function Main(input){
  input = input.split(' ');
  var r = input[0];
  var g = input[1];
  var b = input[2];
  var rgb = Number(r + g + b);


  if( rgb % 4 === 0) {
      console.log('YES');
  } else {
      console.log('NO');
  }

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)
     cin>>a[i];
  sort(a,a+n);
  int ans=0;
   for(int i=0;i<k;i++)
      ans+=a[i];
    cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632
inp1, inp2 = map(int,input().split())
list = list(map(int,input().split()))
list.sort(reverse = True)
if list[inp2-1] >= (sum(list))/ (inp2 * 4):
    print("Yes")
elif list[inp2-1] < (sum(list))/ (inp2 * 4):
    print("No")

Measured memory_bytes: 9184
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

class SegmentTree:
    def __init__(self, N, func, I):
        self.func = func
        self.I = I
        self.sz = 2**(N-1).bit_length()
        self.seg = [I] * (self.sz * 2)
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k >>= 1
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = self.I
        R = self.I
        a += self.sz
        b += self.sz
        while a < b:
            if a & 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b & 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a >>= 1
            b >>= 1
        return self.func(L, R)

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def main():
    N = int(readline())
    L = list(map(int,read().split()))
    seg = SegmentTree(N , gcd , 0)
    for i,n in enumerate(L):
        seg.assign(i , n)
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()


Measured memory_bytes: 54308
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
 ll n,x ;
 cin>> n>>x ;
 ll k=gcd(n,x) ;
 cout <<3*n-3*k<<endl ;

   return 0;
}

Measured memory_bytes: 256
import math
(a, b, C) = [int(i) for i in input().split()]

S = (a * b * math.sin(math.radians(C))) / 2
L = a + b + math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(C)))
h = b * math.sin(math.radians(C))

print('{0:.4f}\n{1:.4f}\n{2:.4f}'.format(S,L,h))

Measured memory_bytes: 6868
n,m=map(int,input().split())
l=list(map(int,input().split()))
ans=n
while 1:
  hoge=list(str(ans))
  flag=0
  for i in range(len(l)):
    flag+=hoge.count(str(l[i]))
  if(flag==0):
    print(ans)
    exit()
  ans+=1


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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n, x; cin>>n>>x;
    if(x==1 || x==2*n-1){
        cout << "No" << endl;
        return 0;
    }

    vector<int> ans(2*n, 0);
    vector<bool> num(2*n, false);
    cout << "Yes" << endl;
    if(n==2){
        for(int i=1; i<=3; i++) cout << i << endl;
    }
    else{
        if(x==2){
            ans[n-1]=x+1, ans[n]=x, ans[n+1]=x-1, ans[n+2]=x+2;
            num[x+1]=num[x]=num[x-1]=num[x+2]=true;
        }
        else{
            ans[n-1]=x-1, ans[n]=x, ans[n+1]=x+1, ans[n+2]=x-2;
            num[x-1]=num[x]=num[x+1]=num[x-2]=true;
        }
        int cnt=1;
        for(int i=1; i<=2*n-1; i++){
            if(!num[i]){
                ans[cnt++]=i;
                if(cnt==n-1) cnt=n+3;
            }
        }
        for(int i=1; i<=2*n-1; i++) cout << ans[i] << endl;
    }
}

Measured memory_bytes: 2304