akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;
typedef long long ll;

bool IsBip(const vector<vector<int> > &g) {
  int N = g.size();
  vector<int> label(N, -1);

  queue<int> q;
  q.push(0);
  label[0] = 0;
  while (not q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (label[v] == -1) {
	label[v] = label[u] == 0 ? 1 : 0;
	q.push(v);
      } else if (label[v] == label[u]) {
	return false;
      }
    }
  }
  
  return true;
}

int FindFurthest(const vector<vector<int> > &g, int start, int &furthest) {
  int N = g.size();
  vector<int> dist(N, -1);
  queue<int> q;
  q.push(start);
  dist[start] = 0;
  while (not q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (dist[v] == -1) {
	dist[v] = dist[u] + 1;
	q.push(v);
      }
    }
  }

  furthest = start;
  int maxdist = 0;
  for (int u = 0; u < N; ++u) {
    if (dist[u] > maxdist) {
      maxdist = dist[u];
      furthest = u;
    }
  }

  return maxdist;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int> > g(N);
  for (int i = 0; i < N; ++i) {
    string S;
    cin >> S;
    for (int j = 0; j < N; ++j) {
      if (S[j] == '1') {
	g[i].push_back(j);
      }
    }
  }
  
  if (not IsBip(g)) {
    cout << -1 << endl;
    return 0;
  }

  int maxdist = 0;
  for (int u = 0; u < N; ++u) {
    int dist, v;
    dist = FindFurthest(g, u, v);
    maxdist = max(maxdist, dist);
  }
  cout << maxdist + 1 << endl;
  
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
// #pragma GCC optimize ("-O3")
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long double PI = 3.14159265358979323846;  /* pi */
vector<int> ans(5e5, -1);

