akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

map<int, int> prime_factors(int n) {
	map<int, int> res;
	if(n == 1) { // n=1 の素因数分解は n^1
		res[n] = 1;
		return res;
	}
	for(int i = 2, _n = n; i*i <= _n; ++i) {
		while(n % i == 0) {
			++res[i]; // 素因数i^{res[i]}
			n /= i;
			}
		}
	if(n != 1) res[n] = 1; // nが素数のとき
	return res;
}

ll modpow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n) {
        if (n & 1) res = (res * x) % mod; // bitが立っていればxを掛ける
        x = (x * x) % mod; // x を二乗しておく
        n >>= 1; // 右bitシフト（log2）
    }
    return res;
}

ll modinv(ll x, ll mod) {
    return modpow(x, mod-2, mod);
}

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

    // 全ての要素を素因数分解し、各素因数の次数の最大値を記録
    map<int, int> factors;
    rep(i, n) {
        map<int, int> mp = prime_factors(a[i]);
        for(const auto& m: mp) {
            int num = m.fi, cnt = m.se;
            if (!factors.count(num)) factors[num] = cnt;
            else factors[num] = max(factors[num], cnt);
        }
    }
    // 素因数ごとの次数の最大値をかけ合わせたものがLCM
    // 乗算の途中でMODを取って良い
    ll modlcm = 1;
    for(const auto& f: factors) {
        int num = f.fi, cnt = f.se;
        ll pownum = modpow(num, cnt, MOD);
        modlcm *= pownum;
        modlcm %= MOD;
    }
    // modlcm / a[i]を足し合わせる
    // MODを取った割り算なのでa[i]の逆元をかける
    ll ans = 0;
    rep(i, n) {
        ll inv = modinv(a[i], MOD);
        ans += modlcm * inv % MOD;
    }
    cout << ans%MOD << endl;
}

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

using namespace std;
//12 30 13 20 -> 50
int main() {
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int min = (h2 * 60 + m2) - (h1 * 60 + m1) - k;
	cout <<  (min <= 0? 0: min)<< '\n'; 
	return 0;
}

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

int main() {
	vector<int> p;
  int n,k;
  cin >> n >> k;
  for(int i=0; i<n; i++){
  	int x;
    cin >> x;
    p.push_back(x);
  }
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0; i<k; i++){
  	ans += p[i];
  }
  cout << ans;
}

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

using namespace std;

const int mxn = 2e5;

char s[mxn + 11];
int cnt[mxn + 11];

int main(){
	scanf("%s", s);
	int slen = strlen(s);
	int carry = 1;
	memset(cnt, 0, sizeof(cnt));
	cnt[0] = 1;
	int cur = 0;
	for (int i = slen - 1; i >= 0; i--){
		int digit = s[i] - '0';
		cur += digit * carry;
		cur %= 2019;
		cnt[cur]++;
		carry = carry * 10 % 2019;
	}
	int ans = 0;
	for (int i = 0; i < 2019; i++){
		ans += (cnt[i] * (cnt[i] - 1) ) >> 1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
   int x;
   cin >> x ;
   x=x/200;
   int ans;
  ans=10-x;
  cout << ans << endl;

}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=1e5+10;
int n,k;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>k;
	int ans=0;
	while(n){
		++ans;
		n/=k;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<pair<int, int>> X(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i].first;
        X[i].second = i;
    }

    sort(X.begin(), X.end());
    
    vector<int> B(N);
    for (int i = 0; i < N; i++) {
        if (i < (N+1) / 2) B[X[i].second] = X[(N+1)/2].first;
        else B[X[i].second] = X[(N-1)/2].first;
    }

    for (int i = 0; i < N; i++) cout << B[i] << endl;
}

Measured memory_bytes: 4480
#include <iostream>
#include <string>
#include <vector>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  string A;
  std::cin >> A;
  ll N = A.length(), ans =(N*(N-1))/2+1;
  std::vector<ll> count(26, 0);
  range(i, N) count[A[i]-'a']++;
  range(i, 26) ans -= (count[i]*(count[i]-1))/2;
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
program ABC166_B
  integer,allocatable::A(:,:),d(:),s(:)
  read(*,*)N,K
  allocate(A(K,N),d(K),s(N))
  s=1
  A=0
  do i=1,K
     read(*,*)d(i)
     read(*,*)A(i,1:d(i))
     do j=1,d(i)
        do k=1,N
           if(A(i,j)==k) then
              s(k)=0
              exit
           end if
        end do
     end do
  end do
  write(*,*)sum(s)
end program ABC166_B

Measured memory_bytes: 2864
n, m = map(int, input().split())

