akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int k;
  cin >> k;
  if (k <= 9) {
    cout << k;
    return 0;
  }
  std::priority_queue<ll, std::vector<ll>, std::greater<ll> > q;
  q.push(1);
  q.push(2);
  q.push(3);
  q.push(4);
  q.push(5);
  q.push(6);
  q.push(7);
  q.push(8);
  q.push(9);
  while (true) {
    ll x = q.top();
    q.pop();
    k--;
    if (k == 0) {
      cout << x;
      return 0;
    }
    if(x%10>0)
    q.push(10 * x + x % 10 - 1);
    q.push(10 * x + x % 10);
    if(x%10<9)
    q.push(10 * x + x % 10 + 1);
  }
}


Measured memory_bytes: 2420
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x = 0, i = 0;
        int[] arr = new int[n];
        if(n <= 100){
        for(i = 0;i < n ;i++){
        	x = scan.nextInt();
        	if(0 <= x && x < 1000){
        	arr[i] = x;
        	}
        }
        for(i = n-1;i >= 0;i--){
        System.out.print(arr[i]);
        if( i > 0){
        System.out.print(" ");
        }
        }System.out.println();
               
 }
		
		
		}
}	
			
		
	
		
		



		

Measured memory_bytes: 26132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;
const ll mod = 1000000007;

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