int findans(int n)
{
    if (ans[n] != -1)
        return ans[n];
    int bc = __builtin_popcount(n);
    ans[n] = 1 + ans[n % bc];
    return ans[n];
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int bc = 0;
    for(int i = 0; i < n; i++)
    {
        if (s[i] == '1')
            bc ++;
    }
    int mod1 = bc + 1;
    int mod2 = bc -1;

    vector<int> valmod1(n+1), valmod2(n+1);
    int v1 = 1;
    int v2 = 1;
    for (int i = 0; i < n; i++)
    {
        valmod1[i] = v1%mod1;
        if (mod2 != 0)
            valmod2[i] = v2%mod2;
        v1 = (v1 << 1) % mod1;
        if (mod2 != 0)
            v2 = (v2 << 1) % mod2;
    }
    ans[0] = 0;
    for (int i = 0; i < 5e5; i++)
    {
        if (ans[i] == -1)
            findans(i);
    }
    int current_ans1 = 0;
    int current_ans2 = 0;
    for (int i = n-1; i >= 0; i--) {
        if (s[n - 1 - i] == '1') {
            current_ans1 = (current_ans1 + valmod1[i]) % mod1;
            if (mod2 != 0)
                current_ans2 = (current_ans2 + valmod2[i]) % mod2;
        }
    }
    for (int i = 0; i < n; i++)
    {
        int p = n - 1 - i;
        if (s[i] == '1')
        {
            // use mod2
            int fval = 0;
            if (mod2 != 0)
            {
                fval = (current_ans2 - valmod2[p]) % mod2;
            }
            else
            {
                cout << "0\n";
                continue;
            }
            while(fval < 0)
                fval += mod2;
            cout << 1 + ans[fval] << "\n";
        }
        else
        {
            // use mod1
            int fval = (current_ans1 + valmod1[p]) % mod1;
            while(fval < 0)
                fval += mod1;
            cout << 1 + ans[fval] << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 7200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; string s; cin >> n >> s;
  int x = 0, best = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'I') x++;
    else x--;
    best = max(best, x);
  }
  cout << best << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int l,r,d;
int cnt=0;
cin>>l>>r>>d;
for(int i=l;i<=r;i++)
{
    if(i%d==0)
    {
        cnt++;

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


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

struct distination {
    int to;
    int distance;
};

int N;
vector<vector<distination>> G;
vector<int> ans;

void dfs(int root, int p, int n) {
    ans[root] = n;
    for(auto e:G[root]){
      if(e.to == p) continue;
      if(e.distance&1) dfs(e.to,root,1-n);
      else dfs(e.to,root,n);
    }
}

int main() {
    cin >> N;
    G.resize(N);
    rep(i, N-1) {
        int from, to, distance;
        cin >> from >> to >> distance;
        from--;
        to--;
        G[from].push_back({to, distance});
        G[to].push_back({from, distance});
    }

    ans.assign(N, 0);
    dfs(0,-1,0);

    for(auto e:ans) cout << e << endl;
}

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

#define rep(i, a, b) for(int i = a; i <= (b); ++i)
#define per(i, a, b) for(int i = b; i >= (a); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define ff first 
#define ss second 
#define boost ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair

#define M 1000*1000*1000+9
#define inf 2*1000*1000*1000+9
#define infl (ll)2*1000*1000*1000*1000*1000*1000+9

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

void solve(){
  ll n,m; cin>>n>>m; 
  char s[n],t[m]; 
  rep(i,0,n-1){
    cin>>s[i]; 
  }  
  rep(j,0,m-1){
    cin>>t[j]; 
  }
  rep(i,0,n-1){
    if( (ll) i*m % n == 0){
      ll ind= (ll) i*m / n; 
      if( 0 <= ind && ind< m  && t[ind] != s[i] ){ 
        cout<<-1; 
        return; 
      }
    }
  }
  ll l=(ll)n*m/__gcd(n,m); 
  cout<<l<<endl; 
}


int main() {
  clock_t beg=clock(); 
  boost;
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
  clock_t end=clock(); 
  fprintf(stderr, "%lf\n", (double)(end-beg)/CLOCKS_PER_SEC);
}

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

const ll lp = 1e9+7;
int t,n,m;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	ll sum=0, x;
	ll ans=0;
	for (int i=0; i<n; i++){
		cin >> x;
		ans = (ans + sum*x) % lp;
		sum = (sum + x) % lp;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3648
package main

import (
	"fmt"
	"math"
)

func main() {
	board := make([][]int, 3)
	board[0] = ints(3)
	board[1] = ints(3)
	board[2] = ints(3)
	n := scInt()
	blist := ints(n)

	checkedBoard := [][]bool{{false, false, false}, {false, false, false, false}, {false, false, false}}

	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < n; k++ {
				if board[i][j] == blist[k] {
					checkedBoard[i][j] = true
				}
			}
		}
	}
	ret := "No"

	if checkedBoard[0][0] && checkedBoard[0][1] && checkedBoard[0][2] {
		ret = "Yes"
	} else if checkedBoard[1][0] && checkedBoard[1][1] && checkedBoard[1][2] {
		ret = "Yes"
	} else if checkedBoard[2][0] && checkedBoard[2][1] && checkedBoard[2][2] {
		ret = "Yes"
	} else if checkedBoard[0][0] && checkedBoard[1][0] && checkedBoard[2][0] {
		ret = "Yes"
	} else if checkedBoard[0][1] && checkedBoard[1][1] && checkedBoard[2][1] {
		ret = "Yes"
	} else if checkedBoard[0][2] && checkedBoard[1][2] && checkedBoard[2][2] {
		ret = "Yes"
	} else if checkedBoard[0][0] && checkedBoard[1][1] && checkedBoard[2][2] {
		ret = "Yes"
	} else if checkedBoard[0][2] && checkedBoard[1][1] && checkedBoard[2][0] {
		ret = "Yes"
	}
	fmt.Println(ret)
}

func scStr() string {
	var s string
	fmt.Scan(&s)
	return s
}

func scInt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func scInt2() (int, int) {
	var x, y int
	fmt.Scan(&x, &y)
	return x, y
}

func scInt3() (int, int, int) {
	var x, y, z int
	fmt.Scan(&x, &y, &z)
	return x, y, z
}

func ints(n int) (slice []int) {
	slice = make([]int, n)
	for i := range slice {
		fmt.Scan(&slice[i])
	}
	return slice
}

func sum(slice []int) (sum int) {
	sum = 0
	for i := range slice {
		sum += slice[i]
	}
	return
}

func unique(strs []string) (unique []string) {
	m := map[string]bool{}
	for _, v := range strs {
		if !m[v] {
			m[v] = true
			unique = append(unique, v)
		}
	}
	return unique
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func powi(x, pow int) int {
	return int(math.Pow(float64(x), float64(pow)))
}


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

int main(void){
    string S,T;

    cin >> S;
    cin >> T;
    
    int cnt = 0; 

    for(int i = 0; i < S.size(); i++){
        if(S[i] != T[i])cnt++;
    }

    cout << cnt << endl;

    return 0;
}


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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  for (int i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    V[a]++;
  }
  
  sort(V.begin(), V.end(), greater<>());
  int temp = 0;
  for (int i = 0; i < K; i++)
  {
    temp += V[i];
  }
  int ans = N -temp;
  cout << ans << endl;
}

Measured memory_bytes: 1024
#import<iostream>
using namespace std;long long int s,d,a,i,N;main(){cin>>N;for(;i<N;++i,a=0){cin>>s>>d;for(;s-d;s/=2,d/=2){if(s%2)++a,++s;if(d%2)++a,--d;}cout<<a<<endl;}}

Measured memory_bytes: 3084
#include <iostream>

using namespace std;

int main()
{
    long long a;
    string sb;
    cin >> a >> sb;

    sb.erase(1, 1);

    long long llb = atoi(sb.c_str());

    long long res = (a * llb / 100);

    cout << res << endl;

    return 0;
}

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 55;

int n, m, k, A, O, a[N];
long long C[N][N];

bool subset(int A, int B) {
	return (A & B) == A;
}

int main() {
	read(n), read(k), read(A), read(O);
	if (!subset(A, O)) {
		print(0);
		return 0;
	}
	m = 0;
	for (int i = 0; i < n; ++i) {
		int x;
		read(x);
		if (subset(A, x) && subset(x, O)) {
			a[m++] = x;
		}
	}
	n = m;
	for (int i = 0; i <= n; ++i) {
		C[i][0] = C[i][i] = 1;
		for (int j = 1; j < i; ++j) {
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
		}
	}
	for (int i = 0; i <= n; ++i) {
		for (int j = 1; j <= k; ++j) {
			C[i][j] += C[i][j - 1];
		}
	}
	long long ans = 0;
	for (int p = 0; p < (1 << 18); ++p) {
		bool flag = 1;
		for (int i = 0; i < 18; ++i) {
			if ((p >> i & 1) && (A >> i & 1) == (O >> i & 1)) {
				flag = 0;
				break;
			}
		}
		if (!flag) {
			continue;
		}
		std::map<int, int> mp;
		for (int i = 0; i < n; ++i) {
			++mp[a[i] & p];
		}
		long long sum = 0;
		for (auto v : mp) {
			sum += C[v.second][k] - 1;
		}
		for (int i = 0; i < 18; ++i) {
			if (p >> i & 1) {
				sum = -sum;
			}
		}
		ans += sum;
	}
	print(ans);
}

Measured memory_bytes: 3640
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def factorization(n):
   arr = []
   temp = n
   for i in range(2, int(-(-n**0.5//1))+1):
       if temp%i==0:
           cnt=0
           while temp%i==0:
               cnt+=1
               temp //= i
           arr.append([i, cnt])
   if temp!=1:
       arr.append([temp, 1])
   if arr==[]:
       arr.append([n, 1])
   return arr

factorial = [1]
for i in range(1, 1000000):
	factorial.append(factorial[i-1] * i % mod)
 
def power(x, y):
	if y == 0:
		return 1
	elif y == 1:
		return x % mod
	elif y % 2 == 0:
		return power(x, int(y/2)) ** 2 % mod
	else:
		return power(x, int((y-1)/2)) ** 2 * x % mod
def C(n, r):
	return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod
 
x_inv = [0] * (1000000)
x_inv[-1] = power(factorial[-1], mod-2)
for i in range(1000000-2, -1, -1):
	x_inv[i] = x_inv[i+1] * (i+1) % mod

N, M = MAP()

fact_M = factorization(M)

ans = 1
if M == 1:
	print(1)
else:
	for n in fact_M:
		ans = (ans*C(n[1]+N-1, n[1]))%mod
	print(ans)


Measured memory_bytes: 83060
import java.util.Scanner;

// https://atcoder.jp/contests/abc157/tasks/abc157_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();

		if(N%2==0) {
			System.out.println(N/2);
		}else {
			System.out.println(N/2+1);
		}
	}
}


Measured memory_bytes: 22740
x, k, d = map(int, input().split())
x = abs(x)
s = x//d
if s>k:
    print(x-d*k)
elif s<=k:
    if (k-s)%2==0:
        print(x-d*s)
    elif (k-s)%2==1:
        print(abs(x-d*(s+1)))

Measured memory_bytes: 9120
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 0;
        switch(s){
            case "SUN":ans=7;break;
            case "MON":ans=6;break;
            case "TUE":ans=5;break;
            case "WED":ans=4;break;
            case "THU":ans=3;break;
            case "FRI":ans=2;break;
            case "SAT":ans=1;break;
        }
        System.out.println(ans);
    }
}

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

 int main()
 {
     long long int a,b,c,d,A,B,C,D;

     cin>>a>>b>>c>>d;
     A = (max(a,b))*(max(c,d));
     B = (min(a,b))*(min(c,d));
     C = (max(a,b))*(min(c,d));
     D = (min(a,b))*(max(c,d));

     cout<<max(max(A,B),max(C,D))<<endl;

     return 0;
 }


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

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, d, cnt = 0;
  cin >> n >> d;
  vector<pair<long long, long long>> arr(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i].first >> arr[i].second;
  for (int i = 0; i < n; i++) {
    long long sum = (arr[i].first * arr[i].first ) + (arr[i].second * arr[i].second );
    if (sum <= d * d) cnt++;
  }
  cout << cnt;
  return 0;
}