l, r = map(int, input().split())
for _ in range(m - 1):
    li, ri = map(int, input().split())
    if ri < l:
        print(0)
        exit()
    elif r < li:
        print(0)
        exit()
    elif l >= li and r >= ri:
        r = ri
    elif l < li and r >= ri:
        l, r = li, ri
    elif l < li and r < ri:
        l = li

print(r - l + 1)


Measured memory_bytes: 3060
n, a, b, c = map(int, input().split())
x = [int(input()) for _ in range(n)]

from itertools import permutations

def dfs(idx):
    if idx == n:
        return [[[], [], []]]

    ret = []
    for ll in dfs(idx + 1):
        ret.append(ll)

        for i in range(3):
            ll2 = [ll[0][:], ll[1][:], ll[2][:]]
            ll2[i].append(idx)
            ret.append(ll2)

    return ret

lists = dfs(0)

target = [a, b, c]

ans = float('inf')
for _lists in lists:
    if [] not in _lists:

        point = 0
        l = []
        for lis in _lists:
            l.append(sum([x[i] for i in lis]))
            point += 10 * (len(lis) - 1)

        for perm in permutations(l):
            point2 = point
            for i in range(3):
                point2 += abs(target[i] - perm[i])

            ans = min(point2, ans)

print(ans)


Measured memory_bytes: 72028
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    string S;
    cin >> N >> S;
    char pre = '*';
    int cnt = 1;
    rep(i,1,N){
        if(S[i-1] != S[i])cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
		Console.SetOut(sw);

		int N = int.Parse(Console.ReadLine());
		Console.WriteLine("ABC" + N);
		
		Console.Out.Flush();
	}
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;

int main(){
  string S;
  cin >> S;
  int S_num;
  S_num = (int)(S.length());
  
  string str(S_num, 'x');
  cout << str << endl;
  return 0;
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll h,n;
  cin >>h >> n;
  ll a[n],b[n];
  for(ll i=0;i<n;i++)cin >> a[i] >> b[i];

  ll dp[30000]={};
  for(ll i=0;i<30000;i++)dp[i]=inf;
  dp[0]=0;

  for(ll i=0;i<30000;i++){
    for(ll j=0;j<n;j++){
      if(i-a[j]>=0)dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
      //if(i==10 && dp[i]==1)cout << i << " " << j << endl;
    }
  }

  ll s=inf;

  for(ll i=h;i<30000;i++)s=min(s,dp[i]);

  cout << s << endl;

  //cout << dp[2] << endl;

}

Measured memory_bytes: 3864
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

#define debug(x) cout << #x << ": " << x << endl;
#define ll long long
#define mod 1000000007

#define COMMENT

int N, D, A, x, h;
vector<pair<ll, int> > X;
ll H[1 << 20];

int main() {

//  freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> N >> D >> A;
  for(int i = 0;i < N;i++) {
    cin >> x >> h;
    int num_bombs = ceil(h * 1.0 / A);
    X.push_back(make_pair(x, num_bombs));
  }

  ll ans = 0;
  sort(X.begin(), X.end());
  for(int i = 0;i < N;i++) {
    if(i) H[i] += H[i-1];

    if(X[i].second + H[i] <= 0) continue;
    ans += X[i].second + H[i];
    int l = upper_bound(X.begin(), X.end(), make_pair(X[i].first + 2 * D, INT_MAX)) - X.begin() - 1;

    H[l+1] += X[i].second + H[i];
    H[i] += -(X[i].second + H[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6512
#include<stdio.h>
#include<stdlib.h>

void putQueen(int**,int*,int*,int*,int*,int*,int,int);
void print(int**);
int main(){
  int **G,*row,*col,*dpos,*dneg,*a,i,j,n,x,y;

  G = malloc(8 * sizeof(int *));
  row = malloc(8 * sizeof(int *));
  col = malloc(8 * sizeof(int *));
  dpos = malloc(15 * sizeof(int *));
  dneg = malloc(15 * sizeof(int *));
  for(i=0;i<8;i++){
    G[i] = malloc(8 * sizeof(int));
  }

  for(i=0;i<8;i++){
    row[i] = 0;
    col[i] = 0;
    for(j=0;j<8;j++){
      G[i][j] = 0;
      dpos[i+j] = 0;
      dneg[i-j+8-1] = 0;
    }
  }
  scanf("%d",&n);
  a = malloc(n * sizeof(int *));
  for(i=0;i<n;i++){
    scanf("%d %d",&x,&y);
    G[x][y] = 1;
    row[x] = -1;
    col[y] = -1;
    dpos[x+y] = -1;
    dneg[x-y+8-1] =-1;
    a[i] = x;
  }
  putQueen(G,row,col,dpos,dneg,a,n,0);

}


void putQueen(int **G,int *row,int *col,int *dpos,int *dneg,int *a,int n,int i){
  int j;
  if(i == 8){
    print(G);
    return;
  }
  for(j=0;j<n;j++){
    if(a[j] == i){
      putQueen(G,row,col,dpos,dneg,a,n,i+1);
      return;
    }
  }
  for(j=0;j<8;j++){
    if(row[i] != -1&&col[j] != -1&&dpos[i+j] != -1&&dneg[i-j+8-1] != -1){
      G[i][j] = 1;
      row[i] = -1;
      col[j] = -1;
      dpos[i+j] = -1;
      dneg[i-j+8-1] =-1;
      putQueen(G,row,col,dpos,dneg,a,n,i+1);
      G[i][j] = 0;
      row[i] = 0;
      col[j] = 0;
      dpos[i+j] = 0;
      dneg[i-j+8-1] = 0;
    }
  }
}

void print(int **G){
  int i,j;
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      if(G[i][j] == 0){
        printf(".");
      }
      else printf("Q");
    }
    printf("\n");
  }
}



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

int main(int argc, char const *argv[]) {
  int n, m ,l;
  int A[100][100], B[100][100];

  cin >> n >> m >> l;
  for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> A[i][j];
  for (int i = 0; i < m; i++) for (int j = 0; j < l; j++) cin >> B[i][j];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      long long c_ij = 0;
      for (int k = 0; k < m; k++) {
        c_ij += (A[i][k] * B[k][j]);
      }
      cout << c_ij;
      if (j != l-1) cout << " ";
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3176
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] box = new int [r+1][c+1];
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                box[i][j] = sc.nextInt();
            }
        }
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                box[i][c] += box[i][j];
            }
        }
        for(int j=0;j<r;j++){
            for(int i=0;i<c+1;i++){
                box[r][i] += box[j][i];
            }
        }
        for(int i=0;i<r+1;i++){
            for(int j=0;j<c+1;j++){
                System.out.print(box[i][j]);
                	if(j != c)
                        System.out.print(" ");
            }
            System.out.println();
        }
        sc.close();
    }
}


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

