akhauriyash/Code-Regression huggingface dataset:
import bisect
import heapq
import sys
import queue


input = sys.stdin.readline
sys.setrecursionlimit(100000)


class V:
    def __init__(self, f):
        self.f = f
        self.v = None

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n)

    def get(self):
        return self.v


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    N = int(input())

    left = 0
    right = N - 1
    D = {}
    c = 0
    for _ in range(21):
        if left not in D:
            print(left)
            sys.stdout.flush()
            res = input()
            c += 1
            if res == "Vacant" or c >= 20:
                return

            D[left] = res

        LD = D[left]
        m = (left + right) // 2

        if m not in D:
            print(m)
            sys.stdout.flush()
            res = input()
            c += 1
            if res == "Vacant" and c >= 20:
                return

            D[m] = res

        MD = D[m]

        if (m % 2 == left % 2 and MD == LD) or (m % 2 != left % 2 and MD != LD):
            left = m if left != m else m + 1
        else:
            right = m


if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, x); }
template<class T, class U> void init(vector<T> &v, U x, size_t n, size_t m...) { v=vector<T>(n); for(auto& a : v) init(a, x, m);}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int k;
    cin >> k;
    int n = 1;
    int r = 7 % k;
    vector<bool> v(k);
    while(1){
        if (v[r])
            break;
        if (r == 0){
            cout << n << endl;
            return 0;
        }
        v[r] = 1;
        r = (r * 10 + 7) % k;
        n++;
    }
    cout << -1 << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}



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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	int n,m,k;
	cin>>n>>m>>k;
	int a[n],b[m];
	ll suma[n+1]={},sumb[m+1]={};
	int x=0,y=0;
	rep(i,n){
		cin>>a[i];
		suma[i+1]=suma[i]+a[i];
		if(k-suma[i+1]>=0)x=i+1;
		
	}
	rep(i,m){
		cin>>b[i];
		sumb[i+1]=sumb[i]+b[i];
		if(k-sumb[i+1]>=0)y=i+1;
	}
	
	int ans=0,c=0,maxi=0;
	if(x>=y){
		maxi=x;
		for(int i=x;i>0;i--){
			ans=i;
			while(k-suma[i]-sumb[c]>=0){
				maxi=max(ans+c,maxi);
				if(c==y)break;
				c++;
			}
			if(c==y)break;
		}
	}
	else {
		maxi=y;
        for(int i=y;i>0;i--){
			ans=i;
            while(k-sumb[i]-suma[c]>=0){
				maxi=max(ans+c,maxi);
				if(c==x)break;
				c++;
            }
			if(c==x)break;
        }

	}

	cout<<maxi<<endl;

	return 0;
}


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

int main() {
  int t[2];
  cin >> t[0] >> t[1];
  sort(t, t+2);
  
  //if((t[1] - t[0])%2 != 0){
  
  for(int i = t[0]; i < t[1]; i++){
    if((t[1]-i) == (i-t[0])){
      cout << i << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))


(let* ((n (read))
	   (k (read))
	   (h (concatenate 'vector (sort (loop repeat n collect (read)) #'<))))
  (princ (loop for i below (- n k) sum (aref h i))))


Measured memory_bytes: 64564
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

