akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

template<typename Monoid,typename OperatorMonoid,typename F,typename G,typename H>
struct Segtree{
	int size=1;
	vector<Monoid>dat;
	vector<OperatorMonoid>lazy;
	const F f;
	const G g;
	const H h;
	Monoid M;
	OperatorMonoid OM;
	void set(int a,Monoid x){
		dat[a+size-1]=x;
	}
	void init(){
		for(int i=size-2;i>=0;i--){
			dat[i]=f(dat[i*2+1],dat[i*2+2]);
		}
	}
	void eval(int k,int l,int r){
		if(lazy[k]!=OM){
			dat[k]=g(dat[k],lazy[k],(r-l));
			if(r-l>1){
				lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
				lazy[2*k+2]=h(lazy[2*k+2],lazy[k]);
			}
			lazy[k]=OM;
		}
	}
	void update(int a,int b,OperatorMonoid M,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]=h(lazy[k],M);
			eval(k,l,r);
			return;
		}
		update(a,b,M,k*2+1,l,(l+r)/2);
		update(a,b,M,k*2+2,(l+r)/2,r);
		dat[k]=f(dat[k*2+1],dat[k*2+2]);
	}
	Monoid query(int a,int b,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l)return M;
		if(a<=l&&r<=b)return dat[k];
		Monoid lv=query(a,b,k*2+1,l,(l+r)/2);
		Monoid rv=query(a,b,k*2+2,(l+r)/2,r);
		return f(lv,rv);
	}
	template<class C>
	int minLeft(int a,int b,C &check,Monoid x,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l||!check(dat[k],x))return -1;
		if(r-l==1)return l;
		int lv=minLeft(a,b,check,x,k*2+1,l,(l+r)/2);
		if(lv!=-1)return lv;
		return minLeft(a,b,check,x,k*2+2,(l+r)/2,r);
	}
	template<class C>
	int maxRight(int a,int b,C &check,Monoid x,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l||!check(dat[k],x))return -1;
		if(r-l==1)return l;
		int rv=maxRight(a,b,check,x,k*2+2,(l+r)/2,r);
		if(rv!=-1)return rv;
		return maxRight(a,b,check,x,k*2+1,l,(l+r)/2);
	}
	Segtree(int x,F f,G g,H h,Monoid M,OperatorMonoid OM)
	:f(f),g(g),h(h),M(M),OM(OM){
		while(size<x)size*=2;
		dat.resize(size*2-1,M);
		lazy.resize(size*2-1,OM);
	}
};

struct S{
	int zero,one,inv;
};
auto f=[](S a,S b)->S{return {a.zero+b.zero,a.one+b.one,a.inv+b.inv+a.one*b.zero};};
auto g=[](S a,int b,int sz)->S{return {a.one,a.zero,a.one*a.zero-a.inv};};
auto h=[](int a,int b)->int{return a^b;};
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N,Q;
	cin>>N>>Q;
	Segtree<S,int,decltype(f),decltype(g),decltype(h)>segtree(N,f,g,h,{0,0,0},0);
	rep(i,N){
		int a;cin>>a;
		if(a==0)segtree.set(i,{1,0,0});
		else segtree.set(i,{0,1,0});
	}
	segtree.init();
	while(Q--){
		int T,L,R;cin>>T>>L>>R;L--;
		if(T==1)segtree.update(L,R,1);
		else cout<<segtree.query(L,R).inv<<"\n";
	}
}

Measured memory_bytes: 19548
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;


int main() 
{
    int n; cin >> n;
    int a[n];
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 1; i < n-1; i++){
        if(a[i] != max({a[i-1],a[i],a[i+1]}) && a[i] != min({a[i-1],a[i],a[i+1]})){
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define isUruu(y) ((y % 4 || (y % 100 == 0 && y % 400)) ? false : true)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef unsigned int uint;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<char> Vc;
typedef vector<Vc> VVc;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

const int INF = 1 << 28;
const double EPS = 1e-9;
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};

int w, h;
int ans;

void dfs (VVc &field, vector<P> &pp, int sx, int sy, uint b, int sum)
{
    if (b == ((1 << pp.size()) - 1)) {
        if (ans > sum) ans = sum;
        return ;
    }
    if (sum > ans) return ;
    rep (j, pp.size()) {
        if (b & (1 << j)) continue;
        queue<P> q;
        q.push(P(sx,sy));
        VV d(h, V(w, INF));
        d[sx][sy] = 0;
        int count = 0;
        while (q.size()) {
            P p = q.front(); q.pop();
            int x = p.first, y = p.second;
            if (x == pp[j].first && y == pp[j].second) {
                count = d[x][y];
                break;
            }
            
            rep (i,4) {
                int nx = x + dx[i], ny = y + dy[i];
                if (0 <= nx && nx < h && 0 <= ny && ny < w && d[nx][ny] == INF && field[nx][ny] != 'x') {
                    d[nx][ny] = d[x][y] + 1;
                    q.push(P(nx,ny));
                }
            }
        }
        if (count == 0) return ;
        dfs(field, pp, pp[j].first, pp[j].second, b | (1 << j), sum + count);
    }
    
    return ;
}

int main()
{
    while (cin >> w >> h, h + w) {
        VVc field(h, Vc(w));
        vector<P> p;
        int sx,sy;
        rep (i,h) rep (j,w) {
            cin >> field[i][j];
            if (field[i][j] == 'o') sx = i, sy = j;
            else if (field[i][j] == '*') p.push_back(P(i,j)); 
        }

        ans = INF;
        dfs(field, p, sx, sy, 0, 0);
        
        cout << (ans == INF ? -1 : ans) << endl;
    }
                
    return 0;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
using namespace std;
#define ll long long

const ll nax=1e18;

bool is_prime(ll n)
{
 ll i;
    if(n==1
       ) return false;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0) return false;
    }
    return true;
}


