akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

int N,Q;
string s;
vector<pair<char,char> > v;

int fall(int x){
  if(x<0) return 1;
  else if(x>=N) return 2;
  int i;
  REP(i,v.size()){
    if(v[i].first == s[x]){
      if(v[i].second == 'L') x--;
      else x++;
    }
    if(x<0) return 1;
    else if(x>=N) return 2;
  }
  return 0;
}

//mode 0 左側に落ちない最小値，mode 1 右側に落ちる最小値
int binary_search(int start,int end, int mode){
  while(true){
    int mid = (start+end)/2;
    int f = fall(mid);
    if(end-start<=1) break;
    if(mode){
      if(!f) start=mid;
      else end=mid;
    }else{
      if(!f) end=mid;
      else start=mid;
    }
  }
  return end;
}

int main(void){
  int i,j;
  cin >> N >> Q;
  cin >> s;
  REP(i,Q){
    char x,y;
    cin >> x >> y;
    v.push_back(pair<char,char>(x,y));
  }
  int start=0,end=N,mid;

  //xが落ちない位置になるようにする．
  while(true){
    mid = (start + end)/2;
    int f = fall(mid);
    if(!f) break;
    else if(f==1) start = mid+1;
    else end = mid;
    if(end-start < 1) break;
  }
  int S,E;
  //S左側に落ちない最初
  //E右側に落ちる最初
  if(fall(start)%2==0) S=start;
  else S = binary_search(start, mid, 0); 
  if(fall(end)!=2) E = end+1;
  else E = binary_search(mid, end,1);
  cout << E-S << endl;
  return 0;
}


Measured memory_bytes: 1024
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)

p = list(map(int, input().split()))

m = [True] * (105)
for i in range(n):
  m[p[i]] = False

l = x
r = x

for i in range(105):
  if m[l] and m[r]:
    print(l)
    exit(0)
  if m[l] and not m[r]:
    print(l)
    exit(0)
  if not m[l] and m[r]:
    print(r)
    exit(0)
  l -= 1
  r += 1
    

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

int main() {
    int n, k, ans = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ans += min(abs(x - k), x);
    }
    ans *= 2;
    cout << ans << endl;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;
 
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int L;
	cin>>L;
	vector<int> ANS[3];

	rep(i,0,19)
	{
		ANS[0].push_back(i+1);
		ANS[1].push_back(i+2);
		ANS[2].push_back(0);
	}

	int b=1;
	int p=1;

	while(2*b<=L)
	{
		ANS[0].push_back(p);
		ANS[1].push_back(p+1);
		ANS[2].push_back(b);
		p++;
		b*=2;
	}

	int sum=L-b;
	int d=b;
	p--,b/=2;
	while(sum!=0)
	{
		if(sum-b>=0)
		{
			ANS[0].push_back(p);
			ANS[1].push_back(20);
			ANS[2].push_back(d);
			sum-=b;
			d+=b;
		}
		b/=2;
		p--;
	}

	cout<<20<<" "<<SZ(ANS[0])<<endl;
	rep(i,0,SZ(ANS[0]))
	{
		cout<<ANS[0][i]<<" "<<ANS[1][i]<<" "<<ANS[2][i]<<endl;
	}
	
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define N first
#define ind second
using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int n, m; cin >> n >> m, n; cout << endl){
        vi in(m);
        while(n --) rep(i, m){
            int dif; cin >> dif;
            in[i] += dif;
        }
        rep(i, m){
            vi::iterator it = max_element(ALL(in));
            cout << ((i)?" ":"") << it - in.begin() + 1;
            *it = -1;
        }
    }

    return 0;
}