int main()
{
  ll n; cin>>n;
  ll z = 0;
  map<pair<ll, ll>, ll> mp;
  rep(i, n) {
    ll aa, bb; cin>>aa>>bb;
    if (aa == 0 && bb == 0) {
      z++; continue;
    }
    if (aa == 0) bb = 1;
    else if (bb == 0) aa = 1;
    else {
      ll g = gcd(aa, bb);
      aa /= g; bb /= g;
      if (aa < 0) {
        aa *= -1; bb *= -1;
      }
    }
    mp[{aa,bb}]++;
  }
  ll ans = 1;
  for (auto v:mp) {
    ll tmp = 1;
    ll x = v.first.first;
    ll y = v.first.second;
    if (y < 0) { x = -x; y = -y; }
    ll a = (modpow(2, v.second)+mod-1)%mod;
    ll b = (modpow(2, mp[{y, -x}])+mod-1)%mod;
    tmp = (tmp + a) % mod;
    tmp = (tmp + b) % mod;
    ans = (ans * tmp) % mod;
    mp[v.first] = 0;
    mp[{y, -x}] = 0;
  }
  ans = (ans+mod-1)%mod;
  ans = (ans+z)%mod;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 28592
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()

	var l, r, ans int
	for i := 0; i < n; i++ {
		l, r = ri(), ri()
		ans += r - l + 1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
    ll n,m;
    std::cin >> n>>m;
    vector<pair<ll,ll>> ab(n);
    vector<pair<ll,ll>> cd(m);
    for (int i = 0; i < n; i++) {
        ll a,b;
        std::cin >> a>>b;
        ab[i] = {a,b};
    }
    for (int i = 0; i < m; i++) {
        ll c,d;
        std::cin >> c>>d;
        cd[i] = {c,d};
    }
    
    for (int i = 0; i < n; i++) {
        ll in = -1;
        ll val = 1e16;
        for (int j = 0; j < m; j++) {
            if( abs(ab[i].first - cd[j].first) + abs(ab[i].second - cd[j].second) < val ){
                val = abs(ab[i].first - cd[j].first) + abs(ab[i].second - cd[j].second);
                in = j;
            }
        }
        std::cout << in+1 << std::endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
#define MAXN 1000000007
 
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll k,x;
	cin>>k>>x;
	if ((k+x)>=100001) {
		for (ll i=x-k+1;i<=100000;i++) {
			cout<<i<<' ';
		}
	}
	else {
		if ((x-k)<=-100000) {
			for (ll i=-100000;i<x+k;i++) {
				cout<<i<<' ';
			}
		}
		else {
			for (ll i=x-k+1;i<x+k;i++) {
				cout<<i<<' ';
			}
		}
	}
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{

    	int N;
    	cin>>N;
    	std::set<std::string> str;
    	string str1;
    	for(int i=0;i<N;i++)
    	{
    		cin>>str1;
    		str.insert(str1);
		}
		cout<<str.size();
	}

Measured memory_bytes: 19252
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

pair<Weight, Edges> prim(const Graph &g, int r) {
  int n = g.size();
  Edges T;
  Weight total = 0;

  vector<bool> visited(n);
  priority_queue<Edge> Q;
  REP(i,r)
    Q.push( Edge(-1, i, 0) );
  while (!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (visited[e.dst]) continue;
//    printf("%d->%d, %d\n",e.src,e.dst,e.weight);
    T.push_back(e);
    total += e.weight;
    visited[e.dst] = true;
    FOR(f, g[e.dst]) if (!visited[f->dst]) Q.push(*f);
  }
  return pair<Weight, Edges>(total, T);
}


int main() {
  int n,m;
  while(cin>>n>>m,n||m) {
    Graph g(n+m);
    REP(i,n) {
      REP(j,m) {
        int a;
        cin >> a;
        if (a) {
          g[i].push_back(Edge(i,j+n,a));
          g[j+n].push_back(Edge(j+n,i,a));
        }
      }
    }
    REP(i,m) {
      for (int j=i+1; j<m; ++j) {
        int a;
        cin >> a;
        if (a) {
          g[i+n].push_back(Edge(i+n,j+n,a));
          g[j+n].push_back(Edge(j+n,i+n,a));
        }
      }
    }
    cout << prim(g, n).first << endl;
  }
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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


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

    ll a, b;
    cin >> a >> b;
    
    if(a*b <= 0){
        cout << "Zero" << endl;
    }else if(a > 0){
        cout << "Positive" << endl;
    }else{
        
        if((b-a)%2==0){
            cout << "Negative" << endl;
        }else{
            cout << "Positive" << endl;
        }
    }


    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main (){

  int a=0;
  int b=0;

  scanf("%d %d" ,&a,&b);

  
  if((a+b)%2==0){
  printf("%d",(a+b)/2);
  }
  else{
    printf("IMPOSSIBLE");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
using std::cout ;
using std::endl ;
using std::cin ;
using std::string ;
using std::vector ;
using std::set ;
using std::map ;
using std::pair ;
#define rep(i,n) for(int i=0, i##_end=(n); i<i##_end; i++)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
template<class T>bool updateMax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool updateMin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(c) c.begin(),c.end()
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

int main() {
    string S, T;
    cin >> S >> T;
    
    cout << ((T.size() == S.size() + 1 && std::equal(std::begin(S), std::end(S), std::begin(T))) ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 3596
import numpy as np
from itertools import product

n,*fp = map(int,open(0).read().split())
f = np.array([fp[i*10:(i+1)*10] for i in range(n)])
p = np.array([fp[(n*10+i*11):(n*10+(i+1)*11)] for i in range(n)])

op_list  = np.array(list(product([0,1],repeat=10)))[1:]
op_count = np.dot(op_list,f.T)
ans = p[np.arange(n),op_count].sum(axis=1).max()
print(ans)


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

int main() {
  int N,M,X;
  int s=0,l=0;
  
  cin >> N >> M >> X;

  for(int i=0;i<M;++i){
    int t; cin >> t;
    if(t < X){
      s += 1;
    }else{
      l += 1;
    }
  }

  cout << min(s,l) << endl;
  return 0;
}


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

int32_t main()
{
    int n;
    cin>>n;
    int a[n];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }

    int q;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        int x,y;
        cin>>x>>y;
        x--;
        cout<<sum+y-a[x]<<endl;
    }
}

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MAX_W = 100000;

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

    vi A(n), B(n), T(MAX_W + 1, -1);
    int min_w = MAX_W;

    rep(i, 0, n) {
        cin >> A[i];
        B[i] = A[i];
        min_w = min(min_w, A[i]);
    }

    sort(A.begin(), A.end());

    // Hash table to the original index.
    rep(i, 0, n) {
        T[A[i]] = i;
    }

    // A : dist_index -> val
    // B : orig_index -> val
    // T : val -> dist_index

    vector<bool> seen(n, false);
    int ans = 0;

    rep(i, 0, n) {
        if (seen[i]) { continue; }
        seen[i] = true;

        int v = i;
        int n = 1;
        ans += A[v];

        while (true) {
            int next_v = T[B[v]];

            if (seen[next_v]) { break; }
            seen[next_v] = true;

            ++n;
            ans += A[next_v];

            v = next_v;
        }

        ans += min((n - 2) * A[i], A[i] + (n + 1) * min_w);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3416
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
	    String S = scanner.next();
	    
	    int kotae = 0;
	    
	    for(int i=0; i<=3; i++) {
	    	if(S.substring(i, i+1).equals("+")) {
	    		kotae++;
	    	}else {
	    		kotae--;
	    	}
	    }
	    System.out.println(kotae);

	}

}

Measured memory_bytes: 21712
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] p = new int[N];
        int max = 0;
        int sum = 0;
        for(int i=0; i<N; i++) {
            p[i] = Integer.parseInt(sc.next());
            sum += p[i];
            if(max < p[i]) {
                max = p[i];
            }
        }
        System.out.println(sum-max/2);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(N), b(N);
    vector<int> c(M), d(M);
    for (int i = 0; i < N; i++){
        cin >> a.at(i) >> b.at(i);
    }
    for (int i = 0; i < M; i++){
        cin >> c.at(i) >> d.at(i);
    }
    for (int i = 0; i < N; i++){
        int ans_f = 1000000000;
        int num;
        for (int j = 0; j < M; j++){
            int ans = abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j));
            //cout << i << " " << j << " " << ans << endl;
            if (ans < ans_f){
                num = j + 1;
                ans_f = ans;
            }
        }
        cout << num << endl;
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<bool> dp(n + 10, false);
  if(n < 100) {
    cout << 0 << endl;
    return 0;
  }
  dp[100] = true;
  dp[101] = true;
  dp[102] = true;
  dp[103] = true;
  dp[104] = true;
  dp[105] = true;
  for(int i = 106; i <= n; i++) {
    if(dp[i - 100] || dp[i - 101] || dp[i - 102] || dp[i - 103] ||
       dp[i - 104] || dp[i - 105])
      dp[i] = true;
  }
  if(dp[n])
    cout << 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
string x;
ll n,k=0;
stack <int> a;

int main(){
	cin>>x;
	n=x.size();
	FOR(i,0,n){
		if(x[i]=='S')a.push(1);
		else{
			if(!a.empty()){
				a.pop();
				k+=2;
			}
		}
	}
	cout<<n-k<<endl;
	return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    int n,x,a[110];
    scanf("%d%d",&n,&x);
    int i,sum=0;
    for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            sum=sum+a[i];
        }
        int remains,cont=0;
        if(x>=sum)
        cont=n;
        remains=x-sum;
        int mi=a[0];
        for(i=0;i<n;i++)
        {
           if(a[i]<mi)
                mi=a[i];
        }
 
   cont=cont+remains/mi;
   printf("%d",cont);
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
typedef pair<int,int> p;
typedef pair< p , p > P;
#define d first.first
#define x first.second
#define y second.first
#define dir second.second
#define INF 1000000000
P Make(int a,int b,int c,int e){
  return P( p( a,b) , p( c, e) );   
}

int w,h;
int mp[30][30],dmp[4][30][30],f[4][30][30];
int let[4];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dijkstra(){

  priority_queue <P,vector <P>,greater<P> >Q;
  Q.push(Make(0,0,0,0));
  dmp[0][0][0]=0;
  while(!Q.empty()){
    P t=Q.top(); Q.pop();
    if(t.x==w-1&&t.y==h-1)return t.d;
    f[t.dir][t.y][t.x]=1;
    for(int i=0;i<4;i++){
      int ndir=(t.dir+i)%4;
      int nx=t.x+dx[ndir];
      int ny=t.y+dy[ndir];
      int nd=t.d;
      if(mp[t.y][t.x]!=i)nd+=let[i];
      if(nx<0||w<=nx||ny<0||h<=ny||f[ndir][ny][nx]==1||dmp[ndir][ny][nx]<=nd)continue;
      dmp[ndir][ny][nx]=nd;
      Q.push(Make(nd,nx,ny,ndir));
    }
  }
  return 0;
}

int main(){
  while(1){
    cin>>w>>h;
    if(w==0)break;  
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin>>mp[i][j];
	for(int k=0;k<4;k++)dmp[k][i][j]=INF,f[k][i][j]=0;;
      }
    for(int i=0;i<4;i++)cin>>let[i];
    cout<<dijkstra()<<endl; 
  }
  return 0;
}

Measured memory_bytes: 1344
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d,w,x,z,y;
	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
	if(n%a==0){
		w=n/a;
	}
	else{
		w=n/a+1;
	}
	if(n%c==0){
		x=n/c;
	}
	else{
		x=n/c+1;
	}
	if(w*b<=x*d){
		printf("%d\n",w*b);
	}
	else{
		printf("%d\n",x*d);
	}
	return 0;
}


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

long memo[51][51][2501];
int N, A, x[51];

long func(int i, int num, int sum)
{
    if (i<0 || num<0 || sum<0) return 0;
    if (num==0 && sum==0) return 1;
    auto& res=memo[i][num][sum];
    if (~res) return res;
    return res=func(i-1, num-1, sum-x[i-1])+func(i-1, num, sum);
}

int main()
{
    memset(memo, -1, sizeof(memo));
    cin>>N>>A;
    for(int i=0; i<N; ++i) cin>>x[i];

    long res=0;
    for(int i=1; i<=N; ++i) res+=func(N, i, i*A);
    cout<<res<<endl;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = ll;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int ga,sa,ba;
int gb,sb,bb;

int main(){
    cin>>n;
    cin>>ga>>sa>>ba;
    cin>>gb>>sb>>bb;
    ll m = n;
    // A to B
    REP(g,n+1)REP(s,n+1){
        ll t = n - g*ga - s*sa;
        if(t<0)continue;
        // no bronze
        CHMAX(m, t + g*gb + s*sb);
        // full bronze
        ll b = t / ba;
        t -= b*ba;
        CHMAX(m, t + g*gb + s*sb + b*bb);
    }
    n = m;
    // B to A
    if(n<=5000){
        REP(g,n+1)REP(s,n+1){
            ll t = n - g*gb - s*sb;
            if(t<0)continue;
            // no bronze
            CHMAX(m, t + g*ga + s*sa);
            // full bronze
            ll b = t / bb;
            t -= b*bb;
            CHMAX(m, t + g*ga + s*sa + b*ba);
        }
    }else{
        assert(ga<gb || sa<sb || ba<bb);
        REP(g,n+1){
            ll t = n - g*gb;
            if(t<0)break;
            // no silver/bronze
            CHMAX(m, t + g*ga);
            // full silver
            ll s = t / sb;
            t -= s*sb;
            CHMAX(m, t + g*ga + s*sa);
            t += s*sb;
            // full bronze
            ll b = t / bb;
            t -= b*bb;
            CHMAX(m, t + g*ga + b*ba);
        }
        REP(s,n+1){
            ll t = n - s*sb;
            if(t<0)break;
            // no gold/bronze
            CHMAX(m, t + s*sa);
            // full gold
            ll g = t / gb;
            t -= g*gb;
            CHMAX(m, t + s*sa + g*ga);
            t += g*gb;
            // full bronze
            ll b = t / bb;
            t -= b*bb;
            CHMAX(m, t + s*sa + b*ba);
        }
        REP(b,n+1){
            ll t = n - b*bb;
            if(t<0)break;
            // no silver/bronze
            CHMAX(m, t + b*ba);
            // full gold
            ll g = t / gb;
            t -= g*gb;
            CHMAX(m, t + b*ba + g*ga);
            t += g*gb;
            // full silver
            ll s = t / sb;
            t -= s*sb;
            CHMAX(m, t + b*ba + s*sa);
            t += s*sb;
        }
    }
    printf("%lld\n",m);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ses   "\n"
#define whp   " "
#define mxi 99999
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define PI acos(-1)
#define sz(a) long long(a.size())
#define ff first
#define ss second
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)
///priority_queue <int, vector<int>, greater<int>> g
#define MS(a,b) memset(a,b,sizeof(a));
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll fx[4]= {1,-1,0,0};
ll fy[4]= {0,0,1,-1};

typedef vector<ll> vll;
typedef vector<string> vss;
typedef vector<pair<ll,ll > > vpr;
typedef vector<pair<string,ll > > vspr;
typedef list<ll> li;
typedef list<string> ls;
typedef list<pair<ll,ll> > lpr;
typedef list<pair<string,ll> > lspr;
#define tc() ll t;cin>>t;while(t--)
bool rs(ll a, ll b){return(a>b);}
ll spd(ll n){ if(n%2==0)return 2; for(ll i=3; i*i<=n; i++){if(n%i==0)return i;}return n;}

int main(){
    string s1,s2; cin>>s1;s2=s1; ll len=s1.length(); char c=s1[len-1];
    if(c=='s')s2+="es";
    else s2+="s";
    cout<<s2<<endl;

return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	ll ch[200010],a[200010];
	for(ll i=0;i<n;i++){
		ch[i]=-1;
		ll x;
		cin>>x;
		x--;
		a[i]=x;
	}
	ll now=0;
	ll sa;
	for(ll i=0;i<=k;i++){
		if(ch[now]!=-1){
			sa=i-ch[now];
			sa=(k-i)%sa;
		//	now=a[now];
		//	cout <<sa<<endl;
		//	cout <<now<<endl;
			break;
		}		if(i==k){
			cout <<now+1;
			return 0;
		}
		ch[now]=i;
		now=a[now];

	}
	for(ll i=0;i<sa;i++){
		now=a[now];
	}
	cout <<now+1;
	// your code goes here
	return 0;
}

Measured memory_bytes: 6712
fn main() {
    let chars: Vec<char> = {
        let s = read::<String>();
        s.chars().collect()
    };

    let mut a_mi = chars.len();
    let mut z_ma = 0;
    for (i, c) in chars.iter().enumerate() {
        if *c == 'A' && a_mi > i {
            a_mi = i;
        }
        if *c == 'Z' && z_ma < i {
            z_ma = i;
        }
    }
    println!("{}", z_ma - a_mi + 1);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>

int main() {
  char s[110], p[110];
  scanf("%s %s", s, p);

  char ring[210];
  strcpy(ring, s);
  strcat(ring, s);
  
  if (strstr(ring, p) == NULL) printf("No\n");
  else printf("Yes\n");
  
  return 0;
}


Measured memory_bytes: 2756
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 * 100 + 47;

struct Fenvic
{
	int T[MAX];
	int n;
	void init(int n1)
	{
		n = n1;
		FOR(i, 0, n) T[i] = 0;
	}

	void add(int i, int delta)
	{
		for (; i < n; i = i | (i + 1))
		{
			T[i] += delta;
		}
	}

	int get(int i)
	{
		int res = 0;
		for (; i >= 0; i = (i & (i + 1)) - 1)
		{
			res += T[i];
		}

		return res;
	}

	int get(int l, int r)
	{
		int res = get(r);
		if (l) res -= get(l - 1);
		return res;
	}
} F;

int A[MAX];
int B[MAX];
int C[3][MAX];
int U[MAX];

void no()
{
	cout << "No" << endl;
	exit(0);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, 3)
	{
		FOR(j, 0, n)
		{
			cin >> C[i][j];
			C[i][j]--;
		}
	}

	FOR(j, 0, n)
	{
		if (C[0][j] / 3 != C[1][j] / 3 || C[0][j] / 3 != C[2][j] / 3) no();

		A[j] = C[0][j] / 3;
		if (C[0][j] < C[1][j] && C[1][j] < C[2][j])
		{
			B[j] = 0;
			continue;
		}

		if (C[0][j] > C[1][j] && C[1][j] > C[2][j])
		{
			B[j] = 1;
			continue;
		}

		no();
	}

	FOR(i, 0, n)
	{
		if (i % 2 != A[i] % 2) no();
	}

	int odd = (n - n / 2) & 1;
	int even = (n / 2) & 1;
	FOR(i, 0, n)
	{
		if (!U[i])
		{
			int x = i;
			while (!U[x])
			{
				U[x] = 1;
				x = A[x];
			}

			if (i & 1)
			{
				even ^= 1;
				continue;
			}
			
			odd ^= 1;
		}
	}

	//F.init(n);
	//int odd = 0;
	//for (int i = 0; i < n; i += 2)
	//{
	//	odd ^= F.get(A[i] + 1, n - 1) % 2;
	//	F.add(A[i], 1);
	//}

	//F.init(n);
	//int even = 0;
	//for (int i = 1; i < n; i += 2)
	//{
	//	even ^= F.get(A[i] + 1, n - 1) % 2;
	//	F.add(A[i], 1);
	//}

	FOR(i, 0, n)
	{
		if (i % 2 == 0 && B[i] == 1) even ^= 1;
		if (i % 2 == 1 && B[i] == 1) odd ^= 1;
	}

	if (odd == 0 && even == 0)
	{
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;
}

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

long n;

void CountingSort(long A[], long B[], long k){
	vector<long> C(k + 1); // count 0 to k
	for (long i = 0; i <= k; i++) C[i] = 0; // initialize
	for (long i = 0; i < n; i++) C[A[i]]++; // counting
	for (long i = 1; i <= k; i++) C[i] += C[i - 1];
	for (long i = 0; i < n; i++){
		B[C[A[i]] - 1] = A[i];
		C[A[i]]--;
	}
}

int main(){
	cin >> n;
	long *A, *B;
	A = new long[2000000];
	B = new long[2000000];
	for (long i = 0; i < n; i++) cin >> A[i];
	CountingSort(A, B, 10000);
	delete[] A;
	for (long i = 0; i < n; i++){
		if (i) cout << " ";
		cout << B[i];
	}
	cout << endl;
	delete[] B;
	return 0;
}

Measured memory_bytes: 32468
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=5e5+100;
ll a[N];
ll c[N];
ll b[N];
int32_t main(){
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    for (int i=0;i<s.size();i++){
        a[i]=s[i]-'0';
    }
    ll l=0,r=N*10;
    while(r-l>1){
        memset(c,0,sizeof c);
        memset(b,0,sizeof b);
        ll mid=(r+l)/2;
        ll car=0;
        for (int i=0;i<N;i++){
            c[i]=a[i]*9+car;
            car=c[i]/10;
            c[i]%=10;
        }
        ll k=mid*9;
        ll cnt=0;
        while(k){
            b[cnt]=k%10;
            k/=10;
            cnt++;
        }
        car=0;
        for (int i=0;i<N;i++){
            c[i]+=b[i]+car;
            car=c[i]/10;
            c[i]%=10;
        }
        ll sum=0;
        for (int i=0;i<N;i++) sum+=c[i];
        if (sum<=9*mid) r=mid;
        else l=mid;
    }
    cout << r << endl;
}


Measured memory_bytes: 15580
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

ans = 1
tmpr_distA = abs(A - (T -0.006*H[0]))
for i in range(1,N,1):
    tmptmpr = abs(A - (T-0.006*H[i]))
    if tmptmpr < tmpr_distA:
        tmpr_distA = tmptmpr
        ans = i+1
print(ans)


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

int power(int x, int y) {
  for (int i = 0; i < y - 1; i++) {
    x *= x;
  }
  return x;
}
int main() {
  int n;
  cin >> n;
  
  vector<double> aji(n);
  for (int i = 0; i < n; i++) {
    cin >> aji.at(i);
  }
  
  sort(aji.begin(), aji.end());
  
  double x = aji.at(0);
  
  for (int i = 0; i < n - 1; i++) {
    x = (x + aji.at(i + 1)) / 2;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll cur = 0;
  ll ans = 0;
  bool ok = true;
  rrep(i, N) {
    if(A[i] > cur) {
      ans += A[i];
      cur = A[i];
    } else if(A[i] == cur) {
    } else {
      ok = false;
      break;
    }
    if(i) cur--;
  }
  cout << (ok&&cur==0 ? ans : -1) << "\n";
  return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

void solve(){
	ll n, m;
	cin >> n >> m;
	vector<vector<ll>> roads(n+1);
	vector<ll> heights(n+1);
	for(int i = 1; i <= n; ++i) cin >> heights[i];
	for(int i = 0; i < m; ++i) {
		ll a, b;
		cin >> a >> b;
		roads[a].emplace_back(b);
		roads[b].emplace_back(a);
	}
	
	ll goods = 0;
	for(int i = 1; i <= n; ++i) {
		if(roads[i].empty()) {
			++goods;
			continue;
		}
		int j = 0;
		for(; j < (int)roads[i].size(); ++j) {
			if(heights[roads[i][j]] >= heights[i]) break;
		}
		if(j == (int)roads[i].size()) {
			++goods;
		}
	}
	
	cout << goods;
}

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

	solve();
    
    return 0;
}


Measured memory_bytes: 9768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int S = Integer.parseInt(st.nextToken());
        int cut = 1000000000 + 7;

        int[] dp = new int[S+10];
        dp[0] = 1;

        for(int i = 1; i <= S; i++) {
            for(int j = 0; j < i - 3 + 1; j++) {
                dp[i] += dp[j];
                dp[i] %= cut;
            }
        }
        
        pw.println(dp[S]);
        br.close();
        pw.close();
    }
}

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

using Graph=vector<vector<int>>;
using P=pair<int,int>;
const int INF=1e9;

int main()
{
   int N; cin>>N;
   Graph G(N);
   for(int i=0;i<N-1;i++){
      int a,b; cin>>a>>b;
      a--; b--;
      G[a].push_back(b);
      G[b].push_back(a);
   }
   int K; cin>>K;
   vector<int> num(N,-1);
   for(int i=0;i<K;i++){
      int v,p; cin>>v>>p;
      num[v-1]=p;
   }

   priority_queue<P,vector<P>,greater<P>> Q;
   vector<int> dist(N,INF);
   for(int i=0;i<N;i++) if(num[i]>=0){
      dist[i]=num[i];
      Q.push({dist[i],i});
   }

   vector<bool> finished(N);
   while(!Q.empty()){
      int v=Q.top().second; Q.pop();
      if(finished[v]) continue;
      finished[v]=true;
      for(int u:G[v]){
         if(num[u]<0 and dist[u]>dist[v]+1){
            dist[u]=dist[v]+1;
            Q.push({dist[u],u});
         }
      }
   }

   for(int i=0;i<N;i++){
      for(int j:G[i]) if(abs(dist[i]-dist[j])!=1){
         cout<<"No"<<endl;
         return 0;
      }
   }
   cout<<"Yes"<<endl;
   for(int i=0;i<N;i++) cout<<dist[i]<<endl;
   return 0;
}



Measured memory_bytes: 8308
def gcd(a,b):
    if b < a:
        b,a = a,b
    if a==0:
        return b
    
    return gcd(b%a,a)

def main():
    k = int(input())
    ans = 0
    for i in range(1,k+1):
        for j in range(1,k+1):
            tmp = gcd(i,j)
            for k in range(1,k+1):
                ans += gcd(tmp,k)
    print(ans)
    

if __name__== "__main__":
    main()

Measured memory_bytes: 77184
using System;

class Program
{
  static void Main()
  {
    int i, j;
    int n = int.Parse(Console.ReadLine());

    for (i = 1; i <= n; i++)
    {
      if (i % 3 == 0)
      {
        Console.Write(" {0}", i);
      }
      else
      {
        j = i;
        while (j > 0)
        {
          if (j % 10 == 3)
          {
            Console.Write(" {0}", i);
            break;
          }
          j /= 10;
        }
      }
    }


    Console.WriteLine();
  }
}

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

typedef long long LL;

const int N=50;

int n;
struct point{
  int x,y;
}a[N+9];

bool cmp(const point &a,const point &b){return a.x<b.x||a.x==b.x&&a.y<b.y;}

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i)
	scanf("%d%d",&a[i].x,&a[i].y);
}

