akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve()
{
    int n;
    cin >> n;
    int ans = n / 3;
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define REP(i, n) for(long long i = 0; i < n; ++i)
#define FOR(i, a, b) for(long long i = a; i < b; ++i)
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    int n, p, ba;
    char card[101];

    while (~scanf("%d", &n)) {
        if (!n) break;
        ba = 0;
        int cnt[11] = {};
        for (int i = 0, p = 0; i < 100; ++i, p = (p == n - 1 ? 0 : p + 1)) {
            scanf(" %c", &card[i]);
            if (card[i] == 'M') cnt[p]++;
            else if (card[i] == 'S') { ba += cnt[p] + 1; cnt[p] = 0; }
            else { cnt[p] += ba + 1; ba = 0; }
        }
        sort(cnt, cnt + n);

        for (int i = 0; i < n; ++i) {
            if (i) printf(" ");
            printf("%d", cnt[i]);
        }
        printf(" %d\n", ba);
    }

    return 0;
}




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

int n, q;
string s;

int main(){
  cin >> n >> q >> s;
  int a[200000];
  rep(i, n){
    a[i] = 0;
  }
  for(int i = 1; i < n; i++){
    a[i] = a[i - 1];
    if(s.at(i - 1) == 'A' && s.at(i) == 'C'){
      a[i]++;
    }
  }
  //rep(i, n) cerr << a[i] << " ";
  
  rep(i, q){
    int l, r;
    cin >> l >> r;
    l--; r--;
    cout << a[r] - a[l] << endl;
  }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = a * c;
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << '\n';
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

Measured memory_bytes: 3632
#include<forward_list>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<iterator> 
#include<sstream>
#include<fstream>
#include<istream>
#include<utility>
#include<vector>
#include<stack>
#include<cmath>
#include<queue>
#include<deque>
#include<list>
#include<map> 
#include<set>
#define NinjaTurtle ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define infile freopen(".txt", "r", stdin);
#define outfile freopen(".txt", "w", stdout);
#define all(v) v.begin(),v.end()
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define ll long long 
#define endl "\n"
using namespace std;
int frq[10];
int main()
{
	NinjaTurtle
		string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);

	int n;
	cin>>n;
	string s1,s2;
	cin>>s1>>s2;
	bool flag=false;
	deque<string> prefix;
	deque<string> suffix;
	for(int i=s1.length();i>=0;i--)
	{
		suffix.push_back(s1.substr(i));
	}
	for(int i=0;i<=s2.length();i++)
	{
		prefix.push_back(s2.substr(0,i));
	}
	int pointer=-1;
	for(int i=1;i<prefix.size();i++)
	{
	//	cout<<prefix[i]<<" "<<suffix[i]<<'\n';
		if(prefix[i]==suffix[i])
		{
			pointer=i;
			//break;
		}
	}
	if(pointer==-1)
	{
		cout<<(s1.length()+s2.length());
	}
	else
	{
		cout<<(s1.length()+s2.length()-pointer);
	}
	cout<<'\n';
}

Measured memory_bytes: 256
// practice with Dukkha
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;

const int N = 1000;
const double INF = 4e9;

int xx[N + 2], yy[N + 2], rr[N + 2];
double dd[N + 2];
bool used[N + 2];

int main() {
	int xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt;
	int n; cin >> n;
	xx[0] = xs, yy[0] = ys;
	for (int i = 1; i <= n; i++)
		cin >> xx[i] >> yy[i] >> rr[i];
	xx[n + 1] = xt, yy[n + 1] = yt;
	n += 2;
	fill(dd, dd + n, INF);
	dd[0] = 0;
	while (true) {
		int i = -1;
		for (int j = 0; j < n; j++)
			if (!used[j] && (i == -1 || dd[i] > dd[j]))
				i = j;
		if (i == -1)
			break;
		used[i] = true;
		for (int j = 0; j < n; j++)
			if (!used[j])
				dd[j] = min(dd[j], dd[i] + max(hypot(xx[i] - xx[j], yy[i] - yy[j]) - rr[i] - rr[j], 0.0));
	}
	printf("%.10f\n", dd[n - 1]);
	return 0;
}


Measured memory_bytes: 3860
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *P = map(int, read().split())

    csum = [0] * (N + 1)
    for i, p in enumerate(P):
        csum[i + 1] = csum[i] + p

    ans = 0
    for i in range(N - K + 1):
        if ans < csum[i + K] - csum[i]:
            ans = csum[i + K] - csum[i]

    print((K + ans) / 2)
    return


