akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;


int main(){
  long ii,jj,kk;
  vector<int> a;
  set<int> s;
  int q,c,x;

  cin >> q;
  set<int>::iterator it;
  for(ii=0;ii<q;ii++){
    cin >> c >> x;
    if(c == 0){
      s.insert(x);
      cout << s.size() << endl;
    }
    else if(c == 2){
      s.erase(x);
    }
    else{
      it = s.find(x);
      if(it != s.end()){
        cout << 1 << endl;
      }
      else{
        cout << 0 << endl;
      }
    }
  }
  
  return 0;
}



Measured memory_bytes: 12392
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = float('INF')
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


a, b = sorted(LS())
print(a * int(b))



Measured memory_bytes: 39664
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)
#define myforInv(i,N) for(i=N;i>=0;i--)
#define myforFLInv(i,f,l) for(i=f;i>l;i--)

using namespace std;

int main(){
	string S,T;
	int i,K;
	cin >> K;
	cin >> S;
	if(S.size()<=K)cout << S << endl;
	else {
		myfor(i,K){
			cout<< S[i];
		}
		cout << "..." << endl;
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i == 0){sum += abs(a[0]);}
        else{sum += abs(a[i] - a[i-1]);}
        if(i == n - 1){sum += abs(a[n-1]);}
    }
    for(int i = 0; i < n; i++){
        if(i == 0){
            cout << sum - (abs(a[i]) + abs(a[i+1]-a[i])) + abs(a[i+1]) << '\n';
        }else if(i == n - 1){
            cout << sum - (abs(a[i]-a[i-1]) + abs(a[i])) + abs(a[i-1]) << '\n';
        }else{
            cout << sum - (abs(a[i]-a[i-1]) + abs(a[i+1]-a[i])) + abs(a[i+1] - a[i-1]) << '\n';
        }
    }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define Rep(i,n) for(int i=0;i<n;i++)
#define Repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Inf 1LL<<60
#define All(v) v.begin(),v.end()
#define Mod (ll)(1e9+7)
using namespace std;
typedef long long ll;

int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll max=a*c;
    if(a*d>max) max=a*d;
    if(b*c>max) max=b*c;
    if(b*d>max) max=b*d;
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

H,W=map(int,input().split())

A=[list(map(int,input().split())) for i in range(H)]
B=[list(map(int,input().split())) for i in range(H)]

SA=[[0]*W for i in range(H)]

for i in range(H):
    for j in range(W):
        SA[i][j]=abs(A[i][j]-B[i][j])

DP=[[0 for i in range(W)] for j in range(H)]

DP[0][0]=1<<(H+W)*80+SA[0][0]

for i in range(H):
    for j in range(W):
        tempbit=DP[i][j]
        if i+1<H:
            DP[i+1][j]|=tempbit<<SA[i+1][j]
            DP[i+1][j]|=tempbit>>SA[i+1][j]

        if j+1<W:
            DP[i][j+1]|=tempbit<<SA[i][j+1]
            DP[i][j+1]|=tempbit>>SA[i][j+1]

ANS=1<<30
for i in range((H+W)*160+1):
    if 1<<i & DP[-1][-1]!=0:
        ANS=min(ANS,abs(i-(H+W)*80))

print(ANS)


Measured memory_bytes: 20468
while True:
    n=raw_input()
    if n in "0":break
    try:
        m=input()
    except SyntaxError:
        break
    S,L=set(),[]
    for i in range(m):
        a,b=map(int,raw_input().split())
        if a==1:
            S.add(b)
        elif b==1:
            S.add(a)
        else:
            L.append((a,b))
    for i in S:
        for s in L:
            if i in s:
                S=S.union(s)
    print len(S)

Measured memory_bytes: 5508
s = input()
a = [0] * len(s)
i = 0
while(i < len(s)):
  if(s[i] == 'R'):
    k = i + 1
    while(s[k] != 'L'):
      k += 1
    a[k] += (k-i)//2
    a[k-1] += k-i-(k-i)//2
    i = k
  i += 1
j = len(s) -1
while(j >= 0):
  if(s[j] == 'L'):
    l = j-1
    while(s[l] != 'R'):
      l -= 1
    a[l] += (j-l)//2
    a[l+1] += j-l- (j-l)//2
    j = l
  j -= 1
num = [str(i) for i in a]
print(" ".join(num))
      


