akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N;
int a[210];
set<int> se;

int main() {
  while (cin >> N) {
	for (int i = 0; i < N; ++i) cin >> a[i];
	se.clear();
	int add = 0;
	for (int i = 0; i < N; ++i) {
	  if (a[i] < 3200) se.insert(a[i] / 400);
	  else ++add;
	}
	int Min = se.size();
	if (Min == 0 && add > 0) Min = 1;
	int Max = se.size() + add;
	cout << Min << " " << Max << endl;
  }
}















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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define REP(i,n) for(int i=0; i < (n); ++i)
#define SIZE(c) (int) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define FWD(i,a,b) for (int i=(a); i<(b); ++i)
#define BCK(i,a,b) for (int i=(a); i>(b); --i)
#define PI 3.14159265358979311600
#define pb push_back
#define mp make_pair
#define st first
#define nd second

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

typedef vector < int > VI;
typedef vector<ll> VL;

typedef long double K;

const int N = 200005;

int n, a[N], b[N];
char s[N];
map<char,int> cnt;

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

	cin >> s;
	n = strlen(s);

	REP(i, n) ++cnt[s[i]];

	ll total = 1 + 1LL*n*(n+1)/2;

	for (auto& item : cnt) {
		ll c = item.second;
		total -= c*(c+1)/2;
	}

	cout << total << '\n';

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int main(){
    int n,kk;cin >> n>> kk;
    ll x[n], y[n];
    REP(i,n){
        cin >> x[i] >> y[i];
    }
    ll ans =1LL<<62;
    REP(i,n){ //left
        REP(j,n){ //right
            REP(l,n){ //bottom
                REP(k,n){//above
                    if(x[j]-x[i] <= 0 || y[k] - y[l] <= 0 || y[i] < y[l] || y[i] > y[k] || y[j] < y[l] || y[j] > y[k] || x[l] < x[i]  || x[l] > x[j] || x[k] < x[i] || x[k] > x[j]) continue;
                    int count =0;
                    REP(m,n){
                        if(x[i] <= x[m] && x[m] <= x[j] && y[l] <= y[m] && y[m] <= y[k]) count++;
                    }
                    if(count==kk){
                        ans = min(ans,(x[j]-x[i]) * (y[k]-y[l]));
                    }

                }
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define LL long long int
#define vvLL vector<vector<LL>>
#define vvi vector<vector<int>>
#define MOD 1000000007
struct res{
    int size;
    LL cases;
};
vector<int> fact;
void factorial(int N){
    fact.push_back(1);
    for (int i = 1; i < N+1; i++){
        LL tmp=(LL)fact[i-1]*i;
        fact.push_back(tmp%MOD);
    }
}
LL modinv(LL a, int b){// a/b mod MOD
    LL res=1;
    int n=MOD-2;
    LL x=b;
    while(n>0){
        if(n&1==1){
            res*=x;
            res%=MOD;
        }
        x*=x;
        x%=MOD;
        n>>=1;
    }
    res*=a;
    res%=MOD;
    return res;
}

//v...vertex, p...parent
struct res dfs(int v,int p, vvi &to, vvLL &dp, vvi &size, 
    vector<int> &deg, vector<int> &pi){
    deg[v]=to[v].size();
    for(int j = 0; j < deg[v]; j++){
        size[v].push_back(0);
        dp[v].push_back(0);
    }
    struct res res;
    res.size=1;res.cases=1;
    for(int i=0; i<to[v].size(); i++){
        int next_v=to[v][i];
        if(next_v==p) {
            pi[v]=i;
            continue;
        }
        struct res tmp=dfs(next_v,v,to,dp,size,deg,pi);
        size[v][i]=tmp.size;
        dp[v][i]=tmp.cases;
        res.size+=size[v][i];
        res.cases*=dp[v][i];
        res.cases%=MOD;
    }
    res.cases=modinv(res.cases,res.size);
    return res;
}

void bfs(int v,struct res res_p, int p, vvi &to, vvLL &dp, vvi &size, 
    vector<int> &deg, vector<int> &pi,vector<int> &ans){
    if(p!=-1){
        size[v][pi[v]]=res_p.size;
        dp[v][pi[v]]=res_p.cases;
    }
    vector<int> sizel(deg[v]+1,0);
    vector<LL> dpl(deg[v]+1,1);
    for (int i = 0; i < deg[v]; i++){
        sizel[i+1]=sizel[i]+size[v][i];
        dpl[i+1]=dpl[i]*dp[v][i]%MOD;
    }
    vector<int> sizer(deg[v]+1,0);
    vector<LL> dpr(deg[v]+1,1);
    for (int i = deg[v]-1; i >=0; i--){
        sizer[i]=sizer[i+1]+size[v][i];
        dpr[i]=dpr[i+1]*dp[v][i]%MOD;
    }
    ans[v]=modinv(dpr[0],sizer[0]+1)*fact[sizer[0]+1]%MOD;
    for (int i = 0; i < deg[v]; i++){
        int u=to[v][i];
        if(u==p)continue;
        struct res res;
        res.size=sizel[i]+sizer[i+1]+1;
        res.cases=dpl[i]*dpr[i+1]%MOD;
        res.cases=modinv(res.cases,res.size);
        bfs(u,res,v,to,dp,size,deg,pi,ans);
    }
}

int main() {
    int N;
    cin>>N;
    vvi to(N);
    vvLL dp(N);
    vvi size(N);
    vector<int> deg(N); //deg[v]:degree of v
    vector<int> pi(N); //pi[v]:parent index of v
    factorial(N);
    for (int i = 0; i < N-1; i++){
        int a,b;
        cin>>a>>b;
        to[a-1].push_back(b-1);
        to[b-1].push_back(a-1);
    }
    dfs(0,-1,to,dp,size,deg,pi);
    struct res dummy;
    vector<int> ans(N);
    bfs(0,dummy,-1,to,dp,size,deg,pi,ans);
    for (int i = 0; i < N; i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 73724
N, L = [int(i) for i in input().split()]

min_ = L
max_ = L + N -1

def eat_apple(N, L, max_):
    if max_<0:
        return max_ 
    if L < 0:
        return 0
    return L

print((min_+max_)*(max_-min_+1)//2 - eat_apple(N, L, max_))

Measured memory_bytes: 2940
n,k,*as=$<.read.split.map &:to_i
h={}
x=[]
c,d=1,1
until h[c]
  x.push(c)
  h[c]=d
  c=as[c-1]
  d+=1
end
l=d-h[c]
puts x[k<h[c] ? k : (k+1-h[c])%l+h[c]-1]

Measured memory_bytes: 39492
s=input()
t=input()
flag=0
for i in s:
    for j in t:
        if i<j:
            flag=1
            break
            
if flag :
    print("Yes")
elif s.count(s[0])==len(s) and t.count(s[0])==len(t) and len(s)<len(t):
    print("Yes")
else:
    print("No")


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

int main() {
  int N;
  cin >> N;
  
  int cnt = 0;
  int ans = 0;
  
  vector<int> H(N);
  
  for(int i = 0; i < N; i++) {
    cin >> H.at(i);
    if((i >= 1) && (H.at(i) <= H.at(i - 1))) {
      cnt++;
      ans = max(cnt, ans);
    }
    else if((i >= 1) && (H.at(i) > H.at(i - 1)))cnt = 0;
  }
     
  cout << ans << endl;
    
}

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

int main() {
  int N,i,k;
  cin >> N;
  int W[N];
  int s,s2,t;
  s=s2=t=k=0;
  for(i=0;i<N;i++){
    cin >> W[i];
    s+=W[i];
  }
  s2=s/2;
  for(i=0;i<N;i++){
    t+=W[i];
    if(t>=s2){
      k=W[i];
      break;
    }
  }
  k=min(abs(s-t*2),s-t*2+k*2);
  cout << k << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int i,k(0),t(0),n;
	int a[100000];
	cin>>n;
	for (i=0;i<n;i++)
	{
	   cin>>a[i];
	   if (a[i]%4==0) k++;
	   else if (a[i]%2==0) t++;
    }
    if ((n-k-t<k+1) || (n-k-t==k+1&&t==0))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ALL(c) (c).begin(),(c).end()

const int O = 400;
const int M = 1000;

int f1[1000][1000], f2[1000][1000];

void solve(long long H, long long W, vector<string> s){
	map<int, vector<pair<int, int>>> mpx, mpy;
	for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) {
		if (s[i][j] == '.') continue;
		int x = i + j + O / 2, y = i - j + O;
		mpx[x].push_back(make_pair(x,y));
		mpy[y].push_back(make_pair(x,y));
		f1[x][y] = f2[x][y] = 1;
	}
	for(int i = 0; i < M; ++i) {
		for(int j = 1; j < M; ++j) {
			f1[i][j] += f1[i][j-1];
		}
	}
	for(int i = 1; i < M; ++i) {
		for(int j = 0; j < M; ++j) {
			f2[i][j] += f2[i-1][j];
		}
	}

	int res = 0;
	for(auto p: mpx) {
		vector<pair<int,int>> v = p.second;
		for(int i = 0; i < v.size(); ++i) for(int j = i + 1; j < v.size(); ++j) {
			auto a = v[i];
			auto b = v[j];
			int y1 = min(a.second, b.second), y2 = max(a.second, b.second);
			int d = y2 - y1; 
			if(a.first - d >= 0) {
				res += f1[a.first - d][y2] - f1[a.first - d][y1 - 1];
				res -= f1[a.first - d][y1] - f1[a.first - d][y1 - 1];
				res -= f1[a.first - d][y2] - f1[a.first - d][y2 - 1];
			}

			if(a.first + d < M) {
				res += f1[a.first + d][y2] - f1[a.first + d][y1 - 1];
				res -= f1[a.first+d][y1] - f1[a.first + d][y1 - 1];
				res -= f1[a.first+d][y2] - f1[a.first + d][y2 - 1];
			}
		}
	}
	for(auto p: mpy) {
		vector<pair<int,int>> v = p.second;
		for(int i = 0; i < v.size(); ++i) for(int j = i + 1; j < v.size(); ++j) {
			auto a = v[i];
			auto b = v[j];
			int d = abs(a.first - b.first);
			int x1 = min(a.first, b.first), x2 = max(a.first, b.first);
			if(a.second - d >= 0) {
				res += max(f2[x2][a.second - d] - f2[x1 - 1][a.second - d], 0);
			}
			if(a.second + d < M) {
				res += max(f2[x2][a.second + d] - f2[x1 - 1][a.second + d], 0);
			}
		}
	}
	cout << res << endl;
}

int main(){	
	long long W;
	long long H;
	scanf("%lld",&H);
	vector<string> s(H-1+1);
	scanf("%lld",&W);
	for(int i = 0 ; i <= H-1 ; i++){
		cin >> s[i];
	}
	solve(H, W, s);
	return 0;
}



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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9+7

using namespace std;

struct room{
  int depth;
  int doors;
  vector<int> dlist;
  room() : depth(0), doors(0), dlist() {}
};

int main(){
  int n; cin >> n;
  REP(counter, n) {
    int num;
    vector<int> data;
    int rs = 0;
    while(cin >> num and num) {
      data.push_back(num);
      if(num > 0) rs++;
    }
    vector<room> rooms(rs);
    int currentid = 0;
    int currentdepth = 0;
    vector<int> parents;
    REP(i, data.size()){
      // cout << data[i] << " : " << currentid << ", " << currentdepth << endl;
      // REP(j, parents.size()) cout << parents[j] << " ";
      // cout << endl;
      if(data[i] > 1){
        rooms[currentid].doors = data[i];
        rooms[currentid].depth = currentdepth;
        if(parents.size() != 0){
          int parent = parents[currentdepth-1];
          // cout << "parent : " << parent << ", ";
          // cout << "dest : " << currentid << endl;
          rooms[parent].dlist.push_back(currentid);
          rooms[currentid].dlist.push_back(parent);
        }
        parents.push_back(currentid);
        currentid++; currentdepth++;
      } else if(data[i] == 1) {
        rooms[currentid].doors = data[i];
        rooms[currentid].depth = currentdepth;
        if(parents.size() != 0){
          int parent = parents[currentdepth-1];
          // cout << "parent : " << parent << ", ";
          // cout << "dest : " << currentid << endl;
          rooms[parent].dlist.push_back(currentid);
          rooms[currentid].dlist.push_back(parent);
        }
        currentdepth--;
        while(currentdepth >= 0 and rooms[parents[currentdepth]].doors == rooms[parents[currentdepth]].dlist.size()){
          // cout << "del" << endl;
          parents.pop_back();
          currentdepth--;
        }
        currentdepth++; currentid++;
      } else {
        currentdepth--;
        int parent = parents[currentdepth];
        // cout << "parent : " << parent << ", ";
        int dest = parents[currentdepth + data[i]];
        // cout << "dest : " << dest << endl;
        rooms[parent].dlist.push_back(dest);
        rooms[dest].dlist.push_back(parent);
        while(currentdepth >= 0 and rooms[parents[currentdepth]].doors == rooms[parents[currentdepth]].dlist.size()){
          // cout << "del" << endl;
          parents.pop_back();
          currentdepth--;
        }
        currentdepth++;
      }
    }
    REP(i, rooms.size()) {
      sort(ALL(rooms[i].dlist));
      cout << i+1;
      REP(j, rooms[i].doors){
        cout << " " << rooms[i].dlist[j]+1;
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3104
n = int(input())
A = list(map(int, input().split()))
N = []

for a in A:
    check = 0
    count = 0
    while check == 0:
        if a % 2 == 0:
            a = a / 2
            count += 1
        else:
            check = 1
    N.append(count)

ans = min(N)
print(ans)

Measured memory_bytes: 3188
n, k = map(int, input().split())
max_multiple_count = 0
max_multiple = 1
while max_multiple < k:
    max_multiple_count += 1
    max_multiple *= 2

if n - k >= 0:
    ans = (n - k + 1)/n
else:
    ans = 0
for i in range(1, min(n+1, k)):
      I = i
      for j in range(1, max_multiple_count+1):
            I *= 2
            if I >= k:
                ans += (1/n) * ((1/2)**j)
                break

print(ans)

Measured memory_bytes: 39536
using System;
using System.Collections.Generic;
using System.Globalization;

namespace abc172_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var S = CIn.Read().ToCharArray();
      var T = CIn.Read().ToCharArray();

      var ans = 0;

      for (int i = 0; i < S.Length; i++)
      {
        if (S[i] != T[i]) ans++;
      }

      Console.WriteLine(ans);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


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

using namespace std;

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

    int p[10000];
    for (int i = 0; i < n; i++)
        scanf("%d", &p[i]);

    sort(p, p + n);

    int ans = 0;
    for (int i = 0; i < k; i++)
        ans += p[i];

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 3816
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

bool next(vector<ll> &a,ll m){
	REPR(i,a.size()){
		if(a[i]==m)continue;
		a[i]++;
		FOR(j,i+1,a.size())a[j]=a[i];
		return true;
	}
	return false;
}
int main(){
	ll n; cin>>n;
	ll m; cin>>m;
	ll q; cin>>q;
	vector<ll> a(q);
	vector<ll> b(q);
	vector<ll> c(q);
	vector<ll> d(q);
	REP(i,q){
		cin>>a[i];a[i]--;
		cin>>b[i];b[i]--;
		cin>>c[i];
		cin>>d[i];
	}

	vector<ll> A(n,1);
	ll maxans=0;
	do{
		//cout << "A: "; REP(i,(signed)A.size()) cout<<A[i]<<" "; cout << endl; //----------cout----------//

		ll ans=0;
		REP(i,q){
			if(A[b[i]]-A[a[i]]==c[i])ans+=d[i];
		}
		//cout<<ans<<endl;
		if(ans>maxans)maxans=ans;
	}while(next(A,m));
	cout<<maxans<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int n, k;
vector<string> v;
set<string> st;

// https://github.com/drken1215/algorithm/blob/master/Others/next_combination.cpp
int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

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

    while(cin >> n >> k, n != 0 || k != 0){
        v.resize(n);
        st.clear();
        rep(i, n){
            cin >> v[i];
        }

        for(int bit = (1 << k) - 1 ; bit < (1 << n) ; bit = next_combination(bit)){
            vector<int> t;
            rep(i, n){
                if(bit >> i & 1){
                    t.emplace_back(i);
                }
            }

            do{
                string s = "";
                rep(i, k){
                    s = s + v[t[i]];
                }
                st.insert(s);
            }while(next_permutation(t.begin(), t.end()));
        }

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

    return 0;
}


Measured memory_bytes: 3380
//Keep Working Hard
  // I__Like__Food
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #pragma comment(linker, "/stack:200000000")
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define f first
  #define s second
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 998244353
  #define N 100005
  #define INF 1e10
  const double PI = acos(-1);

    int wt[N],val[N],dp[N];
int32_t main()
{


  int n, w;
  cin >> n >> w;



  //  dp[i] denotes the minimum weight that can be there for value i

  int sum = 0;
  for(int i = 1; i <= n; i++)
  {
    cin >> wt[i] >> val[i];
    sum += val[i];
  }
  
  for(int i = 1; i <= sum; i++)dp[i] = INF;

    dp[0] = 0;

  for(int i = 1; i <= n; i++)
  {
    for(int j = sum; j -val[i]>= 0; j--)
    {
      // backward to prevent double counting
      dp[j] = min(dp[j],dp[j-val[i]] + wt[i]);
    }
  }
  int ans = 0;
  for(int i = 0; i <= sum; i++)
    {
      
      if(dp[i]  <= w)
        {
          ans = max(ans,i);
        }
    }



    cout << ans;

  return 0;
  
}  

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,y;
  cin >> n >> y;
  int th = y / 10000; 
  REP(i,th+1){
    int th2 = (y-i*10000) / 5000;
    REP(j,th2+1){
      int th3 = n - i - j;
      if(i*10000 + j*5000 + th3*1000 == y){
        cout << i << " " << j << " " << th3 << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v_odd(n/2), v_even(n/2);
    int max_odd=0, max2_odd=0, num_max_odd=0, max_even=0, max2_even=0, num_max_even=0;
    for (int i=0; i<n; i++) {
        if (i%2==0) {
            cin >> v_odd[i/2];
        }
        else{
            cin >> v_even[i/2];
        }
    }
    
    map<int, int> mp_odd, mp_even;
    
    for(int i=0; i<n/2; i++){
        if(mp_odd.find(v_odd[i])==mp_odd.end()){
            mp_odd[v_odd[i]]=1;
            if(mp_odd[v_odd[i]]>max_odd){
                max2_odd=max_odd;
                max_odd=mp_odd[v_odd[i]];
                num_max_odd=v_odd[i];
            }
            else if(mp_odd[v_odd[i]]>max2_odd){
                max2_odd=mp_odd[v_odd[i]];
            }
        }
        else{
            mp_odd[v_odd[i]]++;
            if(mp_odd[v_odd[i]]>max_odd){
                if(num_max_odd!=v_odd[i]){
                    max2_odd=max_odd;
                }
                max_odd=mp_odd[v_odd[i]];
                num_max_odd=v_odd[i];
            }
            else if(mp_odd[v_odd[i]]>max2_odd){
                max2_odd=mp_odd[v_odd[i]];
            }
        }
        
        if(mp_even.find(v_even[i])==mp_even.end()){
            mp_even[v_even[i]]=1;
            if(mp_even[v_even[i]]>=max_even){
                max2_even=max_even;
                max_even=mp_even[v_even[i]];
                num_max_even=v_even[i];
            }
            else if(mp_even[v_even[i]]>max2_even){
                max2_even=mp_even[v_even[i]];
            }
        }
        else{
            mp_even[v_even[i]]++;
            if(mp_even[v_even[i]]>max_even){
                if(num_max_even!=v_even[i]){
                    max2_even=max_even;
                }
                max_even=mp_even[v_even[i]];
                num_max_even=v_even[i];
            }
            else if(mp_even[v_even[i]]>max2_even){
                max2_even=mp_even[v_even[i]];
            }
        }
    }
    
    int ans;
    if(num_max_odd==num_max_even){
        if(max_even+max2_odd>max2_even+max_odd){
            ans=n-(max_even+max2_odd);
        }
        else{
            ans=n-(max2_even+max_odd);
        }
    }
    else{
        ans=n-(max_even+max_odd);
    }
    //cout<<max_even<<endl << max_odd;
    //cout << "odd" << endl << "max_odd:" << max_odd << endl <<  "max2_odd:" << max2_odd << endl;
    cout << ans << endl;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
string s;cin>>s;
for(int j=s.length()-1;0<=j;j--){
    bool ans =true;
    for(int i=0;i<j/2;i++){
        if(j%2==0){
            if(s[i]!=s[i+j/2])ans=false;}
        else ans =false;
    }
    if(ans){cout << j << endl;return 0;}
}



    return 0;
}





Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

	long a, b, c;

	scanf("%ld %ld %ld", &a, &b, &c);

	if (a < b && b < c) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int ret=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return w*ret;
}
int n;
int a[]={0,100,101,102,103,104,105};
void dfs(int step,int tot)
{
	if(tot==n)
	{
		cout<<1<<endl;
		exit(0);
	}
	if(step==7) return;
	for(int i=0;tot+i*a[step]<=n;i++) dfs(step+1,tot+i*a[step]);
}
int main()
{
	cin>>n;
	dfs(1,0);
	cout<<0<<endl;
	return 0;
}

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

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;
const int MOD = 998244353;

/***************************************************************************/

ll power(ll a, ll n, ll m = MOD) {
	if(n == 0) return 1;
	ll p = power(a, n>>1, m);
	p = (p * p) % m;
	if(n & 1) p = (p * a) % m;
	return p;
}

ll fact[N], ifact[N];

void calculateFact() {

	fact[0] = 1;

	for(int i=1; i<N; i++) {
		fact[i] = (i * fact[i-1]) % MOD;
	}
	ifact[N-1] = power(fact[N-1], MOD-2, MOD);

	for(int i=N-1; i>=1; i--) {
		ifact[i-1] = (i * ifact[i]) % MOD;
	}
}

ll nck(int n, int k) {
	
	if(n < k || k < 0) return 0;

	ll ans = fact[n];
	ans = (ans * ifact[k]) % MOD;
	ans = (ans * ifact[n-k]) % MOD;

	return ans;
}

int k;
ll dp[2005][2005];

ll fun(int n, int m) {
	if(n == 0) return 1;
	if(n < 0) return 0;

	ll &memo = dp[n][m];
	if(memo != -1) return memo;
	ll ans = 0;

	if(m == 2) {
		ans = nck(n+k-2, k-2) + nck(n-1+k-2, k-2);
		if(ans >= MOD) ans -= MOD;
	}
	else if(m == 3) {
		ans = (nck(n+k-2, k-2) * 2 - nck(n+k-3, k-3) + MOD) % MOD;
	}
	else {
		ans = fun(n, m-2) - fun(n-2, m-2);
		if(ans < 0) ans += MOD;
	}
	return memo = ans;
}

vector<int> ans;

int main() {

	boost;
	calculateFact();

	int n; cin>>k>>n;
	memset(dp, -1, sizeof dp);

	for(int i=2; i<=k+1; i++) {
		ans.push_back(fun(n, i));
	}
	for(int i=ans.size()-2; i>=0; i--) {
		ans.push_back(ans[i]);
	}

	for(auto it : ans) {
		cout<<it<<"\n";
	}
	return 0;
}

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

using namespace std;

int a[4444], b[4444], dp[2][3333][3333];

int main() {
    int n, t, v = 0;
    cin >> n >> t;
    for(int i=0;i<n;i++) cin >> a[i] >> b[i];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<t;i++) {
        if(i < a[0]) dp[0][i][0] = 0;
        else dp[0][i][0] = b[0];
        if(i < a[n-1]) dp[1][i][n-1] = 0;
        else dp[1][i][n-1] = b[n-1];
    }
    for(int i=1;i<n;i++) {
        for(int j=1;j<t;j++) {
            dp[0][j][i] = max(dp[0][j-1][i],dp[0][j][i-1]);
            if(j >= a[i]) dp[0][j][i] = max(dp[0][j][i],dp[0][j-a[i]][i-1]+b[i]);
            dp[1][j][n-i-1] = max(dp[1][j-1][n-i-1],dp[1][j][n-i]);
            if(j >= a[n-i-1]) dp[1][j][n-i-1] = max(dp[1][j][n-i-1],dp[1][j-a[n-i-1]][n-i]+b[n-i-1]);
        }
    }
    int r = 0;
    for(int i=0;i<n;i++) {
        for(int j=0;j<t;j++) {
            int d1=0, d2=0;
            if(i > 0) d1 = dp[0][j][i-1];
            if(i < n-1) d2 = dp[1][t-j-1][i+1];
            r = max(r,b[i] + d1 + d2);
        }
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 87040
from heapq import heappush, heappop
from math import inf

import numpy as np


n = int(input())
A = []
[heappush(A, (-v, i)) for i, v in enumerate(map(int, input().split()), 1)]
dp = np.full((n + 1, n + 1), -inf, dtype=int)
dp[0, 0] = 0

for i in range(n):
    v, j = heappop(A)
    v = -v
    dp[i + 1, 1:] = dp[i, :-1] + v * np.abs(j - np.arange(1, n + 1))
    dp[i + 1, :-1] = np.maximum(dp[i, :-1] + v * np.abs(j - np.arange(n - i, n + n - i)), dp[i + 1, :-1])

print(dp[-1,].max())


Measured memory_bytes: 58512
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    //int t = 1; cin >> t; while(t--)
    {
    	int n, r;
    	cin >> n >> r;

    	if(n >= 10)
    		cout << r << '\n';
    	else
    		cout << r + 100 * (10 - n) << '\n';
    	
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, k;
int a[100000];

int gcd(int a, int b) {
    while (b) a %= b, swap(a, b);
    return a;
}

int main() {
    scanf("%d%d", &n, &k);
    forn(i, n) scanf("%d", a + i);
    int g = 0;
    forn(i, n) g = gcd(g, a[i]);
    int mx = 0;
    forn(i, n) mx = max(mx, a[i]);
    if (mx >= k && k % g == 0) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
H, W = map(int, input().split())
G = [list(map(int, input().split())) for i in range(H)]

N = 0
ans = []
# 奇数枚だけ右に寄せる(動かすのは1枚）、途中で奇数が見つかればそこで終わり
for h in range(H):
    for w in range(W-1):
        if G[h][w] % 2 == 1:
            G[h][w] -= 1  # 1枚だけ取り出す
            now_w = w
            for x in range(w+1, W):
                N += 1
                ans.append([h+1, now_w+1, h+1, x+1])
                now_w += 1
                #  奇数がみつかればそこに移動して終わり
                if G[h][x] % 2 == 1:
                    G[h][x] += 1
                    break
            else:
                G[h][W-1] += 1

# 右に集まったので同じように上から見ていく
for h in range(H):
    if G[h][W-1] % 2 == 1:
        G[h][W-1] -= 1
        now_h = h
        for y in range(h+1, H):
            N += 1
            ans.append([now_h+1, W, y+1, W])
            now_h = y
            #  奇数が見つかれば終わり
            if G[y][W-1] % 2 == 1:
                G[y][W-1] += 1
                break
        else:
            G[H-1][W-1] += 1

print(N)
for a in ans:
    print(" ".join(map(str, a)))


Measured memory_bytes: 67164
#include<iostream>
#include<string>
using namespace std;
long long a,b,k,ao,ta;

int main(){
    cin >> a >> b >> k;
    if(a-k <= 0){
        ao = b+(a-k);
        ta = 0;
    }else{
        ao = b;
        ta = a-k;
    }
    if(ao <= 0){
        ao = 0;
    }
    cout << ta << " " << ao << endl;
}

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

int main(){
	string str, com, p;
	int q, a, b;

	cin >> str >> q;
	for(int t=0;t<q;t++){
		cin >> com >> a >> b;
		if(com == "print"){
			cout << str.substr(a, b-a+1) << endl;
		}else if(com == "reverse"){
			string tmp = str.substr(a, b-a+1);
			int n = tmp.size();
			for(int i=0;i<n;i++) str[i+a] = tmp[n-i-1];
		}else if(com == "replace"){
			cin >> p;
			str = str.replace(a,b-a+1,p);
		}
	}

	return 0;
}

Measured memory_bytes: 3212
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>
#include <map>

using namespace std;

int main() {
  while( true ) {
    int n;
    cin >> n;
    if ( n == 0 ) break;
    map<int, int> ms;
    for ( int i = 0; i < n; i++ ) {
      int val;
      cin >> val;
      ms[ val ] = ms[ val ] + 1;
    }
    bool exist = false;
    for ( auto elem : ms ) {
      if ( elem.second > n / 2 ) {
	exist = true;
	cout << elem.first << endl;
	break;
      }
    }
    if ( not exist ) {
      cout << "NO COLOR" << endl;
    }
  }
}

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


int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> L(M);
  vector<int> R(M);
  
  for (int i = 0; i < M; i++) {
    cin >> L.at(i) >> R.at(i);
  }
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    if (i+1 >= L.at(M-1)  && i+1 <= R.at(0)) {
      count++;
    }
  }
  cout << count << endl;
  
  
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<int64_t MOD> struct Mint {
    int64_t v;
    Mint() { v = 0; }
    Mint(int64_t x) { v = x % MOD; if(v < 0)  v += MOD; }

    Mint operator-() { return Mint{-v}; };
    Mint operator+(Mint x) { return Mint(v + x.v); };
    Mint operator-(Mint x) { return Mint(v - x.v); };
    Mint operator*(Mint x) { return Mint(v * x.v); };
    Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

    Mint& operator+=(Mint x) { return *this = (*this + x); };
    Mint& operator-=(Mint x) { return *this = (*this - x); };
    Mint& operator*=(Mint x) { return *this = (*this * x); };
    Mint& operator/=(Mint x) { return *this = (*this / x); };

    static Mint pow(Mint base, int64_t exp) {
        if(exp == 0)  return Mint(1);
        return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
    }

    friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

template<class T> struct Counting {
    Counting(int64_t n) {
        _fact.assign(n+1, 1);
        for(int64_t i = 1; i <= n; i++)  _fact[i] = T(i) * _fact[i-1];
    }

    T fact(int64_t n) {
        assert(0 <= n && n < (int)_fact.size());
        return _fact[n];
    }

    T perm(int64_t n, int64_t k) {
        if(n < k)  return 0;
        return fact(n) / fact(n-k);
    }

    T comb(int64_t n, int64_t k) {
        if(n < k)  return 0;
        return fact(n) / (fact(k) * fact(n-k));
    }

    private:
        vector<T> _fact;
};

Counting<mint> cnt(2123456);
mint g(lint r, lint c) {
    return (mint(c+2) * cnt.comb(c+r+2, r) - mint(r+1)) / mint(r+1);
}

int main() {
    lint r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    cout << g(r2,c2) - g(r2,c1-1) - g(r1-1,c2) + g(r1-1,c1-1) << endl;
}

Measured memory_bytes: 16896
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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 gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);

    if(a == b) return false;

    if(a < b) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

int main(){
  ll n; int m; cin >> n >> m;
  vi a(m),b(m);
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  vl ans(m);
  ans[m-1] = n*(n-1)/2;

  UnionFind Uni(n);

  rrep(i,m) {
    if(i == 0) continue;
    ans[i-1] = ans[i];
    if(Uni.root(a[i]) != Uni.root(b[i])){
      ans[i-1] -= (ll)Uni.size(a[i])*Uni.size(b[i]);
      Uni.merge(a[i], b[i]);
    }
  }
  rep(i,m) cout << ans[i] << endl;
}

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

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main()
{
  int n, m;
  cin >> n >> m;
  UnionFind<int> uf(n);
  rep(i,m)
  {
    int l, r, d;
    cin >> l >> r >> d;
    --l;--r;
    if(uf.issame(l, r))
    {
      int diff = uf.diff(l,r);
      if(diff != d)
      {
        cout << "No" << endl;
        return 0;
      }
    }
    else
    {
        uf.merge(l,r,d);
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> 				void _DO(I&&x){	cerr<<x<<endl;	}
template<typename I,typename...T>	void _DO(I&&x,T&&...tail){	cerr<<x<<" , ";	_DO(tail...);	}
template<typename _a,typename _b> 	ostream& operator << (ostream &_s,const pair<_a,_b> &_p)
{	return _s<<'('<<_p.first<<','<<_p.second<<')';	}
#define IOS
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define stp setprecision(30)<<fixed
const ll INF=0x3f3f3f3f3f3f3f3f;
const int NF=0x3f3f3f3f;
const ll MAX=1e5+5,Mlg=__lg(MAX)+2;
const ll MOD=1e9+7;
// ready~ go!
// let's coding and have fun!
// I can't solve this problem
ll a,b,c,x,y;
int main(){
	IOS
	cin>>a>>b>>c>>x>>y;
	x*=2;	y*=2;
	ll ans=INF;
	for(ll i=0;i<=max(x,y);i++){
		ans=min(ans,i*c+ ( x-i>0 ? ((x-i-1)/2+1)*a:0 ) + ( y-i>0 ? ((y-i-1)/2+1)*b:0 )  );
		debug(ans,i);
	}
	cout<<ans<< '\n';
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int num, n, k, ans;
int main() {
	scanf("%d\n%d", &n, &k);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &num);
		ans += 2*min(num, abs(k-num)); 
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>

typedef long long ll;

using namespace std;

int main() {
    ll n, k;
    cin >> n >> k;

    ll r = n % k;

    if (k - r  < r) {
        r = k - r;
    }
    
    cout << r;

    return 0;
}

Measured memory_bytes: 256
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    return n,a,b

def main(n,a,b):
    sum=0
    for i in range(n):
        hp=b[i]
        use0=min(hp,a[i])
        a[i]-=use0
        hp-=use0
        sum+=use0
        if hp>0:
            use1=min(hp,a[i+1])
            a[i+1]-=use1
            sum+=use1
    
    return sum

if __name__=='__main__':
    n,a,b=readinput()
    ans=main(n,a,b)
    print(ans)


Measured memory_bytes: 24184
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;
typedef unsigned long long ull;

inline int scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
using namespace std;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll cha = n-k;
    ll ans = (1+cha)*cha/2;

//    cout << ans << endl;
    ll ji = 1;
    ll ij = 1;
    for(ll i = cha; i >= 1; i--)
    {
//        if(ji <= k)
//        {
            ll kk = i/(k+ij)*ij;
            if((i%(k+ij))-k > 0)kk += (i%(k+ij))-k;
//            cout << kk << endl;
            ans += kk;
            ij++;
//            if(i%k == )
//        }
//        ji++;
    }
    if(k == 0)ans -= n;
    cout << ans << endl;
    return 0;
}
/*
                 ___====-_  _-====___
           _--^^^#####//      \\#####^^^--_
        _-^##########// (    ) \\##########^-_
       -############//  |\^^/|  \\############-
     _/############//   (@::@)   \\############\_
    /#############((     \\//     ))#############\
   -###############\\    (oo)    //###############-
  -#################\\  / VV \  //#################-
 -###################\\/      \//###################-
_#/|##########/\######(   /\   )######/\##########|\#_
|/ |#/\#/\#/\/  \#/\##\  |  |  /##/\#/  \/\#/\#/\#| \|
`  |/  V  V  `   V  \#\| |  | |/#/  V   '  V  V  \|  '
   `   `  `      `   / | |  | | \   '      '  '   '
                    (  | |  | |  )
                   __\ | |  | | /__
                  (vvv(VVV)(VVV)vvv)
                  ÁúÉñ±£ÓÓ ÓÀÎÞbug
*/


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll L,T,X[100001];
	int W[100001];
	vll ans;
	ll collisionnumall=0;
	ll X0zahyo;
	scan(N);scan(L);scan(T);
	rep(i,N){
		scan(X[i]);scan(W[i]);
		if(W[i]==1){
			ans.push_back((X[i]+T)%L);
			if(i==0) X0zahyo=(X[i]+T)%L;
		}
		else{
			ll tmp=(X[i]-T)%L;
			if(tmp<0) tmp+=L;
			ans.push_back(tmp);
			if(i==0) X0zahyo=tmp;
		}
		if(i!=0&&W[i]!=W[0]){
			double initialcoltime;
			if(W[0]==1){
				initialcoltime=(double)(X[i]-X[0])/2+eps;
			}
			else{
				initialcoltime=(double)(X[0]+L-X[i])/2+eps;
			}
			double colcadance=(double)L/2+eps;
			ll colnum;
			if(initialcoltime>=T) colnum=0;
			else colnum=(ll)((T-initialcoltime)/colcadance)+1;
			collisionnumall+=colnum;
		}
	}
	sort(ans.begin(),ans.end());
	ll X0indexbase;
	if(W[0]==1){
		X0indexbase=lower_bound(ans.begin(),ans.end(),X0zahyo)-ans.begin();
	}
	else{
		X0indexbase=upper_bound(ans.begin(),ans.end(),X0zahyo)-ans.begin()-1;
	}
	ll X0index;
	if(W[0]==1){
		X0index=X0indexbase-collisionnumall;
		X0index%=N;
		if(X0index<0) X0index+=N;
	}
	else{
		X0index=X0indexbase+collisionnumall;
		X0index%=N;
		if(X0index<0) X0index+=N;
	}
	rep(i,N){
		prin(ans[(X0index+i)%N]);
	}
	return 0;
}


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    if(n == m)cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
n = input()
if n == 'SUN':
  print('7')
elif n == 'MON':
  print('6')
elif n == 'TUE':
  print('5')
elif n == 'WED':
  print('4')
elif n == 'THU':
  print('3')
elif n == 'FRI':
  print('2')
elif n == 'SAT':
  print('1')

Measured memory_bytes: 3060