Measured memory_bytes: 6352
#include<iostream>
#include<cstdlib>
#include<stack>
using namespace std;

int main() {
	stack<int> S;
	int a, b, x;
	string s;

	while( cin >> s ) {
		if ( s[0] == '+' ) {
			a = S.top(); S.pop();
			b = S.top(); S.pop();
			S.push(a + b);
		} else if ( s[0] == '-' ) {
			b = S.top(); S.pop();
			a = S.top(); S.pop();
			S.push(a - b);
		} else if ( s[0] == '*' ) {
			a = S.top(); S.pop();
			b = S.top(); S.pop();
			S.push(a * b);
		} else {
			S.push(atoi(s.c_str()));
		}
	}

	cout << S.top() << endl;

	return 0;
}

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

// #include <boost/algorithm/string/join.hpp>
// using boost::algorithm::join;
//
// #include "boost/multi_array.hpp"
// boost::multi_array<int, 3> dp;
// dp.resize(boost::extents[10][9][8]);
//
// #include <boost/multiprecision/cpp_dec_float.hpp>  // quite slowly
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision; // mp::log10
// using bigint = boost::multiprecision::cpp_int;
// using rational = mp::cpp_rational;  // double d = static_cast<double>(r);

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

//constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
#define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
vii R;

bool check(int x) {
  const string s = to_string(x);

  for (auto p : R) {
    if (s[p.first-1]-'0' != p.second) return false;
  }

  return true;
}

int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;

  REP(i, M) {
    int s, c;
    cin >> s >> c;
    R.emplace_back(s, c);
  }

  int imax = 1;
  REP(i, N) {
    imax *= 10;
  }
  int imin = imax/10;
  if (imin == 1) imin=0;

  REP(i, imin, imax) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}

