akhauriyash/Code-Regression huggingface dataset:
/*maximum subarray sum 
 * kadane algo space optimize dp
*/




#include <bits/stdc++.h>
using namespace std;



int main()
{
	int n;
	cin>>n;
	int dp[n+1][3];
	int arr[n+1][3];
	for(int i = 0;i<n;i++)cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	
	for(int i = 0;i<n;i++)
		for(int j = 0;j<3;j++)
			dp[i][j] =0;
	//int ans = 0;
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
	for(int i = 1;i<n;i++)
	{
		dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + arr[i][0];
		dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + arr[i][1];
		dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + arr[i][2];
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	
}


Measured memory_bytes: 5924
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

ll dp[90][2][2];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    dp[0][0][0] = 1000;
    dp[0][0][1] = 0;
    dp[0][1][0] = 1000;
    dp[0][1][1] = 0;
    rep(i,n){
        //money
        {
            dp[i+1][0][0] = dp[i][0][0] + a[i] * dp[i][0][1];
            dp[i+1][0][1] = 0;
            ll mon = dp[i][1][0] + a[i] * dp[i][1][1];
            if(dp[i+1][0][0] < mon){
                dp[i+1][0][0] = mon;
                dp[i+1][0][1] = 0;
            }
        }
        //stk
        {
            ll stk = dp[i][0][0] / a[i];
            dp[i+1][1][1] = dp[i][0][1] + stk;
            dp[i+1][1][0] = dp[i][0][0] - stk * a[i];
            ll stk2 = dp[i][1][0] / a[i];
            if(dp[i+1][1][1] < stk2 + dp[i][1][1]){
                dp[i+1][1][1] = stk2 + dp[i][1][1];
                dp[i+1][1][0] = dp[i][1][0] - stk2 * a[i];
            }
            else if(dp[i+1][1][1] == stk2 + dp[i][1][1]){
                chmax(dp[i+1][1][0], dp[i][1][0] - stk2 * a[i]);
            }
        }
    }
    ll ans = max(dp[n][0][0], dp[n][1][0]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3656
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int,int>PII;
const int inf = 1 << 30;
const int mod = 998244353;
map<int,int>mp;
map<int,int>steam;
map<int,int>::iterator it;
const int maxn = 1e5;
/*
struct point{
	int x,cont;
	float c;
}num[maxn+5];

bool cmp(point a,point b){
	if(a.c == b.c) return a.cont > b.cont;
	return a.c > b.c;
}
*/
LL qwe (LL x,LL y){
	LL t = 1;
	while (y){
		if (y%2!=0)
			t = t * x % mod;
		y /= 2;
		x = x * x % mod;
	}
	return t;
}
LL jc(LL x){
	LL t = 1;
	for(int i = 1;i<=x;i++){
		t*=i;
		t % mod;
	}
	return t;
}
int num[maxn+5];
int ans = 0;
int main(){
	for(int i = 0;i<3;i++){
		cin >> num[i];
	}
	sort(num,num+3);
	int pos = num[2]-num[0]+num[2]-num[1],max = 0;
	if(pos%2){
		max = num[2]+1;
		ans += (3*max - num[0]-num[1]-num[2])/2;
	}
	else {
		max = num[2];
		ans += max - num[1];
		ans += (num[1]-num[0])/2;
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main()
{
    int x; cin >> x;
    REP(i,1e5){
        if((i+1)*i/2>=x){
            cout << i << endl; 
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=input().split()#価格
b=input().split()#価値
d=[]#価格差
total_d=[]
s=0
for i in range(n):
    a[i]=int(a[i])
    b[i]=int(b[i])
for i in range(n):
    x=a[i]-b[i]
    d.append(x)
for k in range(n):
    if d[k]>0:
        total_d.append(d[k])
print(sum(total_d))

Measured memory_bytes: 3064
N = int(input())
x = list(map(int, input().split()))
box = 0
for num in range(N-1):
    if x[num] - x[num + 1] > 0:
        box += x[num] - x[num + 1]
        x[num +1] = x[num]
    else:
        box = box
print(box)        

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  u64 n;
  const u64 d = 26;
  cin >> n;

  string s = "";

  while (n > 0) {
    s += (n - 1) % d + 'a';
    if (n == 26)
      break;
    n = (n-1) / d;
  }

  reverse(s.begin(), s.end());
  cout << s << endl;

  return 0;
}


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

def main():
    n = int(input())
    l = sorted(list(map(int, input().split())))
    ans = 0

    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            L = j
            R = n
            ij = l[i] + l[j]
            while R - L != 1:
                if ij <= l[j + 1]:
                    break
                now = (L + R)//2
                if ij > l[now]: #三角形になる
                    L = now
                else:
                    R = now
            ans += L - j

    print(ans)

main()

Measured memory_bytes: 41708
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
  int n; string s;
  cin >> n >> s;
  int x = 0; int sol = 0;
  for(int i = 0; i<n; i++) {
    if(s[i] == 'I') x++;
    else x--;
    sol = max(sol, x);
  }
    cout << sol << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D, x = 0;
  cin >> A >> B;
  D = A;
  C = A;
  for (int i = 0 ; i < B - A + 1; i++) {
    if (C / 10000 == C % 10) {
      C -= 10001 * (C % 10);
      C /= 10;
      if (C / 100 == C % 10){
        x++;
      }
    }
    D++;
    C = D;
  }
  cout << x << endl;
}

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

using mint = modint998244353;
using S = pair<mint, int>;
S op (S a, S b) { return S(a.first + b.first, a.second + a.second); }
S e () { return S(0, 0); }
using F = pair<mint, mint>;
S mapping (F f, S a) { return S(a.first * f.first + a.second * f.second, a.second); }
F composition (F f, F g) { return F(f.first * g.first, f.first * g.second + f.second); }
F id () { return F(1, 0); }

int main(){
    int n, q;  cin >> n >> q;
    vector<S> a(n);
    for (int i = 0; i < n; i++) {
        int aa; cin >> aa;
        a[i] = S(aa, 1);
    }
  
    lazy_segtree<S, op, e, F, mapping, composition, id> data(a);

    while (q--) {
        int t; cin >> t;
        if (t == 0) {
            int l, r, c ,d; cin >> l >> r >> c >> d;
            data.apply(l, r, F(c, d));
        }
        else {
            int l, r; cin >> l >> r;
            cout << data.prod(l, r).first.val() << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 19332
#include<iostream>
#include<map>
using namespace std;
map<pair<int,int>,int>id;
int idcnt;
int f[500][500];
inline void add_edge(int id1,int id2){
	f[id1][id2]=1;
}
int main(){
	int n,m;
	cin>>n>>m;
	char a[n][m];
	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j){
			cin>>a[i][j];
			if(a[i][j]=='.'){
				id[make_pair(i,j)]=idcnt;
				++idcnt;
			}
		}
	for(int i=0;i<idcnt;++i)
		for(int j=0;j<idcnt;++j)
			f[i][j]=0x7fffffff;
	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j){
			if(a[i][j]!='.')
				continue;
			if(i>0&&a[i-1][j]=='.')
				add_edge(id[make_pair(i-1,j)],id[make_pair(i,j)]);
			if(j>0&&a[i][j-1]=='.')
				add_edge(id[make_pair(i,j-1)],id[make_pair(i,j)]);
			if(i<n-1&&a[i+1][j]=='.')
				add_edge(id[make_pair(i+1,j)],id[make_pair(i,j)]);
			if(j<m-1&&a[i][j+1]=='.')
				add_edge(id[make_pair(i,j+1)],id[make_pair(i,j)]);
		}
	for(int k=0;k<idcnt;++k)
		for(int i=0;i<idcnt;++i)
			for(int j=0;j<idcnt;++j)
				if(i!=k&&i!=j&&k!=j&&f[i][k]!=0x7fffffff&&f[k][j]!=0x7fffffff)
					f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
	int maxv=0;
	for(int i=0;i<idcnt;++i)
		for(int j=0;j<idcnt;++j)
			if(f[i][j]!=0x7fffffff)
				maxv=max(maxv,f[i][j]);
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ff(i,n) for(i=0;i<n;i++)
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg=998244353;
void updateBIT(ll BITree[], ll n, ll index, ll val) 
{ 
    index = index + 1; 
    while (index <= n) 
    { 
        BITree[index] += val; 
        index += index & (-index); 
    } 
} 
ll *constructBITree(ll arr[], ll n) 
{ 
    ll *BITree = new ll[n+1]; 
    for (ll i=1; i<=n; i++) 
        BITree[i] = 0; 
    for (ll i=0; i<n; i++) 
        updateBIT(BITree, n, i, arr[i]); 
    return BITree; 
} 
ll getSum(ll BITree[], ll index)  
{
	ll sum =0;
    index = index + 1; 
    while (index>0) 
    { 
        sum += BITree[index]; 
        index -= index & (-index); 
    } 
    return sum; 
} 
void update(ll BITree[], ll l, ll r, ll n, ll val) 
{ 
    updateBIT(BITree, n, l, val); 
    updateBIT(BITree, n, r+1, -val); 
} 
ll gcd(ll n1, ll n2) {
    if (n2 != 0)
        return gcd(n2, n1 % n2);
    else
        return n1;
}
ll pp(string str) 
{ 
    ll l = 0; 
    ll h = str.length() - 1; 
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        { 
            return 0; 
        } 
    } 
	return 1; 
}
int main()
{
    ll t;
    t=1;
    while(t--)
    {
    	ll i,j,n,q,k=0,a=0,ans=bg;
    	cin>>n;
    	ll arr[n];
    	ff(i,n)   cin>>arr[i];
    	ll odd[100000]={0},eve[100000]={0};
    	for(i=0;i<n;i+=2)
    	    odd[arr[i]-1]++;
    	for(i=1;i<n;i+=2)
		    eve[arr[i]-1]++;
		vector<pair<ll,ll> >vec1,vec2;    
		ff(i,100000)
		{
		    a=max(a,odd[i]);
		    vec1.pb(mp(odd[i],i));
		}
		sort(vec1.begin(),vec1.end());
		ff(i,100000)
		{
		    k=max(k,eve[i]);
		    vec2.pb(mp(eve[i],i));
		}
		sort(vec2.begin(),vec2.end());
		ll sumodd = (n+1)/2,sumeven =n/2;
		if(vec2[99999].second==vec1[99999].second)
		{
		    if(a==sumodd && k==sumeven)
		    {
		    	cout<<n/2;
			}
			else
			{
				cout<<n-max(vec1[99998].first+vec2[99999].first,vec2[99998].first+vec1[99999].first);
			}
		    return 0;	
		}
		ans = n - a - k;
		cout<<ans;			    
    }
    return 0;
}

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

int main( void ) {
    
    int n;
    cin >> n;
    
    long long x = 1, y = 1;
    for( int i = 1; i <= n; i ++ ) {
        int a, b;
        cin >> a >> b;
        
        long long mx = max( ( x + a - 1 ) / a,
                            ( y + b - 1 ) / b );
        
        x = a * mx; y = b * mx;
    }
    
    cout << x + y << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std; 
 
struct Point { double x, y; }; 
 
void koch(int d, Point p1, Point p2) { 
  if (d == 0) return; 
  Point s, u, t; 
  double th = M_PI * 60.0 / 180.0; 
 
  s.x = p2.x / 3 + p1.x / 3 * 2; 
  s.y = p2.y / 3 + p1.y / 3 * 2; 
  t.x = p2.x / 3 * 2 + p1.x / 3; 
  t.y = p2.y / 3 * 2 + p1.y / 3; 
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x; 
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y; 
 
  koch(d - 1, p1, s); 
  cout << s.x << " " << s.y << endl; 
  koch(d - 1, s, u); 
  cout << u.x << " " << u.y << endl; 
  koch(d - 1, u, t); 
  cout << t.x << " " << t.y << endl; 
  koch(d - 1, t, p2); 
} 
 
int main() { 
  int n; cin >> n; 
  Point a, b; 
  a.x = 0; 
  a.y = 0; 
  b.x = 100; 
  b.y = 0; 
 
  cout << 0 << " " << 0 << endl; 
  koch(n, a, b); 
  cout << 100 << " " << 0 << endl; 
  return 0; 
} 


Measured memory_bytes: 3296
#include<cstdio>
using namespace std;
#define r(i,n) for(int i=0;i<n;++i)
int main()
{
	int f[5][5]={{0}};
	r(i,9){
		char s[6];
		scanf("%s",s);
		if(i%2){
			r(j,5){
				int a=s[j]-'0';
				f[i/2][j]|=a<<2;
				f[i/2+1][j]|=a;
			}
		}else{
			r(j,4){
				int a=s[j]-'0';
				f[i/2][j]|=a<<1;
				f[i/2][j+1]|=a<<3;
			}
		}
	}
	printf("R");
	int y=0,x=1,p=1;
	do{
		p=(p+2)%4;
		int d=p;
		do
			d=(d+1)%4;
		while(!((f[y][x]>>d)&1));
		p=d;
		putchar("URDL"[d]);
		int dx[] = {0, 1, 0, -1};
		int dy[] = {-1, 0, 1, 0};
		x+=dx[d];
		y+=dy[d];
	}while(y!=0||x!=0||f[0][0]==6&&p==3);
	puts("");
	return 0;
}

Measured memory_bytes: 0
mod = 1000000007

N = int(input())

a = 1
for i in range(N):
    a = (a * 10) % mod

b = 2
for i in range(N):
    b = (b * 9) % mod

c = 1
for i in range(N):
    c = (c * 8) % mod

print((a - b + c) % mod)


Measured memory_bytes: 9204
#include<stdio.h>
#include<string.h>
int main()
{
	int n,m,v,i,j;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		char a[n+2][m+2];
		v=(n+2)*(m+2);
		memset(a,'#',sizeof(char)*v);
		for(i=1;i<n+1;i++)
		{
			scanf("\n");
			for(j=1;j<m+1;j++)
			{
				scanf("%c",&a[i][j]);
			}
		}
		for(i=0;i<n+2;i++)
		{
			for(j=0;j<m+2;j++)
			{
				printf("%c",a[i][j]);
			}
			printf("\n");
		}
	}
}

Measured memory_bytes: 128
n = gets.to_i
aa = gets.split.map(&:to_i)

prev, current = 0, 0
ret = 1
(n - 1).times do |i|
  diff = aa[i + 1] - aa[i]
  next if diff == 0

  if diff > 0
    if prev == -1
      ret += 1
      current = 0
    else
      current = 1
    end
  else
    if prev == 1
      ret += 1
      current = 0
    else
      current = -1
    end
  end
  prev = current
end
puts ret


Measured memory_bytes: 8452
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;


int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    string s,t;
    cin>>s>>t;
    
    cout<<t<<s;
	
    
    
}


Measured memory_bytes: 256
N=input()

if len(N)<3:
    print(0)
else:
    arr=set([357, 375, 537, 573, 735, 753])
    for i in range(len(N)-3):
        new=set()
        for num in arr:
            for j in range(len(str(num))+1):
                n=str(num)[:j]+'3'+str(num)[j:]
                new.add(int(n))
                n=str(num)[:j]+'5'+str(num)[j:]
                new.add(int(n))
                n=str(num)[:j]+'7'+str(num)[j:]
                new.add(int(n))
        arr |= new

    arr=list(arr)
    arr.sort()
    cnt=0
    for i in range(len(arr)):
        if arr[i]<=int(N):
            cnt+=1
        else:
            break
    print(cnt)

Measured memory_bytes: 9384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

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

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};


/////////////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    ll m;
    cin >> m;
    ll LCM = 1;
    vector<ll> a(n);
    set<ll> count;
    for (int i = 0;i < n;i++) {
        cin >> a[i];
        a[i] /= 2;

        ll tmp = a[i];
        ll cnt = 0;
        while(tmp % 2 == 0){
            tmp /= 2;
            cnt++;
        }
        
        count.insert(cnt);

        LCM = lcm(a[i],LCM);
        if (LCM > m){
            cout << 0 << endl;
            return 0;
        }

    }

    if (count.size() > 1){
        cout << 0 << endl;
        return 0;
    }

    ll ok = 1,ng = m;
    while(ng - ok > 1){
        ll mid = (ok + ng) / 2;

        if ((2*(mid - 1) + 1)*LCM <= m) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>

int min (int x, int y) {
	if (x < y) return x;
	return y;
}

int main () {
	int n;
	while (scanf("%d", &n) != EOF) {
		int arr[n];
		for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
		//DP
		int DP[n] = {0, abs(arr[1]-arr[0])};
		for (int i = 2; i < n; i++) {
			DP[i] = min(DP[i-1] + abs(arr[i] - arr[i-1]), DP[i-2] + abs(arr[i] - arr[i-2]));
		}
		printf("%d\n", DP[n-1]);
	}
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
		//order_of_key (k) : Number of items strictly smaller than k .
		//find_by_order(k) : K-th element in a set (counting from zero) (returns an iterator)           


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

int32_t main()
{
	fastIO
	inp_out();
	int n; 
	cin >> n; 
	vector < pii > a(n); 
	for(int i = 0; i < n; ++ i)
		cin >> a[i].fi >> a[i].se; 

	for(int i = 2; i < n; ++ i)
	{
		if(a[i].fi == a[i].se && a[i - 1].fi == a[i - 1].se && a[i - 2].fi == a[i - 2].se)
		{
			cout << "Yes"; 
			return 0; 
		}
	}
	cout << "No"; 
	return 0;
}

Measured memory_bytes: 3652
n,m,t,pre,ans,h,i,a,j;
main(){
	for(;scanf("%d%d",&n,&m),n;){
		t=1e6;
		h=0;
		for(i=0;i<n;i++){
			scanf("%d",&a);
			j=m/a*a;
			if(j<t||j==t&&a<=pre){
				h=j==t&&a==pre;
				t=j;
				pre=a;
				ans=i;
			}
		}
		printf("%d\n",h?n:ans+1);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    int d[n][2];
    rep(i, n) {
        cin >> d[i][0] >> d[i][1];
    }
    for (int i = 1; i < n - 1; i++){
        if (d[i - 1][0] == d[i - 1][1] && d[i][0] == d[i][1] &&
            d[i + 1][0] == d[i + 1][1]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include <algorithm>   
#include <functional>
#include<string>
using namespace std;

int main() {
    int A[200],N,cnt1=0,cnt2=0;
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<N;i++){
        if(A[i]%2==0){
            ++cnt1;
            A[i]/=2;
        }
        else break;
        if(cnt1==N){
            i=-1;
            ++cnt2;
            cnt1=0;
        }
    }
    cout << cnt2 << endl;
}

Measured memory_bytes: 256
def main():
    #ABCD入力を取得する。
    num = list(input())

    sum = 0
    s = ''

    #bit探索をする。(000-111)
    for i in range(8):
        sum = int(num[0])
        s = num[0]
        for j in range(3):
            if (i >> j) & 1:
                sum += int(num[j+1])
                s = s + '+' + num[j+1]
            else:
                sum -= int(num[j+1])
                s = s + '-' + num[j+1]

        if sum == 7:
            s = s + '=' + str(sum)
            print(s)
            return

    return


main()

Measured memory_bytes: 3064
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    if (k == 1) {
      pw.println("1");
      return;
    }
    int maxDenominator = requiredPercentDenominator(1, k);
    int totalNumerator = 0;
    for (int dice = 1; dice <= n; dice++) {
      int requiredPercentDenominator = requiredPercentDenominator(dice, k);
      totalNumerator += maxDenominator / requiredPercentDenominator;
    }
    double numerator = totalNumerator;
    double denominator = maxDenominator * n;
    pw.println(numerator / denominator);
    return;
  }

  static int requiredPercentDenominator(int dice, int k) {
    return intPow(2, requiredContThrows(dice, k));
  }

  static int requiredContThrows(int dice, int k) {
    if (dice >= k) {
      return 0;
    }
    int point = dice;
    for (int i = 1; ; i++) {
      point = point * 2;
      if (point >= k) {
        return i;
      }
    }
  }

  static int intPow(int seed, int n) {
    if (n == 0) {
      return 1;
    }
    int result = seed;
    for (int i = 0; i < n - 1; i++) {
      result = result * seed;
    }
    return result;
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int N;
vector<int> G[100000];
int A[100000];
int B[100000];

void bfs(int si,int d[100000]){
  
  for(int i=0;i<N;i++)
    d[i]=-1;
  
  d[si]=0;
  
  queue<int> Q;
  Q.push(si);

  while(!Q.empty()){
    int pos=Q.front();
    Q.pop();
    for(int to:G[pos]){
      if(d[to]==-1){
        d[to]=d[pos]+1;
        Q.push(to);
      }
    }
  }
}

int main(){
  cin>>N;
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  bfs(0,A);
  bfs(N-1,B);
  int bc=0,wc=0;
  for(int i=0;i<N;i++){
    if(A[i]<=B[i])bc++;
    else wc++;
  }

  if(bc>wc)cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
  return 0;
}


Measured memory_bytes: 6784
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
 int h[10], i;
 for(i = 0;i < 10;i++){
  cin >> h[i];
 }
 sort(h,h+10);

for(i = 9;i > 6;i--){
  cout << h[i] << endl;
}

 return 0; 
}

Measured memory_bytes: 1176
import java.util.Scanner;

public class Main {

    Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        int N=scanner.nextInt();
        int ans=0;
        for(int i=0;i<N;i++){
            ans+=-(scanner.nextInt()-scanner.nextInt()-1);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 25328
#include <cstdio>
#include <algorithm>
#define maxn 100010
using namespace std;
char in[3];
int n,v[3],p[maxn],q[maxn],ans[maxn];
int main(){
	int i;
	scanf("%d",&n);
	for(i=0;i<3;i++)scanf("%d",&v[i]);
	for(i=1;i<=n;i++)scanf("%s",in),p[i]=in[0]-'A',q[i]=in[1]-'A';
	for(i=1;i<=n;i++){
		if(v[p[i]]>v[q[i]])swap(p[i],q[i]);
		else if(v[p[i]]==v[q[i]]){
			if(i+1<=n&&(q[i]==p[i+1]||q[i]==q[i+1]))swap(p[i],q[i]);
		}
		if(!v[q[i]])return 0*printf("No\n");
		v[p[i]]++,v[q[i]]--,ans[i]=p[i];
	}
	printf("Yes\n");
	for(i=1;i<=n;i++)printf("%c\n",'A'+ans[i]);
	return 0;
}

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

    int d[10]{};

    int main()
    {
        ll n{},k{};
        cin>>n>>k;
        for(ll i=0;i<k;i++){
            int t{};
            cin>>t;
            d[t] = 1;
        }
        for(ll i=n;i<1000005;i++){
            string s = to_string(i);
            for(ll j=0;j<s.size();j++){
                if(d[ s[j] - '0']){
                    goto j;
                }
            }
            cout<<i;
            break;
            j:;
        }

        return 0;
    }

Measured memory_bytes: 3684
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

type bufReader struct {
	r   *bufio.Reader
	buf []byte
	i   int
}

var reader = &bufReader{
	bufio.NewReader(os.Stdin),
	make([]byte, 0),
	0,
}

func (r *bufReader) readLine() {
	if r.i < len(r.buf) {
		return
	}
	r.buf = make([]byte, 0)
	r.i = 0
	for {
		line, isPrefix, err := r.r.ReadLine()
		if err != nil {
			panic(err)
		}
		r.buf = append(r.buf, line...)
		if !isPrefix {
			break
		}
	}
}

func (r *bufReader) next() string {
	r.readLine()
	from := r.i
	for ; r.i < len(r.buf); r.i++ {
		if r.buf[r.i] == ' ' {
			break
		}
	}
	s := string(r.buf[from:r.i])
	r.i++
	return s
}

func (r *bufReader) nextLine() string {
	r.readLine()
	s := string(r.buf[r.i:])
	r.i = len(r.buf)
	return s
}

var writer = bufio.NewWriter(os.Stdout)

func next() string {
	return reader.next()
}

func nextInt64() int64 {
	i, err := strconv.ParseInt(reader.next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextInt() int {
	return int(nextInt64())
}

func nextLine() string {
	return reader.nextLine()
}

func out(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	return int(max64(int64(x), int64(y)))
}

func min64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func min(x, y int) int {
	return int(min64(int64(x), int64(y)))
}

func abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func abs(x int) int {
	return int(abs64(int64(x)))
}

func joinInt64s(a []int64, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.FormatInt(v, 10)
	}
	return strings.Join(b, sep)
}

func joinInts(a []int, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.Itoa(v)
	}
	return strings.Join(b, sep)
}

func divUp64(x, y int64) int64 {
	return (x + y - 1) / y
}

func divUp(x, y int) int {
	return int(divUp64(int64(x), int64(y)))
}

func gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func gcd(x, y int) int {
	return int(gcd64(int64(x), int64(y)))
}

func lcm64(x, y int64) int64 {
	return x * y / gcd64(x, y)
}

func lcm(x, y int) int {
	return int(lcm64(int64(x), int64(y)))
}

func pow64(x, y int64) int64 {
	return int64(math.Pow(float64(x), float64(y)))
}

func pow(x, y int) int {
	return int(pow64(int64(x), int64(y)))
}

func main() {
	solve()
	writer.Flush()
}

func solve() {
	x, y := nextInt64(), nextInt64()
	if abs64(x-y) <= 1 {
		out("Brown")
	} else {
		out("Alice")
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

vector<ll> vec[90010];
int main(){

    rep(i,90010) vec[i].push_back(0);
    
    int h,w,d;
    cin >> h >> w >> d;
    map<int,pii> mp;
    int tmp;
    int q;
    int left,right;
    int cnt = 0;
    ll ans = 0;

    rep(i,h){
        rep(j,w){
            cin >> tmp;
            tmp--;
            mp[tmp] = make_pair(j,i);
        }
    }
    
    rep(i,d){
        for(int j = 0; i+j+d < h*w; j += d){
            pii p1 = mp[i+j];
            pii p2 = mp[i+j+d];
            int dis = abs(p1.first - p2.first);
            dis += abs(p1.second - p2.second);
            if(vec[i].size() > 1){
                dis += vec[i][vec[i].size()-1];
            }
            
            vec[i].push_back(dis);
        }
    }

    

    cin >> q;

    rep(i,q){
        ans = 0;
        cin >> left >> right;
        left--; right--;
        if(left == right){
            cout << 0 << endl;
            continue;
        }
        cnt = (right - left) / d;
        tmp = left % d;
        
        ans += vec[tmp][(right-tmp)/d];
        if((left-tmp)/d > 0){
            ans -= vec[tmp][((left-tmp)/d)];
        }

        cout << ans << endl;
    }

    return 0;
}


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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int>a(n);
  for(int i=0;i<n;i++) cin >> a.at(i);
  while(m>0){
    sort(a.begin(),a.end(),greater());
    a.at(0)/=2;
    m--;
    if(m<=0) break;
    for(int i=0;i<n;i++){
      if(a.at(i)>a.at(0)){
        a.at(i)/=2;
        m--;
      }
      //cout << a.at(i) << ' ';
      if(m<=0) break;
    }
    //cout << '\n';
  }
  int64_t ans=0;
  for(int i=0;i<n;i++) ans+=a.at(i);
  cout << ans << endl;
  return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var b = a[1] / a[2];
            var c = (a[0] - 1) / a[2];
            Console.WriteLine(b - c);
        }
    }
}


Measured memory_bytes: 28304
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<ii> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
  }
  sort(a.begin(), a.end());
  int64 ret = 0;
  for (int i = 0; i < n && m > 0; ++i) {
    int rem = min(m, a[i].second);
    m -= rem;
    ret += (int64)a[i].first * rem;
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 1024
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define MX 10000000000
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
ll a[65];
void solve()
{
    ll h;
    cin >> h;
    ll x = 1;
    while (h > 1)
    {
        h = h / 2;
        x++;
    }
    a[0] = 1;
    for (int i = 1; i <= 60; i++)
    {
        a[i] = a[i - 1] * 2;
    }
    cout << a[x] - 1;
}
int main()
{
	int t = 1;
//	cin >> t;
	while (t--)
	{
		solve();
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int lim = 21;
const int inf = 1e9;
int W, H, sy, sx;

int ans = inf;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

void dfs(int n, int y, int x, vector<vector<int>> v){
    if(n > 10 || n >= ans) return;
    for(int i=0; i<4; i++){
        int ny = y + dy[i];
        int nx = x + dx[i];
        
        if(0 <= ny && ny < H && 0 <= nx && nx < W && v[ny][nx] != 1){
            while(0 <= ny && ny < H && 0 <= nx && nx < W){

                if(v[ny][nx] == 3){
                    ans = min(ans, n);
                    return;
                }

                if(v[ny][nx] == 1){
                    v[ny][nx] = 0;
                    dfs(n+1, ny - dy[i], nx - dx[i], v);
                    v[ny][nx] = 1;
                    break;
                }
                ny += dy[i];
                nx += dx[i];
            }
        }
    }
    return;
}

int main(){
    
    while(true){
        ans = inf;
        cin >> W >> H;
        vector<vector<int>> v(H, vector<int>(W, 0));
        if(W == 0 && H == 0) return 0;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cin >> v[i][j];
                if(v[i][j] == 2){
                    sy = i, sx = j;
                    v[sy][sx] = 0;
                }
            }
        }
        dfs(1, sy, sx, v);
        if(ans == inf) cout << -1 << endl;
        else cout << ans << endl;
    }
}


Measured memory_bytes: 3224
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int N = fs.nextInt();
        String s = fs.next();
        int len = s.length();
        long r = 0;
        long g = 0;
        long b = 0;

        for (int i = 0; i < len; ++i) {
            if (s.charAt(i) == 'R') {
                ++r;
            } else if (s.charAt(i) == 'G') {
                ++g;
            } else {
                ++b;
            }
        }

        long ans = r*b*g;
        for (int i = 0; i <= len-3; ++i) {
            for (int j = i+1; j < len-1; ++j) {
                if (s.charAt(i) == s.charAt(j)) continue;
                if (j+j-i < len && s.charAt(j+j-i) != s.charAt(i)
                    && s.charAt(j+j-i) != s.charAt(j)) --ans;
            }
        }

        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}




Measured memory_bytes: 33080
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define ll long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        string query;
        ll count1,count2;
        std::ios::sync_with_stdio(false);
       
            cin>>query;
            ll len = query.length();

            for (int i = 0; i < len; ++i)
            {
                query[i]='x';
            }
            cout<<query;

            
        return 0;
    }


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int NIL = -1; 
const int MAXN = 100005;
struct Node{ int p, r, l; }; 

Node T[MAXN]; 
int D[MAXN];
int n;


void print(int u)
{
	int i, c;
	cout << "node " << u <<": ";
	cout << "parent = "	<< T[u].p <<", ";
	cout << "depth = " << D[u] << ", ";
	
	if(T[u].p == NIL) cout << "root, ";
	else if(T[u].l == NIL) cout << "leaf, ";
	else cout << "internal node, ";
	
	cout << "[";
	
	for(i = 0, c = T[u].l; c != NIL;i++, c = T[c].r){
		if(i) cout << ", ";
		cout << c;
	}
	cout << "]" << endl; 
} 

/*递归求深度*/
int rec(int u, int p)
{
	D[u] = p;
	if(T[u].r != NIL)
		rec(T[u].r, p);
	if(T[u].l != NIL)
		rec(T[u].l, p+1);
}

int main ()
{
	int i, j, v, d, l, r, c;
	cin >> n;
	/*将树初始化*/ 
	for(i = 0; i < n; i++)
	{
		T[i].p = T[i].l = T[i].r = -1;
	}
	
	for(i = 0;i < n; i++)
	{
		cin >> v >> d;
		for(j = 0; j < d; j++)
		{
			cin >> c;
			if(j == 0)
			{
				T[v].l = c;
			}
			else
			{
				T[l].r = c;
			}
			l = c;
			T[c].p = v;
		}
	}
	
	for(i = 0; i < n; i++)
	{
		if(T[i].p == NIL)
			r = i;
	}
	
	rec(r, 0);
	
	for(i = 0; i < n; i++)
		print(i);
		
	return 0;
} 


Measured memory_bytes: 7740
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(abs(a-c)<=d){
        p("Yes");
    }
    else if(abs(a-b)<=d && abs(b-c)<=d){
        p("Yes");
    }else{
        p("No");
    }

    return 0;
}

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

vector<int> v;

long eval(long b){
  long sum = 0;
  for(int i=0;i<v.size();i++)sum += abs(v[i]-b);
  return sum;
}

int main(){
  long n;
  cin >> n;
  v.resize(n);
  for(int i=0;i<n;i++){ cin >> v[i]; v[i] -= i+1; }
  sort(v.begin(), v.end());
  cout << eval(v[n/2]) << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        sc.close();

        // 主処理
        int result = 0;
        if (n != 1) {
            List<Integer> list = primeFactorization(n);
            Map<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < list.size(); i++) {
                int num = list.get(i);
                if (map.containsKey(num)) {
                    map.put(num, map.get(num) + 1);
                } else {
                    map.put(num, 1);
                }
            }

            int[] count = new int[40];
            for (int i = 1; i < count.length; i++) {
                count[i] = count[i - 1] + i;
            }

            for (int key : map.keySet()) {
                int val = map.get(key);
                for (int i = 0; i < count.length; i++) {
                    if (val < count[i]) {
                        result += i - 1;
                        break;
                    }
                }
            }
        }

        // 出力
        System.out.println(result);

    }

    public static List<Integer> primeFactorization(long num) {
        List<Integer> list = new ArrayList<>();
        int max = (int) Math.sqrt(num);
        PriorityQueue<Integer> pq = new PriorityQueue<>(primeList(max));
        int div = pq.poll();
        while (num != 1) {
            if (num % div == 0) {
                num /= div;
                list.add(div);
            } else if (pq.isEmpty()) {
                break;
            } else {
                div = pq.poll();
            }
        }
        if (num != 1) {
            list.add((int) num);
        }
        return list;
    }

    static List<Integer> primeList(int n) {
        List<Integer> list = new ArrayList<>();
        boolean[] prime = new boolean[n + 1];
        Arrays.fill(prime, true);
        prime[0] = false;
        prime[1] = false;
        for (int i = 2; i < Math.sqrt(n); i++) {
            if (!prime[i])
                continue;
            for (int j = 2; i * j <= n; j++) {
                prime[i * j] = false;
            }
        }
        for (int i = 0; i < prime.length; i++) {
            if (prime[i])
                list.add(i);
        }
        return list;
    }
}


Measured memory_bytes: 40680
#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), B(N);
    rep(i, N) cin >> A[i];
    B = A;
    sort(B.rbegin(), B.rend());
    rep(i, N) {
        cout << (A[i] != B[0] ? B[0] : B[1]) << endl;
    }
}

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

int main(void){
    int N;
    int a[300000];
    int r[300000];
    vector<int> result;

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

    for(int i=N-1; i>=0; --i){
        int tmp=0;

        for(int j=2; j*(i+1)-1<N; ++j){
            tmp += r[j*(i+1)-1];
        }
        if(tmp%2 != a[i]){
            r[i] = 1;
            result.insert(result.begin(),i+1);
        }
    }

    if(result.size()==0){
        cout << 0 << endl;
        return 0;
    }
    
    cout << result.size() << endl;
    for(auto i=result.begin(); i!=result.end(); ++i){
        cout << *i;
        if(i+1!=result.end())
            cout << " ";
        else
            cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3832
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N,M;
    R(N,M);
    if(N>=M){
        W(0);
        return 0;
    }
    VI AA(M);
    REP(i,M){
        R(AA[i]);
    }
    sort(ALL(AA));
    VI d;
    REPP(i,1,SZ(AA)){
        d.PB(AA[i]-AA[i-1]);
    }
    LL an=AA.back()-AA[0];
    sort(ALL(d),greater<int>());
    REP(i,N-1)an-=d[i];
    W(an);

    return 0;
}


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

using namespace std;

using ll = long long;
const int MAXN = 500500;

int N;
int A[MAXN];
char S[MAXN];

int main() {
   ios_base::sync_with_stdio(false);
   cin >> (S + 1);
   int N = strlen(S + 1) + 1;
   for (int i = 1; i <= N - 1; ++i) {
      if (S[i] == '<') {
         A[i + 1] = max(A[i + 1], A[i] + 1);
      }
   }
   for (int i = N - 1; i > 0; --i) {
      if (S[i] == '>') {
         A[i] = max(A[i], A[i + 1] + 1);
      }
   }
   cout << accumulate(A + 1, A + N + 1, 0LL) << "\n";
}


Measured memory_bytes: 2688
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<50
#define fst first
#define snd second
#define pb push_back
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(int itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(int itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<ll,ll> P;

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

  int n,c,k;
  cin >> n >> c >> k;
  
  int t[n];
  REP(i,n) cin >> t[i];
  
  sort(t,t+n);
  
  int time = t[0],ans = 1,cnt = 1;
  FOR(i,1,n){
    if(cnt == c || t[i]-time > k){
      ans++;
      time = t[i];
      cnt = 1;
      continue;
    }
    cnt++;
  }
    
  cout << ans << endl; 

  return 0;
}

Measured memory_bytes: 1024
#include<map>
#include<cstdio>
#include<iostream>
using namespace std;
map < int , int > a;
int main() {
    int n, ans = 0; scanf("%d", &n);
    for (int t; n--;)
        scanf("%d", &t), ++a[t];
    for (map < int , int > :: iterator it = a.begin(); it != a.end(); ++it) {
        if (it->second < it->first) ans += it->second;
        else if (it->second > it->first) ans += it->second - it->first;
    } printf("%d\n", ans);
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	string out = "APPROVED";
	for(int i=0;i<n;i++){
		int current;
		cin >> current;
		if((current%2==0 && current%3!=0 && current%5!=0)){
			out = "DENIED";
			break;
		}
	}
	cout << out;
	return 0;
}


Measured memory_bytes: 256