akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int N, W; cin >> N >> W;
   V<int> v(N), w(N);
   REP(i, N) {
      cin >> v[i] >> w[i];
   }

   V<int> dp(W+1);
   REP(j, N) REP(i, W) if (i + w[j] <= W) {
      chmax(dp[i + w[j]], dp[i] + v[j]);
   }
   cout << dp[W] << endl;

   // V<V<int>> dp(N+1, V<int>(W+1));
   // REP(i, W) {
   //    REP(j, N) if (i + w[j] <= W) {
   //       chmax(dp[j+1][i + w[j]], dp[j][i] + v[j]);
   //       chmax(dp[j+1][i], dp[j][i]);
   //    }
   // }

   return 0;
}



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

int main(){
    int N,i;
    int A;
    int temp=0;
    int count=100;

    cin >> N;

    for(i=0;i<N;i++){
        cin >> A;
        temp=0;
        while(A%2==0){
            A/=2;
            temp++;
        }
        if(count>temp){
            count=temp;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
d={}
for a in A:
    if a in d:
        d[a]+=1
    else:
        d[a]=1
a=0
if len(d)==1 and 0 in d:
    a=1
elif len(d)==2:
    k=sorted(d.keys(),key=lambda x:d[x])
    if k[1]^k[1]==k[0] and d[k[0]]*2==d[k[1]]:
        a=1
elif len(d)==3:
    k=list(d.keys())
    if k[0]^k[1]==k[2] and d[k[0]]==d[k[1]]==d[k[2]]:
        a=1
print(['No','Yes'][a])

Measured memory_bytes: 14116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); i++)
 
int main() {
 int n,k,ans;
 ans=1;
 cin>>n>>k;
 rep(i,n){
   if(ans<k){
     ans=ans*2;
   }else{
     ans+=k;
   }
 }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
A = []
for i in range(H):
    a = list(input())
    if '#' in a:
        A.append(a)
ans = []
for col in zip(*A):
    if '#' in col:
        ans.append(col)
for i in zip(*ans):
    print(''.join(i))

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

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}

typedef long long LL;
const int N=5010,M=210;
int L[M][N],R[M][N];
int B[M][N],n,m;
int stk[N],w[N],top;
LL a[N],mat[N][N];

int main()
{
    n=read();m=read();
    for(int i=2;i<=n;i++)
        a[i]=a[i-1]+read();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            B[j][i]=read();
    for(int i=1;i<=m;i++)
    {
        top=0;
        for(int j=1;j<=n;j++)
        {
            while(top&&w[top]<B[i][j]) top--;
            L[i][j]=top?stk[top]+1:1;
            stk[++top]=j;w[top]=B[i][j];
        }
        top=0;
        for(int j=n;j>=1;j--)
        {
            while(top&&w[top]<B[i][j]) top--;
            R[i][j]=top?stk[top]-1:n;
            stk[++top]=j;w[top]=B[i][j];
        }
        for(int j=1;j<=n;j++)
        {
            mat[L[i][j]][j]+=B[i][j];
            mat[L[i][j]][R[i][j]+1]-=B[i][j];
            mat[j+1][j]-=B[i][j];
            mat[j+1][R[i][j]+1]+=B[i][j];
        }
    }
    LL ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++) mat[i][j]+=mat[i][j-1];
        for(int j=1;j<=n;j++) mat[i][j]+=mat[i-1][j];
        for(int j=i;j<=n;j++) ans=max(ans,mat[i][j]-a[j]+a[i]);
    }
    printf("%lld\n",ans);
    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

// E log V
const int INF = 1e9+7;
const int MAXV = 1e5*2+2;
struct edge { int to, cost; edge(int t, int c) : to(t), cost(c) {} };
int V;
vector<edge> G[MAXV];
int d[MAXV];

void dijkstra(int s) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(make_pair(0, s));

    while (!que.empty()) {
        pair<int, int> p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    V = N+M;
    rep(i, N) {
        int k;
        cin >> k;
        rep(j, k) {
            int l;
            cin >> l;
            l--;
            G[i].emplace_back(N+l, 1);
            G[N+l].emplace_back(i, 1);
        }
    }
    dijkstra(0);
    bool ok = true;
    rep(i, N) { if (d[i] == INF) { ok = false; break; }}
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}


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

using namespace std;

const int MaxN = 1e5 + 15;
const int INF = 1e9;
const long double eps = 1e-9;

int n, m;

