akhauriyash/Code-Regression huggingface dataset:
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

const int MOD = 1000 * 1000 * 1000 + 7;
const int MX = 200 * 1000 + 7;

int mul(int x, int y) {
    return (1ll * x * y) % MOD;
}

void add(int& x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
}

int pw(int x, int y) {
    if (y == 0) {
        return 1;
    } else if (y % 2 == 0) {
        return pw(mul(x, x), y / 2);
    } else {
        return mul(pw(x, y - 1), x);
    }
}

int inv(int x) {
    return pw(x, MOD - 2);
}

int fc[MX], rfc[MX];

int C(int n, int k) {
    return mul(fc[n], mul(rfc[k], rfc[n - k]));
}

int f[MX][2];

int ways(int dx, int dy) {
    dx = abs(dx);
    dy = abs(dy);
    return C(dx + dy, dx);
}

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    fc[0] = 1;
    for (int i = 1; i < MX; i++) {
        fc[i] = mul(fc[i - 1], i);
    }
    rfc[MX - 1] = inv(fc[MX - 1]);
    for (int i = MX - 2; i >= 0; i--) {
        rfc[i] = mul(rfc[i + 1], i + 1);
    }

    int h, w, n;
    cin >> h >> w >> n;
    vector<pair<int, int> > pts;
    pts.emplace_back(1, 1);
    pts.emplace_back(h, w);
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        pts.emplace_back(x, y);
    }

    sort(pts.begin(), pts.end(), [&](auto u, auto v) {
        return u.first + u.second < v.first + v.second;
    });

    f[0][0] = 1;
    for (int i = 1; i < pts.size(); i++) {
        for (int j = 0; j < i; j++) {
            if (pts[j].first <= pts[i].first && pts[j].second <= pts[i].second) {
                add(f[i][0], mul(f[j][1], ways(pts[i].first - pts[j].first, pts[i].second - pts[j].second)));
                add(f[i][1], mul(f[j][0], ways(pts[i].first - pts[j].first, pts[i].second - pts[j].second)));
            }
        }
    }

    int ans = (f[pts.size() - 1][1] + MOD - f[pts.size() - 1][0]) % MOD;
    cout << ans << "\n";
    return 0;
}



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

using namespace std;

long long s;

void Reverse(long long &x){
    int xx = x;
    x = 0;
    while(xx / 10){
        x = x * 10 + xx % 10;
        xx /= 10;
    }
}
int main(){
    cin >> s;
    if (s > 1e9){
        if (s % 1000000000 == 0){
            printf("0 0 0 1000000000 %d 0", s/1000000000);
            return 0;
        }
        long long x = 1;
        long long temp = s;
        while(temp && x <= 1e10){
            x = x * 10 + temp % 10;
            temp /= 10;
        }
        x /= 10;
        Reverse(x);
        x = 1e9 - x;
        long long x2 = x, y1 = 1;
        long long x1 = 1e9, y2 = (s + x) / 1e9;
        printf("0 0 %lld %lld %lld %lld\n", x1, y1, x2, y2);
    }
    else              
        cout << "0 0 0 " << s << " 1 0" << endl;
    return 0;
}


