akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}


const int N=1e5+5;
struct it{
    int x,y,i;
}a[N];
int32_t main(){
    int n;
    cin>>n;
    forn(i,n){
        cin>>a[i].x;
    }
    forn(i,n){
        cin>>a[i].y;
        a[i].i=i;
        if(i&1)swap(a[i].x,a[i].y);
    }
    int ans=N;
    forn(mask,1<<n){
        int z=__builtin_popcount(mask);
        if(z==(n+1)/2){
            dbg(mask);
            vector<it> v1,v2;
            forn(i,n){
                if(mask>>i&1){
                    v1.pb(a[i]);
                }else{
                    v2.pb(a[i]);
                }
            }
            sort(v1.begin(), v1.end(),[](const it&p1,const it&p2){return p1.x==p2.x?p1.i<p2.i:p1.x<p2.x;});
            sort(v2.begin(), v2.end(),[](const it&p1,const it&p2){return p1.y==p2.y?p1.i<p2.i:p1.y<p2.y;});
            vector<int> o(n);
            vector<int> u(n);
            for(int i=0,j=0;i<n;i+=2,j++)o[i]=v1[j].i,u[i]=v1[j].x;
            for(int i=1,j=0;i<n;i+=2,j++)o[i]=v2[j].i,u[i]=v2[j].y;
            int ok=1;
            for(int i=1;i<n;++i){
                ok&=(u[i-1]<=u[i]);
            }
            dbg(ok);
            if(ok){
                int pot=0;
                vector<int> f(n);
                iota(f.begin(), f.end(),0);
                forn(i,n){
                    int w=-1,v=o[i];
                    dbg(i,v);
                    forn(j,n){
                        if(f[j]==v){
                            w=j;
                            break;
                        }
                    }
                    dbg(w);
                    for(int j=w;j>i;--j){
                        swap(f[j],f[j-1]);
                        pot++;
                    }
                }
                dbg(pot);
                upn(ans,pot);
            }
        }
    }
    if(ans==N)ans=-1;
    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef int G;std::vector<G>A['   '];G N,M,S['   '],B,L,R,I;G U(G z,G u){while(z<=N)S[z]+=u,z+=z&-z;}main(){scanf("%d%d",&M,&N);for(;~scanf("%d%d",&L,&R);)A[R-L+1].push_back(L);for(L=1;L<=N;L++){B=M;for(I=L;I<=N;I+=L){R=I;while(R)B+=S[R],R-=R&-R;}for(G u:A[L])U(u,1),U(u+L,-1),M--;printf("%d\n",B);}}

Measured memory_bytes: 53760
n=int(input())
a=[0]+list(map(int,input().split()))
b=[0]*(n+1)
for i in reversed(range(1,n+1)):
    if sum(b[i::i])%2!=a[i]:
        b[i]=1
print(sum(b))
for i,j in enumerate(b):
    if j==1:
        print(i,end=" ")


Measured memory_bytes: 8756
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k>max(a):
  print('IMPOSSIBLE')
elif n==1:
  if a[0]==k:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
elif n==2:
  c=gcd(a[0],a[1])
  if k%c==0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
else:
  c=gcd(a[0],a[1])
  for i in range(2,n):
    c=gcd(c,a[i])
  if k%c==0: 
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')


Measured memory_bytes: 16020
#include <map>
#include <iostream>
using namespace std;
typedef long long ll;

int main(){

    //税抜き価格と8%税金、10％税金の組みのマップを作る
    //指定された価格から、条件を満たす価格の範囲を出す
    //範囲がかぶっているか、（インデックスの最大と最小を比較する）

    map<ll, ll> mA, mB; //<price, tax>

    ll A, B;//tax

    for(int i=1;i<2000;i++){
        mA.insert(make_pair(i*0.08, i)); 
        mB.insert(make_pair(i*0.1, i)); 
    }

    cin >> A >> B;

    ll minAi, maxAi, minBi, maxBi;

    minAi = mA.at(A);
    maxAi = mA.at(A+1)-1;
    minBi = mB.at(B);
    maxBi = mB.at(B+1)-1;

    //cout << minAi << " " << maxAi << " " << minBi << " " << maxBi << endl;

    if(maxAi < minBi || minAi > maxBi){
        cout << "-1\n";
    }else{

       (minAi >=  minBi)? cout << minAi << endl : cout << minBi << endl;
    //    if(minAi >=  minBi){
    //        cout << minAi << endl;
    //    }else{
    //        cout << minBi << endl;
    //    }
    }
    
    return 0;

 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc168/abc168_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int K;
  string S;
  cin >> K >> S;

  if (S.size() > K) {
    cout << S.substr(0, K) << "..." << endl;
  } else {
    cout << S << endl;
  }
}

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

signed main(){
  
  string s;
  cin>>s;
  
  if( s == "Sunny" ) cout<<"Cloudy"<<endl;
  if( s == "Cloudy" ) cout<<"Rainy"<<endl;
  if( s == "Rainy" ) cout<<"Sunny"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

typedef long long int lli;

int main () {
  lli n, m, d;
  cin >> n >> m >> d;

  double ans = 0.0;
  if (n - d > 0) {
    if ( d == 0 ) {
ans = ((n - d) * 1.0 / n) * (m - 1) / n;
    } else {
ans = ((n - d) * 2.0 / n) * (m - 1) / n;
    }
    
  }
  printf("%.8lf\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int H;
    int A;
    int N;
    int M;

    scanf("%d %d",&H,&A);

    N=H/A;
    M=H%A;
    if (M != 0)
    {
        N = N + 1;
    }
    

    printf("%d",N);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
    char x, y;
    cin >> x >> y;
    if (x < y) cout << "<" << endl;
    else if (x == y) cout << "=" << endl;
    else cout << ">" << endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;

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

    double sum = 0;

    for(int i = 0; i < N; i++){
        double x;
        string u;

        cin >> x >> u;

        if(u[0] == 'J'){
            sum += x;
        }else{
            sum += 380000*x;
        }
    }

    cout << to_string(sum) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;    
typedef long long ll;
typedef pair<int, int> pii;
//#define int long long
const int mod = 1000000007;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    
    
    int n;
    cin >> n;
    int m;
    cin >> m;
    vector<vector<int>> a(m + 1);
    for(int i = 0; i < n; ++ i)
    {
        int days, cost;
        cin >> days >> cost;
        if(days > m) continue;
        a[days].push_back(cost);
    }
    multiset<int, greater<int>> s;
    int ans = 0;
    for(int i = 1; i <= m; ++ i)
    {
        for(int j = 0; j < a[i].size(); ++ j)
        {
            s.insert(a[i][j]);
        }
        if(!s.empty())
        {
            auto it = s.begin();
            ans += *it;
            debug(*it);
            s.erase(it);
        }
    }
    
    cout << ans << endl;
    
    return 0;
}






Measured memory_bytes: 7808
import java.util.Scanner;

public class Main{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		String s=sc.next();

		if(s.length()==3){
			char c[]=s.toCharArray();
			System.out.print(c[2]);
			System.out.print(c[1]);
			System.out.println(c[0]);

		}
		else System.out.println(s);


	}
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int64_t N;
  cin>>N;
  map<int,int>k;
  for(int i=2;i<=N;i++){
    auto p=prime_factorize(i);
    for(auto c:p){
       k[c.first]+=c.second;
    }
  }
  int64_t ans=1;
  for(auto c:k){
    ans*=(c.second+1);
    ans%=mod;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
    int n,m,k;
    cin >> n >> m >> k;
    
    for(int i=0; i<=n; i++){
        for(int j=0; j<=m; j++){
            if (i*(m-j) + j*(n-i) == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
import math


while True:
    n = int(input())
    if n == 0:
        break
    dp = [0] * (n + 1)
    dp[0] = 1
    for i in range(n):
        dp[i+1] += dp[i]
        if i > 0:
            dp[i+1] += dp[i-1]
        if i > 1:
            dp[i+1] += dp[i-2]
    print(math.ceil((dp[-1] / 10) / 365))



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

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

c = 0

for i in range(N):
  if A[i]%2 == 0:
    if A[i]%6 ==0 and A[i]%10 != 0:
      c = c
    elif A[i]%6 !=0 and A[i]%10 == 0:
      c = c
    elif A[i]%6 ==0 and A[i]%10 == 0:
      c = c
    else:
      c += 1

if c >0:
  print('DENIED')
  
elif c == 0:
  print('APPROVED')
      

Measured memory_bytes: 9052
a,b,c,d=map(int,input().split())
ans=0
for x in range(d//a+1):
    for y in range(d//b+1):
#        print(x,y,(d-(x*a+y*b))//c)
        if (d-(x*a+y*b))%c==0 and (d-(x*a+y*b))>=0:
            ans+=1
print(ans)

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    n -= 2;

    cout << n * 180 << endl;

    return 0;
}



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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int x,y;
	cin >> x >> y;
	if(x<=9 && y<=9)
	{
		cout << x*y << endl;
	}
	else
	{
		cout << "-1" << endl;
	}
}


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

using namespace std;

///////////////////////////////////////////
//const long long int INF = 1000000000000000000LL;
const long long int INF = 1000000;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(    v[0])>()) //降順でVをソート
///////////////////////////////////////////

ll n,k;
ll box[100000001]={0};
int main(){
    cin>>n>>k;
    ll flag=0;//flag = 負の座標の個数
    rep(i,n){
        cin>>box[i];
        if(box[i]>=0 && flag!=0){
            flag= i;
        }
    }
    ll ans = INT64_MAX;
    for(int i=0;n-i>k-1;i++){
        ll mi,ma;
        mi = box[i]; ma = box[k+i-1];//k+i-1 < n
        if(mi<0){
            if(ma<0){
                ans = min(ans,-mi);
            }else{
                ans = min(ans,min(2*ma-mi,ma-2*mi));
            };
        }else{
            ans = min(ans,ma);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    int turn=0;
    while(a>0 && c>0){
        if(turn==0)c-=b;
        else a-=d;
        turn=1-turn;
    }
    if(a<=0)cout<<"No\n";
    else cout<<"Yes\n";
    return 0;   
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for(long long i=0; i<(long long)c; i++)
int main() {
	int H1,M1,H2,M2,K;
	cin>>H1>>M1>>H2>>M2>>K;
	int a,b,c;
	a=H1*60+M1;
	b=H2*60+M2;
	c=b-a-K;
	cout <<c<<endl;
	return 0;
}


Measured memory_bytes: 3636
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var (
		s string
		k int
	)
	fmt.Scan(&s, &k)

	for i := 0; i < k; i++ {
		v, _ := strconv.Atoi(string(s[i]))
		if v == 1 {
			continue
		} else {
			fmt.Println(v)
			return
		}
	}
	fmt.Println(1)
}


Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
using namespace std;

int N, D[100100][3];
int main()
{
	scanf("%d", &N);

	for (int i=1;i<=N;i++){
		int a,b,c; scanf ("%d %d %d",&a,&b,&c);
		int p = a + max(D[i-1][1], D[i-1][2]);
		int q = b + max(D[i-1][0], D[i-1][2]);
		int r = c + max(D[i-1][1], D[i-1][0]);
		D[i][0] = p;
		D[i][1] = q;
		D[i][2] = r;
	}
	printf ("%d\n",max({D[N][0],D[N][1],D[N][2]}));

	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int n, i;
	cin >> n;
	ld arr[n];
	fo(i, 0, n)
	cin >> arr[i];
	sort(arr, arr + n);
	fo(i, 1, n)
	arr[i] = (arr[i] + arr[i - 1]) / 2;
	cout << fixed << setprecision(10) << arr[n - 1];
}

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

int n;
ll ans;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    vector<ll> a(n);
    for (auto& i : a) cin >> i;
    sort(a.begin(), a.end());

    if (n % 2) {
        ll last = a[n / 2];
        ll dp[2] = { 0 };
        for (int i = 0; i < n / 2; i++) {
            dp[0] += abs(last - a[i]);
            last = a[i];
            dp[0] += abs(last - a[n - (i + 1)]);
            last = a[n - (i + 1)];
        }
        last = a[n / 2];
        for (int i = 0; i < n / 2; i++) {
            dp[1] += abs(last - a[n - (i + 1)]);
            last = a[n - (i + 1)];
            dp[1] += abs(last - a[i]);
            last = a[i];
        }
        ans = max(dp[0], dp[1]);
    } else {
        ll last = a[n / 2 - 1];
        for (int i = 0; i < n / 2; i++) {
            ans += abs(a[n - (i + 1)] - last);
            last = a[n - (i + 1)];
            if (i != n / 2 - 1) {
                ans += abs(a[i] - last);
                last = a[i];
            }
        }   
    }
    cout << ans;
}



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

int main(){
  int N;
  cin>>N;
  vector<int> B(N-1);
  for(int i=0;i<N-1;++i){
    cin>>B.at(i);
  }

  int sum=0;
  for(int i=0;i<N;++i){
    if(i==0){
      sum=sum+B.at(0);
    }
    else if(i==N-1){
      sum=sum+B.at(N-2);
    }
    else{
      sum=sum+min(B.at(i),B.at(i-1));
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define REPR(i, n) for (int i = n-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<n)
#define bit_check(bit, i) (bit>>i) & 1
#define setpre(n) fixed << setprecision(n)
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VP = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll mod = 1e9 + 7;

int calc(ll b)
{
    int rem = b % 6;
    if (rem == 0) return 1;
    if (rem == 1) return 10;
    if (rem == 2) return 9;
    if (rem == 3) return 12;
    if (rem == 4) return 3;
    if (rem == 5) return 4;
}

int main(){
  string S;
  cin >> S;
  ll len = S.size();
  VVll dp(len, Vll(13, 0));
  REPR(i, len){
    if (i == len - 1){
        if (S.at(i) != '?'){
            REP(j, 13) if (S.at(i)-'0' == j) dp.at(i).at(j) = 1;
        }
        else REP(j, 10) dp.at(i).at(j) = 1;
        continue;
    }
    int tmp = calc(len-i-1);
    REP(j, 13){
        if (S.at(i) == '?'){
            REP(s_i, 10){
                dp.at(i).at(j) += dp.at(i+1).at((13 + j - ((s_i * tmp) % 13)) % 13);
                dp.at(i).at(j) %= mod;
            }
        }
        else{
            dp.at(i).at(j) += dp.at(i+1).at((13 + j - (((S.at(i)-'0') * tmp) % 13)) % 13);
            dp.at(i).at(j) %= mod;
        }
    }
  }
  cout << dp.at(0).at(5) << endl;

  return 0;
}

Measured memory_bytes: 13696
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

		int n = scan.nextInt();
		ArrayList<String> m = new ArrayList<String>();
		int s[] = new int[n];

		m.add(scan.next());
		s[0] = scan.nextInt();

		boolean t = false;

		for(int i = 1 ; i < n ; i++) {
			String mm = scan.next();
			for(int j = 0 ; j < m.size() ; j++) {

				if(m.get(j).equals(mm)) {
					s[j] += scan.nextInt();
					t = true;
					break;
				}

			}

			if(t == false) {
				m.add(mm);
				s[m.size()-1] = scan.nextInt();
			}
			t = false;
		}


		Map<String , Integer> map = new HashMap<String , Integer>();


		for(int i = 0 ; i < m.size() ; i++) {
			map.put(m.get(i), (Integer)s[i]);
		}
		Collections.sort(m);


		for(int i = 0 ; i < m.size() ; i++) {
			for(int j = 0 ; j < m.size()-1-i ; j++) {

				if(m.get(j).length() > m.get(j+1).length()) {

					String o = m.get(j);
					m.set(j,m.get(j+1));
					m.set(j+1,o);

				}

			}
		}

		for(int i = 0 ; i < m.size() ; i++) {
			System.out.println(m.get(i)+" "+ map.get(m.get(i)));
		}

	}
}


Measured memory_bytes: 48044
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

// I'm trying to ~~~
int main(){
    int N; cin >> N;
    if(N<1000) cout << "ABC" << endl;
    else cout << "ABD" << endl;
}


Measured memory_bytes: 256
//bismillahir rahmanir rahim            //Author:Fayed Anik

#include <bits/stdc++.h> 

using namespace std;


#define         ll                         long  long
#define         lf                         double 
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")

int main(){
	ll n,d;
	sfl(n),sfl(d);
	d=2*d+1;
	cout << ceil(n/(double)d) << endl;
}



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

bool solve(const int a, const int b, const int c) {
	vector<bool> used(b, false);
	int sum = 0;
	for(int i = 1; i <= b; i++) {
		sum += a;
		used[sum%b] = true;
		//cout << sum%b << ",";
	}
	return used[c];
}

int main() {
	int a, b, c;
	cin>>a>>b>>c;
	bool ans = solve(a, b, c);
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use proconio::fastout;
use proconio::input;
//use proconio::marker::*;
//use std::collections::HashSet;
// use std::cmp::*;
//use std::collections::VecDeque;

fn main() {
    input! {
       N:i32
    }

    println!("{}", (1000 - (N % 1000)) % 1000);
}


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

using ll=long long;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
  int a[5],n=0;
  for (int i=0;i<5;i++) cin >> a[i];
  for (int i=1;i<5;i++){
    if (a[i]%10==0) continue;
    if (a[n]%10>a[i]%10) n=i;
  }
  for (int i=0;i<5;i++){
    if (i==n || a[i]%10==0) continue;
    a[i]=((a[i]/10)+1)*10;
  }
  cout << a[0]+a[1]+a[2]+a[3]+a[4] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll MAX = 1e+18;

int main()
{
    ll X, Y;
    cin >> X >> Y;

    if (X % Y == 0) {
        cout << -1 << endl;
    } else {
        cout << X << endl;
    }

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int n;
    cin>>n;
    vector<long int>v;
    int ele;
    for(auto i=0;i<n;i++)
    {
        cin>>ele;
        v.push_back(ele);
    }
    int x = 0;
    for(auto i=0;i<n;i++)
    {
        x^=v[i];
    }
    for(auto i=0;i<n;i++)
    {
        int sol = x^v[i];
        cout<<sol<<" ";
    }
    return 0;
}

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

A = list(map(int, input().split()))
A.sort()
if N % 2:
    start = N//2
    end = N-1
    print(sum(A[start:end]) * 2 + A[end] - A[start])
else:
    start = N//2
    end = N-1
    print(sum(A[start:end]) * 2 + A[end])

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

int main() {
  int a, b, c;
  cin >> a >> b;
  c = a * b % 2;
  
  if ( c == 0 ) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
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; }
constexpr int INF = 1 << 28, MOD = int(1e9) + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vi L(M), R(M), p(Q), q(Q);
    rep(i, M) cin >> L[i] >> R[i];
    rep(i, Q) cin >> p[i] >> q[i];

    vv<int> lines = vvec(N + 2, N + 2, 0);
    rep(i, M) {
        lines[L[i]][R[i]]++;
    }
    
    for (int l = N; l > 0; --l) {
        for (int r = 1; r <= N; ++r) {
            lines[l][r] += lines[l + 1][r] + lines[l][r - 1] - lines[l + 1][r - 1];
        }
    }

    rep(i, Q) {
        write(lines[p[i]][q[i]]);
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
typedef long long ll;
int a,b,c,ans,N,M,T,q[107];
int main(){
	scanf("%d",&N);
	rep(i,1,N) scanf("%d",&q[i]);
	int ans=0;
	rep(i,1,N) if (q[i]!=i) ans++;
	if (ans>2) printf("NO\n");
	else printf("YES\n");
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define rep(i,n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define sz(a) int((a).size())
#define endl '\n' // remove for interactive

const int N = 1000 + 5;
char arr[N][N];
int dp[N][N];
int main()
{
    ios_base::sync_with_stdio(0); //cant use scanf, printf
    cin.tie(0);cout.tie(0); // no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); // no scientific output
    int n, m;
    cin>>n>>m;
    rep(i, n)
    {
        rep(j, m)
        {
            cin>>arr[i][j];
        }
    }
    dp[0][0] = 1;
    rep(i, n)
    {
        rep(j, m)
        {
            if(i == 0 && j== 0) continue;
            if(arr[i][j] == '.') dp[i][j] = (dp[max(0,i-1)][j] + dp[i][max(0, j-1)]) % (1000000000 + 7);
        }
    }
    cout<<dp[n-1][m-1];
    
    
}



/*before sub
loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
*/

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int main()
{
    vector<ll>v;
    for(ll i=1;i<=9;i++)
    {
        for(ll j=1;j<=9;j++)
        {
            v.pb(i*j);
        }
    }
    ll a; cin>>a;
    for(ll i=0;i<v.size();i++)
    {
        if(v[i]==a)
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

int a[2005];
int min_c[2005];

int main()
{
	int N, x;
	cin >> N >> x;
	REP(i, N)
	{
		cin >> a[i];
		min_c[i] = a[i];
	}

	ll min = MOD * 2000;
	REP(i, N)
	{
		ll cost = x*i;
		REP(j, N)
		{
			int k = (j - i + N) % N;
			min_c[j] = std::min(min_c[j], a[k]);
			cost += (ll)min_c[j];
		}
		min = std::min(min, cost);
	}

	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int MAX = 100, INFTY = (1 << 21), WHITE = 0, GRAY = 1, BLACK = 2;

int N, M[MAX][MAX];
void dijkstra() {
	int minv;
	int D[MAX], C[MAX];

	for (int i = 0; i < N; i++) {
		D[i] = INFTY;
		C[i] = WHITE;
	}

	D[0] = 0;
	C[0] = GRAY;
	while (true) {
		minv = INFTY;
		int u = -1;
		for (int i = 0; i < N; i++) {
			if (minv > D[i] && C[i] != BLACK) {
				u = i;
				minv = D[i];
			}
		}
		if (u == -1) break;
		C[u] = BLACK;
		for (int v = 0; v < N; v++) {
			if (C[v] != BLACK && M[u][v] != INFTY) {
				if (D[v] > D[u] + M[u][v]) {
					D[v] = D[u] + M[u][v];
					C[v] = GRAY;
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << i << ' ' << (D[i] == INFTY ? -1 : D[i]) << endl;
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			M[i][j] = INFTY;
		}
	}
	int k, c, u, v;
	for (int i = 0; i < N; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			M[u][v] = c;
		}
	}
	dijkstra();
}


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

int main() {
    ll A, B, C;
    cin >> A >> B >> C;

    ll ans = 0;
    ll A1 = A, B1 = B, C1 = C;
    ll A2, B2, C2;
    while(A1 % 2 == 0 && B1 % 2 == 0 && C1 % 2 == 0) {
        ++ans;
        A2 = (B1 + C1) / 2;
        B2 = (A1 + C1) / 2;
        C2 = (A1 + B1) / 2;
        A1 = A2, B1 = B2, C1 = C2;

        if(A1 == A && B1 == B && C1 == C) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define fi first
#define se second
using ll = long long;
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    multiset<int> s;
    int mx = 0;
    for(int i = 0, x; i < (1 << n); ++i) {
        cin >> x;
        s.insert(x);
        mx = max(mx, x);
    }
    multiset<int> done;
    done.insert(mx);
    s.erase(s.find(mx));

    while(s.empty() == false) {
        vector<int> born;
        for(auto it = done.rbegin(); it != done.rend(); ++it) {
            auto t = s.lower_bound(*it);
            if(t == s.begin()) {
                cout << "No\n";
                return 0;
            }
            --t;
            born.push_back(*t);
            s.erase(t);
        }
        for(auto x : born) {
            done.insert(x);
        }
    }
    cout << "Yes\n";
}


Measured memory_bytes: 13304
#include <iostream>

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

int main(void) {
    int max = 0;
    int min = 1e09;
    int n;
    cin >> n;
    int temp;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        if (temp > max) {
            max = temp;
        }
        if (temp < min) {
            min = temp;
        }
    }
    cout << max - min << endl;
    return 0;
}


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

int main(){
	int N;
  	cin >> N;
	vector<int> place(N);
  	for(int i=0;i<N;i++){
		cin >> place.at(i);
    }
  	
  	int dub=0;
 	int sigma = 0;
  	int P=0;
  	for(int i=0;i<N;i++){
      dub += place.at(i) * place.at(i);
      sigma += place.at(i);
    }
  
  	P = (int)(sigma*1.0/N+0.5);
  	cout << dub - 2*P*sigma + N*P*P << endl;
  
	return(0);
}


Measured memory_bytes: 256
n,m=map(int,input().split())
x=[2,5,5,4,5,6,3,7,6]#各数に使うマッチ棒の本数
a=[]#使う数字でけ格納するリスト
for i in map(int,input().split()):
    a.append([i,x[i-1]])#数と使う本数をリストで入力
    #ここでタプルにするとソートできない
a.sort(reverse=True)
#tuple(a)#タプルにしても実行時間、メモリーに大きな変化なし
#ソートしないと、大きい数字が先に来ないので間違う
#(OK)print(a)使える数字だけ
dp=[0]*(n+1)
#dp[i]：ちょうどi本使った時に表せる最大の数
#ループの順番が、いまひとつ、腑に落ちない
#大きい数字から先に試す。マッチの本数は徐々に増やす。
for i in range(m):
#外側ループが使用できる数、最初１番大きい数字、その後、使える数字が増える
    #print(i)
    for j in range(n+1):#マッチ棒は0からnまで使える
        #print(j,dp[j])
        if j==0 or dp[j]!=0:
        #(NG)if dp[j]!=0: 「jの範囲を1始め」でもNG
            if j+a[i][1]<=n:#マッチ棒が使用範囲内なら
                #print(dp[j+a[i][1]],dp[j]*10+a[i][0])
                #print(max(dp[j+a[i][1]],dp[j]*10+a[i][0]))
                dp[j+a[i][1]]=max(dp[j+a[i][1]],dp[j]*10+a[i][0])
#この更新はDP典型。右１項が左と同じ。右は両項とも、前から使っているj本に
#新しく使うi番目を使った　本数での数を表している。
print(dp[n])

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

int main() {
	string s;
	cin >> s;
	cout << ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
pumi=0
ff=0
cut=1
for i in range(0,N-1):
    if pumi==0:
        ff=0
    elif pumi==-1:
        ff=-1
    elif pumi==1:
        ff=1

    if A[i+1]>A[i]:
        pumi=1
    elif A[i+1]<A[i]:
        pumi=-1

    if pumi==-1 and ff==1:
        cut+=1
        pumi=0
    elif pumi==1 and ff==-1:
        cut+=1
        pumi=0
print(cut)

Measured memory_bytes: 14224
// Problem : AT1980 [AGC001B] Mysterious Light
// Contest : Luogu
// URL : https://www.luogu.com.cn/problem/AT1980
// Memory Limit : 250 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <iostream>
using namespace std;
long long int ans;
inline void dfs( long long int x, long long int y )
{
    if ( x % y == 0 )
    {
        ans += x * 2 - y;
        return;
    }
    else
    {
        ans += ( x - x % y ) * 2;
        dfs( y, x % y );
    }
}
int main()
{
    long long int n, m;
    cin >> n >> m;
    ans = n;
    n -= m;
    dfs( max( n, m ), min( n, m ) );
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(LL)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define INF 1LL << 50

const int MAX_V=1e5+3;
struct edge{int to,cost;};
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

struct UnionFind
{
    vector<int> par;
    vector<int> sizes;

    UnionFind(int n) : par(n), sizes(n, 1) {
        REP(i,n) par[i] = i;
    }

    int find(int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return sizes[find(x)];
    }
};


int main(){
    int N,M;
    cin>>N>>M;
    int s=-1,t=-1;
    REP(i,M){
        int A,B;
        cin>>A>>B;
        A--;B--;
        edge e={B,1};
        edge e2={A,1};
        G[A].PB(e);
        G[B].PB(e2);
        s=A;t=B;
    }
    UnionFind uf(N);
    deque<int> path;
    path.push_back(s);path.push_back(t);
    uf.unite(s,t);
    bool flag=false;
    while(!flag){
        flag=true;
        REP(i,SZ(G[s])){
            if(!uf.same(s,G[s][i].to)){
                path.push_front(G[s][i].to);
                uf.unite(s,G[s][i].to);
                s=G[s][i].to;
                flag=false;
                break;
            }
        }
        REP(i,SZ(G[t])){
            //cout<<i<<" "<<t<<" "<<G[t][i].to<<endl;
            if(!uf.same(t,G[t][i].to)){
                path.push_back(G[t][i].to);
                uf.unite(t,G[t][i].to);
                t=G[t][i].to;
                flag=false;
                break;
            }
        }

    }
    //cout<<uf.same(t,3)<<endl;
    cout<<SZ(path)<<endl;
    while(!path.empty()){
        cout<<1+path.front();
        if(SZ(path)!=1)cout<<" ";
        else cout<<endl;
        path.pop_front();
    }

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<pair<ll,ll>> p;
    int x,l;
    for (int i=0;i<n;i++) {
        cin >> x >> l;
        p.push_back(make_pair(x,l));
    }
    sort(p.begin(),p.end());
    int ans=n;
    ll m=p[0].first+p[0].second;
    for (int i=1;i<n;i++) {
        if (m>p[i].first-p[i].second) {
            ans--;
            if (m>p[i].first+p[i].second) m=p[i].first+p[i].second;
        } else if (m<p[i].first+p[i].second) {
            m=p[i].first+p[i].second;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  int A[N], B[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  long long ans = 0;
  for (int i = 0; i < N; i++)
    if (A[i] > B[i]) ans = -1;
  if (ans < 0) {
    cout << -1 << '\n';
    return 0;
  }
  auto next = [&](int i) { return (i + 1) % N; };
  auto prev = [&](int i) { return (i - 1 + N) % N; };
  queue<int> que;
  for (int i = 0; i < N; i++) que.push(i);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    if (B[v] <= A[v]) continue;
    int n = next(v), p = prev(v);
    ans += (B[v] - A[v]) / (B[n] + B[p]);
    B[v] = (B[v] - A[v]) % (B[n] + B[p]) + A[v];
    if (B[n] > B[v] + B[next(n)]) que.push(n);
    if (B[p] > B[v] + B[prev(p)]) que.push(p);
  }
  for (int i = 0; i < N; i++)
    if (A[i] != B[i]) ans = -1;
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

const int N = 55;

char a[N][N], b[N][N];

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		string str;
		cin >> str;
		for (int j = 0; j < n; j++) {
			a[i][j] = str[j];
		}
	}
	for (int i = 0; i < m; i++) {
		string str;
		cin >> str;
		for (int j = 0; j < m; j++) {
			b[i][j] = str[j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			bool fail = 0;
			if (i + m - 1 >= n || j + m - 1 >= n) continue;
			for (int k = 0; k < m; k++) {
				for (int l = 0; l < m; l++) {
					if (a[i + k][j + l] != b[k][l]) fail = 1;					
				}
			}
			if (!fail) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}                            

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);
	
	LL X,Y;
	cin >> X >> Y;
	LL ans = 0;
	LL now = X;
	while(now <= Y){
		ans++;
		now *= 2;
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double xs = sc.nextDouble();
        double ys = sc.nextDouble();
        double xg = sc.nextDouble();
        double yg = sc.nextDouble();
        int N = sc.nextInt();
        double[] x = new double[N+2];
        double[] y = new double[N+2];
        double[] r = new double[N+2];
        for (int i=0;i<N;i++) {
            x[i] = sc.nextDouble();
            y[i] = sc.nextDouble();
            r[i] = sc.nextDouble();
        }
        x[N]=xs;y[N]=ys;r[N]=0;x[N+1]=xg;y[N+1]=yg;r[N+1]=0;

        ArrayList<ArrayList<double[]>> edge = new ArrayList<ArrayList<double[]>>();
        for (int i=0;i<N+2;i++) {
            ArrayList<double[]> add = new ArrayList<double[]>();
            edge.add(add);
        }
        for (int i=0;i<N+2;i++) {
            for (int j=0;j<N+2;j++) {
                if (i==j) continue;
                double dist = Math.pow(Math.pow(x[i]-x[j], 2)+Math.pow(y[i]-y[j], 2), 0.5);
                double[] add = {j, Math.max(dist-r[i]-r[j], 0)};
                edge.get(i).add(add);
            }
        }

        double[] dist_arr = new double[N+2];
        Arrays.fill(dist_arr, -1);
        double[] first = {N, 0};
        PriorityQueue<double[]> pq = new PriorityQueue<double[]>((o1, o2)->Double.compare(o1[1], o2[1]));
        pq.add(first);
        while (!pq.isEmpty()) {
            double[] rem = pq.poll();
            if (dist_arr[(int)rem[0]]!=-1) continue;
            dist_arr[(int)rem[0]] = rem[1];
            for (double[] tmp : edge.get((int)rem[0])) {
                double[] add = {tmp[0], rem[1]+tmp[1]};
                if (dist_arr[(int)tmp[0]]==-1) pq.add(add);
            }
        }
        System.out.println(dist_arr[N+1]);
        // System.out.println(Arrays.toString(dist_arr));
        // System.out.println(edge);
    }
}

Measured memory_bytes: 129748
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int main(void)
{
	int x; cin >> x;
	int ans = 0;
	ans += x/500*1000;
	x %= 500;
	ans += x/5*5;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
vector <vector <ll> > dp,input;
ll n;
ll mod = 1e9+7;
ll func(ll node,ll last_state,ll par)
{
    if(input[node].size() == 1 && input[node][0] == par)
    {
        if(last_state == 0)
            return 1;
        else
            return 2;
    }
    if(dp[node][last_state] != -1)
        return dp[node][last_state];
    ll result = 1,test1=1,test2=1;
    for(ll i=0;i<input[node].size();i++)
    {
        if(input[node][i] == par)
            continue;
        ll t1;
        t1 = func(input[node][i],1,node)%mod;
        test1 = ((test1%mod)*t1)%mod;
        ll t2 = func(input[node][i],0,node)%mod;
        test2 = ((test2%mod)*t2)%mod;
        if(last_state == 0)
        {
            result =test1%mod;// result*t1;
        }
        else
            result = (test1+test2)%mod;//result*t1+result*func(input[node][i],0,node);
    }
    return dp[node][last_state] = result;
}
int main()
{
    cin>>n;
    input.clear();
    input.resize(n+1);
    for(ll i=0;i<n-1;i++)
    {
        ll a,b;
        cin>>a>>b;
        input[a].push_back(b);
        input[b].push_back(a);
    }
    if(n == 1)
    {
        cout<<2<<endl;
        return 0;
    }
    dp.clear();
    dp.resize(n+1,vector <ll> (2,-1));
    cout<<func(1,1,-1);
}

Measured memory_bytes: 18176