akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

#define nl '\n'

#define PI 3.14159265

using namespace std;

int a, b, c, d, e, k;

int main(){
    vector<int> v;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a > k){
        cout << ":(";
    } else{
        cout << "Yay!";
    }



}

//g++ -std=c++14 comp.cpp -o b; ./b.exe


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

const int maxn = 3005;

int R, C, k, r, c, v, dp[maxn][maxn][4], val[maxn][maxn];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> R >> C >> k;
    for(int i = 0; i < k; i++)
    {
        cin >> r >> c >> v;
        r--; c--;
        val[r][c] = v;
    }
    for(int i = 0; i < R; i++)
        for(int j = 0; j < C; j++)
            for(int k = 0; k < 4; k++)
            {
                dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
                dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
                if(k < 3)
                {
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k] + val[i][j]);
                    dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1], dp[i][j][k] + val[i][j]);
                }
            }
    int ans = 0;
    for(int k = 0; k < 4; k++)
        ans = max(ans, max(dp[R][C - 1][k], dp[R - 1][C][k]));
    cout << ans << "\n";
    return 0;
}

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

void solver() {
  string s;
  cin >> s;

  if (s[2] == s[3] and s[4] == s[5]) cout << "Yes" << "\n";
  else cout << "No\n";
  return;
}

int main() {
  solver();
  return 0;
}


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


def make_divisors(n):
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


ans = len(tuple(make_divisors(N - 1))) - 1

it = make_divisors(N)
next(it)

for k in it:
    tmp = N
    while not tmp % k:
        tmp //= k
    if tmp % k == 1:
        ans += 1
print(ans)


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


#define ALL(a) 		(a.begin() , a.end())
#define ll 			long long int
#define ff          first
#define ss          second
#define pb          push_back
#define ar 			array
#define mp 			make_pair
#define f(i,a,b)   	for(ll i =a;i<=b;i++)
#define inf 		INT_MAX
#define pll 		pair<ll,ll>
#define mat 		vector<vector<ll>>


#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 {
#ifndef ONLINE_JUDGE
~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__) << "] "
 //debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }


 

const ll INF = 1e18;
void init(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE 
		freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
}
 
bool checkp2(ll n){
	return n && !(n & (n-1));
}

ll numsetbit(ll n){
	ll count = 0;
	for(;n;count++){
		n = n & (n-1);
	}
	return count;
}
 
ll powe(ll x , ll n ,const ll mod){
    x = x % mod;
	ll po = 1;
	while(n){
		if(n & 1){
			po = (po*x) % mod;
		}
		n = n>>1;
		x = ((x % mod) * (x % mod)) % mod;
	}
	return po;
}

ll powm(ll x , ll n){
	ll po = 1;
	while(n){
		if(n & 1){
			po = (po*x);
		}
		n = n>>1;
		x = (x*x);
	}
	return po;
} 



bool isPrime(ll x){
	if(x < 2)
		return 0;
	for(ll y = 2; y * y <= x; y++){
		if(x % y == 0){
			return 0;
		}
	}
	return true;
}
const ll mod = 1e9 + 7;
void solve(){

		ll N;
		cin>>N;

		ll ans1 = powe(10 , N , mod);
		ll ans2 = powe(9 , N , mod);
		ll ans3 = ans2;
		ll ans4 = powe(8 , N , mod);

		ll ans = ans1 + ans4 - ans2 - ans3;
		ans %= mod;
		ans += mod;
		ans %= mod;
		cout<<ans<<endl;
}

int main(){
	
	//init();
	ll t = 1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>

long long kk;

void dfs(int digit, long long current, int lastNum, int lastPow, int &order)
{
    if(lastPow == 0)
    {
        order++;
        if(order == kk)
        {
            std::cout << current;
        }
        return;
    }
    
    // 前
    if(lastNum != 0)
    {
        int myPow = lastPow - 1;
        int myDigit = lastNum - 1;
        long long myCurrent = current + std::pow(10, myPow) * myDigit;
        dfs(digit, myCurrent, myDigit, myPow, order);
    }
    // 今
    {
        int myPow = lastPow - 1;
        int myDigit = lastNum;
        long long myCurrent = current + std::pow(10, myPow) * myDigit;
        dfs(digit, myCurrent, myDigit, myPow, order);
    }
    // 後ろ
    if(lastNum != 9)
    {
        int myPow = lastPow - 1;
        int myDigit = lastNum + 1;
        long long myCurrent = current + std::pow(10, myPow) * myDigit;
        dfs(digit, myCurrent, myDigit, myPow, order);
    }
}

int c()
{
    std::cin >> kk;

    int order = 0;
    for(int i = 0; i < 10; i++) //桁数
    {
        for(int k = 1; k < 10; k++) //スタートの数字
        {
            long long startNum = std::pow(10, i) * k;
            dfs(i, startNum, k, i, order);
        }
    }
    
    return 0;
}

int main(int argc, const char * argv[])
{
    c();
    return 0;
}

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, A: int):
    if (N % 500) <= A:
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    solve(N, A)