if __name__ == '__main__':
    main()


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

typedef long long int lli;

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

	ios::sync_with_stdio(0);
	cin.tie(0);

	string s,t;
	cin>>s>>t;

	int count=0;

	for(int i=0;i<3;i++)
		if(s[i]==t[i])
			count++;

	cout<<count;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    if (n == 1){
        cout << "Hello World" << endl;
    }else{
        int a = in(), b = in();
        cout << a + b << endl;
    }

    return 0;
}


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

typedef long long ll;
const int N = 1e5 + 5, MOD = 1e9 + 7;

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

	ll a, b, c, k;

	cin >> a >> b >> c >> k;

	k %= 2LL;

	ll res;

	if (!k) res = a - b;

	else res = (b + c) - (a + c);

	if (res > 1e18) cout << "Unfair\n";
	else cout << res << '\n';

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b,c;
    cin >> a >> b;
    if(b < 100 && b >= 10){
        a *= 100;
    }
    if(b == 100){
        a *= 1000;
    }
    if(b < 10){
        a *= 10;
    }
    c = a + b;
    bool ans = false;
    for(int i = 1; i < 320; i++){
        if(c % i == 0 && c / i == i){
            ans = true;
            break;
        }
    }
    if(ans)
    cout << "Yes" << endl;
    if(ans != true)
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    // data loader
    int n;
    cin>>n;
    int a[n+1];
    for (int i=0;i<n+1;i++){
        cin>>a[i];
    }
    int b[n];
    for (int i=0;i<n;i++){
        cin>>b[i];
    }
    
    //main
    long long rem=0;
    if (a[0]<b[0]){
        rem+=a[0];
        b[0]-=a[0];
    }else{
        rem+=b[0];
        b[0]=0;
    }
    for (int i=0;i<n-1;i++){
        if (a[i+1]<b[i]){
            rem+=a[i+1];
            a[i+1]=0;
        }else{
            rem+=b[i];
            a[i+1]-=b[i];
        }
        if (a[i+1]<b[i+1]){
            rem+=a[i+1];
            b[i+1]-=a[i+1];
        }else{
            rem+=b[i+1];
            b[i+1]=0;
        }
    }
    if (a[n]<b[n-1]){
        rem+=a[n];
    }else{
        rem+=b[n-1];
    }
    cout<<rem<<endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N = (int) 2e5 + 7;
int n;
vector<int> g[N];
ll dp[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = n; i >= 1; i--) {
    vector<int> bg;
    for (auto &j : g[i]) {
      if (j > i) {
        bg.push_back(j);
      }
    }
    sort(bg.begin(), bg.end());
    bg.push_back(n + 1);
    vector<pair<int, int>> tv;
    tv.push_back({i, bg[0] - 1});
    for (int j = 0; j + 1 < (int) bg.size(); j++) {
      tv.push_back({bg[j], bg[j + 1] - 1});
    }
    dp[i] = dp[i + 1];
    for (int j = 0; j < (int) tv.size(); j++) {
      dp[i] -= (ll) (tv[j].second - tv[j].first + 1) * (j - 1);
    }
  }
  ll sol = 0;
  for (int i = 1; i <= n; i++) {
    sol += dp[i];
  }
  cout << sol << "\n";
  return 0;
}



Measured memory_bytes: 19416
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
template<class T>
void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>
void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,w;
	cin>>n>>w;
	vvl dp(n+1,vl(100001,LINF));
	dp[0][0]=0;
	rep(i,n){
		ll wg,vl;
		cin>>wg>>vl;
		rep(j,100001){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			if(j+vl<=100000 and dp[i][j]+wg<=w)dp[i+1][j+vl]=min(dp[i+1][j+vl],dp[i][j]+wg);
		}
	}
	rep(i,100001){
		if(dp[n][100000-i]!=LINF){
			cout<<100000-i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 80256
/*"Everything in the universe is balanced. Every disappointment
   you face in life will be balanced by something good for you!
                Keep going, never give up."						*/
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define ld double 
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define deb cerr << "Line no." << __LINE__
#define nl '\n'
#define pb push_back
#define all(a) a.begin(),a.end()
#define P pair<ll,ll> 
#define F first
#define S second
const ll p_mod=9999999999999983;
const long double pi = 3.14159265358979323;
const ll N=1e6+9;
const ll mod=1e9+7;
typedef double f80;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){uniform_int_distribution<int> uid(l, r); return uid(rng); }
ll powerk(ll x, ll y);

ll a[N];
vector<P> v;

void solve()
{    
	ll n,m;
	cin>>n>>m;
	rep(i,1,n)
	{
		ll x,y;		
		cin>>x>>y;
		v.pb({x,y});
	}
	sort(all(v));
	rep(i,1,100000)a[i]=1e18;
	rep(i,0,n-1)
	{
		repd(j,100000,v[i].S)
		{
			a[j] = min(a[j] , a[j-v[i].S] + v[i].F);
		}
	}
	repd(i,100000,1)
	{
		//cout<<i<<" "<<a[i]<<nl;
		if(a[i]<=m){cout<<i;break;}
	}

}


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    while(t--)
    {
      solve();
    }  
}
ll powerk(ll x, ll y)
{
  if(y==0)return 1;
  if(y==1)return x%mod;
  if(y&1)
    return ((powerk((x*x)%mod, y/2)%mod)*x)%mod;
  else return powerk((x*x)%mod,y/2)%mod;
}