int distance_is_integer(std::vector<int>& a,std::vector<int>& b)
{
	int square_distance = 0;
	for(int i=0;i<a.size();i++) square_distance+=(a[i]-b[i])*(a[i]-b[i]);
	for(int i=0;i<400;i++) {
		if(i*i==square_distance) return 1;
		if(i*i>square_distance) return 0;
	}
	return 0;
}
signed main() {
	int n,d;
	std::cin >> n >> d;
	std::vector<std::vector<int> > points(n,std::vector<int>(d));
	rep(i,n)rep(j,d)std::cin >> points[i][j];
	int count = 0;
	for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) {count+=distance_is_integer(points[i],points[j]);}
	print(count);
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    map<int, int> mp;
    for (int i=1; i<=3; ++i) {
        int x;
        cin >> x;
        mp[x]++;
    }
    for (auto& x : mp) {
        if (x.second == 2) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define all(vvv) vvv.begin(), vvv.end()
#define sz size()
#define mp make_pair
#define f first
#define s second
int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if(a[0] == a[1] && a[1] != a[2]) cout << "Yes";
	else if(a[1] == a[2] && a[0] != a[1]) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 2e9
#define ALL(v) v.begin(), v.end()
string s;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    int si=s.length();
    s=s.c_str();
    int count =0;
    for(int i =0;i<si;i++){
        if(s[i]=='x'){
            count++;
        }
    }
    if(15-count>=8){
        YES;
        return 0;
    }

   NO;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {

        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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


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

fn main() {
    input! {
        d: usize,
        g: i64,
        pc: [(i64, i64); d],
    }
    let ans = (0..1 << d).fold(std::i64::MAX, |r, i| {
        let mut cnt = 0;
        let mut pnt = 0;
        for j in 0..d {
            if i & (1 << j) != 0 {
                cnt += pc[j].0;
                pnt += pc[j].0 * (j + 1) as i64 * 100 + pc[j].1;
            }
        }
        for j in (0..d).rev() {
            if pnt >= g {
                break;
            }
            if i & (1 << j) == 0 {
                let last_cnt = std::cmp::min((g - pnt) / ((j + 1) as i64 * 100), pc[j].0 - 1);
                cnt += last_cnt;
                pnt += last_cnt * (j + 1) as i64 * 100;
            }
        }
        if pnt >= g {
            std::cmp::min(r, cnt)
        } else {
            r
        }
    });
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define prt_cs                  printf("Case %lld: ",cs)
#define sqr(x)                  (x)*(x)
#define ms(a,b)                 memset(a, b, sizeof(a))
#define db                      double
#define ll                      long long int
#define MOD                     100000007
#define PI                      2*acos(0.0)
#define pii                     pair< int, int >
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
#define gcd(a, b)               __gcd(a, b)
#define lcm(a, b)               (((a)*(b))/gcd(a,b))
#define MAX                     100005
#define MM                      (ll)(1e18)+7
using namespace std;

ll mat[301][301],nxt[301][301],adj[301][301];

int main()
{
//    READ;
//    WRITE;
//    cerr<<MM<<endl;
    for(int i=0;i<301;i++)
        for(int j=0;j<301;j++)
        {
            mat[i][j]= i==j?0:MM;
        }
    int n,m,L;
    scanf("%d %d %d",&n,&m,&L);
    for(int i=0;i<m;i++)
    {
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
            mat[a][b]=c;
            mat[b][a]=c;
    }
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            {
                mat[i][j]=min(mat[i][j],mat[i][k]+mat[k][j]);
            }
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            {
                adj[i][j]=MM;
                if(i==j)
                {
                    adj[i][j]=0;
                    continue;
                }
                if(mat[i][j]<=L)adj[i][j]=1;
            }
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            {
//                if(adj[i][k]==-1 || adj[k][j]==-1)continue;
//                if(adj[i][j]==-1 || adj[i][j]>adj[i][k]+adj[k][j])
//                {
//                    adj[i][j]=adj[i][k]+adj[k][j];
//                    nxt[i][j]=nxt[i][k];
//                }
                    adj[i][j]=min(adj[i][j],adj[i][k]+adj[k][j]);
            }
    int q,cs=0;
    scanf("%d",&q);
    while(q--)
    {
        int s,t;
        scanf("%d %d",&s,&t);
        ll k=adj[s][t];
        if(k>=MM)
        printf("-1\n");
        else
        printf("%lld\n",k-1);
//        cout<<k<<endl;
    }
    return 0;
}


Measured memory_bytes: 1920
#include <cstdio>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
typedef long long ll;

int A[110], N;

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

  cin >> N;
  REP(i,N) cin >> A[i];
  REP(i,N) {
    int key = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > key) {
      A[j+1] = A[j];
      --j;
    }
    A[j+1] = key;
    REP(j,N) {
      cout << A[j];
      if (j < N-1) {
        cout << " ";
      } else {
        cout << endl;
      }
    }
  } 
    
  return 0;
}

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

int main()
{


        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,sz1,sz2,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX; string str,ttr,ntr;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct,tct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr,mp1,mp2;

        scanf("%lld",&n);

        for(i=1;i<=n;i++)
        {

            scanf("%lld",&a);   v.push_back(a);

            sc=i-a;  mp[sc]++;

        }

        for(i=1;i<n;i++)
        {

            p=v[i-1]+1+(i-1);
            ans=ans+mp[p];


        }



       printf("%lld\n",ans);







    return 0;
}





Measured memory_bytes: 27552
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n,m;
	cin>>n>>m;
	ll c=0;
	vector<ll> vc[m];
	for(i=0;i<m;i++){
		cin>>k;
		for(j=0;j<k;j++){
			cin>>l;
			vc[i].ps(l);
		}
	}
	ll p[m];
	for(i=0;i<m;i++){
		cin>>p[i];
	}

	k=0;
	ll an=0;
	string t="";
	for(i=0;i<n;i++){
		t+="0";
	}
	l=1;
	for(i=0;i<m;i++){
		k=0;
		for(j=0;j<vc[i].size();j++){
			if(t[vc[i][j]-1]=='1') k++;
		}
		if(k%2!=p[i]){
			l=0;
			break;
		}
	}
	if(l==1) an+=1;
	k=0;
	for(i=0;i<n;i++){
		k=(k|((ll)1<<i));
		string s="";
		for(j=0;j<n;j++){
			if(((ll)1<<j)&k){
				s+="1";
			}
			else s+="0";
		}
		sort(all(s));
		ll a,b,f;
		do{
			f=1;
			for(a=0;a<m;a++){
				ll g=0;
				for(b=0;b<vc[a].size();b++){
					if(s[vc[a][b]-1]=='1') g++;
				}
				if(g%2!=p[a]){
					f=0;
					break;
				}
			}
			if(f==1){
				an++;
			}
		}while(next_permutation(s.begin(),s.end()));
	}
	cout<<an;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>

using namespace std;

long long sum[2] = {0};

long long check(int n, int s, long long a[]) {
    long long cnt = 0;
    // 条件を満たすように修正した要素を格納するための配列
    long long na[n];

    for (int i = 0; i < n; i++) {
        na[i] = a[i];

        // 偶数番目のsumが正の場合の操作回数をカウントする
        if (s == 0) {
            sum[s] += na[i];
            // 偶数番目のsumが負の場合、差分を計算する
            if (i % 2 == 0 && sum[s] <= 0) {
                // 変更する差分
                long long dx = 1 - sum[s];
                na[i] += dx;
                cnt += abs(dx);
                sum[s] += dx;
            // 奇数番目のsumが正の場合、差分を計算する
            } else if (i % 2 != 0 && sum[s] >= 0) {
                // 変更する差分
                long long dx = -1 - sum[s];
                na[i] += dx;
                cnt += abs(dx);
                sum[s] += dx;
            }
        }
        // 奇数番目のsumが正の場合の操作回数をカウントする
        if (s == 1) {
            sum[s] += na[i];
            // 奇数番目のsumが負の場合、差分を計算する
            if (i % 2 != 0 && sum[s] <= 0) {
                // 変更する差分
                long long dx = 1 - sum[s];
                na[i] += dx;
                cnt += abs(dx);
                sum[s] += dx;
            // 偶数番目のsumが正の場合、差分を計算する
            } else if (i % 2 == 0 && sum[s] >= 0) {
                // 変更する差分
                long long dx = -1 - sum[s];
                na[i] += dx;
                cnt += abs(dx);
                sum[s] += dx;
            }
        }
    }
    return cnt;
}

int main()
{
    int n; cin >> n;
    long long a[100001];

    for (int i = 0; i < n; i++) cin >> a[i];
    // a[0]のsumを正、負のどちらにすれば最小になるかを計算する
    cout <<min(check(n, 0, a), check(n, 1, a)) << endl;

    return 0;
}


Measured memory_bytes: 1152
n, m = map(int, input().split())
k_s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))