void solve()
{
    ll n,i;
    cin>>n;
    ll cnt=0;
    ll p=n,k;
    map<ll,ll>mp;
    for(i=2;i*i<=p;i++)
    {
     if(n%i==0)
     {ll k=i;
        while(n%k==0)
        {
            cnt++;
            n/=k;
            mp[k]++;
            k*=i;
        }
      while(n%i==0)n=n/i;
     }
     
    }
    if(is_prime(n)&&!mp[n])cnt++;
    cout<<cnt<<endl;
}

int main()
{
 int t=1;
  //  cin>>t; 
    
    while(t--)
     solve();   
    
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void){

	int S,h,m,n;

	scanf("%d",&S);
	h=S/3600;
	m=(S-h*3600)/60;
	n=S-h*3600-m*60;

	printf("%d:%d:%d\n",h,m,n);

	return 0;

}

Measured memory_bytes: 1800
X, N = list(map(int, input().split()))

p = list(map(int, input().split()))

count_up= 0
count_down = 0
while True:
  if not X + count_up in p:
    break
  count_up += 1
    
while True:
  if not X - count_down in p:
    break
  count_down += 1

if count_up < count_down:
  print(X+count_up)
else:
  print(X-count_down)

Measured memory_bytes: 9092
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
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 dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
struct union_find{
	vector<int> par, sizes;
	union_find(int n): par(n), sizes(n, 1) {
		for (int i = 0; i < n; ++i) {
			par[i] = i;
		}
	}
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x,int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;

		if (sizes[x] > sizes[y]) std::swap(x, y);
		par[x] = y;
		sizes[y] += sizes[x];
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sizes[find(x)];
	}
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    vector<ll> ans;
    for (int i = 0; i < m; ++i) {
        cin >> a[m-1-i] >> b[m-1-i];
		--a[m-1-i];
		--b[m-1-i];
    }
    ans.push_back( n * (n - 1LL) / 2);
    union_find uf(n);
    for (int i = 0; i < m; ++i) {  
		if(uf.same(a[i],b[i])) ans.push_back(ans[i]);
        else ans.push_back(ans[i] - uf.size(a[i])*uf.size(b[i]));
		uf.unite(a[i], b[i]);
	}
    for (size_t i = ans.size()-1; i--;) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3828
#ifdef __GNUC__ 
#include <bits/stdc++.h>
auto & in = std::cin;
#else
std::istringstream in;
#endif
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/dynamic_bitset.hpp>
#include <boost/preprocessor.hpp>

using namespace std;
#define ALL(v) std::begin(v),std::end(v)
using u6 = std::uint64_t;
using u3 = std::uint32_t;
constexpr u6 moduloNo = 1'000'000'000 + 7; //' 1e9 + 7
constexpr u3 maxA = 0x10'0000;//'
// (u6,N,M)
// (string s,s)

#define GENINIT_FN_OP(s,state,valname) state >> valname
#define GENINIT_FN(s,state,valname) s