int Get_ans(int dx,int dy){
  int res=n;
  for (int i=1;i<=n;++i)
	for (int j=i+1;j<=n;++j)
	  if (a[j].x-a[i].x==dx&&a[j].y-a[i].y==dy) --res;
  return res;
}

int ans;

void Get_ans(){
  ans=n;
  sort(a+1,a+n+1,cmp);
  for (int i=1;i<=n;++i)
	for (int j=i+1;j<=n;++j) ans=min(ans,Get_ans(a[j].x-a[i].x,a[j].y-a[i].y));
}

void work(){
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 3824
from time import time

start = time()
D = int(input())
C = [int(i) for i in input().split()]
scores = [[int(i) for i in input().split()] for j in range(D)]
t = []
for i in scores:
    t.append(i.index(max(i))+1)
DC = [0]*26

def calcScore(t):
    score = []
    S = 0
    last = [0]*26
    for d in range(1,D+1):
        S += scores[d-1][t[d-1]-1]
        last[t[d-1]-1] = d
        for i in range(26):
            S -= C[i] * (d - last[i])
            DC[i] += (d - last[i])
        score.append(S)
    return score[-1]

from random import randint
ts = calcScore(t)
i = 0
while time() - start < 1.95:
    d,q = i, randint(1,26)
    temp = [t[i] if d-1 != i else q for i in range(D)]
    if calcScore(temp) > ts:
        t = temp
        i += 1

print("\n".join(map(str, t)))


Measured memory_bytes: 9968
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	int x = 0, y = 0;

	while (a >= b) x++, b *= 2;
	while (b >= c) y++, c *= 2;

	if (k >= x + y) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main(){
	int n, p[105];
	string s[105];
	cin >> n;
	pair<pair<string, int>, int> pairs[105];
	for(int i = 0; i < n; i++){
		cin >> s[i] >> p[i];
		pairs[i] = make_pair(make_pair(s[i], -p[i]), i);
	}
	sort(pairs, pairs + n);
	for(int i = 0; i < n; i++){
		printf("%d\n", pairs[i].second+1);
	}
}

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

int main(){
  int N, M;
  cin >> N >> M;
  int g[M][2];
  int lb = 1, ub = N;
  int ans;
  for(int i=0; i<M; i++){
    int L, R;
    cin >> L >> R;
    if(R < lb || L > ub){
      ans = 0;
      break;
    } else {
      lb = max(lb, L);
      ub = min(ub, R);
      ans = ub-lb+1;
    }
  }

  cout << ans << endl;

}

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

// # DEFINES # //
#define ll long long
#define M (ll)1e9+7
#define EPS 1e-9

using namespace std;

int gcd(int a, int b) {
    if(b == 0)
        return a;
    else 
        return gcd(b, a % b);
}

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

    int x, y, z;

    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);

    cout << x << " " << y << " "<< z << endl;

    return 0;
}