if __name__ == '__main__':
    main()


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

#define int long long
#define ld long double
#define ll long long
#define vll vector<int>
#define mset(a) memset(a,0,sizeof(a))
#define pb push_back
#define range(c) c.begin() , c.end()
#define forn(i,n) for(ll i=0; i<(int)n; ++i)
#define for1(i,n) for(ll i=1; i<(int)n; ++i)
#define endl '\n'
#define MOD 1000000007
#define pii pair<int,int>
#define test ll t;cin>>t;while(t--)
using namespace std;

vector<bool> sieve(ll n){
    vector<bool>prime(n+1,true);
    prime[0]=prime[1]=false;
    for(ll i=2; i<=n; ++i){
        if(prime[i]&&(i*i)<=n)
        for(ll j=i*i; j<=n; j+=i)prime[j]=false;
    }
    return prime;
}

ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

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

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

    

    int n;cin>>n;
    int res = 1;
    int cur = n;

    while(cur%360 != 0) {
        cur+=n;
        res++;
    }    

    cout<<res<<endl;

    return 0;
}


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

int main(){
  while(true){
    int a,b;
    cin >> a >> b;
    if(a == 0 && b == 0)
      break;
    else
    if(a < b)
      cout << a << " " << b << endl;
    else
      cout << b << " " << a << endl;
  }
  return 0;
}



Measured memory_bytes: 3012
#include <iostream>

int main()
{
  std::string s;
  std::cin >> s;

  int pos_a = 0;
  int pos_z = s.size() - 1;
  while(s[pos_a] != 'A') {
    pos_a++;
  }
  while(s[pos_z] != 'Z') {
    pos_z--;
  }

  std::cout << pos_z - pos_a + 1 << std::endl;

  return 0;
}


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

int main()
{
  while(true)
  {
    cout<<fixed<<setprecision(20);
    int n=0;
    cin>>n;
    if(n==0) return 0;
    vector<double> s(n);
    double m=0;
    for(auto&& e: s) 
    {
      cin>>e;
      m+=e;
    }
    m/=n;
    cout<<sqrt(accumulate(s.begin(), s.end(),0.0,[&](double init,double a){
      return init+(a-m)*(a-m)/n;
    }))<<endl;
  }
}


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

int main(){
    int owan;
    int n;
    int p;
    int turn;

    while(cin >> n >> p, n != 0 && p != 0){
        turn = 0;
        vector<int> hand(n);

        for(int i=0; i<n; i++){
            hand[i] = 0;
        }

        owan = p;

        for(int i=0; i<1000000; i++){
            if(owan != 0){
                owan--;
                hand[turn]++;
            }else if(owan == 0){
                owan = hand[turn];
                hand[turn] = 0;
            }

            if(hand[turn] == p){
                break;
            }

            turn++;

            if(turn == n){
                turn = 0;
            }
        }

        cout << turn << endl;
    }
    return 0;
}

