akhauriyash/Code-Regression huggingface dataset:
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		lr: [(usize, usize); n],
	}

	let mut ans = 0;
	for i in 0..n {
		ans += lr[i].1 - lr[i].0 + 1;
	}
	println!("{}", ans);
}



Measured memory_bytes: 2092
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	sort(A);
	rep(i, N - 1) {
		if (A[i] == A[i + 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define kai "\n"
#define yuque priority_queue
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define lob lower_bound
#define upb upper_bound
#define nep next_permutation
#define MOD 1000000007ll
#define MIN (1e-10)
#define equal(a,b) (abs((a)-(b))<MIN)
#define v2 ten
#define chokusen senbun
#define tenten senbun
#define takaku vec<ten>
using namespace std;
void solve();
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed;
	solve();
}
struct pea{
	ll f,s;
	bool operator<(const pea &p)const{
		return f!=p.f?f<p.f:s<p.s;
	};
};
struct tri{
	ll f,s,t;
	bool operator<(const tri &p)const{
		if(f!=p.f)return f<p.f;
		if(s!=p.s)return s<p.s;
		return t<p.t;
	};
};
class ten{
public:
	ld x,y;
	ten operator+(ten p){return{x+p.x,y+p.y};}
	ten operator-(ten p){return{x-p.x,y-p.y};}
	ten operator*(ld k){return{k*x,k*y};}
	ten operator/(ld k){return{x/k,y/k};}
	ld abs(){return sqrt(abs2());}
	ld abs2(){return x*x+y*y;};
	bool operator<(const ten &p)const{return x!=p.x?x<p.x:y<p.y;};
	bool operator==(const ten &p)const{return (-MIN<x-p.x)&&(x-p.x<MIN)&&(-MIN<y-p.y)&&(y-p.y<MIN);};
	ld naiseki(v2 b){return x*b.x+y*b.y;}
	ld gaiseki(v2 b){return x*b.y-y*b.x;}
};
struct senbun{ten p1,p2;};
struct en{ten o;ld r;};
//0-1 ナップザック問題
ll maxvalue(ll W,const vll &v,const vll &w,vll &select){
	ll n=v.size();
	vec<vll> dp(n+1,vll(W+1,0));
	vec<vec<bool>> tuika(n+1,vec<bool>(W+1,false));
	rep(i,1,n+1){
		rep(j,1,W+1){
			if(j-w[i-1]>=0&&dp[i-1][j-w[i-1]]+v[i-1]>dp[i-1][j]){
				dp[i][j]=dp[i-1][j-w[i-1]]+v[i-1];
				tuika[i][j]=true;
			}else dp[i][j]=dp[i-1][j];
		}
	}
	ll ww=W;select.clear();
	rrep(i,n,1){
		if(tuika[i][ww]){
			select.pub(i-1);
			ww-=w[i-1];
		}
	}
	reverse(ALL(select));
	return dp[n][W];
}
void solve(){
	ll n,W;cin>>n>>W;
	vll v(n),w(n);
	rep(i,0,n)cin>>v[i]>>w[i];
	vll ans;
	cout<<maxvalue(W,v,w,ans)<<kai;
}


Measured memory_bytes: 11000
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,k;
	cin>>n>>k;
	int t=1;
	rep(i,n){
		if(t<k)t+=t;
		else t+=k;
	}
	cout<<t<<endl;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
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(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    iosetup;
    string S; cin >> S;
    int ans = 1;
    rep(i, 1, S.size() / 2){
        if(S.substr(0, i) == S.substr(0 + i, i)) chmax(ans, i);
    }
    cout << ans * 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100000

int parent(int i) {return i / 2;}
int left(int i) {return i * 2;}
int right(int i) {return i * 2 + 1;}

int main(){
  int H,A[MAX + 1];

  cin >> H;
  for(int i=1; i <= H; ++i)  cin >> A[i];

  for(int i=1; i <= H; ++i){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
    if(left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
    if(right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }



  return 0;
}



Measured memory_bytes: 3112
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <climits>
#include <deque>
#include <map>
#include <deque>
#include <iomanip>
#include <cmath>
#include <functional>
#include <set>
#include <list>
#include <bitset>
#include <stack>
#include <stdio.h>
#define endl '\n'
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
typedef pair<ll,ll> pll;
int main()
{
    /*
for reading from input.txt and writing on output.txt
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
*/
    cin.sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;cin>>n;
    if(n&1)
    {
        cout<<0<<endl;
        return 0;
    }
    else
    {
        n/=2;
        ll ans=0;
        ll d=5;
        while(n/d)
        {
            ans+=n/d;
            d=d*5;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
  int n, a[101], max = 0;

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

  for(int i = 0; i < n - 1; i++){
    for(int j = i + 1; j < n; j++){
      if(abs(a[i] - a[j]) > max)
        max = abs(a[i] - a[j]);
    }
  }

  cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
double pi = 3.141592653589793;
ll mod = 1000000007;

int d[10][10];
int V = 10;

void warshallFloyd() {
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> d[i][j];
        }
    }
    warshallFloyd();
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int x;
            cin >> x;
            if (x != -1) {
                ans += d[x][1];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N, T, A[100001];
	scanf("%d %d", &N, &T);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	int min = 1 << 30, max = 0, ans = 0;
	for (i = 1; i <= N; i++) {
		if (A[i] < min) min = A[i];
		if (A[i] - min > max) {
			max = A[i] - min;
			ans = 1;
		} else if (A[i] - min == max) ans++;
	}

	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


struct Robo
{
	int x, y, clean;
	Robo(int x, int y, int clean)
		: x(x), y(y), clean(clean) { };
};
int main()
{
	int w, h;
	while (cin >> w >> h, w)
	{
		static char c[32][32];
		int sx, sy;
		int kitanai = 0;
		for (int y = 0; y < h; ++y)
		{
			cin >> c[y];
			for (int x = 0; x < w; ++x)
			{
				if (c[y][x] == 'o')
					sx = x, sy = y;
				else if (c[y][x] == '*')
					c[y][x] = '0' + kitanai++;
			}
		}

		static int d[20][20][1 << 10];
		const int INF = 1 << 25;
		for (int y = 0; y < h; ++y)
			for (int x = 0; x < w; ++x)
				for (int i = 0; i < 1 << kitanai; ++i)
					d[y][x][i] = INF;

		queue<Robo> q;
		q.push(Robo(sx, sy, (1 << kitanai) - 1));
		d[sy][sx][(1 << kitanai) - 1] = 0;
		int res = -1;
		while (!q.empty())
		{
			Robo r = q.front(); q.pop();

			int nclean = r.clean;
			if (isdigit(c[r.y][r.x]))
			{
				int w = c[r.y][r.x] - '0';
				if (r.clean & (1 << w))
				{
					nclean ^= 1 << w;
					if (!nclean)
					{
						res = d[r.y][r.x][r.clean];
						break;
					}
				}
			}

			int nc = d[r.y][r.x][r.clean] + 1;
			for (int i = 0; i < 4; ++i)
			{
				int nx = r.x + dx[i], ny = r.y + dy[i];
				if (0 <= nx && nx < w && 0 <= ny && ny < h
					&& c[ny][nx] != 'x' && nc < d[ny][nx][nclean])
				{
					q.push(Robo(nx, ny, nclean));
					d[ny][nx][nclean] = nc;
				}
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
    ll n,k;
    cin >> n >> k;
    ll ans = INT_MAX;
    if(n>=k) {
        n = n%k;
        ans = n;
    }
    if(k>n) {
        ans = n%k;
        n = abs(n-k);
        ans = min(ans, n);
    }

    cout << ans <<endl;
}

signed main() {
    boost;
    solve();
}

Measured memory_bytes: 256
#include<stdio.h>
int n,A[50];
int solve(int i,int m){
	int res;
	if(m==0)return 1;
	if(i>=n)return 0;
	res=solve(i+1,m)||solve(i+1,m-A[i]);
	return res;
}
int main(void){
	int q,M,i;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&M);
		if(solve(0,M))printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

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

using ll = long long;

// c++ allows passing an array with
// atleast one dimension defined

ll knapsack_dp(int p[][2], int n, int W)
{
    int  value, weight;
    ll dp[n+1][W+1];

    for(int i=0; i<=n; ++i)
    {
        value = p[i-1][1];
        weight = p[i-1][0];

        for(int w=0; w<=W; w++)
            if (i==0 | w == 0)
                dp[i][w] = 0;
            else if(w - weight>= 0)
                dp[i][w]= max(dp[i-1][w-weight] + value, dp[i-1][w]);
            else
                dp[i][w]= dp[i-1][w];
    }
    
    return dp[n][W];
    
}

int main()
{
    int N, W;
    cin >> N >> W;

    int p[N][2];

    for(int i=0; i<N; i++)
        cin >> p[i][0] >> p[i][1];

    cout << knapsack_dp(p, N, W);
    return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using iii = pair<int, ii>;
using ll = long long;

int n, m;
char _mt[30][30];
char mt[30][30];

int32_t main(){
	scanf("%d %d", &n, &m);
	for(int i=0; i<n; ++i) scanf("%s", _mt[i]);
	
	int ans = 0;
	for(int _i=0; _i<n; ++_i){
		for(int _j=0; _j<m; ++_j){
			if(_mt[_i][_j]=='#') continue;
			for(int i=0; i<n; ++i) 
				for(int j=0; j<m; ++j) mt[i][j] = _mt[i][j];
			queue<iii> q;
			q.push({0, {_i, _j}});
			mt[_i][_j] = '#';
			while(not q.empty()){
				int d = q.front().ff;
				int i = q.front().ss.ff;
				int j = q.front().ss.ss; q.pop();
				ans = max(ans, d);
				if(i>0 and mt[i-1][j]!='#') q.push({ d+1, {i-1, j} }), mt[i-1][j]='#';
				if(i<n-1 and mt[i+1][j]!='#') q.push({ d+1, {i+1, j} }), mt[i+1][j]='#';
				if(j<m-1 and mt[i][j+1]!='#') q.push({ d+1, {i, j+1} }), mt[i][j+1]='#';
				if(j>0 and mt[i][j-1]!='#') q.push({ d+1, {i, j-1} }), mt[i][j-1]='#';
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,d,s,n;
  while(scanf("%d",&n)!=EOF){
    s=0;
    if(n>2000)n=4000-n;
    for(a=0;a<1001;a++){
      if(a>n)break;
      for(b=0;b<1001;b++){//printf("%d %d %d\n",a,b,c);
	if((a+b>n)/*||(n-(a+b)>2000)*/)break;
	for(c=0;c<1001;c++){
	  if(n-(a+b+c)<1001){
	    if(n-(a+b)<1001){
	      s+=n-(a+b+c);
	      s++;
	      break;
	    }
	    else{
	      s+=1000-c;//printf("%d",n-(a+b));
	      s++;
	      break;
	    }
	  }
	}
      }
    }
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 110
using namespace std;
ll n,k,num[N];
int main(){
	ll i,j,d,x,ans=0;
	cin>>n>>k;
	for(i=0;i<k;i++)
	{
		cin>>d;
		for(j=0;j<d;j++)
		{
			cin>>x;
			x--;
			num[x]++;
		} 
	}
	for(i=0;i<n;i++)
	{
		if(num[i]==0)
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll t[200005];
int main() {
	ll n, T;
	cin >> n >> T;
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}
	ll ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (t[i] + T <= t[i + 1]){
			ans += T;
		}
		else {
			ans += t[i + 1] - t[i];
		}
	}
	cout << ans + T << endl;
	return 0;
}

Measured memory_bytes: 1920
a, b, c, x, y = map(int, input().split())

res = a*x + b*y
for i in range(1, max(x, y)+1):
    ab = i*2
    cand = ab*c + a*max(0, x-i) + b*max(0, y-i)

    res = min(res, cand)

print(res)

Measured memory_bytes: 9188
#ifndef _WIN32
#include<iostream>
#endif

using namespace std;
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<iomanip>
#include<stack>
#include<set>
#include<functional>
#include<map>

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int dr[] = { 0, 1, 0, -1 };
const int dc[] = { 1, 0, -1, 0 };

int f1[212][212];
int f2[212][212];

int a[3123];
int b[3123];
int c[3123];

typedef vector<int> V;
typedef vector<V> VV;
int N, M;
map<string, int> sato;
void init(){
	sato.clear();
	REP(i, 212)REP(j, 212){
		f1[i][j] = 0;
		f2[i][j] = 1;
	}
}

string nobu[212];

int dfs(int v, int t,V &used,VV &g,int cc){
	if (v == t&&cc==0)return 1;
	if (used[v])return 0;
	used[v] = 1;
	int res = 0;
	for (auto &e : g[v]){
		int u = b[e];
		//cout << "edge:"<<nobu[v] << " " << nobu[u] << endl;
		res |= dfs(u, t, used, g,(cc+c[e])%2);

	}
	return res;
}
int main(){
	while (cin >> N, N){
		init();
		int id = 0;
		REP(i, N){
			string xy;
			cin >> xy;
			int pos = 0;
			while (xy[pos] != '-')pos++;
			auto x = xy.substr(0, pos);
			auto y = xy.substr(pos+1, xy.size() - pos-1);

			if (sato.count(x) == 0)sato[x] = id++;
			if (sato.count(y) == 0)sato[y] = id++;
			a[i] = sato[x];
			b[i] = sato[y];
			c[i] = 1;
		}
		VV g(id);
		REP(i, N){
			g[a[i]].push_back(i);
		}
		for (auto &it : sato)nobu[it.second] = it.first;

		REP(i, N)FOR(j, i + 1, N){
			if (a[i] == a[j])f1[b[i]][b[j]] = f1[b[j]][b[i]] = 1;
			if (b[i] == b[j])f1[a[i]][a[j]] = f1[a[j]][a[i]] = 1;
			if (a[i] == b[j])f2[a[j]][b[i]] = f2[b[i]][a[j]] = 0;
			if (b[i] == a[j])f2[a[i]][b[j]] = f2[b[j]][a[i]] = 0;
		}

		REP(i, id)FOR(j, i + 1, id)if (f1[i][j] && f2[i][j]){
			a[N] = i;
			b[N] = j;
			c[N] = 0;
			g[i].push_back(N++);
			a[N] = j;
			b[N] = i;
			c[N] = 0;
			g[j].push_back(N++);
			//cout << nobu[i] << " " << nobu[j] << endl;
		}

		cout << id << endl;

		int M;
		cin >> M;


		REP(_, M){
			string xy;
			cin >> xy;
			int pos = 0;
			while (xy[pos] != '-')pos++;
			auto x = xy.substr(0, pos);
			auto y = xy.substr(pos+1, xy.size() - pos-1);
			if (sato.count(x) == 0 || sato.count(y) == 0){ cout << "NO" << endl; continue; }
			int xx = sato[x];
			int yy = sato[y];
			V used(id, 0);
			if (dfs(xx, yy, used, g, 1))cout << "YES" << endl;
			else cout << "NO" << endl;

		}
	}



	return 0;
}

Measured memory_bytes: 3468
//what the fuck was this question
#include <bits/stdc++.h> 
using namespace std;
typedef unsigned long long int ll;
#define f(i,a,b) for(ll i = a; i < b; i++)
bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
  
vector <ll> primeFactors(ll n)  
{  
    // Prll the number of 2s that divide n 4
    vector <ll> v;
    while (n % 2 == 0)  
    {  
        v.push_back(2);  
        n = n/2;  
    }  
  
    // n must be odd at this poll. So we can skip  
    // one element (Note i = i +2)  
    for (ll i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, prll i and divide n  
        while (n % i == 0)  
        {  
            v.push_back(i);  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        v.push_back(n);  
        
        return v;
}  
  
  
int main() {
    
       ll n;
       
       cin>>n;
       if(isPrime(n))
       {
           cout<<"1";
           return 0;
       }
       vector <ll> v;
       v = primeFactors(n);
       ll  c = 0;
       ll ans = 0;
       ll j;
       f(i,0,v.size())
       {
           c = 0;
           while(n%v[i] == 0)
           {
               n /= v[i];
               c++;
           }
           for(j=1;j < 1000000;j++)
           {
               if(j*(j+1)/2 > c)
               break;
           }
           ans  += j-1;
           
       }
       cout<<ans;
	return 0;
 
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string>) {}
template<typename T1,typename T2> ostream& operator<<(ostream& os, pair<T1,T2> buf) {
  return os << "(" << buf.first << ": " << buf.second << ")"; }
#define DefOut(Con) template<typename T>ostream&operator<<(ostream&os,Con<T>&A){ bool f = false; os << "{"; \
  for (const auto e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
#define DefOut2(Con) template<typename K,typename V>ostream&operator<<(ostream&os,Con<K,V>&A) \
{ bool f = false; os << "{"; for (auto &e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
template<typename T>ostream &operator << (ostream &os,vector<vector<T>>& A) {
  for (auto &B: A) os << '\n' << B; return os; }
DefOut(vector) DefOut(set) DefOut(multiset) DefOut2(map) 
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1000000007;
long long const INF = 1e18;
#define PI 3.14159265358979323846
/***********************************************************************/
int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<i64> a(3), b(3);
  for (auto &z: a) cin >> z;
  for (auto &z: b) cin >> z;
  
  vector<i64> values(3);
  for (int i = 0; i < 3; ++i) {
    values[i] = b[i] - a[i];
  }
  vector<i64> dp(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (i - a[j] >= 0) uax(dp[i], values[j] + dp[i - a[j]]);
    }
  }
  int m = n + dp[n];
  dp.assign(m + 1, 0LL);
  for (int i = 1; i <= m; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (i - b[j] >= 0) uax(dp[i], -values[j] + dp[i - b[j]]);
    }
  }
  cout << m + dp[m] << '\n';
  
  return 0;
}


Measured memory_bytes: 195584
import java.util.*;
import java.text.*;

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        for(;;) {
            int n = sc.nextInt();
            if(n == 0) break;
            int [] xs = new int[n];
            long s = 0;
            for(int i = 0; i < n; i++) {
                xs[i] = sc.nextInt();
                s += xs[i];
            }
            double m = s / (double) n;
            double d = 0;
            for(int i = 0; i < n; i++) {
                d += (xs[i] - m) * (xs[i] - m);
            }
            d /= n;
            NumberFormat format = NumberFormat.getInstance();
            format.setMaximumFractionDigits(5);
            format.setMinimumFractionDigits(5);
            format.setGroupingUsed(false);
            System.out.println("" + format.format(Math.sqrt(d)));
        }
    }
}

Measured memory_bytes: 23800
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(n)]
wv.sort(key=lambda x:-x[1])
wv.sort(key=lambda x:x[0])
#print(wv)
w0=wv[0][0]
x=[[0],[0],[0],[0]]
for i in range(n):
    if wv[i][0]==w0:
        k=wv[i][1]+x[0][-1]
        l=len(x[0])
        if l*w0<=w:x[0].append(k)
    elif wv[i][0]==w0+1:
        k=wv[i][1]+x[1][-1]
        l=len(x[1])
        if l*(w0+1)<=w:x[1].append(k)
    elif wv[i][0]==w0+2:
        k=wv[i][1]+x[2][-1]
        l=len(x[2])
        if l*(w0+2)<=w:x[2].append(k)
    else:
        k=wv[i][1]+x[3][-1]
        l=len(x[3])
        if l*(w0+3)<=w:x[3].append(k)
#print(x)
ma=0
for i in range(len(x[0])):
    for j in range(len(x[1])):
        for k in range(len(x[2])):
            for l in range(len(x[3])):
                if i*w0+j*(w0+1)+k*(w0+2)+l*(w0+3)<=w:
                    ma_sub=x[0][i]+x[1][j]+x[2][k]+x[3][l]
                    ma=max(ma,ma_sub)
                else:
                    break
print(ma)


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;
int main(){
	int m,f,b,sum;
	cin>>m>>f>>b;
	sum=m+f;
	if(sum<b)cout<<"NA"<<endl;
	else if(m>=b)cout<<"0"<<endl;
	else if(sum>=b&&m<b)cout<<b-m<<endl;
	return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <unistd.h>
#include <map>

#define pii pair<int,int>
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;


typedef long long ll;
static const ll INF = 1000000000000000000LL;
static const ll MOD = 1000000007;


int main()
{
    ll n,a,b;
    cin >> n >> a >> b;
    if(a == 0 && b == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    ll res = 0;
    res += (n /(a+b)) * a;
    ll tmp = n % (a+b);
    res += min(tmp, a);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N;
    bool isYes = false;

    cin >> N;

    if(N % 10 == 7){
        isYes = true;
    }

    int tmp1 = N % 10;
    tmp1 = N - tmp1;
    tmp1 = tmp1 % 100;
    if(tmp1 / 10 == 7){
        isYes = true;
    }

    int tmp2 = N % 100;
    tmp2 = N -tmp2;
    if(tmp2 / 100 == 7){
        isYes = true;
    }

    if(isYes){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

bool comp(pair<int, pair< string, int > > l, pair<int, pair<string, int> > r){
    pair<string, int> a = l.second;
    pair<string, int> b = r.second;
    if(a.first != b.first){
        return a.first < b.first;
    } else {
        return a.second > b.second;
    }
}

int main(){
    int n;
    cin >> n;
    vector< pair<int, pair< string, int > > > v;
    for(int i = 1; i <= n; i++){
        string s;
        int p;
        cin >> s >> p;
        pair<string, int> t = make_pair(s, p);
        pair<int, pair<string, int> > h = make_pair(i, t);
        v.push_back(h);
    }
    sort(v.begin(), v.end(), comp);
    for(int i = 0; i < v.size(); i++){
        cout << v.at(i).first << endl;
    }
    return 0;
}

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

#define int long long

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

const int mod = 1e9+7;

int N;
auto dp = vectors(111, 9, 9, 9, -1); // dp[i][x][y][z]: i文字目までみたとき、iの3文字前がx、2文字前がy、1文字前がzのとき、AGC文字列以外の組み合わせの数
vector<int> AGCT = {'A', 'G', 'C', 'T'}; // 使用する文字リスト
// 文字とDPに使うインデックスの対応付け
map<char, int> mp = {
  {'A', 1},
  {'G', 2},
  {'C', 3},
  {'T', 4},
  {'*', 5}, // 「*」はA, G, C, Tのどれも使っていない状態
};

// 渡されたリストがAGCになるかの判定
bool isAGC(vector<int> C) {
  return C[0] == 'A' and C[1] == 'G' and C[2] == 'C';
}

int rec(int idx, int c3, int c2, int c1) {
  if (idx >= N) {
    return !isAGC({c3, c2, c1});
  }

  if (dp[idx][mp[c3]][mp[c2]][mp[c1]] != -1) {
    return dp[idx][mp[c3]][mp[c2]][mp[c1]];
  }

  int ret = 0;

  for (char now : AGCT) {
    vector<int> t = {c3, c2, c1, now};
    bool ok = true;

    // tがAGC文字列になるかを判定する
    if (isAGC({c3, c2, c1}) or isAGC({c2, c1, now})) {
      ok = false;
    }

    // tをスワップしてAGC文字列になるかを判定する
    for (int i = 0; i < AGCT.size()-1; i++) {
      vector<int> tt = t;
      swap(tt[i], tt[i+1]);
      if (isAGC({tt[0], tt[1], tt[2]}) or isAGC({tt[1], tt[2], tt[3]})) {
        ok = false;
      }
    }

    // tがAGC文字列にならないなら遷移させる
    if (ok) {
      Add(ret, rec(idx + 1, c2, c1, now));
    }
  }

  return dp[idx][mp[c3]][mp[c2]][mp[c1]] = ret;;
}

signed main() {
  cin >> N;

  int ans = rec(0, '*', '*', '*');

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 896
#B
n,k=map(int,input().split())
h_list=list(map(int,input().split()))
h1=abs(h_list[0]-h_list[1])
cst_list=[0,h1]
for i in range(2,n):
    x_list=[]
    for j in range(1,min(i+1,k+1)):
        x=cst_list[i-j]+abs(h_list[i]-h_list[i-j])
        x_list.append(x)
    cst_list.append(min(x_list))
print(cst_list[n-1])    

Measured memory_bytes: 85464
import java.util.*;
import java.io.PrintWriter;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		int[] p=new int[n];
		for(int i=0; i<n; i++){
			p[i]=sc.nextInt();
		}
		Arrays.sort(p);
		int ans=0;
		for(int i=0; i<k; i++){
			ans+=p[i];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 38728
h, w= map(int, input().split())
maze = [input() for i in range(h)]
maze_num =[[0] for i in range(h)]



maze_num =[[0]*w for i in range(h)]
for i in range(h):
    for k in range(w):
        maze_num[i][k] = [float("inf"), maze[i][k]]

maze_num[0][0][0] = 0

for i in range(h):
    for k in range(w):
        if i == h-1 and k ==w-1:
            break
        if k != w-1:
            if maze_num[i][k][1] =="#" and maze_num[i][k+1][1] ==".":
                maze_num[i][k+1][0] = min(maze_num[i][k+1][0], maze_num[i][k][0]+ 1)
            else:
                maze_num[i][k+1][0] = min(maze_num[i][k+1][0], maze_num[i][k][0])
        if i != h-1:
            if maze_num[i][k][1] =="#" and maze_num[i+1][k][1] ==".":
                maze_num[i+1][k][0] = min(maze_num[i+1][k][0], maze_num[i][k][0]+ 1)
            else:
                maze_num[i+1][k][0] = min(maze_num[i+1][k][0], maze_num[i][k][0])

if maze_num[h-1][w-1][1] =="#":
    print(maze_num[h-1][w-1][0] + 1)
else:
    print(maze_num[h-1][w-1][0])

Measured memory_bytes: 4212
#include<stdio.h>
#include<algorithm>
using namespace std;
int c[60];
int v[60];
int u[60];
int n;
int solve(int a,int b){
	if(b==0){
		bool ok=true;
		for(int i=0;i<n;i++)if(!u[i]){ok=false;break;}
		if(ok)return 1;
		int at=0;
		for(int i=0;i<n;i++){
			if(v[i]){
				v[i]=0;
				int res=solve(0,c[i]);
				if(res)return 1;
				v[i]=1;
			}
			if(!u[i])break;
		}
		return 0;
	}
	if(a==n)return 0;
	if(!u[a]&&b>=c[a]){
		u[a]=v[a]=1;
		if(solve(a+1,b-c[a]))return 1;
		u[a]=v[a]=0;
	}
	int rem=0;
	for(int i=a+1;i<n;i++)if(b>=c[i]&&!u[i])rem+=c[i];
	if(rem<b)return 0;
	return solve(a+1,b);
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		n=a;
		for(int i=0;i<a;i++)scanf("%d",c+i);
		for(int i=0;i<a;i++)c[i]=-c[i];
		std::sort(c,c+a);
		for(int i=0;i<a;i++)c[i]=-c[i];
		for(int i=0;i<a;i++)v[i]=u[i]=0;
		v[0]=u[0]=1;
		if(solve(0,0))printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 1016
#include <cstdio>
#include<string>


using namespace std;


int main()
{
    char a[6];
    scanf("%s", a);
    if(a[2]==a[3]&&a[4]==a[5]){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main (){
    int H,W,a,b,c;
    while(1){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0)break;
        for(a = 0;a < H;a++){
            for(b = 0;b < W;b++){
                if(a%2 == 0 && b%2 == 0 || a%2 == 1 && b%2 == 1){
                        printf("#");
                }
                if(a%2 == 1 && b%2 == 0 || a%2 == 0 && b%2 == 1){
                        printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    ll N;cin>>N;
    ll kouho=sqrt(N);
    if((kouho+1)*(kouho+1)<=N){
        cout<<(kouho+1)*(kouho+1)<<endl;
    }else if(kouho*kouho<=N){
        cout<<kouho*kouho<<endl;
    }else{
        cout<<(kouho-1)*(kouho-1)<<endl;
    }
}

Measured memory_bytes: 3684
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>	
#include <cmath>
#include <string>
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================


ll a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;

int main()
{
	cin >> s;
	if (s[0] == '7' || s[1] == '7' || s[2] == '7')
		cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

//long long a[1002];


int main()
{
	long long N, cnt = 0, tmp, ans = 1;

	cin >> N;
	
	string a = "";
	while (N != 0) {
		if (N%2 != 0) {
			N--;
			a = "1" + a;
		}
		else {
			a = "0" + a;
		}
		N /= -2;
	}

	if (a == "") a = "0";
	cout << a;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;


int main(){
    int N, K; cin >> N >> K;
    string S; cin >> S;

    char current = S[0];
    vector<int> compress;
    int count = 0;
    rep(i,N){
        if (current == S[i]){
            count++;
        }
        else{
            compress.push_back(count);
            count = 1;
            current = S[i];
        }
    }
    compress.push_back(count);

    vector<int> cum(compress.size()+1,0);
    rep(i,compress.size()){
        cum[i+1] = cum[i] + compress[i];
    }

    int now = 0;
    if (S[0] == '1') now++;
    
    int ans = 0;
    for (int i = 0; i < cum.size(); i++){
        int tmp = 0;
        int interval = 2*K;
        if (now == 1) interval++;
        if (i+interval < cum.size()){
            tmp = cum[i+interval] - cum[i];
        }
        else{
            tmp = cum[cum.size()-1] - cum[i];
        }

        ans = max(ans, tmp);
        now = abs(now-1);
    }

    cout << ans << endl;

}

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

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

A.sort(reverse=True)

gain = 0

n = 1
while n <= N-1:
  if n % 2:
    gain += A[(n-1)//2]
    # print(f'{n}, added {A[(n-1)//2]}')
  else:
    gain += A[(n+1)//2]
    # print(f'{n}, added {A[(n+1)//2]}')
  n += 1

print(gain)

Measured memory_bytes: 31608
#include<cstdio>
#include<cmath>
#include<algorithm>
#define EPS 1e-6	

struct pt {
	int x, y;
	pt(){};
	pt(int _x, int _y) : x(_x), y(_y){};


	bool operator<(pt p) {
		return(x < p.x || (x == p.x && y < p.y));
	}

	bool operator==(pt p) const {
		return(x == p.x && y == p.y);
	};
};

pt points[100];

inline pt operator-(pt a, pt b) {
	return pt(a.x-b.x, a.y-b.y);
}

inline double cross(pt a, pt b) {
	return(a.x*b.y - a.y*b.x);
}

inline double dot(pt a, pt b) {
	return (a.x*b.x + a.y*b.y);
}


void find(pt p, int numPoints) {
	pt pa, pb;
	bool cut = false;

	// assume that there is a horizontal line ray with 
	// p as its origin in the easterly direction
	for (int i = 0; i < numPoints; ++i) {
		if (p == points[i]) {
			printf("1\n");
			return;
		}
		
		pa = points[i] - p;
		pb = points[(i+1)%numPoints] - p;

		// assuming that they are orthogonal
		// check that vectors are parallel (since we are only using z, not x or y)
		// i.e. are collinear
		if (dot(pa, pb) <= EPS && cross(pa, pb) == 0) {
			printf("1\n");
			return;
		}

		// otherwise check if p-ray cuts across ab
		if (pa.y < pb.y) {
			pt temp = pa;
			pa = pb;
			pb = temp;
		}

		// pa points more up
		// pb points more down
		// i.e. ab is a vaguely vertical interval
		if (pa.y >= 0 && pb.y < 0) {
			// p-ray cuts between a and b
			if (cross(pa,pb) > 0) cut = (!cut);
		}

				
	}
	if (cut) {
		printf("2\n");
	} else {
		printf("0\n");
	}
}

int main() {
	int numPoints, numTests, val, a, b;
	scanf("%d", &numPoints);
	for (int i = 0; i < numPoints; ++i) {
		scanf("%d %d", &a, &b);
		points[i] = pt(a, b);
	}

	scanf("%d", &numTests);
	for (int i = 0; i < numTests; ++i) {
		scanf("%d %d", &a, &b);
		find(pt(a,b), numPoints);
	}

	return 0;
}


Measured memory_bytes: 2600
N=int(input())
*T, = map(int,input().split())
*A, = map(int,input().split())

mod = 10**9+7
mT = [T[0]]*N
MT = [T[0]]*N
for i,t in enumerate(T[1:],1):
    if t>T[i-1]:
        mT[i] = t
        MT[i] = t
    else:
        mT[i] = 1
        MT[i] = t
mA = [A[-1]]*N
MA = [A[-1]]*N
for i,a in enumerate(A[-2::-1],2):
    if a>A[-i+1]:
        mA[-i] = a
        MA[-i] = a
    else:
        mA[-i] = 1
        MA[-i] = a
m = [max(a,t) for a,t in zip(mA,mT)]
M = [min(a,t) for a,t in zip(MA,MT)]
ans = 1
for a,b in zip(m,M):
    ans *= max(0,b-a+1)
    ans %= mod
print(ans)

Measured memory_bytes: 18756
const main = input => {
  const inputs = input.trim().split('\n')
  const [N, D] = inputs[0].split(' ').map((x) => parseInt(x))

  let count = 0
  for (let i = 0; i < N; i++) {
    const [x, y] = inputs[i + 1].split(' ').map((a) => parseInt(a))
    if (x * x + y * y <= D * D) {
      count++;
    }
  }

  console.log(count)
}


// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 62520
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N; cin >> N;
	int P[N];
	map<int, int> mp;
	rep(i, N) cin >> P[i];
	rep(i, N) {
		mp[P[i]] = i;
	}
	int ans = 0;
	int tmp = 0;
	rep(i, N) {
		// cout << mp[i + 1] << " " << mp[i + 2] << endl;
		while (mp[i + 1] < mp[i + 2] && i < N) {
			tmp++;
			i++;
		}
		ans = max(ans, tmp);
		tmp = 0;
	}

	cout << N - ans - 1 << endl;



    return 0;
}


Measured memory_bytes: 10368
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000  // スタックの最大値

typedef struct{
  int top;         // スタックポインタ(一番上の位置)
  int S[MAX];
}Stack;


// スタック st の初期化
void initialize(Stack *st)
{
  st->top = 0;
  st->S[st->top] = 0;
}

// スタック st が空かどうかを確認
int isEmpty(Stack *st)
{
  return st->top == 0;
}

// スタック st が一杯かどうかを確認
int isFull(Stack *st)
{  
  return st->top >= MAX - 1;
}

// スタック st に要素 x をプッシュ(一番上に要素を追加)
void push(int x, Stack *st)
{
  if (isFull(st)) 
    exit(1);

  st->top++;
  st->S[st->top] = x;
}

// スタック st から要素をポップ(一番上の要素を取り出す)
int pop(Stack *st) {
  if (isEmpty(st)) 
    exit(1);

  st->top--;
  return st->S[st->top+1];
}


int main(void)
{
  Stack st1;     // '\' の開始位置を格納するスタック
  Stack st2_j;   // 各水たまりの最も左の'\' の位置を格納するスタック
  Stack st2_a;   // 各水たまりの水量を格納するスタック

  // スタック初期化
  initialize(&st1);
  initialize(&st2_j);
  initialize(&st2_a);

  char c;
  int sum = 0;  // 水たまりの総水量

  // 地形を読み込み，各水たまりの水量を計算
  for (int i = 0; (c = getchar()) != EOF; i++) {
    if (c == '\\') {                                 // '\' が出た時の処理
      // 位置 i を st1 にプッシュ(write your code)
    	push(i,&st1);
    }else if (!isEmpty(&st1) && c == '/') {          // '/' が出た時の処理
      // 水たまりの総水量 sum を更新(write your code)
      // st2_j と st2_a を用いて水たまりの水量を更新 
    	int j=pop(&st1);
    	sum+=i-j;
      int a = i - j;   // 更新する水たまりの水量を a に格納していく
      while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {  // 最も左の '\' の位置が j よりも大きい場合，以下を繰り返す
        // 水たまりの水量を求めていく (write your code)
      	pop(&st2_j);
      	a+=pop(&st2_a);
      }
      // 更新した水たまりの「最も左の'\' の位置」および「水量」を更新 (write your code)
    	push(j,&st2_j);
    	push(a,&st2_a);
    }
  }

  printf("%d\n", sum);       // 水たまりの総水量を出力
  printf("%d", st2_a.top);   // 水たまりの個数を出力

  // 各水たまりの水量を断面図の左から出力(スタックの底から出力)
  for (int i = 1; i <= st2_a.top; i++) 
    printf(" %d", st2_a.S[i]);  
  printf("\n");

  return 0;
}


Measured memory_bytes: 2144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            for (int i = 0; i < sS.Length; i++)
            {
              if (sS[i] == "0") { iOut = i + 1; }
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 25704
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vector<int> A, B;
string S, T;

void input() {
  int x, y, z;
  cin>>N;
  ;
}
void solve() {
  ;
  int ans = 1;

  cout<<N*N*N<<endl;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define L long long
using namespace std;
int main()
{
	string x;
	cin >> x;
	if (x == "Sunny")cout << "Cloudy";
	else if (x == "Rainy")cout << "Sunny";
	else { cout << "Rainy"; }
	return 0;
}


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

int main(){
  int n,x,t;
  cin >> n >> x >> t;

  int amari; //一杯に焼いた場合の端数
  amari = n % x;

  int a;//一杯に焼いた場合に焼く回数
  a = (n - amari) / x;
  int ans =0;
  ans = a * t;//一杯に焼いた場合にかかる時間

  if (amari == 0){
    cout << ans << endl;
  }
  else{
    ans = ans + t;
    cout << ans << endl;
  }
}

Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <iomanip>
#include <ios>
using namespace std;
int main(void){
  string s;
  cin >> s;
  int n = s.length();
  
  string ans = "";
  
  for(int i=0;i<n;i++){
    if(s[i] == '0')
      ans += '0';
    else if(s[i] == '1')
      ans += '1';
    else{
      if(ans.length())
        ans = ans.substr(0,ans.length() - 1);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256