Measured memory_bytes: 256
mod = 2019
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod
L,R = map(int,input().split())
#LL = L % 2019
#RR = R % 2019

if R-L <= 2019*2:
    g = 9999999999999
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            if i<j:
                g = min(g,mul(i,j))
                if g == 0:
                    break
    print(g)
else:
    print(0)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        sc.close();

        if(X >= 30){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }

    }
}

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

using namespace std;

#define ll long long int
#define L 300001

bool sort_vect(const vector<int> &v1, const vector<int> &v2)
{
	return v1[0] < v2[0];
}

void update(int *tree, int index, int value)
{
	int i,parent,n;
	n = L;
	i = index + n;
	tree[i] = tree[i] + value;

	while(i>0){
		parent = i/2;
		tree[parent] = max(tree[2*parent], tree[2*parent+1]);
		i = parent;
	}
}

//Segment Tree[1] is maximum
void create(int *tree, int *a)
{
	int i,n;
	n=L;
	for(i=n;i<2*n;i++)
		tree[i] = a[i-n];

	for(i=n-1;i>0;i--)
		tree[i] = max(tree[2*i],tree[2*i+1]);
}

// _j in not inclusive
// For complete tree call (0,n)
ll maximum(int *tree, int _i, int _j)
{
	int n;
	n=L;
	int left,right, maxi = -1;
	left = _i + n;
	right = _j + n;

	while(left < right)
	{
		if(left%2==1){
			maxi = max(maxi, tree[left]);
			left = left + 1;
		}

		if(right%2==1)
		{
			right = right - 1;
			//This will make sure you don't go 'Out of Bound'
			maxi = max(maxi, tree[right]);
		}
		left = left/2;
		right = right/2;
	}
	return maxi;
}