Measured memory_bytes: 908
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<list>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
int main(){
    char A[3];
    cin >> A;
    if(A[1] == 'R'){
        cout << "ABC" << endl;
    }
    else
    {
        cout << "ARC" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  ulint n, k, a;
  cin >> n >> k;
  if(n >= k){
    a = n % k;
    a = min(a, k-a);
  }
  else{
    a = min(n, k-n);
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(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 printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n; string s; cin >> n >> s;

	ll cnt[26]; memset(cnt, 0, sizeof(cnt));
	zep(i, 0, n){
		cnt[s[i]-'a']++;
	}

	ll dnt[26]; memset(dnt, 0, sizeof(dnt));
	ll ans = 0;
	zep(i, 0, n){
		dnt[s[i]-'a']++;

		ll buf = 0;
		zep(j, 0, 26){
			if(dnt[j] > 0 && cnt[j]-dnt[j] > 0){
				buf++;
			}
		}
		ans = max(ans, buf);
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h,w;
vector<string> s;
int dp[55][55][55][55];
bool used[55][55][55][55];
bool mv[55][55][55][55];
bool oc[55][55];
vector<int> cy[2][30],cx[2][30];
typedef pair<int,int> P;
void calc(){
  memset(mv,0,sizeof(mv));
  int ax[]={1,0};
  int ay[]={0,1};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#') continue;
      queue<P> q;
      q.push(P(i,j));
      mv[i][j][i][j]=1;
      while(!q.empty()){
	P p=q.front();q.pop();
	int y=p.first,x=p.second;
	for(int k=0;k<2;k++){
	  int ny=y+ay[k],nx=x+ax[k];
	  if(ny>=h||nx>=w) continue;
	  if(s[ny][nx]=='#') continue;
	  if(mv[i][j][ny][nx]) continue;
	  q.push(P(ny,nx));
	  mv[i][j][ny][nx]=1;
	}
      }
    }
  }
}
int in(int sy,int sx,int ty,int tx,int y,int x){
  return sy<=y&&y<=ty&&sx<=x&&x<=tx;
}
int dfs(int sy,int sx,int ty,int tx){
  //cout<<sy<<" "<<sx<<" "<<ty<<" "<<tx<<endl;
  if(used[sy][sx][ty][tx]) return dp[sy][sx][ty][tx];
  if(!mv[sy][sx][ty][tx]) return dp[sy][sx][ty][tx]=-1;
  //if(sy==ty&&sx==tx) return dp[c][sy][sx][ty][tx]=0;
  int res=0;
  for(int k=0;k<26;k++){
    for(int i=0;i<(int)cy[0][k].size();i++){
      if(oc[cy[0][k][i]][cx[0][k][i]]) continue;
      for(int j=0;j<(int)cy[1][k].size();j++){
	if(oc[cy[1][k][j]][cx[1][k][j]]) continue;
	if(!in(sy,sx,ty,tx,cy[0][k][i],cx[0][k][i])) continue;
	if(!in(sy,sx,ty,tx,cy[1][k][j],cx[1][k][j])) continue;
	if(!mv[sy][sx][cy[0][k][i]][cx[0][k][i]]) continue;
	if(!mv[cy[0][k][i]][cx[0][k][i]][cy[1][k][j]][cx[1][k][j]]) continue;
	if(!mv[cy[1][k][j]][cx[1][k][j]][ty][tx]) continue;
	oc[cy[0][k][i]][cx[0][k][i]]=1;
	oc[cy[1][k][j]][cx[1][k][j]]=1;
	//cout<<k<<endl;
	int tmp=0,cur;
	cur=dfs(sy,sx,cy[0][k][i],cx[0][k][i]);
	if(cur<0){
	  oc[cy[0][k][i]][cx[0][k][i]]=0;
	  oc[cy[1][k][j]][cx[1][k][j]]=0;
	  continue;
	}
	tmp+=cur;
	cur=dfs(cy[0][k][i],cx[0][k][i],cy[1][k][j],cx[1][k][j]);
	if(cur<0){
	  oc[cy[0][k][i]][cx[0][k][i]]=0;
	  oc[cy[1][k][j]][cx[1][k][j]]=0;
	  continue;
	}
	tmp+=cur;
	cur=dfs(cy[1][k][j],cx[1][k][j],ty,tx);
	if(cur<0){
	  oc[cy[0][k][i]][cx[0][k][i]]=0;
	  oc[cy[1][k][j]][cx[1][k][j]]=0;
	  continue;
	}
	tmp+=cur;
	res=max(res,tmp+1);
	oc[cy[0][k][i]][cx[0][k][i]]=0;
	oc[cy[1][k][j]][cx[1][k][j]]=0;
	//cout<<":"<<res<<endl;
      }
    }
  }
  //cout<<res<<endl;
  //if(sy==ty&&sx==tx&&res) cout<<sy<<" "<<sx<<endl;
  used[sy][sx][ty][tx]=1;
  return dp[sy][sx][ty][tx]=res;
}
signed main(){
  while(cin>>h>>w,h){
    s.clear();
    s.resize(h);
    for(int i=0;i<h;i++) cin>>s[i];
    memset(dp,-1,sizeof(dp));
    memset(used,0,sizeof(used));
    for(int i=0;i<26;i++){
      cy[0][i].clear();
      cy[1][i].clear();
      cx[0][i].clear();
      cx[1][i].clear();
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(islower(s[i][j])){
	  cy[0][s[i][j]-'a'].push_back(i);
	  cx[0][s[i][j]-'a'].push_back(j);
	}
	if(isupper(s[i][j])){
	  cy[1][s[i][j]-'A'].push_back(i);
	  cx[1][s[i][j]-'A'].push_back(j);
	}
      }
    }
    calc();
    memset(oc,0,sizeof(oc));
    cout<<dfs(0,0,h-1,w-1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 56744
#include <iostream>
#include <string.h>
#include <vector>

using namespace std;

int main(){
    
    int n;
    cin >> n;
    vector<string> W(110);
    int i;
    for(i=0; i<n; ++i){
        cin >> W[i];
        //cout << W[i] << "\n";
    }
    
    bool flow = true;
    for(i=1; i<n; ++i){
        //cout << W[i].front() << W[i-1].back() << endl;
        if( W[i].front() != W[i-1].back() ){
            flow = false;
        }
    }
    
    bool same = true;
    for(i=0; i<n; ++i){
       for(int j=i+1; j<n; ++j){
           if( W[i] == W[j] ) same = false;
       } 
    }
    
    if( same && flow ) cout << "Yes";
    else cout << "No";
    
    
    
    return 0;
}

Measured memory_bytes: 256
def main():
    from collections import Counter

    n, k, *a = map(int, open(0).read().split())
    c = Counter(a).values()
    v = len(c) - k
    l = list(c)
    l.sort()
    ans = sum(l[:v])
    print(ans)


if __name__ == '__main__':
    main()


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

#define rep(i,n) for( (i)=0;(i)<(n);++(i) )
#define repr(i,n) for( (i)=(n);(i)>0;==(i) )
#define FOR(i,j,n) for( (i)=(j);(i)<(n);++(i) )
#define forr(i,j,n) for( (i)=(j);(i)>(n);--(i) )
#define debg(a) cout<<(a)<<endl;
#define INF 9999999
#define int long long 
#define str string
#define elif else if

int i,j,k;
int dx,dy;
int a,b,c,x,y,n,m,cnt=0,ans=0;
str s,t;

signed main(){ 
  int w,h;
  cin>>w>>h>>n;
  int x[n],y[n],a[n];
  rep(i,n)cin>>x[i]>>y[i]>>a[i];
  int xs=0,ys=0,xe=w,ye=h;
  rep(i,n){
    if(a[i]==1&&xs<x[i])xs=x[i];
    elif(a[i]==2&&xe>x[i])xe=x[i];
    elif(a[i]==3&&ys<y[i])ys=y[i];
    elif(a[i]==4&&ye>y[i])ye=y[i];
    //debg(xs);debg(xe);debg(ys);debg(ye);
  }
  
  int sq;
  if(xe<=xs||ye<=ys)sq=0;
  else sq=(xe-xs)*(ye-ys);
  cout<<sq<<endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    a = LI()
    if n == 3:
        print(max(a))
        return
    dp = [[-inf] * 3 for i in range(n + 1)]
    dp[0] = [0, 0, 0]
    dp[1][0] = a[0]
    dp[2][1] = a[1]
    for i in range(3, n+1):
        dp[i][0] = dp[i - 2][0] + a[i-1]
        dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + a[i-1]
        dp[i][2] = max(dp[i - 2][2], dp[i - 3][1], dp[i - 4][0]) + a[i-1]
    if n & 1:
        print(max(dp[-3][0], dp[-1][1], dp[-1][2]))
    else:
        print(max(dp[-1][1], dp[-2][0]))
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 137228
n,m,k=map(int,input().split())
flag=False
if n==1 or m==1:
  print('Yes')
else:
  for i in range(n+1):
    for j in range(m+1):
      if i*j + (n-i)*(m-j) + k == n*m:
        flag=True
  if flag:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 2940
N = int(input())
A = [int(n) for n in input().split()]

from fractions import gcd
L = [0]*(N+1)
R = [0]*(N+1)
ans = 0
for i in range(N):
    L[i] = gcd(L[i-1],A[i])
for i in reversed(range(N)):
    R[i] = gcd(R[i+1],A[i])
for i in range(N):
    if gcd(L[i-1],R[i+1]) > ans:
        ans = gcd(L[i-1],R[i+1])
print(ans)

Measured memory_bytes: 14052
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

struct WeightedUnionFind
{
  vector<int> uni, dw;

  explicit WeightedUnionFind(int n): uni(n+5, -1), dw(n+5, 0) {}

  int   size(int x)         { return -uni[root(x)]; }
  int   weight(int x)       { return root(x), dw[x]; }
  int   diff(int x, int y)  { return weight(y) - weight(x); }
  bool  same(int x, int y)  { return root(x) == root(y); }

  int root(int x) {
    if (uni[x] < 0) { return x; }
    int r = root(uni[x]);
    return dw[x] += dw[uni[x]],  uni[x] = r;
  }

  int unite(int x, int y, int w) {
    w += weight(x) - weight(y);
    x = root(x); y = root(y);
    if (x == y) { return false; }
    if (uni[y] < uni[x]) swap(x,y), w = -w;
    uni[x] += uni[y]; uni[y] = x; dw[y] = w;
    return true;
  }
};

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

  int N, M;
  bool ok = true;
  cin >> N >> M;

  WeightedUnionFind wuf(N);

  for (int i= 0; i < M; ++i) {
    int l, r, d;
    cin >> l >> r >> d;
    if ( !wuf.unite(l, r, d) && wuf.diff(l,r) != d ) {
      ok = false;
      break;
    }
  }

  cout << (ok? "Yes" : "No") << endl;


  return 0;
}



Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
using namespace std;
//________
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__ )
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define Size 1000111
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define NIL -1
//________


signed main()
{
   FAST();
   int N, Y;
   cin >> N >> Y;
   Y /= 1000;
   if(Y < N){
      cout << -1 << ' ' << -1 << ' ' << -1 << endl;
      return(0);
   }

   int x, y, z = N;
   for(x=0; x <= N; ++x){
      for(y = 0; y <= N-x; ++y){
         z = N - x - y;
         if(x*10 + y*5 + z == Y){
            cout << x << ' ' << y << ' ' << z << endl;
            return(0);
         }
      }
   }
   cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
bool vis[200005];
vll adj[200005];
ll col[200005], nwc[200005];
void dfs(ll u, ll c){
	if (vis[u]) return; vis[u] = 1; col[u] = c;
	for (ll i = 0; i < adj[u].size(); i++) dfs(adj[u][i], c);
}
int main(){
	ll n, m; cin >> n >> m;
	for (ll i = 0; i < m; i++){
		ll u, v; cin >> u >> v; u--; v--;
		adj[u].pb(v); adj[v].pb(u);
	}
	ll cc = 0;
	for (ll i = 0; i < n; i++){
		if (!vis[i]){
			dfs(i, cc); cc++;
		}
	}
	for (ll i = 0; i < n; i++) nwc[col[i]]++;
	ll ans = 0; for (ll i = 0; i < cc; i++) ans = max(ans, nwc[i]);
	cout << ans << endl;
}

Measured memory_bytes: 25600
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	int n,m;
	cin>>n>>m;
	m/=1000;
	int a=m-n;int b=10*n-m;
	for(int y=0;y<=n;y++)	
	{
		if((a-4*y)<0 or (b-5*y)<0)
			continue;
		if((a-4*y)%9 or (b-5*y)%9)continue;
		int x=(a-4*y)/9;int z=(b-5*y)/9;
		if((x+y+z)==n and (10*x+5*y+z)==m)
		{
			cout<<x<<" "<<y<<" "<<z<<"\n";
			return 0;
		}
	}

	puts("-1 -1 -1");




	

}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
    string s, t;
    cin >> s >> t;
    sort(ALL(s));
    sort(ALL(t));
    reverse(ALL(t));
    if (s < t) { //sをできるだけ小さく、tをできるだけ大きく
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;

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

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

  set<int> treat;
  int d;
  int tmp;

  rep(i, K){
    cin >> d;
    rep(j, d){
      cin >> tmp;
      treat.insert(tmp);
    }
  }

  int cnt=0;
  for(int i = 1; i < N+1; i++){
    if(!treat.count(i)) cnt++;
  }

  cout << cnt << endl;

}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

int main(){

    int A, B, C;
    cin >> A >> B >> C;

    int ans = 0;

    if (B >= C){
        ans = B + C;
    }else{
        if ((A + B) >= C){
            ans = B + C;
        }else{
            ans = A + 2 * B + 1;
        }
    }
    
    cout << ans << endl;

    return 0;
}

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

int main() {
int n;
cin >> n;
int cnt = 0;
for(int i = 1; i <= n; i++){
  string s = to_string(i);
  if(s.size()%2 != 0) cnt++;
  
}

cout << cnt << endl;
}
  


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(i,array) for(auto& x:array)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

ll n;
vector<ll> usetime(5);

int main(){
    cin>>n;
    rep(i,5)cin>>usetime[i];
    sort(all(usetime));
    ll ans=ceil((double)n/usetime[0])-1+5;
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  for(long i = -1024; i <= 1024; i++){
    for(long j = -1024; j <= 1024; j++){
      if(i * i * i * i * i - j * j * j * j * j == N){
        cout << i << ' ' << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3600
n = int(input())
list = [list(map(int, input().split())) for i in range(n)]
section = [[[0]*10, [0]*10, [0]*10], [[0]*10, [0]*10, [0]*10], [[0]*10, [0]*10, [0]*10], [[0]*10, [0]*10, [0]*10]]
for i in range(n) :
	sec_num = list[i][0]
	floor = list[i][1]
	room_num = list[i][2]
	person = list[i][3]
	#下の式の左辺の3つ目の括弧がだめ
	section[sec_num-1][floor-1][room_num-1] += person

for i in range(3) :
	for j in range(10) :
		print(" ", end="")
		print(section[0][i][j], end="")
		if j == 9 :
			print("")
print("#"*20)

for i in range(3) :
	for j in range(10) :
		print(" ", end="")
		print(section[1][i][j], end="")
		if j == 9 :
			print("")
print("#"*20)

for i in range(3) :
	for j in range(10) :
		print(" ", end="")
		print(section[2][i][j], end="")
		if j == 9 :
			print("")
print("#"*20)

for i in range(3) :
	for j in range(10) :
		print(" ", end="")
		print(section[3][i][j], end="")
		if j == 9 :
			print("")



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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int mod = 998244353;

int32_t main()
{   fastio;

    int a , b;
    cin>>a>>b;

    int arr[1000];
    int cnt=1;
    arr[0]=0;
    map<int , int>mp;
    for(int i=1; i <= 999; i++)
    {
        arr[i]=cnt+arr[i-1];
        cnt++;
        mp[arr[i]]=i;
    }

    for(int i=0; i <= 499500; i++)
    {
        if(mp.find(a+i) != mp.end() && mp.find(b+i) != mp.end())
        {
            if(mp[a+i]+1 == mp[b+i]) {
                cout<<i<<endl;
                return 0;
            }
        }
    }

}


Measured memory_bytes: 3724
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    int N, ans = 0;
    cin >> N;
    vector<int>memo(N+1,0);
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        if (A > N) { ans++; continue; }
        memo[A]++;
    }

    for (int i = 1; i <= N; i++) {
        if (i < memo[i])ans += memo[i] - i;
        else if (memo[i] < i)ans += memo[i];
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    vector<long long> luca;
    luca.push_back(2);
    luca.push_back(1);

    for(int i=2; i<87; i++) luca.push_back(luca.at(i-1)+luca.at(i-2));
    int N;
    cin>>N;
    cout<<luca.at(N);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
int n, b[200005], dp[200005], cnt, M[200005 << 2], q, x, y;
std::vector<int> v[200005];
void modify(int cur, int l, int r, int pos, int num) {
	M[cur] = std::min(M[cur], num);
	if (l == r) return;
	int mid = l + r >> 1;
	if (pos <= mid) modify(cur << 1, l, mid, pos, num);
	else modify(cur << 1 | 1, mid + 1, r, pos, num);
}
int query(int cur, int l, int r, int L, int R) {
	if (L <= l && R >= r) return M[cur];
	int mid = l + r >> 1, ans = 0x3f3f3f3f;
	if (L <= mid) ans = std::min(ans, query(cur << 1, l, mid, L, R));
	if (R > mid) ans = std::min(ans, query(cur << 1 | 1, mid + 1, r, L, R));
	return ans;
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]), cnt += b[i] == 0;
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) scanf("%d%d", &x, &y), v[x].push_back(y);
	memset(M, 0x3f, sizeof M); memset(dp, 0x3f, sizeof dp);
	dp[0] = 0; modify(1, 0, n, 0, 0);
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < v[i].size(); j++) 
			modify(1, 0, n, v[i][j], dp[v[i][j]] = std::min(dp[v[i][j]], query(1, 0, n, i - 1, v[i][j])));
		modify(1, 0, n, i, dp[i] = std::min(dp[i], dp[i - 1] + (b[i] ? 1 : -1)));
	}
	printf("%d\n", dp[n] + cnt);
	return 0;
}

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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  int cnt = 1;
  bool can = false;
  for(int i = 0; i < n; i++){
  	cin >> a[i];
  	if(a[i]==cnt){
    	can = true;
    	cnt++;
    }
  }
  
  if(can) cout << n-cnt+1 << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int nakayoshi[10001][10001];
int main() {
  int n;
  cin >> n;
  int ans = 0;
  vi a(n);
  rep(i,n){
    int tmp;
    cin >> tmp;
    tmp--;
    a[i] = tmp;
  }
  rep(i,n){
    if(a[a[i]] == i) ans++;
  }
  cout<<ans/2<<endl;
  return 0;
}

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_cs(i, l, n) for (int i = (l); i <= n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;
Graph G;
vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

ll dp[100100];
ll v[110];
ll w[110];

int main()
{
    ll N; cin >> N;
    ll c[N];
    rep(i, 0, N) cin >> c[i];
    rep(i, 0, 100100) dp[i] = INF;

    dp[0] = 0;

    rep(i, 0, N)
    {
        chmin(dp[i + 1], dp[i] + abs(c[i] - c[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(c[i] - c[i + 2]));
    }

    cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1792
local function getxor(x, y)
  local ret = 0
  local mul = 1
  while 0 < x or 0 < y do
    if (x % 2) + (y % 2) == 1 then
      ret = ret + mul
    end
    x, y, mul = x // 2, y // 2, mul * 2
  end
  return ret
end

local n = io.read("*n")
local a = {}
local allzero = true
local t = {}
local tcnt = 0
for i = 1, n do
  a[i] = io.read("*n")
  if a[i] ~= 0 then allzero = false end
  if t[a[i]] then
    t[a[i]] = t[a[i]] + 1
  else
    if tcnt < 3 then
      tcnt = tcnt + 1
      t[a[i]] = 1
    else
      tcnt = 4
    end
  end
end
if allzero then
  print("Yes")
elseif n % 3 ~= 0 then
  print("No")
elseif tcnt == 3 then
  local f = true
  local g = {}
  for k, v in pairs(t) do
    if v ~= n // 3 then f = false end
    table.insert(g, k)
  end
  if f then
    f = getxor(g[1], g[2]) == g[3]
  end
  print(f and "Yes" or "No")
elseif tcnt == 2 then
  local f = true
  for k, v in pairs(t) do
    if v == n // 3 and k == 0 then
    elseif v == n * 2 // 3 then
    else f = false
    end
  end
  print(f and "Yes" or "No")
else
  print("No")
end


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

#include <unistd.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
 
 
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
int dx_ori[4] = { -1,0, 1,0 }, dy_ori[4] = { 0,1,0,-1 };
int dx[4] = {0, 0, 0, 0}, dy[4] = {0, 0, 0, 0};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
  fio();
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vl a(n);
  rep (i, n) {
    cin >> a[i];
  }
  sort(all(a));
  reverse(all(a));

  vl sum(n + 1);
  rep (i, n) {
    sum[i + 1] = sum[i] + a[i];
  }
  
  int ok = p - 1, ng = n;
  while (ok + 1 < ng) {
    int mid = (ok + ng) / 2;
    ll x = a[mid] + m;
    if (x < a[p - 1]) {
      ng = mid;
      continue;
    }
    ll nokori = v - p;
    if (v - p <= 0) {
      ok = mid;
      continue;
    }

    nokori *= m;
    for (int j = p - 1; j < n; j++) {
      if (j == mid) continue;
      int can = x - a[j];
      if (can > m) can = m;
      nokori -= can;
      if (nokori <= 0) break;
    }
    if (nokori <= 0) {
      ok = mid;
    }
    else {
      ng = mid;
    }
  }
  cout << ng << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    int left = 0, right = INF, u, v;
    while (m--) {
        scanf("%d %d", &u, &v); 
        left = max(left, u);
        right = min(right, v);
    }
    printf("%d\n", max(0, right-left+1));
}


Measured memory_bytes: 384
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

cnt = 0
from collections import Counter
for i in range(1, n):
    a = Counter(prime_factorize(i))
    add = 1
    for j in a.values():
        add *= j + 1
    cnt += add
print(cnt)


Measured memory_bytes: 69892
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>


using namespace std;


int main(){
    int a;
    string s;

    cin >> a >> s;

    if(a >= 3200){
        cout << s << endl;
    }else{
        cout << "red" << endl;
    }



}


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

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;
}
const int MOD=1000000007;
vector<string>a;
int dp[1100][1100]={0};

void add(int &a,int b){
    a+=b;
    if(a>=MOD)a-=MOD;
}

int main(){
    cin>>H>>W;
    a.resize(H);

    for(int i=0;i<H;i++)cin>>a[i];

    dp[0][0]=1;

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(i+1<H && a[i+1][j]=='.')add(dp[i+1][j],dp[i][j]);
            if(j+1<W && a[i][j+1]=='.')add(dp[i][j+1],dp[i][j]);
        }
    }
    cout<<dp[H-1][W-1]<<endl;

}

Measured memory_bytes: 9808
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
 
    // Your code here!
    // 三項演算子 ? :　("条件")　? "条件が真の時" : "条件が偽の時"
    int a,b;
    cin >> a >> b;
    a*b % 2 ? cout << "Odd" : cout << "Even";
    cout << endl;
}

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

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

#define HORIZONTAL 0
#define VERTICAL 1

int main()
{
	int n;
	scanf("%d", &n);
	
	char inp[2][n];
	for(int i = 0; i < 2; i++) 
		scanf("%s", inp[i]);
	
	vector<int> t;
	for(int i = 0; i < n; i++) {
		if(inp[0][i] == inp[1][i]) {
			t.push_back(VERTICAL);
		} else {
			t.push_back(HORIZONTAL);
			i++;
		}
	}
	
	ll cnt = t[0] == HORIZONTAL ? 6 : 3;
	for(int i = 1; i < (int)t.size(); i++) {
		int prev = t[i - 1];
		int curr = t[i];

		if(prev == VERTICAL)
			cnt *= 2;
		else if(prev == HORIZONTAL && curr == HORIZONTAL)
			cnt *= 3;
		else
			cnt *= 1;
		cnt %= MOD;
	}
		
	printf("%lld\n", cnt);
	

	return 0;
}


Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for i in range(q)]
l = [e[0]-1 for e in lr]
r = [e[1]-1 for e in lr]

account = [0 for i in range(len(s)+1)]
for i in range(1, len(s)):
	if s[i-1] == 'A' and s[i] == 'C':
		account[i] += 1
	account[i+1] = account[i]

for i in range(q):
	print(account[r[i]] - account[l[i]])

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

const int MAX = (int)2e5 + 5;

vector<int> graph[MAX];
bool visited[MAX];
string charNodes;
int cnt[MAX][2];
queue<int> invalidNodes;

void bfs(){
	while(!invalidNodes.empty()){
		int currentNode = invalidNodes.front();
		invalidNodes.pop();
		
		for(int i = 0; i < graph[currentNode].size(); i++){
			int currentNeighbour = graph[currentNode][i];
			
			if(visited[currentNeighbour]) continue;
			
			cnt[currentNeighbour][charNodes[currentNode] - 'A']--;
			
			if(cnt[currentNeighbour][0] == 0 || cnt[currentNeighbour][1] == 0){
				invalidNodes.push(currentNeighbour);
				visited[currentNeighbour] = 1;
			}
				
		}
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	cin >> charNodes;
	
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		--a; --b;
		
		graph[a].push_back(b);
		graph[b].push_back(a);
		
		cnt[a][charNodes[b] - 'A']++;
		cnt[b][charNodes[a] - 'A']++;
	}
	
	
	for(int i = 0; i < n; i++){
		if(cnt[i][0] == 0 || cnt[i][1] == 0){
			invalidNodes.push(i);
			visited[i] = 1;
		}
	}
	
	bfs();
	
	for(int i = 0; i < n; i++){
		if(!visited[i]){
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}

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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    ll n, a, b;
    cin >> n >> a >> b;
    cout << n / (a + b) * a + min(n % (a + b), a) << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int K, S; cin >> K >> S;
  int ans = 0;
  rep(x, K+1){
    rep(y, K+1){
      if(S-x-y>=0 && S-x-y<=K) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>
#include<math.h>
#include"boost/algorithm/string.hpp"

using namespace std;


int main(){
	/*Q1*/

	int a, b;
	cin >> a >> b;

	cout << (int)(a - b + 1) << endl;
	
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int GetDiff(string& a, string& b) {
  int ret = 0;
  for(int i = 0; i < a.size(); ++i) {
    if(a[i] != b[i]) {
      ret += 1;
    }
  }
  return ret;
}
int main() {
  string source;
  cin >> source;
  
  int len = source.size();
  string s0;
  string s1;
  for(int i = 0; i < len; ++i) {
    if(i % 2 == 0) {
      s0.push_back('0');
      s1.push_back('1');
    } else {
      s0.push_back('1');
      s1.push_back('0');
    }
  }
  int minDiff = min(GetDiff(source, s0), GetDiff(source, s1));
  cout << minDiff << endl;
  return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
int main(void)
{
    char H[10];
    int i;
    
    i = 0;
    scanf("%s", H);
    while (H[i])
        i++;
    if (i % 2 != 0 || i > 10 || i == 0)
        printf ("No");
    else
    {
        i = 0;
        while (H[i])
        {
            if (i % 2 == 0)
            {
                if (H[i] != 'h')
                {
                    printf ("No");
                    break ;
                }
            }
            else
            {
                if (H[i] != 'i')
                {
                    printf ("No");
                    break ;
                }
            }
            i++;
            if (H[i] == '\0')
                    printf("Yes");
        }
    }
    return (0);
}

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

int main(){
    int N,A,B;
    cin >> N >> A >> B;

    if (A * N > B){
        cout << B << endl;
    }
    else if (A * N < B){
        cout << A * N << endl;
    }else{
        cout << B << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

int n;
map<int,int> A;

int main(){
    cin>>n;
    int m1=0,m2=0;
    rep(i,0,n){
        int a;cin>>a;
        A[a]++;
        if(A[a]%2==0){
            if(a>m1){
                m2=m1;m1=a;
            }else if(a<=m1&&a>m2){
                m2=a;
            }
        }
    }
    cout<<(ll)m1*(ll)m2<<endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
char a[10001];
int main(){
	int s=0;
	cin>>a;
	for(int i=1;i<(strlen(a)-1);i++){
		s++;
	}
	cout<<a[0]<<s<<a[(strlen(a)-1)]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
ll n,x;
ll gcd(ll a,ll b)
{
	return a==0?b:gcd(b%a,a);
}
int main()
{
	scanf("%lld %lld",&n,&x);
	printf("%lld\n",3*(n-gcd(n,x)));
}

Measured memory_bytes: 128
# a<=x<=b
# c<=y<=d

a,b,c,d = map(int,input().split())
maxans = -10**18 - 1
maxans = max(a*c,maxans)
maxans = max(a*d,maxans)
maxans = max(b*c,maxans)
maxans = max(b*d,maxans)
print(maxans)

Measured memory_bytes: 9172