akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#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()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

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


map<string,map<string,int> > ans;
set<string> app;

main(){
  int n;
  scanf("%d ",&n);
  string in;
  app.insert("ld");
  app.insert("mb");
  app.insert("mp");
  app.insert("nc");
  app.insert("nd");
  app.insert("ng");
  app.insert("nt");
  app.insert("nw");
  app.insert("ps");
  app.insert("qu");
  app.insert("cw");
  app.insert("ts");
  vector<string> order(38);
  rep(i,26)order[i]+=char('a'+i);
  order[26]="ld";
  order[27]="mb";
  order[28]="mp";
  order[29]="nc";
  order[30]="nd";
  order[31]="ng";
  order[32]="nt";
  order[33]="nw";
  order[34]="ps";
  order[35]="qu";
  order[36]="cw";
  order[37]="ts";
  bool db=false;
  while(n--){
    getline(cin,in);
    stringstream ss(in);
    while(ss>>in){
      string be;
      string now;
      if(in.size()==1)continue;
      
      rep(i,in.size()){
        now+=in[i];
	if(now.size()==2){
	  if(app.count(now)){
	    if(be.size()==0){
	      be=now;
	      now="";
	    }else{
	      ans[be][now]++;
	      if(db)cout<<be<<" "<<now<<endl;
	      be=now;
	      now="";
	    }
	  }else{
	    string back;
	    char c=now[0];
	    back+=c;
	    if(be.size()==0)be=back;
	    else{
	      ans[be][back]++;
	      if(db)cout<<be<<" "<<back<<endl;
	      be=back;
	    }
	    now="";
	    now+=in[i];
	    if(i+1==in.size()){
	      ans[be][now]++;
	      if(db)cout<<be<<" "<<now<<endl;
	      be=now;
	      now="";
	    }
	  }
	}else if(now.size()==1 && i+1==in.size()){
	  ans[be][now]++;
	  if(db)cout<<be<<" "<<now<<endl;
	  be=now;
	  now="";
	}
      }
    }
  }
  rep(i,order.size()){
    string tt=order[i];
    int ansnum=0;
    string out="a";
    rep(j,order.size()){
      string kc=order[j];
      if(ans[tt][kc]>ansnum){
	ansnum=ans[tt][kc];
	out=kc;
      }
      if(db)cout<<kc<<" "<<ans[tt][kc]<<" ";
    }
    if(db)cout<<endl;

    cout<<tt<<" "<<out<<" "<<ansnum<<endl;
  }
    
}

Measured memory_bytes: 0
import java.util.Scanner;

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

        String n = sc.nextLine();
        String[] a = n.split("");
        if ((a[0].equals(a[1]) && a[1].equals(a[2])) || (a[1].equals(a[2]) && a[2].equals(a[3])))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

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

using namespace std;

typedef long long ll;

int sumv[505][505],rpos[505][505];
int minn[2][505][505],maxn[2][505][505];

char str[505][505];