int main()
{
	int H, W, M, a, b, i, j,current;
	ll count,temp;
	cin >> H >> W >> M;

	vector<std::vector<int>> v(M, vector<int>(2));
	for(i=0;i<M;i++){
		cin >> a >> b;
		a--;
		b--;
		v[i][0] = a;
		v[i][1] = b;
	}

	sort(v.begin(), v.end(), sort_vect);

	int *c = new int[L];
	for(i=0;i<L;i++){
		c[i] = 0;
	}

	for(i=0;i<M;i++){
		c[v[i][1]]++;
	}
	int *segTree = new int[2*L];
	create(segTree, c);

	count=0;
	i=0;
	current=v[i][0];
	update(segTree, v[i][1], -1);
	i++;
	j=0;
	while(i<M){
		if(v[i][0]==current){
			update(segTree, v[i][1], -1);
		}
		else{
			temp = maximum(segTree,0,L);
			temp = temp + (i-j);
			if(count<temp)
				count = temp;

			//backprop
			for(j=j;j<i;j++){
				update(segTree, v[j][1], 1);
			}

			j=i;
			current=v[i][0];
			update(segTree, v[i][1], -1);
		}
		i++;
	}

	temp = maximum(segTree,0,L);
	temp = temp + (i-j);
	if(count<temp)
		count = temp ;
	
	cout << count << endl;
	return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_W = 100000;
int N,W;
ll dp[2][MAX_W+1];

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> N >> W;

  forn(i,N) {
    int w,v;
    cin >> w >> v;
    forn (j,W+1) {
      chmax(dp[1-(i&1)][j], dp[i&1][j]);
      if (j+w <= W)
        chmax(dp[1-(i&1)][j+w], dp[i&1][j]+v);
    }
  }

  cout << *max_element(dp[N&1],dp[N&1]+W+1) << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int min(int a, int b){return a>b?b:a;}
int dif(short a, int b){return a<b?b-a:a-b;}

short N, j;
int l, i;
short A, B, C, L[8];
int a[4], b[4];
int ans, now;

int main(){
	scanf("%hd%hd%hd%hd", &N, &A, &B, &C);
	for(i=0; i<N; i++){
		scanf("%hd", L+i);
	}
	ans = 2147483647;
	for(i=0, l=(1<<(N<<1)); i<l; i++){
		a[0]=a[1]=a[2]=a[3]=0;
		b[0]=b[1]=b[2]=b[3]=0;
		for(j=0; j<N; j++){
			a[(i>>(j<<1))&3] ++;
			b[(i>>(j<<1))&3] += L[j];
		}
		if(a[0]==0 || a[1]==0 || a[2]==0){continue;}
		now = (a[0]+a[1]+a[2]-3)*10 + dif(A, b[0])+dif(B, b[1])+dif(C, b[2]);
		ans = min(ans, now);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
const int MOD=1e9+7;
using pii=std::pair<int,int>;
using namespace std;

int a, b, c, d;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> a >> b >> c >> d;
    int bdead = (c + b - 1) / b, adead = (a + d - 1) / d;
    if(bdead > adead)
        cout << "No\n";
    else
        cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
//#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;
int main() {
	while (cin >> n, n) {
		vector<pair<int, int>> vp1;
		vector<pair<int, int>> vp2;
		vp1.push_back(pair<int, int>(0, 0));
		vp2.push_back(pair<int, int>(0, 0));
		for (int i = 0; i < n - 1; i++) {
			int a, d; cin >> a >> d;
			if (d == 0) {
				int b, c;
				b = vp1[a].first;
				c = vp1[a].second;
				vp1.push_back(pair<int, int>(b - 1, c));
				vp2.push_back(pair<int, int>(c,b-1));
			}
			else if (d == 1) {
				int b, c;
				b = vp1[a].first;
				c = vp1[a].second;
				vp1.push_back(pair<int, int>(b , c-1));
				vp2.push_back(pair<int, int>(c-1, b));
			}
			else if (d == 2) {
				int b, c;
				b = vp1[a].first;
				c = vp1[a].second;
				vp1.push_back(pair<int, int>(b + 1, c));
				vp2.push_back(pair<int, int>(c, b + 1));
			}
			else {
				int b, c;
				b = vp1[a].first;
				c = vp1[a].second;
				vp1.push_back(pair<int, int>(b , c+1));
				vp2.push_back(pair<int, int>(c+1, b ));
			}
		}
		sort(vp1.begin(), vp1.end());
		sort(vp2.begin(), vp2.end());
		//cout << vp1[0].first <<" "<< vp1[0].second << endl;
		//cout << vp1[n-1].first <<" "<< vp1[n-1].second << endl;
		//cout << vp2[0].first <<" "<< vp2[0].second << endl;
		//cout << vp2[n-1].first <<" "<< vp2[n-1].second << endl;
		cout << vp1[n - 1].first - vp1[0].first + 1 << " ";
		cout << vp2[n - 1].first - vp2[0].fi + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

const ld pi = 3.141592653589793;

#ifdef EBUG
#define debug(x) cout << "\033[31m" << #x << ": " << x << "\033[0m\n";
#else
#define debug(x)
#endif

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

ll h1, m1, h2, m2, k;

int main() {
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  ll time = (h2 * 60 + m2) - (h1 * 60 + m1) - k;
  cout << time << endl;
}

Measured memory_bytes: 3636
N, K = map(int, input().split())
S = []
for _ in range(K):
    S.append(list(map(int, input().split())))
mod = 998244353

dp = [0 for _ in range(2 * N + 1)]
dp[1] = 1

cum = [0 for _ in range(2 * N + 1)]
cum[1] = 1

for i in range(N):
    for l, r in S:
        dp[i + 1] += cum[i - l + 1] - cum[i - r]
        dp[i + 1] %= mod
    cum[i + 1] = cum[i] + dp[i + 1]
    cum[i + 1] %= mod
print(dp[N])


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

int main(){
   int N;
   cin >> N;
   vector<int> a(N);
   for (int i=0; i<N; i++)
      cin >> a.at(i);

   sort(a.begin(), a.end());
   reverse(a.begin(), a.end());
   int A_sum = 0, B_sum = 0;
   for (int i=0; i<N; i++){
      if (i%2 == 0)
         A_sum = A_sum + a.at(i);
      else
         B_sum = B_sum + a.at(i);
   }
   cout << A_sum - B_sum << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	cout << max((ll)0, (b - a) * (n - 2) + 1) << endl;
}

Measured memory_bytes: 256
#define LOCAL

#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

// From Errichto's Youtube stream
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
const int MOD = 1000000007;

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

    int N;
    cin >> N;

    vector<char> is_prime(N + 1, 1);
    for (int i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (int j = 2 * i; j <= N; j += i)
                is_prime[j] = 0;
        }
    }
    vector<int> primes;
    for (int i = 2; i <= N; i++)
        if (is_prime[i])
            primes.push_back(i);

    int result = 1;
    for (auto p : primes) {
        int cnt = 0;
        for (int i = 2; i <= N; i++) {
            auto x = i;
            while (x % p == 0) {
                x /= p;
                cnt++;
            }
        }
        //debug() << p << " " << cnt;
        result = (int64)result * (cnt + 1) % MOD;
    }

    cout << result << "\n";

    return 0;
}


Measured memory_bytes: 256
# AOJ 2816: Alphabet Block
# Python3 2018.7.11 bal4u

dic = {}
S = list(input())
for s in S:
	if s not in dic: dic[s] = 1
	else: dic[s] += 1
ans = 0
for k in list(dic.keys()):
	if dic[k] & 1: ans += 1
print(ans>>1)


Measured memory_bytes: 5572