vector <pair<int, int> > v[MaxN];
bool used[MaxN];
int d[MaxN];

void dfs(int x, int y)
{
    used[x] = true;
    d[x] = y;
    for(auto to : v[x])
    {
        if(!used[to.first])
            dfs(to.first, y + to.second);
        else
        {
            if(d[to.first] != y + to.second)
            {
                cout << "No\n";
                exit(0);
            }
        }
    }
}


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

//    freopen("input.txt", "r", stdin);

    cout.precision(9);

    cin >> n >> m;
    for(int i = 1; i <= m; ++i)
    {
        int x, y, z;
        cin >> x >> y >> z;
        v[x].push_back(make_pair(y, z));
        v[y].push_back(make_pair(x, -z));
    }
    for(int i = 1; i <= n; ++i)
        if(!used[i])
            dfs(i, 0);

    cout << "Yes\n";

    return 0;
}


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

int main() {
        int N, M;
        cin >> N >> M;
        vector<int>             a(N);
        vector<int>             b(M);
        vector<int>             c(N, 0);

        rep(n, N) {
                cin >> a[n];
        }

        rep(m, M) {
                cin >> b[m];
        }

        rep(m, M) {
                rep(n, N) {
                        if (b[m] >= a[n]) {
                                c[n]++;
                                break;
                        }
                }
        }
        int ansp = -1, ansn;
        rep(n, N) {
                if (ansp <= c[n]) {
                        ansp = c[n];
                        ansn = n;
                }
        }
        cout << ansn+1 << endl;
        return 0;
}



Measured memory_bytes: 3100
N = gets.to_i
array = []
N.times do
  array << gets.split(' ')
end

array_sorted = array.sort{|a, b| (a[0] <=> b[0]).nonzero? || (b[1].to_i <=> a[1].to_i)}

ans = []
array_sorted.each do |e|
  array.each.with_index(1) do |e2, i|
    if e[0] == e2[0] && e[1] == e2[1]
      ans << i
      break
    end
  end
end
 
puts ans

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll

class BGuidebook {
public:
        pair<string, int> P[222];
        map<pair<string, int> , int> M;
void solve(std::istream& cin, std::ostream& cout) {
    int N;
    cin >> N;
    string s;
    int n;
    _for(i,N){
        cin >> s >> n;
        M[{s,-n}] = i+1;
        P[i] = {s,-n};
    }
    sort(P, P+N);
    _for(i,N)cout << M[P[i]] << endl;
}
};


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


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


int main()
{
  int N;
  cin >> N;//N泊する
  int K;
  cin >> K;//K泊まではX円（１日あたり）
  int X,Y;
  cin >> X >> Y;
  
  int sum = 0;
   if (N <= K) {
     sum = N*X;
   }
   else if (N > K) {
    sum = K*X + (N - K)*Y;
   }
  
  cout << sum << endl;
 
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
a = [0,0,0,0,0]
b = [[0,i] for i in range(5)]
for i in range(5):
    a[i] = int(input())
    b[i][0] = a[i] % 10
b.sort()
j = 0
while j < 5 and b[j][0] == 0:
    j += 1
time = 0
if j == 5:
    for i in range(5):
        time += a[i]
else:
    for i in range(5):
        if i != b[j][1]:
            if a[i] % 10 == 0:
                time += a[i]
            else:
                time += (a[i] + (10 - a[i] % 10))
    time += a[b[j][1]]
print(time)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+100;
ll a[maxn],ans[maxn];
int main()
{
	std::ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		if(i%2==0)ans[0]+=a[i];
		else ans[0]-=a[i];
	}
	for(int i=1;i<n;i++)
	{
		ans[i]=2*a[i-1]-ans[i-1];
	}
	for(int i=0;i<n;i++)
	{
		cout<<ans[i]<<" ";
	}
	return 0; 
}

Measured memory_bytes: 2944
k, n = map(int, input().split())
a = list(map(int, input().split()))
ans = k
b = a[0] + (k-a[-1])

prev = a[0]

for v in a[1:]:
    ans = min(ans, k-(v-prev))
    prev = v
ans = min(ans, k-b)
    
print(ans)

Measured memory_bytes: 25840
#include<stdio.h>
#include<stdlib.h>