#define DEFVAL1(r,type,name) type name; 
#define DEFVALS(tpl) BOOST_PP_SEQ_FOR_EACH(DEFVAL1,BOOST_PP_TUPLE_ELEM(0,tpl) ,BOOST_PP_TUPLE_TO_SEQ(BOOST_PP_TUPLE_POP_FRONT(tpl)))
//#define DEFVAL(tplseq)  BOOST_PP_SEQ_FOR_EACH(DEFVALS, _ ,tplseq)
template <typename T>
struct invecT {
	decltype(auto) begin()const {
		return std::istream_iterator<T>(in);
	}
	decltype(auto) end()const {
		return std::istream_iterator<T>();
	}
};
template <typename T>
invecT<T> invec;
struct State {
	array<u3, 3> buf;
	//State() :buf{ 1,0,1 } {}
	constexpr State() :buf{1,0,0}{}
	State(u3 zerocount) :buf{ 1,0,zerocount } { addX(zerocount); }
	void addX(u3 zero) {
		if (zero != buf[2]) {
			u6 zerodiff = zero - buf[2];
			buf[0] = (u3)(((u6)buf[0] + zerodiff * buf[1]) % moduloNo);
			buf[2] = zero;

		}

		buf[1] = buf[0] + buf[1];
		buf[1] = (buf[1] >= moduloNo) ? buf[1] - moduloNo : buf[1];
	}
};
u6 pow2(u6 n) {
	if (n < 64)return (u6(1) << n) % moduloNo;
	else if (n == 64)return (u6(0) - moduloNo) % moduloNo;
	u6 tmp = pow2(n / 2);
	tmp = tmp * tmp;
	if (n & 1)tmp *= 2;
	return tmp % moduloNo;
}
 /*
u6 pow2(u6 n) {
	if(n<64)return (u6(1) << n) % moduloNo;
	u6 powcount = 0, mod2 = 0;
	while (n >= 64) {
		mod2 += n & 1;
		++powcount;
		n >>= 1;
	}
	u6 result = (u6(1) << n) % moduloNo;
	for (u6 i = 0; i < powcount; ++i) {
		result = (result*result) % moduloNo;
	}
	return (result* pow2(mod2)) % moduloNo;
}*/

struct Calc {
	DEFVALS((u6,N));
	State stmap[maxA];
	u6 calc(u6 N_) {
		N = N_;
		u3 st = 0;
		//u3 tmp;
		u3 zerocount = 0;
		for (auto tmp:invec<u3>) {
			// in >> tmp;
			st ^= tmp;
			if (!st) {
				++zerocount;
			}
			else {
				stmap[st].addX(zerocount);
			}
		}
		if (st != 0) {
			return stmap[st].buf[0];
		}
		else {
			u6 result = pow2(zerocount - 1);
			for (auto & stv : stmap) {
				result = (result + stv.buf[1]) % moduloNo;
			}
			return result;
		}
	}
};
Calc calc;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);//
#ifndef __GNUC__ 
	in.str("24\n1 2 5 3 3 6 1 1 8 8 0 3 3 4 6 6 4 0 7 2 5 4 6 2");
#endif
	u6 N;
	in >> N;
	cout << calc.calc(N) << endl;
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    ll n, h, w; cin >> n >> h >> w;
    int ans = 0;
    rep(i, n) {
        ll a, b; cin >> a >> b;
        if(a >= h && b >= w) ans++;
    }
    cout << ans << '\n';
    return 0;
}

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

int main(){
  int a,b;

  while(scanf("%d%d",&a,&b) != EOF)
    {
      int cnt = 0;
      int sum = a + b;
      
      while(1)
	{ 
	  sum /= 10;
	  cnt++;
	  if(!sum) break;
	}
      cout << cnt << endl;
    }
  return 0;
}



Measured memory_bytes: 3144
import sys
input = lambda: sys.stdin.readline().rstrip()
D = {"AB": 2, "AC": 1, "BC": 0}
N, a, b, c = map(int, input().split())
X = [a, b, c]
S = [D[input()] for _ in range(N)]
ANS = []
if max(X) == 0:
    print("No")
    exit()

if sum(X) == 1:
    t = 0 if a else 1 if b else 2
    for s in S:
        if X[s]:
            print("No")
            exit()
        t ^= s ^ 3
        ANS.append(t)
        X[s-1] ^= 1
        X[s-2] ^= 1
    print("Yes")
    print("\n".join([chr(t+65) for t in ANS]))
    exit()

s = S[0]
if X[s-1] + X[s-2] == 0:
    print("No")
    exit()

for i, s in enumerate(S):
    if X[s-1] > X[s-2]:
        ANS.append((s-2) % 3)
        X[s-1] -= 1
        X[s-2] += 1
    elif X[s-1] < X[s-2]:
        ANS.append((s-1) % 3)
        X[s-1] += 1
        X[s-2] -= 1
    elif i == N - 1 or S[i+1] == (s-1) % 3:
        ANS.append((s-2) % 3)
        X[s-1] -= 1
        X[s-2] += 1
    else:
        ANS.append((s-1) % 3)
        X[s-1] += 1
        X[s-2] -= 1

print("Yes")
print("\n".join([chr(t+65) for t in ANS]))

Measured memory_bytes: 11880
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	int num[4];
	int n;
	int l, s;
	
	while (cin >> n, n){
		int ct = 0;
		if (n % 1111 == 0){
			cout << "NA" << endl;
			continue;
		}
		while(n != 6174){
			l = s = 0;
			for (int i = 0; i < 4; i++){
				num[i] = n % 10;
				n /= 10;
			}
			sort(num, num + 4);
			
			for (int i = 0; i < 4; i++){
				s = s * 10 + num[i];
				l = l * 10 + num[3 - i];
			}
			n = l - s;
			ct++;
		}
		cout << ct << endl;
	}
	return (0);
}

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