Measured memory_bytes: 10876
N = int(input())
ans = []
A = [int(x) for x in input().split()]
moto = sum(A)
B = [int(x) for x in input().split()]
for i in reversed(range(N)):
  if A[i+1] >= B[i]:
    A[i+1] = A[i+1] -B[i]
  else:
    if A[i] >= (B[i] -A[i+1]):
      A[i] = A[i] + A[i+1] -B[i]
      A[i+1] = 0
    else:
      A[i+1] = 0
      A[i] = 0
print(moto-sum(A))
              

Measured memory_bytes: 19004
#include <iostream>
#include <vector>
#include <map>
#include <bitset>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <list>
#include <sstream>
#include <numeric>

#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;

const ll mod = 1000000007;
const ll inf = 9223372036854775803;
const int maxN = 300005;


int main() {
//    cout.precision(10);
//    cout << fixed;
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s1,s2;
    cin >> s1 >> s2;
    bool good = s2.length() == s1.length() + 1;
    if (good) {
        for (int i = 0; ( i < s1.length()) && good; i++) {
            good = s1[i] == s2[i];
        }
    }

    cout << (good ? "Yes" : "No");
    return 0;
}



Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define DIM 100007
#define INF 1000000007
using namespace std;

long long n,k,h[DIM],d[DIM];

int main()
{
    cin>>n>>k;
    for(int i = 1; i <= n; ++i)
        cin>>h[i];

    for(int i = n-1; i >= 1; --i)
        {d[i] = INF;
        for(int j = i+1; j <= min(i+k,n); ++j)
            d[i] = min(d[i],d[j]+abs(h[i]-h[j]));}

    cout<<d[1];
    return 0;
}


Measured memory_bytes: 1792
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( 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>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}


void main() {
    int n;
    R(n);
    VI a(n);
    map<int,int> mp;
    REP(i,n) {
        R(a[i]);
        mp[a[i]]++;
    }
    // sort(ALL(a));
    sort_uniq(a);
    int ans=0;
    n=a.size();
    REP(i,n) {
        REP1(j,i+1,n-1) {
            REP1(k,j+1,n-1) {
                if ( a[k]<a[i]+a[j] ) {
                    dump(i+1,j+1,k+1);
                    ans+=mp[a[i]]*mp[a[j]]*mp[a[k]];
                }
            }
        }
    }
    W(ans);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}

Measured memory_bytes: 3800
INT_MAX=10**11+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=======================================================================
import math as M
h,n=INPUT()
A=INPUT()
if sum(A)>=h:
    print("Yes")
else:
    print("No")


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

int main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N) {
        cin >> P.at(i);
        P.at(i)--;
    }
    rep(i, N) {
        cin >> Q.at(i);
        Q.at(i)--;
    }

    map<vector<int>, int> ord;
    int iter = 0;

    vector<int> v(N);
    for (int i = 0; i < N; ++i) v[i] = i;

    do {
        ord[v] = iter++;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(ord[P] - ord[Q]) << endl;
}


