akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()

typedef long long int ll;

ll general,total;
ll num[ten5];
//ll num2[ten5];
//char cmap[10][10];
//priority_queue<ll> pqll;   //decrease
//priority_queue<double> pqd;
//stack<int> stk;
//vector<pair<ll,ll>> vpll;
//vector<pair<double,double>> vpdd;
//vector<ll> vll[ten52];
//vector<double> vd;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
//set<char> sch;
//set<string> sStr;
//map<ll,ll> mp;

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/


int main()
{
    long long int sum,sum2;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    string s;
    sum=sum2=0;
    a=a1=a2=a3=a4=a5=a6=0;
    cin>>n>>a1>>a2;
    for(i=1;i<n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            a=min(abs(i-a1)+1+abs(j-a2),j-i);
            num[a]++;
        }
    }
    for(i=1;i<n;i++)
        cout<<num[i]<<endl;
    return 0;
}





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

typedef signed long long ll;
const int MX = 1e3 + 5;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    (c >= a && c <= b) ? cout << "Yes\n" : cout << "No\n";
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
  int x = tx - sx; int y = ty - sy;
  vector<string> ans;
  REP(i, y) ans.push_back("U");
  REP(i, x) ans.push_back("R");
  REP(i, y) ans.push_back("D");
  REP(i, x) ans.push_back("L");
  ans.push_back("L");
  REP(i, y + 1) ans.push_back("U");
  REP(i, x + 1) ans.push_back("R");
  ans.push_back("D");
  ans.push_back("R");
  REP(i, y + 1) ans.push_back("D");
  REP(i, x + 1) ans.push_back("L");
  ans.push_back("U");
  REP(i, ans.size()) cout << ans[i];
  cout << endl;
}

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