int main(void) 
{
    int n, m, l;
    int A[100][100], B[100][100];
    long C[100][100];
    int i, j, k;
    
    scanf("%d %d %d", &n, &m, &l);
    //scanf A's element
    for (i = 0; i < n; i++)
    	for (j = 0; j < m; j++)
    		scanf("%d", &A[i][j]);
    //scanf B's element;
    for (i = 0; i < m; i++)
    	for (j = 0; j < l; j++)
    		scanf("%d", &B[i][j]);

    /*for (i = 0; i < n; i++)
    {
        for (j = 0; j < m; j++)
            printf("%d", A[i][j]);
        printf("\n");
    }
    
    for (i = 0; i < m; i++)
    {
        for (j = 0; j < l; j++)
            printf("%d", B[i][j]);
        printf("\n");
    }*/
    for (i = 0; i < n; i++)
    	for (j = 0; j < l; j++)
    	{
    		C[i][j] = 0;
    		for(k = 0; k < m; k++)
    			C[i][j] += A[i][k] * B[k][j];
    	}

    for (i = 0; i < n; i++)
    {
        for (j = 0; j < l; j++)
        	if(j != l - 1)
            	printf("%ld ", C[i][j]);
            else
            	printf("%ld", C[i][j]);
        printf("\n");
    }

    
    return 0;
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, a, b, c, d, e, k;
  in3(n, a, b);
  in3(c, d, e);
  k = min({a, b, c, d, e});
  out((n + k - 1) / k + 4);
  memi;
}

Measured memory_bytes: 256
#include <stdio.h>

void frame(int, int);

int main(void) {
    int h, w;
    while(scanf("%d %d", &h, &w), h || w) {
        frame(h, w), printf("\n");
    }
    return 0;
}

void frame(int h, int w) {
    int i, j;
    for(i = 0; i < h; i++) {
        for(j = 0; j < w; j++) {
            if(!i || !j || i == ~-h || j == ~-w) {
                printf("#");
            } else {
                printf(".");
            }
        }
        printf("\n");
    }
}

