akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll n,q;
string s;
vector<pair<char,char> > v;
bool chk1(ll x){
    ll idx = x-1;
    REP (i,q) {
        if (v[i].X == s[idx]) {
            if (v[i].Y == 'L') idx--;
            else idx++;
        }
        if (idx < 0) return true;
    }
    return false;
}
bool chk2(ll x){
    ll idx = n-x;
    REP (i,q) {
        if (v[i].X == s[idx]) {
            if (v[i].Y == 'L') idx--;
            else idx++;
        }
        if (idx >= n) return true;
    }
    return false;
}
int main(){
    IOS();
    cin >> n >> q;
    cin >> s;
    REP (i,q) {
        char t,d;
        cin >> t >> d;
        v.eb(t,d);
    }

    ll l=0,r=n+1;
    while (l != r-1) {
        ll mid = (l+r)>>1;
        if (chk1(mid)) l = mid;
        else r = mid;
    }
    debug(l,r);
    ll l1=0,r1=n+1;
    while (l1 != r1-1) {
        ll mid = (l1+r1)>>1;
        if (chk2(mid)) l1 = mid;
        else r1 = mid;
    }
    debug(l1,r1);
    cout << max(0LL,n-l-l1) << endl;
}


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

vector<vector<pair<int, int>>> G;
vector<long long> D;

void dfs(int current, int parent) {
  for (auto nx : G.at(current)) {
    if (nx.first == parent) continue;
    D.at(nx.first) = D.at(current) + nx.second;
    dfs(nx.first, current);
  }
}