ans = 0

for bit in range(1<<n):
  on = 0
  for i in range(m):
    numon = 0
    k = k_s[i][0]
    s = k_s[i][1:]
    for j in range(k):
      mask = 1<<(s[j]-1)
      if mask&bit:
        numon += 1
    if numon%2 == p[i]:
      on += 1
  if on == m:
    ans += 1

print(ans)
  

Measured memory_bytes: 9200
import sys
import queue
#+++++
		
def main():
	n,q = map(int, input().split())
	tree=[[] for _ in range(n+1)]
	hh=[0 for _ in range(n+1)]
	ret=[0 for _ in range(n+1)]
	
	for i in range(n-1):
		pa,ch = map(int, input().split())
		tree[pa].append(ch)
		
	for v in range(q):
		nd, hv = map(int, input().split())
		hh[nd] += hv
		
	ol = queue.Queue(n+1)
	ret[1]=hh[1]
	vv=hh[1]
	for cc in tree[1]:
		ol.put((vv,cc))
		
	while not ol.empty():
		ph,nd=ol.get()
		ret[nd]=hh[nd]+ph
		vv=ret[nd]
		for cc in tree[nd]:
			ol.put((vv,cc))

	rets=' '.join([str(v) for v in ret[1:]])
	print(rets)
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

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

  int count=0;
  for (int i=0;i<4;++i) {
    if (s[i]=='+') ++count;
    else --count;
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;


int main()
{
    Go_
    int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    
    while(cin>>n>>r)
     {
         if(n>=10) cout<<r<<endl;
         else cout<<r+(100*(10-n))<<endl;
     }
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int w[1000];
int m;
int n;

bool kuwa(int s) {
  int t = s;
  int l = m;
  for(int i = 0; i < n; i++) {
    if (t - w[i] >= 0) {
      t -= w[i];
    }else{
      t = s;
      l --;
      i --;
      if (l <= 0) {
        return false;
      }
    }
  }
  return true;
}

int bin_search(int min, int max) {
  int s = (min + max) / 2;
  if (min + 1 == max) {
    if (kuwa(min)) {
      return min;
    }else{
      return max;
    }
  }
  if (! kuwa (s) ) {
    return bin_search(s, max);
  } else {
    return bin_search(min,  s);
  }
}

int main() {
  while (1) {
    cin >> m >> n;
    if ((n == 0) && (m == 0)) {
      return 0;
    }
    for (int i = 0; i < n; i++) {
      cin >> w[i];
    }
    cout << bin_search(0, 100000000) << endl;
      
  }
}

Measured memory_bytes: 3064
// 解き直し.
// https://atcoder.jp/img/arc072/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){

    // 1. 入力情報.
    LL X, Y;
    scanf("%lld %lld", &X, &Y);
    
    // 2. 出力(解説通り).
    printf("%s\n", (abs(X - Y) <= 1) ? "Brown": "Alice");
    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N;
  scanf("%d", &N);

  char s[N+10];

  scanf("%s", s);

  int red = 0;

  int i;

  for(i = 0; i < N; i++){
    if(s[i] == 82) red++;
  }

  if(2 * red > N) printf("Yes\n");
  else printf("No\n");

  return 0;
}


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

vector<vector<int> > edge;
int visited[128];
int n;
int depth = 0;

int solve(int k) {
	if(visited[k])
		return -1;
	visited[k] = 1;
	int res = -1;
	for(int i = 0; i < edge[k].size(); i++) {
		res = max(res, solve(edge[k][i]));
	}
	visited[k] = 0;
	return res+1;
}

int main() {
	while(cin >> n, n) {
		for(int i = 0; i < 128; i++)
			visited[i] = 0;
		edge.clear();
		edge.resize(100);
		for(int i = 0; i < n; i++) {
			int a, b;
			cin >> a >> b;
			a--; b--;
			edge[a].push_back(b);
			edge[b].push_back(a);
		}

		int res = 0;
		for(int i = 0; i < 100; i++) {
			res = max(res, solve(i) + 1);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int n;
int a[110];

int selectionSort(int a[], int n)
{
  int cnt = 0;
  rep(i, n){
    int minj = i;
    REP(j, i, n-1){
      if(a[j] < a[minj]){
        minj = j;
      }
    }
    if(minj != i){
      swap(a[i], a[minj]);
      cnt++;
    }
  }
  return cnt;
}

int main(){
  cin >> n;
  rep(i, n) cin >> a[i];
  
  int ans = selectionSort(a, n);

  rep(i, n){
    if(i>0) cout << " ";
    cout << a[i];
  }
  cout << endl;
  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 3096
n, k = gets.chomp.split.map(&:to_i)
s = gets.chomp
cnt = 0
i = 0
j = 0
one = []
zero = []
while i < n
  one[j] = 0
  zero[j] = 0
  while i <= n && s[i] == "1"
    one[j] += 1
    i += 1
  end
  while i <= n && s[i] == "0"
    zero[j] += 1
    i += 1
  end
  j += 1
end

ans = []
ans[0] = 0

if (s[n-1] == "0" && k >= one.length) || (s[n-1] == "1" && k >= one.length - 1)
  ans[0] = n
else
  k.times do |a|
    ans[0] += one[a] + zero[a]
  end
  ans[0] += one[k]
  if one.length > 1
    i = 1
    while i < one.length - k
      ans[i] = ans[i-1] - one[i-1] - zero[i-1] + zero[i+k-1] + one[i+k]
      i += 1
    end
    ans[i] = ans[i-1] - one[i-1] - zero[i-1] + zero[i+k-1]
  end
end
puts ans.max


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

int main(){
  int n;
  scanf("%d",&n);
  int a[200001];
  int b[200001]={};
  for(int i=2;i<=n;i++){
    scanf("%d",&a[i]);
    b[a[i]]++;}

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


Measured memory_bytes: 3292
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n: usize,
        mut sp: [(String, i64); n]
    }
    let mut new_sp = vec![];
    for (i, &(ref stri, ref pt)) in sp.iter().enumerate() {
        new_sp.push(((stri, -1 * pt), i+1));
    }

    new_sp.sort();
    for ((_, _), i) in new_sp {
        println!("{}", i)
    }
}


Measured memory_bytes: 4352
A = [0] * (10**4+1)
N = gets.to_i
1.upto(99) {|x|
  i = 6*x*x
  A[i] += 1  if A[i]
  i = 3*x*x
  (x+1).upto(99) {|z|
    j = i + 2*x*z + z*z
    A[j] += 3  if A[j]
  }
  i = x*x
  (x+1).upto(99) {|y|
    j = i + 3*y*y + 2*x*y
    A[j] += 3  if A[j]
    j = i + (x+y)*y
    (y+1).upto(99) {|z|
      k = j + z*z + (x+y)*z
      A[k] += 6  if A[k]
} } }
puts A[1,N]

Measured memory_bytes: 14380
#include <iostream>

using namespace std;

int N;
void NChecker(int i,int n);

int main(){

	while (1){
		cin >> N;
		if (N == 0)break;
		NChecker(0, N);
	}
	return 0;
}

int Nout[30] = { 0 };
int total;

void NChecker(int i,int n){//[i]=nのときの全探査([0]=nツリーのみ)
	if (n == 0)return;//終了
	//代入
	Nout[i] = n;

	//リスト全値の和を取る
	total = 0;
	for (int j = 0; j <= i; ++j){
		total += Nout[j];
	}

	if (total == N){//トータルが目的値
		cout << Nout[0];//出力
		for (int j = 1; j <= i; ++j){
			cout << " " << Nout[j];
		}
		cout << endl;
	} else if (total < N){//トータルが目的値に足らない
		//行追加で再捜査
		NChecker(i + 1, n);
	}
		
	//n値を下げて再捜査
	NChecker(i, n - 1);
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;


int main(){
	int x, y;
    cin >> x >> y;
    cout << x + y/2 << endl;
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

ll dp[110][100010];

int main() {
    ll N, W; cin >> N >> W;
    vector<ll> w(N);
    vector<ll> v(N);
    rep(i, N) cin >> w.at(i) >> v.at(i);

    rep(i, N){
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i+1][j] = dp[i][j];
            }
            else {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            }
        }
    }

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

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


int main()
{
	int n, m, l;
	long long a[102][102], b[102][102];
	cin >> n >> m >> l;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++){
		for (int j = 0; j < l; j++){
			cin >> b[i][j];
		}
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < l; j++){
			long long sum = 0;
			for (int k = 0; k < m; k++){
					sum += a[i][k] * b[k][j];
			}
			if (j < l - 1){
				cout << sum <<" ";
			}
			else{
				cout << sum << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1328
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <bitset>
#include <iterator>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <random>
#include <numeric>
#include <set>
#include <cassert>
#include <cmath>
#include <cinttypes>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}
template<class T> T read_val() { throw 1; }
template<> int read_val() { int tmp; scanf("%" PRId32, &tmp); return tmp; }
template<> long long read_val() { long long tmp; scanf("%" PRId64, &tmp); return tmp; }
auto read_int = read_val<int>; auto read_long = read_val<long long>;
template<class T> void scanf_vec(vector<T>& vec) { for (int i = 0; i < vec.size(); i++) vec[i] = read_val<T>(); }

#define MOD 1000000007
#define inf 2000000000
#define FWT_SIZE 2000000
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define sort_all(x) sort(all(x))
#define make_unique(x) (x).erase(unique(all(x)), (x).end())


long long a, b, c, d;

map<long long, long long> mm;

long long rec(long long n)
{
	if (n == 1)
		return d;
	if (mm.find(n) != mm.end())
	{
		return mm[n];
	}
	long long ans = 3LL * 1e18;
	if (n < ans / d) ans = n * d;
	
	if (n >= 3)
	{
		long long rem3 = n % 3;
		if (rem3 < (3 - rem3))
			ans = min(ans, d * rem3 + b + rec(n / 3LL));
		else
			ans = min(ans, (3 - rem3) * d + b + rec(n / 3LL + 1LL));
	}

	if (n>=5)
	{
		long long rem5 = n % 5;
		if (rem5 < (5 - rem5))
			ans = min(ans, d * rem5 + c + rec(n / 5LL));
		else
			ans = min(ans, d * (5 - rem5) + c + rec(n / 5LL + 1LL));
	}

	if (1)
	{
		if (n % 2 == 0)
			ans = min(ans, a + rec(n / 2LL));
		else
		{
				ans = min(ans, d + a + rec((n + 1) / 2LL));
				ans = min(ans, d + a + rec((n) / 2LL));

		}
	}
	mm[n] = ans;
	return ans;
}

int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t;
	cin >> t;
	while (t-- > 0)
	{
		long long n;
		mm.clear();
		cin >>n>> a >> b >> c >> d;
		cout << rec(n) << "\n";
	}

	return 0;
}

Measured memory_bytes: 4344
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
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 mod 1000000007
#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())
int n;
string a,b;
int main(){ cin>>n>>a>>b; rep(i,2*n){ if(i%2==0)cout<<a[i/2]; else cout<<b[i/2]; } cout<<endl;}

Measured memory_bytes: 256
#include<cstring>
#include<iostream>
#include<math.h>
#include<set>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#include<string>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
typedef long long ll;
using namespace std;
const int MAXN = 11000;


int main()
{
    ios_base:: sync_with_stdio(0);
    cin.tie();
    cout.tie(0);
    string s;
    cin >> s;
    if(s.size() >= 4 && s.substr(0 , 4) == "YAKI")
        cout << "Yes";
    else cout << "No";
    return 0;
    
}

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

using namespace std;

#define fo(i,n) for(int i=0; i<n; i++)
#define Fo(i,k,n) for(int i=k; i<n; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int N;
vvi edges;

const int mod = 1e9+7;

ll mul(int a, int b){
    return (ll)a*b%mod;
}

ll add(ll a, ll b){
    if(a+b>=mod)return a+b-mod;
    else return a+b;
}

pii dfs(int node, int parent){
    ll smt_is_blk = 0;
    ll all_wht = 1;
    for(auto child:edges[node]){
        if(child!=parent){
            auto curr = dfs(child, node);
            ll wb = mul(all_wht, curr.second);
            ll ww = mul(all_wht, curr.first);
            ll bw = mul(smt_is_blk, curr.first + curr.second);
            all_wht = wb;
            smt_is_blk = (bw+ ww)%mod;
        }
    }
    return make_pair(all_wht, (all_wht+ smt_is_blk)%mod);
}

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

    cin>>N;
    edges.resize(N+1);
    Fo(i,1,N){
        int x,y;
        cin>>x>>y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
    pii ans = dfs(1, -1);
    cout<<(ans.first+ ans.second)%mod<<endl;
    
    return 0;
}

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

int main() {
  int x,y;
  cin >> x >> y;

  for (int c = 0;c <= x; c++) {
    int t = x-c;
    int asi = c*2+t*4;
    if (asi == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int _=1;
    //cin>>_;
    while(_--)
    {
        string s;
        cin>>s;
        (s[2]==s[3] && s[4]==s[5] && s.length()==6)?cout<<"Yes":cout<<"No";
        
    }
    return 0;
}

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

typedef long long ll;


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

	ll l, r, len;
	ll pbl = 0, pbr = 0, ans = 0, L, R;
	priority_queue<ll> ql;
	priority_queue<ll, vector<ll>, greater<ll>> qr;
	
	while (n--) {
		cin >> l >> r;
		len = r - l;

		pbr += len;

		ql.push(r - pbl);
		qr.push(r - pbr);

		while ((L = ql.top() + pbl) > (R = pbr + qr.top())) {
			ans += L - R;

			ql.pop();
			qr.pop();

			ql.push(R - pbl);
			qr.push(L - pbr);
		}

		pbl -= len;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2036
#include<iostream>
long dp[50];
int fib(int n){
	if (n == 0 || n == 1)
		return 1;
	else{
		if (dp[n]==0)
		    return (dp[n] = fib(n - 1) + fib(n - 2));
		else return dp[n];
	}
}
int main(){
	int n;
	std::cin >> n;
		std::cout << fib(n) << "\n";
}

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

#define int long long int 

int32_t main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
      cin>>a[i];
      sort(a,a+n);
      reverse(a,a+n);
      int ans=0;
      for(int i=0;i<n;i++)
      {
          if(i%2==0)
          ans+=a[i];
          else
          ans-=a[i];
      }
      cout<<ans<<endl;
}

Measured memory_bytes: 3608
n=int(input())
hoge=list(map(int,input().split()))
ans=[]
for i in range(n):
  for j in range(len(hoge)):
    if(hoge[-j-1]==len(hoge)-j):
      ans.append(hoge[-j-1])
      hoge.pop(-j-1)
      break
ans.reverse()
if(len(hoge)==0):
  for i in ans:
    print(i)
else:
  print(-1)

Measured memory_bytes: 3064
N, M= map(int, input().split())
H = list(map(int, input().split()))
a=[0]*M
b=[0]*M
for i in range(M):
    a[i], b[i]=map(int, input().split())

tenbou=[1]*N

for i in range(M):
    if H[a[i]-1]>H[b[i]-1]:
        tenbou[b[i]-1]=0
    elif H[a[i]-1]<H[b[i]-1]:
        tenbou[a[i]-1]=0
    else:
        tenbou[a[i]-1]=0
        tenbou[b[i]-1]=0

print(sum(tenbou))

Measured memory_bytes: 21848
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-2.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n,m;cin>>n>>m;
  vector<int> x(n);

  vector<int> cnt(100001);
  rep(i, n) {
    cin>>x[i];
    cnt[x[i]]++;
  }
  dump(x);

  int ans = 0;
  rep(i, m){
    if (i<(m-i)%m){
      multiset<int> st1, st2;
      int s1 = 0;
      int s2 = 0;
      int o1 = 0;
      int o2 = 0;
      for(int j=i; j<100001; j+=m){
        if (cnt[j]>0){
          st1.insert(cnt[j]);
          s1 += cnt[j];
          if (cnt[j]%2==1) o1++;
        }
      }
      for(int j=m-i; j<100001; j+=m){
        if (cnt[j]>0){
          st2.insert(cnt[j]);
          s2 += cnt[j];
          if (cnt[j]%2==1) o2++;
        }
      }
      dump(i, m-i, st1, st2, o1, o2);

      if (o1==o2){
        ans += (s1+s2)/2;
      }
      else {
        if (o2 < o1){
          swap(s1,s2);
          swap(o1,o2);
        }

        if (s1-o1>=o2-o1){
          ans += (s1+s2)/2;
        }
        else{
          ans += ((s1+s2)-(o2-s1))/2;
        }
      }
    }
    else if (i==(m-i)%m){
      int num = 0;
      for(int j=i; j<100001; j+=m){
        num += cnt[j];
      }
      ans += num/2;
    }
    dump(i, ans);
  }
  cout << ans << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 3840
/*
	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0004
	Simultaneous Equation
*/

#include <stdio.h>
int main(void)
{
	int a,b,c,d,e,f;
	double x=0,y=0;

	while (scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != EOF)
	{
		/* ?????????
			ax + by = c ...???1
			dx + ey = f ...???2

			???2????????????(a/d)?????????????????????????????????????????¨y???????????????
			ax + e(a/d)y = f(a/d) ...???2'

			(b - ea/d) y = (c - fa/d) ...???1 - ???2'


			???2????????????(b/e)?????????????????????????????????????????¨x???????????????
			d(b/e)x + by = f(b/e) ...???2''

			(a - db/e) x = (c - fb/e) ...???1 - ???2''
		*/

		x = (double) (c*e - b*f) / (a*e - b*d);
		y = (double) (c*d - a*f) / (b*d - a*e);

		/* -0????????????????????? */

		if (x == -0)
		{
			x = 0;
		}

		if (y == -0)
		{
			y = 0;
		}

		printf("%.3lf %.3lf\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 636
n,m = map(int,input().split())
dp = [0] * (n+1) + [0] * 10

mod = 10**9 + 7
for i in range(m):
    dp[int(input())] = -1 # 壊れているので、-1としておこう?

dp[0] = 0 # 0段目にいるとしよう
# 1段目が行けなかったら...?
dp[1] = 1 if dp[1] != -1 else -1 # 1段目にいく方法は1通り?
dp[2] = -1 if dp[2] == -1 else (1 if dp[2] != -1 and dp[1] == -1 else 2) # 2段目に行く方法は2通り?
for i in range(3,n+1):
    if dp[i] != -1 and dp[i-1] != -1:
        dp[i] += dp[i-1]
        dp[i] %= mod
    if i > 1:
        if dp[i] != -1 and dp[i-2] != -1:
            dp[i] += dp[i-2]
            dp[i] %= mod
#print(dp)
print(dp[n]%mod)


Measured memory_bytes: 6972
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
s = [_ for _ in input()][::-1]

a = set()
ans=0
ii = set()
for i in range(n-2):
  if s[i] in ii:
    continue
  ii.add(s[i])
  jj = set()
  for j in range(i+1,n-1):
    if s[j] in jj:
      continue
    jj.add(s[j])
    kk = set()
    for k in range(j+1,n):
      if k not in kk:
        ans+=1
        kk.add(s[k])
        a.add(''.join([s[k],s[j],s[i]]))
    
print(len(a))


Measured memory_bytes: 76424
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

vector<int> A;

// {C, B}
vector<pair<int, int>> cands;

ll solve(const int N, const int M) {
    int c_i = 0;

    for (int a_i = 0; a_i < N; a_i++) {
        int a = A[a_i];

        if (a >= cands[c_i].first) {
            break;
        }
        A[a_i] = cands[c_i].first;

        cands[c_i].second--;
        if (cands[c_i].second == 0) {
            c_i++;
        }
        if (c_i >= M) {
            break;
        }
        // printf("a_i: %d, c_i: %d\n", a_i, c_i);
    }

    ll acc = 0;
    for (int i = 0; i < N; i++) {
        acc += A[i];
    }
    return acc;
}

int main(void) {
    int N, M;
    cin >> N >> M;

    A.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    cands.resize(M);
    for (int i = 0; i < M; i++) {
        cin >> cands[i].second >> cands[i].first;
    }

    // sort by descending order of C
    sort(cands.begin(), cands.end(), [](const pair<int, int> &a, const pair<int, int> &b) {
            return a.first > b.first;
            });

    // for (int i = 0; i < M; i++) {
    //     printf("{%d, %d}\n", cands[i].first, cands[i].second);
    // }

    cout << solve(N, M) << endl;

    return 0;
}


Measured memory_bytes: 1536
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>


using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

class AAddSubMul {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int a,b,arr[3];
    int ans = 0;
    cin >> a >> b;
    arr[0] = a+b;
    arr[1] = a-b;
    arr[2] = a*b;
    ans = *max_element(arr,arr+3);
    cout << ans << endl;
}
};


int main() {
	AAddSubMul solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main(){
    int k;
    cin >> k;
    vector<ll> a(k);
    rep(i,k) cin >> a[i];
    reverse(a.begin(),a.end());
    ll l = 2, r = 3;
    bool can = true;
    rep(i,k){
        l = (l+a[i]-1)/a[i]*a[i];
        r = (r+a[i]-1)/a[i]*a[i];
        if(l == r) {
            can = false;
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << l << " " << r-1 << endl;
    return 0;
}

Measured memory_bytes: 1024
import sys
def input():
    return sys.stdin.readline()[:-1]

import collections

n = int(input())
a = [int(i) for i in input().split()]

dic = collections.defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

ls = collections.deque()
for i in dic.keys():
    if dic[i] > 1:
        ls.append(i)

ans = n
if len(ls) > 0:
#n/2回ループ
    for i in range(n//2):
        if len(ls) == 1 and dic[ls[0]] == 2:
            ans -= 2
            dic[ls[0]] -= 1
            break
        else:
            if len(ls) == 1:
                dic[ls[0]] -= 2
            else:
                dic[ls[0]] -= 1
                dic[ls[-1]] -= 1
            ans -= 2

        if len(ls) > 1:
            if dic[ls[-1]] <= 1:
                ls.pop()
        if dic[ls[0]] <= 1:
            ls.popleft()

        if len(ls) == 0:
            break
print(ans)


Measured memory_bytes: 61676
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int N = 201000;
ll A[N],B[N],s[N],f[N];
int n,m,p[N],fa[N];
vector<int> e[N],a[N];
int find(int x){return fa[x]= fa[x]==x?x:find(fa[x]);}
void dp(int x){
	s[x]=B[x];
	for(int v:e[x]) dp(v),s[x]+=s[v];
	if(!e[x].size()){
		f[x]=max(A[x],B[x]);
		return;
	}
	f[x]=1e18;
	for(int v:e[x])
		f[x]=min(f[x],max(f[v],A[x]-B[x])+s[x]-s[v]);
}
int main(){
	read(n);read(m);
	for(int i=1;i<=n;i++) read(A[i]),read(B[i]);
	for(int i=1;i<=m;i++){
		int x,y;read(x);read(y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	for(int i=1;i<=n;i++) p[i]=i,fa[i]=i;
	sort(p+1,p+n+1,[&](int a,int b){
		return A[a]-B[a]<A[b]-B[b];
	});
	for(int i=1;i<=n;i++){
		int x=p[i];
		for(int v:a[x])
			if(A[v]-B[v]<=A[x]-B[x]&&find(v)!=find(x)){
				e[x].push_back(find(v));
				fa[find(v)]=find(x);
			}
	}
	for(int i=1;i<=n;i++)
		if(fa[i]==i){
			dp(i);
			cout<<f[i]<<'\n';
			return 0;
		}
	return 0;
}


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

using namespace std;

typedef long long ll;

int main () {
  int n;
  cin >> n;
  vector< pair<int, int> > a(n);
  for (int i = 0; i < n; ++i) {
		cin >> a[i].first;
		a[i].second = i + 1;
	}
	sort(a.begin(), a.end());
	for (auto x : a) {
		cout << x.second << ' ';
	}
}


Measured memory_bytes: 1536
"use strict"

function Main(input) {
  input = input.split("\n");
  let A = parseInt(input[0], 10);
  let B = parseInt(input[1], 10);
  let C = parseInt(input[2], 10);
  let X = parseInt(input[3], 10);

  let count = 0;

  for (let i = 0; i <= A; i++) {
    for (let j = 0; j <= B; j++) {
      for (let k = 0; k <= C; k++) {
        if (X === ((500 * i) + (100 * j) + (50 * k))) {
          count++;
        }
      }
    }
  }
  console.log(count);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372