int main() {
    long long  n,k;
    cin >> n >> k;
    long long i=0;
    while(1){
        long long a=1;
        for(int j=1;j<=i;j++){
            a = a*k;
        }
        if(n/a==0) break;
        i++;
    }
    cout << i << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    ll N; cin >> N;
    ll a = 2;
    map<ll, int> m;
    while(N >= a * a){
        if(N % a == 0){
            m[a]++;
            N /= a;
        }else{
            a++;
        }
    }
    m[N]++;

    // for(auto x:m){
    //     cout << x.first << " " << x.second << endl;
    // }
    vector<int> table;
    // cout << "OK";
    table.push_back(0);
    for(int i = 1; i < 50; i++){
        if(i <= 2) table.push_back(1);
        else if(i <= 5) table.push_back(2);
        else if(i <= 9) table.push_back(3);
        else if(i <= 14) table.push_back(4);
        else if(i <= 20) table.push_back(5);
        else if(i <= 27) table.push_back(6);
        else if(i <= 35) table.push_back(7);
        else if(i <= 44) table.push_back(8);
        else table.push_back(9);
    }
    ll ans = 0;
    for(auto x:m){
        if(x.first != 1){
            ans += table[x.second];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long T, long long X){
    cout << double(T) / double(X) << endl;
}

int main(){

    long long T;
    scanf("%lld",&T);
    long long X;
    scanf("%lld",&X);
    solve(T, X);
    return 0;
}



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


int main(void){
int N;
int count=0;
int i;

scanf("%d", &N);

for(i=1;i<N;i++){
  if(N%i!=0) count+=N/i;
  else count+=N/i-1; 
}

printf("%d", count);

  return 0;

}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string s, t;
	cin >> s >> t;

	string INF(s.size(), 'z');
	string ans = INF;
	for(int i = 0; i + t.size() <= s.size(); i++){
		bool ok = true;
		for(int j = 0; j < t.size(); j++){
			if(s[i + j] != '?' && s[i + j] != t[j]) ok = false;
		}
		if(!ok) continue;
		string a = s;
		for(int j = 0; j < s.size(); j++){
			if(s[j] == '?') a[j] = 'a';
		}
		for(int j = 0; j < t.size(); j++){
			a[i + j] = t[j];
		}
		ans = min(ans, a);
	}
	if(ans == INF) cout << "UNRESTORABLE" << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i,n) for(int i(1);i<=n;++i)
 
int main(){
	int n;
	cin >> n;
	int a[n+1],b[n+1],c[n];
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	rep(i,n-1) cin >> c[i];
	int ans=0;
	for(int i(1);i<n;++i){
		if(a[i+1]==a[i]+1) ans+=(c[a[i]]+b[a[i]]);
		else ans+=b[a[i]];
	}
	ans+=b[a[n]];
	cout << ans;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int k;
int a[100001];

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

int main(void){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int gd=a[0];
	for(int i=1;i<n;i++){
		gd=gcd(gd,a[i]);
	}
	sort(a,a+n);
	if(k%gd!=0 || k>a[n-1]){
		printf("IMPOSSIBLE\n");
	}else{
		printf("POSSIBLE\n");
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll  C,D,E,F,G,H,K,L,M,N,Q,R,U,W,X,Y,Z;
string S,T,A,B;

int main(){
  cin >> S >> Q;
  rep(i,Q){
    cin >> C;
    if(C==1){
      Z++;
    }
    else{
      cin >> F >> T;
      if((Z+F)%2==1){
        A.pb(T[0]);
      }
      else{
        B.pb(T[0]);
      }
    }
  }
  if(Z%2==0){
    reverse(ALL(A));
    cout << A << S << B << endl;
  }
  else{
    reverse(ALL(B));
    reverse(ALL(S));
    cout << B << S << A << endl;
  }
}


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

using namespace std;

int main ()
{
	int n;
    double ans;
  cin >> n;
  if (n == 1)
    ans = 1;
  if(n % 2 == 1)
  {
    ans = n / 2;
    ans += 1;
  	ans /= n;
  }
  else
  {
    ans = n / 2;
  	ans /= n;
  }
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int n,a,b;
    while(cin>>n>>a>>b){
    int w=a+b;
    int ans=(n/w)*a;
    ans+= min((n%w),a);
    cout << ans << endl;
    }
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn     cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;

int main()
{
    int n,k,q;
    cin>>n>>k;
    map<int,int> a;
    rep(i,n)cin>>q,a[q]++;
    vi x(n);
    for(auto z:a) x.pb(z.second);
    sort(all(x));
    q=0;
    for(int i=0;x.size()-i>k;i++) q+=x[i];
    cout<<q<<endl;

    return 0;
}


Measured memory_bytes: 12800
/*
* @author:  codancer
* @createTime:  2020-08-15, 20:41:12
*/

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

typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
#define deb(x) cerr<<#x<<" = "<<(x)<<"\n"
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll B) {
	return (ull)rng() % B;
}
const int N = 6000;
ll c[N],p[N];
ll n,k;
bool vis[N];
vector<int> G[N];

vector<ll> tmp;

void dfs(int x){
	if(vis[x]){
		return ;
	}
	vis[x]=1;
	tmp.pb(c[x]);

	for(int v:G[x]){
		dfs(v);
	}
}
ll solve(vector<ll> tmp){
	int siz=(int)tmp.size();

	ll s=0;
	for(ll v:tmp) s+=v;

	vector<ll> cc(2*(siz+1));
	int cnt=0;
	for(ll v:tmp){
		cc[++cnt]=v;
	}
	for(ll v:tmp){
		cc[++cnt]=v;
	}
	rep(i,1,cnt){
		cc[i]+=cc[i-1];
	}


	ll maxx=-1e18;
	for(int i=1;i<=cnt/2;i++){

		for(int steps=1;i+steps-1<=cnt&&steps<=min(k,(ll)siz);steps++){
			ll ss=s*((k-steps)/siz);
			maxx=max(maxx,cc[i+steps-1]-cc[i-1]+(ss>0?ss:0));
		}
	}
	return maxx;
}
int main(){
	cin>>n>>k;
	rep(i,1,n) cin>>p[i];
	rep(i,1,n) cin>>c[i];
	rep(i,1,n){
		G[i].pb(p[i]);
	}
	ll ans=-1e18;
	rep(i,1,n){
		if(!vis[i]){
			tmp.clear();
			dfs(i);
			ans=max(ans,solve(tmp));
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int N,M;
  cin>>N;
  vector<string> s(N);
  map<string,int> m;
  for(int i=0;i<N;i++){
    cin>>s.at(i);
    if(m.count(s.at(i))==0){
      m[s.at(i)]=0;
    }
    m[s.at(i)]++;
  }
  cin>>M;
  vector<string> t(M);
  for(int i=0;i<M;i++){
    cin>>t.at(i);
    if(m.count(t.at(i))==0){
      m[t.at(i)]=0;
    }
    m[t.at(i)]--;
  }
  int ans=0;
  for(auto x : m){
    ans=max(ans,x.second);
  }
  cout<<ans<<endl;
}


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

int main() {
    int t=1;
    //cin >> t;
    while(t--){
        string s;
        cin >> s;
        ll sum=0,i,j;
        for(i=0;i<s.size();i++){
            sum+=(s[i]-'0');
        }
        if(sum%9==0){
            cout << "Yes"<<endl;
        }else{
            cout << "No" << endl;
        }
    }
}

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

int main() {
	string S,T = "Sunny";
	cin >> S;
  if(S == "Sunny")
  {
  	T = "Cloudy";
  }
  else if(S == "Cloudy")
  {
  	T = "Rainy";
  }
  cout << T << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define all(x) (x).begin(), (x).end()
#define v(T) vector<T>
#define vv(T) vector<v(T)>
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
template<class T>bool chmax(T &a, const T &b){
    if (a < b) {a = b; return true;}
    return false;
}
template<class T>bool chmin(T &a, const T &b){
    if (a > b) {a = b; return true;}
    return false;
}

int comb(int n, int k){
    if (n<k or k < 0) return 0;
    int ret = 1;
    for (int i = n; i> n-k; i--){
        ret *= i;
    }
    for (int i = 1;i<k+1;i++){
        ret /= i;
    }
    return ret;
}

int dp[1000][4][2];
int main()
{
    string s;
    cin >> s;
    int N = s.size();
    int K; cin >> K;
    dp[0][0][0] = 1;
    rep(i, N){
        int num = s[i]-'0';
        rep(j, K+1) rep(k, 2){
            rep(d, 10){
                int nj = j, nk = k;
                if (d!= 0) nj++;
                if (nj > K) continue;
                if (k==0) {
                    if (d > num) continue;
                    else if (d < num) nk++;
                }
                dp[i+1][nj][nk] += dp[i][j][k];
            }

        }
    }
    cout << dp[N][K][0]+dp[N][K][1] << endl;
}



Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>

#define arr_print_d0dn(a, n) for(int i=0;i<(n)-1;++i)printf("%d ",(a)[i]);printf("%d\n",(a)[(n)-1])
#define arr_rprint_d0dn(a, n) for(int i=(n)-1;i>0;--i)printf("%d ",(a)[i]);printf("%d\n",(a)[0])
#define arr_print_dndn(a, n) for(int i=0;i<(n);++i)printf("%d\n",(a)[i])
#define arr_rprint_dndn(a, n) for(int i=(n)-1;i>=0;--i)printf("%d\n",(a)[i])

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
int cnt;
void merge(int *first, int *mid, int *last) {
    const int N1 = (int)(mid - first);
    const int N2 = (int)(last - mid);
    int *left = malloc(sizeof(int) * (N1 + 1));
    int *right = malloc(sizeof(int) * (N2 + 1));
    for(int i = 0; i < N1; ++i) left[i] = first[i];
    for(int i = 0; i < N2; ++i) right[i] = first[i + N1];
    left[N1] = right[N2] = 1 << 30;
    for(int *it = first, i = 0, j = 0; it != last; ++it, ++cnt) {
        *it = left[i] <= right[j] ? left[i++] : right[j++];
    }
    free(left);
    free(right);
}
void merge_sort(int *first, int *last) {
    const int N = (int)(last - first);
    if(N < 2) return;
    int *mid = first + N / 2;
    merge_sort(first, mid);
    merge_sort(mid, last);
    merge(first, mid, last);
}
int main(int argc, char **argv) {
    int n = get_uint();
    int s[500001];
    for(int i = 0; i < n; ++i) s[i] = get_uint();
    merge_sort(s, s + n);
    arr_print_d0dn(s, n);
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 5324
#include<stdio.h>
int main(){
  int H[3000], W[3000], i, l, k, n;
  for(i=0;;i++){
    scanf("%d %d", &H[i], &W[i]);
    if(H[i]==0 && W[i]==0){
      break;
    }
  }
  n = i-1;
  for(i=0;i<=n;i++){
    for(l=0;l<H[i];l++){
      for(k=0;k<W[i];k++){
        if(l==0 || l==H[i]-1 || k==0 || k==W[i]-1){
          printf("#");
        }else{
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }
    return 0;
}

Measured memory_bytes: 1812
#include <iostream> // cout, endl, cin
#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 <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x/GCD(x,y)*y;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }
    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

template <typename T>
string tostr(const T& input) {
    ostringstream oss;
    oss << input;
    return oss.str();
}

int main()
{

 int N;
 cin>>N;

 vector<pair<int,int>> vp(N);

  for(int i=1;i<=N;++i){
   int j=i;
   int k=0;
   while(j%2==0){
     j/=2;
     ++k;
   }
   vp[i-1].first=k;
   vp[i-1].second=i;
  }

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

  cout<<vp[N-1].second<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

int main() {
	int n, a, b; cin >> n >> a >> b;
	unsigned long long int sum = 0;
	for (int i = 1; i <= n; i++) {
		int p1 = i % 10;
		int p2 = i / 10%10;
		int p3 = i / 100 % 10;
		int p4 = i / 1000 % 10;
		int p5 = i / 10000 % 10;
		int sump = p1 + p2 + p3 + p4+p5;
		if (sump >= a && sump <= b) {
			sum += i;
		}

	}
	cout << sum << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<bitset>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
 
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
typedef pair<Pii, int> Piii;
struct edge{int from, to; ll cost;};

vector<Pll> G[100000];
ll pos[100000];
int used[100000];

int dfs(ll node){
    for(Pll next: G[node]){
        if(pos[next.first] != LLONG_MAX && pos[next.first] != pos[node] + next.second){
            return 0;
        }else if(!used[next.first]){
            pos[next.first] = pos[node] + next.second;
            used[next.first] = 1;
            if(!dfs(next.first)) return 0;
        }
    }
    return 1;
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n,m; ll l,r,d;
    cin >> n >> m;
    if(m == 0){
        cout << "Yes" << endl;
        return 0;
    }

    set<ll> nodes;
    rep(m){
        cin >> l >> r >> d;
        l--; r--;
        G[l].emplace_back(r, d);
        G[r].emplace_back(l, -d);
        if(nodes.find(l) == nodes.end() && nodes.find(r) == nodes.end()) nodes.insert(l);
    }

    fill(pos, pos+n, LLONG_MAX);
    int used[n];
    rep(n){
        used[i] = 1;
        if(pos[i] == LLONG_MAX) pos[i] = 0;
        if(!dfs(i)){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 20352
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define MAXN int(1e6)
#define qi queue<int>
#define si stack<int>
#define mii map<int, int>
#define msi map<string, int>
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
using namespace std;

ll dp[1000][1000], h, w;

const int mod = 1e9+7;

char grid[1000][1000];

int main(int argc, char** argv) {
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	
	cin >> h >> w;

	memset(dp, 0, sizeof dp);

	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> grid[i][j];

	dp[0][0] = 1;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i+1 < h) {
				if (grid[i+1][j] == '.')
					dp[i+1][j] = (dp[i+1][j]+dp[i][j])%mod;
				else
					dp[i+1][j] = 0;
			}
			
			if (j+1 < w) {
				if (grid[i][j+1] == '.')
					dp[i][j+1] = (dp[i][j+1]+dp[i][j])%mod;
				else 
					dp[i][j+1] = 0;
			}
		}
	}

	//for (int i = 0; i < h; i++) {
		//for (int j = 0; j < w; j++)
			//cout << dp[i][j] << ' ';
		//cout << '\n';
	//}

	cout << dp[h-1][w-1] << '\n';

	return 0;
}






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

using namespace std;

typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<LL> vl;
typedef vector<vector<LL>> vvl;
typedef vector<vector<vector<LL>>> vvvl;


const int inf = 1e9+7;
const LL INF = 1e18+5;
const int mod = 1e9+7;
const int mxN = 1e5+5;
const int mxM = 1e5+5;

int vis[mxN*2];
vi adj[mxN*2];

void dfs(int s,int &c){
    if(vis[s]) return;
    vis[s] = true;
    for(auto i:adj[s]){
        if(!vis[i]){
            c = c+1;
            dfs(i,c);
        }
    }
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("E:\\Coding\\Programming\\input.txt", "r", stdin);
    freopen("E:\\Coding\\Programming\\output.txt", "w", stdout);
    #endif
    int n,m;
    cin>>n>>m;
    
    memset(vis,false,sizeof vis);
    memset(adj,{},sizeof adj);
    map<pair<int,int>,int> exist;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        if(exist.find({u,v})==exist.end()){
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        exist[{u,v}] = 1;
        exist[{v,u}] = 1;
    }

    int ans = 0;
    for(int i=0;i<n;i++){
        if(!vis[i]){
            int x=1;
            dfs(i,x);
            ans = max(ans,x);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 49592
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in).useDelimiter("\\D+");

    public static void main(String[] args) {
        int cnt = 0;
        while(scn.hasNextInt()) {
            cnt += scn.nextInt();
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 26204
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        int a[41];
        rep(i,n){
            string s;
            cin >> s;
            a[i] = s.size();
        }
        int t[5] = {5,7,5,7,7};
        int k, c, ans = -1;
        rep(i,n){
            k = 0;
            c = 0;
            range(j,i,n){
                c+=a[j];
                if(c == t[k]){
                    k++;
                    c = 0;
                }else if(c > t[k]){
                    break;
                }
                if(k == 5){
                    ans = i;
                    break;
                }
            }
            if(ans != -1) break;
        }
        cout << ans + 1 << endl;
    }
}

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

int main()
{
  int N, M;
  cin >> N >> M;
  
  vector<int> date(M);
  for(int i = 0; i < M; i++)
  {
    cin >> date.at(i);
  }
  
  int ans = 0;
  for(int i = 0; i < M; i++)
  {
    ans += date.at(i);
  }
  
  if(N >= ans)
  {
    cout << N - ans << endl;
  }
  else
  {
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 3628
package main

import (
  "fmt"
)

func main() {
  var (
    n,count int
    )
  fmt.Scan(&n)
  v := make([]int, n)
  for i := 0; i < n; i++ {
      fmt.Scan(&v[i])
  }
  c := make([]int, n)
  for i := 0; i < n; i++ {
      fmt.Scan(&c[i])
  }

  for i:=0; i < n; i++ {
      if v[i] - c[i] > 0 {
        count += v[i] - c[i]
      }
  }
  fmt.Println(count)
}


Measured memory_bytes: 512
import sys
fin = sys.stdin.readline


MAX_INT = (1 << 63) - 1
N = int(fin())
h_list = [int(elem) for elem in fin().split()]

dp = [MAX_INT] * N
dp[0] = 0
dp[1] = abs(h_list[1] - h_list[0])

for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(h_list[i] - h_list[i - 1]),
                dp[i - 2] + abs(h_list[i] - h_list[i - 2]))

print(dp[N - 1])


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

void dfs(char a[][101],int m, int n,int x, int y, char test)
{
	if (a[x][y] == test&&x >= 0 && y >= 0 && x < m&&y < n)
	{
		a[x][y] = '0';
		dfs(a, m, n, x, y-1,test);
		dfs(a, m, n, x, y+1,test);
		dfs(a, m, n, x-1, y,test);
		dfs(a, m, n, x+1, y,test);
	}
}

int main()
{
	int m, n, i, j;
	while (cin >> m >> n)
	{
		if (m == 0 && n == 0)
			break;
		char a[101][101];
		int count = 0;
		for (i = 0; i < m; i++)
			for (j = 0; j < n; j++)
				cin >> a[i][j];
		for (i = 0; i < m; i++)
			for (j = 0; j < n; j++)
			{
				if (a[i][j] != '0')
				{
					dfs(a, m, n, i, j, a[i][j]);
					count++;
				}
			}
		cout << count << endl;
	}
    return 0;
}

Measured memory_bytes: 1784
while 1:
    w,d = map(int,raw_input().split())
    if w == 0: break
    front = map(int,raw_input().split())
    side = map(int,raw_input().split())
    for i in front:
        if i in side: side.remove(i)
    ans = sum(front)+sum(side)
    print ans

Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,R;
  cin >> N >> R;
  
  int IR;
  
  if(N > 10){
    IR = R;
  }else{
    IR = R + (100 * (10 - N));
  }
  
  cout << IR;
  
  return 0;
}

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

typedef struct{
  double x,y,r;
}Circle_t;


inline double dist(Circle_t a, Circle_t b){
  return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
}

int main(){

  int n;
  Circle_t a,b;

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a.x >> a.y >> a.r >> b.x >> b.y >> b.r;

    if( a.r + b.r < dist(a,b) ) cout << 0 << endl;

    else if(a.r-b.r > dist(a,b)) cout << 2 << endl;

    else if(b.r-a.r > dist(a,b)) cout << -2 << endl;

    else cout << 1 << endl;

  }

  return 0;
}

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

ll N;

int main() {
    cin >> N;

    vector<ll> target = {1};

    ll t = N / 6;
    ll idx = 1;
    while (t != 0) {
        target.push_back(pow(6, idx));
        idx++;
        t = t / 6;
    }

    ll t2 = N / 9;
    ll idx2 = 1;
    while (t2 != 0) {
        target.push_back(pow(9, idx2));
        idx2++;
        t2 = t2 / 9;
    }

    // for (int i = 0; i < target.size(); i++) {
    //     cout << target[i] << " ";
    // }
    // cout << endl;
    vector<ll> dp(N + 1, 1e9);
    dp[0] = 0;
    for (ll i = 0; i <= N - 1; i++) {
        for (ll j = 0; j < target.size(); j++) {
            if (i + target[j] > N) continue;
            // printf("%d %d\n", dp[i] + 1, dp[i + target[j]]);
            dp[i + target[j]] = min(dp[i] + 1, dp[i + target[j]]);
        }
    }

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

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

ll f(ll x, ll y, ll z) {
	return x * x + y * y + z * z + x * y + y * z + z * x;
}

int main() {
	ll N;
	cin >> N;
	for (ll n = 1; n <= N; ++n) {
		//cerr << ":" << n << ":" << endl;
		ll ans = 0;
		for (ll i = 1;; ++i) {
			bool jf = true;
			for (ll j = 1;; ++j) {
				bool kf = true;
				for (ll k = 1;; ++k) {
					if (f(i, j, k) < n) {
						jf = false;
						kf = false;
					}
					else if (f(i, j, k) == n) {
						++ans;
						//cerr << i << " " << j << " " << k << endl;
					}
					else break;
				}
				if (kf)break;
			}
			if (jf)break;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3632
#pragma GCC optimize("O3", "unroll-loops")

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <limits>
#include <ext/rope>

using namespace std;
using namespace __gnu_cxx;

const int inf = (1 << 30) + 9e8;
const int MAXN = 1e5;
const int P = 131;
const long long MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<bool> vb;

#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define all(a) a.begin(), a.end()
#define pb push_back
#define files(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define ppb pop_back
#define ppf pop_front
#define fs first
#define sd second
#define eb emplace_back

template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
std::mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int add(int a, int b) {
    a += b;
    if (a >= MOD) {
        a -= MOD;
    }
    if (a < 0) {
        a += MOD;
    }
    return a;
}

void solve() {
    int h, w;
    cin >> h >> w;
    char x[h][w];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> x[i][j];
        }
    }
    vvi dp(h, vi(w, 0));
    for (int j = 0; j < w; ++j) {
        if (x[0][j] == '#')
            break;
        dp[0][j] = 1;
    }
    for (int j = 0; j < h; ++j) {
        if (x[j][0] == '#')
            break;
        dp[j][0] = 1;
    }
    for (int i = 1; i < h; ++i) {
        for (int j = 1; j < w; ++j) {
            if (x[i][j] == '#')
                continue;
            dp[i][j] = add(dp[i][j], dp[i - 1][j]);
            dp[i][j] = add(dp[i][j], dp[i][j - 1]);
        }
    }
    cout << dp[h - 1][w - 1];
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    FAST;
    int q = 1;
    // cin >> q;
    // int st = clock();
    while (q--) {
        solve();
    }
    // int en = clock();
    // cout << en - st << "ms.";
    return 0;
}


Measured memory_bytes: 8240
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

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

void solve() {
	int n = 3;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	int ans = v[2] * 10 + v[1] + v[0];
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<vector<int>> s(3 * k + 1, vector<int>(3 * k + 1));
    for (int i = 0; i < n; i++) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        if (c == 'W') {
            y += k;
        }
        x %= 2 * k;
        y %= 2 * k;
        if ((x < k) == (y < k)) {
            x %= k;
            y %= k;
            x += k;
            y += k;
            s[x + 1][y + 1]++;
            for (int i = -1; i <= 1; i++) {
                for (int j = -1; j <= 1; j++) {
                    if (i * j) {
                        s[x + 1 + k * i][y + 1 + k * j]++;
                    }
                }
            }
        } else {
            x %= k;
            y %= k;
            x += k;
            y += k;
            for (int i = -1; i <= 1; i++) {
                for (int j = -1; j <= 1; j++) {
                    if (!i ^ !j) {
                        s[x + 1 + k * i][y + 1 + k * j]++;
                    }
                }
            }
        }
    }
    for (int i = 1; i <= 3 * k; i++) {
        for (int j = 1; j <= 3 * k; j++) {
            s[i][j] -= s[i - 1][j - 1] - s[i - 1][j] - s[i][j - 1];
        }
    }
    int ans = 0;
    for (int i = k; i <= 3 * k; i++) {
        for (int j = k; j <= 3 * k; j++) {
            ans = max(ans, s[i][j] + s[i - k][j - k] - s[i][j - k] - s[i - k][j]);
        }
    }
    cout << ans << '\n';
    return 0;
}


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

const int nIMPOS = -1;
struct StDist
{
  int m_nDist;
  int m_nDone;

  StDist(int nDist) : m_nDist(nDist), m_nDone(0)
  { }
};

void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StDist>& rvoDist)
{
  int nxSiz;
  cin >> nxSiz;

  rvvnAdjcy.resize(nxSiz + 1, vector<int>(nxSiz + 1, 0));
  for (int i = 0; i < nxSiz; ++i)
  {
    int nx, nySiz;
    cin >> nx >> nySiz;
    for (int j = 0; j < nySiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
  StDist oDist(nIMPOS);
  rvoDist.resize(nxSiz + 1, oDist);
}

void fnBreadthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy, 
                          queue<int>& rqnBFSrch, vector<StDist>& rvoDist)
{
  while (rqnBFSrch.size())
  {
    int nx = rqnBFSrch.front(); rqnBFSrch.pop();
    if (rvoDist[nx].m_nDist == nIMPOS)  continue;

    for (int ny = 1; ny < cnrvvnAdjcy[nx].size(); ++ny)
    {
      if (cnrvvnAdjcy[nx][ny] == 1  &&
          rvoDist[nx].m_nDone == 0)
      {
        int nDist = rvoDist[nx].m_nDist + 1;
        if (rvoDist[ny].m_nDist == nIMPOS)
          rvoDist[ny].m_nDist = nDist;
        else
          rvoDist[ny].m_nDist = min(rvoDist[ny].m_nDist, nDist);

        rqnBFSrch.push(ny);
      }
    }
    rvoDist[nx].m_nDone = 1;
  }
}

void fnResult(const vector<StDist>& cnrvoDist)
{
  for (int i = 1; i < cnrvoDist.size(); ++i)
    cout << i <<  " " << cnrvoDist[i].m_nDist << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;
  queue<int>  qnBFSrch;
  vector<StDist> voDist;

  fnInput(vvnAdjcy, voDist);

  voDist[1].m_nDist = 0;
  qnBFSrch.push(1);
  fnBreadthFirstSearch(vvnAdjcy, qnBFSrch, voDist);
  fnResult(voDist);

  return 0;
}

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

long p = 998244353;
long ans;
vector<long> facMap;

vector<long> makeFacMap(long n)
{
    vector<long> fac;
    long cur = 1;
    rep(i, n + 1)
    {
        fac.push_back(cur);
        cur *= i + 1;
        cur %= p;
    }
    return fac;
}

long modPow(long n, long m)
{
    if (m == 0)
    {
        return 1;
    }
    long halfPow = modPow(n, m / 2);
    if (m % 2 == 0)
    {
        return (halfPow * halfPow) % p;
    }
    else
    {
        long v = (halfPow * halfPow) % p;
        return (v * n) % p;
    }
}

long comb(long n, long m)
{
    long ret = facMap.at(n);
    ret *= modPow(facMap.at(n - m), p - 2);
    ret %= p;
    ret *= modPow(facMap.at(m), p - 2);
    ret %= p;
    // cout << n << "C" << m << "=" << ret << endl;
    return ret;
}
int main()
{
    long n, m, k;
    cin >> n >> m >> k;
    facMap = makeFacMap(n + 1);
    ans = 0;
    long temp;
    for (long i = 0; i <= k; i++)
    {
        // cout << n - 1 << " " << i << endl;
        temp = (m * modPow(m - 1, n - i - 1)) % p;
        temp *= comb(n - 1, i);
        // cout << temp << endl;
        ans += temp % p;
        ans %= p;
    }
    // puts("ok3");
    // scanf("%d", &x);
    // printf("%d\n", x * x * x);
    cout << ans << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M);
  for (int i = 0; i < M; ++i)
    cin >> L[i] >> R[i];
  int l = 0, r = 100001;
  for (int i = 0; i < M; ++i)
    l = max(L[i], l), r = min(R[i], r);
  cout << max(r - l + 1, 0) << endl;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int a = sc.nextInt();
        int l = sc.nextInt();

        String ans = "No";

        for (int i = 0; i<(a+1); i++){
            for (int j = 0; j<(a+1); j++){
                if ((i+j) == a){
                    if ( (i*2)+(j*4) == l ){
                        ans = "Yes";
                    }
                }
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 35816
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin >> a>>b>>c;
int i;
bool can = false;
for(i=0;i<b+1;i++){
if(a*i%b==c) {can=true; break;}
}
if(can) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
s=[[] for i in range(n)]
for i in range(m):
  inp=list(map(int,input().split()))
  s[inp[0]-1].append(inp[1]-1)
  s[inp[1]-1].append(inp[0]-1)
c=0
d=[0 for i in range(n)]
for i in range(n):
  if d[i]:
    continue
  c+=1
  d[i]=c
  st=s[i]
  while st:
    ns=[]
    for j in st:
      if d[j]:
        continue
      d[j]=c
      ns+=s[j]
    st=ns
c=0
for i in range(n):
  if d[i]==d[a[i]-1]:
    c+=1
print(c)

Measured memory_bytes: 33520
#include <stdio.h>
#include <stdlib.h>

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

int main(){
  int n;
  scanf("%d", &n);
  int a[n];
  int i;
  for(i=0;i<n;i++){
    scanf("%d", &a[i]);
  }
  qsort(a, n, sizeof(int), compare);
  int ans = 0;
  for(i=0;i<n;i++){
    if(i%2==0){
      ans += a[i];
    }else{
      ans -= a[i];
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec; typedef pair<int, int> pi;
int dd[] = { 0, 1, 0, -1, 0 };
#define all(u) begin(u),end(u)
#define mp make_pair
#define pb push_back
	
int main()
{
	int n, k;
	cin >> n >> k;
	i64 ans = 1;
	rep(i,n)
	{
		ans = min(ans*2, ans+k);
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define lc (1 + (idx << 1))
#define rc (2 + (idx << 1))
#define md ((st + nd) >> 1)
#define fi first
#define se second
#define pb push_back
typedef long long ll;

const int N = 16;
int a[N][N];
ll dp[1<<N], b[1<<N];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	for (int j = 1; j < (1 << n); j++) {
		for (int u = 0; u < n; u++) {
			if (j & (1 << u)) {
				for (int v = u + 1; v < n; v++) {
					if (j & (1 << v)) {
						b[j] += a[u][v];
					}
				}
			}
		}
	}
	//memset(dp, -1, sizeof dp);
	dp[0] = 0;
	//for (int i = 1; i <= n; i++) {
		for (int j = 1; j < (1 << n); j++) {
			dp[j] = -1;
			int hold = j;
			do {
				if (dp[hold] != -1) {
					dp[j] = max(dp[j], dp[hold] + b[j^hold]);
				}
				--hold;
				hold &= j;
			} while (hold != j);
		}
	//}
	printf("%lld", dp[(1<<n)-1]);
	return 0;
}
/*
3
0 10 20
10 0 -100
20 -100 0
*/
/*
2
0 -10
-10 0
*/
/*
4
0 1000000000 1000000000 1000000000
1000000000 0 1000000000 1000000000
1000000000 1000000000 0 -1
1000000000 1000000000 -1 0
*/
/*
16
0 5 -4 -5 -8 -4 7 2 -4 0 7 0 2 -3 7 7
5 0 8 -9 3 5 2 -7 2 -7 0 -1 -4 1 -1 9
-4 8 0 -9 8 9 3 1 4 9 6 6 -6 1 8 9
-5 -9 -9 0 -7 6 4 -1 9 -3 -5 0 1 2 -4 1
-8 3 8 -7 0 -5 -9 9 1 -9 -6 -3 -8 3 4 3
-4 5 9 6 -5 0 -6 1 -2 2 0 -5 -2 3 1 2
7 2 3 4 -9 -6 0 -2 -2 -9 -3 9 -2 9 2 -5
2 -7 1 -1 9 1 -2 0 -6 0 -6 6 4 -1 -7 8
-4 2 4 9 1 -2 -2 -6 0 8 -6 -2 -4 8 7 7
0 -7 9 -3 -9 2 -9 0 8 0 0 1 -3 3 -6 -6
7 0 6 -5 -6 0 -3 -6 -6 0 0 5 7 -1 -5 3
0 -1 6 0 -3 -5 9 6 -2 1 5 0 -2 7 -8 0
2 -4 -6 1 -8 -2 -2 4 -4 -3 7 -2 0 -9 7 1
-3 1 1 2 3 3 9 -1 8 3 -1 7 -9 0 -6 -8
7 -1 8 -4 4 1 2 -7 7 -6 -5 -8 7 -6 0 -9
7 9 9 1 3 2 -5 8 7 -6 3 0 1 -8 -9 0
*/


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;cin >> n;
    string s[n];
    int t[n];
    rep(i,n)
    {
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    int neru = -1;
    rep(i,n)
    {
        if (x == s[i])
        {
            neru = i;
        }
    }
    // cout << neru << endl;
    int ans = 0;
    REP(i, neru+1, n)
    {
        ans += t[i];
    }
    cout << ans << endl;
}




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

namespace {
  ll read() {
    ll x;
    cin >> x;
    return x;
  }

  string reads() {
    string s;
    cin >> s;
    return s;
  }

  template<class T>
  void write(T x) {
    cout << x << ' ';
  }

  void newline() {
    cout << '\n';
  }
}

int main() {
  string S;
  cin >> S;
  const int N = S.size();
  ll ans = 0;
  ll cnt = 0;
  int i = 0;
  while (i < N) {
    if (S[i] == 'A') {
      cnt++;
      i++;
    } else if (i + 1 < N && S[i] == 'B' && S[i + 1] == 'C') {
      ans += cnt;
      i += 2;
    } else {
      cnt = 0;
      i++;
    }
  }
  cout << ans << '\n';
}

struct init {
  init() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} init_;




Measured memory_bytes: 720
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;

	void solve() {
		int[] ia = readNums();
		int n = ia[0];
		int k = ia[1];
		int[] ib = readNums();
		Arrays.sort(ib);
		long ans = 0;
		for (int i = 0; i < k; i++) {
			ans += ib[n - i - 1];
		}
		pln(ans);
	}

	// -----------------------------------------------------
	// 2018/04/25 r1
	// -----------------------------------------------------
	int abs(int a) {
		return (a >= 0) ? a : -a;
	}

	long abs(long a) {
		return (a >= 0) ? a : -a;
	}

	int max(int a, int b) {
		return (a > b) ? a : b;
	}

	long max(long a, long b) {
		return (a > b) ? a : b;
	}

	int min(int a, int b) {
		return (a < b) ? a : b;
	}

	long min(long a, long b) {
		return (a < b) ? a : b;
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	long readLong() {
		String line = readLine();
		return plong(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++)
			nums[i] = pint(flds[i]);
		return nums;
	}

	long[] readLongs() {
		String[] flds = readFlds();
		long[] nums = new long[flds.length];
		for (int i = 0; i < flds.length; i++)
			nums[i] = plong(flds[i]);
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;
	static boolean _bElapsed = false;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (_bElapsed)
			System.err.println((end - start) + "ms");
	}
}


Measured memory_bytes: 21204