akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys

mod = 10 ** 9 + 7

def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


def get_numbers():
    return map(int, input().split())


n, m = get_numbers()
a = set(get_nums(m))

dp = [0 for _ in range(n + 1)]
dp[0] = 1
if 1 not in a:
    dp[1] = 1

for i in range(2, n + 1):
    if i not in a:
        dp[i] = dp[i - 1] + dp[i - 2]
        dp[i] %= mod

print(dp[-1])

Measured memory_bytes: 54940
import sys
input = sys.stdin.readline
import collections
from collections import deque
n,d,a= map(int, input().split())
x= [list(map(int, input().split())) for i in range(n)]

x.sort()
for i in range(n):
    x[i][1]=-(-x[i][1]//a)

# どのモンスターまで倒したか管理しながら進める。
# 累積ダメージを管理
qq=deque([])
ans=0
atk=0
for i in range(n):
    w=x[i][1]
    # ダメージの有効期限を超過している場合
    while len(qq)>0 and x[i][0] > qq[0][0]:
        atk-=qq[0][1]
        qq.popleft()

    if w-atk>0:
        ans+=w-atk
        # 有効期限　ダメージ
        qq.append([x[i][0]+2*d,w-atk])
        atk += w - atk
print(ans)


Measured memory_bytes: 84444
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
long long GCD(long long a,long long b){
    if(b==0)return a;
    return GCD(b,a%b);
}
long long LCM(long long a,long long b){
    return a*b/GCD(a,b);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll sum=0;
    rep3(i,1,n+1){
        rep3(j,1,n+1){
            rep3(k,1,n+1){
                sum+=GCD(i,GCD(j,k));
            }
        }
    }
    cout<<sum<<endl;
}


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


int main(){
    int N; cin >> N;
    vector<int> S;
    
    while(1){
        if(N%2==0){
            S.push_back(0);
            N /= -2;
        }
        else {
            N--;
            S.push_back(1);
            N /= -2;
        }
        
        if(N==1){
            S.push_back(1);
            break;
        }
        else if(N==0) break;
    }
    reverse(S.begin(),S.end());
    for(int i=0; i<S.size(); i++) cout << S[i];
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll mod=1e9+7;
int n;
int a[100][100];
int dp[23][(1<<21)+3];
ll fun(int row,ll mask){
  ll ans=0;
  if(row==n && mask==((1<<n)-1)){
    return 1;
  }
  if(dp[row][mask]!=-1)
  return dp[row][mask];
  for(int i=0;i<n;i++){
    if(a[row][i]==1 && ((mask&(1<<i))==0))
      ans=(ans+fun(row+1,mask|(1<<i)))%mod;
  }
  return dp[row][mask]=ans;
} 
int main(){
   
    memset(dp,-1,sizeof dp);
cin>>n;
for(int i=0;i<n;i++){
  for(int j=0;j<n;j++)
    cin>>a[i][j];
}
cout<<fun(0,0)<<endl;
return 0;
}

Measured memory_bytes: 188672
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <cstdio>
using namespace std;
#define mygc(c) (c)=getchar()
void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;} }for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}

int64_t A[5000];
int B[5000][200];