// Xorawar

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

using namespace std;

const int MAX_A = 100000;
const int MIN_A = -100000;
const int RANGE = MAX_A - MIN_A + 1;
const int BIAS = -MIN_A;
int n;
vector<int> l, r;
int lc[RANGE] = {}, rc[RANGE] = {};

int main()
{
  cin >> n;
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    lc[x+BIAS]++, rc[y+BIAS]++;
  }
  lc[BIAS]++, rc[BIAS]++;

  for (int i = 0; i < RANGE; i++) {
    while (lc[RANGE-1-i]--) l.push_back(RANGE-1-BIAS-i);
    while (rc[i]--) r.push_back(i-BIAS);
  }

  uint64_t d = 0;
  for (int i = 0; i < n && l[i] > r[i]; i++)
    d += (l[i] - r[i]) * 2;

  cout << d << endl;

  return 0;
}


Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <stdio.h>

using namespace std;

int N, V;
double A[40005], B[40005], C[40005];
int ax[40005], ay[40005], p[40005], array[40005];
vector< pair<double, int> > vec;

int bit[40005];
void init(){
	for(int i = 1; i <= N; i++) bit[i] = 0;
}
int sum(int i)
{
	int ret = 0;
	while(i > 0){
		ret += bit[i];
		i -= i & (-i);
	}
	return ret;
}
void add(int i, int val)
{
	while(i <= N){
		bit[i] += val;
		i += i & (-i);
	}
}

int checkx(double x)
{
	vec.clear();
	for(int i = 1; i <= N; i++){
		vec.push_back( make_pair(-A[i]/B[i]*x + C[i]/B[i], i) );
	}
	sort(vec.begin(), vec.end());
	for(int i = 0; i < vec.size(); i++){
		p[vec[i].second] = i+1;
	}
	
	int ret = 0;
	for(int i = 1; i <= N; i++){
		array[p[i]] = ax[i];
	}
	init();
	for(int i = 1; i <= N; i++){
		ret += sum(array[i]);
		add(array[i], 1);
	}
	return ret >= (V+1)/2;
}

int checky(double x)
{
	vec.clear();
	for(int i = 1; i <= N; i++){
		vec.push_back( make_pair(-B[i]/A[i]*x + C[i]/A[i], i) );
	}
	sort(vec.begin(), vec.end());
	for(int i = 0; i < vec.size(); i++){
		p[vec[i].second] = i+1;
	}
	
	int ret = 0;
	for(int i = 1; i <= N; i++){
		array[p[i]] = ay[i];
	}
	init();
	for(int i = 1; i <= N; i++){
		ret += sum(array[i]);
		add(array[i], 1);
	}
	return ret >= (V+1)/2;
}

int main(void)
{
	cin >> N;
	for(int i = 1; i <= N; i++){
		cin >> A[i] >> B[i] >> C[i];
	}
	V = N*(N-1)/2;
	
	vec.clear();
	for(int i = 1; i <= N; i++){
		vec.push_back( make_pair(-A[i]/B[i], i) );
	}
	sort(vec.begin(), vec.end());
	for(int i = 0; i < vec.size(); i++){
		ax[vec[i].second] = i+1;
	}
	
	vec.clear();
	for(int i = 1; i <= N; i++){
		vec.push_back( make_pair(-B[i]/A[i], i) );
	}
	sort(vec.begin(), vec.end());
	for(int i = 0; i < vec.size(); i++){
		ay[vec[i].second] = i+1;
	}
	
	double ansx, ansy;
	
	double ub = 1e9, lb = -1e9, mid;
	for(int i = 0; i < 200; i++){
		mid = (ub + lb) / 2.0;
		if(checkx(mid)) ub = mid;
		else lb = mid;
	}
	ansx = (ub+lb) / 2.0;
	
	ub = 1e9, lb = -1e9, mid;
	for(int i = 0; i < 200; i++){
		mid = (ub + lb) / 2.0;
		if(checky(mid)) ub = mid;
		else lb = mid;
	}
	ansy = (ub+lb) / 2.0;
	
	printf("%.12f %.12f\n", ansx, ansy);
	return 0;
}

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