Measured memory_bytes: 1196
#include<iostream>
using namespace std;
int main(){
    string w,t;
    int c=0;
    cin>>w;
    for(int i=0; i<w.length(); i++)        w[i]=tolower(w[i]);
    while(cin>>t){
        if(t=="END_OF_TEXT")    break;
        for(int i=0; i<t.length(); i++)    t[i]=tolower(t[i]);
        if(t==w)    c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
#define mod 998244353LL
#define powmod 998244351LL
using namespace std;
long long f[300001];
int N,A,B;
long long K,Ans = 0;
void factorial()
{
   f[0] = 1LL;
   for(int i = 1;i <= 300000;i++)
   {
      f[i] = (long long)(f[i - 1] * i * 1LL)% mod;
   }
}
long long power(int u,int v)
{
   if(v == 0) return 1LL;
   if(v == 1) return u*1LL;
   long long X = power(u,v/2) % mod;
   if(v % 2 == 0) return X * X % mod;
   else return ((X * X) % mod * u) % mod;
}
long long C(int k,int n)
{
   //printf("C(%lld,%lld) = %lld\n",k,n,nume*power(deno,powmod) % mod);n
   long long _n = f[n];
   long long _k = f[k];
   long long _t = f[n - k];
   long long deno = power(_k,powmod) * power(_t,powmod) % mod;
   long long nume = _n;
   return nume * deno % mod;
}
signed main()
{ 
    factorial();
   cin >> N >> A >> B >> K;
   //cout << "Snap!";
   for(int i = 0;i < N + 1;i++)
   {
      if((K - A*i) % B == 0LL)
      {
         long long j = (K - A*i)/B;
         if(j > N || j < 0LL) continue;
         Ans += C(i,N) * C(j,N) % mod;
      }
   }
   cout << Ans % mod;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

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

constexpr ll MOD = 1000000007;

int p[100001];

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, k, q; cin >> n >> k >> q;
  rep(i, n) p[i] = k - q;

  rep(i, q) {
    int a; cin >> a;
    ++p[a-1];
  }

  int ans = 0;
  rep(i, n) {
    if (p[i] > 0) cout << "Yes\n";
    else cout << "No\n";
  }

  return (0);
}


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

def nCk(n, k, mod=10 ** 9 + 7):
    if n < k:
        return 0
    k = min(k, n - k)
    
    numer = 1
    for x in range(n - k + 1, n + 1):
        numer = (numer * x) % mod
        
    denom = 1
    for x in range(1, k + 1):
        denom = (denom * x) % mod
## if z=pow(x,-1)%P, where P is prime then according to Fermat's Theorem z=pow(x,P-2)%P,
    return numer * pow(denom, mod - 2, mod) % mod
  
if (X+Y)%3!=0:
    print(0)
else:
    a = (2*Y - X)//3
    b = (2*X - Y)//3
    if a<0 or b<0:
        print(0)
    else:
        print(nCk(a+b, a)%(7+10**9))

Measured memory_bytes: 39280
/*
g++ code.cpp
./a.out
*/

#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main() {
    int64_t n;
    cin >> n;
    vector<int64_t> a(n-1);
    vector<int64_t> b(n);
    rep(i,n-1){
        cin >> a[i];
        b[a[i]-1]++;
    }
    rep(i,n){
        cout << b[i] << endl;
    }

}

Measured memory_bytes: 6424
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <cmath>

#define ll long long int
#define loop(v,n) for(ll v=0;v<n;v++)

using namespace std;

#define MAXN 100000

priority_queue<ll> s,t;

vector<pair<pair<string,ll>,int>> r;

int main() {
    /*
    int a,p;
    cin >> a>>p;
    cout << (a*3+p)/2 << endl;
     */
    int n;
    cin >> n;
    for(int  i = 0;i < n;i++) {
        string s;
        ll p;
        cin >> s >> p;
        r.push_back(make_pair(make_pair(s,1000-p),i+1));
    }
    sort(r.begin(),r.end());
    for(auto& e:r) {
        cout << e.second << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 1;
  ll n, p;
  cin >> n >> p;
  mllll m;
  while(p % 2 == 0) {
    m[2]++;
    p /= 2;
  }
  for(int i = 3; i <= sqrt(p); i += 2) {
    while(p % i == 0) {
      m[i]++;
      p /= i;
    }
  }
  if(p > 2)
    m[p]++;

  for(auto x: m) {
    // ans *= pow(x.first, x.second / n);
    fi(0, x.second / n)
      ans *= x.first;
  }

  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	int a;
	cin >> a;
	cout << "ABC" << a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    vec<l_l> v;
    rep(i,N){
        ll X, L;
        cin >> X >> L;
        v.emplace_back(X+L-1,X-L);
    }
    //終端ソート
    sort(all(v));
    //print(v);
    ll ans = 0;
    ll r = -INFLL;
    for(int i = 0; i < N; i++){
        ll nr = v[i].first;
        ll nl = v[i].second;
        if(r < nl){
            r = nr;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2420
#include<cstdio>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define MAXN 2000000
#define INF 0x7FFFFFFF
int main() {
	int n,x,y;
	scanf("%d%d%d",&n,&x,&y);
	n-=x;
	while(n>=y)
		n-=y;
	printf("%d\n",n);
	return 0;
}


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

int main() {
	char s[13];
	for (int i = 0; i < 13; i++) {
		if (i != 4) {
			cin >> s[i];
		}
		else {
			s[i] = ' ';
		}
		cout << s[i];
	}
	cout << endl;
}

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

int main(){
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<int>l(n);
  for(int i=0; i<n; i++)cin >> l[i];
  sort(l.begin(), l.end());
  int ret=1000000000;
  do {
    for(int i=1; i<=n-2; i++){
      for(int j=i+1; j<=n-1; j++){
        int tmpret=0;
        vector<int>rui=l;
        
        for(int k=1; k<i; k++)rui[k]+=rui[k-1];
        for(int k=i+1; k<j; k++)rui[k]+=rui[k-1];
        for(int k=j+1; k<n; k++)rui[k]+=rui[k-1];
        
        int mind=10000000;
        for(int k=0; k<i; k++)mind=min(mind, abs(a-rui[k])+10*k);
        tmpret+=mind;
        mind=10000000;
        for(int k=i; k<j; k++)mind=min(mind, abs(b-rui[k])+10*(k-i));
        tmpret+=mind;
        mind=10000000;
        for(int k=j; k<n; k++)mind=min(mind, abs(c-rui[k])+10*(k-j));
        tmpret+=mind;
        
        ret=min(ret, tmpret);
      }
    }
  }while(next_permutation(l.begin(), l.end()));
  cout << ret;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	int arr[n];
	double last = 0, cur = 0;
	for (int i = 0; i < n; ++i){
		cin >> arr[i];
		if(i < k)
			cur += log(arr[i]);
	}
	for (int i = k; i < n; ++i) {
		cur = last;
		cur -= log(arr[i - k]);
		cur += log(arr[i]);

		if(cur > last)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;

		last = cur;
	}
}

Measured memory_bytes: 4712
f = lambda: map(int,input().split())
n,_ = f()
a = list(f())
b = [a[0]]+[0]*(n-1)
for i in range(1,n):
    b[i] = min(a[i], b[i-1])
c = [a[i]-b[i] for i in range(n)]
m = max(c)
print(c.count(m))


Measured memory_bytes: 14224
#include <math.h>
#include <stdio.h>

#define swap( x, y ) do { double tmp; tmp = x; x = y; y = tmp; } while ( 0 )
#define EPS 1e-10

int rel_s_s( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double *x, double *y ) {
	double dn = ( x2 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y2 - y1 );
	double nm = ( x3 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y3 - y1 );

	if ( fabs( dn ) < EPS )
		if ( fabs( nm ) < EPS ) {
			if ( x1 == x2 ) {
				if ( y2 < y1 )
					swap( y1, y2 );
				if ( y4 < y3 )
					swap( y3, y4 );

				if ( y4 < y1 || y2 < y3 )
					return 3;
				else if ( y4 == y1 || y2 == y3 ) {
					*x = x1;
					*y = y4 == y1 ? y1 : y2;
					return 4;
				} else
					return 5;
			} else {
				if ( x2 < x1 ) {
					swap( x1, x2 );
					swap( y1, y2 );
				}
				if ( x4 < x3 )
					swap( x3, x4 );

				if ( x4 < x1 || x2 < x3 )
					return 3;
				else if ( x4 == x1 || x2 == x3 ) {
					*x = x4 == x1 ? x1 : x2;
					*y = x4 == x1 ? y1 : y2;
					return 4;
				} else
					return 5;
			}
		} else
			return 2;
	else
		if ( fabs( nm / dn - 0.5 ) < 0.5 + EPS && fabs( ( ( x3 - x1 ) * ( y2 - y1 ) - ( x2 - x1 ) * ( y3 - y1 ) ) / dn - 0.5 ) < 0.5 + EPS ) {
			*x = x1 + nm / dn * ( x2 - x1 );
			*y = y1 + nm / dn * ( y2 - y1 );

			if ( fabs( ( x2 - x1 ) * ( x4 - x3 ) + ( y2 - y1 ) * ( y4 - y3 ) ) < EPS )
				return 1;
			else
				return 0;
		} else
			return 6;
}

int main( void ) {
	int q;

	scanf( "%d", &q );
	while ( q-- ) {
		double x0, y0, x1, y1, x2, y2, x3, y3, x, y;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3 );

		rel_s_s( x0, y0, x1, y1, x2, y2, x3, y3, &x, &y );
		printf( "%.8f %.8f\n", x, y );
	}

	return 0;
}

Measured memory_bytes: 668
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<cstdio>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007

#define ARRAY_MAX 10005


int main(){

    int n,a;
    cin >> n;
    multiset<int> st;
    REP(i,n){
        cin >> a;
        st.insert(a);
    }
    int ans = 0;
    while(!st.empty()){
        auto itr = st.end();
        itr--;
        int x = *itr;
        st.erase(itr);
        int num = 1;
        for(num = 1;num <= x;num *= 2);
        if(st.find(num-x) != st.end()){
            st.erase(st.find(num-x));
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9600
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}


void solve() {
	int K, Q; cin >> K >> Q;
	vector<int>D(K);
	REP(i, K)cin >> D[i];
	while (Q--) {
		int n, x, m; cin >> n >> x >> m;
		x %= m;
		vector<int>d = D;
		REP(i, K)d[i] %= m;
		ll sum = 0;
		REP(i, K)sum += d[i];
		int c = n - 1;
		x += c / K * sum;
		int rem = c - c / K * K;
		REP(i, rem)x += d[i];
		ll over = x / m;
		ll c_sum = 0;
		REP(i, K)if (d[i])c_sum++;
		ll ans = c_sum * (c / K);
		REP(i, rem)if (d[i])ans++;
		ans -= over;
		print(ans);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

struct Operation {
    int64_t b{};
    int64_t c{};
};

int main() {
    int n{}, m{};
    std::cin >> n >> m;
    std::vector<int64_t> a(n);
    std::vector<Operation> op(m);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    for (int i = 0; i < m; i++) std::cin >> op[i].b >> op[i].c;
    std::sort(a.begin(), a.end());
    std::sort(op.begin(), op.end(), [](const auto& x, const auto& y) {
        return x.c > y.c;
    });
    int a_i = 0;
    int op_i = 0;
    while (a_i < n && op_i < m && op[op_i].c > a[a_i]) {
        a[a_i] = op[op_i].c;
        op[op_i].b--;
        if (op[op_i].b == 0) op_i++;
        a_i++;
    }
    std::cout << std::accumulate(a.begin(), a.end(), 0LL) << std::endl;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1 << 20;
int a, b, c, d, e, f;
bool can_water[N];
bool can_sugar[N];
const int F = 3001;

void update(int& x, int& y, int X, int Y)
{
	if (x == -1)
	{
		x = X;
		y = Y;
		return;
	}
	
	int moje = X / 100 * e;
	if (moje < Y) return;
	
	if (y * (X + Y) > Y * (x + y)) return;
	
	x = X;
	y = Y;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> a >> b >> c >> d >> e >> f;
	
	FOR(i, 0, F) FOR(j, 0, F)
		can_water[i * a + j * b] = true; 
	FOR(i, 0, F) FOR(j, 0, F)
		can_sugar[i * c + j * d] = true; 
	
	int ans_water = -1, ans_sugar = -1;
	
	for(int water = 100; water <= f; water += 100) 
	for(int sugar = 0; sugar + water <= f; ++sugar)
		if (can_water[water / 100] && can_sugar[sugar])
			update(ans_water, ans_sugar, water, sugar);
	
	assert(ans_sugar != -1);
	cout << ans_water + ans_sugar << ' ' << ans_sugar << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



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

int main() {
	int a[4];
	string input; cin >> input;
	for (int i = 0; i < 4; i++) a[i] = input[i] - '0';
	

	for (int x = 0; x < 8; x++) {
		int sum = a[0];
		string s;
		s += (char)('0' + a[0]);
		for (int i = 0; i < 3; i++) {
			if (x & (1 << i)) {
				sum += a[i + 1];
				s += '+';
				s += (char)('0' + a[i + 1]);
			}
			else {
				sum -= a[i + 1];
				s += '-';
				s += (char)('0' + a[i + 1]);
			}
		}
		if (sum == 7) {
			cout << s + "=7" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import collections

N = int(input())
S = list()
for i in range(N):
  S.append(str(input()))

c = collections.Counter(S)
d = c.most_common()
d = d + [("test", 0)]
e = list()

e.append(d[0][0])

for j in range(N):
  if d[j][1] == d[j+1][1]:
    e.append(d[j+1][0])
  else:
    break

f = sorted(e)

for k in range(len(f)):
  print(f[k])

Measured memory_bytes: 49300
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i <= (n); ++i)
#define repD(i, a, n) for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define MAXN 5000000
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
const long long mod = 1000000007;
int Ceil(int a, int b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}
int main(){
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int n;
    cin>>n;
    ll ans = 0;
    for(ll i = 1;i<=n;i++){
       for(ll j = 1;j<=n;j++){
        for(ll k = 1;k<=n;k++){
            ll g = __gcd(__gcd(i,j),k);
            ans+= g;
        }
       }
    }
    cout<<ans;
return 0;
}

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

using namespace std;

using ll  = long long;

ll d = 1e9+7;

int main() {

	ll N;
	cin>>N;
	vector<ll> A(N);
	for (auto &x : A) {
		cin>>x;
	}
	
	ll ans = 0;
	ll y = 0;
	for (ll c = 0;c < 60;++c) {
		y = 1LL<<c;
		ll a = 0, b = 0;
		for (auto &x : A) {
			if (x&y) a += 1;
			else b += 1;
		}
		
		ll temp_ans = ((y%d)*((a*b)%d))%d;
		ans += temp_ans%d;
	}
	
	cout<<ans%d<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>

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

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

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

    std::vector<int> l(n + 1, 0), r(n + 1, 0);

    for (int i = 0; i < n; i++) {
        l[i + 1] = gcd(l[i], a[i]);
    }

    for (int i = n - 1; i >= 0; i--) {
        r[i] = gcd(r[i + 1], a[i]);
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = std::max(ans, gcd(l[i], r[i + 1]));
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 1536
import math

if __name__=="__main__":
    n, k = map(int, input().split())
    log_k_n = math.log10(n)/math.log10(k)
    if math.floor(log_k_n) == math.ceil(log_k_n):
        print(math.ceil(log_k_n) + 1)
    else:
        print(math.ceil(log_k_n))

Measured memory_bytes: 3060
n, m, v, p = map(int, input().split())
# n:問題数 m:人数 v:投じる標数 p:選ばれるもの
prob_set = list(map(int, input().split()))
prob_set.sort(reverse=True)
ruiseki_prob = [0 for i in range(n)]
ruiseki_prob[0] = prob_set[0]
high = n
low = 0
mid = (high + low) // 2
f = True


for i in range(1, n):
    ruiseki_prob[i] = ruiseki_prob[i - 1] + prob_set[i]

while low < high:
    mid = (low + high) // 2
    if mid <= p-1:
        f = True
    elif prob_set[mid] + m < prob_set[p - 1]:
        f = False
    else:
        hyou = m * (p - 1) + m * (n - mid)
        for i in range(p-1,mid):
            hyou += prob_set[mid] + m - prob_set[i]
        # まず0 ~ p-2まで(1,2,,,p-1まで) :p-1
        # 次にmid,mid+1,,,n-1まで       :n-mid
        # 上限はp-1,p,,,mid-1は(mid)+mずつ
        # 和はmid-1 - p-2
        if hyou < m*v:
            f = False
        else:
            f = True
    if f:
        low = mid + 1
    else:
        high = mid

print(high)

# 昇順に並んでいるとき,a_i が選ばれる → i > jなるa_jも選ばれる
# 二分探索することで間に合いそう
# あるiについて評価するとき,以下の観点に注意する


Measured memory_bytes: 14964
def main():
    # 写経AC
    MOD = 10**9 + 7
    S = input()
    N = len(S)
    dp = [[0]*2 for i in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        # a+b = 0
        if S[i] == '0':
            dp[i+1][0] = dp[i][0]
            dp[i+1][1] = dp[i][1]
        else:
            dp[i+1][1] = dp[i][0] + dp[i][1]
            dp[i+1][1] %= MOD
        # a+b = 1
        if S[i] == '0':
            dp[i+1][1] += dp[i][1]*2
            dp[i+1][1] %= MOD
        else:
            dp[i+1][0] += dp[i][0]*2
            dp[i+1][0] %= MOD
            dp[i+1][1] += dp[i][1]*2
            dp[i+1][1] %= MOD
    print((dp[N][0]+dp[N][1]) % MOD)


if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin >> N;
  
  int sum;
  
  if (N <= 9){
    sum += N;
  }
  else{
    sum += 9;

    if (N > 99){
      sum += 0;
      
      if (N <= 999){
        sum += N - 99;
      }
      else{
        sum += 900;
        
        if (N > 9999){
          sum += 0;
          
          if (N <= 99999){
            sum += N - 9999;
          }
          else{
            sum += 90000;
          }
        }
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    if(s.size()==2)cout<<s<<endl;
    else{
        reverse(all(s));
        cout<<s<<endl;
    }
}

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

int main(void){
   string str1;
   cin >> str1;
   int count = 0;
   for(int i = 0;i < 4;i++){
    if(str1.at(i) == '+'){
        count++;
    }else{
        count--;
    }
   }
   cout << count << endl;
}

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

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

Measured memory_bytes: 256
H, W = list(map(int, input().split()))
C = [list(map(int, input().split())) for _ in range(10)]

# T[j][i]: cost from j to i, O(V^3)
# T[j][i] = 0 if j == i


def warshall_floyd(T, V):
    for k in range(V):
        for j in range(V):
            for i in range(V):
                T[j][i] = min(T[j][i], T[j][k] + T[k][i])


warshall_floyd(C, 10)

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

ans = 0
for h in range(H):
    for w in range(W):
        if A[h][w] != -1:
            ans += C[A[h][w]][1]
print(ans)


Measured memory_bytes: 40412
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

#define SEG_LEN (1 << 18)
int seg[SEG_LEN *2];

void add(int ind, int v){
    ind += SEG_LEN;
    seg[ind] += v;
    while (true){
        ind /= 2;
        if (ind == 0)break;
        seg[ind] = seg[ind*2] + seg[ind*2 + 1];
    }
}

int sum(int l, int r){
    l += SEG_LEN;
    r += SEG_LEN;
    int ret = 0;
    while (l < r){
        if (l%2 == 1){
            ret += seg[l];
            l++;
        }
        l /= 2;

        if (r%2 == 1){
            ret += seg[r-1];
            r--;
        }
        r /= 2;
    }
    return ret;
}


int main() {
    int n,q; cin >> n >> q;
    
    for (int i=0; i<q; i++){
        int com; cin >> com;
        // add
        if (com == 0){
            int ind , v;
            cin >> ind >> v;
            add(ind, v);
        }
        if (com == 1){
            int l, r; cin >> l >> r;
            // 半開区間
            cout << sum(l,r+1) << endl;
        }
    }
}


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

int main()
{
    int n; cin>>n;
    vector<int> a(n);
    for(auto& e: a) cin>>e;

    int x=0;
    int y=*max_element(begin(a), end(a));
    for(auto& e: a) if (abs(y/2-e)<abs(y/2-x)) x=e;
    cout<<y<<' '<<x<<endl;
}


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

int f(int e) {
	if(11 <= e) return 0;
	if(6 <= e) return 1;
	if(2 <= e) return 2;
	else return 3;
}

int main(void) {
	int ans[4][2];
	int i;
	double l, r;
	memset(ans, 0, sizeof ans);

	for(;~scanf("%lf %lf", &l, &r);) {
		ans[f(l * 10 + 1e-10)][0]++;
		ans[f(r * 10 + 1e-10)][1]++;
	}

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

	return 0;
}

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


const ll mod = 1000000007;
#define MAX_N 2200000
ll f[MAX_N];
ll invf[MAX_N];

ll modpow(ll  a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll nCm(ll n,ll m){return ((f[n]*invf[m])%mod)*invf[n-m]%mod;  }

int gcd(int x,int y){
    if(x%y == 0)return y;
    return gcd(y%x,x);
}

map<P,int> mp1,mp2;
int non;
signed main()
{
    int n;cin >> n;
    rep(i,n){
        int a,b;cin >> a >> b;
        if( a == 0 && b == 0)non++;
        else if(a == 0){
            mp1[P(0,1)]++;
            mp2[P(1,0)]++;
        }
        else if(b == 0){
            mp1[P(1,0)]++;
            mp2[P(0,1)]++;
        }

        else if(a > 0 && b >0){
            int hoge = gcd(a,b);
            mp1[P(a/hoge,b/hoge)]++;
            mp2[P(-b/hoge,a/hoge)]++;
        }
        else if(a > 0 && b < 0){
            int hoge = gcd(a,-b);
            mp1[P(-a/hoge,-b/hoge)]++;
            mp2[P(-b/hoge,a/hoge)]++;


        }
        else if(a < 0 && b > 0){
            int hoge = gcd(-a,b);
            mp1[P(a/hoge,b/hoge)]++;
            mp2[P(b/hoge,-a/hoge)]++;

        }
        else if(a < 0 && b < 0){
            int hoge = gcd(-a,-b);
            mp1[P(-a/hoge,-b/hoge)]++;
            mp2[P(b/hoge,-a/hoge)]++;
        }

        
    }
    int ans = 1;
    for(auto tmp:mp1){
        
        auto pr = tmp.first;
        auto p = tmp.second;
        auto q = mp2[pr];
        
        int res =modpow(2ll,p,mod) + modpow(2ll,q,mod) -1;//仲の悪い集合A,Bについて、AとBどちらからもとるようなことがないように選ぶ場合の数
        int a = pr.first,b = pr.second;
        if(a == 0){
            mp2[P(1,0)] = 0;
            mp1[P(1,0)] = 0;

        }
        else if(b == 0){
            mp2[P(0,1)] = 0;
            mp1[P(0,1)] = 0;

        }
        if( a> 0 &&b > 0){
            mp2[P(-b,a)] = 0;
            mp1[P(-b,a)] = 0;
        }
        else if(a <0 && b >0){
            mp2[P(b,-a)] = 0;
            mp1[P(b,-a)] = 0;
        }

        ans *= res;
        ans = (ans%mod+mod)%mod;
        

    }
    ans -= 1;//一つも選ばない
    ans += non;//ゼロゼロは単体でしか選べない
    
    cout << (ans%mod+mod)%mod << endl;

    
    return 0;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
#define VL vector<lol>
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    lol n, m; cin >> n >> m;
    vector<vector<lol>> f(n+1);
    REP(i, m)
    {
        lol a, b; cin >> a >> b;
        f[a].push_back(b);
        f[b].push_back(a);
    }
    
    lol count{1}, group[n+1] = {};
    FOR(i, 1, n)
    {
        //cout << "a" << endl;
        if(group[i] != 0) continue;
        queue<lol> que;
        que.push(i);
        group[i] = count;
        //cout << "b" << endl;
        while(!que.empty())
        {
            lol cur = que.front(); que.pop();
            REP(j, f[cur].size())
            {
                lol fnext = f[cur][j];
                if(group[fnext] == 0)
                {
                    group[fnext] = count;
                    que.push(fnext);
                }
            }
        }
        count++;
    }
    count--;
    VL groupnum(count+1, 0);
    FOR(i, 1, n)
    {
        //cout << group[i] << " ";
        groupnum[group[i]]++;
        //cout << groupnum[group[i]] << " ";
    }
    sort(ALL(groupnum));
    //cout << groupnum[2];
    lol save{0};
    REP(i, count)
    {
        //cout << i+1 << " " << groupnum[i+1] << " " << endl;
        save += groupnum[i+1] - groupnum[i];
    }
    result = save;

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 18316
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var seqH = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        for (int i = seqH.Length - 1; i > 0; --i)
        {
            int ii = i - 1;
            if (seqH[i - 1] - 1 > seqH[i])
            {
                Console.WriteLine("No");
                return;
            }

            seqH[i - 1] -= Math.Max(seqH[i - 1] - seqH[i], 0);
        }
        Console.WriteLine("Yes");
    }
}


Measured memory_bytes: 25948
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
ll dp[1<<16],w[1<<16];int n,a[101][101];
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)scanf("%d",&a[i][j]);
	for(int i=1;i<(1<<n);++i){ll ans=0;int k=log2(i&-i);for(int j=1;j<=n;++j)(i&(1<<j-1))&&(ans+=a[k+1][j]);w[i]=w[i&(i-1)]+ans;}
	memset(dp,-0x3f,sizeof(dp));dp[0]=0;
	for(int i=0;i<(1<<n);++i)for(int x=(~i)&((1<<n)-1);x;x=(x-1)&(~i))dp[i|x]=max(dp[i|x],dp[i]+w[x]);
	printf("%lld\n",dp[(1<<n)-1]);return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for(int i = f; i < (int)l; ++i)
#define repit(it, t) for(__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++)
#define endl "\n"
#define pb emplace_back
#define lb lower_bound
#define int long long
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second
#define DBG0(x) { cout << #x << ": " << x << "\t"; }
#define DBG(x) {DBG0(x); cout << endl;}
#define DBG2(x, y) {DBG0(x); DBG(y);}
#define DBG3(x, y, z) {DBG0(x); DBG2(y, z);}
#define DBG4(w, x, y, z) {DBG0(w); DBG3(x, y, z);}

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;

int gcd(int x, int y) {
    if (x == y) {
        return x;
    }
    if (x > y) {
        return gcd(y, x);
    }
    return y % x == 0 ? x : gcd(y % x, x);
}

signed main(void){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans;
    cin >> ans;
    rep(i, n - 1) {
        int a;
        cin >> a;
        ans = gcd(ans, a);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# ABC 155: B – Papers, Please
N = int(input())
A = [int(s) for s in input().split()]

result = 'APPROVED'

for n in A:
    if n % 2 == 0:
        if n % 3 != 0 and n % 5 != 0:
            result = 'DENIED'
            break

print(result)

Measured memory_bytes: 2940
n = int(input())
nn = n

keta = 0
for i in range(1,20):
    nn -= (26 ** i)
    if nn <= 0:
        keta = i
        break

nn += (26 ** keta - 1)
a = []
for i in range(keta):
    x = nn % 26
    nn //= 26
    a.append(x)
        
ans = []
for i in a[::-1]:
    ans.append(chr(97+i))
    
print(*ans,sep="")

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

typedef long long ll;

#define F first 
#define S second 
#define PB push_back
#define MP make_pair 
#define rep(i,a,b) for (ll i=a;i<b;i++)
const ll INF = 1LL << 60;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;
typedef pair<ll,ll> pl;


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

    if(a[2] == a[3] && a[4]==a[5]) {
        cout<< "Yes"<<endl;
    } else 
    {
        cout<<"No"<<endl;
    }

    return 0; 
}



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

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

  map<int, int> mp;
  int A, B;
  for (int i = 0; i < N; i++) {
    cin >> A >> B;
    mp[A] = B;
  }

  // for (auto it = mp.begin(); it != mp.end(); it++) {
  //   cout << it->first << ":" << it->second << endl;
  // }

  auto it = mp.end(); it--;
  //cout << it->first << ":" << it->second << endl;
  cout << it->first + it->second << endl;


  return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;

#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
 
const int maxn = 1000;  
int link[maxn], g[maxn][maxn];  
bool used[maxn];  
int nx, ny, n, m;  
  
bool dfs (int u) {  
    for (int v = 1; v <= ny; v++) {  
        if (!used[v] && g[u][v]) {  
            used[v] = true;  
            if (link[v] == -1 || dfs (link[v])) {  
                link[v] = u;  
                return true;  
            }  
        }  
    }  
    return false;  
}  
  
int maxmatch () {  
    int res = 0;  
    memset (link, -1, sizeof (link));//link[i]=-1±íÊ¾i²»ÔÚÆ¥ÅäÖÐ£¬·ñÔò(link[i],i)ÕâÌõ±ßÔÚÆ¥ÅäÖÐ  
    for (int i = 1; i <= nx; i++) {  
        memset (used, false, sizeof (used));  
        if (dfs (i)) res++;  
    }  
    return res;  
}  

int a[111],b[111],c[111],d[111];


int main()
{
    int i,j,k;
    
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
    }
    for(i=1;i<=n;i++)
    {
        cin>>c[i]>>d[i];
    }
    
    nx=ny=n;
    memset(g,0,sizeof(g));
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(a[i]<c[j] && b[i]<d[j])
            {
                g[i][j]=1;
            }
        }
    }
    //system("pause");
    cout<<maxmatch()<<endl;
    
    return 0;
}


Measured memory_bytes: 4096
# -*- coding: utf-8 -*-
'import sys'
c={
    'S':[0]*13,
    'H':[0]*13,
    'C':[0]*13,
    'D':[0]*13
}
n=int(input())
for i in range(n):
    s,num=input().split()
    c[s][int(num)-1]=1
for i in["S","H","C","D"]:
    for j in range(13):
        if c[i][j]==0:
            print(i,j+1)


Measured memory_bytes: 5604
n=int(input())
l=list(map(int,input().split()))
l_mid=int(sum(l)/2)
l_sum=sum(l)
x=0
for i in range(len(l)):
  x+=l[i]
  if x+l[i+1]>=l_mid:
    if abs(l_sum-x*2)<=abs(l_sum-(x+l[i+1])*2):
      print(abs(l_sum-x*2))
    else:
      print(abs(l_sum-(x+l[i+1])*2))
    break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(), v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 1;
vector<int> g[N];
vector<int> vis(N);
void dfs(int v, int &size){
    size++;
    vis[v] = 1;
    for(int u : g[v]){
        if(!vis[u]){
            dfs(u, size);
        }
    }
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n, m;
        cin >> n >> m;
        for(int i = 1; i <= m; i++){
            int u, v;
            cin >> u >> v;
            g[u].pb(v);
            g[v].pb(u);
        }
        int ans = 0;
        for(int i = 1; i <= n; i++){
            if(!vis[i]){
                int size = 0;
                dfs(i, size);
                ans = max(ans, size);
            }
        }
        cout << ans << '\n';
    }
}

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

int main() {
	int h[10],max;
	for (int i = 0; i < 10; i++) {
		cin >> h[i];
	}
	
	for (int j = 0; j < 3; j++) {
		max = 0;
		for (int i = 1; i < 10; i++) {
			if (h[max] < h[i])
				max = i;
		}
		cout << h[max] << "\n";
		h[max] = -1;
	}
	return 0;
}


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


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

    vector<int> li(n);
    int min = 0xFFFFFF;
    for (int i = 0; i < n; i++)
    {
        li[i] = l+i;
        if (abs(li[i]) < abs(min))
        {
            min = li[i];
        }
    }
    
    cout << accumulate(li.begin(), li.end(), 0) - min << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
const int MR=1e6+10;

int n;
char a[15]={};

void search(int p){
	if(p==n){
		a[p]=0;
		printf("%s\n",a);
		return;
	}
	char m=a[0];
	for(int i=1;i<p;i++) m=max(m,a[i]);
	for(a[p]='a';a[p]<=m+1;a[p]++){
		search(p+1);
	}
}

int main(){
	cin>>n;
	a[0]='a';
	search(1);
	return 0;
}

Measured memory_bytes: 1536