int main(){
    int N,M;
    reader(&N); reader(&M);
    for(int i=1;i<N;i++){
        int a;
        reader(&a);
        A[i]=(int64_t)a+A[i-1];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            reader(&B[i][j]);
        }
    }
    int64_t ans=0;
    for(int i=0;i<N;i++){
        int32_t T[200] = {};
        for(int j=i;j<N;j++){
            int64_t temp=A[i]-A[j];
            for(int k=0;k<200;k++){
                T[k]=max(T[k],B[j][k]);
            }
            for(int k=0;k<200;k++){
                temp+=T[k];
            }
            ans=max(ans,temp);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int inf = (int) 1e9;
            int N = sc.nextInt();
            int[] B = new int[N - 1];
            for (int i = 0; i < N - 1; i++) {
                B[i] = sc.nextInt();
            }
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = inf;
            }
            for (int i = 0; i < N - 1; i++) {
                A[i] = Math.min(A[i], B[i]);
                A[i + 1] = Math.min(A[i + 1], B[i]);
            }
            long sum = 0;
            for (int i = 0; i < N; i++) {
                sum += A[i];
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s; cin>>s;
    int posC = 0, posF = 0;
    vector<int>pos[2];
    for(int i = 0 ; i < s.size(); ++i){
        if(s[i] == 'C'){
            pos[0].push_back(i + 1);
        }if(s[i] == 'F'){
            pos[1].push_back(i + 1);
        }
    }
    for(int i  : pos[0]){
        for(int j : pos[1]){
            if(i < j){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
}


Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,A,B;
  cin>>N>>A>>B;
  cout<<B<<endl;
  cout<<N<<endl;
  cout<<A<<endl;
}


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

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int N;
int A[200010];
vector<int> E[200010];
int ans[200010];
int dp[200020];

void dfs(int now, int par)
{
  int ng = -1, ok = N+5;
  while(ok - ng > 1)
  {
    int mid = (ok + ng) / 2;
    if (A[now] <= dp[mid])
    {
      ok = mid;
    }else
    {
      ng = mid;
    }
  }
  int memo = dp[ok];
  dp[ok] = A[now];

  int ng1 = 0, ok1 = N+5;
  while(ok1 - ng1 > 1)
  {
    int mid = (ok1 + ng1) / 2;
    if (dp[mid] == INF)
    {
      ok1 = mid;
    }else{
      ng1 = mid;
    }
  }
  ans[now] = ok1;
  for (int to: E[now])
  {
    if(to == par) continue;
    dfs(to, now);
  }
  dp[ok] = memo;
}


int main(){
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  for (int i = 0; i < N-1; i++)
  {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  for (int i = 0; i < N+10; i++)
  {
    dp[i] = INF;
  }
  dfs(0, -1);
  for (int i = 0; i < N; i++)
  {
    cout << ans[i] << endl;
  }
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vll c(n);
  for(int i=0;i<n;++i) {
    cin >> c[i];
  }

  sort(c.rbegin(), c.rend());

  ll ans = 0;
  ll mul = 1;
  for(int i=0;i<n-1;++i) {
    mul *= 4;
    mul %= MOD;
  }

  for(int i=0;i<n;++i) {
    ans += mul * c[i] % MOD * (i+2) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;

}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n, k;
	cin >> n >> k;
	if (k * 2 - 1 >= n) {
		cout << (n+k-1)/k;
		return 0;
	}
	cout << (n -2) / (k - 1) + 1;
}

Measured memory_bytes: 256
n = int(input())
s_l = [  input() for _ in range(n)  ]

name_d = ['M','A','R','C','H']
sub_s = {}
for d in name_d:                    
    sub_s[d] = 0

for s in s_l:
    if s[0] in name_d:
        sub_s[s[0]] += 1

ans = 0
memo = set()
for i in range(5):
    for j in range(5):
        for k in range(5):
            a,b,c = sorted([i, j, k])
            if a != b and a!=c and b!=c:
                key = str(a)+str(b)+str(c)
                if key not in memo:
                    ans +=sub_s[name_d[a]] * sub_s[name_d[b]] * sub_s[name_d[c]]
                    memo.add(key)
print(ans)

Measured memory_bytes: 15904
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define pb push_back

typedef vector<int> vi;
typedef vector<vector<int> > vvi;

int lcs(string a, string b) {
  vvi len(a.length()+1, vi(b.length()+1, 0));
  for (int ia = 1 ; ia <= a.length() ; ia++) {
    for (int ib = 1 ; ib <= b.length() ; ib++) {
      if (a[ia-1] == b[ib-1]) {
        len[ia][ib] = len[ia-1][ib-1]+1;
      } else {
        len[ia][ib] = max(len[ia][ib-1], len[ia-1][ib]);
      }
    }
  }
  return len[a.length()][b.length()];
}

int main() {
  int t;
  cin >> t;
  vi results;
  for (int dataset = 0 ; dataset < t ; dataset++) {
    string a, b;
    cin >> a;
    cin >> b;
    results.pb(lcs(a, b));
  }

  for (int it = 0 ; it < t ; it++) {
    printf("%d\n", results[it]);
  }

  return 0;
}

Measured memory_bytes: 6760
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

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

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

template <ll SIZE>
struct DSU {
    ll par[SIZE] , sz[SIZE];
    DSU(){
        fill(par , par + SIZE , -1);
        fill(sz , sz + SIZE , 1);
    }

    ll Find(ll v){
        return (par[v] == -1 ? v : par[v] = Find(par[v]));
    }

    ll Union(ll v , ll u){
        ll pv = Find(v) , pu = Find(u);
        if(pv == pu)    return 0;
        if(sz[pv] < sz[pu]) swap(pv , pu); // union by rank
        par[pu] = pv;
        sz[pv] += sz[pu];
        return 1;
    }

    ll getSize(ll v){
        return sz[Find(v)];
    }
};

DSU<MAXN * 2> dsu;
ll n , ans , x , y , cntx[MAXN * 2] , cnty[MAXN * 2];

int main() {
    fast_io;

    cin >> n;
    for(ll i = 0 ; i < n ; i++){
        cin >> x >> y;
        dsu.Union(x , y + MAXN);
    }

    for(ll i = 0 ; i < MAXN ; i++){
        cntx[dsu.Find(i)]++;
    }
    for(ll i = 0 ; i < MAXN ; i++){
        cnty[dsu.Find(i + MAXN)]++;
    }

    for(ll i = 0 ; i < MAXN * 2 ; i++){
        ans += cntx[i] * cnty[i];
    }
    cout << ans - n << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 51072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<ll, ll> mp;
    ll n; cin>>n;
    vector<ll> aa(n);
    rep(i,n){
        ll a; cin>>a;
        aa[i] = a;
        mp[a]++;
    }
    ll sum = 0;
    for(auto au : mp){
        sum += (au.second * (au.second-1))/2;
    }
    rep(i, n){
        ll tmp = mp[aa[i]];
        ll ans = sum - (tmp*(tmp-1))/2 + ((tmp-1)*(tmp-2))/2;
        cout << ans <<endl;
    }
}

Measured memory_bytes: 12416
#include<iostream>
#include<cstdio>
using namespace std;
int n,x,y;
int f[2001][2001];
int vis[20001];
int main()
{
	scanf("%d%d%d",&n,&x,&y);
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
			f[i][j]=f[j][i]=j-i;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			if(i<=x&&j>=y)
				f[i][j]-=y-x-1;
			if(i>x&&i<y)
				f[i][j]=min(f[i][j],f[i][x]+f[y][j]+1);
			if(j>x&&j<y)
				f[i][j]=min(f[i][j],f[j][y]+f[x][i]+1);
			f[j][i]=f[i][j];
		}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			vis[f[i][j]]++;
	for(int i=1;i<=n-1;i++)
		printf("%d\n",vis[i]);
	return 0;
}

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

using namespace std;

using ll = long long;
const int maxw = 100010;
int N, W;
ll minw[maxw];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> W;
	int v; ll w;
	fill(minw, minw + maxw, W+2);
	minw[0] = 0;
	while (N--) {

		cin >> w >> v;
		for (int j = 100000; j >= v; j--) {
			minw[j] = min(minw[j], minw[j-v] + w);
			// if (minw[j] < 1e9) cout << "val: " << j << endl;
		}
	}
	int ans = 0;
	for (int i = 1; i <= 100000; i++) {
		if (minw[i] <= W) ans = i;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans; 
}
void solve()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    fo(i,n)
    {
        cin>>a[i];
    }
    ll dp[k+1];
    memset(dp,0,sizeof(dp));
    for(int i=a[0];i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i-a[j]>=0 && dp[i-a[j]]==0)
            {
                dp[i]=1;
                break;
            }
        }
    }
    if(dp[k]==1)
    {
        cout<<"First"<<nl;
    }
    else
    {
        cout<<"Second"<<nl;
    }


}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
}


Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define in_range(x, y, r, c) (x <= r && y <= c && x >= 0 && y >= 0)
#define MAXN 200100
#define ff first
#define ss second
using namespace std;
const int mod = 1e9+7;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);

	for (int i=0; i<n; i++){
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	int mid = n/2;
	if (n&1){
		if (v[mid-1] == v[mid]) cout << "0" << endl;
		else cout << "1";
	}
	else {
		if (v[mid] == v[mid-1]) cout << "0" << endl;
		else cout << v[mid] - v[mid-1] << endl;
	}
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100 + 10;
int f[N][N];
char a[N][N];
void upd(int &x,int y){
    x = min(x,y);
}
int main(){
    int n,m; cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>(a[i]+1);
    memset(f,0x7f,sizeof(f));
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
        if(i==1&&j==1) f[i][j] = (a[1][1]=='#');
        if(a[i][j]=='#'){
            upd(f[i+1][j],f[i][j]);
            upd(f[i][j+1],f[i][j]);
        }
        else{
            upd(f[i+1][j],f[i][j]+(a[i+1][j]=='#'));
            upd(f[i][j+1],f[i][j]+(a[i][j+1]=='#'));
        }
    }
    cout<<f[n][m]<<endl;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j); i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
