akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
from math import gcd

class SegTree:
    def __init__(self, N, ele):
        self.num = 2**(N-1).bit_length()
        self.el = ele
        self.data = [ele]*(2*self.num)

    def calc(self, x, y):
        return gcd(x, y)

    def update(self, idx, x):
        idx += (self.num - 1)
        self.data[idx] = x
        while idx > 0:
            idx = (idx-1)//2
            self.data[idx] = self.calc(self.data[2*idx+1], self.data[2*idx+2])

    def prod(self, l, r):
        L = l + self.num
        R = r + self.num
        res = self.el
        while L < R:
            if L & 1:
                res  = self.calc(res, self.data[L-1])
                L += 1
            if R & 1:
                R -= 1
                res = self.calc(res, self.data[R-1])
            L >>= 1
            R >>= 1
        return res

    def get(self, idx):
        idx += (self.num - 1)
        return self.data[idx]
    

n = int(input())
A = list(map(int, input().split()))
seg = SegTree(n, 0)
for i, a in enumerate(A):
    seg.update(i, a)

ans = 0
for i in range(n):
    g = seg.get(i)
    seg.update(i, 0)
    ans = max(ans, seg.prod(0, n))
    seg.update(i, g)
print(ans)

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

int main() {
    int N;
    cin >> N;
    vector<int> P(N); // 0-indexed
    rep(i, N) cin >> P.at(i);

    vector<int> m(N); // P[0]~P[i]の最小値
    m.at(0) = P.at(0);
    rep2(i, 1, N) {
        m.at(i) = min(m.at(i - 1), P.at(i));
        // cout << m.at(i) << " "; //DB
    }

    int ans=0;
    rep(i, N) {
        if (m.at(i) == P.at(i)) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T> ostream& operator<<(ostream &os, vector<T> &v){os << "{";ITR(i,v){if(i!=v.begin())os << ","; os << *i;}os << "}"; return os;}
template <typename T, typename U> ostream& operator<<(ostream& os, pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

LLI dp[101000][3];

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

  int N; cin >> N;
  vector<int> a(N),b(N),c(N);
  REP(i,N) cin >> a[i] >> b[i] >> c[i];
  
  REP(i,N){
    REP(j,3){
      chmax(dp[i+1][0], max(dp[i][1]+a[i], dp[i][2]+a[i]));
      chmax(dp[i+1][1], max(dp[i][0]+b[i], dp[i][2]+b[i]));
      chmax(dp[i+1][2], max(dp[i][0]+c[i], dp[i][1]+c[i]));
    }
  }

  LLI ans = max({dp[N][0], dp[N][1], dp[N][2]});
  cout << ans << endl;
  
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int count = 0;
    for(int i = 0; i < n-1; i++){
        if(s.at(i) != s.at(i+1)){
            count++;
        }
    }
    cout << count+1 << endl;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<long long> PPP(N), PPM(N), PMP(N), PMM(N);
	for (int i = 0; i < N; i++) {
		long long x, y, z;
		cin >> x >> y >> z;
		PPP[i] = x + y + z;
		PPM[i] = x + y - z;
		PMP[i] = x - y + z;
		PMM[i] = x - y - z;
	}
	sort(PPP.begin(), PPP.end());
	sort(PPM.begin(), PPM.end());
	sort(PMP.begin(), PMP.end());
	sort(PMM.begin(), PMM.end());
	vector<long long> sum(8);
	for (int i = 0; i < M; i++) {
		sum[0] -= PPP[i];
		sum[1] -= PPM[i];
		sum[2] -= PMP[i];
		sum[3] -= PMM[i];
		sum[4] += PPP[N - 1 - i];
		sum[5] += PPM[N - 1 - i];
		sum[6] += PMP[N - 1 - i];
		sum[7] += PMM[N - 1 - i];
	}
	cout << *max_element(sum.begin(), sum.end()) << endl;
}

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

typedef pair<int, int> PII;
#define fi first
#define se second

const int N=10005;
vector<PII> g[N];
int dist[N];
bool vis[N];
int n;

void dijkstra(){
    dist[0]=0;
    priority_queue<PII, vector<PII>, greater<PII>> q;
    q.push({0, 0});
    while(!q.empty()){
        int node=q.top().se;
        q.pop();
        if(vis[node]) continue;
        vis[node]=true;
        for(auto &e: g[node]){
            int v=e.fi;
            int w=e.se;
            if(dist[v]>dist[node]+w){
                dist[v]=dist[node]+w;
                q.push({dist[v], v});
            }
        }
    }
}

int main(){
    memset(dist, 0x3f, sizeof dist);
    memset(vis, 0x00, sizeof vis);
    cin>>n;
    for(int i=0; i<n; ++i){
        int u, k;
        cin>>u>>k;
        for(int j=0; j<k; ++j){
            int v, w;
            cin>>v>>w;
            g[u].push_back({v, w});
        }
    }
    
    dijkstra();
    for(int i=0; i<n; ++i) cout<<i<<" "<<dist[i]<<endl;
    
    return 0;
}


Measured memory_bytes: 8120
#include<iostream>
using namespace std;
const int BUF = 200005;


int nA, nB, limit;
int aVal[BUF], bVal[BUF];

void read() {
    cin >> nA >> nB >> limit;
    for (int i = 0; i < nA; ++i) cin >> aVal[i];
    for (int i = 0; i < nB; ++i) cin >> bVal[i];
}


void work() {
    int ans = 0;
    
    long long sum = 0;
    int bIdx = 0;
    while (bIdx < nB && sum + bVal[bIdx] <= limit) {
        sum += bVal[bIdx++];
    }

    ans = bIdx;

    for (int aIdx = 0; aIdx < nA; ++aIdx) {
        sum += aVal[aIdx];
        while (bIdx - 1 >= 0 && sum > limit) {
            --bIdx;
            sum -= bVal[bIdx];
        }
        
        if (sum <= limit) {
            ans = max(ans, aIdx + 1 + bIdx);
        }
    }

    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 5096
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int h = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int r = sc.nextInt();
    if((x + r) <= w && (x - r) >= 0 && (y + r) <= h && (y - r) >= 0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
    sc.close();
  }
}



Measured memory_bytes: 26340
import numpy as np
from itertools import combinations
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0

for i, j in combinations(X, 2):
    cnt += (sum(dif**2 for dif in np.array(i) - np.array(j))**.5).is_integer()
print(cnt)


Measured memory_bytes: 27168
#include<stdio.h>

int main(void){
  int K,A,B;
  scanf("%d\n",&K );
  scanf("%d %d\n",&A,&B );
  for(int i=A; i<=B; i++){
    if(i % K ==0){
      printf("OK\n" );
      return 0;
    }
  }
  printf("NG\n" );
  return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
#include <set>
#include <map>
using ll = long long;
using namespace std;

int main(void){
    string s;
    string E={'-','-','-'};
    int a,b,c,d;
    int n=3;
    cin>>s;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    
    for (int bit = 0; bit < (1<<n); ++bit) {
        vector<int> S;
        string E2=E;
        int sum=s[0]-'0';
        
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { 
                S.push_back(i);
            }
        }
        for (int i = 0; i < (int)S.size(); ++i) {
            E2[S[i]]='+';
        }
        for (int i = 1;i<=n;i++){
            if(E2[i-1]=='-') sum-=s[i]-'0';
            else sum+=s[i]-'0';
        }
        if(sum==7){
            cout<<a<<E2[0]<<b<<E2[1]<<c<<E2[2]<<d<<"=7";
            exit(0);
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,cnt=0,a,check,cnt2=0,check2=0,k=0,ki=0;
cin>>n;
vector<int>v,v2;
for(int i=0;i<n;i++)
{
    cin>>a;
    v.push_back(a);
     v2.push_back(a);
}
sort(v2.begin(),v2.end());
int temp=v[0];
for(int i=1;i<n;i++)
{
    if(v[i]<temp)
    {
        cnt++;
        if(cnt==1)
            k=i-1;
        else
            ki=i;

    }

    if(cnt==2)
        break;
temp=v[i];
}
int temp2=v[k];
v[k]=v[ki];
v[ki]=temp2;
for(int i=0;i<n;i++)
{
    if(v[i]==v2[i])
        cnt2++;

}
if(cnt2==n)
    cout<<"YES"<<endl;
else
    cout<<"NO"<<endl;
return 0;
}


Measured memory_bytes: 256
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    val n = in.next.head
    val x = in.next
    var res = 0L
    def msort(s: Int, e: Int): Unit = {
        if (e-s > 0) {
            msort(s, (s+e)/2)
            msort((s+e)/2+1, e)
            var i = s
            var j = (s+e)/2+1
            var k = 0
            val tmp = Array.fill(e-s+1)(0)
            var f = true
            while (f)
                if (i > (s+e)/2 && j > e) f = false
                else if (j > e || (i <= (s+e)/2 && x(i) < x(j))) {tmp(k) = x(i); i += 1; k += 1}
                else {tmp(k) = x(j); j += 1; k += 1; res += ((s+e)/2-i+1)}
            tmp.copyToArray(x, s)
        }
    }
    msort(0, n-1)
    println(res)
}

Measured memory_bytes: 109196
#include <iostream>
using namespace std;
int main(){
    int eng,ma,jp,n;
    char judge[10000];
    while(1){
        cin>>n;
        if(n==0){
            break;
        }
        for(int i=0;i<n;i++){
            cin>>ma>>eng>>jp;
            if((ma==100 || eng==100 || jp==100)||((ma+eng)/2>=90)||((ma+eng+jp)/3>=80)){
                judge[i]='A';
            }
            else if(((ma+eng+jp)/3>=70)||((ma+eng+jp)/3>=50&&(eng>=80 || ma>=80))){
                judge[i]='B';
            }
            else {
                judge[i]='C';
            }
        }
        for(int i=0;i<n;i++){
            cout<<judge[i]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  string s;cin>>s;
  int x=stoi(s);
  int a=0;
  rep(i,s.size())a+=s[i]-'0';
  if(x%a==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
h = [int(input()) for i in range(n)]
ng = 0
ok = 10 ** 9
while ok - ng > 1:
  mid = (ok + ng) // 2
  s = 0
  for i in h:
    s += max(0, (i - mid * b + a - b - 1) // (a - b))
  if s <= mid:
    ok = mid
  else:
    ng = mid
print(ok)


Measured memory_bytes: 7196
#include<stdio.h>

int main(){

  int x,y,r,d;


  scanf("%d%d", &x,&y);
  
 if(x<y){
    d = x;
    x = y;
    y = d;
  }


  r = x % y;
  while(r!=0){
    x = y;
    y = r;
    r = x % y;
  }

  printf("%d\n",y);

  return 0;
}



  



Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const ll INF = 0x3f3f3f3f;

// a1=x1+x2, a2=x2+x3, a3=x3+x1
// a1-x1=a2-x3
// a1-x1=a2-a3+x1
// -2x1=-a1+a2-a3
// 2x1=a1-a2+a3

int a[100001];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("A.txt", "r", stdin);
    #endif
    int n, ans=0;
    cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
        ans += a[i]*pow(-1, i+1);
    }

    for(int i=1; i<=n; i++)
    {
        cout << ans << ' ';
        ans = 2*(a[i]-ans/2);
    }

}


Measured memory_bytes: 1664
var lines = [];


var readline = require("readline");
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.on('line', function (x) {
  lines.push(x);
});

rl.on('close', function () {
  var N = Number(lines[0].split(" ")[0]);
  var M = Number(lines[0].split(" ")[1]);

  lines.shift();

  var AB = lines.map(i => i.split(" ").map(i => Number(i)));
  AB.sort((a, b) => a[0] - b[0]);


  var ans = 0;
  for (var i = 0; i < N; i++) {
    var A = AB[i][0]; var B = AB[i][1];

    if (B < M) { ans += A * B; M -= B }
    else {
      ans += A * M; break;
    }
  }
  console.log(ans);
});

Measured memory_bytes: 54732
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T, class U> inline void chmax(T &a, const U &b) { if ((a) < (b)) (a) = (b); }
template <class T, class U> inline void chmin(T &a, const U &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

vvl ans;

void dfs(vec<ll> x, ll level){
    dump(x);
    if (sz(x) <= 1) return;

    int m = sz(x);
    rep(i, m/2){
        rep(j, m/2, m){
            ans[x[i]][x[j]] = level;
        }
    }

    {
        vl y(m/2);
        rep(i, m/2){
            y[i] = x[i];
        }
        dfs(y, level+1);
    }
    {
        vl y(m - m/2);
        dump(m, m/2);
        rep(i, m/2, m){
            y[i-m/2] = x[i];
        }
        dfs(y, level+1);
    }
    return;
}

int solve() {
    ll n;cin>>n;
    ans = make_table(n, n, 0LL);
    vl x(n);
    iota(all(x), 0LL);
    dfs(x, 1);
    dump_2d(ans, n, n);

    rep(i, n){
        vl buf;
        rep(j, i+1, n) buf.pb(ans[i][j]);
        rep(j, sz(buf)) cout << buf[j] << (j!=sz(buf)-1 ? " " : "\n");
    }

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 5464
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int a,b,d,r;
    double f,aa,bb;
    cin >> a >> b;
    aa = a;
    bb = b;
    d = a/b;
    r = a%b;
    f = aa/bb;
    cout << d << " " << r << " " << flush;
    printf("%.5lf\n", f);
}


Measured memory_bytes: 3340
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

long long dp[100][(int)1e5+1] ;

int main()
{
	int t=1;
	// cin >> t ;

	while(t--)
	{
		for(int i=0 ; i<100 ; i++) 
			for(int j=0 ; j<=1e5 ; j++)
				dp[i][j] = 0 ;
		
		int n ,W; 
		cin>>n>>W;
		vector<long long> w ,v ;
		w.resize(n) ;
		v.resize(n) ;
		for(int i = 0 ; i<n ; i++)
			cin>>w[i]>>v[i] ;

		for(int i=n-1 ; i>=0 ; i--)
		{
			for(int c=0 ; c<=W ; c++)
			{
				if(i+1<n) dp[i][c] = dp[i+1][c] ;

				if(c>=w[i])
				{
					if(i+1<n)
						dp[i][c] = max(dp[i+1][c-w[i]]+v[i] , dp[i][c]) ;
					else dp[i][c] = v[i] ;
				}
			}
		}
		cout << dp[0][W] << endl ;
	}
	return 0;
}

Measured memory_bytes: 78464
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

#define INF (1 << 21)

using namespace std;

int N;

int check[1000000];

queue<string> que, que_next;

int index(string str){
	
	int ref = 0;
	
	for(int i = 0; i < N; i++){
		ref += str[i] - '0';
		ref *= 3;
	}
	
	return ref;
}

int main(){
	
	while(true){
		string str;
		cin >> str;
		
		queue<string> que_emp;
		
		que = que_emp;
		que_next = que_emp;
		
		for(int i = 0; i < 1000000; i++){
			check[i] = INF;
		}
		
		if(str[0] == '0'){
			break;
		}else{
			N = str.size();
			for(int i = 0; i < N; i++){
				if(str[i] == 'r'){
					str[i] = '0';
				}else if(str[i] == 'b'){
					str[i] = '1';
				}else{
					str[i] = '2';
				}
			}
		}
		
		que.push(str);
		
		int depth = 0;
		
		while(true){
			while(!que.empty()){
				string str = que.front();
				que.pop();
				if(check[index(str)] != INF){
					continue;
				}
				check[index(str)] = depth;
				for(int i = 0; i < N - 1; i++){
					if(str[i] != str[i + 1]){
						string str_copy = str;
						if(str[i] != '0' && str[i + 1] != '0'){
							str_copy[i] = '0';
							str_copy[i + 1] = '0';
						}else if(str[i] != '1' && str[i + 1] != '1'){
							str_copy[i] = '1';
							str_copy[i + 1] = '1';
						}else{
							str_copy[i] = '2';
							str_copy[i + 1] = '2';
						}
						que_next.push(str_copy);
					}
				}
			}
			que = que_next;
			que_next = que_emp;
			depth++;
			if(que.empty()){
				break;
			}
			//cout << depth << " " << que.size() << endl;;
		}
		
		string check_0 = "";
		string check_1 = "";
		string check_2 = "";
		
		for(int i = 0; i < N; i++){
			check_0 = check_0 + "0";
			check_1 = check_1 + "1";
			check_2 = check_2 + "2";
		}
		
		int ans = min(min(check[index(check_0)], check[index(check_1)]), check[index(check_2)]);
		
		if(ans == INF){
			cout << "NA" << endl;
		}else{
			cout << ans << endl;
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 7820
import collections
n = int(input())
a = list(map(int,input().split()))
ans = 0
cnt = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        cnt += 1
    else:
        ans += cnt //2
        cnt = 1
ans += cnt // 2
print(ans)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if(N < 1000) cout << 1000- N << endl;
  else if(N % 1000 ==0) cout << 0 << endl;
  else cout << 1000 - (N % 1000) << endl;
}

Measured memory_bytes: 3616
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let k:String = read!();
    let mut v:Vec<char> = k.chars().collect();
    if v[0]==v[1]&&v[1]==v[2] {
        println!("No");
    }
    else {
        println!("Yes");
    }
}

Measured memory_bytes: 2160
#include <bits/stdc++.h>
using namespace std;
int main(){
  int in;
  cin >> in;
  int upper3=in/10;
  int lower3= in-(in/1000)*1000;
  int upper=in/1000;
  int lower=in- (in/10)*10;
  
  if(lower3==0){
    cout<<"Yes"<<endl;
  }else if( upper3==upper*111
    || lower3==lower*111){
    cout << "Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
}

Measured memory_bytes: 256
/*
       This sky
       Is lonely and grey
       But every night I feel your gravity waves
       And the world is cold
       But it's beautiful
       I wish you were here now
       I miss your soul
       But you lost your light
       When the darkness called
       I still stand here waiting
       The last to fall
       The last to fall
       The last to fall
       The last to fall
                            */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const unordered_map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define dbg(x) cout<<#x<<" = "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________________
int main()
{
       int n;
       cin>>n;
       ll a[n];
       arrin(a,n);
       map<ll,ll> mp;
       ll sum = 0;
       fri(i,0,n){
              sum += a[i];
              mp[a[i]]++;
       }
       int q;
       cin>>q;
       while(q--)
       {
              int b,c;
              cin>>b>>c;
              sum -= mp[b]*b;
              sum += mp[b]*c;
              mp[c] += mp[b];
              mp[b] = 0;
              cout<<sum<<endl;
       }
}


Measured memory_bytes: 10224
#!/usr/bin/env python3
import sys


def solve(X: int, A: int, B: int):
    ret = (X - A) % B
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(X, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a;
	int n;
	cin >> n;
	if (n == 7 || n == 5 || n == 3) {
		cout << "YES" << "\n";
	}
	else {
		cout << "NO" << "\n";
	}
	cin >> a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline int read() {
	int x = 0, fh = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fh = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	return x * fh;
}
const int N = 1e5 + 10;
vector<pair<int, int> > g[N];
queue<int> q;
int n, x, y, d, i, col[N], vis[N];
int main() {
	n = read();
	for (i = 1; i < n; i++) {
		x = read(); y = read(); d = read();
		g[x].push_back(make_pair(y, d));
		g[y].push_back(make_pair(x, d));
	}
	q.push(1);
	col[1] = vis[1] = 1;
	while (!q.empty()) {
		x = q.front();
		q.pop();
		for (i = 0; i < g[x].size(); i++) {
			if (vis[g[x][i].first]) continue;
			vis[g[x][i].first] = 1;
			if (g[x][i].second & 1) col[g[x][i].first] = col[x] ^ 1;
			else col[g[x][i].first] = col[x];
			q.push(g[x][i].first);
		}
	}
	for (i = 1; i <= n; i++) cout << col[i] << '\n';
	return 0;
}

Measured memory_bytes: 10364
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


n = readint()
a = readints()

b = a[0]
ans = 0
for i in range(1,n):
    ans += max(b-a[i],0)
    b = max(a[i],b)
print(ans)


Measured memory_bytes: 92676
days = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']

S = input()

mode = 0
for i, day in enumerate(days * 2):
    if mode == 0:
        mode = 1 if S == day else 0
        i_today = i
    else:
        if day == 'SUN': break

if S == 'SUN':
    print(7)
else:
    print(i - i_today)
    

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

int N;
string s, t;

int main() {
  cin >> N >> s >> t;
  int i;
  for (i=N; i>=0; i--) {
    if (s.substr(N-i, N) == t.substr(0, i)) break;
  }
  cout << 2*N - i << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a <= b) {
        if (b <= c){
            cout << c - a << endl;
        } else if (a <= c){
            cout << b - a << endl;
        } else {
            cout << b - c << endl;
        }
    } else {
        if (a <= c){
            cout << c - b << endl;
        } else if (b <= c){
            cout << a - b << endl;
        } else {
            cout << a - c << endl;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        char[] s = S.toCharArray();
        char[] t = T.toCharArray();
        lavel:
        for (int i = 0; i < S.length(); i++) {
            int l = 0;
            for (int j = i; j < S.length(); j++, l++) {
                if (s[j] == t[l]) {
                } else {
                    continue lavel;
                }
                if (l == S.length() - 1 && i == 0) {
                    System.out.println("Yes");
                    return;
                }
            }
            for (int k =0; k < i; k++, l++) {
                if (s[k] == t[l]) {
                } else {
                    continue lavel;
                }
                if (l == S.length() - 1) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
int x[101],y[101],h[101];
signed  main(){
  int n;cin>>n;
  for(int i=1;i<=n;++i){
    cin>>x[i]>>y[i]>>h[i];
  }
  //let's brute force for cx,cy
  for(int i=0;i<=100;++i){
    for(int j=0;j<=100;++j){
      //if i,j is centre
      set<int>S;
      for(int k=1;k<=n;++k){
        int val=h[k]+abs(x[k]-i)+abs(y[k]-j);
        if(val>0)
        S.insert(val);
      }
      int hi=*S.begin();
      bool flag=true;
      for(int k=1;k<=n;++k){
        if(max(hi-abs(i-x[k])-abs(j-y[k]),(int64_t)0)!=h[k]){flag=false;break;}
      }
      if(flag){
        cout<<i<<" "<<j<<" "<<*S.begin()<<"\n";
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans = "";
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '0')
                ans += "0";
            else if (s.charAt(i) == '1')
                ans += "1";
            else {
                if (ans.length() > 0)
                    ans = ans.substring(0, ans.length() - 1);
                else
                    ;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct Edge {
	int from, to;
};
struct RLAQ {
	ll sst[1 << 18];
	ll adt[1 << 18];
	RLAQ() {
		fill(sst, sst + (1 << 18), 0);
		fill(adt, adt + (1 << 18), 0);
	}
	void add(int p, int q, ll x, int k = 0, int l = 0, int r = (1 << 17)) {
		if (r <= p || q <= l) return;
		if (p <= l && r <= q) {
			adt[k] += x;
			return;
		}
		add(p, q, x, 2 * k + 1, l, (l + r) / 2);
		add(p, q, x, 2 * k + 2, (l + r) / 2, r);
		sst[k] = max(sst[2 * k + 1] + adt[2 * k + 1], sst[2 * k + 2] + adt[2 * k + 2]);
	}
	ll find(int p, int q, int k = 0, int l = 0, int r = (1 << 17)) {
		if (r <= p || q <= l) return LLONG_MIN / 2;
		if (p <= l && r <= q) return sst[k] + adt[k];
		ll m1, m2;
		m1 = find(p, q, 2 * k + 1, l, (l + r) / 2);
		m2 = find(p, q, 2 * k + 2, (l + r) / 2, r);
		return max(m1, m2) + adt[k];
	}
};

int arr[1000001], pc;
void Eratosthenes(int N) {//Nまでの素数表
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = i * 2; j <= N; j += i) {
				arr[j] = 0;
			}
		}
	}

	int cou = 0;
	for (int i = 2; i < N; i++) {
		if (arr[i] == 1) {
			arr[cou] = i;
			cou++;
		}
	}
	pc = cou;
}
int main() {
	int n;
	cin >> n;
	vector<int> a(n),k(n);
	REP(i, n) {
		scanf("%d %d", &a[i], &k[i]);
	}
	int grundy = 0;

	REP(i, n) {
		int cur = a[i];
		int bef = cur,bf = -1;
		while (cur % k[i]) {
			int fase = cur / k[i] + 1;
			cur -= fase;
			fase = cur / k[i] + 1;
			int b = (cur / k[i]) * k[i];
			cur = (cur-b) % fase + b;
			if (cur < 0 || cur == bef || fase == bf)
				return -1;
			bef = cur;
			bf = fase;
		}

		grundy ^= cur/k[i];
	}

	cout << (grundy ? "Takahashi" : "Aoki") << endl;
	return 0;
}

Measured memory_bytes: 256
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
import bisect
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

N = int(input())
T = [None]*N
for i in range(N):
    Ai = int(input())
    T[i] = [-1]*N
    for j in range(Ai):
        xij, yij = map(int, input().split())
        dump(i, xij-1, yij)
        T[i][xij-1] = yij
dump(T)


def imply(p, q): return (not p) or q


ans = -1
for trusts in it.product([0, 1], repeat=N):
    dump(trusts)
    ok = True
    for i, trust in enumerate(trusts):
        if trust:
            for j, tij in enumerate(T[i]):
                ok = ok and imply(tij == 1, trusts[j]) and (
                    imply(tij == 0, not trusts[j]))
    if ok:
        ans = max([ans, len([i for i in trusts if i == 1])])
    dump(ans)
print(ans)


Measured memory_bytes: 45036
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    ll n; cin>>n;
    map<ll,ll> box;
    vector<ll> a(n);
    rep(i,n){
        ll x;
        cin>>x;
        box[x]+=1;
        a[i]=x;
    }
        ll sum=0;
        for(auto j : box){
            ll y=j.second;
            sum+=y*(y-1)/2;
        }
    
    rep(i,n){
        ll i_sum=sum-box[a[i]]+1;
        cout<<i_sum<<endl;
    }


}


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

#define ll long long 
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define pl pair<long ,long >
#define pi pair<int ,int >
#define lb(v,x) lower_bound(v.begin(),v.end(),x)-v.begin();
#define ub(v,x) upper_bound(v.begin(),v.end(),x)-v.begin();
#define ct(i) cout<< i << "\n";
#define sv(v) sort(v.begin(),v.end());
#define mod 1000000007
#define M 100005

void answer(){
    ll n,ans=0,m;
    cin>>n;
    int a[n];
    std::vector<int> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    sort(v.rbegin(),v.rend());
    ans = v[0];
    int k=0;
    for(int i=0;i<n-2;i++){
        if(i%2==0) k++;
        ans+=v[k];
    }
    cout<<ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    int q;
    //cin>>q; while(q--)
        answer();
    return 0;
}


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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    vector<int> b(N);
    for (int i = 0; i < N; ++i) {
        cin >> b[i];
    }
    vector<int> res;
    for (int i = 0; i < N; ++i) {
        bool found = false;
        for (int j = (int)b.size() - 1; j >= 0; --j) {
            if (b[j] == j + 1) {
                b.erase(b.begin() + j);
                res.push_back(j + 1);
                found = true;
                break;
            }
        }
        if (!found) {
            cout << -1 << "\n";
            return 0;
        }
    }
    reverse(begin(res), end(res));
    for (int x : res) {
        cout << x << "\n";
    }


    return 0;
}

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

using namespace std;

void hawawa()
{
  int a, b;
  char op;
  cin >> a >> op >> b;
  switch (op) {
  case '+':
    cout << a + b << "\n";
    break;
  case '-':
    cout << a - b << "\n";
  }
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <unordered_map>
#define M ((ll)1e12)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi acos(-1)
typedef long long ll;
using namespace std;

void solve()
{
   //int a,b,c;cin>>a>>b>>c;
   string s;cin>>s;
   int n=s.size(),c=0;
   for(int i=0;i<n/2;i++)
   {
       if(s[i]!=s[n-i-1])
       c++;
   }
   cout<<c<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    solve();
    return 0;}

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

int main (){
  int N;
  cin >> N;
  int tab[N][2];
  for(int i=0;i<N;i++){
    cin >> tab[i][0] >> tab[i][1];
  }
  
  bool fl = false;

  for(int i=0;i<N;i++){
    if(tab[i][0] == tab[i][1] && tab[i+1][0] == tab[i+1][1] && tab[i+2][0] == tab[i+2][1])
      fl = true;
  }
  
  if(fl)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

#define mp make_pair
#define pb push_back
const int MAXN=2e5+50;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;

template<typename T, typename U> 
static inline void amin(T &x, U y){
	if(x>y)
		x = y;
}
template<typename T, typename U> 
static inline void amax(T &x, U y){
	if(x<y)
		x = y;
}

vll lazy(4*MAXN),tree(4*MAXN);
vll s(4*MAXN),e(4*MAXN),arr(MAXN+1,0);

ll calculate(int node){
	return max(tree[node],lazy[node]);
}

void lazyPropagation(int node){
	amax(lazy[2*node],lazy[node]);
	amax(lazy[2*node+1],lazy[node]);
    lazy[node] = 0;
}

void build(int node,int l,int r){
	s[node]=l;
	e[node]=r;
	if(l==r){
		tree[node]=0;
		return;
	}
	int mid=(l+r)/2;
	build(2*node,l,mid);
	build(2*node+1,mid+1,r);
	tree[node]=max(tree[2*node],tree[2*node+1]);
	return;
}

void update(int node,int l,int r,ll x){
	if(s[node]>r || e[node]<l)
	return;
	if(l<=s[node] && e[node]<=r){
		amax(lazy[node],x);
		return;
	}
	lazyPropagation(node);
	update(2*node,l,r,x);
	update(2*node+1,l,r,x);
	tree[node]=max(calculate(2*node),calculate(2*node+1));
}

ll query(int node,int l,int r){
	if(s[node]>r || e[node]<l)
	return 0ll;
	if(l<=s[node] && e[node]<=r){
		return calculate(node);
	}
	lazyPropagation(node);
	ll left=query(2*node,l,r);
	ll right=query(2*node+1,l,r);
	tree[node]=max(calculate(2*node),calculate(2*node+1));
	return max(left,right);
}

int main(){
	int n;
    cin >> n;
    ll a[n], h[n];
    for(int i=0;i<n;++i){
        cin >> h[i];
    }
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    build(1,0,n-1);
    vll dp(MAXN,0);
    for(int i=0;i<n;++i){
        amax(dp[h[i]],query(1,0,h[i]-1)+a[i]);
        update(1,h[i],MAXN-5,dp[h[i]]);
    }
    ll ans = 0;
    for(int i=0;i<n;++i){
        amax(ans,dp[h[i]]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 31488
num = int(input())

def rec_get_k(n, current_under, current_k):
  next_k = current_k + 1
  curremt_upper = current_under + 26 ** next_k
  if n < curremt_upper and n >= current_under:
    return next_k
  else:
    return rec_get_k(n, curremt_upper, next_k)

use_k = rec_get_k(num, 1, 0)
use_num = num
res_list = []
tmp_k = use_k
for i in range(use_k):
  tmp_num = use_num % 26
  if tmp_num == 0:
    tmp_num = 26
  use_num -= tmp_num
  use_num = use_num // 26
  res_list.append(chr(96 + (tmp_num)))

res_list.reverse()
print("".join(res_list))

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

int main(){
    int n;
    cin >>n;
    int a[n];
    for (int i=0;i<n;i++){
        cin >>a[i];
    }
    int ans=INT_MAX/2;
    for (int i=0;i<110;i++){
        int stamina=0;
        for (int j=0;j<n;j++){
            stamina+=(a[j]-i)*(a[j]-i);
        }
        ans=min(ans,stamina);
    }
    cout <<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

// template {{{
using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))

using int64 = long long;

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

bool in_field(int W, int H, int x, int y) {
  return (0 <= x && x < W) && (0 <= y && y < H);
}

// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

// }}}

// url: https://atcoder.jp/contests/abc103/tasks/abc103_d

int N, M;
pair<int, int> P[100000];

int main() {
  cin >> N >> M;
  rep(i, M) { cin >> P[i].first >> P[i].second; }
  sort(P, P + M, [](pair<int, int> a, pair<int, int> b) {
    if (a.second != b.second) {
      return a.second < b.second;
    } else {
      return a.first < b.first;
    }
  });

  int ans = 0;
  int remove = 0;
  rep(i, M) {
    // cout << P[i] << endl;
    if (P[i].first > remove) {
      remove = P[i].second - 1;
      // cout << "removed:" << remove << endl;
      ans++;
    } else {
    }
  }
  cout << ans << endl;

  return 0;
}

// vim: foldmethod=marker


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
str1 = input()
str2 = input()


result = ""
str_len = len(str1)
for i in range(str_len):
    if((str1[str_len - i:] + str1[0:str_len - i]) == str2):
        result = "Yes"
        break


if(result != "Yes"):
    print("No")
else:
    print(result)


Measured memory_bytes: 2940
import string

n = int(input())
s = input()

ans = 0
for i in range(n + 1):
    #i文字目が壁になる
    #0文字目の手前まで:空文字列
    #n+1文字目の手前まで:全文字列
    a, b = s[:i], s[i:]
    tmp = 0
    for c in string.ascii_lowercase:
        if (c in a) and (c in b):
            tmp += 1
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 3828
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
	long long a, b, k;
	cin >> a >> b >> k;

	if (a - k >= 0) {
		a -= k;
	}
	else {
		b -= (k - a);
		if (b < 0)
			b = 0;
		a = 0;
	}
	cout << a <<" "<< b << endl;
}

Measured memory_bytes: 256
//============================================================================
// Name        : competitive_programing.cpp
// Author      : .Data_Nerd.
// Description : problem solving training
//============================================================================

#include <bits/stdc++.h>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define MOD 1000000007
#define OO 0x3f3f3f3f
#define NIL -1
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector <bool> lala;
typedef pair<int, int> piaz;
typedef vector<vector<int>> board;
typedef priority_queue <piaz, vector <piaz>, greater<piaz>> wMinPQ;
typedef priority_queue <int, vector <int>, greater<int>> minPQ;
template <typename T> T GCD(T a, T b) { return !a ? b : GCD(b % a, a); }
template <typename T> T LCM(T a, T b) { return (a * b) / GCD(a, b); }
template <typename T>
T fastPower(T base, T power) {
	if(!power)
		return 1;
	T ans = fastPower(base, power >> 1);
	return power & 1 ? ans * ans * base : ans * ans;
}
template <typename T>
T modPower(T base, T power, T m = MOD) {
	if(!power)
		return 1;
	T ans = modPower(base, power >> 1) % m;
	return power & 1 ? (((ans * ans) % m) * (base % m)) % m : (ans * ans) % m;
}

string k;

int d;

const int N =  1e4 + 1;

int memo[N][100][2];

int add(int x, int y, int m) {
	return (x + y) % m;
}

int dp() {
	memo[k.size()][0][false] = memo[k.size()][0][true] = 1;
	for(int idx = k.size() - 1; idx >= 0; --idx) {
		for(int smaller = 0; smaller <= 1; ++smaller) {
			for(int sum = 0; sum < d; ++sum) {
				for(int digit = 0; digit < 10; ++digit) {
					if(not smaller and digit > k[idx] - '0')
						continue;
					int &ans = memo[idx][sum][smaller];
					ans = add(memo[idx + 1][add(sum, digit, d)][smaller | (digit < k[idx] - '0')], ans, MOD);
				}
			}
		}
	}
	return memo[0][0][0];
}

int main() {
    Data_Nerd

	cin >> k >> d;

    cout << (dp() - 1 + MOD) % MOD;

    return 0;
}


Measured memory_bytes: 8064
import Foundation

let _ = readLine()!
var input = readLine()!.componentsSeparatedByString(" ").map { Int($0)! }

var sum = 0
for i in input {
    sum += i
}

let maxL = input.maxElement()!

if maxL < sum - maxL {
    print("Yes\n")
} else {
    print("No\n")
}


Measured memory_bytes: 1152
N,M,X,Y = (int(i) for i in input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
ans='War'
for Z in range(-100,101):
    if(X<Z<=Y 
        and all([x[i]<Z for i in range(N)]) 
        and all([y[i]>=Z for i in range(M)])
    ):
        ans ='No War'
        break
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

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

	ll n, m, k;
	cin>>n>>m>>k;
	ll a[n], b[m];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	ll c=0;
	ll tot=0;
	int i=0, j=0;
	ll ans=0;
	while(tot<k){
		if(i<n){
			tot+=a[i++];
		}
		else break;
		
		if(tot<=k) c++;
		else {
			tot-=a[--i];
			break;
		}
	}
	while(tot<k){
		if(j<m){
			tot+=b[j++];
		}
		else break;

		if(tot<=k) c++;
		else {
			tot-=b[--j];
			break;
		}
	}
	//cout<<tot;
	ans = c;
	//cout<<c;
	while(j<m){
		if(i!=0) tot-=a[--i];
		else break;
		c--;
		while(tot<k){
			if(j<m){
				tot+=b[j++];
			}
			else break;

			if(tot<=k) c++;
			else {
				tot-=b[--j];
				break;
			}
		}
		ans = max(ans, c);
		//cout<<c;
	}
	cout<<ans;

    return 0;
}


Measured memory_bytes: 6768