int main(){
	string a,b="ACGT";
	int j,max=0,count=0;

	cin >> a;

	for(int i=0;i<(int)a.length();i++){
		for(j=0;j<4;j++){
			if(a[i]==b[j]){
				count++;
				if(max<count)max=count;
				break;
			}
		}
		if(j==4)count=0;
	}
	cout<<max<<endl;
	return 0;
}


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

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

A = []
A.append(B[0])
for i, x in enumerate(B):
    if i == N-2:
        A.append(x)
        break
    if x <= B[i+1]:
        A.append(x)
    else :
        A.append(B[i+1])

result = sum(A)
print(result)

Measured memory_bytes: 3064
if __FILE__==$0
	r_i=lambda{|str|str.strip.to_i}
	r_s=lambda{|str|str.strip}
	n=r_i[gets]
	chars=Array.new(n)
	rsl=[]
	for i in 0..n-1
		chars[i]=r_s[gets].split("").sort
	end
	dist=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
	for d in dist
		cnt=Float::INFINITY
		for c in chars
			n=c.count(d)
			if n<cnt
				cnt=n
			end
		end
		if cnt>0
			cnt.times do |i|
				rsl.push(d)
			end
		end
	end
	puts rsl.length>0 ? rsl.join("") : ""
end

Measured memory_bytes: 1916
#include <vector>
#include <iostream>
using namespace std;
template <class Type>
class BIT {
private:
	int size_; vector<Type> v;
	Type sum(int r) { Type ret = 0; while (r > 0) ret += v[r], r -= r & -r; return ret; }
public:
	BIT() : size_(0), v(vector<Type>()) {};
	BIT(int size__) { for (size_ = 1; size_ < size__;) size_ <<= 1; v.resize(size_ + 1); }
	void add(int i, Type x) { i++; while (i <= size_) v[i] += x, i += i & -i; }
	Type sum(int l, int r) { return sum(r) - sum(l); }
};
int n, q, c, x, y;
int main() {
	cin >> n >> q;
	BIT<int> b(n);
	for (int i = 0; i < q; i++) {
		cin >> c >> x >> y;
		if (!c) b.add(x - 1, y);
		else cout << b.sum(x - 1, y) << endl;
	}
	return 0;
}

Measured memory_bytes: 3352
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a, b, c; cin >> a >> b >> c;
  if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
 
public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！
 
        Scanner sc = new Scanner(System.in);
        int line = sc.nextInt();
      int line2 = sc.nextInt();
        System.out.println((line+1)-line2);
    }
}

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

int main() {
	int h, w, d; cin >> h >> w >> d;
    pair<int, int> loca[h*w];
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            int a; cin >> a;
            loca[a-1] = make_pair(i, j);
        }
    }

    long long cost[h*w];
    for (int i = 0; i < d; i++)
    {
        cost[i] = 0;
        int tmp = i + d;
        while (tmp < h * w)
        {
            cost[tmp] = cost[tmp-d] + abs(loca[tmp].first - loca[tmp-d].first) + abs(loca[tmp].second - loca[tmp-d].second);
            tmp += d;
        }
    }

    int q; cin >> q;
    for (int i = 0; i < q; i++)
    {
        int l, r; cin >> l >> r;
        l--, r--;
        cout << cost[r] - cost[l] << endl;
    }


    return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

class RollingHash {
    template <int B, int M>
    class RollingHashPart {
      private:
        size_t len;
        std::vector<int> pow_b, hash;

      public:
        RollingHashPart() {}
        template <typename T>
        RollingHashPart(const T &s) : len(s.size()), pow_b(s.size() + 1), hash(s.size() + 1) {
            pow_b[0] = 1;
            hash[0]  = 0;
            for (int i = 0; i < len; i++) {
                pow_b[i + 1] = (ll)pow_b[i] * B % M;
                hash[i + 1]  = ((ll)hash[i] * B + s[i]) % M;
            }
        }
        // [l, r)
        int get(int l, int r) const {
            int res = (hash[r] - (ll)hash[l] * pow_b[r - l]) % M;
            if (res < 0)
                res += M;
            return res;
        }
    };