int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%s",str[i]+1);
  int cur=0;
  ll ans=0;
  for(int i=n;i>0;i--) {
  	cur^=1;
  	for(int j=n;j>0;j--)
  	  if (str[i][j]!='#') {
  	  	  sumv[i][j]=sumv[i][j+1]+sumv[i+1][j]+str[i][j]-'0';
  	  	  rpos[i][j]=max(max(rpos[i][j+1],rpos[i+1][j]),i);
  	  	  minn[cur][j][i]=j;
  	  	  for(int k=i+1;k<=rpos[i+1][j];k++) minn[cur][j][k]=minn[cur^1][j][k];
  	  	  for(int k=max(rpos[i+1][j],i)+1;k<=rpos[i][j+1];k++) minn[cur][j][k]=minn[cur][j+1][k];
  	  	  maxn[cur][j][i]=j;
  	  	  for(int k=i;k<=rpos[i][j+1];k++) maxn[cur][j][k]=maxn[cur][j+1][k];
  	  	  for(int k=max(rpos[i][j+1],i)+1;k<=rpos[i+1][j];k++) maxn[cur][j][k]=maxn[cur^1][j][k];
  	  	  int d=i+1,r=min(rpos[i][j+1],rpos[i+1][j]);
  	  	  while (d<=r) {
  	  	  	    if (maxn[cur^1][j][d]>=minn[cur][j+1][d]) {
  	  	  	    	    sumv[i][j]-=sumv[d][minn[cur][j+1][d]];
  	  	  	    	    d=rpos[d][minn[cur][j+1][d]];
					  }
  	  	  	    d++;
			  }
		  ans+=(ll)(str[i][j]-'0')*(sumv[i][j]-(str[i][j]-'0'));
		}
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 6400
<?php

	$n = trim(fgets(STDIN));
	$a = explode(" ", trim(fgets(STDIN)));
	$ans = 0;
	for($i=1; $i<$n; $i++){
	    if($a[$i] == $a[$i-1]){
	        $ans++;
	        $i++;
	    }
	}
	echo $ans;
?>

Measured memory_bytes: 4728
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll A[200001];
	vll As;
	scan(N);
	rep(i,N){
		scan(A[i]);
		As.push_back(A[i]);
	}
	sort(rALL(As));
	ll ans=0;
	rep(i,N-1){
		ans+=As[(i+1)/2];
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 6644
use std::collections::HashSet;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

pub fn main() {
    let n: i32 = read();
    let mut s: HashSet<(char,i32)> = HashSet::new();
    for _ in 0..n {
        let v: Vec<String> = read_vec();
        s.insert((
            v[0].chars().next().unwrap(),
            v[1].parse::<i32>().unwrap()));
    }
    for c in &['S', 'H', 'C', 'D' ] {
        for i in 1..14 {
            if s.get(&(*c, i)).is_none() {
                println!("{} {}", *c, i);
            }
        }
    }
}



Measured memory_bytes: 5040
main :: IO()
main = do
  [n] <- map read . words <$> getLine
  print $ slv [1..n] 0
 
slv :: [Integer] -> Integer -> Integer
slv [] cnt = cnt
slv (n:ns) cnt | (10^0 <= n && n < 10^1) || (10^2 <= n && n < 10^3) || (10^4 <= n && n < 10^5) = slv ns (cnt + 1)
               | otherwise = slv ns cnt

Measured memory_bytes: 892
#include<iostream>
using namespace std;
int main(void){
  int n;
  cin>>n;
  int a[n];
  for(int i(0);i<n;i++){
    cin>>a[i];
  }
  int max(a[0]),min(a[0]);
  for(int i(1);i<n;i++){
    if(max<a[i])max=a[i];
    if(min>a[i])min=a[i];
  }
  cout<<max-min<<endl;
  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> >vvi;
const ll MOD=1000000007LL;
int main(){
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  ll ans;
  if(a+b>=2*c){
    if(x>y){
      if(2*c<a)ans=x*2*c;
      else ans=y*2*c+(x-y)*a;
    }
    else{
      swap(x,y);
      swap(a,b);
      if(2*c<a)ans=x*2*c;
      else ans=y*2*c+(x-y)*a;
    }
    cout<<ans<<endl;
    return 0;
  }
  else cout<<x*a+b*y<<endl;
}

Measured memory_bytes: 256
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

typedef long long LL;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }

int main(int argc, char* argv[]) {
	while (true) {
		int len = -1, cnt = 0, miss = 0;
		cin >> len;
		string s;
		cin >> s;
		if (len <= 0) break;
		for (char c : s) {
			if (c == '(') {
				++cnt;
			} else if (cnt <= 0) {
				++miss;
			} else {
				--cnt;
			}
		}
		string ans = string(miss, '(') + s + string(cnt, ')');
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
from collections import deque, namedtuple

class RootedTree:
    def __init__(self, t, n):
        self.t = t
        self.n = n
        self.d = [-1] * n

    def setDepth(self, u, p):
        self.t[u] = self.t[u]._replace(d = p)
        for i in self.getChildren(u):
            self.setDepth(i, p + 1)

    def getChildren(self, u):
        ret = []
        c = self.t[u].l
        while c != -1:
            ret.append(c)
            c = self.t[c].r
        return(ret)

    def printNode(self, i):
        p_ = self.t[i].p
        d_ = self.t[i].d
        c_ = self.getChildren(i)
        if p_ == -1:
            t_ = "root"
        elif len(c_) == 0:
            t_ = "leaf"
        else:
            t_ = "internal node"
        print("node {}: parent = {}, depth = {}, {}, {}".format(i, p_, d_, t_, c_))

if __name__ == '__main__':
    n = int(input().rstrip())
    Node = namedtuple('Node', ['p', 'l', 'r', 'd'])
    t = [Node(-1, -1, -1, -1)] * n
    r = -1
    for i in range(n):
        tmp = deque([int(i) for i in input().rstrip().split(" ")])
        v = tmp.popleft()
        d = tmp.popleft()
        for j in range(d):
            c = tmp.popleft()
            if j == 0:
                t[v] = t[v]._replace(l = c)
            else:
                t[l] = t[l]._replace(r = c)
            l = c
            t[c] = t[c]._replace(p = v)
    for i in range(n):
        if (t[i].p == -1):
            r = i
    x = RootedTree(t, n)
    x.setDepth(r, 0)
    for i in range(n):
        x.printNode(i)
    

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

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)

using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif


std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int a, int b) {
    return uniform_int_distribution<int>(a, b)(rng);
}

ll power(ll x, ll y, ll p){
   ll res = 1;
   x = x % p;
   while (y > 0) {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}

const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll Hashprime = (ll)31;

const int maxn = 100100;

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    int TestCases = 1; // cin >> TestCases;
    while(TestCases--){
       int n,r; cin >> n >> r;
       if(n >= 10){
          cout << r << '\n';
       }else{
          cout << r + (100 * (10 - n)) << '\n';
       }
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =99999999999;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




//10億7。　　　100000007
//2*2行列 H*W
//vector<vector<int>> vec(H,vector<int>(W));
//for(int i=0;i<H;i++){
//for(int j=0;j<W;j++){
//cin>>vec[i][j];
//  }
//}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//ソート　sort(vec.begin(),vec.end());



int main(){
cout<<fixed<<setprecision(10);

  
  int r,g,b;cin>>r>>g>>b;
  if((10*g+b)%4==0){
    cout<<"YES"<<endl;
  }else{
cout<<"NO"<<endl;
  }
  
  
}


Measured memory_bytes: 256
#define __STDC_FORMAT_MACROS
#define p64 PRId64

#include <cinttypes>
#include <cstdio>
#include <string>

using namespace std;
using ll = int64_t;

int main()
{
    ll N, M;
    if (scanf("%" p64 "%" p64, &N, &M) < 2) return 0;

    if (N == 1)
    {
        if (M == 1)
        {
            printf("%" p64 "\n", 1);
        }
        else
        {
            printf("%" p64 "\n", M - 2);
        }
    }
    else
    {
        if (M == 1)
        {
            printf("%" p64 "\n", N - 2);
        }
        else
        {
            printf("%" p64 "\n", (N - 2) * (M - 2));
        }
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define INF (1e18)

int main(){   
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,C;
    cin >> A >> B >> C;
    print(min(C, B/A));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 
 
int main() {
    char c, cn; 
    cin >> c;
    cn = c + 1; 
    cout << cn << endl; 
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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


Measured memory_bytes: 2036
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;

ll a[100010][3]; 
ll dp[100010][3];

int main() {
    int N; 
    cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define US unordered_set
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;

int main(){
  ll N; cin>>N;
  vi E(N); REP(i,N) cin>>E[i];
  if(N==23) {
    UM<ll,ll> cnt;
    for(ll i:E) cnt[i]++;
    cnt[0]++;
    bool flag=false;
    REP(i,12) if(cnt[i]>2) flag=true;
    if(cnt[12]>1) flag=true;
    if(flag) cout<<0<<endl;
    else cout<<1<<endl;
    return 0;
  }
  if(N>=24) {
    cout<<0<<endl;
    return 0;
  }
  ll ans=0;
  E.PB(0);
  N+=1;
  vi v(N);
  REP(i,(1ll<<N)) {
    REP(j,N)
      if(i&(1ll<<j)) v[j]=E[j];
      else v[j]=24-E[j];
    sort(ALL(v));
    ll mi=INF;
    REP(j,N-1) mi=min(mi,v[j+1]-v[j]);
    mi=min(mi,v[0]+24-v[N-1]);
    ans=max(ans,mi);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 100

void trace(int[], int);

int main() {
  
  int i, j, tmp, length;
  int A[N + 1];
  scanf("%d", &length);

  for(i = 0; i < length; i++) {
    scanf("%d", &A[i]);
  }
    trace(A, length);
    for(j = 1; j < length; j++) {
      tmp = A[j];
      i = j - 1;
      while((i >= 0) && (A[i] > tmp)) {
	A[i + 1] = A[i];
	i--;
      }
      A[i + 1] = tmp;
      
      trace(A, length);
    }
    
    return 0;
  }

  void trace(int A[], int length) {
    int i;
    for(i = 0; i < length; i++){
      if(i > 0) {
	printf(" ");
      }
      printf("%d", A[i]);
    }
    printf("\n");
  }

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
 
    ll N, ans = 0;
    cin >> N;
    vector<ll>A(N), B(N);
    for(ll i = 0; i < N; i++)cin >> A[i] >> B[i];
    for(ll i = N - 1; i >= 0; i--){
        ll a = A[i] + ans, b = B[i];
        ll tmp = a % b;
        if(tmp == 0)continue;
        ans += b - tmp;
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++){
        for (int j = 0; j < s.length(); j++){
            if(i > j){
                continue;
            }

            string s1 = s.substr(0, i);
            string s2 = s.substr(j);
            string t = s1 + s2;
            if(t == "keyence"){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    
    int N, K, V[110];
    cin >> N >> K;
    for (int i = 0; i < N; ++i){
        cin >> V[i];
    }
    
    int ans = 0;
    for (int A = 0; A <= min(N, K); ++A){
        for (int B = 0; A+B <= min(N, K); ++B){
            vector<int> v;
            for (int i = 0; i < A; ++i) v.push_back(V[i]);
            for (int i = 0; i < B; ++i) v.push_back(V[N-1-i]);
            sort(v.begin(), v.end());
            
            int CD = K - A - B;
            int sum = 0;
            for (auto _v : v){
                if (_v < 0 && CD > 0) CD--;
                else sum += _v;
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 256
n = int(input())
X = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        x = x-1
        X[i].append((x, y))

ans = 0
for i in range(2**n):
    cnt = 0
    temp = [-1]*n
    for j in range(n):
        if (i >> j) & 1:
            cnt += 1
            temp[j] = 1
        else:
            temp[j] = 0
    flag = True
    for j in range(n):
        if (i >> j) & 1:
            for x, y in X[j]:
                if temp[x] != y:
                    flag = False
    if flag:
        ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 43484
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
lli a, b, c, d;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        if(s == "AC") a++;
        else if(s == "WA") b++;
        else if(s == "TLE") c++;
        else d++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main()
{
	long long n, a[100001], ans = 0, now = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
    a[n] = 1000000001;
	for (int i = n - 2; i >= 0; --i)
	{
		if (a[i] >= a[i + 1])
			++now;
		else
		{
			ans = max(ans, now);
			now = 0;
		}
        ans = max(ans, now);
        //cout << now << ' ';
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
	long n,i,min,max,sum,inp;
    min = 0;
    max = 0;
    sum = 0;
    cin >> n;

    for (i = 0; i<n; i++){
        cin >> inp;
        sum += inp;
        if (min > inp || min == 0){
            min = inp;
        }
        if (max < inp || max == 0){
            max = inp;
        }
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;


}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); i++)

using namespace std;

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

constexpr int INF = 2000000000;

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

    int minimum = INF, ans = -INF;

    rep(i, 0, n) {
        int r;
        cin >> r;

        ans = max(ans, r - minimum);
        minimum = min(minimum, r);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n;
		try(Scanner sc = new Scanner(System.in)) {
			n = sc.nextInt();
		}
//		long sum = (n * (n + 1)) / 2;
		long sum = 0;
		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0 || i % 5 == 0) {
				continue;
			}
			sum += i;
		}
		System.out.println(sum);
	}

}


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

long long cal(long long b0, int n, long long* a, long long ans){

  long long b[n];
  b[0] = b0;
  for(int i=1; i<n; i++){

    b[i] = b[i-1] + a[i];

    if(b[i]==0){
      ans++;
      b[i] = -1 * b[i-1]/abs(b[i-1]);
    }
    if(a[i]*b[i-1]>0 || (abs(a[i])-abs(b[i-1]))<0){
      ans += abs(a[i]+b[i-1])+1;
      b[i] = -1 * b[i-1]/abs(b[i-1]);
    }
  }
  return ans;
}

int main(){

  int n;
  cin >> n;
  long long a[n], ans=0;
  for(int i=0; i<n; i++) cin >> a[i];

  if(a[0]!=0){
    cout << (cal(a[0],n,a,ans)<cal(-a[0]/abs(a[0]),n,a,ans+abs(a[0])+1) ? cal(a[0],n,a,ans): cal(-a[0]/abs(a[0]),n,a,ans+abs(a[0])+1)) << endl;
  }else{
    ans++;
    cout << (cal(1,n,a,ans)<cal(-1,n,a,ans) ? cal(1,n,a,ans) : cal(-1,n,a,ans)) << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

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

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

Measured memory_bytes: 256
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(double);
		void decrement(void);
		void decrement(double);
		double getResult(void);
	private:
		double result;
	};
	void Ans::showResult(void) {
		printf("%.0lf\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(double value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(double value) {
		this->result -= value;
	}
	double AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void input(Str* str) {
		str->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				str->push_back(row);
				row = "";
			} else {
				row += buf[i];
			}
		}
		str->push_back(row);
	}
	void input(Num* num) {
		num->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				num->push_back(std::atoi(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		num->push_back(std::atoi(row.c_str()));
	}
	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::Num s;
	AtCoder::input(&s);

	const int a = s[0], b = s[1];
	const int ans = a - (b * 2);

	if (0 < ans) {
		printf("%d\n", ans);
	} else {
		printf("0\n");
	}

	return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <stdlib.h>
#define N_MAX 100

int main(){
  int top = 0, a[N_MAX];
  char s[1000];
  
  while(scanf("%s", &s) != EOF){
    if(s[0] == '+'){
      a[top - 2] = a[top - 1] + a[top - 2];
      top--;
    }
    else if(s[0] == '-'){
      a[top - 2] = a[top - 2] - a[top - 1];
      top--;
    }
    else if(s[0] == '*'){
      a[top - 2] = a[top - 1] * a[top - 2];
      top--;
    }
    else{
      a[top] = atoi(s);
      top++;
    }
  }
  printf("%d\n", a[top - 1]);
  return 0;
}


Measured memory_bytes: 2108
#include <stdio.h>

int main(void)
{
  int i, j, x;
  int student[30] = {};
  int tmp;

  for (i = 0; i < 28; i++){
    scanf("%d", &tmp);
    student[tmp - 1] = 1;
  }



  for(i = 0; i < 30; i++){
    if (student[i] == 0){
      printf("%d\n", i + 1);
    }
  }
  return (0);
}

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int N;

    scanf("%d", &N);

    if(N <= 1){
        printf("1\n");
    }else if(N <= 3){
        printf("2\n");
    }else if(N <= 7){
        printf("4\n");
    }else if(N <= 15){
        printf("8\n");
    }else if(N <= 31){
        printf("16\n");
    }else if(N <= 63){
        printf("32\n");
    }else{
        printf("64\n");
    }

    return 0;
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}

bool check(string str, int k) {
   int n = SZ(str);
   set<char> s;
   FOR(i, n - k, k) {
      s.insert(str[i]);
      if (SZ(s) == 2) {
         return false;
      }
   }
   return true;
}

int binary_search(string s, int MIN, int MAX)
{
   int m, l = MIN, r = MAX+1;
   while (r - l > 1) {
      m = (l + r) / 2;
      if (check(s, m)) {
         l = m;
      } else {
         r = m;
      }
   }
   return l;
}

signed main()
{
   string S; cin >> S;
   cout << binary_search(S, 1, SZ(S)) << endl;
   return 0;
}


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

int main()
{	

	int n, a, b;
	int final_sum = 0;
	cin >> n >> a >> b;
	
	for(int i=1; i<=n; i++)
	{	
		int samp = i;
		int sum = 0;
		while(samp/10 > 0)
		{	
			int dig = samp%10; 
			//cout << dig << endl;
			samp = samp/10;
			sum += dig;
		}
		
		sum += samp;
		//cout << sum << endl;
		if(sum>=a && sum<=b)
		{
			final_sum += i;
		}
		
	}
	
	cout << final_sum << endl; 
	return 0;
}

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

using namespace std;

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

    int cnt=0;
    for(int i=min(a,b);i>0;i--){
        if(a%i==0 && b%i==0) cnt++;
        if(cnt>=k){
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
def sieve(n):
    p=0
    prime=[0]*n
    is_prime=[0]*(n+1)
    for i in xrange(n+1):
        is_prime[i]=True
    is_prime[0]=is_prime[1]=False
    for i in xrange(2,n+1):
        if is_prime[i]:
            p+=1
            prime[p]=i
            for j in xrange(2*i,n+1,i):
                is_prime[j]=False
    return p
while 1:
    try:
        n=input()
        print(sieve(n))
    except:
        break

Measured memory_bytes: 24456
import java.io.*;
import java.math.BigInteger;

public class Main  implements Runnable {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }

    public void run() {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        n = in.nextInt();
        s = new long[n];
        for (int i = 0; i < n; i++) {
            s[i] = in.nextLong();
        }

        System.out.println(Math.min(apply(-1), apply(1)));
    }

    int n;
    long[] s;
    long apply(long st) {
        long ans = 0;
        long sum = 0;
        long target = st;

        for (int i = 0; i < n; i++) {
            long a = s[i];
            if ((a + sum) * target > 0) sum += a;
            else {
                ans += Math.abs(a + sum - target);
                sum = target;
            }
            target = -Long.signum(sum);
        }
        return ans;
    }
}

class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException {super(System.out);}
}
class ContestScanner implements Closeable {
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}

Measured memory_bytes: 39324
open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let Mod = (1e9|>int64)+7L
[<EntryPoint>]
let main argv =
    let N = R int
    let S = R string
    [0..N-3]
    |>Seq.sumBy(fun c -> if S.[c..(c+2)]="ABC" then 1 else 0)
    |>stdout.WriteLine
    0


Measured memory_bytes: 13396
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++
#define all(x) (x).begin(), (x).end()

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  int ans = 0;
  for (int i = 0; i < N; i++) cin >> h[i];
  if (max_element(all(h)) == min_element(all(h))) {
    cout << *max_element(all(h)) << endl;
    return 0;
  }
  while (1) {
    int l = -1;
    int r = N;
    for (int i = 0; i < N; i++) {
      if (l < 0 && h[i] > 0) l = i;
      if (i > 0 && h[i] <= 0 && h[i - 1] > 0) {
        r = i;
        break;
      }
    }
    if (l < 0) l = 0;
    int hmin = 1000;
    for (int i = l; i < r; i++)
      if (h[i] > 0) hmin = min(hmin, h[i]);

    for (int i = l; i < r; i++) {
      h[i] -= hmin;
    }
    ans += hmin;

    int hmax = *max_element(h.begin(), h.end());
    if (hmax <= 0) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#define L 1000000


int main() {

  int n,S[L],q,T[L];
  int i,num=0;
  int mid;
  int right,left;

  scanf("%d", &n);

  for( i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }

  scanf("%d", &q);

  for (i = 0; i < q; i++) {
    /* code */
    scanf("%d", &T[i]);
  }

  //BainarySearch
  for (i = 0; i < q; i++) {
    /* code */

  left = 0;
  right = n;
//  printf("A\n");
    while (left<right) {
    //  printf("B\n");
      /* code */
      mid=(left+right)/2;
      if(S[mid] == T[i]){
        left=mid;
        right=mid;
       num++;
    }else if(T[i]<S[mid]){
      right=mid;
    }else if(T[i]>S[mid]){
      left=mid+1;
    }
  }
//  printf("C\n");

}
  printf("%d\n", num);



  return 0;
}



Measured memory_bytes: 2300
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>
#include <iomanip>

using namespace std;

using ll = long long;

typedef pair<int, int> P;

#define rep(i,N) for(long long i = 0;i < (long long)N; ++i)

static int mod = 1000000007;
static int large_int = 1000000000;
static ll large_ll = 1000000000000000000;

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

int N, M, C;

int b[20];
int a[20][20];

int ans;

int main() {
	cin >> N >> M >> C;
	rep(i, M) {
		cin >> b[i];
	}
	rep(i, N) {
		int rec = 0;
		rep(j, M) {
			cin >> a[i][j];
			rec += a[i][j] * b[j];
		}
		rec += C;
		if (rec > 0) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    while(1){
        int H,W,h,w;
        scanf("%d %d",&H,&W);
        if(H==0&&W==0){
            break;
        }
        for(h=1;h<=H;h++){
            for(w=1;w<=W;w++){
                if(h!=1&&h!=H&&w!=1&&w!=W){
                    printf(".");
                }
                else{
                    printf("#");
                }
            }
        printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2036
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	char s[1000006];
	scanf("%s", s);
	int q;
	scanf("%d", &q);
	int k[102];
	int i, j;
	for (i = 0; i < q; i++)
		scanf("%d", &k[i]);
	long long int ans;
	long long int d, m, dm;
	for (j = 0; j < q; j++)
	{
		ans = 0;
		d = m = dm = 0;
		for (i = 0; i < k[j]; i++)
		{
			if (s[i] == 'D')
				d++;
			if (s[i] == 'M')
			{
				m++;
				dm += d;
			}
			if (s[i] == 'C')
				ans += dm;
		}
		for (i = k[j]; i < n; i++)
		{
			if (s[i - k[j]] == 'D')
			{
				dm -= m;
				d--;
			}
			if (s[i - k[j]] == 'M')
				m--;
			if (s[i] == 'D')
				d++;
			if (s[i] == 'M')
			{
				m++;
				dm += d;
			}
			if (s[i] == 'C')
				ans += dm;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define INF 2147483647
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define MAX 100005
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

vector<int> v[MAX];

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, a, b, m;

    cin>>n>>m;

    for(int i = 0; i < n; i++){
        cin>>a>>b;
        v[a].pb(b);
    }

    priority_queue<int> pq;
    int res = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 0; j < v[i].size(); j++){
            pq.push(v[i][j]);
        }
        if(pq.size()){
            res += pq.top();
            pq.pop();
        }
    }

    cout<<res<<endl;

    return 0;
}



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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
// ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

int solve(int N, int M, vi& l, vi& r) {
    int lmax = *max_element(ALL(l));
    int rmin = *min_element(ALL(r));
    if (lmax <= rmin) return rmin - lmax + 1;
    else return 0;
}

int main() {
    int N, M; scanf("%d %d%*c", &N, &M);
    vi l(M),r(M);
    rep(i,M) {
        scanf("%d %d%*c", &l[i], &r[i]);
        l[i]--; r[i]--;
    }
    cout << solve(N,M,l,r) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long//
#define rp(i,a,b) for(ll i=a;i<b;i++)
#define r(i,n) for(ll i=0;i<n;i++)
#define rt return
#define db double
#define ldb long double
#define vd void
#define p(x) cout<<(x)<<endl;
#define ce continue;
#define bl bool
#define r0 rt 0;
#define r1 rt 1;
#define elif else if
#define bk break;
#define A p("A")
#define B p("B")
#define C p("C")
#define D p("D")
#define E p("E")
#define F p("F")
#define S(a) sort(a.begin(),a.end());
#define R(a) reverse(a.begin(),a.end());
#define cl cout<<endl;
#define pb(x) push_back(x);
#define str string
using namespace std;
void Cond(int g){if(g)p("YES")else p("NO")rt;}
void cond(int g){if(g)p("Yes")else p("No")rt;}
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)rt b;gcd(b,a%b);}
str su="0123456789";
str m1="abcdefghijklmnopqrstuvwxyz";
str m2="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
map<char,ll>m5;
typedef pair<ll,ll> P;
const ll INF=(ll)1e18+10;
ll t1=0,t2=0,t3=0,t4=0,t5=0,t6=0,t7=0,t8=0,g=0,ans=0;
ll n=0,m=0,k=0,mx=-INF,mn=INF,ct=0;
ll tmp=0,tmp1=0,tmp2=0,tmp3=0,tmp4=0;
ll sum=0,mask=0;
set<P> pst;
set<ll>st,st1,st2;
set<char> cst;
ll powmod(ll a,ll b,ll x){//(a^b)modx
    if(!b)r1
    if(!(b%2)){//B
        ll t=powmod(a,b/2,x);
        rt t*t%x;
    }
    rt ((a)*powmod(a,b-1,x))%x;
}
void di(){m5['a']=0;
    m5['b']=1;
    m5['c']=2;
    m5['d']=3;
    m5['e']=4;
    m5['f']=5;
    m5['g']=6;
    m5['h']=7;
    m5['i']=8;
    m5['j']=9;
    m5['k']=10;
    m5['l']=11;
    m5['m']=12;
    m5['n']=13;
    m5['o']=14;
    m5['p']=15;
    m5['q']=16;
    m5['r']=17;
    m5['s']=18;
    m5['t']=19;
    m5['u']=20;
    m5['v']=21;
    m5['w']=22;
    m5['x']=23;
    m5['y']=24;
    m5['z']=25;
}
map<ll,ll>mp,mp1,mp2,mp3;
typedef std::vector<ll> vl;
typedef pair<ll,ll> P;
typedef pair<ll,P>  P2;
typedef struct edge2{P tos;ll cost;}EDGE2;
typedef struct edge1{ll to,cost;}EDGE;
bl used[(ll)1e9];
const ll M=(ll)1e9+7;
ll fac[1000007],finv[1000007],inv[1000007];
void initcmb(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<1000007;i++){
        fac[i]=fac[i-1]*i%M;
        inv[i]=M-inv[M%i]*(M/i)%M;
        finv[i]=finv[i-1]*inv[i]%M;
    }
}
ll cmb(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%M)%M;
}
db pi=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll MAX=5+(ll)1e5*3;
vl rui(MAX);

   

vector<vector<EDGE>>G(1e6);

int main(){//swap(ary１,ary２)
    //a.erase(a.begin()+5),a.insert(a.begin()+3,tmp)    ios_base::sync_with_stdio(0); cin.tie(0);
clock_t start = clock();//timecalc
di();

str s;
cin>>s;
r(i,3){
	cout<<s[i];
}cl


clock_t end = clock();//
const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;//timecalc
//printf("time %lf[ms]\n", time);//
return 0;
}//main


Measured memory_bytes: 28948
import sys

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


a = read_int()
b = read_int()
if a > b:
    print('GREATER')
if a < b:
    print('LESS')
if a == b:
    print('EQUAL')


Measured memory_bytes: 2940
import java.io.*;
import java.util.*;
import java.util.stream.Stream;
public class Main {
	public static Scanner stdIn = new Scanner(System.in);
	public static void main(String[] args){
		String L1 = stdIn.nextLine();
		String L2 = stdIn.nextLine();
		String[] s1 = L1.split(" ", 0);
		String[] s2 = L2.split(" ", 0);
		int[] i2 = Stream.of(s2).mapToInt(Integer::parseInt).toArray();
		Arrays.sort(i2);
		int r=0;
		for (int i=Integer.parseInt(s1[0]);i>Integer.parseInt(s1[0])-Integer.parseInt(s1[1]);i--){
			 r+=i2[i-1];
		}
		
		System.out.println(r);
	}
}

Measured memory_bytes: 26948
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long x,a,b,c,ans=0;
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++)
        for(int j=0;j<=b;j++)
            for(int k=0;k<=c;k++)
                if(i*500+j*100+k*50==x)
                    ans++;
    cout<<ans<<endl;
    return 0;
}

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

#ifdef HELTHAZAR
#define dout if (true) cout
#else
#define dout if (false) cout
#endif

const int MAXN = 1e5 + 1;

struct edge {
	int next, d;
};
vector<edge> edges[MAXN];
int used[MAXN];
int dis[MAXN];

bool dfs(int v) {
	used[v] = 1;
	for (auto e: edges[v])
		if (!used[e.next]) {
			dis[e.next] = dis[v] + e.d;
			if (!dfs(e.next))
				return false;
		}
		else if (dis[e.next] != dis[v] + e.d)
			return false;
	return true;
}

void solve() {
	int n, m;
	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int l, r, d;
		cin >> l >> r >> d;
		edges[l].push_back({r, d});
		edges[r].push_back({l, -d});
	}

	for (int i = 1; i <= n; i++)
		if (!used[i] && !dfs(i)) {
			cout << "No" << endl;
			return;
		}

	cout << "Yes" << endl;
}

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

	solve();
}


Measured memory_bytes: 11520