int main() {
  int N; cin >> N;
  G.resize(N);
  D.resize(N);
  for (int i = 0; i < N-1; i++) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;
    G.at(a).push_back(make_pair(b, c));
    G.at(b).push_back(make_pair(a, c));
  }
  int Q, K; cin >> Q >> K;
  vector<pair<int, int>> R(Q);
  for (int i = 0; i < Q; i++) {
    int x, y; cin >> x >> y;
    x--; y--;
    R.at(i) = make_pair(x, y);
  }
  dfs(K-1, -1);
  for (int i = 0; i < Q; i++) {
    cout << D.at(R.at(i).first) + D.at(R.at(i).second) << endl; 
  }
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<string> s(n);rep(i,n){cin>>s[i];}
    ll lim = 1e+10;
    vector<vector<ll>> mat(n,vector<ll>(n,lim));
    rep(i,n){
        mat[i][i] = 0;
        rep(j,n){
            if(s[i][j]=='1'){
                mat[i][j]=1;
            }
        }
    }
    ll d = -1;
    ll start = -1;
    rep(k,n){
        rep(i,n){
            rep(j,n){
                chmin(mat[i][j],mat[i][k]+mat[k][j]);
            }
        }
    }
    rep(i,n){
        rep(j,n){
            if(chmax(d,mat[i][j])){
                start = j;
            }
        }
    }
    DEBUG{
        printf("d: %lld\n",d);
        printf("start: %lld\n",start);
    }
    queue<pair<ll,ll>> que;
    que.emplace(start, 1);
    ll res = 1;
    vector<ll> v(n,0);
    v[start] = 1;
    while(!que.empty()){
        auto tmp = que.front();
        DEBUG{
            cout << tmp.first << endl;
        }
        que.pop();
        ll cur = tmp.first;
        chmax(res, tmp.second);
        rep(j,n){
            if(s[cur][j]=='1'){
                if(v[j]==0){
                    v[j]=tmp.second+1;
                    que.emplace(j, v[j]);
                }else if(v[j]!=tmp.second+1&&v[j]!=tmp.second-1){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
    cout << d+1 << endl;
    return 0;
}


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

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

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

int n;
string s;

int main()
{
  fastio();

  cin >> n >> s;

  int ans = 0;
  for (int i = 0; i < n-1; i++) {
    if (s[i] != s[i+1]) ans++;
  }

  cout << ans+1 << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 10000
#define INF 10001000

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,a,n) for(int i = a; i < (n); i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll; 

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

    double a = n/2;
    double ans;
    if(n%2!=0) { ans = (double)(a+1)/n; printf("%.8f\n", ans);}
    else       { ans = (double)a/n;     printf("%.8f\n", ans);}

    return 0;
}


Measured memory_bytes: 256
using namespace std;
using ll=long long;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#define out(S) cout<<(S)<<endl;
#define mod(i) ((i)%(ll)(1000000000 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define For(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFor(i,a,b) for(size_t i=(a)-1;i>=(b);i--)
#define Rep(i,a) for(size_t i=0;i<(a);i++)
#define rRep(i,a) for(size_t i=(a)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)

int main(){
	int K, S;
	cin >> K >> S;
	ll ans = 0;
	K++;
	For(i, 0, K) {
		For(n, 0, K) {
			if (S - i - n > K-1) continue;
			ans++;
		}
	}
	out(ans);
	return 0;
}



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

using namespace std;

const int N = 105;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

int n, m, a[N], f[N][maxn], g[N][maxn];

void add (int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
}

void sub (int &x, int y) {
    x -= y;
    if (x < 0) x += mod;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    f[0][0] = g[0][0] = 1;
    for (int i = 1; i <= m; i++) add(g[0][i], g[0][i - 1]);
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            f[i][j] = g[i - 1][j] - (j - a[i] - 1 >= 0 ? g[i - 1][j - a[i] - 1] : 0);
            if (f[i][j] < 0) f[i][j] += mod;
            g[i][j] = f[i][j];
        }
        
        for (int j = 1; j <= m; j++) add(g[i][j], g[i][j - 1]);
    }
    
    cout << f[n][m];
    return 0;
}

Measured memory_bytes: 82176
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N,  A, B;
  cin >> N >> A >> B;
  if (A > B) cout << B << " " ;
  else cout << A << " " ;
  
  if (N < A + B) {
    cout << A + B - N << endl;
  } else {
    cout << 0 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())
    print((1000 - (n % 1000)) % 1000)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 65324
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
    int b_n;
    int n[9][2];
    bool flg = 0;
    rep(i, 9) {
        n[i][1] = 0;
        cin >> n[i][0];
    }
    cin >> b_n;
    vector<int> b(b_n);
    rep(i, b_n) {
        cin >> b[i];    
        rep(j, 9) {
            if (b[i] == n[j][0]) {
                n[j][1] = 1;
            }
        }
    }
    if (n[0][1] == 1 && n[1][1] == 1 && n[2][1] == 1) {
        flg = 1;
    }
    if (n[3][1] == 1 && n[4][1] == 1 && n[5][1] == 1) {
        flg = 1;
    }
    if (n[6][1] == 1 && n[7][1] == 1 && n[8][1] == 1) {
        flg = 1;
    }
    if (n[0][1] == 1 && n[3][1] == 1 && n[6][1] == 1) {
        flg = 1;
    }
    if (n[1][1] == 1 && n[4][1] == 1 && n[7][1] == 1) {
        flg = 1;
    }
    if (n[2][1] == 1 && n[5][1] == 1 && n[8][1] == 1) {
        flg = 1;
    }
    if (n[0][1] == 1 && n[4][1] == 1 && n[8][1] == 1) {
        flg = 1;
    }
    if (n[2][1] == 1 && n[4][1] == 1 && n[6][1] == 1) {
        flg = 1;
    }
    if (flg == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

string S;
int a[4];

int char2num(char c)  // c: 0-9
{
  return c - '0';
}

void solve()
{
  REP(i,0,4) a[i] = char2num(S[i]);

  REP(bit,0,1<<3) {
    int x = a[0];
    REP(i,0,3) {
      // 0 --> + / 1 --> -
      if (bit & (1<<i)) x += a[i+1];
      else x -= a[i+1];
    }

    if (x == 7) {
      printf("%d%c%d%c%d%c%d=7\n",
             a[0],
             (bit & (1<<0)) ? '+' : '-',
             a[1],
             (bit & (1<<1)) ? '+' : '-',
             a[2],
             (bit & (1<<2)) ? '+' : '-',
             a[3]);
      return;
    }
  }
}

int main()
{
  cin >> S;
  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){

  int n,q,b,e;
  int a[1010];

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  
  cin >> q;
  while(q--){
    cin >> b >> e;
    reverse(a+b,a+e);
  }
  
  for(int i=0;i<n;i++){
    cout << a[i];
    if(i == n-1) cout << endl;
    else cout << " ";
  }
  
  return(0);
}



Measured memory_bytes: 3072
n, a, b, c = map(int, input().split())                                                 
l = [int(input()) for _ in range(n)]                                                   
                                                                                       
def base10to(x, y):  # xをy進数に                                                          
    if int(x/y):                                                                       
        return base10to(int(x/y), y)+str(x%y)                                          
    return str(x%y)                                                                    
                                                                                       
ans = float("inf")                                                                     
                                                                                       
for i in range(4**n):                                                                  
    i_base4 = base10to(i, 4)                                                           
    while len(i_base4)<n:                                                              
        i_base4 = "0"+i_base4                                                          
    if ("0" not in i_base4) or ("1" not in i_base4) or ("2" not in i_base4):           
        continue                                                                       
    memo = [0, 0, 0]  # [A, B, C]                                                      
    fusion = -3  # 合成回数                                                                
    for j in range(n):                                                                 
        if i_base4[j]=="3":                                                            
            continue                                                                   
        fusion += 1                                                                    
        memo[int(i_base4[j])] += l[j]                                                  
    mp = abs(memo[0]-a) + abs(memo[1]-b) + abs(memo[2]-c) + fusion*10                  
    ans = min(ans, mp)                                                                 
                                                                                       
print(ans)                                                                             
                                                                                       

Measured memory_bytes: 3064
n = int(input())

ans = ""
last_is_z = False
while n:
    if last_is_z:
        n -= 1
        if n == 0:
            break
    if n % 26 == 0:  # zのとき
        ans += "z"
        last_is_z = True
    else:
        ans += chr(96 + n % 26)
        last_is_z = False
    n //= 26

print(ans[::-1])

Measured memory_bytes: 9064
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 10000000
int main(){
	int n; cin >> n;
	while(n--){
		int mx = 0, mn = 0;
		int d; cin >> d;
		int a,b; cin >> a;
		for(int i=0;i<d-1;i++){
			cin >> b;
			int tmp = abs(b-a);
			if(b > a) mx = max(mx,tmp);
			else mn = max(mn,tmp);
			a = b;
		}
		cout << mx << " " << mn << endl;
	}
}

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> l(n);
  rep(i,n){cin >> l[i];}
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());
  int max = 0;
  rep(i,k){max += l[i];}
  cout << max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

int main(){

    int n;
    cin>>n;
    vector<int>vec(n);
    for(int i=0;i<n;i++)cin>>vec[i];
    sort(vec.begin(), vec.end());
    int ans = 0;
    for(int i=0;i<n;i++)ans += vec[i];
    ans -= vec[n-1] / 2;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
amax = max(a)
amin = min(a)

print(2*n-1)
if amax > abs(amin):
    a_i = a.index(amax)
else:
    amax += amin
    a_i = a.index(amin)
for i in range(n):
    print(a_i+1,i+1)

if amax > 0:
    for i in range(n-1):
        print(i+1,i+2)
else:
    for i in range(n,1,-1):
        print(i,i-1)


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

int main() {

  ll N , M ;
  cin >> N >> M ;
  vector<ll> A[N+1] ;
  ll P[M+1] ;
  ll Y[M+1] ;
  rep(i,M){
    int P1 , Y1 ;
    cin >> P1 >> Y1 ;
    A[P1].push_back(Y1) ;
    P[i] = P1 ;
    Y[i] = Y1 ;
  }
  rep(i,N+1) sort( A[i].begin(),A[i].end() ) ;
  rep(i,M){
    ll B = ll(lower_bound( A[P[i]].begin() , A[P[i]].end() ,Y[i] )  - A[P[i]].begin());
    printf("%012lld\n",P[i] * 1000000 + B + 1 );
  }
}

Measured memory_bytes: 8576
#include <bits/stdc++.h> 
using namespace std;
int n = 0, num[2050];
int gcd(int x, int y) { return y? gcd(y, x % y): x; }
int dis[2050];
bool abl[2050][2050], lin[2050][2050];
bool vis[2050];
int ans[2050], tot = 0;
void dfs(int x)
{
	vis[x] = true;
	for(int i = 1; i <= n; i++)
		if(not vis[i] && abl[x][i])
		{
			lin[x][i] = true;
			dfs(i);
		}
}
signed main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", num + i);
	sort(num + 1, num + n + 1);
	for(int i = 1; i < n; i++)
		for(int j = i + 1; j <= n; j++)
			if(gcd(num[i], num[j]) > 1)
				abl[i][j] = abl[j][i] = true;
	for(int i = 1; i <= n; i++)
		if(not vis[i]) dfs(i);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			if(lin[i][j]) dis[j]++;
	priority_queue<int> df;
	for(int i = 1; i <= n; i++)
		if(dis[i] == 0) df.push(i);
	while(not df.empty())
	{
		int x = df.top(); df.pop();
		tot++, ans[tot] = num[x];
		for(int i = 1; i <= n; i++)
			if(lin[x][i])
			{
				dis[i]--;
				if(dis[i] == 0) df.push(i);
			}
	}
	for(int i = 1; i <= n; i++)
		printf("%d%c", ans[i], " \n"[i == n]);
	return 0;
} 

Measured memory_bytes: 8576
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
ans = 0

for i in range(1, n+1):
    if i % 2 == 1:
        if len(make_divisors(i)) == 8:
            ans += 1

print(ans)

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

int main(){
    int n,m;
    cin >> n >> m;
    vector <int> l(m), r(m);
    rep(i,m) cin >> l[i] >> r[i];

    int maxleft=l[0], minright=r[0];
    for(int i=0;i<m; i++){
        if(l[i] > maxleft) maxleft = l[i];
        if(r[i] < minright) minright = r[i];
    }

    if(maxleft > minright){
        cout << 0 << endl;
        return 0;
    }
    else cout << minright - maxleft + 1 << endl;


} 


Measured memory_bytes: 1024
#include <stdio.h>

int main(void) { int i,x;
  for(i = 1;  ; i++)  {
 scanf("%5d",&x);
 if(x==0){
   break;
 }
 if(x>1&&10000<x){
   break;
 }
  printf("Case %d: %d\n",i,x);}
}


Measured memory_bytes: 2564
var
  a:array[1..100000] of longint;
  i,n,j,m,k:longint;
  ans:qword;
procedure qsort(l,r:longint);
var
  i,j,mid,p:longint;
begin
  i:=l;j:=r;
  mid:=a[(l+r)shr 1];
  repeat
    while a[i]<mid do inc(i);
    while a[j]>mid do dec(j);
    if i<=j then
      begin
        p:=a[i];a[i]:=a[j];a[j]:=p;
        inc(i);
        dec(j);
      end;
  until i>j;
  if l<j then qsort(l,j);
  if i<r then qsort(i,r);
end;
begin
  readln(n,k);
  for i:=1 to n do readln(a[i]);
  qsort(1,n);
  ans:=maxlongint;
  for i:=1 to n-k+1 do if ans>(a[i+k-1]-a[i]) then ans:=a[i+k-1]-a[i];
  writeln(ans);
end.

Measured memory_bytes: 512
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<double,int>P;
int main(){
    P s[3][8];
    for(int i=0;i<3;i++){
        for(int j=0;j<8;j++){
            double v;
            int p;
            scanf("%d%lf",&p,&v);
            s[i][j]=P(v,p);
        }
    }
    for(int i=0;i<3;i++)sort(s[i],s[i]+8);
    P t[6];
    for(int i=0;i<3;i++){
        for(int j=0;j<2;j++){
            printf("%d %.2f\n",s[i][j].second,s[i][j].first);
            t[i*2+j]=s[i][j+2];
        }
    }
    sort(t,t+6);
    for(int i=0;i<2;i++){
        printf("%d %.2f\n",t[i].second,t[i].first);
    }
    return 0;
}

Measured memory_bytes: 1080
#include<cstdio>

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


Measured memory_bytes: 2668
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub fn bsearch<F>(ok: i64, ng: i64, pred: F) -> Option<i64>
where
    F: Fn(i64) -> bool,
{
    let orig_ok = ok;
    let mut ok = ok;
    let mut ng = ng;
    while (ok - ng).abs() > 1 {
        let mid = (ok + ng) / 2;
        if pred(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    if ok == orig_ok {
        None
    } else {
        Some(ok)
    }
}

fn solve() {
    input! {
        n: usize, m: i64,
        mut av: [i64; n]
    };

    av.sort();
    let min_point = bsearch(-1, 10_i64.pow(5) * 2 + 10, |p| {
        let mut count = 0_i64;
        for i in 0..n {
            let x = av[i];
            let j = bsearch(n as i64, -1, |j| {
                let y = av[j as usize];
                let min_y = p - x;
                y >= min_y
            });
            if let Some(j) = j {
                count += n as i64 - j;
            }
        }
        count >= m
    })
    .unwrap();

    let cusum = av
        .iter()
        .rev()
        .scan(0, |acc, &x| {
            *acc += x;
            Some(*acc)
        })
        .collect::<Vec<_>>();
    let mut res = 0_i64;
    let mut count = 0_i64;
    for i in 0..n {
        let x = av[i];
        let j = bsearch(n as i64, -1, |j| {
            let y = av[j as usize];
            let min_y = min_point - x;
            y >= min_y
        });
        if let Some(j) = j {
            let c = n as i64 - j;
            count += c;
            res += x * c + cusum[n - (j as usize + 1)];
        }
    }
    res -= (count - m) * min_point;
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

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

/*********** TEMPLATE ENDS HERE *************/

unordered_map <char, int> H;

vector <char> v = {'M', 'A', 'R', 'C', 'H'};

main()
{
	IOS
	
	int n;
	cin >> n;
	
	while(n--)
	{
		string s;
		cin >> s;
		H[s[0]]++;
	}
	
	ll nr_ways = 0;
	
	for(int i = 0; i <= 2; i++)
		for(int j = i + 1; j <= 3; j++)
			for(int k = j + 1; k <= 4; k++)
				nr_ways += H[v[i]] * 1LL * H[v[j]] * H[v[k]];
	cout << nr_ways;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int mod=1e9+7;
vector<int> g[26];
bool can[26][26];
//dp[i][j]  number of digits at ith idx that give remainder j
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif

	string s,t;
	cin>>s>>t;int n=s.length();
	vector<int> st(26,-1),end(26,-1);
	for(int i=0;i<n;i++)
	{
		int a=s[i]-'a';int b=t[i]-'a';
		if(st[a]!=-1 or end[b]!=-1)
		{
			if(st[a]!=b or end[b]!=a)
			{
				puts("No");return 0;
			}
		}
		else
		{
			st[a]=b;end[b]=a;
		}
	}
	puts("Yes");

	

	
	
}

Measured memory_bytes: 3824
import java.util.Scanner;

public class Main {

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

		String amoji = moji.substring(0,1) + (moji.length()-2) + moji.substring(moji.length()-1, moji.length());

		System.out.println(amoji);

		sc.close();
	}


}


Measured memory_bytes: 22100
n, m, x = gets.split.map(&:to_i)

a = []
c = []

n.times {
  c_i, *a_i = gets.split.map(&:to_i)
  c << c_i
  a << a_i
}

costs = [0]
skill = [[0] * m]

(0...n).each { |i|
  costs += costs.map { |d| d + c[i] }
  skill += skill.map { |s| s.zip(a[i]).map(&:sum) }
}

lea = costs.zip(skill).reject { |(_, ss)|
  ss.reject { |y| y < x }.length < m
}.transpose[0]

puts lea.nil? ? -1 : lea.min


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

int main(){

    int a,b;
    cin >>a >>b;
    if(a*b%2==0){
        cout << "Even" << endl;
    }else{
        cout << "Odd" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
 
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e6;
const int Nmax=2e5+1;
const int Nd=61;
 
 
 
int main(){
  ll n,d; cin>>n>>d;
  ll ans=0;
  rep(i,n){
    ll x,y;
    cin>>x>>y;
    if(x*x+y*y<=d*d){
      ans++;
    }
  }
  cout<<ans<<endl;
 

}

Measured memory_bytes: 3632
import math
import collections

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

p = primes(10000)
dic = collections.defaultdict(int)
N = int(input())
mod = 10**9 +7
for i in range(1, N+1):
    for j in p:
        while i % j == 0:
            dic[j] += 1
            i = i // j
    ans = 1
for c in dic.values():
    ans *= (c+1)
    ans %= mod
print(ans)

Measured memory_bytes: 3696
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

//定义变量
int a,b,c;
int sum=0;

int main(){

	cin>>a>>b>>c;
	sum=a+b+c;

	int ans=0;
	while (true){
		if (sum%3==0){
			int k=sum/3;
			if (k>=a && k>=b && k>=c) {cout<<ans<<endl;break;}
		}
		sum+=2;
		ans++;
	}

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 90000000000000000
signed main(void){
    string s;cin>>s;
    vector<string>V(7);
    V={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    rep(i,7){
        if(s==V[i]){
            cout<<7-i<<endl;
            return 0;
        }
    }
    
}
        

Measured memory_bytes: 256
N = int(input())
a = []

for i in range(N):
    x, y = map(str, input().split())
    a.append([x, int(y), i + 1])

a.sort(key=lambda x: x[1], reverse=True)
a.sort(key=lambda x: x[0])

for i in a:
    print(i[2])

Measured memory_bytes: 3060
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>

int main(void)
{
  int n, count = 0, ans = 0;
  scanf("%d", &n);
  std::string s, as, bs, os;
  std::cin >> s;

  for (int i = 0; i < n-1; i++) {
    count = 0;
    os = "";
    as = s.substr( 0, i+1 );
    bs = s.substr( i+1, n-1);

    for (int j = 0; j < i+1; j++) {
      if (os.find(as[j]) == std::string::npos) {
        if (bs.find(as[j]) != std::string::npos) {
          count++;
          os+=as[j];
        }
      }
    }
    if (count>ans) {
      ans = count;
    }
  }

  std::cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

void Solve(){
	int x,n;	cin >> x >> n;
	if(n == 0){
		cout << x << endl;
		return;
	}
	set <int> s;
	int Min = 10000, Ans;
	Rep(i,0,n){
		int num;	cin >> num;
		s.insert(num);
		if(abs(num-x) <= Min){
			Min = abs(num-x);
			Ans = num;
		}
	}
	int Ans2 = Ans;
	while(s.count(Ans)){
		Ans--;
	}
	while(s.count(Ans2)){
		Ans2++;
	}
	if(abs(x-Ans) == abs(x-Ans2)){
		cout << Ans << endl;
	}else{
		if(abs(x-Ans) < abs(x-Ans2)){
			cout << Ans << endl;
		}else{
			cout << Ans2 << endl;
		}
		//cout <<	(Ans?abs(x-Ans)<abs(x-Ans2):Ans2) << endl;
	}
}

int main(){
	ios::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	//int t;	cin >> t;
	while(t--) Solve();
	//system("pause");
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <list>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <bitset>
#include <string.h>
// #include <limits.h>

#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long        ll;
typedef unsigned long long    ull;

#define INTMAX  99999999

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

int A,B,C;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> A >> B >> C;

	if(A<=C && C<=B) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1000010;
ll n;
ll ans;
ll trie[N][26], quick[N][26], tot = 1;
ll sum[N], cnt[26];//子树和 
char s[N];
string t[200010];
map<string, int> mp;
void get_ans(ll p, ll len) {
	if (len == 1) {
		//可以不走当前字符 
		ans += quick[p][s[len] - 'a'];
		return;
	} else {
		//不可不走当前字符 
		if (trie[p][s[len] - 'a']) {
			get_ans(trie[p][s[len] - 'a'], len - 1);
		}
	}
}
void insert(int p, int len) {
	sum[p]++;
	if (!len) return;
	int k = s[len] - 'a';
	if (!trie[p][k]) {
		trie[p][k] = ++tot;
	}
	insert(trie[p][k], len - 1);
	cnt[k]++;
	for (int i = 0; i < 26; i++) {
		if (cnt[i]) {
			quick[p][i]++;
		}
	}
}
int main() {
	scanf("%lld", &n);
	for (ll i = 1; i <= n; i++) {
		cin >> t[i];
		for (int j = 0; j < t[i].length(); j++) {
			s[j + 1] = t[i][j];
		}
		ll len = t[i].length();
		get_ans(1, len);
		memset(cnt, 0, sizeof(cnt));
		insert(1, len);
	}
	memset(trie, 0, sizeof(trie));
	memset(quick, 0, sizeof(quick));
	memset(sum, 0, sizeof(sum));
	tot = 1;
	for (int i = n; i >= 1; i--) {
		for (int j = 0; j < t[i].length(); j++) {
			s[j + 1] = t[i][j];
		}
		ans -= mp[t[i]];
		ll len = t[i].length();
		get_ans(1, len);
		memset(cnt, 0, sizeof(cnt));
		insert(1, len);
		mp[t[i]]++;
	}
	printf("%lld", ans);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll r;cin>>r;
  out(setprecision(10)<<r*2*M_PI);

  return 0;
}


Measured memory_bytes: 3788
#include<bits//stdc++.h>
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
typedef long long int ll;
int main() {
    int n; cin >> n; ll ans= 0; vector<vector<ll>> dp(n, vector<ll>(n,1)), G(n, vector<ll>(n));
    rep(i, n) rep(j, n) cin >> G[i][j];
    rep(i, n) {
        rep(j, n) {
            rep(k, n) {
                if (G[i][j] > G[i][k] + G[k][j]) {
                    cout << -1 << endl;
                    return 0;
                }
                else if (k != i && k != j && G[i][j] == G[i][k] + G[k][j])dp[i][j] = 0;
            }
        }
    }
    rep(i, n) rep(j, n) if (dp[i][j]) ans += G[i][j];
    cout << ans/2 << endl;
}

Measured memory_bytes: 5048
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    a *= 100;  b*= 100;

    ll ans1 = 0, ans2 = 0;  // ans1 : すぬけ君が作る砂糖水の質量, ans2 : それに溶けている砂糖の質量
    double maxNoudo = 0.0;  // すぬけ君が作る砂糖水の濃度の最大値
    exrep(x1, 0, f/a) {  // 操作1をx1回行う
        exrep(x2, 0, (f - a*x1)/b) {  // 操作2をx2回行う
            ll water = a*x1 + b*x2;  // いまビーカーに入っている水の量
            ll lim = min(f - water, (water/100)*e);  // ビーカーに入れられる砂糖の量の上限
            exrep(x3, 0, lim/c) {  // 操作3をx3回行う
                exrep(x4, 0, (lim - c*x3)/d) {  // 操作4をx4回行う
                    ll sugar = c*x3 + d*x4;  // いまビーカーに入っている砂糖の量
                    if(water + sugar == 0) {  // ビーカーに砂糖も水も入っていないときはダメ
                        continue;
                    }
                    double noudo = (double)(100*sugar)/(double)(water + sugar);  // いまビーカーに入っている砂糖水の濃度
                    if(maxNoudo <= noudo) {
                        ans1 = water + sugar;
                        ans2 = sugar;
                        maxNoudo = noudo;
                    }
                }
            }
        }   
    }

    cout << ans1 << " " << ans2 << endl;
    re0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

s = gets.chomp
first = s[0..1].to_i
second = s[2..3].to_i

if 1 <= first and first <= 12
  if 1 <= second and second <= 12
    puts "AMBIGUOUS"
  else
    puts "MMYY"
  end
elsif first == 0
  if 1 <= second and second <= 12
    puts "YYMM"
  elsif second == 0
    puts "NA"
  else
    puts "NA"
  end
else # first == YY
  if 1 <= second and second <= 12
    puts "YYMM"
  elsif second == 0
    puts "NA"
  else
    puts "NA"
  end
end


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

int main()
{
    string s;
    cin>>s;
    int flag=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='7')flag++;
    }
    if(flag==0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
long long a[200010],b[200010];
using namespace std;

int main()
{
    int n,l;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);b[i]=a[i];

    }
    sort(b,b+n);l=n/2;
    for(int i=0;i<n;i++)
    {
        if(a[i]<=b[l-1])
          printf("%lld\n",b[l]);
        else
            printf("%lld\n",b[l-1]);
    }
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include "algorithm"
using namespace std;

int main() {
    int n;
    int *a;

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

    int sw = 0;
    for (int i = 0; i < n; i++) {
        for (int j = n -1; j >= i + 1; j--) {
            if (a[j] < a[j-1]) {
                swap(a[j], a[j-1]);
                sw++;
            }
        }
    }

    for (int i = 0; i < n ; i++) {
        if (i) cout << " ";
        cout << a[i] ;
    }
    cout << endl << sw << endl;
    return 0;
}



Measured memory_bytes: 3112
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
   let (mut x, mut y, mut z): (usize, usize, usize);
   input!(x, y, z);

   x ^= y;
   y ^= x;
   x ^= y;

   x ^= z;
   z ^= x;
   x ^= z;

   println!("{} {} {}", x, y, z);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    //cout<<s.size()<<endl;
    if(s.size()>n){
        string k= s.substr(0,n);
        cout<<k<<"...";
    } else cout<<s;
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
dp[s] = 状態sから全て開けるのに必要な最小コスト
*/

ll n,m,a[1010],b[1010],c[1010]={},dp[4097];

// ll f(ll s){
// 	if(s==(1<<n)-1)return 0;
// 	if(dp[s]!=1e18)return dp[s];
// 	ll ans=1e18;
// 	rep(i,m){
// 		if((s|c[i])!=s)ans = min(ans,f(s|c[i])+a[i]);
// 	}
// 	return dp[s]=ans;
// }

void init(){
	cin>>n>>m;
	rep(s,1<<n)dp[s]=1e18;
	rep(i,m){
		cin>>a[i]>>b[i];
		rep(j,b[i]){
			ll x;
			cin>>x;
			c[i]+=1<<(x-1);
		}
	}
}

int main(void){
	init();
	dp[0]=0;
	rep(i,m){
		rep(s,1<<n){
			dp[s|c[i]] = min(dp[s|c[i]],dp[s]+a[i]);
		}
	}
	// f(0);
	cout<<(dp[(1<<n)-1]==1e18?-1:dp[(1<<n)-1])<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e6+5;
int main()
{
	ll n;
	scanf("%lld",&n);
	int ans=0;
	for(int i=2;i<=N;i++){
		int cnt=0;
		while(n%i==0){
			n/=i;
			cnt++;
		}
		if(cnt){
			int t=0;
			int sum=0;
			for(int j=1;;j++){
				if(sum+j<=cnt){
					sum+=j;
					t++;
				}
				else{
					break;
				}
			}
			ans+=t;
		}
	}
	if(n>1){
		ans++;
	}
	printf("%d",ans);
}


Measured memory_bytes: 3836
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()

    ans = INF
    if H % 3 == 0 or W % 3 == 0:
        ans = 0
    else:
        # 同方向に分割する場合
        ans = min(H, W)

        # 分割方向を変える場合
        s = [0] * 3
        # 縦→横の場合と横→縦の場合
        for _ in range(2):
            s[0] = H * (W // 3)
            s[1] = (W - W // 3) * (H // 2)
            s[2] = (W - W // 3) * (H - H // 2)
            ans = min(max(s)- min(s), ans)
            s[0] = H * (W // 3 + 1)
            s[1] = (W - (W // 3 + 1)) * (H // 2)
            s[2] = (W - (W // 3 + 1)) * (H - H // 2)
            ans = min(max(s)- min(s), ans)
            H, W = W, H
       
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10112
n = input()

black = []
white = []
bit = 0
for i in range(len(n)):
    black.append(bit)
    white.append(bit ^ 1)
    bit ^= 1

black_cnt = 0
white_cnt = 0
for i in range(len(n)):
    if black[i] != int(n[i]):
        black_cnt += 1
    if white[i] != int(n[i]):
        white_cnt += 1

print(min(black_cnt, white_cnt))
    

Measured memory_bytes: 4852
import java.util.Scanner;

public class Main{


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

		int n = scan.nextInt();
		scan.nextLine();

		int[] array = new int[n];
		int max = 0;
		for (int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
			if (array[i] > max) {
				max = array[i];
			}
		}
		int[] result = new int[max + 3];
		int ans = 0;
		for (int i = 0; i < n; i++) {
			result[array[i]+1]++;
			result[array[i]]++;
			result[array[i] + 2]++;

		}
		int newMax = 0;
		for (int i = 0; i < max + 3; i++) {
			if (result[i] > newMax) {
				newMax = result[i];
			}
		}
		System.out.println(newMax);

	}

}


Measured memory_bytes: 50236
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include<iomanip>

#define int long long int
using namespace std;
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
int mod(int x)
{
    return (((x)%1000000007)+1000000007)%1000000007;
}

int solve()
{
   string s;
   cin>>s;
   int n=s.size();
   if(s[n-1]=='s')
   {
       cout<<s<<"es";
   }
   else
   {
       cout<<s<<"s";
   }
   return 0; 
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	int t;
	//cin >> t;
	t=1;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3648