int descending_compare(const void *a, const void *b){
    return (int)(*(int*)b - *(int*)a);
}

int ascending_compare(const void *a, const void *b){
    return (int)*(int*)a - *(int*)b;
}


int main(void){
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);

    if (a+b>c+d){
        printf("Left\n");
    }else if (c+d>a+b){
        printf("Right\n");
    }else{
        printf("Balanced\n");
    }
    





    return 0;
}


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

int main(){
int W,a,b,c;
cin>>W>>a>>b;
if(a>=b){
c=a-b-W;
if(c<=0){
cout<<0<<endl;
}else{
cout<<c<<endl;
}
}else{
c=b-a-W;
if(c<=0){
cout<<0<<endl;
}else{
cout<<c<<endl;
}
}
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    if 2<=n<4:
        print(2)
    elif n==1:
        print(1)
    elif n<8:
        print(4)
    elif n<16:
        print(8)
    elif n<32:
        print(16)
    elif n<64:
        print(32)
    else:
        print(64)
resolve()

Measured memory_bytes: 38384
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
n=read()
#s=["" for i in range(n)]
ac,wa,tle,re=0,0,0,0
for i in range(n):
  s=input()
  if s=="AC":
    ac+=1
  elif s=="WA":
    wa+=1
  elif s=="TLE":
    tle+=1
  else :
    re+=1
print("AC x "+ str(ac) )
print("WA x "+ str(wa) )
print("TLE x "+ str(tle) )
print("RE x "+ str(re) )



Measured memory_bytes: 68968
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,i,a;
	while (cin >> n) {
		a = 1;
		for (i = 0; i < 10; i++) {
			a *= 2;
			if (n%a != 0) {
				cout << a/2;
				n -= a / 2;
				if (n != 0) {
					cout << " ";
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const int MAX = 510000;

ll 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(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll, int> prime_factor(ll n)
{
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    auto soinsu = prime_factor(m);
    ll ans = 1;
    COMinit();
    for (const auto &p : soinsu)
    {
        ans = ans * COM(p.second + n - 1, p.second) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12160
#include <stdio.h>

int main(){
  int ad[5];
  int k,i,j;
  for(i=0; i<5; i++){
    scanf("%d",&ad[i]);
  }
  scanf("%d",&k);
  for(i=0; i<5; i++){
    for(j=0; j<5; j++){
      if(abs(ad[i]-ad[j]) > k){
        puts(":(\n");
        return 0;
      }
    }
  }
  puts("Yay!\n");
}

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

int main() {
  
  int N, K; 
  cin >> N >> K;
  int f = 1;
  //2,4,8,16,32,
  //二倍したときとKを足したときにどちらが小さいか比べる
  
  for (int i = 0; i < N; i++){
    
    if (f * 2 <= f + K){
      f = f * 2;
    }
    else if (f * 2 > f + K){
      f = f + K;
    }
    
  }
  
  cout << f << endl;
  

 }

Measured memory_bytes: 3572
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define fi first
#define se second
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int main(){
	int n;
	int ss=100000;
	cin>>n;
	fu(0,n){
		ss=ss*1.05;
		if(ss%1000!=0) ss=ss/1000*1000+1000;
	}
	cout<<ss<<endl;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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 n, x, t;
    cin >> n >> x >> t;
    int ans = ceil(n,x) * t;
    cout << ans << endl;
}

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int n;
    cin >> n;

    vector<int> l(n);

    rep(i, n){
        cin >> l[i];
    }

    int ans = 0;

    for(int i = 0; i < n - 2; i++){
        for(int j = i + 1; j < n - 1; j++){
            for(int k = j + 1; k < n; k++){

                if(l[i] != l[j] && l[i] != l[k] && l[j] != l[k]){
                    vector<int> tmp = {l[i], l[j], l[k]};

                    sort(ALL(tmp));

                    if(tmp[0] + tmp[1] > tmp[2]){
                        //cerr << i << " " << j << " " <<  k << endl;
                        ans++;
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn abs(x: usize, y: usize) -> usize {
    max(x, y) - min(x, y)
}
fn rec(a: usize, b: usize, c: usize, d: usize) -> usize {
    let (x1, y1, x2, y2) = if b < d { (a, b, c, d) } else { (c, d, a, b) };
    for i in (0..30).rev() {
        let p = 3usize.pow(i);
        let (i1, j1, i2, j2) = (x1 / p, y1 / p, x2 / p, y2 / p);
        if i1 != i2 {
            break;
        }
        if i1 % 3 == 1 && abs(j2, j1) > 1 {
            return min(min(x1, x2) + 1 - p * i1, p * (i1 + 1) - max(x1, x2)) * 2;
        }
    }
    0
}
fn solve(a: usize, b: usize, c: usize, d: usize) -> usize {
    let best = abs(a, c) + abs(b, d);
    best + max(rec(a, b, c, d), rec(b, a, d, c))
}
use std::cmp::{max, min};
fn main() {
    input! { iter = iter, q };
    for _ in 0..q {
        input_inner! { iter, a: usize1, b: usize1, c: usize1, d: usize1 };
        println!("{}", solve(a, b, c, d));
    }
}


Measured memory_bytes: 4476
n,x = map(int, input().split())
al = list(map(int, input().split()))

costs = al[:]
curr_sums = sum(costs)

# curr_mins = al[:]
curr_mins = al[:]

ans = 10**18
for i in range(0,n): # move cnt
    curr_i_ans = 0
    for j in range(n): # ind
        ind = j-i
        if ind < 0: ind+=n
        # xcost = i*x
        next_a = al[ind]
        if curr_mins[j] > next_a:
            curr_mins[j] = next_a
        cost = curr_mins[j]
        curr_i_ans += cost
    ans = min(ans, curr_i_ans+i*x)

print(ans)

Measured memory_bytes: 68336
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

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

// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll N, M;
	cin >> N >> M;
 
	// 解法
	ll ans = M;
	ll max_d = M/N;
	for (ll i = max_d; i > 0; --i){
		if (M%i==0){
			ans = i;
			break;
		}
	}
	cout << ans << endl;
}
 


Measured memory_bytes: 256
#include<iostream>
#define lim 1000001
typedef long long ll;
using namespace std;
const long long M=1e9+7;
ll p[lim];

ll _pow(ll no,ll p,ll m){
    ll ans=1;
while(p!=0){
    if(p&1) ans=ans*no%m;
    no=(no%m*no%m)%m;
       p= p>>1;
       //cout<<ans<<endl;
       //cout<<p<<endl;
}
return ans;
}
int main(){
	
long long N;
ll i,j;
cin>>N;
ll A[N];

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


 
for(i=0;i<N;i++){
    ll number=A[i];
    ll c=0;
    
    for(j=2;j*j<=number;j++){
        while(number%j==0){
            number/=j;
            c++;
        }
        p[j]=max((int)p[j],(int)c);
        c=0;
    }
    if(number>1)
        p[number]=max((int)p[number],(int)1);
        
}
ll lcm=1;

for(i=2;i<lim;i++){
    if(p[i]!=0){
    	//cout<<i<<" "<<p[i]<<endl;
        lcm=(lcm*_pow(i,p[i],M));
      	lcm=lcm%M;
        
    }
   //cout<<lcm<<endl;
}
//cout<<lcm;
ll ans=0;
for(i=0;i<N;i++){
    ans=ans+lcm*_pow(A[i],M-2,M);
    ans=ans%M;
}
cout<<ans;
}


Measured memory_bytes: 6656
#include <stdio.h>

int main(void)
{
	int i;
	int n;
	int c = 0;
	int mv[1000] = {0};
	
	while (scanf("%d", &n) != EOF){
		mv[n]++;
		
		for (i = 0; i < 1000; i++){
			if (c <= mv[i]){
				c = mv[i];
			}
		}
		
	}
	
	for (i = 0; i < 1000; i++){
		if (c == mv[i]){
			printf("%d\n", i);
		}
	}
	
	return (0);
}

Measured memory_bytes: 600
a, b, h, m = map(int, input().split())

import math

hour_v = 2 * math.pi / 12
min_v = 2 * math.pi / 60

hour_ang = (h + (m/60)) * hour_v
min_ang = m * min_v

if hour_ang < min_ang:
    theta = min_ang - hour_ang
else:
    theta = hour_ang - min_ang


ans = math.sqrt((a ** 2) + (b ** 2) - 2 * a * b * math.cos(theta))
print(ans)

Measured memory_bytes: 9516
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define For(i,n) for(int i=0;i<n;i++)
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,ans,h,w;
    cin>>h>>w>>n;
    if(h>w){swap(h,w);}
    if(n%w==0)ans=n/w;
    else{ans=n/w+1;}
    cout<<ans;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 10000
 
typedef struct{
  int p,l,r;
}Node;
 
Node T[N];
int n, D[N], H[N];
 
void setDepth(int u, int d){
  if(u == -1) return;
  D[u] = d;
  setDepth(T[u].l, d+1);
  setDepth(T[u].r, d+1);
}
 
int setHeight(int u){
  int h1=0, h2=0;
  if(T[u].l != -1) h1 = setHeight(T[u].l) + 1;
  if(T[u].r != -1) h2 = setHeight(T[u].r) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}
 
int getSibling(int u){
  if(T[u].p == -1) return -1;
  if(T[T[u].p].l != u && T[T[u].p].l != -1) return  T[T[u].p].l;
  if(T[T[u].p].r != u && T[T[u].p].r != -1) return T[T[u].p].r;
  return -1;
}
 
int main(){
  int i, v, l, r, d, root=0;
 
  scanf("%d", &n);
 
  for(i=0; i<n; i++) T[i].p = -1;
 
  for(i=0; i<n; i++){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if(l != -1) T[l].p = v;
    if(r != -1) T[r].p = v;
  }
 
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
 
  setDepth(root, 0);
  setHeight(root);
 
  for(i=0; i<n; i++){
    printf("node %d: ", i);
    printf("parent = %d, ", T[i].p);
    printf("sibling = %d, ", getSibling(i));
    d = 0;
    if(T[i].l != -1) d++;
    if(T[i].r != -1) d++;
    printf("degree = %d, ", d);
    printf("depth = %d, ", D[i]);
    printf("height = %d, ", H[i]);
 
    if(T[i].p == -1) printf("root\n");
    else if(T[i].l == -1 && T[i].r == -1) printf("leaf\n");
    else printf("internal node\n");
  }
   
  return 0;
}

Measured memory_bytes: 624
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;
   
  
   
int main(){
   
    int n; 
    int r[1000],w[1000];
    int sum_r=0,sum_w=0,idx=0;
	
    while(scanf("%d",&n),n){
         
        sum_r=sum_w=idx=0;
        for(int i=0;i<n;i++){
            scanf("%d %d",&r[i],&w[i]);
            sum_r+=r[i];
            sum_w+=w[i];
            if(r[idx]<r[i]) idx=i;
        }
  
        int r0=r[idx],r=sum_r-r0;
        w[idx]=0;
 
        if(r0 <= r){
            cout<<sum_r+sum_w<<endl;
        }else{
  
            int res=2*r0;
            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));
  
			bool cur[1001]={};
            cur[0]=true;
            for(int i=0;i<n;i++){
				bool next[1001]={};
                for(int j=0;j<1000;j++){
                    if(cur[j]){
                        next[j]=true; 
                        if(j+w[i]<1000)
                            next[j+w[i]]=true; 
                    }
                }
				swap(cur,next);
            }
  
            int opt=r0-r;
            while(!cur[opt]) opt--;
  
            res+=sum_w-opt;
            printf("%d\n",res);
  
  
  
        }
          
          
    }
}

Measured memory_bytes: 1244
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
module Main where
import Control.Applicative
import Control.Monad
import qualified Data.ByteString as BS
import Data.ByteString.Char8 (readInt)
import qualified Data.IntSet as IS
import Data.Maybe (fromJust)
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  n <- readLn
  as <- VU.replicateM n $ fst . fromJust . readInt <$> BS.getLine
  print $ solve as

solve :: VU.Vector Int -> Int
solve as = IS.size $ VU.foldl' f IS.empty as
  where
    f s e = case IS.lookupGE e s of
      Just ix | e < ix     -> IS.insert e $ IS.delete ix s
              | otherwise -> s
      Nothing -> IS.insert e s

Measured memory_bytes: 11308
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#define	MOD  1000000007;
#define PI = 3.14159265358979323846;
using namespace std;

int main()
{
	int N;
	cin >> N;
	int a[100];

	map<int, int> mp;
	for (int i = 0; i < 8; i++)
	{
		mp[i];
	}
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		if (a[i] <= 399)
		{
			mp[0]++;
		}
		else if (a[i] <= 799) {
			mp[1]++;
		}
		else if (a[i] <= 1199) {
			mp[2]++;
		}
		else if (a[i] <= 1599) {
			mp[3]++;
		}
		else if (a[i] <= 1999) {
			mp[4]++;
		}
		else if (a[i] <= 2399) {
			mp[5]++;
		}
		else if (a[i] <= 2799) {
			mp[6]++;
		}
		else if (a[i] <= 3199) {
			mp[7]++;
		}
		else {
			mp[8]++;
		}
	}

	int min = 0;
	for (int i = 0; i < 8; i++)
	{
		if (mp[i] != 0) {
			min++;
		}
	}

	if (min != 0)
	{
		cout << min << " " << min + mp[8] << endl;
	}
	else {
		cout << 1 << " " << mp[8] << endl;
	}
}

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

int n, m;
vector<int>a;
vector<int>b;

void input(){
	
	scanf("%d %d", &n, &m);
	
	a.resize(n);
	b.resize(n);
	
	for(int ai, i = 0 ; i < n ; i ++){
		scanf("%d", &ai);
		a[i] = ai;
	}
	
	return;
}

int solve(){
	
	int q2 = -1;
	for(int i = 0 ; i < n ; i ++){
		int ai = a[i];
		if(q2 == -1){
			q2 = 0;
			while((ai % 2) == 0){
				ai /= 2;
				q2 ++;
			}
		} else {
			int curr_q2 = 0;
			while((ai % 2) == 0){
				ai /= 2;
				curr_q2 ++;
			}
			if(q2 != curr_q2) return 0;
		}
		b[i] = ai;
	}
	
	long long X_1 = (1<<(q2 - 1));
	long long lcm = 0LL;
	
	for(int i = 0 ; i < n ; i ++){
		int bi = b[i];
		if(!lcm) lcm = bi;
		else lcm = (lcm*bi)/__gcd(lcm, (long long)bi);
		if(lcm > m) return 0;
	}
	
	X_1 *= lcm;
	long long cnt = 0LL;
	
	for(long long i = 1 ; ; i += 2){
		long long X = i*X_1;
		if(X <= m) cnt++;
		else break;
	}
	
	return cnt;
}

int main(){
	
	input();
	printf("%d\n", solve());
	
	return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int c[5000][5000];

int main() {
    int N;
    cin >> N;
    int k = 1;
    while (k * (k - 1) / 2 < N) ++k;
    if (k * (k - 1) / 2 != N) {
        puts("No");
        return 0;
    }

    memset(c, -1, sizeof(c));
    {
        int now = 0;
        rep(i, k - 1) {
            for (int j = 0; j <= i; ++j) {
                c[i][j] = now++;
            }
        }
    }

    VV<int> ans(k);

    rep(i, k - 1) {
        for (int j = 0; j <= i; ++j) {
            ans[i].pb(c[i][j]);
        }
        for (int j = i + 1; j < k - 1; ++j) {
            ans[i].pb(c[j][i]);
        }
    }
    for (int i = 0; i < k - 1; ++i) {
        ans.back().pb(c[i][i]);
    }

    puts("Yes");
    cout << k << endl;
    rep(i, k) {
        printf("%d ", k - 1);
        rep(j, k - 1) {
            printf("%d%c", ans[i][j] + 1, j == k - 2 ? '\n' : ' ');
        }
    }

    return 0;
}

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI;
typedef pair<int,int> pii;
typedef pair<ll,int> pil;
const ll mod = 1e9+7;

vector<vector<pii>> r;

vector<ll > bfs(int sy) {
	const ll inf = 1LL<<50;
	vector<ll > d(sz(r), inf);
	queue<int> que;
	que.push(sy); d[sy]=0;
	while(!que.empty()){
		int v = que.front();
		que.pop();
		for(const auto& rp : r[v]){ 
			int rct, rto; tie(rto, rct) = rp;
			if(d[rto] == inf){
				d[rto] = d[v] + rct;
				que.push(rto);
			}
		}
	}
	return d;
}




int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n,q,k;
	cin >>n;
		r.resize(n);
	rep(i,n-1){
		int a,b, c;
		cin >>a >>b >>c;
		r[a-1].push_back(pii(b-1,c));
		r[b-1].push_back(pii(a-1,c));
	}
	cin >>q >>k;
	auto ds = bfs(k-1);

	rep(i,q){
		int x,y; cin >>x >>y;
		cout << ds[x-1] + ds[y-1] <<"\n";
	}
	return 0;
}


Measured memory_bytes: 8820
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    if (k>=40) {
        rep(i,n) a[i]=n;
    } else {
        rep(i,k) {
            vector<int> b(n);
            rep(i,n) {
                int l=max(0,i-a[i]);
                b[l]+=1;
                if (i+a[i]+1<n) b[i+a[i]+1]-=1;
            }
            a[0]=b[0];
            rep(i,n-1) a[i+1]=a[i]+b[i+1];
        }
    }
    rep(i,n) cout << a[i] << ' ';
    cout << endl;
    return 0;   
}

Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x; cin>>x;
  bool flag=true, ans=true;;
  if (x==2) cout <<2 <<endl;
  else {
    while(flag){
      ans=true;
      for(int i=2;i<=sqrt(x);i++){
        if(x%i==0){
          ans=false;
          break;
        }
      }
      if(ans)flag=false;
      else x++;
    }
    cout<<x <<endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	ll x, y, ans=1;
	
	cin >> x >> y;
	
	while(y - x >= x){
		++ans;
		x += x;
	}
	cout << ans;

}


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

// mod. m での a の逆元 a^{-1} を計算する
// a^n mod を計算する
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll calc(ll n, ll k, ll mod){
    ll a=1, b=1;
    // 分子
    rep(i, k){
        a = (a* (n-i)) % mod;
        b = (b*(i+1))% mod;
    }
    // cout << "tmp: " << tmp << endl;

    return a*modpow(b, mod-2, mod)%mod;
}


int main(){
    // 前処理
    ll mod = 1e9+7;
    ll N, a, b; cin >> N >> a >> b;

    ll all = modpow(2, N, mod)-1;
    // cout << "all: " << all << endl;
    ll ans = all-calc(N, a, mod)-calc(N, b, mod);
    while (ans<0) ans+=mod;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

int main()
{
    int height, width;
    std::cin >> height >> width;

    int color_num;
    std::cin >> color_num;
    std::queue<int> color;

    for (int c = 0; c < color_num; ++c) {
        int num;
        std::cin >> num;
        for (int i = 0; i < num; ++i) {
            color.push(c + 1);
        }
    }

    //assert(H * W == N);
    std::vector<std::vector<int>> color_map(100, std::vector<int>(100));

    for (int h = 0; h < height; ++h) {
        for (int w = 0; w < width; ++w) {
            if (h % 2 != 0) {
                color_map[h][width - 1 - w] = color.front();
            } else {
                color_map[h][w] = color.front();
            }
            color.pop();
        }
    }

    for (int h = 0; h < height; ++h) {
        for (int w = 0; w < width; ++w) {
            std::cout << color_map.at(h).at(w) << ' '; 
        }
        std::cout << std::endl;
    }
    return 0;
}


Measured memory_bytes: 384
import string


def main():
    S = input()
    _str = set(S)
    lower_set = set(string.ascii_lowercase)
    if _str == lower_set:
        print("None")
    else:
        no_exists = list(lower_set - _str)
        print(sorted(no_exists)[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3832
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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; }

string S;
ll ans=0;

ll max(ll a, ll b){
    if(a>b)return a;
    else return b;
}

int main(){
    cin>>S;
    ll l[S.size()+1],r[S.size()+1];
    l[0]=0;
    r[S.size()]=0;
    rep(i,S.size()){
        if(S[i]=='<')l[i+1] = l[i] + 1;
        else l[i+1] = 0;
    }
    for(int i=S.size()-1; i>=0; i--){
        if(S[i]=='>')r[i] = r[i+1] + 1;
        else r[i] = 0;
    }
    rep(i,S.size()+1)ans+=max(l[i],r[i]);

    out(ans);
    
    
}


Measured memory_bytes: 8708
#include <bits/stdc++.h>
using namespace std;
typedef struct
{
    char b[100];
}qq;
int main()
{

    int n;
    scanf("%d",&n);
    int b[50];
    int c[50];
    memset(b,0,sizeof(b));
    qq a[100];
    for(int i=0;i<n;i++)
    {
        scanf("%s",a[i].b);
    }
    for(int i=0;a[0].b[i];i++)
    {
        b[a[0].b[i]-'a']++;
    }
    for(int j=1;j<n;j++)
    {
       memset(c,0,sizeof(c));
       for(int w=0;a[j].b[w];w++)
       {
           c[a[j].b[w]-'a']++;
       }
       for(int jj=0;jj<30;jj++)
       {
           b[jj]=min(b[jj],c[jj]);
       }

    }

    int flag=0;
    for(int i=0;i<30;i++)
    {
        if(b[i]!=0)
        {
            flag=1;
            for(int j=1;j<=b[i];j++)
            {
                printf("%c",i+'a');
            }
        }
    }
    if(flag==0)
    {
        printf(" \n");
    }
    else
    {
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var (k, a, b) = readLine()!!.split(" ").map(String::toLong)
    if (b > a + 1 && k > a - 1) {
        k -= a - 1
        a + ((k / 2) * (b - a)) + (k % 2)
    } else {
        k + 1
    }.let(::println)
}


Measured memory_bytes: 37932
def run():
  N, X = map(int, input().split())
  y = N-X
  ans = N
  while True:
    y, X = max(y, X), min(y, X)
    a = y//X
    b = y%X
    ans += a*X*2
    if b == 0:
      break
    y, X = X, b
  print(ans-X)
  
  
if __name__ == '__main__':
  run()

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

const long long MOD = 2019;

void solve(long long L, long long R) {
  long long ans =9999;
  vector<long long> rlist;
  vector<long long> llist;
    for(long long i=L; i<=R; i++){
      if(i%2019==0){
          cout<<0<<endl;
        return;
      }
    }
    for(long long i=L; i<R; i++){
      for(long long j=i+1; j<=R; j++){
          ans = min(ans, ((i%2019)*(j%2019))%2019);
      }
    }
    cout << ans << endl;
}

int main() {
  long long L;
  scanf("%lld", &L);
  long long R;
  scanf("%lld", &R);
  solve(L, R);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    double ans = 0;
    reps(i, N + 1, 1)
    {
        int value = i;
        int n = 0;
        double prob = 1 / (double)N;
        while (value < K)
        {
            prob *= 0.5;
            value *= 2;
            n++;
        }
        ans += prob;
    }
    cout << fixed << setprecision(10) << ans << endl;
 //   system("pause");
    return 0;
}

Measured memory_bytes: 256
n=int(input())
H=list(map(int, input().split()))

ans = 0
p = 0
for i in range(n-1):
    if H[i] >= H[i+1]:
        p += 1
    else:
        ans = max(ans, p)
        p = 0
ans = max(ans, p)
print(ans)

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

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 MAX_DIGIT = 50;
// dp[上からi桁まで][今までに決めた桁でXがKより小さいことが判明しているか否か(0:未確定 1:確定)]
ll dp[55][2];

void Main() {
    int n;
    ll k;
    cin >> n >> k;
    vll a(n);
    rep(i, n) cin >> a[i];

    memset(dp, -1, sizeof(dp));

    dp[0][0] = 0;


    rep(i, MAX_DIGIT) {
        ll mask = 1LL << (MAX_DIGIT - i - 1);

        // a のうちもともと i 桁目にビットが立っているものの個数
        int num = 0;
        rep(j, n) {
            if (a[j] & mask)++num;
        }

        // x の i 桁目を 0, 1 にしたときのスコア
        ll score0 = mask * num; // 0にすると、a の i 桁目が 1 のものがスコアに影響する
        ll score1 = mask * (n - num);   // 1 にすると、a の i 桁目が 0 のものがスコアに影響する

        // 既に x < k が確定していれば、0でも1でも良い
        // スコアが大きくなる方を選ぶ
        if (dp[i][1] != -1) {
            chmax(dp[i + 1][1], dp[i][1] + max(score0, score1));
        }

        // x < k を確定させる遷移
        // k の上から i 桁目が 1 である場合に限り、 0 にすることで x < k を確定させることが出来る
        if (dp[i][0] != -1) {
            if (k & mask) {
                chmax(dp[i + 1][1], dp[i][0] + score0);
            }
        }

        // x < k を確定させない遷移
        // k の上から i 桁目と同じ数を、x の上から i 桁目に入れる
        if (dp[i][0] != -1) {
            if (k & mask) chmax(dp[i + 1][0], dp[i][0] + score1);
            else chmax(dp[i + 1][0], dp[i][0] + score0);
        }
    }

    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;


}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()

int main() {
  ll n;
  cin>>n;
  vector<ll> a(n+2);
  rep(i,n-1){
    ll count;
    cin>>count;
    a[count]++;
  }
  rep2(i,1,n+1) cout<<a[i]<<endl;
return 0;
}


Measured memory_bytes: 4768