  public:
    using HashData = pair<int, int>;
    RollingHashPart<1033, 1000000007> rh1;
    RollingHashPart<6037, 999999937> rh2;

    RollingHash() {}
    template <typename T>
    RollingHash(const T &s) : rh1(s), rh2(s) {}
    // [l, r)
    HashData get(int l, int r) const { return HashData{rh1.get(l, r), rh2.get(l, r)}; }
    // [l1, r1), [l2, r2)
    int lcp(const RollingHash &rhs, int l1, int r1, int l2, int r2) const {
        int lb = 0, ub = std::min(r1 - l1, r2 - l2) + 1;
        while (ub - lb > 1) {
            int md                                               = (lb + ub) >> 1;
            (get(l1, l1 + md) == rhs.get(l2, l2 + md) ? lb : ub) = md;
        }
        return lb;
    }
};

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    RollingHash rh(s);
    int ok     = 0;
    int ng     = n;
    auto check = [&](int m) {
        set<RollingHash::HashData> hashset;
        vector<RollingHash::HashData> hashvec(n - m + 1);
        for (int i = 0; i < n - m + 1; ++i) {
            hashvec[i] = rh.get(i, i + m);
            if (i >= m)
                hashset.insert(hashvec[i - m]);
            if (hashset.count(hashvec[i]) == 1) {
                return true;
            }
        }
        return false;
    };
    while (ok + 1 != ng) {
        int mid = (ok + ng) / 2;
        if (check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << "\n";
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n;
  cin >> n;
  rep(i,n){
    char s;
    cin >> s;
    if(s == 'Y'){
      cout << "Four";
      return 0;
    }
  }
  
  cout << "Three";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vi vector<ll>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vt vector<tuple<ll, ll, ll>>
using namespace std;
//vector<vector<ll>> vv(110, vector<ll>(50, 0));

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	ll n, m;
	cin >> n >> m;
	if (!(n % 3) || !(m % 3) || !((n + m) % 3)) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}


signed main() {
  ios::sync_with_stdio(false);
  ll h, w;
  cin >> h >> w;
  map<char, int> a;
  REP(i, h) {
    string s;
    cin >> s;
    REP(j, w) {
      if(a.count(s[j])) {
        a[s[j]]++;
      }
      else {
        a[s[j]] = 1;
      }
    }
  }
  int b[] = {0, 0, 0, 0};
  REP_FROM(i, 'a', 'z'+1) {
    if(a.count(i)) {
      b[a[i]%4]++;
    }
  }
  b[1] += b[3];
  b[1] += b[3];
  // cout << b[0] << ":" <<  b[1] << ":" << b[2] << ":" << b[3] << endl;
  if(h*w==1){
    cout << "Yes" << endl;
    return 0;
  }
  if(h == 1 || w == 1) {
    if((h % 2 == 1 && w % 2 == 1) && b[1] == 1) {
      cout << "Yes" << endl;
    }
    else if(b[1] == 0) {
      cout << "Yes" << endl;
    }
    else {
    cout << "No" << endl;
    }
    return 0;
  }
  if(h%2==1 && w%2==1) {
    if(b[1] != 1) {
      cout << "No" << endl;
    }
    else if(b[2] <= (h-1)/2+(w-1)/2) {
      cout << "Yes" << endl;
    }
    else {
       cout << "No" << endl;
    }
  }
  else if(h%2==1 || w%2==1) {
    int m = h%2==1 ? w/2:h/2;
    if(b[1] == 0 && b[2] <= m) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    if(b[1] == 0 && b[2] == 0) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int A=in(),B=in();
	out(A*B,2*(A+B));
	
	return 0;
}



Measured memory_bytes: 3148
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;
 
 
int main()
{
	IOS;
	v32 a;
	cin>>n;
	int cnt=1;
	forn(i,n){
		cin>>x;
		a.pb(x);
		if(x==cnt){
			cnt++;
		}
	}
	if(cnt==1){
		cout<<-1<<ln;
	}
	else{
		cout<<n-(cnt-1)<<ln;
	}
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int k = sc.nextInt();

		int sum = 0;
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int sub = Math.abs(x - k);
			sum += sub < x ? sub * 2 : x * 2;
		}
		System.out.println(sum);
		sc.close();
	}
}


Measured memory_bytes: 23124
H,W=list(map(int,input().split()))