Measured memory_bytes: 5248
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N,M;cin>>N>>M;
  vector<ll> a(M);
  rep(i,M) cin>>a[i];

  SORT(a);

  vector<ll> m(M-1);

  rep(i,M-1){
    m[i] = a[i+1] - a[i];
  }

  SORT(m);
  ll ans = 0;
  rep(i,M-N){
    ans += m[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a, b,k;
    cin>>a>>b>>k;

    vector<int>v;
    for(int i=1;i<=100; i++)
    {
        if(a%i==0 && b%i==0)
        {
            v.push_back(i);
            //cout<<i<<" ";
        }
    }
    sort(v.begin(),v.end(),greater<int>());
   cout<<v[k-1]<<endl;
}


Measured memory_bytes: 256
import copy
h,w=map(int,input().split())
maze = [['#']+list(input())+['#'] for i in range(h)]
maze.insert(0,['#']*(w+2))
maze.append(['#']*(w+2))

def get_max_length_from_start(maze,x,y):
    ans_maze=[]
    min_now=1000000000
    max_length_list=[]
    tmp_maze=copy.deepcopy(maze)
    searching = [[y,x]]
    length=0
    while len(searching)!=0:
        next_searching_list=[]
        for point in searching:
            tmp_maze[point[0]][point[1]]=length
            mawari = [[point[0]+1,point[1]],[point[0]-1,point[1]],[point[0],point[1]+1],[point[0],point[1]-1]]
            next_searching = list(filter(lambda x:tmp_maze[x[0]][x[1]]==".",mawari))
            if len(next_searching)==0:
                max_length_list.append(length)
                continue
            next_searching_list += next_searching
        searching = list(map(list, set(map(tuple, next_searching_list))))
        length+=1
    return max(max_length_list)

true_max_length_list=[]
for y in range(1,h+1):
    for x in range(1,w+1):
        if maze[y][x]=='#':
            continue
        max_length=get_max_length_from_start(maze,x,y)
        true_max_length_list.append(max_length)

print(max(true_max_length_list))

Measured memory_bytes: 3568
X, Y = map(int, input().split())

if X == 1 and Y == 1:
    print(1000000)

elif (X == 1 and Y == 2) or (X == 2 and Y == 1):
    print(500000)

elif (X == 1 and Y == 3) or (X == 3 and Y == 1) or (X == 2 and Y == 2):
    print(400000)

elif (X == 1 and Y >= 4) or (X >= 4 and Y == 1) or (X == 2 and Y == 3) or (X == 3 and Y == 2):
    print(300000)

elif (X == 2 and Y >= 4) or (X >= 4 and Y == 2) or (X == 3 and Y == 3):
    print(200000)

elif (X == 3 and Y >= 4) or (X >= 4 and Y == 3):
    print(100000)

else:
    print(0)

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    set<int> st;
    for(int i = 1; i <= 9; i++) {
        for(int j = 1; j <= 9; j++) {
            st.insert(i * j);
        }
    }
    int n;
    cin >> n;
    cout << (st.count(n) ? "Yes\n" : "No\n");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[]){
  int n,a[100],i,r,sub;
  int cmin = 201,imin,sum = 0,csum=0;
  
  scanf("%d",&n);
  for(i = 0; i < n; i++){
  	scanf("%d",&a[i]);
    sum += a[i];
  }
  
  for(i = 0; i < n; i++){
    csum += a[i];
    sub = sum - 2*csum;
    if(sub < 0) sub = -sub;
    if(sub < cmin){
      cmin = sub;
    }
  }
  
  printf("%d",cmin);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <fstream>
#include <stdlib.h>
#include <ctime>
using namespace std;
typedef long long ll;
int n=0;
int sz=1;
int x,y;
int c[200000][17];
int a[17];
int b[17];
pair<pair<int,int>,int> h[17];
bool cmp(pair<pair<int,int>,int> a1,pair<pair<int,int>,int> b1){
    if(a1.first.first==a1.first.second) return 0;
    if(b1.first.first==b1.first.second) return 1;
    return 0;
}
int ans[200000];
int main(){
    //ios_base::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);
    cin>>n;//n=1?
    for(int i=0;i<n;i++)sz*=2;
    cin>>x;
    cin>>y;
    int sum=0;
    for(int i=0;i<n;i++){
        h[i].first.first=x%2;
        x/=2;
        h[i].first.second=y%2;
        y/=2;
        h[i].second=i;
    }    
    sort(h,h+n,cmp);
    for(int i=0;i<n;i++){
        a[i]=h[i].first.first;
        b[i]=h[i].first.second;
        sum+=a[i];
        sum+=b[i];
       // cout<<a[i]<<" "<<b[i]<<endl;
    }
    if(sum%2==0){
        cout<<"NO";
        return 0;
    }
    int d=sz;
    int j=1;
    d/=2;
    for(int i=0;i<d;i++){
        c[i][0]=a[0];
    }
    for(int i=d;i<sz;i++){
        c[i][0]=b[0];
    }
    for(;j<n;j+=2){
        if(a[j]==b[j]) break;
        d/=4;
        int ss=a[j];
        int ss2=a[j+1];
        int i=0;
            
            for(;i<8*d;i++){
                if(i==d || i==3*d || i==6*d){
                    ss=1-ss;
                }
                if(i==2*d || i==5*d || i==7*d){
                    ss2=1-ss2;
                }
                c[i][j]=ss;
                c[i][j+1]=ss2;
            }
            
            for(;i<sz;i++){
                if(i%(2*d)==0 && i%(4*d)!=0){
                    ss=1-ss;
                }
                if(i%d==0 && i%(2*d)!=0){
                    ss2=1-ss2;
                }
                c[i][j]=ss;
                c[i][j+1]=ss2;
            }
    }
    while(j<n){
        d/=2;
        int ss=a[j];
        for(int i=0;i<sz;i++){
            if(i%d==0 && i%(2*d)!=0){
                ss=1-ss;
            }
            c[i][j]=ss;
        }
        j++;
    }
   // for(int i=0;i<n;i++){
  //      for(int j=0;j<sz;j++){
  //          cout<<c[j][i]<<" ";
  //      }
   //     cout<<endl;
   // }
    cout<<"YES\n";
    for(int i=0;i<sz;i++){
        for(int j=0;j<n;j++){
            ans[i]+=c[i][j]*pow(2,h[j].second);
            
            //cout<<h[j].second<<" ";
        }
        cout<<ans[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    string s;
    stringstream sstm;
    sstm << a << b;
    s = sstm.str();
    istringstream is(s);
    int val;
    is>>val;
    for(int i=1;i<=1000;i++){
        if(i*i == val){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){
	int d;
	while(scanf("%d", &d) && d != 0){
		int S[100009];
		int n,m;
		int temp;
		int l,ls,ss;
		int ans= 0;
		
		scanf("%d%d", &n, &m);
		
		S[0] = 0;
		S[n] = d;
		
		for(int i = 1; i < n; i++){
			scanf("%d", &S[i]);
		}
		
		sort(S,S+n);
		
		for(int i = 0; i < m; i++){
			scanf("%d", &temp);
			int *mx = upper_bound(S,S+n+1,temp);
			ls = mx - S;
			ss = mx -1 -S;
//			printf("S[%d] = %d : S[%d] = %d\n", ls, S[ls], ss, S[ss]);
			
			l = min( S[ls]-temp, temp-S[ss]);
//			printf("%d\n",l);
			ans+=l;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1156
#include<iostream>

using namespace std;

int dis(int s,int e,int r){
  //cout << s<<e<<r<<endl;
    return min(abs(e-s),e-s+r);
}


int main(){
    int radius,total;
    cin >> radius >> total;
    int a[total];
    for(int i = 0;i<total;i++){
        cin >> a[i];
    }
  int tmp=0;
    for(int i=0;i<total;i++){
      	tmp=max(tmp,dis(a[i],a[(i+1)%total],radius));
        //tmp=max(tmp,dis(a[i],a[i-1+radius%total],radius));
        //cout << tmp << endl;
    }
	tmp-=radius;
    cout << abs(tmp) << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    char c, ans;
    cin >> c;
    if(c=='A')ans = 'T';
    else if(c=='T') ans = 'A';
    else if(c=='C') ans = 'G';
    else ans = 'C';
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool right(char c){
  string r = "qwertasdfgzxcvb";
  for(int i=0;i<r.length();++i) if(c==r[i]) return true;
  return false;
}
bool left(char c){
  string l = "yuiophjklnm";
  for(int i=0;i<l.length();++i) if(c==l[i]) return true;
  return false;
}
int solve(string s){
  int cnt = 0;
  for(int i=0;i+1<s.length();++i){
    if(right(s[i])&&left(s[i+1])) ++cnt;
    else if(left(s[i])&&right(s[i+1])) ++cnt;
  }  
  return cnt;
}
int main(){
  string s;
  while(cin>>s,s!="#")
    cout << solve(s) << endl;
  return 0;
}

Measured memory_bytes: 1192
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let t: usize = v.iter().cloned().sum();
    let mut ans = usize::max_value();
    let mut cum = 0;
    for i in 0..n - 1 {
        cum += v[i];
        if t > 2 * cum {
            ans = min(ans, t - 2 * cum);
        } else {
            ans = min(ans, 2 * cum - t);
        }
    }
    println!("{}", ans);
}


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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define bp __builtin_popcount
#define cr const reg&
using namespace std;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

int a[1024][1024];

int main() {
	reg n = read(), m = read();
	fo(i, 1, (1 << n) - 1) {
		fo(j, 1, (1 << m) - 1) {
			a[i][j] = bp(i & j) & 1;
			reg c = a[i][j] ^ a[i - 1][j] ^ a[i][j - 1] ^ a[i - 1][j - 1];
			putchar(!c ? '0' : '1');
		} puts("");
	}
	return 0;
}



Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
const int M=1e9+7;
int f[65][2][2],dl[65],dr[65];
ll l,r;
int dfs(int pos,bool fl,bool fr){
	if (!pos) return 1;
	int &t=f[pos][fl][fr];
	if (~t) return t;
	t=0;int up=fr?dr[pos]:1,dn=fl?dl[pos]:0;
	for (int y=dn;y<=up;y++)
		for (int x=dn;x<=y;x++) (t+=dfs(pos-1,fl&(x==dn),fr&(y==up)))%=M;
	return t;
}
int solve(ll l,ll r){
	int lenl=0,lenr=0;
	for (;l;l>>=1) dl[++lenl]=l&1;
	for (;r;r>>=1) dr[++lenr]=r&1;
	int ans=0;
	for (int i=lenl;i<=lenr;i++) (ans+=dfs(i-1,i==lenl,i==lenr))%=M;
	return ans;
}
signed main(){
	memset(f,-1,sizeof(f));
	scanf("%lld%lld",&l,&r);
	printf("%d",solve(l,r));
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
  int a, b, c, n;
  while(cin >> a >> b >> c){
    if(a == 0 && b == 0 && c == 0) break;
    cin >> n;
    int E[1001], M[1001], K[1001];
    bool r[1001];
    
    for(int i = 0 ; i < n ; i++){
      cin >> E[i] >> M[i] >> K[i] >> r[i];
    }
    
    int exam[310];
    fill(exam, exam+310, 2);
    
    for(int i = 0 ; i < n ; i++){
      if(r[i]){
	exam[E[i]] = 1;
	exam[M[i]] = 1;
	exam[K[i]] = 1;
      }
    }
    
    for(int i = 0 ; i < n ; i++){
      if(!r[i]){
	if(exam[E[i]] == 1 && exam[M[i]] == 1) exam[K[i]] = 0;
	if(exam[E[i]] == 1 && exam[K[i]] == 1) exam[M[i]] = 0;
	if(exam[M[i]] == 1 && exam[K[i]] == 1) exam[E[i]] = 0;
      }
    }
    
    for(int i = 1 ; i <= a + b + c ; i++){
      cout << exam[i] << endl;
    }
  }
  return 0;
}


    

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

using namespace std;

#define endl "\n"
#define int long long 
#define test int qt;cin>>qt;while (qt--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

int32_t main()
{
    int n ;cin>>n;
    cout<<(n%1000==0?0:1000-n%1000);
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define assem99 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define endll '\n'
#define sz(a) (int)(a).size()
#define RWFile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int dx[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int dy[] = { -1, 0, 1, 0, 1, -1, -1, 1 };
const int MOD = 1e9 + 7, N = 2e6 + 5, oo = 1e9;
const double pi = acos(-1);
using namespace std;

int arr[N];

int main()
{
    assem99
    int n; cin>>n;
    vector<int> a, b, c;
    for(int i = 0; i < n; i++)
    {
        int x; cin>>x;
        a.push_back(x);
    }
    for(int i = 0; i < n; i++)
    {
        int x; cin>>x;
        b.push_back(x);
    }
    for(int i = 0; i < n; i++)
    {
        int x; cin>>x;
        c.push_back(x);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    for(auto it : b)
    {
        ll i = upper_bound(a.begin(), a.end(), it - 1) - a.begin();
        ll j = c.end() - upper_bound(c.begin(), c.end(), it);
        ans += (i * j);
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 4676
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for ( auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);blockTime.second;\
debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define li long long int
#define ld long double
#define eb push_back
#define pb pop_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define size(a) a.size()
#define rev(a) reverse(a.begin(),a.end())
#define len(a) a.length()
#define f first
#define s second
#define sort(a) sort(a.begin(),a.end())
#define vli vector<li>
#define vvli vector<vli >
#define pli pair<li,li>
#define vpli vector<pli>
#define inp(t) li t;cin>>t; while(t--)
using namespace std;
const li mod = 1e9+7;
#define MAXN 1000005 

li power(li a, li b) { a%=mod; li ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
li add(li a,li b) { return (((a%mod)+(b%mod))%mod);}
li sub(li a,li b) { return (((a%mod)-(b%mod))%mod);}
li mul(li a,li b) { return (((a%mod)*(b%mod))%mod);}

bool isprime(li n)
{
  if (n == 1)
    return false;
  int i = 2;
  while (i*i <= n){
      if (n % i == 0)return false;
      i += 1;
  }
  return true;
}

li lcm(li a,li b)
{
    return ((a*b)/__gcd(a,b));
}

void solve()
{
  vli v(5);

  rep(i,0,5)
  cin>>v[i];

  rep(i,0,5)
  {
    if(v[i]==0)
    {
      cout<<i+1<<endl;
      return;
    }
  }
}
int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    solve();
    return 0;
}

Measured memory_bytes: 3612
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXS 262144
#define MO 1000000007
int dp[2][MAXS+5];
using namespace std;
int N,X,Y,Z;
int PowMod(int a,int b)
{
	int ret=1;
	a%=MO;
	while(b)
	{
		if(b&1)
			ret=1LL*ret*a%MO;
		a=1LL*a*a%MO;
		b>>=1;
	}
	return ret;
}
int main()
{
	scanf("%d %d %d %d",&N,&X,&Y,&Z);
	int tot=(1<<(X+Y+Z-1));
	int all=(1<<(X+Y+Z));
	dp[0][0]=1;
	int ans=0;
	for(int i=1;i<=N;i++)
	{
		int id=i%2;
		for(int s1=0;s1<all;s1++)
			for(int k=1;k<=10;k++)
			{
				int s2=((s1<<k)+(1<<(k-1)))%all;
				dp[id][s2]=(1LL*dp[id][s2]+dp[!id][s1])%MO;
			}
		for(int s2=0;s2<all;s2++)
		{
			if((s2&tot)&&((1<<(Y+Z-1))&s2)&&((1<<(Z-1))&s2)&&(dp[id][s2]!=0))
				ans=(1LL*ans+1LL*dp[id][s2]*PowMod(10,N-i)%MO)%MO,dp[id][s2]=0;
		}
		memset(dp[!id],0,sizeof(dp[!id]));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main() {
  long n;
  cin >> n;
  long b = 0;
  long a = sqrt(n);

  rep(i, a){
    if (n % (i+1) == 0){
      b = n / (i+1);
    }
  }
  cout << to_string(b).size() << endl;
  return 0;
}


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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    int n;
    cin>>n;
    vector<int>v(n);
    for(auto &c:v) cin>>c;
    if(n==1 || n==2)
        cout<<1<<endl;
    else{
        int i=1;
        while(v[i]==v[i-1] && i<n)
            i++;
        int inc=false;
        if(v[i]>v[i-1])
            inc=true;
        int cnt=1;
        for(int j=i;j<n;)
        {
            if(v[j]==v[j-1] || (inc && v[j]>v[j-1]) || (!inc && v[j]<v[j-1]))
                j++;
            else
            {
                cnt++;
                if(j==n-1)
                {
                    break;
                }
                else{
                    j+=1    ;
                    while(v[j]==v[j-1] && j<n)
                        j++;
                    inc = j < n && v[j] - v[j - 1] > 0;

                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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

fn main(){
  loop {
    let n: usize = read();

    if n == 0 { break; }

    let mut adj: Vec<Vec<usize>> = vec![vec![0;26];26];
    let mut set: HashSet<usize> = HashSet::new();
    let mut uf: UnionFind = UnionFind::new(26);
    
    for _ in 0 .. n {
      let s:String = read();
      let h = s.chars().next().unwrap() as usize - 97;
      let t = s.chars().last().unwrap() as usize - 97;
      adj[h][t] += 1;
      set.insert(h);
      set.insert(t);
      uf.unite(h, t);
    }

    let mut link = true;
    let sl = set.len();
    
    for i in set.iter() {
      if sl != uf.size(*i) {
        link = false;
        break;
      }
    }

    let mut eg = true;

    for i in 0 .. 26 {
      let mut sr = 0;
      for j in 0 .. 26 {
        sr += adj[i][j];
      }
      let mut sc = 0;
      for j in 0 .. 26 {
        sc += adj[j][i];
      }
      if sr != sc {
        eg = false;
        break;
      }
    }
    
    println!("{}", if link && eg { "OK" } else { "NG" });

  }
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

#[derive(Debug)]
struct UnionFind {
  p: Vec<isize>
}

#[allow(dead_code)]
impl UnionFind {
  fn new(n: usize) -> UnionFind {
    UnionFind {
      p: vec![-1;n]
    }
  }

  fn root(&mut self, a: usize) -> usize {
    let u = self.p[a];
    if u < 0 { a }
    else {
      let rt = self.root( u as usize);
      self.p[a] = rt as isize;
      rt
    }
  }

  fn unite(&mut self, a: usize, b: usize){
    let ra = self.root(a);
    let rb = self.root(b);

    if ra != rb {
      if self.p[ra] < self.p[rb] {
        self.p[ra] = self.p[ra] + self.p[rb];
        self.p[rb] = ra as isize;
      } else {
        self.p[rb] = self.p[ra] + self.p[rb];
        self.p[ra] = rb as isize;
      }
    }
  }

  fn same(&mut self, a: usize, b:usize) -> bool {
    self.root(a) == self.root(b)
  }

  fn size(&mut self, a: usize) -> usize {
    let ra = self.root(a);
    (-1 * self.p[ra]) as usize
  }
}



Measured memory_bytes: 5048
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
#define INF 999999999
#define lint long long
#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define rep0(i, n) for(int i = 0; i < (int)(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
    lint N, M;
    cin >> N >> M;
    if (N > M / 2) { cout << M / 2; return 0; }
    cout << N + (M - N * 2) / 4;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

const double PI = atan(1.0) * 4;
double x[1001];
double y[1001];

int main() {
    x[1] = 1; y[1] = 0;
    for (int i=2; i<=1000; ++i) {
        double rad = atan2(y[i-1], x[i-1]) + (PI / 2.0);
        x[i] = x[i-1] + cos(rad);
        y[i] = y[i-1] + sin(rad);
    }
    int n;
    while (cin >> n, 0 < n) {
        cout.precision(2);
        cout << fixed;
        cout << x[n] << endl << y[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 1324
#include<bits/stdc++.h>
using namespace std;
int main(){
    char a[105];
    int b,ans=0;
    vector<int> kazu(30);

    cin>>a;

    b=strlen(a);
for(int i=0;i<b;i++){
        ans=(int)(a[i])-97;
        //cout<<ans<<" ";
        kazu[ans]++;
        if(kazu[ans]>1){
            kazu[ans]=0;
        }
    }

    for(int j=0;j<30;j++){
        ans=0;
        if(kazu[j]!=0){
           // cout<<"あ";
            ans=1;
            break;
        }
    }


    if(ans==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

//    cout<<(int)(a)<<endl;
/*
if(a<=0&&b>=0||a==0||b==0){
        cout<<"Zero"<<endl;
    }else if(b<0&&(a-b)%2==0){
        cout<<"Negative"<<endl;
    }else{
        cout<<"Positive"<<endl;
    } 
*/
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int INF=1000000000;
int n,d[100];
int G[100][100];
void dijkstra(int s){
    fill(d,d+n,INF);
    bool used[n]={false};
    d[s]=0;
    while(true){
	int v=-1;
	for(int u=0;u<n;u++){
	    if(used[u]) continue;
	    if(v==-1||d[u]<d[v]) v=u;
	}
	if(v==-1) break;
	used[v]=true;
	
	for(int u=0;u<n;u++){
	    d[u]=min(d[u],d[v]+G[v][u]);
	}
    }
}
int main(){
    cin>>n;
    fill(G[0],G[n],INF);
    for(int i=0;i<n;i++){
	int u,k;
	cin>>u>>k;
	for(int j=0;j<k;j++){
	    int v,c;
	    cin>>v>>c;
	    G[u][v]=c;
	}
    }
    dijkstra(0);
    for(int i=0;i<n;i++){
	cout<<i<<' '<<d[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define rep(i, n)     for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n)    for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n)    for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n)   for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v)  for (auto &&V : v)
#define all(x)        (x).begin(), (x).end()
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = 1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;

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

  int n, x;
  cin >> n >> x;
  set<int> l{0};
  int bf = 0;
  rep (i, n) {
    int x;
    cin >> x;
    bf += x;
    l.insert(bf);
  }
  cout << distance(l.begin(), l.upper_bound(x)) << endl;
  return 0;
}

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

# define    ll            long long 
# define    vi             std::vector<int>
# define    int            long long 
# define    setbits(x)     __builtin_popcountll(x)
# define    zrobits(x)     __builtin_ctzll(x)
# define    fast           ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
# define    pb             push_back
# define    fn             for(int i=0;i<n;i++)
# define    rep(i,a,b,c)      for(ll i=a;i<b;i+=c)
# define    all(x)         x.begin(), x.end()
# define    allr(a)        a.rbegin(), a.rend()
# define    PI             3.14159265358979323846
# define    mod            1000000007
# define    endl           "\n"
# define    pii            pair<ll,ll>
# define    deb1(x)        cout<<#x<<" "<<x<<endl;
# define    deb2(x,y)      cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
# define    deb3(x,y,z)    cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
 
void getio();

const ll one = 5009;
ll p[one], c[one], usethis[one], vis[one], iskiValue[one];
void solve(){
	ll t, i, x, j, y, 	z;
	z = -LLONG_MAX;
	ll n,k;
	cin>>n>>k;
	fn{
		cin >> p[i];
		p[i]--;
	}
	fn cin >> c[i];
	
	fn {
		if (!vis[i]) {
			vector<ll> v;
			j = i;	
			t = 0;
			while(!vis[j]) {
				vis[j] = 1; v.push_back(j); t += c[j];j=p[j];
			}
			for (auto zx : v) {
				usethis[zx] = v.size(); iskiValue[zx] = t;
			}
		}
	}
	fn vis[i] = 0;
	
	fn {
		ll reps = max(0LL, (k - usethis[i]) / usethis[i]);t = reps * iskiValue[i];		if (t < 0)	t = 0;ll left = k % usethis[i];if (k >= usethis[i])	left += usethis[i];
		j = p[i];
		while (left--) {
			t += c[j]; z = max(z, t);j = p[j];
		}
	}
	cout<<z<<endl;
}


int32_t main()
{
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	getio();
	// sieve();
    // int t; cin>>t; while(t--) 
    solve();
}

void getio()
{
    fast
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

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

int main(void) {
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double th = (h * 60 + m) / (12.0 * 60);
  double tm = m / 60.0;

  double hx = a * cos(th * 2 * acos(-1));
  double hy = a * sin(th * 2 * acos(-1));

  double mx = b * cos(tm * 2 * acos(-1));
  double my = b * sin(tm * 2 * acos(-1));

  double dx = abs(hx - mx);
  double dy = abs(hy - my);
  cout << setprecision(15) <<sqrt(dx * dx + dy * dy) << endl;
  return 0;
}


Measured memory_bytes: 4128
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        if k<0 or n<k:
            return 0
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

N,A=ilint()
ans=0
beki2=[2**(59-i) for i in range(60)]
S=[0]*60
B=list(map(lambda x:bin(x)[2:].zfill(60),A))

def f(x):
    global S
    for i in range(60):
        S[i]+=int(x[i])

f(B[N-1])
for i in range(N-2,-1,-1):
    for j in range(60):
        ans += beki2[j]*S[j] if B[i][j]=='0' else beki2[j]*(N-1-i-S[j])
        ans %= MOD
    f(B[i])
    
print(ans)

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

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    int d = b-a;
    int ans = d*(d+1)/2 - b;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 50000000
using namespace std;
int n,minn=N;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,sum=0;
		scanf("%d",&x);
		while(x%2==0) x/=2,sum++;
		minn = min(minn,sum);
	}
	printf("%d",minn);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a=1e9,b=1e9;
	while(cin >> a >> b){
		int ans=0;
		a+=b;
		while(a!=0){
			ans++;
			a/=10;
		}
		a=1;b=1;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 2996
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; // find_by_order(), order_of_key()
using ll = long long int;
using i64 = long long int;
#define SZ(v) (int((v).size()))
#define ALL(vec) (vec).begin(),(vec).end()
template <typename T> inline void ckmax(T &x, T y) {if (y > x) x = y; }
template <typename T> inline void ckmin(T &x, T y) {if (y < x) x = y; }
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " =: " << a << endl;
    err(++it, args...);
}
template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& buf) {
    return os << "(" << buf.first << ": " << buf.second << ")";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v) {
    bool first = true;
    os << "[";
    for(unsigned int i = 0; i < v.size(); i++) {
        if(!first) os << ", ";
        os << v[i];
        first = false;
    }
    return os << "]";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const multiset<T>& v) {
    bool first = true;
    os << "{";
    for (auto ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii;
        first = false;
    }
    return os << "}";
}
inline std::ostream &operator << (std::ostream & os,const std::multiset<pair<int,int>,greater<pair<int,int>>>& v) {
    bool first = true;
    os << "{";
    for (auto x: v) {
        if(!first) os << ", ";
        os << x;
        first = false;
    }
    return os << "}";
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v) {
    bool first = true;
    os << "{";
    for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii ;
        first = false;
        return os << "}";
    }
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const vector<vector<T>>& v) {
    for (auto &u: v) os << '\n' << u;
    return os;
}
template<typename T>
void finish(T ans) {cout << ans << '\n'; exit(0);}
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double EPS = 1e-6;
#define PI 3.14159265358979323846
/***********************************************************************/

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

    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << ' ' << max(0, a + b - n) << '\n';
    
    return 0;
}



Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        if self.parents[y] < self.parents[x]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def solve():
    N, M = map(int, input().split())
    A, B = [0] * M, [0] * M
    for i in range(M):
        A[i], B[i] = map(lambda x: int(x) - 1, input().split())
    
    disconnect = []
    d = N * (N - 1) // 2
    uf_tree = UnionFind(N)
    for ai, bi in zip(A[::-1], B[::-1]):
        disconnect.append(d)
        if uf_tree.find(ai) != uf_tree.find(bi):
            d -= uf_tree.size(ai) * uf_tree.size(bi)
            uf_tree.union(ai, bi)
    
    for ans in disconnect[::-1]:
        print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 97496
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    ll H, N;
    cin >> H >> N;
    vector<ll> A(N), B(N);
    int tmp = 0;
    REP(i, N){
        cin >> A[i] >> B[i];
        tmp = max(tmp, A[i]);
    }
    vector<ll> res(H+tmp+1, 1e10);

    res[0] = 0;
    REP(i, N){
        REP(j, H) res[j+A[i]] = min(res[j+A[i]], res[j]+B[i]);
    }
    ll ans = 1e9;
    for(int i = H; i < H + tmp + 1; i++) ans = min(ans, res[i]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384