/* vim: set expandtab shiftwidth=2 softtabstop=2 : */


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
  string s;
  char last='@';
  int n;
  while(cin>>s){
    for(int i=0;i<(int)s.length();i++){
      if(s[i]!='@'){
        last=s[i];
        cout<<s[i];
      }
      else{
        i++;
        n=s[i]-'0';
        i++;
        for(int j=0;j<n;j++){
          cout<<s[i];
        }
      }
    }
    cout<<endl;
  }
  return 0;
}



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

int main() {
  string s, t;
  cin >> s >> t;
  
  string x;
  int ans = 0;
  for(int i=stoi(s); i<=stoi(t); i++) {
    x = to_string(i);
    if(x[0]==x[4] && x[1]==x[3]) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

long long a,b,k;
long long aa, ab,ak;

int main(){
    cin >> a >> b >> k;
    aa = a -k;
    if(aa < 0){
        ab = b+aa;
        if(ab < 0){
            ab = 0;
        }
        aa=0;
    }else{
        ab = b;
    }

    cout << aa << ' ' <<  ab << endl;
}

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

typedef int integer;

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define pb push_baceach
#define bs binary_search
#define up upper_bound
#define fs first 
#define sd second 
#define mp maeache_pair    

#define fore(i,a,b) for(ll i = a; i < b; i++)
#define rfore(i, a, b) for(ll i = a - 1; i >= b; i--)
#define forev(a,b) fore(i,0,b)cout<<a[i]<<" "; 
#define mm(a,b) memset(a , b , sizeof a) 
#define ALL(a) a.begin(),a.end() 
#define SZ(n) ((ll) (n).size())

#define infll 1e17
#define infi  2e9
#define int long long
#define endl '\n'
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;


typedef pair<ll,ll> pll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

const int MAX_N = 2e5+10;
int lis[MAX_N];

#define oper max
#define NEUT 0
struct STree { // segment tree for min over integers
    vector<int> st;int n;
    STree(int n): st(4*n+5,NEUT), n(n) {}
    void init(int k, int s, int e, int *a){
        if(s+1==e){st[k]=a[s];return;}
        int m=(s+e)/2;
        init(2*k,s,m,a);init(2*k+1,m,e,a);
        st[k]=oper(st[2*k],st[2*k+1]);
    }
    void upd(int k, int s, int e, int p, int v){
        if(s+1==e){st[k]=v;return;}
        int m=(s+e)/2;
        if(p<m)upd(2*k,s,m,p,v);
        else upd(2*k+1,m,e,p,v);
        st[k]=oper(st[2*k],st[2*k+1]);
    }
    int query(int k, int s, int e, int a, int b){
        if(s>=b||e<=a)return NEUT;
        if(s>=a&&e<=b)return st[k];
        int m=(s+e)/2;
        return oper(query(2*k,s,m,a,b),query(2*k+1,m,e,a,b));
    }
    void init(int *a){init(1,0,n,a);}
    void upd(int p, int v){upd(1,0,n,p,v);}
    int query(int a, int b){return query(1,0,n,a,b);}
}; // usage: STree rmq(n);rmq.init(x);rmq.upd(i,v);rmq.query(s,e);


integer main(){
    int n; cin>>n;
    int h[n],a[n];
    fore(i,0,n)cin>>h[i];
    fore(i,0,n)cin>>a[i];
    STree st(n+1); st.init(lis);
    fore(i,0,n){
        int c = h[i];
        int cmax = st.query(0,c);
        int up = a[i]+cmax;
        st.upd(h[i],up);
    }
    cout<<st.query(0,n+1);
	return 0;
}




Measured memory_bytes: 9600
#include <iostream>
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 100000;




int main() {
    int k,s;
    ll count= 0;
    cin >> k >> s;
    rep(i,k+1){
        rep(j,k+1){
            if(0<=s-i-j && s-i-j<=k) count++;
        }
    }

    cout << count << endl;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();
signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t=1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    // cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
// int arr[(int)1e5+2];
void solve(){
    int a;
    cin>>a;
    if(a==0){
        cout<<"1"<<endl;
    }
    else{
        cout<<"0"<<endl;
    }
}

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

const int M = 305, N = 305;

int m, n, k, cnt = 0, su[M][N], ans[M][N];
char s[M][N];

int get_sum(int lc, int rc, int lr, int rr) {
    return su[rc][rr] - su[lc - 1][rr] - su[rc][lr - 1] + su[lc - 1][lr - 1];
}

void solve(int lc, int rc, int lr, int rr) {
    if (get_sum(lc, rc, lr, rr) == 1) {
        cnt++;
        for (int i = lc; i <= rc; i++) {
            for (int j = lr; j <= rr; j++) {
                ans[i][j] = cnt;
            }
        }
        return;
    }
    for (int k = lc; k < rc; k++) {
        if (get_sum(lc, k, lr, rr) > 0 && get_sum(lc, k, lr, rr) < get_sum(lc, rc, lr, rr)) {
            solve(lc, k, lr, rr);
            solve(k + 1, rc, lr, rr);
            return;
        }
    }
    for (int k = lr; k < rr; k++) {
        if (get_sum(lc, rc, lr, k) > 0 && get_sum(lc, rc, lr, k) < get_sum(lc, rc, lr, rr)) {
            solve(lc, rc, lr, k);
            solve(lc, rc, k + 1, rr);
            return;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> m >> n >> k;
    for (int i = 1; i <= m; i++) {
        cin >> (s[i] + 1);
        for (int j = 1; j <= n; j++) {
            su[i][j] = su[i - 1][j] + su[i][j - 1] - su[i - 1][j - 1] + (s[i][j] == '#');
        }
    }
    solve(1, m, 1, n);
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            cout << ans[i][j] << " ";
        }
        cout << '\n';
    }
}


Measured memory_bytes: 1536
#include <iostream>

using namespace std;

int main(){
  
  int d, n;
  cin >> d >> n;
  
  if(d == 0){
    if(n == 100){
      cout << "101" << endl;
    }else{
      cout << n << endl;
    }
  }else if(d == 1){
    if (n == 100){
      cout << "10100" << endl;
    }else{
      cout << n * 100 << endl;
    }
  }else if(d == 2){
    if (n == 100){
      cout << "1010000" << endl;
    }else{
      cout << n * 10000 << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
import collections
def factorization(n):
    if n < 2:
        return []

    prime_factor = []

    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            prime_factor.append(i)
            n //= i

    #素因数分解した結果、1か√n 以上のものが残る。
    if n > 1 :
        prime_factor.append(n)

    return prime_factor
n = int(input())
#print(factorization(n))

count = 0

c = collections.Counter(factorization(n))
#print(c)
d = list(c.values())
#指数部分を取り出すpqr
#print(d)
for v in c.values():
    for i in range(1,n):
        v -= i
        if v >= 0:
            count += 1
        else:break 

print(count)

Measured memory_bytes: 9720
#https://atcoder.jp/contests/abc171/tasks/abc171_c

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

now=n[0]
li=[]
while now>26:
    if now%26!=0:
        li.append(now%26)
        now=now//26
    else:
        li.append(26)
        now=now//26-1
    #print(li)
li.append(now)

#print(li)
ans=""
for i in li:
    ans+=chr(96+i)

print(ans[::-1])



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

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

  vector<string>status;
  for(int i=0;i<num_prob;i++){
    string str;
    cin>>str;
    status.push_back(str);
  }
  int wa=0;
  int ac=0;
  int tle=0;
  int re=0;

  for(int i=0;i<status.size();i++){
    if(status[i]=="WA"){wa++;}
    else if(status[i]=="AC"){ac++;}
    else if(status[i]=="TLE"){tle++;}
    else if(status[i]=="RE"){re++;}
  }

  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 7468
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-01-29 22:24:56
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
const int N=510;
int k,n;
int ans[N][N];
int main()
{
	k=read();
	if(k==1){ printf("1\n1\n"); return 0; }
	n=(k/4+(k%4!=0))*2;
	fr(i,1,n) fr(j,1,n) ans[i][j]=(i&1?n:0)+(i+j)%n;
	fr(i,1,n) fr(j,1,n) if(ans[i][j]>=k) ans[i][j]-=n;
	printf("%d\n",n);
	fr(i,1,n) fr(j,1,n) printf("%d%c",ans[i][j]+1,j==n?'\n':' ');
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    set<int> st;
    queue<int> q;
    rep(i,n) {
        if (st.find(1) == st.end()) {
            st.insert(1);
            q.push(1);
        }
        else {
            st.erase(q.front());
            st.insert(q.front() + 1);
            q.push(q.front() + 1);
            q.pop();
        }
    }
    for (auto itr = st.begin(); itr != st.end(); itr++) {
        cout << *itr;
        if (itr != st.end()) cout << " ";
    }
    cout << endl; 
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if(a+b == c+d) printf("Balanced\n");
  else if(a+b < c+d) printf("Right");
  else printf("Left");
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n,m,x,a,s=0;
	cin>>n;
	cin>>m>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(m%a==0)
			s+=m/a;
		else
			s+=m/a+1;
	}
	cout<<s+x;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int maxn=1000000;
const int infly=(1<<21);
const int white=0;
const int grey=1;
const int black=-1;

struct node{
    int k;
    int to;
    int next;
};

struct node m[2*maxn+5];
int head[maxn+5],n=0;
int color[maxn+5],d[maxn+5],p[maxn+5];
int tu,k,v,c,nn;
int cnt=0;

void add(int u,int v,int tot)
{
    m[++n].k=v;
    m[n].next=head[u];
    m[n].to=tot;
    head[u]=n;
}

void ds()
{
    priority_queue<pair<int, int> > p;
    for(int i=0;i<=maxn;i++)
    {
        color[i]=white;
        d[i]=infly;
    }

    d[0]=0;
    p.push(make_pair(0,0));
    color[0]=grey;

    while(!p.empty())
    {
        pair<int,int> f=p.top();
        p.pop();
        int u=f.second;

        color[u]=black;

        for(int j=head[u];j;j=m[j].next)
        {
            int v=m[j].k;
            if(color[v]==black) continue;
            if(d[v]>d[u]+m[j].to)
            {
                d[v]=d[u]+m[j].to;
                p.push(make_pair(d[v]*(-1),v));
                color[v]=grey;
            }
        }
    }
}

int main()
{
    scanf("%d",&nn);
    for(int i=1;i<=nn;i++)
    {
        scanf("%d%d",&tu,&k);
        for(int j=1;j<=k;j++)
        {
            scanf("%d%d",&v,&c);
            add(tu,v,c);
        }
    }


    ds();
    for(int i=0;i<nn;i++)
    {
        printf("%d ",i);
        if(d[i]!=infly) printf("%d\n",d[i]);
        else printf("-1\n");
    }

    return 0;
}

Measured memory_bytes: 16940
while 1:
	try:
		N,M = map(int,raw_input().split())
		dp = [[0]*(M+1) for i in range(3)]
		for _ in range(N):
			name = raw_input()
			C,V,D,L = map(int,raw_input().split())
			VDL = [V,D,L]
			for i in range(3):
				try: dp[i][C] = max(dp[i][C],VDL[i])
				except: pass
				for j in range(M):
					if dp[i][j]:
						try: dp[i][j+C] = max(dp[i][j+C],dp[i][j]+VDL[i])
						except: break
		print max(max(dp[0]),max(dp[1]),max(dp[2]))
	except:
		break

Measured memory_bytes: 4272
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n,m; cin>>n>>m;
    pair<int,pair<int,int>> state[m];
    rep(i,m){
        cin>>state[i].second.first>>state[i].first;
        state[i].second.second=i+1;
    }
    sort(state,state+m);
    int cnt[n+1]={};
    priority_queue<pair<int,string>,vector<pair<int,string>>,greater<pair<int,string>>> pq;
    rep(i,m){
        int pre=state[i].second.first,num=state[i].second.second;
        int cnt0=0,pre1=pre,cnt1=++cnt[pre];
        int cnt2=cnt1;
        // cout<<pre1<<" "<<cnt1<<endl;
        while(pre1>0) {pre1/=10,cnt0++;}
        string tmp;
        rep(j,6-cnt0) tmp=tmp+"0";
        string ss;
        while(pre>0) {ss+=(pre%10+'0');pre/=10;}
        reverse(all(ss));
        tmp+=ss;
        cnt0=0;
        while(cnt1>0) {cnt1/=10,cnt0++;}
        rep(j,6-cnt0) tmp=tmp+"0";
        string sss;
        // cout<<cnt2<<endl;
        while(cnt2>0) {sss+=(cnt2%10+'0');cnt2/=10;}
        // cout<<sss<<endl;
        reverse(all(sss));
        tmp+=sss;
        // cout<<tmp<<endl;
        pq.push({num,tmp});
    }
    while(pq.size()){
        auto i=pq.top(); pq.pop();
        cout<<i.second<<endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a;
    int cnt[100006]={};
    map<int,int> mp;
    for(int i=0;i<n;i++){
        cin>>a;
        cnt[a]++;
        if(cnt[a]>1) mp[a]=cnt[a];
    }

    int odd=0,even=0;
    int ans=n;
    for(auto i:mp){
        if(i.second%2==0){
            ans-=i.second-2;
            if(even){
                ans-=2;
                even--;
            }
            else even++;

        }
        else{
            ans-=i.second-1;
        } 
    }
    if(even){
        ans-=2;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        string str;
        cin>>str;
        int n = str.size();
        int k = n;
        for(int i=0;i<n-1;++i)
       {
            if(str[i]!=str[i+1]) 
               k = min(k,max(n-i-1,i+1));
        }
        cout<<k<<endl;
        return 0;
    }

Measured memory_bytes: 512
#include <iostream>
#include <cctype>

using namespace std;

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

	int length = s.length();
	bool wa = false;
	bool c = false;
	if (s[0] == 'A' && islower(s[1])) {	
		for (int i = 2; i < length && !wa; ++i) {
			if (i < length - 1 && s[i] == 'C') {
				if (c) {
					wa = true;
				} else {
					c = true;
				}
			} else if (isupper(s[i])) {
				wa = true;
			}
		}
	}
	
	if (!wa && c)
		cout << "AC" << endl;
	else
		cout << "WA" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
#define F first
#define S second
#define pb push_back
#define REP(i,a,b) for (int i = a; i <= b; i++)

int main()
{
 string s;
  cin >> s;
 if(s[2]==s[3] && s[4]==s[5])
      {
          cout << "Yes" << endl;
      }
      else
      cout << "No" << endl;
  
  return 0;
}

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

int main(){
	int num[3];
  	cin >> num[0] >> num[1] >> num[2];
  	
  	for(int i=0; i<2; i++){
      for(int j=i+1; j<3; j++){
        if(num[i]<num[j]){
          int tmp=num[i];
          num[i]=num[j];
          num[j]=tmp;
        }
      }
    }
  if(num[0]==num[1] && num[1]==num[2]){
        cout << "No\n";
  }else if(num[0]==num[1] && num[1]!=num[2]){
        cout << "Yes\n";
  }else if(num[0]!=num[1] && num[1]==num[2]){
        cout << "Yes\n";
  }else{
      cout << "No\n";
  }
  return 0;
  
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C072
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int amax = s.Select(x => int.Parse(x)).Max();
            int[] a = new int[amax + 1];

            foreach (string c in s)
            {
                int i = int.Parse(c);
                a[i]++;
            }

            int max = 0;
            for (int i = 0; i <= amax; i++)
            {
                int sum = a[i];
                if (i > 0) sum += a[i - 1];
                if (i < amax) sum += a[i + 1];
                if (sum > max) max = sum;
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 19040
#include <bits/stdc++.h>
using namespace std;
int main(){
        int n, k; cin >> n >> k;
        for (int q = 0; q <= n; ++q){
            for (int w = 0; w <= n-q; ++w){
                int e = n - q - w;
                if (e < 0) break;
                if (q * 10000 + w * 5000 + e * 1000 == k){
                    cout << q << " " << w << " " << e << endl;
                    return 0;
                }
            }
        }
        cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main() {
    int a, b; cin >> a >> b;
    string S = "";
    if (a >= b) {
        for (int i = 0; i < a; i++) S += char('0' + b);
    }
    else {
        for (int i = 0; i < b; i++) S += char('0' + a);       
    }
    cout << S << endl;
}

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

int main(){
  char str[2048] = {}, *w;
  int len, f = 0;
  fgets(str, sizeof(str), stdin);
  for(w = strtok(str, " .,"); w != NULL;w = strtok(NULL, " .,")){
    len = strlen(w);
    if(len > 2 &&  7 > len){
      if(f != 0) putchar(' ');
      printf("%s", w);
      f++;
    }
  }
  puts("");
  return 0;
}

Measured memory_bytes: 528
#include <iostream>
#include<vector>
#include<string>
#include <sstream>      // std::ostringstream
using namespace std;
vector<string> split_s(const string &str, char sep);
vector<int> split_i(const string &str, char sep);
const int NOT_FOUND = -1;
int binary_search(vector<int> v, int target);
int main()
{
  string line;
  //S
  getline(cin, line);
  int ssize = stoi(line);
  getline(cin, line);
  vector<int>S= split_i(line, ' ');
  //T
  getline(cin, line);
  int tsize = stoi(line);
  getline(cin, line);
  vector<int>T= split_i(line, ' ');

  int totalcnt = 0;
  for (int t : T)
  {
    //cout << "debug : "<<t << endl;
    totalcnt += binary_search(S, t)==NOT_FOUND? 0:1 ;
  }
  cout<<totalcnt<<endl;
}
vector<string> split_s(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
vector<int> split_i(const string &str, char sep)
{
  vector<int> veci;
  vector<string> vecs = split_s(str, sep);
  for(string s:vecs)
  {
    veci.push_back(stoi(s));
  }
  return veci;
}
//二分探索
//startpointとendpointをちょこちょこ更新していく
int binary_search(vector<int> list,int target)
{
  int listsize = list.size();
  int divpoint = listsize / 2;
  int startpoint = 0;
  int endpoint = listsize-1;
  while (true)
  {
    int halfpoint=(startpoint + endpoint) / 2;

    int tmpval = list[halfpoint];
    //cout<<"debug startpoint,endpoint,tmpval :"<<startpoint<<","<< endpoint<< ","<<halfpoint<<endl;
    if (target < tmpval)
    {
      //左側にある
      endpoint = halfpoint;
    }
    else if (target==tmpval)
    {
      //探索終了
      return halfpoint;
    }
    else
    {
      //右側にある
      startpoint = halfpoint;
    }
    //探索範囲が残り1
    if(startpoint==endpoint)
    {
      if (target==list[startpoint])
      {
        //探索終了
        return startpoint;
      }
      return NOT_FOUND;
    }
    //探索範囲が残り2
    else if (endpoint-startpoint==1)
    {
      if (target==list[startpoint])
      {
        //探索終了
        return startpoint;
      }
      if (target==list[endpoint])
      {
        //探索終了
        return endpoint;
      }
      return NOT_FOUND;
    }
  }
}


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

int a,b,c,k;

int main(void){
	scanf("%d %d %d %d",&a,&b,&c,&k);
	int ans=0;
	ans+=min(k,a);
	k-=a;
	k-=b;
	if(k>0){
		ans-=k;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3796
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <string>
#include <deque>
#include <stack>
#include <cmath>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (LL i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<LL> VI;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000;
const LL LINF = 1LL * INF*INF;
const int MAX = 400040	;
const long double PI = acos(-1.);
const double EPS = 1e-6;
LL mod = 1000LL * 1000 * 1000 + 7;

int n;
int h[MAX/2];
LL a[MAX/2];
LL t[MAX/2];


LL getmax (int r)
{
	LL result = 0;
	for (; r >= 0; r = (r & (r+1)) - 1)
		result = max (result, t[r]);
	return result;
}

void update (int i, LL new_val)
{
	for (; i < n; i = (i | (i+1)))
		t[i] = max (t[i], new_val);
}


int main()
{
	//freopen("input.tXXt", "r", stdin);
	ios_base::sync_with_stdio(0);
//	FILL(dpT,-1);
	cin >> n;
	FOR(i,0,n)
		cin >> h[i];
	FOR(i,0,n)
		cin >> a[i];

	FOR(i,0,n)
	{
		update(h[i]-1,getmax(h[i]-2)+a[i]);
	}
	cout<<getmax(n-1);
	return 0;
}


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

int main(){
  int n;  cin >> n;
  vector<int> a(n);
  rep(i,n)	cin >> a[i];
  rep(i,n){
    if(a[i]%2) continue;
    if(a[i]%3==0 || a[i]%5==0) continue;
    puts("DENIED");
    return 0;
  }
  puts("APPROVED");
  return 0;
}

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


def solve(S: str, T: str, A: int, B: int, U: str):
    if (U == S):
        A -= 1
    else:
        B -=1

    print("{} {}".format(A,B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    U = next(tokens)  # type: str
    solve(S, T, A, B, U)

if __name__ == '__main__':
    main()


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

#define prtd(d) printf("%d\n", d)
#define prts(s) printf("%s\n", s.c_str())
#define cout(s) cout << s << endl
#define rep(i,n) for(long long (i)=0;(i)<(n);(i)++)

#define SIZE(array) sizeof(array)/sizeof(*array)

long long combi(long long n, long long k);
long long same_L(long long *A, size_t SIZE);
long long check_same(long long sum, long long *A);
void small(long long *A, long long i);
void big(long long *A, long long i);

long long cost = 0;

int main(void) {

	long long N;
	cin >> N;

	
    long long A[N];
	long long L=0;
	for(int i=0; i<N; i++){
		scanf("%lld", &A[i]);
		L+=A[i];
		//cout << A[i] << endl;
	}
    long long min_cost = L;
    long long sum = 0; //sum 前半部分の和
    //printf("L=%lld\n", L);
    //printf("L=%d\n", L);
    for(int i = 0; i<N; i++){
		sum+=A[i];
        //printf("sum(0~%d)=%d \n", i, sum);
        //long long sum_latter = L - sum;
        //printf("sum_latter(%d~%lld)=%d \n", i+1, N, sum_latter);
        //min_cost = min(min_cost, abs(sum - (L-sum))); 
        //printf("min_cost = %lld \n", min_cost);
        min_cost = min(min_cost, abs(sum - (L - sum)));
        
    }
    prtd(min_cost);
    //cout << "min(5,abs(1-7)): "<< min(2,abs(3-(10-3))) << endl;
    //printf("%d\n", min_cost);
    /*

	
	//cout <<"size(in main):" << SIZE(A) << endl;

	long long loc = same_L(A, SIZE(A));
	//printf("loc=%d", loc);
	long long cost_max = 999;
	if(loc != -1){
		prtd(0);
		return 0;
	}else{
		long long sum=0;
		for(long long i = 0; i<SIZE(A); i++){
			sum+=A[i];
			//printf("sum(0~%d)=%d \n", i, sum);
			long long after = 0;
			
			//for(long long j=i+1; j<SIZE(A);j++){
			//	after += A[j];
			//}
			after = L -sum;
			//printf("sum_after(%d~%d)=%d \n\n", i+1, N,after);
			long long cost = abs(sum - after);
			//printf("(sum, after, cost) = (%d, %d, %d)\n", sum, after, cost);
			if((cost_max == -999)|| (cost < cost_max)) cost_max = cost;
		}
	}*/

	//prtd(cost_max);




    return 0;
}



long long same_L(long long *A, size_t size){
	//cout << "--------in same_L---------" << endl;
	long long sum=0;
	//size_t size =  SIZE(A);
	//printf("(size, sum)=(%d, %d)\n",size, sum);
	//cout <<"size(in same_L):" << size << endl;
	
	for(long long i=0; i<size-1; i++){
		sum+=A[i];
		//printf("(i,sum)=(%d,%d)\n",i,sum);
		long long sum_after = 0;
		for(long long j=i+1; j<size;j++){
			sum_after += A[j];
		}
		//printf("(sum, sum_after) = (%d, %d)\n", sum, sum_after);
		if(sum == sum_after) return i; //i番目で2等分できる

	}
	return -1; //分割不可能

	cout << "--------in same_L---------" << endl;
}

void small(long long *A, long long i){
	if(A[i] >= 2) A[i]--;
	else printf("ERROR in small");

	cost++;
}

void big(long long *A, long long i){
	A[i] += 1;
	cost++;
}


//nCkの計算関数
long long combi(long long n, long long k){
	if(n == k || k == 0){
		return 1;
	}
	else{
		return combi(n-1, k-1) + combi(n-1, k);
	}
}

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

const int N = 1e5 + 7;

int n, m, q;
vector <int> ad[N];
int str[N], clr[N], dis[N];
int res[N], cld[N];

void solve(int t) {
	if (dis[t] == 0 && !res[str[t]])
		res[str[t]] = clr[t];
	if (cld[str[t]] >= dis[t])
		return;
	cld[str[t]] = dis[t]; 
	queue < pair <int, int> > qer;
	qer.push({str[t], dis[t]});
	if (!res[str[t]])
		res[str[t]] = clr[t];
	while (qer.size()) {
		int v = qer.front().first, d = qer.front().second;
		qer.pop();
		if (!d)
			continue;
		for (auto u: ad[v]) {
			if (cld[u] < d - 1) {
				qer.push({u, d - 1});
				cld[u] = d - 1;
				if (!res[u])
					res[u] = clr[t];
			}
			if (!res[u])
				res[u] = clr[t];	
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int a, b;
		cin >> a >> b;
		ad[a].push_back(b);
		ad[b].push_back(a);
	}
	cin >> q;
	for (int i = 1; i <= q; i++)
		cin >> str[i] >> dis[i] >> clr[i];
	for (int i = q; i >= 1; i--)
		solve(i);
	for (int i = 1; i <= n; i++)
		cout << res[i] << endl;
	return 0;
}


Measured memory_bytes: 8952