int main()
{
   char s[10];
   scanf("%s",&s);
   if (s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
   cout<<"Yes"<<endl;
   else
   cout<<"No"<<endl;
   return 0;
}



Measured memory_bytes: 256
N=int(input())
X=[0 for i in range(N)]
Y=[0 for i in range(N)]
for i in range(N):
  X[i],Y[i]=map(int,input().split())
Sum=0
for i in range(N):
  for p in range(N):
    Sum+=((X[i]-X[p])**2+(Y[i]-Y[p])**2)**(1/2)
print(Sum/N)

Measured memory_bytes: 3064
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    int n;
    cin >> n;
    vector<LL> ws(n);
    rep(i, n) {
        cin >> ws[i];
    }
    //sort(ws.begin(), ws.end());

    LL ans = 1010101010;
    rep(i, n) {
        vector<LL> ls, rs;
        rep(l, i) {
            ls.push_back(ws[l]);
        }
        for (LL r = i; r < n; r++) {
            rs.push_back(ws[r]);
        }
        LL res = 0;
        rep(i,ls.size()) {
            res += ls[i];
        }
        rep(i, rs.size()) {
            res -= rs[i];
        }
        res = abs(res);
        ans = min(ans, res);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define ll long long int
#define rep(i,n) for(i=0;i<(n);i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
typedef pair< ll, ll > lpair;

bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    if(a.ff == b.ff)
        return (a.ss < b.ss);
    return (a.ff < b.ff);
}

vector< ll > prime(1000005,1);
void p()
{
    ll i,j;
    for(i=2;i<=1000000;i++)
    {
        if(prime[i] == 1)
        {
            for(j = 2*i;j<=1000000;j+=i) prime[j] = 0;
        }
    }
}

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

    ll n,i,k,j;
    cin>>n>>k;

    vector< ll > dp(n+1),h(n+1);
    for(i = 1;i<=n;i++) cin>>h[i];
    dp[1] = 0;

    for(i = 2;i<=n;i++)
    {
        dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
        for(j = 2;j<=k;j++)
        {
            if(i-j <= 0) break;
            dp[i] = min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
        }
    }
    cout<<dp[n]<<endl;
}



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

using namespace std;
using ll = long long;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> v(M + 1, 0);
	for (int i = 0; i < N; ++i) {
		int K;
		cin >> K;
		for (int j = 0; j < K; ++j) {
			int a;
			cin >> a;
			v[a] += 1;
		}
	}

	int res = 0;
	for (int i = 0; i <= M; ++i) {
		if (v[i] == N) { ++res; }
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  string s;
  cin>>s;
  for(ll i=0;i<s.size();i++){
    if(s[i]==',') cout<<" ";
    else cout<<s[i];
  }
  cout<<"\n";
  return 0;
}
	

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

using namespace std;

int main(){

    ll n;
    cin>>n;

    vector<ll> v(n-1);
    for(ll i=0;i<n-1;i++){
        cin>>v[i];
    }

    vector<ll> arr(n+1, 0);
    for(ll i=0;i<n-1;i++){
        arr[v[i]]++;
    }

    for(ll i=1;i<=n;i++){
        cout<<arr[i]<<endl;
    }


    return 0;
}

Measured memory_bytes: 6360
import java.util.*;

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

        int num = sc.nextInt();
        String s = Integer.toString(num);

        int counter = 0;

        for(int i = 0; i < s.length(); ++i){
            if(s.charAt(i) == '1') ++counter;
        }

        System.out.println(counter);
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(in) in.begin(), in.end()
#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int, int> PII;