Measured memory_bytes: 3700
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,k,a[200005]={},ans=0,b[200005]={},cnt=0,x;
  cin >> n >> k;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    b[a[i]-1]++;
  }
  for(int i=0; i<=200000; i++) {
    if(b[i]) {
      cnt++;
    }
  }
  if(cnt<=k) {
    cout << 0 << endl;
    return 0;
  }
  sort(b,b+n);
  x=cnt-k;
  for(int i=0; i<=200000; i++) {
    if(b[i]) {
      ans+=b[i];
      x--;
      if(x==0) {
        cout << ans << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}



signed main(){
	ll a,b,c,n,cnt = 0;
	cin >> a >> b >> c >> n;
	
	
	rep(i,0,n/a+1){
		rep(j,0,n/b+1){
			if((n-i*a-j*b) % c == 0 && (n-i*a-j*b) >= 0) cnt++;
		}
	}
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define inp 3005
#define check exit(0)
#define nl cout<<endl;
#define mod 1000000007 
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define deb(v) for(int i=0;i<v.size();i++) {cout<<v[i]; (i==v.size()-1) ? cout<<"\n":cout<<" "; }
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace __gnu_pbds;
using namespace std;

// Pick yourself up, 'cause...

// max ans. if i have an array i to j

vector<vector<ll>> dp(inp,vector<ll>(inp,-1));
vector<ll> pre(inp,0);

ll func(int i,int j)
{
    if(i==j) return pre[i]-pre[i-1];
    if(dp[i][j]!=-1) return dp[i][j];

    ll sum = pre[j]-pre[i-1]; //sum in these segment
    dp[i][j] = max(pre[i]-pre[i-1] + (pre[j]-pre[i]-func(i+1,j)) , pre[j]-pre[j-1] + (pre[j-1]-pre[i-1]-func(i,j-1)) );
    return dp[i][j];
}

int main()
{
    jaldi
    
    int n;
    cin>>n;

    vector<ll> v(n);
    for(ll &x:v) cin>>x;

    for(int i=1;i<=n;i++) { pre[i]=pre[i-1]+v[i-1]; }
    //deb(pre);
    ll first = func(1,n);
    ll second = pre[n]-first;
    cout<<first-second;

    return 0;
}


Measured memory_bytes: 74564
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)

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; }

using namespace std;

int main(void){
	int h,w;
	while(cin>>h>>w,h,w) {
		int diag2 = 150*150*2;
		int res_h, res_w;
		rep(_h,1,150+1) rep(_w,1,150+1) {
			if(_w > _h) {
				if(h*h+w*w <= _h*_h+_w*_w) {
					if(h*h+w*w==_h*_h+_w*_w && _h<=h) continue;
					if(chmin(diag2, _h*_h+_w*_w)) {
						res_h = _h;
						res_w = _w;
					}
				}
			}
		}
		cout << res_h << " " << res_w << endl;
	}
        
	return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define INF 9003372036854775807LL
#define mod 1000000007
#define fixed fixed<<setprecision(12)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
using pii=pair<int, int > ;
lol a[300010];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  lol n,m,k,r,x,y,z;
  cin >>n>>m>>r;
  if((n&1)||(m&1)||(r&1)){
    cout <<"0\n";
    return 0;
  }
  if(n==m&&m==r) cout <<"-1\n";
  else{
    bool u=true;
    lol ans=0;
    while(u){
      x=n,y=m,z=r;
      n=(y+z)/2;
      m=(x+z)/2;
      r=(x+y)/2;
      ans++;
      if(n&1) u=false;
      if(m&1) u=false;
      if(r&1) u=false;
    }
    cout <<ans<<'\n';
  }
  return (0);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N, M;
// vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  // A.resize(N);
  // for (int i = 0; i < N; i++) {
  //   int tmp;
  //   cin >> tmp;
  //   A[i] = tmp;
  // }

  if (N == M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

int main()
{    
    int n, ans = 0;
    string s;
    cin >> n >> s;

    for (int i = 0; i < 1000; i++) {
        int tmp[3] = {i/100, i/10%10, i%10};
        int cnt = 0;
        for (int j = 0; j < n; j++) {
            if (s[j] - '0' == tmp[cnt]) cnt++;
            if (cnt == 3) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define rrep(i, a, b) for(int i = a; i >= (b); --i)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int n; cin >> n;
  vector<double> dp(n+1);
  dp[0] = 1.0;
  rep(i,0,n){
    double d; cin >> d;
    rrep(j,i+1,0)
      dp[j] = (j ? dp[j-1] * d : 0) + dp[j] * (1-d);
  }
  double ans = 0.0;
  rep(i,n/2+1,n+1) ans += dp[i];
  cout << fixed << setprecision(10) << ans << "\n";
}


Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, M;
vector<int> A;
bool jdg = 1;
cin >> N;
for(int i=0; i<N; i++){
  cin >> M;
  A.push_back(M);
}
for(int i=0; i<N; i++){
  if( (A.at(i) % 2 == 0) && (A.at(i) % 3 != 0) && (A.at(i) % 5 != 0)){
    jdg = 0;
    break;
  }
}
if(jdg){
  cout << "APPROVED" << endl;
}
else{
  cout << "DENIED" << endl;
}
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int n = read(), tmp = n;
  int sum = 0;
  while (tmp != 0) {
    sum += tmp % 10;
    tmp = tmp / 10;
  }
  if (n % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> xs(n), ls(n);
    for(int i = 0; i < n; i++){
        cin >> xs[i] >> ls[i];
    }
    vector<int> is(n);
    iota(is.begin(), is.end(), 0);
    sort(is.begin(), is.end(), [&](int i, int j){ return xs[i] + ls[i] < xs[j] + ls[j]; });
    map<int, int> mp;
    mp[-M] = 0;
    for(auto& i : is){
        auto ite = mp.upper_bound(xs[i] - ls[i]);
        ite--;
        int cand = ite->second + 1;
        auto ite2 = mp.end();
        ite2--;
        if(cand > ite2->second){
            mp[xs[i] + ls[i]] = cand;
        }
        printde(mp);
    }
    auto ite = mp.end();
    ite--;
    cout << ite->second << '\n';
}


Measured memory_bytes: 6144
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    const double PI=3.14159265358979323846;

    double hRad = (H / 12.0 + M / 12.0 / 60.0) * 2.0 * PI;
    double mRad = M / 60.0 * 2.0 * PI;

    double rad = hRad < mRad ? mRad - hRad : hRad - mRad;

    double length = sqrt(A * A + B * B - 2.0 * A * B * cos(rad));

    cout << fixed << setprecision(20) << length << endl;

    return 0;
}

Measured memory_bytes: 4164
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
V<int> dx={0,-1,0,1},dy={-1,0,1,0};
vector<bool> prime;
void make(int num){
    prime.resize(num,true);
    prime[0]=false;
    for(int i=0;i*i<num;i++){
        if(prime[i]){
            for(int j=2;(i+1)*j<=num;j++){
                prime[(i+1)*j-1]=false;
            }
        }
    }
}
int main(){
	make(500000);
while(1){
	int n;
	cin>>n;
	if(n==0)return 0;
	int ans=0;
	for(int i=n;i<2*n;i++)if(prime[i])ans++;
	cout<<ans<<endl;
}
}



Measured memory_bytes: 3284
#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,k;
  cin >> n >> k;
  vector<int> x(n);
  rep(i,n) cin>>x[i];
  int sum=0;
  rep(i,n) sum+=2*(min(x[i],k-x[i]));
  cout << sum;
  return 0;
}

Measured memory_bytes: 3560
#include <iostream>
 
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b&&b==c){ cout << 1 << endl; }
    else if(a==b||b==c||a==c){ cout << 2 << endl; }
    else{ cout << 3 << endl; }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n,k = map(int, input().split())
h_list = []

for _ in range(n):
    h_list.append(int(input()))

sort_h_list = sorted(h_list)

L_index = 0
R_index = 0
L_value = sort_h_list[0]
R_value = sort_h_list[0]
count = 0
ans = 10**9

#尺取り法ぽいの
while (R_index < n):
    if (count < k):
        count += 1
        R_value = sort_h_list[R_index]
        if count == k:
            ans = min(ans,R_value - L_value)
        R_index += 1

    else:
        count -= 1
        L_index += 1
        L_value = sort_h_list[L_index]

print(ans)

Measured memory_bytes: 14172
#include <stdio.h>

int main()
{
    int x=0,y=0;
    
    while(1)
    {
        scanf("%d %d\n",&x,&y);
        
        if(x==0&&y==0)
        {
            break;
        }
       
        if(x<y)
        {
            printf("%d %d\n",x,y);
        }else
        {
            printf("%d %d\n",y,x);
        }
    }
    
    return 0;
}


Measured memory_bytes: 1952
import sys
from bisect import bisect
from itertools import accumulate


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = sorted(map(int, input().split()))
    b = sorted(map(int, input().split()))
    c = sorted(map(int, input().split()))
    # 各中部パーツを乗せられる下部パーツの個数
    # b_c_cnt = [len(c[bisect(c, b[i]) :]) for i in range(n)]
    b_c_cnt = [0] * n
    past = 0
    for i in range(n):
        pos = bisect(c, b[i], lo=past)
        past = pos
        b_c_cnt[i] = n - pos

    # b_c_cntに後ろから累積和をとる
    acc = list(accumulate(b_c_cnt[::-1]))[::-1] + [0]
    ans = 0
    past = 0
    for i in range(n):
        pos = bisect(b, a[i], lo=past)
        ans += acc[pos]
        past = pos
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

typedef vector<int> V;

bool binary_search(V v, int t) {
    int left = 0;
    int right = v.size();
    while (left < right) {
        int mid = (left + right) / 2;
        if (v[mid] == t) {
            return true;
        } else if (v[mid] > t) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    V s = V(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    int q;
    cin >> q;
    int c = 0;
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (binary_search(s, t)) {
            c++;
        }
    }

    cout << c << "\n";
}



Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll x;
    cin >>x;
    ll ans;
    if(x%11==0){
        ans=x/11*2;
    }else if((x-x/11*11)<=6){
        ans=x/11*2+1;
    }else{
        ans=x/11*2+2;
    }
    
    cout << ans<< endl;


    return 0;
    

}

Measured memory_bytes: 3604
import sys

N, W = map(int, input().split())
WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]

INF = 10**10 + 1
dp = [[INF]*(N+1) for i in range(1000*N+2)]

for i in range(N+1):
        dp[0][i]=0

i = 1

while(True):
        for j in range(1, N+1):
                if i-WV[j-1][1]>=0:
                        dp[i][j] = min(dp[i-WV[j-1][1]][j-1]+WV[j-1][0], dp[i][j-1])
                else:
                        dp[i][j] = min(dp[i][j-1], WV[j-1][0])
        #print(i, dp[i][N])
        if dp[i-1][N] <= W and dp[i][N] > W:
                break
        i += 1

print(i-1)

Measured memory_bytes: 130780
#include <iostream>
#include<stdio.h>
using namespace std;
int main(void){
    int n,f[45];
    cin>>n;
    f[0]=1;
    f[1]=1;
    for(int i=2;i<=n;i++){
        f[i]=f[i-1]+f[i-2];
    }
    cout<<f[n]<<endl;
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>

using namespace std;

const double PI = 3.14159265358979;

struct Node {
	int key;
	Node* left, * right;
};

void preorder(Node* const root) {

	if (root) {
		printf(" %d", root->key);
		preorder(root->left);
		preorder(root->right);
	}
}

void inorder(Node* const root) {

	if (root) {
		inorder(root->left);
		printf(" %d", root->key);
		inorder(root->right);
	}
}


void insert_key(Node *root, int key) {

	Node* comer = new Node;
	comer->key = key;
	comer->left = 0;
	comer->right = 0;

	Node* temp = root;
	Node* par = 0;
	while (temp) {
		par = temp;
		if (key < temp->key)
			temp = temp->left;
		else
			temp = temp->right;
	}
	if (key < par->key) par->left = comer;
	else par->right = comer;

}

void display_tree(Node* const root) {

	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
}

int main() {

	int n;  cin >> n;
	Node* root = 0;

	string cmd;
	int key;
	for (int i = 0; i < n; i++)	{
		cin >> cmd;
		if (cmd[0] == 'i') {
			cin >> key;
			if (!root) {
				root = new Node;
				root->key = key;
				root->left = root->right = 0;
			} else
				insert_key(root, key);
		} else {
			display_tree(root);
		}
	}

	return 0;
}



Measured memory_bytes: 18852
w,h,n=[int(j) for j in input().split()]
xl,xr=0,w
yl,yr=0,h
for i in range(n):
    x,y,a=[int(j) for j in input().split()]
    if a==1:
        xl=max(xl,x)
    elif a==2:
        xr=min(xr,x)
    elif a==3:
        yl=max(yl,y)
    else:
        yr=min(yr,y)
if (xr-xl)>=0 and (yr-yl)>=0:
    ans=(xr-xl)*(yr-yl)
else:
    ans=0
print(ans)

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

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int A, B;
  cin >> A >> B;
  if (A >= 13) cout << B << endl;
  else if (A > 5) cout << B/2 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b){
    return *(int *)b - *(int *)a;
}

int main(void){
    int N = 0; int H = 0;
    scanf("%d %d", &N, &H);
    int a[100000] = {0}; int b[100000] = {0};
    for(int i = 0; i < N; i++){
        scanf("%d %d", &a[i], &b[i]);
    }
    int amax = 0;
    for(int i = 0; i < N; i++){
        if(amax < a[i]){
            amax = a[i];
        }
    }
    qsort(b, N, sizeof(int), compare_int);

    int attack = 0;
    for(int i = 0; i < N; i++){
        if(b[i] >= amax){
            H -= b[i];
            attack++;
            if(H <= 0){
                break;
            }
        }else {
            break;
        }
    }
    while(H > 0){
        H -= amax;
        attack++;
    }
    printf("%d\n", attack);
    return 0;
}

Measured memory_bytes: 1276
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

S.append(0)
T.append(0)
MAX = 2005
dp0 = [[0] * MAX for _ in range(MAX)]
dp1 = [[0] * MAX for _ in range(MAX)]

dp0[0][0] = 1
for i in range(N + 1):
    for j in range(M + 1):
        dp0[i + 1][j] += dp0[i][j] % MOD
        dp1[i][j] += dp0[i][j] % MOD
        dp1[i][j + 1] += dp1[i][j] % MOD
        if S[i] == T[j]: 
            dp0[i + 1][j + 1] += dp1[i][j] % MOD
print(dp1[N][M] % MOD)


Measured memory_bytes: 133200
import fractions as math

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

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

l = a[0]
for num in a[1:]:
    l = lcm(num, l)

ans = 0
for num in a:
    ans += (l - 1) % num

print(ans)



Measured memory_bytes: 5600
#include <algorithm>
#include <iostream>

using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], b[maxn];
int main(void)
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        cin >> b[i];
    int j = 0, last = -1;
    for (int i = 0; i < n; ++i)
    {
        if(last!=a[i])
            j = 0;
        if (a[i] == b[i])
        {
            for (; j < n; ++j)
            {
                if (a[j] != a[i] && b[j] != a[i])
                {
                    swap(b[i], b[j]);
                    break;
                }
            }
            if (a[i] == b[i])
            {
                cout << "No" << endl;
                return 0;
            }
        }
        last = a[i];
    }
    cout << "Yes" << endl;
    for (int i = 0; i < n; ++i)
        cout << b[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 5192
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
using namespace std;

int main(int argc, const char * argv[]) {
    int x;
    cin >> x;
    if(x==0) cout << 1 << endl;
    else if(x==1) cout << 0 << endl;
    return 0;
}



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

int main(){
  int n,m,a,b,cnt=0;
  int mp[10][10]={};
  cin>>n>>m;
  int p[n];

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

  for(int i=0;i<m;++i){
    cin>>a>>b;
    mp[a][b]=mp[b][a]=1;
  }

  do{
    if(p[0]!=1)break;
    bool ans=true;

    for(int i=1;i<n;++i){
      if(mp[p[i]][p[i-1]]!=1){
	ans=false;
      }
    }

    if(ans)cnt++;

  }while(next_permutation(p,p+n));

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc124/tasks/abc124_d

N, K = map(int, input().split())
S = input()
arr = []
prev = '1'
length = 0
for c in S:
  if prev != c:
    arr.append(length)
    length = 0
  length += 1
  prev = c
arr.append(length)
if S[-1] == '0':
  arr.append(0)

arr = [0] + arr
for i in range(len(arr) - 1):
    arr[i + 1] += arr[i]

L = K * 2 + 1
if L >= len(arr):
  print(N)
  exit()
ans = 0
for i in range(0, len(arr) - L, 2):
    t = arr[i + L] - arr[i]
    ans = max(ans, t)
print(ans)


Measured memory_bytes: 79544
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, o, e;
    cin >> n;
    for(ll i=0, x ; i<n ; i++){
        cin >> x;
        if(x % 2 == 0){
            e++;
        } else {
            o++;
        }
    }
    if(o%2 != 0){
        cout << "NO\n";
    } else {
        cout << "YES\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#include "string"

const int N = 2e5 + 5;
string s;
int dp[N][2];

int solve(int id,int cur) {
	if(id >= s.size())
		return 0;
	int &tmp = dp[id][cur];
	if(tmp != -1)
		return tmp;
	if(cur) {
		if(s[id] == 'W') {
			tmp = solve(id + 1, 1) + 1;
			tmp = min(tmp , solve(id + 1, 0));
		}
		else
			tmp = solve(id + 1, 1);
	}
	else{
		tmp = solve(id + 1, cur);
		if(s[id] == 'R')
			tmp++;
	}
	return tmp;
}

int32_t main(){
	boost;
	int n; 
	cin >> n;
	cin >> s;
	int sf[n + 1] = {0};
	for(int i = n - 1; i >= 0; i--) {
		if(s[i] == 'R')
			sf[i]++;
		sf[i] += sf[i + 1];
	}
	int cnt = 0;
	int ans = n;
	for(int i = 0; i < sf[0]; i++) {
		if(s[i] == 'R')
			cnt++;
		int req = i + 1 - cnt;
		ans = min(ans , req + sf[i + 1] - req);
	}
	ans = min(ans , sf[0]);
	cout << ans << endl;
}


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

if N <= 2:
    print(N)
else:
    s = 0
    l = []
    for i in range(1, N):
        s += i
        l.append(i)
        if s > N:
            break
    # print(l)

    for i in range(len(l)):
        if s-l[i] == N:
            l.pop(i)
            break

    for i in l:
        print(i)


Measured memory_bytes: 3572
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
//    cout << fixed << setprecision(10);
    
    int K, A, B;
    cin >> K >> A >> B;
    
    A -= 1;
    A /= K;
    B /= K;
    
    if (B - A >= 1) {
        cout << "OK";
    } else {
        cout << "NG";
    }
    
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
using namespace std;

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

typedef long long ll;

int a,d,n;
bool p[1100000];

void solve(){
}

int main(){
  memset(p,true,sizeof(p));
  p[0] = p[1] = false;
  rep(i,1100000){
    if(p[i]){
      for(int j=i+i;j<=1100000;j+=i){
        p[j] = false;
      }
    }
  }

  while(cin>>a>>d>>n,a||d||n){
    while(1){
      if(p[a]){
        n--;
        if(n == 0) break;
      }
      a += d;
    }
    cout<<a<<endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
  int H,W;
  cin>>H>>W;
  string S[100]={};
  for(int i=0;i<H;i++){
      string P;
      cin>>P;
      S[i]=P;
  }
  string Q[200]={};
  for(int i=0;i<H;i++){
        Q[2*i]=S[i];
        Q[2*i+1]=S[i];
  }
  for(int i=0;i<2*H;i++){
      cout<<Q[i]<<endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str=Console.ReadLine().Split(' ');
    long N=long.Parse(str[0]);
    long A=long.Parse(str[1]);
    long B=long.Parse(str[2]);
     long ans=N/(A+B)*A;
      long rem=N%(A+B);
      if(rem<A){
        ans+=rem;
      }else{
          ans+=A;
        }
          
      Console.WriteLine(ans);
    }
  }

}


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

int main() {
 	    int n,k;
         cin>>n>>k;
         int arr[n];
         for(int i=0;i<n;i++)cin>>arr[i];
         long int dp[n];
         dp[0]=0; //first stone
         for(int i=1;i<n;i++){
             dp[i]=LONG_MAX; //as it is surely more than first cost we encounter in inner loop where we used mins
             for(int j=1;j<=k;j++)
             if(i-j>=0) //i.e not out of array
             dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
             
         }
         cout<<dp[n-1]<<endl;

	return 0;
}

Measured memory_bytes: 4728
def main():
  n = int(input())
  a = n*(n+1)/2
  b = (n//3)*(n//3+1)/2*3
  c = (n//5)*(n//5+1)/2*5
  d = (n//15)*(n//15+1)/2*15
  print(int(a-b-c+d))
main()

Measured memory_bytes: 9184
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string.h>
using namespace std;
typedef long long int llint;
int main(){
	char a[110], b[110];
	cin >> a >> b;
	if (strlen(a) != strlen(b)){
		if (strlen(a) < strlen(b)){
			cout << "LESS" << endl;
		}
		else{
			cout << "GREATER" << endl;
		}
	}
	else{
		for (int i = 0; i < strlen(a); i++){
			if (a[i] < b[i]){
				cout << "LESS" << endl;
				return 0;
			}
			if (a[i]>b[i]){
				cout << "GREATER" << endl;
				return 0;
			}
		}
		cout << "EQUAL" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  Int ans=0;
  for(Int i=0;i<n;i++) ans|=a[i]&1;  
  
  cout<<(ans?"first":"second")<<endl;
  return 0;
}


Measured memory_bytes: 1024
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    # for i in range(h):
    #     print("#" * w)
    # print()
    for height in range(h):
        for width in range(w):
            print('#', end='')
        print()
    print()


Measured memory_bytes: 7000
#include<stdio.h>
int main()
{
    int i,j,h[10],temp;
for(i=0;i<10;i++)
    scanf("%d",&h[i]);


      for(i=0;i<10;i++)
      {
          for(j=i+1;j<10;j++)
            {if(h[i]<h[j])
          {temp=h[i];
          h[i]=h[j];
          h[j]=temp;


          }
      }}
for(i=0;i<3;i++)
    printf("%d\n",h[i]);
return 0;
}



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

int n,m;
vector<int>vec[100005];
vector<int>dis(100005,0);
vector<bool>vis(100005,false);

void dfs(int nod)
{
//	cout<<nod<<" ";
	vis[nod]=true;
	for(int i=0;i<vec[nod].size();i++)
	{
		if(!vis[vec[nod][i]])
		dfs(vec[nod][i]);
		
		dis[nod]=max(1+dis[vec[nod][i]],dis[nod]);
		
	}
}


int main()
{
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
    int a,b;
    cin>>n>>m;
    while(m--)
    {
    	cin>>a>>b;
    	vec[a].push_back(b);
	}
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		dfs(i);
	}
	int ma=0;
	for(int i=1;i<=n;i++)
	ma=max(ma,dis[i]);
    cout<<ma;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#include<unordered_map>
#define ll long long
using namespace std;
#define sd(n) scanf("%d",&n)
#define clr(a) memset(a,0,sizeof(a)) 
ll a;
int main(){
	cin>>a;
	if(a%2==0){
		cout<<a;
	}else
	cout<<2*a;
} 


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<functional>

#define REP(i,n) for(int i=0;i<n;i++)
#define ll long long int

using namespace std;

int to_int(string s) {
  return atoi(s.c_str());
}

vector<ll> a;

int main() {
  int n;
  cin >> n;

  a.resize(n);
  REP(i,n) {
    cin >> a[i];
    a[i] -= i+1;
  }

  sort(a.begin(), a.end());
  ll b;
  if(n%2 == 0) {
    b = a[n/2 -1];
  } else {
    b = a[(n-1)/2];
  }

  ll r = 0;

  REP(i,n) {
    r += abs(a[i] - b);
  }

  cout << r << endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	double r;
	cin >> r;
	double pi = 3.1415926;
	cout << setprecision(10) << 2*r*pi << endl;

  return 0;
}


Measured memory_bytes: 3772
#include<stdio.h>
    int main()
    {
        int a, b, all=1, i;
        scanf("%d%d",&a,&b);
        for(i=0;;i=i+1)
        {
            if(all>=b)
                break;
            else all--,all +=a;
        }
        printf("%d\n",i);
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % moder;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), moder - 2, moder) % moder * mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

string s;
signed main() {
	cin >> s;
	//01...
	int ans1 = 0;
	rep(i, s.size()) {
		if (i % 2 == 0 && s[i] != '0')ans1++;
		if (i % 2 && s[i] != '1')ans1++;
	}
	//10...
	int ans2 = 0;
	rep(i, s.size()) {
		if (i % 2 == 0 && s[i] != '1')ans2++;
		if (i % 2 && s[i] != '0')ans2++;
	}
	cout << min(ans1, ans2) << endl;
}

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

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

    ll a, b, x;
    cin >> a >> b >> x;
    if (a == 0) cout << b / x + 1 << endl;
    else if (a == b && b % x == 0) cout << 1 << endl;
    else cout << b / x - (a - 1) / x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

int ctoi(char c) {
   return c - '0';
}
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n, m;
   cin >> n >> m;
   vector<P> p(m);
   rep(i, 0, m) { cin >> p[i].first >> p[i].second; }
   rep(x, 0, 1000) {
      string t = to_string(x);
      if (t.size() != n) continue;
      bool ok = true;

      rep(i, 0, m) {
         if (ctoi(t[p[i].first - 1]) != p[i].second) ok = false;
      }
      if (ok) {
         cout << x << endl;
         return 0;
      }
   }
   cout << -1 << endl;
   return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/14  Problem: 079_abc_c / Link: https://abc079.contest.atcoder.jp/tasks/abc079_c?lang=en  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VI a(4);
	FOR(i, 0, 4) {
		a[i] = N / (int)pow(10, 3 - i);
		a[i] %= 10;
	}
	string OP = "+-";
	FOR(op, 0, 1<<3) {
		int ret =a[0];
		FOR(i, 1, 4) {
			if (op&(1 << (i - 1))) {
				ret -= a[i];
			}
			else ret += a[i];
		}
		if (ret == 7) {
			cout << a[0];
			FOR(i, 1, 4) {
				cout << OP[(op&(1 << (i - 1))) ? 1 : 0];
				cout << a[i];
			}
			cout << "=7" << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
    int h, w;
    int i, j;
    while(1){
        scanf("%d %d ", &h, &w);
        if(h==0&&w==0)break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}


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

int main(){

	int n,ans=0,count=0;
	string s;
	cin >> n >> s;
	for(int i = 0; i < n; i++){
		if(s[i] == 'I'){
			count ++;
		}
		else{
			count --;
		}
		ans = max(ans,count);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
map<int,int> mp;
const int maxn=200005;
int vis[maxn];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int z;
        scanf("%d",&z);
        mp[z]++;
    }
    int m;
    scanf("%d",&m);
    bool f=1;
    for(int i=1;i<=m;i++){
        int z;
        scanf("%d",&z);
        if(f&&mp[z]>0)
            mp[z]--;
        else f=0;
    }
    if(f)
        printf("YES\n");
    else printf("NO\n");

}


Measured memory_bytes: 9600
// Slimes.cpp
// https://atcoder.jp/contests/dp/tasks/dp_n

#include <iostream>
#include <cstring>
#include <climits>

using namespace std;
typedef long long int llu;

pair<llu, llu> memoTable[400][400];
bool isComputed[400][400];

int nSlimes;
int slimesLen[400];

pair<llu, llu> minCost(int i, int j){

    if(i == j){
        return make_pair(slimesLen[i], 0);
    }

    if(isComputed[i][j] == 1){
        return memoTable[i][j];
    }

    isComputed[i][j] = 1;

    pair<llu, llu> cost (LONG_MAX, LONG_MAX);
    pair<llu, llu> t1;
    pair<llu, llu> t2;


    for(int k = i; k<j; ++k){

        t1 = minCost(i, k);
        t2 = minCost(k+1, j);

        if(t1.first + t2.first <= cost.first && t1.second + t2.second < cost.second){
            cost.first = t1.first + t2.first;
            cost.second =  t1.second + t2.second;
        }
    }

    cost.second += cost.first;
    memoTable[i][j] = cost;
    return cost;
}


int main(){

    // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); cout<<"Slimes.cpp\n";

    memset(isComputed, 0, sizeof(isComputed));

    cin >> nSlimes;
    for(int i=0; i<nSlimes; ++i){
        cin >> slimesLen[i];
    }    

    pair<llu,llu>p = minCost(0, nSlimes-1);
    cout<<p.second;
    return 0;
}



Measured memory_bytes: 2816
#include <iostream>
#include <climits>
#include <algorithm>
#include <numeric>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <array>
#include <memory>

#define IN(a,b) (a.find(b) != a.end())
#define p(a,b) make_pair(a,b)
#define readVec(a) for (int64_t __i = 0; __i<(int64_t)a.size();__i++){cin>>a[__i];}

// jimjam

template<typename T>
void pMin(T &a, T b) {if (b<a){a=b;}}
template<typename T>
void pMax(T &a, T b) {if (b>a){a=b;}}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c);
template<typename A, typename B>
std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& c) {std::cout << "(" << c.first << ", " << c.second << ")";return os;}

using namespace std;

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

	const int64_t mod = 1e9+7;
	int64_t n; cin >> n;
	vector<int64_t> a(n);
	readVec(a);
	
	int64_t ans=0;
	
	int64_t sumBefore=a[0];
	for (int i = 1; i < n; i++) {
		ans += a[i] * sumBefore;
		ans %= mod;
		sumBefore %= mod;
		sumBefore+=a[i];
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 4784
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

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

int main()
{
	int n;
	cin >> n;
	int a = n / 1000;
	int b = (n % 1000) / 100;
	int c = (n % 100) / 10;
	int d = n % 10;
	vector<int> v{ a,b,c,d };

	for (int i = 0; i < 1 << 3; i++)
	{
		bitset<3> s(i);
		int sum = v[0];
		for (int i = 0; i < 3; i++)
		{
			if (s.test(i))
			{
				sum += v[i + 1];
			}
			else
			{
				sum -= v[i + 1];
			}
		}

		if (sum == 7)
		{
			cout << a << (s.test(0) ? '+' : '-') << b << (s.test(1) ? '+' : '-')
				<< c << (s.test(2) ? '+' : '-') << d << "=7";
			break;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
ll p[100009], mod=1000000007;
ll n, m ;
int main()
{
	IO;
	p[0]=1;
	for (int i=1; i<=100000; i++)
		p[i]=(i*p[i-1])%mod;
	cin>>n>>m;
	if (abs(n-m)>1)
		return cout<<0, 0;
	if (abs(n-m)==1)
		cout<<(p[n]*p[m])%mod;
	else
		cout<<((2*p[n]*p[m])%mod);
}


Measured memory_bytes: 1024
c(void *a,void *b){
  return *(int*)a - *(int*)b;
}
a[3];
main(void){
  scanf("%d%d%d",a,a+1,a+2);
  qsort(a,3,4,c);
  printf("%d %d %d\n",*a,a[1],a[2]);
  return 0;
}

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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void solve(){
	ll n;
	cin >> n;
	string s;
	ll k;
	ll a[n+1] = {0};
	map < string, ll > mpp;
	rep(i, n){
		cin >> s >> k;
		mpp[s] = i+1;
		a[i+1] = k;
	}
	fo(i, 1, n){
		a[i] += a[i-1];
	}
	cin >> s;
	cout << a[n] - a[mpp[s]] << endl;
}

int main(){
    IOS;
    //io_set();
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
    }
    return 0;
} 


Measured memory_bytes: 256
#include<stdio.h>
  
int main(void)
{
	int t[4][14];
	int n, i, j, c;
	char m, d;
	for (i = 0; i < 4; i++){
		for (j = 0; j < 14; j++){
			t[i][j] = 0;
		}
	}
	scanf("%d", &c);
	for (i = 0; i < c; i++){
		scanf("%c", &d);
		scanf("%c %d", &m, &n);
		if (m == 'S'){
			t[0][n] = 1;
		}
		else if (m == 'H'){
			t[1][n] = 1;
		}
		else if (m == 'C'){
			t[2][n] = 1;
		}
		else if (m == 'D'){
			t[3][n] = 1;
		}
	}
	for (j = 1; j < 14; j++){
		if (t[0][j] != 1){
			printf("S %d\n", j);
		}
	}

	for (j = 1; j < 14; j++){
		if (t[1][j] != 1){
			printf("H %d\n", j);
		}
	}

	for (j = 1; j < 14; j++){
		if (t[2][j] != 1){
			printf("C %d\n", j);
		}
	}

	for (j = 1; j < 14; j++){
		if (t[3][j] != 1){
			printf("D %d\n", j);
		}
	}
	return 0;
}


Measured memory_bytes: 2048