min_d=10**27

if H%3==0 or W%3==0:
    print(0)
else:
    min_d=min(H,W)
    for i in range(H+1):
        a=i*W
        b=(H-i)*(W//2)
        c=(H-i)*W - b
        min_d = min(max(a,b,c)-min(a,b,c),min_d)
    for i in range(W+1):
        a=i*H
        b=(W-i)*(H//2)
        c=(W-i)*H - b
        min_d = min(max(a,b,c)-min(a,b,c),min_d)
    print(min_d)

Measured memory_bytes: 40304
# -*- coding: utf-8 -*-

def DFS(adj, start):
    n = len(adj)
    d = [0] * n
    f = [0] * n
    flag = [0] * n
    S = []
    time = 1

    S.append(start)
    flag[start] = 1
    d[start] = time
    time = time + 1
    
    while flag.count(2) != n: # ??¨????????????????????¢?´¢????????????????????§
        if len(S) != 0:
            u = S.pop()
            v = next(adj, u)
            v = [i for i in v if flag[i] == 0] # v <= ??£??\???????????????????????¢?´¢??????????????????
            if len(v) != 0:
                S.append(u)
                S.append(v[0])
                flag[v[0]] = 1
                d[v[0]] = time
                time = time + 1
            else:
            #??£??\??????????????¨????¨??????????
                flag[u] = 2
                f[u] = time
                time = time + 1

        else:
            u = flag.index(0)
            S.append(u)
            flag[u] = 1
            d[u] = time
            time = time + 1            

    return d, f



def next(adj, u):
    """
    u?????£??\??????????????????????????????????????????
    """
    return [i for i, x in enumerate(adj[u]) if x == 1]
    

def main():
    
    n = int(input())
    adj = [[0 for i in range(n)] for j in range(n)]

    for i in range(n):
        tmp = list(map(int, input().split()))
        u = tmp[0]
        u = u -1
        k = tmp[1]
        v = tmp[2:]
        for j in range(k):
            adj[u][v[j]-1] = 1
    
    d, f = DFS(adj, 0)
    for i in range(n):
        print(i+1, d[i], f[i])

if __name__ == "__main__":
    main()    

Measured memory_bytes: 7888
Q, H, S, D,= map(int, raw_input().split())
N = int(input())
if Q*2 > H:
    M1 = H
else:
    M1 = Q*2

if  M1*2 > S:
    M = S
else:
    M = M1*2
if M*2 < D:
    print(M*N)
else:
    if N%2 == 0:
        print(D*(N//2))
    else:
        print(D*(N//2) + M)

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 20;
int n, v[N], c[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> v[i];
  FOR(i, 0, n) cin >> c[i];
  ll ans = 0;
  FOR(i, 0, n) ans += max(0, v[i]-c[i]);
  cout << ans << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [u64; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }
 
// https://practice.contest.atcoder.jp/tasks/practice_1

fn main() {
    input! { a: usize,b:usize,c:usize,d:usize,e:usize,k:usize }
    let mut ans = 0;
    if b-a > k { ans+=1; }
    if c-a > k { ans+=1; }
    if d-a > k { ans+=1; }
    if e-a > k { ans+=1; }
    if c-b > k { ans+=1; }
    if e-b > k { ans+=1; }
    if d-b > k { ans+=1; }
    if d-c > k { ans+=1; }
    if e-c > k { ans+=1; }
    if e-d > k { ans+=1; }
    if ans == 0 { println!("Yay!"); } else { println!(":(");}
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
    if (T.substr(0, S.length()) == S && T.length() == S.length() + 1) {
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'

const int MAXN=10;
const int MOD=10000000;

int c;
ll a,v,b,w,t;

int main(){
	cin>>a>>v>>b>>w>>t;
	if(a>b){
		ll e=a;
		a=b;
		b=e;
	} 
	if(a + v*t >= b+w*t)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	
	return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e18
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(a, x) for(auto& a : x)
struct Interval {int start, end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}
vll dp(100005,MAX);
int main()
{
    fio;
    ll n,W;
    cin>>n>>W;
    ll w[n+1],v[n+1];
    repA(i,1,n)
    cin>>w[i]>>v[i];
    dp[0]=0;
    repA(i,1,n)
    {
        repD(j,1000*n-v[i],0)
        if(j>=0)
            dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
    }
    ll ans;
    repD(i,1000*n,0)
    if(dp[i]<=W)
    {
        ans=i;
        break;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
long long ans[510][510];
long long sum[510][510];
int n, m, x, y;
int main()
{
	cin >> n >> m >> x >> y;
	int a = (1e9 - 1) / (x * y - 1), b = -a * (x * y - 1) - 1;
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++)
			ans[i][j] = a;
	for(int i = x; i <= n; i += x)
		for(int j = y; j <= m; j += y)
			ans[i][j] = b;
	for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            sum[i][j] = ans[i][j] + sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1];
    for(int i = x; i <= n; i ++)
        for(int j = y; j <= m; j ++)
            if(sum[i][j] + sum[i - x][j - y] - sum[i - x][j] - sum[i][j - y] > 0)
            {
                puts("No");
                return 0;
            }
    if(sum[n][m] < 0) {puts("No");return 0;}
    puts("Yes");
	for(int i = 1; i <= n; i ++, puts(""))
		for(int j = 1; j <= m; j ++)
			cout << ans[i][j] << " ";
    return 0;
}


Measured memory_bytes: 6912
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class BPalace {
public:
	void solve(istream& in, ostream& out) {
        double n,t,a; in >> n >> t >> a;
        vector<double> h(n);
        rep(i,n) in >> h[i];

        vector<double> abst(n);
        double x = (t - a) / 0.006;
        rep(i,n) abst[i] = abs(h[i] - x);
        double MIN = 1e6;
        rep(i,n) MIN = min(MIN,abst[i]);
        rep(i,n) if(abst[i] == MIN) {
            out << i + 1 << endl;
            break;
        }
	}
};

int main() {
	BPalace solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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

int main() {
    int x, y;
    std::cin >> x >> y;

    std::unordered_set<int> g1 = {1, 3, 5, 7, 8, 10, 12};  
    std::unordered_set<int> g2 = {4, 6, 9, 11};  
    std::unordered_set<int> g3 = {2};  

    if ((g1.count(x) == 1 && g1.count(y) == 1) ||
        (g2.count(x) == 1 && g2.count(y) == 1) ||
        (g3.count(x) == 1 && g3.count(y) == 1)
    ) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }

    return 0;
}


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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	// たくさんの数式
	string s;
	cin >> s;
	// roop は2^(n-1)回のループ
	ll ans = 0;
	for(int tmp = 0; tmp <(1 << s.size() - 1); tmp++){
		bitset<10> bit(tmp);
		ll ret = 0;
		// bitが立っているところまでの文字列を作る
		string t = "";
		rep(i,s.size()){
			t += s[i];
			if(bit.test(i)){
				if(t != ""){
					ret += stoll(t);
				}
				t = "";
			} 	
		}
		if(t != ""){
			ret += stoll(t);
		}
		ans += ret;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    Hello
    int n, m, ans = 0;
    cin >> n >> m;
    vector<vector<int>> v;
    priority_queue<int> pq;
    v.resize(1e5 + 5);
    for(int i = 0, a, b; i < n; i++){
        cin >> a >> b;
        v[a].push_back(b);
    }
    for(int i = 1; i <= m; i++){
        for(int j = 0; j < v[i].size(); j++)
            pq.push(v[i][j]);
        if(pq.size()){
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 5632
def main():

    n = int(input())
    W = list(map(int, input().split()))

    ans = abs(sum(W[:1]) - sum(W[1:]))

    for t in range(1, len(W)):
        S_1 = sum(W[:t])
        S_2 = sum(W[t:])
        ans = min(ans, abs(S_1 - S_2))

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

vector<int> get_factors(int num) {
    vector<int> ret;
    for (int i = 1; i * i <= num; i++) {
        if (num % i == 0) {
            ret.push_back(i);
            if (i * i != num) ret.push_back(num / i);
        }
    }
    return ret;
}

int main() {
    int N, A[200000];
    cin >> N;
    map<int, int> mii;
    REP(i, N) {
        cin >> A[i];
        mii[A[i]]++;
    }
    int ans = 0;
    REP(i, N) {
        vector<int> fs = get_factors(A[i]);
        bool ok = true;
        for (int f : fs) {
            if (f == A[i]) {
                if (mii[f] >= 2) {
                    ok = false;
                    break;
                }
            } else {
                if (mii[f] >= 1) {
                    ok = false;
                    break;
                }
            }
        }
        if (ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 33208
N = int(input())
S = list(input())
c = 0
l = []
for i in S:
    if i == "(":
        c += 1
    else:
        c -= 1
    l.append(c)

m = min(l)
if m < 0:
    for i in range(N):
        l[i] += (-m)

    M = l[-1]
    ans = ["("] *(-m) + S + [")"] *M
    
else:
    M = l[-1]
    ans = S + [")"] *M

output = "".join(ans)
print(output)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define LL long long
typedef pair<int, int> P;
const int MAX = 100000;
int n, a[MAX], b[MAX], c[MAX], d[MAX];
bool cmpA(const int &o, const int &p){
    return a[o] > a[p];
}
bool cmpB(const int &o, const int &p){
    return b[o] > b[p];
}
int main(){
    #ifdef TTEST
        freopen("input.txt", "r", stdin);
    #endif
    while(scanf("%d", &n) == 1){
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        for(int i = 0, u;i < n; ++i){
            scanf("%d", &u);
            u--;
            if(i & 1){
                b[u] ++;
            }else{
                a[u] ++;
            }
        }
        for(int i = 0;i < MAX; ++i){
            c[i] = i;
            d[i] = i;
        }
        sort(c, c + MAX, cmpA);
        sort(d, d + MAX, cmpB);
        int ans = 0;
        for(int i = 0;i < 2; ++i){
            for(int j = 0;j < 2; ++j){
                if(c[i] == d[j]) continue;
                ans = max(ans, a[c[i]] + b[d[j]]);
            }
        }
        cout << n - ans << endl;
    }
    return 0;
}


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

int main(void){
  int N;
  int sum = 0;
  
  cin >> N;

  int tmp = N;
  while(tmp > 10){
    sum += tmp % 10;
    tmp /= 10;
  }
  sum += tmp;
 
 
  if(N%sum == 0) cout << "Yes" << "\n";
  else  cout << "No" << "\n";

}


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

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> LR;
    LR = vector<vector<int>>(N+1, vector<int>(N+1, 0));
    for(int i=0; i<M; i++){
        int L, R;  cin >> L >> R;
        LR[L][R]++;
    }
    for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) LR[i][j] += LR[i][j-1];
    for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) LR[i][j] += LR[i-1][j];

    for(int i=0; i<Q; i++){
        int p, q;  cin >> p >> q;
        cout << LR[q][q] - LR[p-1][q] - LR[q][p-1] + LR[p-1][p-1] << endl;
    }
}


Measured memory_bytes: 1920
#include <stdio.h>

int main()

{

long long int b[1000000];

long long int n,i,k=0;

scanf("%lld",&n);

for(i=0;i<n;i++)
{
scanf("%lld",&b[i]);
}
for(i=1;i<=n;i++)
{
if(b[i]==b[n-1])
{
break;
}
if((b[i-1]>b[i]) && (b[i]>b[i+1])) 
{
k++;

b[i]=b[i-1];
}
else if((b[i-1]<b[i]) && (b[i]<b[i+1]))
{
k++;
b[i]=b[i-1];
}

}
printf("%lld\n",k);
 
return 0;
} 

Measured memory_bytes: 1720
#include <stdio.h>
int main(void){
  int n,m,i;
  int sum = 0;
  int t[100],p[100],x[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&t[i]);
  }
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d %d",&p[i],&x[i]);
  }
  for(i=0;i<n;i++){
    sum += t[i];
  }
  for(i=0;i<m;i++){
    printf("%d\n",sum-(t[p[i]-1]-x[i]));
  }
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 13, 2020 05:11:35 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


class PrimeComb:
  def __init__(self, MAX=510000, MOD=1000000007):
    # preprocessing: O(MAX)
    self.MAX  = MAX
    self.MOD  = MOD
    self.fac  = [0]*MAX
    self.inv  = [0]*MAX
    self.finv = [0]*MAX
    self.fac[0]  = self.fac[1] = 1
    self.finv[0] = self.finv[1] = 1
    self.inv[1]  = 1
    for i in range(2, MAX):
      self.fac[i]  = self.fac[i-1] * i % MOD
      self.inv[i]  = MOD - self.inv[MOD % i] * int(MOD / i) % MOD
      self.finv[i] = self.finv[i-1] * self.inv[i] % MOD

  def com(self, n, k):
    # compute -> nCk % self.P : O(1)
    if (n < k): return 0
    if (n < 0 or k < 0): return 0
    return self.fac[n] * (self.finv[k] * self.finv[n-k] % self.MOD) % self.MOD


def main():
  N, K = list(map(int, input().split()))

  MOD = 1_000_000_007
  PC = PrimeComb()
  for i in range(1, K+1):
    print(PC.com(N-K+1, i) * PC.com(K-1, i-1) % MOD)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 85944