Measured memory_bytes: 572
def main():
    N, M = (int(i) for i in input().split())
    A = {int(input()) for i in range(M)}
    MOD = 10**9 + 7
    dp = [0]*(N+1)
    dp[0] = 1
    for i in range(N):
        if i + 1 not in A:
            dp[i+1] += dp[i]
            dp[i+1] %= MOD
        if i+2 <= N and i+2 not in A:
            dp[i+2] += dp[i]
            dp[i+2] %= MOD
    print(dp[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 50904
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    rep(i, 0, n)
    {
        int a;
        cin >> a;
        cnt += int(a % 2 ==1);
    }

    if (cnt % 2 == 0)
        cout << "YES" <<endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000LL
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue
 
#define FOR(i, a, b) for (ll i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 10005
ll n;
ll sm;

void test(ll m){
    if(m == 0) return;
    if(n % m == n / m) sm += m;
}

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

    cin >> n;
    ll rt = sqrt(n)+1;
    //cout << rt << "\n";
    FOR(i, 1, rt){
        if(n % i != 0) continue;
        ll o = n/i;
        if(o < i) continue;
        //sm += (i-1);
        test(i-1);
        //if(o != i) sm += (o-1);
        if(o != i) test(o-1);
    }

    cout << sm << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <complex>
#include <bits/stdc++.h>

#define ll long long
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define HS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f first
#define s second
#define INF 0x3f3f3f3f3f3f3f3f
#define pnt complex <double> 
#define pi acos(-1)
#define mod 1000000007

using namespace std;

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp) {
	if (exp == 0)
		return 1;
	ll ans = fp(base, exp / 2);
	ans = (ans * ans) % mod;
	if (exp % 2 != 0)
		ans = (ans * (base % mod)) % mod;
	return ans;
}

void calcFacAndInv(ll n) {
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++) {
		fact[i] = (i * fact[i - 1]) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}

ll ncr(ll n, ll r) {
	return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r) {
	return (fact[n] * inv[n - r]) % mod;
}
double dot(pnt a, pnt  b) {
	return (conj(a)*b).real();
}

int main() {

	HS
	calcFacAndInv(1000000);
	int n, k;
	cin >> n >> k;
	int  blue = k, red = n - k;
	
	for (int i = 1; i <= k; i++) {

		if (red + 1 - i < 0) {
			cout << 0 << endl;
			continue;
		}
		ll ans = (ncr(blue - 1, i - 1) % mod * ncr( red + 1, i) % mod) % mod;
		cout << ans << endl;
	}
	return 0;
}

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

typedef long long ll;
const ll mod=1e9+7;
const ll N=20003;
const ll INF=1e10;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<int> x(n),y(n);
	for(int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		x[i]=a+b;
		y[i]=a-b;
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	cout<<max(x.back()-x.front(),y.back()-y.front());
}	  


Measured memory_bytes: 4772
#ABC050

n = int(input())
t = list(map(int,input().split()))
m = int(input())
p = [list(map(int,input().split())) for _ in range(m)]

for i in range(m):
    
    tmp = t[p[i][0]-1]
    t[p[i][0]-1] = p[i][1]
    
    print(sum(t))
    t[p[i][0]-1] = tmp
    

Measured memory_bytes: 3060
s = input()
for i in [0]*int(input()):
    command = input().split()
    a, b = int(command[1]), int(command[2])
    b += 1
    if command[0] == 'replace':
        s = s[:a] + command[3] + s[b:]
    elif command[0] == 'reverse':
        s = s[:a] + s[a:b][::-1] + s[b:]
    else:
        print(s[a:b])


Measured memory_bytes: 5616
#include "bits/stdc++.h"
#include<assert.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MRE assert(0);
const int inf = 1e17;
const int mod = 924844033;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int N, L, T;
int x[100006], w[100006];
int FP[100006],FX[100006];

int cntcross(int S) {
	int res = 0;
	rep(i, N) {
		if (w[S] != w[i]) {
			int dis;
			if (w[S] == 1)dis = (x[i] - x[S] + L) % L;
			else dis = (L + x[S] - x[i]) % L;
			if (dis <= 2 * T)res += (2 * T - dis) / L + 1;
		}
	}
	return res;
}

signed main() {
	cin >> N >> L >> T;
	rep(i, N) cin >> x[i] >> w[i];

	vector<P>V1;
	rep(i, N) {
		if (w[i] == 1) {
			FP[i] = (x[i] + T) % L;
		}
		else {
			FP[i] = (x[i] + L - T%L) % L;
		}
		V1.push_back(P(FP[i], i));
	}
	sort(V1.begin(), V1.end());
	if (N == 1) {
		cout << FP[0] << endl;
		return 0;
	}
	sort(FP, FP + N);
	int X0, P0 = FP[0], I1 = V1[0].second;
	if (w[I1] == 1)X0 = (I1 + cntcross(I1)) % N;
	else X0 = (N - cntcross(I1)%N + I1) % N;

	rep(i, N) {
		if (FP[i] == P0) {
			rep(j, N) {
				FX[(i + j) % N] = (X0 + j) % N;
			}
			break;
		}
	}
	vector<P>V;
	rep(i, N) {
		V.push_back(P(FX[i], FP[i]));
	}
	sort(V.begin(), V.end());
	rep(i, N)cout << V[i].second << endl;
}


Measured memory_bytes: 8048
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    int a,b;

    while(~scanf("%d%d",&a,&b)){

        if((double)(a+b)/2-(double)((a+b)/2)>0)
            printf("IMPOSSIBLE\n");
        else
            printf("%d\n",(a+b)/2);
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

int N = 300005;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
vector<vector<pil> > G(N);

vector<ll> dijkstra(int s) {
  vector<ll> d(N, INF);
  //頂点、最短距離、小さい順に
  priority_queue<pli, vector<pli>, greater<pli> > q;

  d[s] = 0;
  q.push(pli(0, s));

  while (!q.empty()) {
    pli p = q.top();
    q.pop();
    int v = p.S;
    if (d[v] < p.F) continue;
    for (pil np : G[v]) {
      int nv = np.F;
      ll cost = np.S;
      if (chmin(d[nv], d[v] + cost)) {
        q.push(pli(d[nv], nv));
      }
    }
  }

  return d;
}

void solve() {
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[3 * a].eb(3 * b + 1, 1);
    G[3 * a + 1].eb(3 * b + 2, 1);
    G[3 * a + 2].eb(3 * b, 1);
  }
  int s, t;
  cin >> s >> t;
  s--; t--;
  auto v = dijkstra(3 * s); // debuged, s to 3*s
  cout << (v[3 * t] == INF ? -1 : v[3 * t] / 3) << '\n';
}


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

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

    string s;
    cin >> s;

    int n = s.size();
    bool flag = true;
    for(int i = n - 1; i >= 1; i--){
        if(s[i] != '9'){
            flag = false;
            break;
        }
    }
    if(flag){
        int ans = 0;
        for(int i = 0; i < n; i++){
            ans += s[i] - '0';
        }
        cout << ans << endl;
    } else {
        int ans = 0;
        ans += 9 * (n - 1);
        ans += s[0] - '0' - 1;
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
n,m = map(int,input().split())
info = [[0]+list(map(int,input().split())) for i in range(n)]

ans = 0
for oishi in range(2):
  for kirei in range(2):
    for ninki in range(2):
      for i in range(n):
        info[i][0] = ((-1)**kirei)*info[i][1] + ((-1)**oishi)*info[i][2] + ((-1)**ninki)*info[i][3]
      info = sorted(info,reverse = True)
      ans_kirei = 0
      ans_oishi = 0
      ans_ninki = 0
      for i in range(m):
        ans_kirei += ((-1)**kirei)*info[i][1]
        ans_oishi += ((-1)**oishi)*info[i][2]
        ans_ninki += ((-1)**ninki)*info[i][3]
      ans = max(ans,ans_kirei + ans_oishi + ans_ninki)
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL N,K;

int main(){
	cin>>N>>K;
	cout<<min(N%K,K-(N%K))<<endl;
}

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

using namespace std;

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

    int res = 0;

    for (int i = 1; i <= N; i++){
        int a;
        cin >> a;
        if((a % 2 == 1) && (i % 2 == 1)){
            res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int M = 1e5 + 5;
int r;
pair <int, int> t[M];
int dp [M][102];

int solve (int n, int id) {
    if (id == r || n < t[id].first) return 0;
    if (!dp[n][id]) dp[n][id] = max (solve(n, id+1), solve(n-t[id].first, id+1) + t[id].second);
    return dp[n][id];

}

main () {
    int n;
    cin >> r >> n;
    for (int i = 0; i < r; i++) {
        int a, b;
        cin >> a >> b;
        t[i] = {a, b};
    }
    sort(t, t+r);
    cout << solve (n, 0);
}



Measured memory_bytes: 78080
#include <stdio.h>
#include<string.h>
int main(void){
    int a,b;
    int i,j;
    scanf("%d %d",&a,&b);
    
    char words[a][b+1];
    char word[101];
    
    for(i=0;i<a;i++)
    {
        scanf("%s",words[i]);
        //printf("%s\n",words[i]);
    }
    for(i=0;i<a;i++)
    {
        for(j=i+1;j<a;j++)
        {
            
        
            if(strcmp(words[i],words[j])<0)
            {
                
            }
            else if(strcmp(words[i],words[j])==0)
            {
                
            }
            else
            {
                strcpy(word,words[i]);
                strcpy(words[i],words[j]);
                strcpy(words[j],word);
            }
        }
    }
    for(i=0;i<a;i++)
        printf("%s",words[i]);
    
}

Measured memory_bytes: 128
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	string s;
	cin >> s;
	int fst, lst;
	int n = s.size();
	for (int i = 0; i < n; i++){
		if (s[i] == 'A'){
			fst = i;
			break;
		}
	}
	for (int i = 0; i < n; i++){
		if (s[i] == 'Z'){
			lst = i;
		}
	}
	cout << lst - fst + 1;
}


Measured memory_bytes: 640
#include <cassert>
#include <algorithm>
#include <cctype>
#include <complex>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <typeinfo>
#include <unordered_set>
#include <unordered_map>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REPD(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define PB(e) push_back(e)
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define BIT(n, m) (((n) >> (m)) & 1)

typedef long long ll;

template <typename S, typename T> ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

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

int main(int argc, char *argv[])
{
  ll N, A;
  cin >> N;
  bool win = false;
  REP(i, N) {
    cin >> A;
    if (A % 2 == 1) {
      win = true;
    }
  }
  cout << (win  ? "first" : "second" ) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void){
  char str[102];
  int k;
  int x;
  int i;
  
  scanf("%d", &k);
  scanf("%s", str);
  x=strlen(str);
  
  if(x<=k){
    printf("%s", str);
  }else{
    for(i=0;i<k;i++){
      printf("%c", str[i]);
    }
    printf("...");
  }
  
  return 0;
}

Measured memory_bytes: 1732
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void solve() throws Exception {
		int h = scanInt(), w = scanInt();
//		int h = 185, w = 185;
		int a[][] = new int[h + 1][w + 1];
		for (int i = 0; i < h; i++) {
			String l = scanString();
			for (int j = 0; j < w; j++) {
				a[i + 1][j + 1] = (l.charAt(j) == '#' ? 1 : 0) + a[i + 1][j] + a[i][j + 1] - a[i][j];
//				a[i + 1][j + 1] = ((i + j) & 1) + a[i + 1][j] + a[i][j + 1] - a[i][j];
			}
		}
		int maxComp = (32 - Integer.numberOfLeadingZeros(h - 1)) + (32 - Integer.numberOfLeadingZeros(w - 1));
		byte dyn[][][][] = new byte[maxComp + 1][h + 1][][]; // [c][y2][y1][x1] -> x2
		for (int y2 = 1; y2 <= h; y2++) {
			for (int c = 0; c <= maxComp; c++) {
				dyn[c][y2] = new byte[y2][w + 1];
			}
			for (int y1 = y2 - 1; y1 >= 0; y1--) {
				for (int x1 = w; x1 >= 0; x1--) {
					int xm;
					for (xm = x1; xm < w; xm++) {
						int cnt = a[y2][xm + 1] - a[y1][xm + 1] - a[y2][x1] + a[y1][x1];
						if (cnt != 0 && cnt != (y2 - y1) * (xm + 1 - x1)) {
							break;
						}
					}
					for (int c = 0; c <= maxComp; c++) {
						if (c > 0 && y1 + 1 < y2) {
							int l = y1 + 1, r = y2 - 1;
							while (l <= r) {
								int y = (l + r) >> 1;
								int v1 = dyn[c - 1][y][y1][x1] & 0xff, v2 = dyn[c - 1][y2][y][x1] & 0xff;
								xm = max(xm, min(v1, v2));
								if (v1 < v2) {
									r = y - 1;
								} else {
									l = y + 1;
								}
							}
						}
						dyn[c][y2][y1][x1] = (byte) xm;
						xm = dyn[c][y2][y1][xm] & 0xff;
					}
				}
			}
		}
		for (int i = 0;; i++) {
			if ((dyn[i][h][0][0] & 0xff) == w) {
				out.print(i);
				return;
			}
		}
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

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

#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main() {
  int N;
  cin >> N;
  if (N < 100) {
    cout << min(N, 9) << endl;
    return;
  }

  int dig = (int)log10(N);
  int ans = 0;
  if (dig % 2 == 0) {
    ans += N - (int)pow(10, dig) + 1;
    dig -= 2;
  } else {
    dig--;
  }
  for (int i = dig; i > 0; i -= 2) {
    ans += (int)pow(10, i) * 9;
  }
  ans += 9;
  cout << ans << endl;
  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 512
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
sum_vote = sum(a)
judge = sum_vote /  (4*m)
ans = 'Yes'
for x in a[:m:]:
    if x < judge:
        ans = 'No'
        break
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
	int student_num;
	int i;
	int m,e,j;
	while(1) {
		scanf("%d",&student_num);
		if(student_num==0)break;
		for(i=0;i<student_num;i++) {
			scanf("%d%d%d",&m,&e,&j);
			if(m==100 || e==100 || j==100) {
				puts("A");
				continue;
			}
			if((m+e)/2>=90) {
				puts("A");
				continue;
			}
			if((m+e+j)/3>=80) {
				puts("A");
				continue;
			}
			if((m+e+j)/3>=70) {
				puts("B");
				continue;
			}
			if((m+e+j)/3>=50 && (m>=80 || e>=80)) {
				puts("B");
				continue;
			}
			puts("C");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <cmath>
#include <iostream>

using namespace std;

bool f(int a, int b, int c, int d) {
  return abs(c - a) <= d || (abs(b - a) <= d && abs(c - b) <= d);
}

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (f(a, b, c, d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

int main() {
  int n, k, v, u;
  cin >> n;
  vector<vector<int>> ADJ(n, vector<int>(n, 0));
  for (size_t i = 0; i < n; i++) {
    cin >> u >> k;
    for (size_t j = 0; j < k; j++) {
      cin >> v;
      ADJ[u - 1][v - 1] = 1;
    }
  }

  for (size_t i = 0; i < n; i++) {
    for (size_t j = 0; j < n; j++) {
      if (j == n - 1) {
        cout << ADJ[i][j] << endl;
      } else {
        cout << ADJ[i][j] << " ";
      }
    }
  }
}



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

int main(void){
  bool a1=1,a2=1;
  int a,n,count1=0,count2=0,count=1;
  std::vector<int> p;
  std::vector<int> q;

  cin >> n;

  vector<int> perm(n, 0);
  for (int i = 0; i < perm.size(); i++) perm[i] = i+1;
  for(int i=0; i<n; i++){
    cin >> a;
    p.push_back(a);
  }
  for(int i=0; i<n; i++){
    cin >> a;
    q.push_back(a);
  }

  do {
    for (int i = 0; i < perm.size(); i++){
      if(a1){
        if(p[i] == perm[i]){
          count1++;
        }
      }
      if(a2){
        if(q[i] == perm[i]){
          count2++;
        }
      }
    }
    if(a1){
      if(count1 == n){
        count1 = count;
        a1 = 0;
      }else{
        count1 = 0;
      }
    }
    if(a2){
      if(count2 == n){
        count2 = count;
        a2 = 0;
      }else{
        count2 = 0;
      }
    }
    count++;
  } while(next_permutation(perm.begin(), perm.end()));
  cout << abs(count1-count2);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 998244353;
#define PI 3.1415926535
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
const int siz = 2*(1e5 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int has[siz];
int ifact[siz];
int bit[siz];
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}

bool ispalin(string s)
{
	string k = s;
	reverse(k.begin(),k.end());
	if(k == s)
	{
		return true;
	}

	return false;
}


signed main()
{
	
	speedrap
	double x ;
	cin>>x;
	double c = (x*x*x);
	c /= 27;
	std::cout << std::fixed;
    std::cout << std::setprecision(12);
    std::cout << c;
	//cout<<setprecision(7)<<(double)c;

}

Measured memory_bytes: 384
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>

int n;

int main(void){
    
    cin>>n;
    for(int i=1;i<=n;i++){
        double x=(double)i*1.08;
        int k=(int)x;
        if(k==n){
            cout<<i<<endl;
            return 0;
        }
    }
    
    cout<<":("<<endl;
    
    return 0;
}

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

int main(void)
{
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;


	int minp = pow(10, 5)*5000*2+1;
	if (a+b < c*2) {
		for (int i = 0; i < max(x, y)*2; i+=2) {
			int a_num = x-i/2;
			int b_num = y-i/2;
			a_num = a_num < 0 ? 0 : a_num;
			b_num = b_num < 0 ? 0 : b_num;
			int price = a*a_num + b*b_num + c*i;
			if (price < minp)
				minp = price;
			else
				break;
		}
	} else {
		for (int i = 0; i <= x; i++) {
			int price;
			for (int j = 0; j <= y; j++) {

				int k = max(x-i, y-j)*2;


				price = a*i+b*j+c*k;
				if (price < minp)
					minp = price;
				else {
					break;
				}
			}
		}
	}

	cout << minp << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

const int N = 500000;
const int MOD = 998244353;

int n;
int dp[N];
pair<int, int> v[N];
int go[N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i].first >> v[i].second;
    }
    sort(v, v + n);
    dp[n] = 1;
    for (int i = n - 1; i >= 0; i--)
    {
        int r = v[i].first + v[i].second;
        int j = i + 1;
        while (j < n && v[j].first < r)
            r = max(r, v[j].first + v[j].second), j = go[j];
        dp[i] = (dp[i + 1] + dp[j]) % MOD;
        go[i] = j;
    }
    cout << dp[0];
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  ll n, k;
  cin >> n >> k;
  priority_queue<pair<int, int>> q;
  rep(i, n){
    int a, b;
    cin >> a >> b;
    a *= -1;
    q.push(make_pair(a, b));
  }

  while(1){
    auto p = q.top(); q.pop();
    k -= p.second;
    if(k <= 0){
      cout << p.first*(-1) << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1400
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  sort(rall(a));
  rep(i, n - 1) loop(j, i + 1, n) {
    string s = to_string(a[i] * a[j]);
    bool f   = true;
    loop(i, 1, s.size()) f &= s[i] == s[i - 1] + 1;
    if (f) {
      cout << s << endl;
      return;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3276
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n,m,d,a;
  while(cin>>n){
    if(n==0) break;
    cin>>m>>a>>d;
    string sen[31];
    int s[31];
    int g[31];
    s[0] = m;
    g[d] = a;
    REP(i,d){
      cin>>sen[i];
    }
    REP(i,d){
      if(s[i]!=1&&sen[i][s[i]-2]=='1'){
        s[i+1] = s[i] -1;
      }else if(s[i]!=n&&sen[i][s[i]-1]=='1'){
        s[i+1] = s[i] +1;
      }else{
        s[i+1] = s[i];
      }
      if(g[d-i]!=1&&sen[d-i-1][g[d-i]-2]=='1'){
        g[d-i-1] = g[d-i] -1;
      }else if(g[d-i]!=n&&sen[d-i-1][g[d-i]-1]=='1'){
        g[d-i-1] = g[d-i] +1;
      }else{
        g[d-i-1] = g[d-i];
      }
    }
    bool f=true;
    int ans[2];
    if(s[d]==g[d]){
     cout<<0<<endl;
    }else{
      FOR(i,1,d+1){
        if(g[i]-s[i]==1){
          if(sen[i-1][s[i]-1]=='0'&&(s[i]==1||sen[i-1][s[i]-2]=='0')
              &&(g[i]==n||sen[i-1][s[i]]=='0')){
            f=false;
            ans[0] = i;
            ans[1] = s[i];
            break;
          }
        }else if(g[i]-s[i]==-1){
            swap(s[i],g[i]);
          if(sen[i-1][s[i]-1]=='0'&&(s[i]==1||sen[i-1][s[i]-2]=='0')
              &&(g[i]==n||sen[i-1][s[i]]=='0')){
            f=false;
            ans[0] = i;
            ans[1] = s[i];
            break;
          }
        }
      }
      if(f) cout<<1<<endl;
      else{
        printf("%d %d\n",ans[0],ans[1]);
      }
    }  
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
vector<ll> a(0);

int f(ll x){
    if((int)(to_string(x).size()) > 9) return 0;
    a.push_back(10*x+3);
    f(10*x+3);
    a.push_back(10*x+5);
    f(10*x+5);
    a.push_back(10*x+7);
    f(10*x+7);
    return 0;
}

int main(){
    ll n; cin >> n;
    f(0);
    ll ans = 0;
    sort(a.begin(),a.end());
    for(int i=0;i<(int)a.size();i++){
        ll x = a.at(i);
        if(x>n) break;
        string s = to_string(x);
        int flag = 1;
        for(int j=0;j<(int)s.size();j++){
            if(s.at(j) == '3') flag*=3;
            else if(s.at(j) == '5') flag*=5;
            else if(s.at(j) == '7') flag*=7;
        }
        if(flag%105==0) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1400
N = int(input())
XL = [tuple(map(int, input().split())) for _ in range(N)]
XL.sort(key=lambda p:(p[0]+p[1]))
L = -10 ** 10
ans = 0
for x, l in XL:
    if L <= x - l:
        L = x + l
        ans += 1
print(ans)

Measured memory_bytes: 21356
s = int(input())
a = s
b = set()
b.add(a)
m = 1
while m <= 10**6:
    if a%2 == 1:
        if 3*a+1 in b:
            m += 1
            print(m)
            break
        else:
            b.add(3*a+1)
            a = 3*a+1
            m += 1
    else:
        if a//2 in b:
            m += 1
            print(m)
            break
        else:
            b.add(a//2)
            a = a//2
            m += 1

Measured memory_bytes: 3064
//THIS IS THE AATMANIRBHAR SOLUTION I FOUND..!!!!!
#include<bits/stdc++.h>
using namespace std ;
#define int long long
// #define int double
// #define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define P push
#define vvi vector<vector<int>>
#define vi vector<int>
#define vf vector<float>
#define vc vector<char>
#define vs vector<string>
#define pii vector<pair<int, int>>
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define sort(v) sort(all(v))
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(j,a,b) for(int j=a-1;j>=b;j--)
#define binod ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int N = 1e9 + 7 , N1 = 1e7 + 5 , N2 = 1e6 + 3, N3 = 1e5 + 3;
#define IX INT_MAX
#define IM INT_MIN


void solve()
{
    int n;
    cin>>n;
    int cnt=0;
    vi ans(n+5,0);
    for(int i=1;i<sqrt(n);i++)
    {
        for(int j=i;j<n;j++)
        {
            if(i==j and i*i<n)
            cnt++;
            else if(i*j<n)
            cnt+=2;
            else break;
        }
    }
    cout<<cnt;
}


signed main(){
    binod;
    int t1=1;
    //cin>>t1;
    // cout<<fixed<<setprecision(9);
    while(t1--){
        solve();
        cout<<endl;
    }
}

                                                                            //Don't judge me or anyone
                                                                            //this is life,
                                                                            //not a reality show



Measured memory_bytes: 11088