int main(){
    FIO;
    ll n;
    cin >> n;
    ll arr[n+1], brr[n];
    for(ll i = 0 ; i < n+1 ; i++){
        cin >> arr[i];
    }
    for(ll i = 0 ; i < n ; i++){
        cin >> brr[i];
    }
    ll ans = 0;
    for(ll i = n-1 ; i >= 0 ; i--){
        if(arr[i+1] > brr[i]){
            arr[i+1] -= brr[i];
            ans += brr[i];
        }else{
            brr[i] -= arr[i+1];
            ans += arr[i+1];
            if(arr[i] > brr[i]){
                arr[i] -= brr[i];
                ans += brr[i];
            }else{
                ans += arr[i];
                arr[i] = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define PI acos(-1)
#define int long long int
#define pb push_back
#define pi pair<int, int>
#define fir first
#define sec second
#define MAXN 300001
#define mod 1000000007

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = LLONG_MIN;
  ans = max(ans, a * d);
  ans = max(ans, a * c);
  ans = max(ans, b * c);
  ans = max(ans, b * d);
  cout << ans << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    // ABC054-B

    int N, M; cin >> N >> M;
    char A[N][N];
    REP(i,N) REP(j,N) cin >> A[i][j];

    char B[M][M];
    REP(i,M) REP(j,M) cin >> B[i][j];

    REP(i,N/M + 1){
        REP(j, N/M + 1){
            int cnt=0;
            REP(k, M){
                REP(l, M){
                    if(A[i+k][j+l]==B[k][l]){
                        cnt++;
                    }else{
                        break;
                    }
                }
            }
            if(cnt == M*M){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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;}
/*
void chmin(ll a, ll b){if (a>b){a = b; return true;}return false;}
void chmax(ll a, ll b){if (a<b){a = b; return true;}return false;}
*/

const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  int x; cin >>x;
  vector<bool> prime(100001, true);
  prime.at(0) = false, prime.at(1) = false;
  for (int i=2; i<prime.size(); i++){
    if (!prime.at(i)) continue;
    int j = i * 2;
    while(j < prime.size()){
      prime.at(j) = false; j += i;
    }
  }
  int ans = -1;
  int check = x;
  while(check < prime.size()){
    if (prime.at(check)){
      ans = check; break;
    }
    check++;
  }
  if (check == prime.size()){
    ans = 100003;
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var (
	N, D, A int
	ms      PairList
	answer  int
)

func main() {
	N = nextInt()
	D = nextInt()
	A = nextInt()
	ms = make([]Pair, N)
	for i := 0; i < N; i++ {
		x := nextInt()
		h := nextInt()
		ms[i] = Pair{x, h}
	}
	sort.Sort(ms)
	bit := NewBIT(N)
	for i := 0; i < N; i++ {
		dmg := bit.Accumulate(i)
		h := ms[i].Health
		h -= dmg
		if h <= 0 {
			continue
		}
		attack := (h + A - 1) / A
		answer += attack
		newDmg := attack * A
		bit.Add(i, newDmg)
		upper := minIndexLargerThan(ms[i].Loc + 2*D)
		bit.Add(upper, -newDmg)
	}
	fmt.Println(answer)
}

func minIndexLargerThan(loc int) (result int) {
	ok := N
	ng := -1
	for math.Abs(float64(ok-ng)) > 1.0 {
		mid := (ok + ng) / 2
		if ms[mid].Loc > loc {
			ok = mid
		} else {
			ng = mid
		}
	}
	return ok
}

type PairList []Pair

func (pl PairList) Len() int {
	return len(pl)
}

func (pl PairList) Less(i, j int) bool {
	return pl[i].Loc < pl[j].Loc
}

func (pl PairList) Swap(i, j int) {
	pl[i], pl[j] = pl[j], pl[i]
}

type Pair struct {
	Loc    int
	Health int
}

var scanner *bufio.Scanner

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

type BIT struct {
	Nodes []int
	Size  int
}

func NewBIT(size int) *BIT {
	bit := new(BIT)
	bit.Size = size
	bit.Nodes = make([]int, size+1)
	return bit
}

func (bit *BIT) Add(location, value int) {
	for i := location + 1; i <= bit.Size; i += (i & -i) {
		bit.Nodes[i] += value
	}
}

func (bit *BIT) Sum(start, end int) int {
	return bit.Accumulate(end) - bit.Accumulate(start-1)
}

func (bit *BIT) Accumulate(end int) (result int) {
	if end >= bit.Size {
		end = bit.Size - 1
	}
	for i := end + 1; i > 0; i -= i & -i {
		result += bit.Nodes[i]
	}
	return
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int T,X;

int main()
{
  cin >> T >> X;

  double res;
  res = (double)T/X;
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
s = str(input())
for i in range(len(s)):
     if i % 2 ==0:
          if s[i] == 'L':
               print('No')
               sys.exit()
     if i % 2 ==1:
          if s[i] == 'R':
               print('No')
               sys.exit()
print('Yes')

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

void change( int& x, int& y )
{
    int aux;
    aux = x;
    x = y;
    y = aux;
}
int main()
{
    int a,b,c;
    int aux;
    cin >> a >> b >> c;
    if( a > b)
    change( a, b );
    if( a > c )
    change( a , c );
    if( b > c)
    change( b ,c );
    
    cout<<a<<" "<<b<<" "<<c<<endl;

    return 0; 
}


Measured memory_bytes: 3092
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    vector<int> a(N + 1, 0);
    int k = 0;
    while(K--) {
        k++;
        int d;
        cin >> d;
        int j;
        for (int i = 0; i < d; i++) {
            cin >> j;
            a[j] = 1;
        }
    }
    int res = 0;
    for (int i = 1; i <= N; i++) {
        if (a[i] == 0) res++;
    }
    cout << res <<endl;
    return 0;
}

Measured memory_bytes: 3660
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef vector<vector<ll>> matrix;

int freq[256];
void solve() {
  string s;
  ll ret = 1;
  cin >> s;
  for(int i = 0; i < s.size(); i++) {
    ret += i+1;
    ret -= ++freq[s[i]];
  }
  cout << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> ac(n, false);
  vi wac(n, 0);
  vector<pair<int, string>> ps(m);
  REP(i, m) {
    int p;
    string s;
    cin >> p >> s;
    p--;
    ps[i] = make_pair(p, s);
  }

  REP(i, m) {
    if (ac[ps[i].first])
      continue;
    if (ps[i].second == "AC") {
      ac[ps[i].first] = true;
    } else {
      wac[ps[i].first]++;
    }
  }
  int acc = 0;
  int wacc = 0;
  REP(i, n) {
    if (ac[i]) {
      acc++;
      wacc += wac[i];
    }
  }
  cout << acc << " " << wacc << endl;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define ll long long
#define max 1000000
using namespace std;


int main() 
{
    int n;
    cin >> n;
    vector<int> v1;
    vector<int> v2;
    int k = 1;
    while (k<=max)
    {
        v1.push_back(k);
        k*=9;
    }
    k = 1;
    while (k<=max)
    {
        v2.push_back(k);
        k*=6;
    }
    sort(v1.rbegin(),v1.rend());
    sort(v2.rbegin(),v2.rend());
    int res = INT_MAX;
    for (int i=0; i<=n; i++)
    {
        int ans=0;
        int a1=i;
        int a2=n-i;
        for (int j=0; j<v1.size(); j++)
        {
            while (a1>=v1[j])
            {
                ans++;
                a1-=v1[j];
            }
        }
        for (int j=0; j<v2.size(); j++)
        {
            while (a2>=v2[j])
            {
                ans++;
                a2-=v2[j];
            }
        }
        res=min(ans,res);
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int e,b,c;cin>>e>>b>>c;
  vector<int >nos(b,0);
  int seen=0;
  int i=2;
  int a = e;
  while(nos[a%b]!=1){
  	nos[a%b]=1;
    if(a%b==c){cout<<"YES";seen=1;break;}
    a=e*i;
    i++;
  }
  if(seen==0)cout<<"NO";
}

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

using namespace std;

int main() {
    long long a,b,n,max;
    cin >> a >> b >> n;
    if(a < b) {
        if( (b - 1) < n) {
            max = (a * (b-1))/b;
        }else {
            max = (a * n)/b;
        }
    }else{
        max = (a * n)/b - a * ( n / b );
        long long temp = (n / b ) * b - 1;
        temp = (a * temp)/b - a * ( temp / b );
        if(temp > max){
            max = temp;
        }
    }
    cout << max << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,len;
    string s;
    cin>>n;
    cin>>s;
    len=s.length();
    if(len>n)
    {
        for(int i=0;i<n;i++)
        {
            cout<<s[i];
        }
        cout<<"...";
    }
    else
    {
        cout<<s;
    }

}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define	pii pair<int,int>
#define vi vector<int>
 
 
 
long long int solve(int n, int wt, int v[], int w[])
{
	long long int dp[wt+1];
  	for(int i=0;i<=wt;i++)	dp[i]=0;
	for(int i=0;i<n;i++){
		for(int j=wt;j>=w[i];j--)
			dp[j] = max(v[i]+dp[j-w[i]], dp[j]);
	}
	return dp[wt];
}
 
int main()
{
	int n,wt;	cin>>n>>wt;
	int w[n],v[n];
	for(int i=0;i<n;i++)	cin>>w[i]>>v[i];
	cout<<solve(n,wt,v,w)<<endl;
	return 0;
}

Measured memory_bytes: 1024
n = gets.chomp.to_i

if n % 4 == 0
  print "Yes"
elsif n % 7 == 0
  print "Yes"
else
  i = 1
  while (i*4) <= n do
    j = 1
    while ((i*4)+(j*7)) <= n do
      if ((i*4)+(j*7)) == n
        print "Yes"
        return
      end
      j += 1
    end
    i += 1
  end
  print "No"
end


Measured memory_bytes: 14272
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  for(int i=0;i<4;i++){
    cout << s.at(i);
  }
  cout << " ";
  for(int i=4;i<s.size();i++){
    cout << s.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        ArrayList<ArrayList<Integer>> arys =
                new ArrayList<ArrayList<Integer> >();
        HashMap<Integer,Boolean> map = new HashMap<Integer, Boolean>();
        for(int i = 0; i< n; ++i){
            arys.add(new ArrayList<Integer>());
            for(int j = 0; j < d; ++j){
                Integer value =  sc.nextInt();
                arys.get(i).add(value);
            }
        }
        for(int i = 1; i < 1000; ++i){
            map.put(i * i,true);
        }
        int ans = 0;
        for(int i = 0; i < n; ++i){
            for(int j =i + 1; j < n; ++j){
                Integer res = Main.cal(arys.get(i),arys.get(j));
                if(map.get(res) == null){

                } else {
                    ++ans;
                }
            }
        }
        System.out.println(ans);

    }

    public static Integer cal(ArrayList<Integer>a, ArrayList<Integer>b) {
        Integer k = 0;
        for (int i = 0; i < a.size(); ++i) {
            k += (a.get(i) - b.get(i)) * (a.get(i) - b.get(i));
        }
        return k;
    }

}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

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

    ll count=0;
    ll ans=0;
    for(int i=0; i<n-1; i++){
        if(h[i] >= h[i+1]){
            count ++;
            ans = max(ans,count);
        }
        else{
            count = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3960
#include <iostream>
#include <algorithm>
using namespace std;
 
int main()
{
    int n, ans = 0, m = -1;
    cin >> n;
    int h[1000] = {0};
    for(int i = 0; i < n; ++i) {
        cin >> h[i];
        if (h[i] >= m){

        m = h[i];
        ans += 1;}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>

typedef long long ll;

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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}


int main() {
	cin >> n;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<ll>());
	ll p, q = INF; ll t = 0;
	p = a[0];
	for (ll i = 1; i < n; i++) {
		if (q >= abs(p - 2*a[i])) {
			q = abs(p - 2 * a[i]);
			t = a[i];
		}
	}
	cout << p <<" "<< t << endl;
}

Measured memory_bytes: 1152
import java.util.*;

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

        long A = sc.nextLong();
        long B = sc.nextLong();

        System.out.println(lcm(A, B));

    }


    static long lcm(long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return (long) (c / b);
    }
}

Measured memory_bytes: 23252
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############
# 何番目の仕事かをレコードできる？
# 貪欲っぽい

N = getN()
A = getList()
B = getList()
plus = []
minus = []
for i in range(N):
    score = A[i] - B[i]
    if score < 0:
        minus.append(score)
    else:
        plus.append(score)
plus.sort(reverse = True)

if len(minus) == 0:
    print(0)
    exit()

cnt = sum(minus)
ans = len(minus)
for i in range(N - ans):
    cnt += plus[i]
    ans += 1
    if cnt >= 0:
        print(ans)
        exit()
print(-1)


Measured memory_bytes: 110208
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100000
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n;
ll a[100000];
ll del[100000];
ll x, sum;
ll cnt;

int main(){
    cin >> n;
    x = n*(n+1)/2;
    rep(i,n) cin >> a[i];
    rep(i,n) sum += a[i];
    if(sum%x != 0){
        cout << "NO" << endl;
        return 0;
    }
    cnt = sum/x;
    rep(i,n){
        ll dif = a[i]-a[(i+1)%n];
        if((dif+cnt)%n != 0){
            cout << "NO" << endl;
            return 0;
        }
        ll z = (dif+cnt)/n;
        if(a[i] < z*n){
            cout << "NO" << endl;
            return 0;
        }
    }
    rep(i,n){
        ll y = a[i];
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main()
{
	stuff;
	// #ifndef ONLINE_JUDGE 
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
	// #endif

	li a, b, n;
	cin >> a >> b >> n;
	li x;
	if(n<b) x = n;
	else x = b-1;
	li ans = (a*x)/b;
	cout << ans;
	return 0;
}


Measured memory_bytes: 3580
#include <iostream>
using namespace std;
int main(void){
    int x1,y1,x2,y2,a,b,c,d;
    cin >> x1 >> y1 >> x2 >> y2;
    if(x1 < x2 && y1 < y2){
    a = x2 - abs(y1-y2);
    b = y2 + abs(x1-x2);
    c = a - abs(x1-x2);
    d = b - abs(y1-y2);
    }else if(x1 > x2 && y1 < y2){
    a = x2 - abs(y1-y2);
    b = y2 - abs(x1-x2);
    c = a + abs(x1-x2);
    d = b - abs(y1-y2);
    }else if(x1 < x2 && y1 > y2){
    a = x2 + abs(x1-x2);
    b = y2 + abs(y1-y2);
    c = a - abs(x1-x2);
    d = b + abs(y1-y2);
    }else if(x1 > x2 && y1 > y2){
    a = x2 + abs(y1-y2);
    b = y2 - abs(x1-x2);
    c = a + abs(x1-x2);
    d = b + abs(y1-y2);
    }
    
    else if(x1 == x2 && y1 < y2){
    a = x2-(y2-y1);
    b = y2;
    c = a;
    d = y1;
    }else if(x1 == x2 && y1 > y2){
    a = x2 + (y1-y2);
    b = y2;
    c = a;
    d = y1;
    }else if(x1 < x2 && y1 == y2){
    a = x2;
    b = y2 + x2-x1;
    c = x1;
    d = b;
    }else if(x1 > x2 && y1 == y2){
    a = x2;
    b = y2 - (x1-x2);
    c = x1;
    d = b;
    }
    cout << a << " "<< b << " "<< c << " " << d << endl;
    return 0;
}

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

#define pb push_back
#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 3e5 + 10;

int A[N], c[N];
vector<int> ans[N];

int main() {

	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);

	if (1ll * a * b < n || a + b - 1 > n) {
		puts("-1");
		return 0;
	}

	c[1] = b;
	int re = n - b;
	For(i, 2, a) c[i] = min(b, re - (a - i)), re -= c[i], c[i] += c[i - 1];
	For(i, 1, a) For(j, 1, c[i] - c[i - 1]) ans[j].pb(c[i] + 1 - j);
	For(i, 1, b) for (int x : ans[i]) printf("%d ", x);

	return 0;
}

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

void chmax(int64_t& a, int64_t b){
    a = max(a, b);
}

const int M = 200001;
int L, N;
int64_t X[M], Y[M], Xs[M], Ys[M];

int main(){
    cin >> L >> N;
    for(int i=1; i<=N; i++){
        cin >> X[i];
        Y[N+1-i] = L - X[i];
    }
    for(int i=1; i<=N; i++){
        Xs[i] = Xs[i-1] + X[i];
        Ys[i] = Ys[i-1] + Y[i];
    }

    const int dx[2] = {1, 0};
    const int dy[2] = {0, 1};
    int64_t ans = 0;
    for(int d=0; d<=N; d++){
        int xt = d, yt = N-d;
        for(int k1=0; k1<2; k1++){
            for(int k2=0; k2<2; k2++){
                int cx = min(xt, yt + (- dy[k1] - dy[k2] + dx[k1] + dx[k2]) / 2);
                int cy = min(yt, xt + (- dx[k1] - dx[k2] + dy[k1] + dy[k2]) / 2);
                if(cx < 0 || cy < 0) continue;

                int64_t result = 0;
                result += (Xs[xt] - Xs[xt-cx]) * 2;
                result += (Ys[yt] - Ys[yt-cy]) * 2;
                result -= (k2 ? Y[yt] : X[xt]);
                chmax(ans, result);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){

    int n;
    cin>>n;
    vector<long long>A(n);
    rep(i,n)cin>>A[i];
    sort(A.begin(),A.end());

    vector<long long>B(n);
    rep(i,n)cin>>B[i];
    sort(B.begin(),B.end());

    vector<long long>C(n);
    rep(i,n)cin>>C[i];
    sort(C.begin(),C.end());
    
    long long ans=0;
    vector<long long >b(n+1);
    b[n]=0;
    for(int i=n-1;i>-1;i--){
        int k=upper_bound(C.begin(),C.end(),B[i])-C.begin();
        b[i]=(n-k)+b[i+1];
    }




    rep(i,n){
        int p=upper_bound(B.begin(),B.end(),A[i])-B.begin();
        ans+=b[p];
    }
    /*
    rep(i,n+1){
        cout<<b[i]<<" ";
    }
    cout<<endl;
    */
    cout<<ans<<endl;
    

    return 0;

}
/*
3
2 2 2
1 2 4
3 3 3

*/


Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s[0]=='M'){
		cout<<"6"<<endl;
	}
	else if(s[0]=='T'&&s[1]=='U'){
		cout<<"5"<<endl;
	}
	else if(s[0]=='W'){
		cout<<"4"<<endl;
	}
	else if(s[0]=='T'&&s[1]=='H'){
		cout<<"3"<<endl;
	}
	else if(s[0]=='F'){
		cout<<"2"<<endl;
	}
	else if(s[0]=='S'&&s[1]=='A'){
		cout<<"1"<<endl;
	}
	else{
		cout<<"7"<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    int N,a=0,b=0,c,d,e,f=10000;
    cin>>N;
    vector<int>W(N);
    for(int i=0;i<N;i++){
        cin>>W.at(i);
        a+=W.at(i);
    }
    for(int i=0;i<N-1;i++){
        b+=W.at(i);
        c=a-b;
        d=abs(b-c);
        e=min(f,d);
        if(e==f){
            cout<<e<<endl;
            exit(0);
        }
        f=d;
    }
    cout<<e<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100000005];
int main()
{
  int n,m,k;
  int flag;
  cin>>n>>m>>k;
  int num=0;
  if( k >= (m-n)){
    for(int i=n;i<=m;i++){
      cout<<i<<endl;
    }
    return 0;
  }
  for(int i=n;i<=m;i++){
    cout<<i<<endl;
    num++;
    if(num == k){
      flag = i;
      break;
    }
  }
  num = 0;
  for(int i=m;i>=n;i--){
    a[num++] = i;
    if(num == k)break;
  }
  for(int i=num-1;i>=0;i--){
    if(flag != a[i])
    cout<<a[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import itertools

# input
menu = []
for i in range(5):
  menu.append(int(input()))
  
# main
ans = []
for v in itertools.permutations(menu):
  tmp = 0
  for i in range(5):
    tmp += v[i]
    if tmp % 10 != 0 and i != 4:
      tmp += 10 - tmp % 10
  ans.append(tmp)
  
# output
print(min(ans))


Measured memory_bytes: 3060
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;

int main() {
	int a, b;
	cin >> a >> b;
	int ans = a;
	int cnt = 1;
	if (b == 1) {
		cout << 0 << endl;
		return 0;
	}
	while (ans < b) {
		ans += (a - 1);
		++cnt;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256