typedef long long LL;
int get_int(){int x;scanf("%d",&x);return x;}
int get_ll(){LL x;scanf("%lld",&x);return x;}

string s;
int N,K;

void tests(){
    ;
}

void build_window(int &st,int &ed){
    int cnt = 0;
    int ok = 0;
    if(s[0] == '0'){
        cnt++;
        ok = 1;
    }
    while(cnt <= K){
        ed++;
        if(ed == N) return;
        if(s[ed] == '0' && ok) continue;
        else if(s[ed] == '0' && !ok){
            cnt++;
            ok = true;
        }
        else if(s[ed] == '1' && !ok) continue;
        else if(s[ed] == '1' && ok){
            ok = false;
        }
    }
}

void slide(int &st,int &ed){
    int ok = 0;
    if(s[st] == '0'){
        ok = 1;
    }
    while(true){
        st++;
        if(st == N) break;

        if(s[st] == '0' && ok) continue;
        else if(s[st] == '1' && ok) break;
        else if(s[st] == '0' && !ok){
            ok = 1;continue;
        }
        else if(s[st] == '1' && !ok) continue;
    }

    ok = 0;
    while(true){

        if(s[ed] =='1' && !ok){ok = 1;}
        else if(s[ed] == '0' && ok) break;
        ed++;
        if(ed == N) return;
    }



}

int main()
{
    cin >> N >> K >> s;
    int st = 0;int ed = 0;
    build_window(st,ed);

    int res = ed-st;
    while(ed < N && st < N){
        slide(st,ed);
        //cout << st <<" "<<ed << endl;
        res = max(res,ed-st);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int l=s.size();
    if(l>=6)
    {
        if(s[2]==s[3]&&s[4]==s[5])
        {
            cout<<"Yes";
            
        }
        else
        cout<<"No";
    }
    else
    cout<<"No";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

vector<ll> FactorialInv, Factorial;

void init_combination(ll MAX){
    Factorial.resize(MAX + 1);
    FactorialInv.resize(MAX + 1);
    Factorial[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = power(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    if(b < 0) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

//modの値の確認をすること
int main(){
    ll h,w;
    cin >> h >> w;
    vector<vector<ll> > dp(h,vector<ll>(w,INF)),g(h + 1,vector<ll>(w + 1,0ll));
    dp[0][0] = 0;
    rep0(i, h)rep0(j, w){
        char c;
        cin >> c;
        if(c == '#')g[i][j] = 1;
    }
    rep0(i, h)rep0(j, w){
        if(i != h-1) dp[i + 1][j] = min(dp[i + 1][j],dp[i][j] + (g[i][j] == g[i + 1][j]? 0:1));
        if(j != w-1) dp[i][j + 1] = min(dp[i][j + 1],dp[i][j] + (g[i][j] == g[i][j + 1]? 0:1));
    }
    ll ans = dp[h - 1][w - 1] + g[0][0] + g[h - 1][w - 1];
    pf(ans / 2);
    return 0;
}


Measured memory_bytes: 384
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

def main(K, N, MOD):
    def fact_table(N, MOD):
        inv = np.empty(N, np.int64)
        inv[0] = 0
        inv[1] = 1
        for n in range(2, N):
            q, r = divmod(MOD, n)
            inv[n] = inv[r] * (-q) % MOD
        fact = np.empty(N, np.int64)
        fact[0] = 1
        for n in range(1, N):
            fact[n] = n * fact[n - 1] % MOD
        fact_inv = np.empty(N, np.int64)
        fact_inv[0] = 1
        for n in range(1, N):
            fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD
        return fact, fact_inv, inv

    fact, fact_inv, inv = fact_table(2_000_010, MOD)
    f = np.zeros(K + 1, np.int64)
    f = fact[N - 1:K + N] * fact_inv[N - 1] % MOD * fact_inv[0:K + 1] % MOD
    x = 1
    for i in range(1, K + 1):
        x = (x * 25) % MOD
        f[i] = f[i] * x % MOD
    for i in range(1, K + 1):
        f[i] += f[i - 1] * 26
        f[i] %= MOD
    return f[-1]

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.from_dtype(np.int64)
    signature = (i8, i8, i8)

    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()

from my_module import main

K = int(readline())
N = len(read().rstrip())

print(main(K, N, MOD))


Measured memory_bytes: 73288
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

/* カードの情報（数、文字）を記憶する構造体 */
typedef struct{

  int n;
  char c;
  
}Card;

void swap(Card *, Card *);
int partition(Card A[], int, int);
void quicksort(Card A[], int,int);
int isStable(Card A[], Card B[], int);
void mergeSort(Card A[], int, int);
void merge(Card A[], int, int, int);


int main()
{
  Card *A, *B;
  int n, i;

  scanf("%d", &n);
  A = (Card *)malloc( sizeof(Card) * n );      /* カードの配列を動的に確保 */
  B = (Card *)malloc( sizeof(Card) * n );

  /* カード情報を読込み */
  for( i = 0; i<n; i++ )
    scanf(" %c%d", &A[i].c, &A[i].n);

  /* Aの内容をBにコピー */
  for( i = 0; i<n; i++ )
    B[i] = A[i];

  /* Aに対してクイックソートを行う */
  quicksort(A, 0, n-1);
  /* Bに対してマージソートを行う */
  mergeSort(B, 0, n);
  /* 結果を出力 */
  if( isStable(B, A, n) == 1 )
    printf("Stable\n");
  else
    printf("Not stable\n");
  for( i = 0; i<n; i++ )
    printf("%c %d\n", A[i].c, A[i].n);
  
  return 0;
}

/* Card型の a, b を交換する関数 */
void swap(Card *a, Card *b)
{
  Card tmp;

  tmp = *a;
  *a  = *b;
  *b = tmp;
}

/* A[p..r]の配列を各要素がA[q]以下のA[p...q-1]と 各要素がA[q]より大きいA[q+1..r]に分割する関数
   戻り値： インデックスq */
int partition(Card A[], int p, int r)
{
  int i, j;
  Card x;

  x = A[r];
  i = p-1;

  for( j = p; j<r; j++ )
    {
      if( A[j].n <= x.n )
	{
	  i++;
	  swap(&A[j], &A[i]);
	}
    }
  swap(&A[i+1], &A[r]);

  return i+1;
}

/* Card型の配列に対してクイックソートを行う関数 （昇順）*/
void quicksort(Card A[], int p,int r)
{
  int q;
  
  if( p<r )
    {
      q = partition(A, p, r);
      quicksort(A, p, q-1);
      quicksort(A, q+1, r);
    }
}

/* マージを行う関数　*/
void merge(Card A[], int left, int mid, int right)
{
  int i, j, k, n1, n2;
  Card *L, *R;

  n1 = mid - left;
  n2 = right - mid;

  /* マージ用の一時記憶配列を動的に確保　要素が１つ多いのは末端に番兵を挿入するため　*/
  L = (Card *)malloc( sizeof(Card) * ( n1 + 1) );
  R = (Card *)malloc( sizeof(Card) * ( n2 + 1) );

  for( i = 0; i<n1; i++ )
    L[i] = A[ left + i ];
  for( j = 0; j<n2; j++ )
    R[j] = A[ mid + j ];

  /*　番兵を挿入　*/
  L[i].n = INT_MAX;
  R[j].n = INT_MAX;

  i = 0;
  j = 0;
  /* マージ　*/
  for( k = left; k<right; k++ )
    {
      if( L[i].n<= R[j].n )
        A[k] = L[i++];
      else
        A[k] = R[j++];
    }
}

/* マージソートを行う関数　*/
void mergeSort(Card A[], int left, int right)
{
  int mid = (right + left)/2;

  if( left+1 < right )
    {
      mergeSort(A, left, mid);
      mergeSort(A, mid, right);
      merge(A, left, mid, right);
    }
  else
    return;
}

/* マージソートの結果Aとその他のソートSの結果Bを比較することで、ソートアルゴリズムSが安定かどうか判定する関数
   戻り値： 安定である １   安定でない ０ */
int isStable(Card A[], Card B[], int n)
{
  int i;
  
  for( i = 0; i<n; i++ )
    {
      if( A[i].c != B[i].c )
	return 0;
    }
  return 1;
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll K;
	cin >> K;
	vector<ll> A(K);
	REP(i, K) cin >> A[i];

	ll ma = 2;
	ll mi = 2;
	REP(i, K){
		ll D = A[K-1-i];
		ll maD = (ma/D)*D;
		ll miD = (mi%D==0?mi:((mi/D)+1)*D);
		if(miD>maD){
			cout << -1 << endl;
			return 0;
		}
		ma = maD + D - 1;
		mi = miD;
	}
	cout << mi << " " << ma << endl;
    return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <cmath>
#include <ctime>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <chrono>
#include <functional>
#include <random>
#include <numeric>
#include <tuple>
#include <bitset>
using namespace std;
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef pair<int, int> ii;
template<class T> string toString(T x) { ostringstream ss; ss << x; return ss.str(); }
void solve();
int main() {
#ifdef LOCAL_COMP
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);
	solve();
#ifdef LOCAL_COMP
	cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


void solve() {
	int n;
	while (cin >> n) {
		vector<int> a(n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(all(a));
		map<int, int> mp;
		int prev = 0;
		int h = n;
		for (int i = 0; i < n; ) {
			int cnt = 1;
			int j = i;
			while (j < n && a[i] == a[j]) j++;
			int len = j - i;
			int diff = a[i] - prev;
			mp[h] = diff;
			h -= len;
			prev = a[i];
			i = j;
		}
		int res = 0;
		for (auto& it : mp) {
			int val = it.first;
			int cnt = it.second;
			if (cnt % 2 != 0) {
				res ^= val;
			}
		}
		if (res != 0) {
			cout << "first" << endl;
		} else {
			cout << "second" << endl;
		}
	}
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    if(s[0] == 'A' && s[1] == 'C')
    {
        cout << "Yes" << endl;
    }
    else if(s[1] == 'A' && s[2] == 'C')
    {
        cout << "Yes" << endl;
    }
    else if(s[2] == 'A' && s[3] == 'C')
    {
        cout << "Yes" << endl;
    }
    else if(s[3] == 'A' && s[4] == 'C')
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

}

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

using namespace std;
// using Graph = vector<vector<ll>>;

typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

const ll MOD = 1000000007;
const ll INF = 1e18; //1*10^18
const double PI = 3.14159265;

int ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
//最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//最小公倍数

ll powll(ll a, ll n)
{ //O(log n)
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a;
    }
    a = a * a;
    n >>= 1; //(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a, ll n, ll mod) //O(log n)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1; //(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number = to_string(num);
  return number.length();
}

const ll MAX = 1e6;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() //MODは素数じゃないとだよ！！
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind
{
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N)
  { //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x)
  { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y)
  {                   // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry)
      return;     //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y)
  { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main()
{
  // COMinit();
  // srand((unsigned int)time(NULL));//--> rand()
  ll i, j, k, l, ans = 0;
  ll n, x[500], position, saisyou = INF, count = 0;
  cin >> n;
  for (i = 0; i < n; i++)
  {
    cin >> x[i];
  }

  for (i = 0; i < 100; i++)
  {
    count = 0;
    for (j = 0; j < n; j++)
    {
      count += powll(x[j] - i, 2);
    }
    saisyou = min(saisyou, count);
  }

  ans = saisyou;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
const int N = 1e6;
int main(){
	Fast;
	ll n , p , q ,s;
	ll ans=0;
	cin >> p >> q >> s >> n;
	for(int i =0 ;i <=n ;i++){
	    for(int j=0;j<=n ;j++){
	       /// cout << n-p*i-q*j << endl;
	        if((n-p*i-s*j)%q==0 && ((n-p*i-s*j)/q>=0))
	        ans++;
	    }
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

int dp[3010][3010];
signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);

    string s,t;
    // 配列dp[文字列sのi文字目][文字列tのj文字目]
    stack <char> ans;
    cin>>s>>t;
    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int i=s.size();
    int j=t.size();
    while(dp[i][j]!=0){
        if(s[i-1] == t[j-1]){
            ans.push(s[i-1]);
            i--;
            j--;
        }else{
            if(dp[i-1][j] > dp[i][j-1]){
                i--;
            }else{
                j--;
            }
        }
    }
    while(!ans.empty()){
        cout<< ans.top();
        ans.pop();
    }
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll pw(ll x, ll k) {
	if (k == 0) return 1;
	else return x * pw(x, k - 1);
}

void solve() {
	int n, p;
	cin >> n >> p;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	int odd = 0;
	int even = 0;
	rep(i,n) {
		if (v[i] % 2 == 0) even++;
		else odd++;
	}
	if (odd == 0) {
		if (p == 1) cout << 0 << endl;
		else cout << pw(2, n) << endl;
	} else {
		cout << pw(2, even) * pw(2, odd - 1) << endl;
	}
}

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
int main() {
    ll a,b;
    cin>>a>>b;
    vector<pair<ll,ll>> p(a+1);
    ll q,r;
    for(ll i= 0;i<a;i++){
        cin>>q>>r;
        p[i] =  make_pair(q,r);
    
    }
sort(p.begin(),p.end());
auto it = p.begin();
priority_queue<ll> ps;
ll ans = 0;
for(ll i = 1;i<= b;i++){
    while(it != p.end() && it->first<= i){
ps.push(it->second);
it++;
    }
    if(!ps.empty()){
        ans += ps.top();
        ps.pop();
    }
}
cout<<ans<<"\n";
}


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

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;





int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int ans=0;
    for(int i=1;i<=n;++i){
        string s=to_string(i);
        int sum=0;
        for(int j=0;j<s.size();++j){
            sum+=s[j]-'0';
        }
        if(a<=sum&&sum<=b)ans+=i;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#! /usr/bin/env python3

n, m, qq = map(int, input().split())

lr = [[0 for i in range(n + 1)] for j in range(n + 1)]
acc = [[0 for i in range(n + 1)] for j in range(n + 1)]

for _ in range(m):
    l, r = map(int, input().split())
    lr[l][r] += 1

for i in range(1, n + 1):
    for j in range(1, n + 1):
        acc[i][j] = acc[i][j-1] + lr[i][j]

res = []
for _ in range(qq):
    ans = 0
    p, q = map(int, input().split())
    for i in range(p, q + 1):
        ans += acc[i][q] - acc[i][i - 1]
    res.append(ans)

for row in res:
    print(row)


Measured memory_bytes: 66648
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

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

	ll N;
	cin >> N;
	vector<ll> A(N),B(N);
	FOR(i,0,N)cin >> A[i] >> B[i];
	priority_queue< tuple<ll,ll,ll> > Q;
	FOR(i,0,N){
		Q.push({A[i]+B[i],A[i],B[i]});
	}
	ll ans = 0;
	FOR(i,0,N){
		if(i&1){
			ans -= get<2>(Q.top());
			Q.pop();
		}else{
			ans += get<1>(Q.top());
			Q.pop();
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 6260
#include<stdio.h>
int main(){
	int i,j,n,sum,max,min,s1,s2,s3,s4,s5;
	for(;scanf("%d",&n)&&n;){
		for(i=0;i<n&&scanf("%d %d %d %d %d",&s1,&s2,&s3,&s4,&s5);i++){
			sum=s5+s1+s2+s3+s4;
			if(!i){
				max=sum;min=sum;
			}
			else if(i==1){
				if(max<sum){
					min=max;max=sum;
				}
				else if(min>sum){
					max=min;min=sum;
				}
			}
			else {
				if(max<sum)max=sum;
				if(min>sum)min=sum;
			}
		}
		printf("%d %d\n",max,min);
	}
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define UF_NUM 505050

int main() {
    li n;
    string s;
    cin >> n >> s;
    li cnt[2] = {0};
    rin{
        cnt[s[i] == 'R' ? 1 : 0]++;
    }
    cout << (cnt[1] > cnt[0] ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	string S;
	cin >> S;

	string ans = "Yes";
	int N = S.size();
	REP(i, N / 2) {
		int idx = N - 1 - i;
		if (S[i] != S[N - 1 - i]) {
			ans = "No";
			break;
		}
	}

	REP(i, N / 4) {
		int idx = N / 2 - 1 - i;
		if (S[i] != S[idx]) {
			ans = "No";
			break;
		}

		int idx1 = i + (N + 3) / 2  - 1;
		int idx2 = idx + (N + 3) / 2 - 1;
		if (S[idx1] != S[idx2]) {
			ans = "No";
			break;
		}
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import *
import sys
try: fin = open('in')
except: fin = sys.stdin
input = lambda: fin.readline().strip()

mod = 10 ** 9 + 7

n, k = map(int, input().split())
nparts = []
i = 1
while i <= n:
	j = n // (n // i)
	nparts.append(j - i + 1)
	i = j + 1

row = nparts
for r in range(1, k):
    tmp = []
    s = 0
    for i in range(len(nparts) - 1, -1, -1): # go backwards
        s += row[-(i + 1)] # prefix sum thingy
        tmp.append(s * nparts[i] % mod)
    tmp.reverse()
    row = tmp

print (sum(row) % mod)

Measured memory_bytes: 137876
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using intl = int64_t;
using graph = vector<vector<int> >;
int main(){
    const intl m=1000000007;
    int n;
    cin >> n;
    intl a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    
    intl s[n-1];
    s[0]=a[0]%m;
    for(int i=1;i<n-1;i++){
        s[i]= (s[i-1]+a[i])%m; 
    }

    intl sum=0;
    for(int i=0;i<n-1;i++){
        sum += (s[i]*a[i+1])%m;
    }

    cout << sum%m << endl;
}

Measured memory_bytes: 6736
#!/usr/bin/python
# -*- coding: utf-8 -*-

# def
def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return x

def int_map():
    return map(int,input().split())

def int_list():
    return list(map(int,input().split()))

def print_space(l):
    return print(" ".join([str(x) for x in l]))

# import
import numpy as np



# main code
K = int(input())

if 7%K == 0:
    print(1)
    exit()


y = 7%K
x = 7%K

for i in range(1,K+1):
    x = (10*x)%K
    y = (y+x)%K
    if y == 0:
        print(i+1)
        exit()

print(-1)

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

int main(){
  int n,m;
  int cnt = 0;
  bool flag=true;
  cin >> n >> m;
  vector <int> a(n);
  rep(i,n)cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  rep(i,n){//cout << a[i] << " ";
    cnt+=a[i];
  }
  
  rep(i,m){
    double cnt2 = cnt/(4.0*m);
    //cout << " \n" << cnt2;
    if(a[i]<cnt2)flag=false;
  }
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp

signed main(){
	int k; cin>>k;
	string s; cin>>s;
	int n=s.size();
	if(n>k){
		rep(i,0,k){
			cout<<s[i];
		}
		cout<<"...";
	}
	else cout<<s;
	return 0;
}

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

#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  solve();
  return 0;
}

void solve() {
  int r, g;
  std::cin >> r >> g;
  cout(2 * g - r);
}


Measured memory_bytes: 256