akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

 int main(){
  ll n ;cin>> n;
  vector<ll> A(n) ;rep(i,n) cin>>A[i] ;
  ll ans=0 ;
  ll j=0 ;
  ll a= 0 ;ll b=0 ;
  ll sum=0 ;
  rep(i,n){
   if(j%2==0) a+=A[i]%2 ;
   if(j%2==1) b+=A[i]%2 ;
   j++ ;
   if(A[i]==0 || i==n-1){
      if(a%2!=b%2) ans++ ;
     a=0 ; b=0 ;
     j=0 ;
   }  
   sum+=A[i] ;
  }
   cout<<(sum-ans)/2<<endl ;
   return 0;
  }

Measured memory_bytes: 1024
import sys


def main():
    read = sys.stdin.buffer.read
    k, n, *A = map(int, read().split())
    far = k + A[0] - A[-1]
    y = A[0]
    for x in A[1:]:
        dis = x - y
        if far < dis:
            far = dis
        y = x
    print(k - far)


if __name__ == "__main__":
    main()

Measured memory_bytes: 27908
#include <iostream>
#include <algorithm>

using namespace std;

const int INF = (1<<28);

main(){
  int n;
  while(cin >> n && n){
    int dp[41][4], p, t, ng = -1, pre_t = 0, pre_p = 0;
    fill(dp[0], dp[41], INF);
    dp[0][0] = 0;
    for(int i=0;i<n;i++){
      cin >> p >> t;
      for(int j=0;j<4;j++){
        if(dp[i][j] == INF) continue;
        if(j < 3 && t - pre_t >= abs(p - pre_p) * (j + 1)) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + abs(p - pre_p));
        if(t - pre_t >= pre_p * (j + 1) + p) dp[i+1][1] = min(dp[i+1][1], dp[i][j] + pre_p + p);
      }
      pre_p = p;
      pre_t = t;
    }
    int ans = INF;
    for(int i=0;i<4;i++) ans = min(ans, (i ? dp[n][i] + pre_p : dp[n][i]));
    if(ans != INF) cout << "OK " << ans << endl;
    else{
      for(ans=n-1;ans>=0;ans--) for(int j=0;j<4;j++) if(dp[ans][j] != INF) goto END;
      END: cout << "NG " << ans+1 << endl;
    }
  }
}

Measured memory_bytes: 1160
import Data.List

ans ([0]:_) = []
ans (_:x:r) =
  let s = sort x
      s'= drop 1 s
      d = minimum $ map (\ (a,b) -> a-b ) $ zip s' s
  in
    d:(ans r)

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  mapM_ print o



Measured memory_bytes: 5532
def resolve():
    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))
    colors = []
    for i, ai in enumerate(a):
        colors += [i + 1] * ai
    ans = []
    for i in range(h):
        if i % 2 == 1:
            ans.append(colors[w * i:w * (i + 1)][::-1])
        else:
            ans.append(colors[w * i:w * (i + 1)])
    for row in ans:
        print(" ".join([str(e) for e in row]))


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 39792
#include <algorithm>
#include <cstdio>
#define LL long long

using namespace std;

const int N = 1e5 + 5;

int n, m, v, p;
int d[N];

bool cmp(int a, int b) {
    return a > b;
}

bool check(int mid) {
    if (mid <= p) return 1;
    if (d[mid] + m < d[p]) return 0;
    if (v < p && d[mid] + m >= d[p]) return 1;
    LL ans = (LL)m * p;
    for (int i = n, j = v - p; i > mid && j; i--, j--) {
        ans += m;
    }
    LL ned = (LL)m * v - ans;
    int cd;
    for (int i = p; i < mid; ++i) {
        int x = min(m, max(0, d[mid] + m - d[i]));
        if (x > ned) x = ned;
        ned -= x;
        if (i == p) {
            cd = d[p] + x;
        }
    }
    return cd <= m + d[mid] && ned <= 0;
}

int main() {
    scanf("%d%d%d%d", &n, &m, &v, &p);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &d[i]);
    }
    sort(d + 1, d + n + 1, cmp);
    int l = 1, r = n;
    int ans = 0;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (check(mid)) {
            l = mid + 1;
            ans = mid;
        } else {
            r = mid - 1;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int p[100001];
int main(){
	int n;
	cin >> n;
	int ans=0;
	int cont=0;
	for(int i=1;i<=n;i++){
		cin >> p[i];
		if(p[i]==i) cont++;
		if(p[i]!=i || i==n) {
			ans+=cont/2+cont%2;
			cont=0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> & l, const pair<T1, T2> & r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> & l, const pair<T1, T2> & r) { return make_pair(l.first - r.first, l.second - r.second); }


template <std::int_fast64_t Modulus>
class modint
{
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept
	{
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept
	{
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept
	{
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept
	{
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept
	{
		a += rhs.a;
		if (a >= Modulus)
		{
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept
	{
		if (a < rhs.a)
		{
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept
	{
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept
	{
		u64 exp = Modulus - 2;
		while (exp)
		{
			if (exp % 2)
			{
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
const lint MOD = 1e9 + 7;
typedef modint<MOD> ModInt;
#pragma endregion

lint arr[300000];
lint cnt[61];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	lint N;
	cin >> N;
	REP(i, N) {
		cin >> arr[i];
	}
	REP(i, N) {
		lint tmp = arr[i];
		REP(j, 60) {
			if ((tmp >> j) % 2 == 1) cnt[j]++;
		}
	}
	ModInt ans = 0;
	REP(i, 60) {
		ans += ((1ll << i) % MOD) * ((cnt[i] * (N - cnt[i]))%MOD);
	}
	cout << ans.a;
}


Measured memory_bytes: 2560
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef double d;
typedef long double ld;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(auto &x:v)
    {
        cin>>x;
    }
    vector<ll> dp(n);
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(ll i=2;i<n;i++)
    {
        ll a=dp[i-1]+abs(v[i]-v[i-1]);
        ll b=dp[i-2]+abs(v[i]-v[i-2]);
        dp[i]=min(a,b);
    }
    cout<<dp[n-1];
    return 0;
}




Measured memory_bytes: 1792
import sys

input = sys.stdin.readline


def main():
    N, L = map(int, input().split())
    S = [None] * N
    for i in range(N):
        S[i] = input().rstrip()
    S.sort()
    ans = "".join(S)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] T = new int[N];
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      T[i] = sc.nextInt();
      A[i] = sc.nextInt();
    }
    long t = 1;
    long a = 1;
    for (int i = 0; i < N; i++) {
      long n = Math.max((t + T[i] - 1) / T[i], (a + A[i] - 1) / A[i]);
      t = n * T[i];
      a = n * A[i];
    }
    System.out.println(t + a);
  }
}

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

typedef long long ll;
const int mod=998244353;

int n,sz,x[200005],d[200005];
pair<int,int> robots[200005];
int dp[200005];
int f[200005];
int dat[800005];

void upd(int pos,int val){
    pos+=sz-1;
    dat[pos]=val;
    while(pos>1){
        pos>>=1;
        dat[pos]=max(dat[pos<<1],dat[pos<<1|1]);
    }
}

int qry(int bk,int l,int r,int ql,int qr){
    if(qr<l||r<ql)return 0;
    if(ql<=l&&r<=qr)return dat[bk];
    return max(qry(bk<<1,l,l+r>>1,ql,qr),qry(bk<<1|1,(l+r>>1)+1,r,ql,qr));
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    sz=1;while(sz<n)sz<<=1;
    for(int i=1;i<=n;i++){
        cin>>robots[i].first>>robots[i].second;
    }
    sort(robots+1,robots+1+n);
    for(int i=1;i<=n;i++){
        x[i]=robots[i].first;
        d[i]=robots[i].second;
    }
    for(int i=n;i>=1;i--){
        int j=upper_bound(x+1,x+1+n,x[i]+d[i]-1)-x-1;
        f[i]=max(i,qry(1,1,sz,i,j));
        upd(i,f[i]);
    }
    dp[n+1]=1;
    for(int i=n;i>=1;i--){
        dp[i]=(dp[i+1]+dp[f[i]+1])%mod;
    }
    cout<<dp[1]<<endl;

    return 0;
}

Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int>k(m);
  vector<vector<int> >s(m);
  int ss;
  vector<int>p(m);
  int bit = 0;
  int i,j;
  for(i=0;i<m;i++){
    cin >> k[i];
    for(j=0;j<k[i];j++){
      cin >> ss;
      s[i].push_back(ss);
    }
  }
  for(i=0;i<m;i++){
    cin >> p[i];
  }
  int tmp = 0;
  int light = 0;
  int ans = 0;
  for(bit=0;bit<1<<n;bit++){
    light = 0;
    for(i=0;i<m;i++){
      tmp = 0;
      for(j=0;j<k[i];j++){
        if(bit & 1<<(s[i][j]-1))tmp++;
      }
      if(tmp%2==p[i])light++;
    }
    if(light==m)ans++;
  }
  cout << ans << endl;
}


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

using namespace std;


int main() {
	int N, Y;
	cin >> N >> Y;
	int a, b, c;
	a = -1; b = -1; c = -1;

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			int k = N - i - j;
			if(k >= 0) {
				if (10000 * i + 5000 * j + 1000 * k == Y) {
					a = i;
					b = j;
					c = k;
				}
			}
		}
	}

	cout << a << " " << b << " " << c << endl;

	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	ll pos=0;
	REP(act,n-1) {
		ll npos=(pos+1)/(k-1)*k;
		if((pos+1)%(k-1)==0) npos--;
		else npos+=(pos+1)%(k-1);
		pos=npos;
	}
	cout<<pos<<endl;
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define ff(i,s,n) for(int i=s;i<n;i++)
#define fr(i,s,n) for(int i=n-1;i>=s;i--)
#define llu long long int
const int mod=1000000007;

int val=0;
void dfs(set<int> adj[], bool visited[], int source){
	val++;
	visited[source]=true;
	set<int>::iterator i;
	for (i = adj[source].begin(); i != adj[source].end(); ++i) 
        if (!visited[*i]) 
            dfs(adj, visited, *i); 
	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,e;
	cin>>n>>e;
	set<int> adj[n];
	for(int i=0;i<e;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		//if(find(adj[a].begin(),adj[a].end(),b)==adj[a].end())
			adj[a].insert(b);
		//if(find(adj[b].begin(),adj[b].end(),a)==adj[b].end())
			adj[b].insert(a);
	}
	
	bool visited[n];
	memset(visited,false,sizeof(visited));
	
	int ans=0;
	for(int i=0;i<n;i++){
		val=0;
		//TODO: for every node do DFS 
		if(!visited[i]){
			dfs(adj,visited,i);
			ans=max(ans,val);
		}
	}
	cout<<ans;
	return 0;
}


//1
//7 2
//3 5 4 5 1 1 1


Measured memory_bytes: 41256
def read():
    N, K = list(map(int, input().strip().split()))
    P = list(map(int, input().strip().split()))
    return N, K, P

def excepted_value(p):
    return p * (p+1) // 2

def solve(N, K, P):
    s = [0 for i in range(N+1)]
    for i in range(1, N+1):
        s[i] = s[i-1] + P[i-1]
    max_left_value = -1
    max_left_idx = -1
    for i in range(N+1-K):
        if s[i+K] - s[i] > max_left_value:
            max_left_value = s[i+K] - s[i]
            max_left_idx = i
    excepted_value_sum = 0.0
    for i in range(max_left_idx, max_left_idx+K):
        excepted_value_sum += float(excepted_value(P[i])) / P[i] 
    return excepted_value_sum


if __name__ == '__main__':
    inputs = read()
    print("%.8f" % solve(*inputs))


Measured memory_bytes: 25172
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

ll X,Y;
ll A,B,C;
priority_queue<ll> p,q,pqr;

int main(){
    cin>>X>>Y>>A>>B>>C;
    rep(i,A){ll x; cin>>x; p.push(x);}
    rep(i,B){ll x; cin>>x; q.push(x);}
    rep(i,C){ll x; cin>>x; pqr.push(x);}

    rep(i,X){pqr.push(p.top()); p.pop();}
    rep(i,Y){pqr.push(q.top()); q.pop();}

    ll ans=0;
    for(int i=0;i<X+Y;i++){
        ans+=pqr.top();
        pqr.pop();
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 8048
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int N;
    cin >> N;
    int d[N];
    int ans = 0;
    REP(i,N)cin >> d[i];
    REP(i,N){
        REP(j,N){
            if(i != j)ans += d[i]*d[j];
        }
    }
    cout << ans/2 << endl;
}


Measured memory_bytes: 256
def check_odd(i, j):
    return (i + j) % 2 == 0


def check_even(i, j):
    return i % 2 == 0


def solve(n, d1, d2):
    s1, s2 = 0, 0
    while d1 % 4 == 0:
        d1 >>= 2
        s1 += 1
    while d2 % 4 == 0:
        d2 >>= 2
        s2 += 1

    f1 = check_odd if d1 % 2 else check_even
    f2 = check_odd if d2 % 2 else check_even
    lim = n ** 2

    buf = []
    cnt = 0
    for i in range(2 * n):
        _i1 = i >> s1
        _i2 = i >> s2
        for j in range(2 * n):
            if f1(_i1, j >> s1) and f2(_i2, j >> s2):
                buf.append('{} {}'.format(i, j))
                cnt += 1
                if cnt == lim:
                    return buf


n, d1, d2 = map(int, input().split())
print('\n'.join(solve(n, d1, d2)))


Measured memory_bytes: 9496
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

int main(){

	int n,m,length,count,tmp_length;
	char* buf = new char[1000050],pre,start;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		length = 2*n+1;

		scanf("%d",&m);
		scanf("%s",buf);

		count = 0;
		tmp_length = 1;
		pre = buf[0];
		start = buf[0];
		for(int i = 1; i < m; ){
			if(buf[i] != pre){
				tmp_length++;
				pre = buf[i];
				i++;
			}
			else{
				if(start == 'O')tmp_length--;
				if(tmp_length%2==0)tmp_length--;

				if(tmp_length >= length){
					count += (tmp_length-length)/2+1;
				}

				tmp_length = 1;
				pre = buf[i];
				start = buf[i];
				i++;
			}
		}

		printf("%d\n",count);
	}


    return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int delicious = 0;
		boolean poison = false;

		while(c > 0) {

			if(poison) 	break;

			c--;
			delicious++;

			poison = true;

			if(b > 0) {
				b--;
				delicious++;
				poison = false;
			} else if(a > 0) {
				a--;
				poison = false;
			}
		}

		delicious += b;
		System.out.println(delicious);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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,a; cin >> n >> a;
    cout << (n+a-1)/a << endl;
}
    

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

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

int w, h;
string mp[20];

int dfs(int x, int y) {
	int res = 1;
	mp[y][x] = '#';
	int dx[4] = {-1, 0, 1, 0};
	int dy[4] = { 0,-1, 0, 1};
	rep(i, 4) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(0<=nx && nx<w && 0<=ny && ny<h && mp[ny][nx]=='.') {
			res += dfs(nx, ny);
		}
	}
	return res;
}

int main() {
	while(cin >> w >> h, w||h) {
		int sx, sy;
		rep(i, h) {
			cin >> mp[i];
			rep(j, w) {
				if(mp[i][j] == '@') {
					sx = j;
					sy = i;
				}
			}
		}
		cout << dfs(sx, sy) << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    string S;// = "125";
    cin >> S;

    ll sum = 0;
    rep(pat, 1 << (S.size() - 1)) {
        vector<string> t;
        int st = 0;
        rep (i, S.size() - 1) {
            if ((pat >> i) & 1) {
                t.push_back(S.substr(st, i + 1 - st));
                st = i + 1;
            }
        }
        t.push_back(S.substr(st, S.size() - st));

        rep(i, t.size()) {
            sum += atoll(t[i].c_str());
        }
    }
    put(sum);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3592
let () = Scanf.scanf "%d" @@ fun n ->
  let ls = Array.init n @@ fun _ -> Scanf.scanf " %d" Fun.id in
  let ans = 
    List.fold_left (List.fold_left (List.fold_left ( + ))) 0 @@
      List.init n @@ fun i ->
        List.init i @@ fun j ->
          List.init j @@ fun k ->
            if
              ls.(i) <> ls.(j) &&
              ls.(i) <> ls.(k) &&
              ls.(j) <> ls.(k) &&
              ls.(i) + ls.(j) > ls.(k) &&
              ls.(i) + ls.(k) > ls.(j) &&
              ls.(j) + ls.(k) > ls.(i)
            then 1 else 0
  in
  Printf.printf "%d\n" ans

Measured memory_bytes: 9752
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

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

  ll ans = n;
  for (ll i = 1; i*i <= n; i++) {
    if (n % i == 0) {
      ans = min(ans, i + n/i - 2);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
# ＢＦＳ, パターン列挙_全探索用

from collections import deque

n = int(input())

# DFS_start
queue = deque([0]) # 初期化_ここでは'0'を設置
pre_ans = [] # パターン候補の器_初期化

while queue: # queueが空になるまでループ
    tmp = queue.popleft() # パターンの候補を popleft
    if tmp <= n: # パターンとしての条件を確認
        pre_ans.append(tmp) # 条件に合えば append
        x = tmp * 10 + 3 # パターンの候補を作成して...
        y = tmp * 10 + 5 # 〃
        z = tmp * 10 + 7 # 〃
        queue += [x, y, z]  # 積む
# DFS_end

ans = 0
for i in pre_ans: # 列挙したパターンを全探索
    if len(set(str(i))) == 3:
        ans += 1

print(ans)

'''
上記は パターンを列挙 → 全探索 だが、
実際には パターンを列挙 しながら 探索 が高効率

from collections import deque

n = int(input())

# DFS_start
queue = deque([0]) # 初期化_ここでは'0'を設置

ans = 0
while queue: # queueが空になるまでループ
    tmp = queue.popleft() # パターンの候補を popleft
    if tmp <= n: # パターンとしての条件を確認
        if len(set(str(tmp))) == 3: # ここで ansを探索
            ans += 1
        x = tmp * 10 + 3 # パターンの候補を作成して...
        y = tmp * 10 + 5 # 〃
        z = tmp * 10 + 7 # 〃
        queue += [x, y, z]  # 積む

print(ans)

'''

Measured memory_bytes: 7284
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define MOD 1e9 + 7
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265359

template <typename T>
void printVector(string name, vector<T> vec)
{
    cout << name << ": ";
    rep(i, vec.size())
    {
        cout << vec[i] << " ";
    }
    cout << endl;
}

void Main()
{
    int d;
    cin >> d;
    cout << "Christmas";
    rep(i, 25 - d)
    {
        cout << " Eve";
    }
    cout << endl;

    return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
	ll n, d;
	cin >> n >> d;
	ll cnt = 0;
	REP(i, n){
		ll x, y;
		cin >> x >> y;
		if(x * x + y * y <= d * d){
			cnt ++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, vector<long long> A) {
  ll all = 0;
  ll mi = 1000000010;
  ll ma = 0;
  ll allN = 0;
  REP(i, N) allN += i + 1;

  REP(i, N) { all += A[i]; }

  if (all % allN != 0) {
    cout << "NO" << endl;
    return;
  }

  ll K = all / allN;

  REP(i, N) {
    ll d = (i < N - 1) ? A[i + 1] - A[i] : A[0] - A[N - 1];

    // cout << d << " " << ((d - K) % N) << endl;
    if (d - K > 0 || (d - K) % N != 0) {
      cout << "NO" << endl;
      return;
    }
  }

  cout << "YES" << endl;
  return;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> A(N - 1 + 1);
  for (int i = 0; i <= N - 1; i++) {
    cin >> A[i];
  }
  solve(N, A);
  return 0;
}


Measured memory_bytes: 1792
import scala.io.StdIn

object Main extends App {
  val s = StdIn.readLine
  val t = StdIn.readLine

  val sb = StringBuilder.newBuilder
  sb.append(t)
  val len = t.length

  for(i <- 1 to len if (s != sb.toString)) {
    sb.clear
    if(i != len) {
      sb.append(t.substring(len-i))
        .append(t.substring(0,len-i))
      }
  }

  println(if(!sb.isEmpty) "Yes" else "No")
}


Measured memory_bytes: 25396
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  int d = log10(n)+1;
  ll ans = 0;
  for(int i=1; i<d; i+=2) {
    ans += 9*pow(10,i-1);
  }
  if(d%2) ans += n-pow(10,d-1)+1;
  cout << ans << "\n";
  return 0;
}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

void solve() {
    string s; cin >> s;
    int cnt[26] = {};
    FOR(i, 0, sz(s)) cnt[s[i] - 'a']++;
    long long ans = 0;
    FOR(i, 0, 26) FOR(j, i + 1, 26) {
        ans += (long long) cnt[i] * cnt[j];
    }
    cout << ans + 1 << "\n";
}

int main() {
    int JUDGE_ONLINE = 1;
    if (fopen("in.txt", "r")) {
        JUDGE_ONLINE = 0;
        assert(freopen("in.txt", "r", stdin));
        //assert(freopen("out.txt", "w", stdout));
    }
    else {
        ios_base::sync_with_stdio(0), cin.tie(0);
    }
    solve();
    if (!JUDGE_ONLINE) {
        //cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    }
    return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n,q;
string s;
vector<char> t,d;


bool g(int m){
  m--;
  rep(i,q){
    if(s[m]==t[i]){
      if(d[i]=='L') m--;
      else m++;
    }
    if(m<0||m>n) return true;
  }
  return false;
}


int f(){
  int l=-1,r=n;
  while(r-l>1){
    int m=(r+l)/2;
    if(g(m)) l=m;
    else r=m;
  }

  if(g(r)) return r;

  return l;
}
  

int main(){
  cin>>n>>q;
  cin>>s;
  rep(i,q){
    char a,b;
    cin>>a>>b;
    t.PB(a); 
    d.PB(b);
  }

  int l=f();
  reverse(all(s));
  rep(i,q){
    if(d[i]=='L') d[i]='R';
    else d[i]='L';
  }
  int r=f();

  cout<<min(n,n-l-r)<<endl;
}


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

int main()
{
    int n;
    string str;
    stack<char> s;

    while( cin >> n )
    {
        if( n == 0 )
            break;
        cin >> str;
        
        for( int i = 0; i < n; i++ )
        {
            int j = str.size() - 1;
            while( j >= 0 )
            {
                s.push(str[j]);
                int cnt = 1;
                while( j - 1 >= 0 && str[j] == str[j-1] )
                {
                    cnt++;
                    j = j - 1;
                }
                while( cnt != 0 )
                {
                    s.push((cnt%10)+'0');
                    cnt /= 10;
                }
                j--;
            }
            str = "";
            while( s.size() != 0 )
            {
                str += s.top();
                s.pop();
            }
        }
        cout << str << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(void)
{
  long long i, N, sum, target, tmp;
  // get input
  cin >> N;
  // summation of springboard
  sum = 0;
  cin >> tmp;
  target = tmp;
  for(i = 1; i < N; i++) {
    cin >> tmp;
    if(target > tmp) {
      sum += target - tmp;
    } else {
      target = tmp;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(b==1) return a;else if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(n);
    out((n==0));
}

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

typedef long long int lli;

const lli maxn = lli(2e5)+5, inf = lli(1e18)+5;

lli a[maxn];

int main(void)
{
	lli n, tot = 0;
	scanf("%lld", &n);
	for(lli i = 0;i < n;i++)
	{
		scanf("%lld", &a[i]);
		tot += a[i];
	}

	lli cur = 0, res = inf;
	for(lli i = 0;i < n-1;i++)
	{
		cur += a[i];
		res = min(res, llabs(cur-(tot-cur)));
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int n[100],k;
	
	k=0;
	while(cin >> n[k]){
		if(n[k]==0){
			cout << n[k-1] << "\n";
			k--;
		}
		else{
			k++;
		}
	}
		
return 0;
}

Measured memory_bytes: 1160
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if op == "?":
        break
    elif op == "+":
        print( a + b)
    elif op == "-":
        print( a - b)
    elif op == "/":
        print( a // b)
    else:
        print( a * b)


Measured memory_bytes: 5592
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=200000000000000;
//setprecision(2) <<

const int MOD = 1000000007;

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

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}
long myPow(long long x, long long n, long long m=MOD){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

class Point{
public:
	long long x;
	long long y;
	long long dis;
	Point(long long _x,long long _y,long long _dis){
		x=_x;
		y=_y;
		dis=_dis;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long n;
	cin>>n;
	long long ans=INF;
	for(long long  i=1;i*i<=n;i++){
		if(n%i==0){
			long long  j=n/i;
			ans=min(ans,i+j-2);
		}
	}
	cout<<ans<<endl;
}


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


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


    int d, t, s; cin >> d >> t >> s;


    cout << (d <= s * t ? "Yes" : "No") << endl;


    return 0;
}


Measured memory_bytes: 3632
package main

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

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	ma, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	args := strings.Split(sc.Text(), " ")

	value := []int{}
	for _, v := range args {
		a, _ := strconv.Atoi(v)
		value = append(value, a)

	}
	ans(ma, value)

}

func ans(n int, value []int) {

	max := 0
	cnt := 0

	for i := 0; i < n; i++ {

		if value[i] == 1 {
			cnt++
		} else {
			if cnt > max {
				max = cnt
			}
			cnt = 0
		}
	}

	if cnt > max {
		max = cnt
	}

	fmt.Printf("%d\n", max+1)
}



Measured memory_bytes: 1108
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;
 
int gcd(int i, int j) {
    int a = i;
    int b = j;
 
    int r = a % b;
 
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
 
    return b;
}
 
int main(){
    int N;
    cin >> N;
 
    long long sum = 0;
 
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            for(int k = 1; k <= N; k++){
                sum += gcd(gcd(i,j),k); 
            }
        }
    }
 
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 3632
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, M = li_input()
    R = [0] * (N+1)
    
    for i in range(M):
        a, b = li_input()
        R[a] += 1
        R[b] += 1

    for i in range(1, N+1):
        print(R[i])



main()


Measured memory_bytes: 4904
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;

	cin >> a >> b >> c;

	if (a == b && b == c)
		cout << 1 << endl;
	else
		if (a != b && b != c && a != c)
			cout << 3 << endl;
		else
			cout << 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a;
    for(int i = 1; i < 6; i++){
        cin >> a;
        if(a == 0)
            cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
function main(lines) {
  const N = n();
  const as = na();

  const counts = Array(N).fill(0);
  as.forEach(a => {
    counts[a-1]++;
  });
  const ans = counts.join('\n');
  
  return ans;
}



const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");

let lineCount = 0;
const s = () => lines[lineCount++];
const n = () => Number(s());
const b = () => BigInt(s());
const sa = () => s().split(' ');
const na = () => sa().map(Number);
const ba = () => sa().map(BigInt);

const ans = main(lines);
console.log( ans );

Measured memory_bytes: 54720
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
const int w=5e5+5;
const ll mod=998244353;
int n,m;
int main()
{
    int i,j;
    ll x,y,z;
    cin>>x>>y>>z;
    if(y>z)
        swap(y,z);
    if((z-y)%2==0)
        printf("%lld\n",(z-y)/2);
    else
    {
        ll ans=(z-y)/2;
        ans++;
        ans+=min(y-1,x-z);
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define int long long
using namespace std;
const int maxn = 1e5+10;
const int mod = 1e9+7;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int ksm(int x,int y){
	int sum=1;
	while(x){
		if(x&1)sum=sum*y%mod;
		y=y*y%mod;
		x>>=1;
	}
	return sum;
}

int k,m,n;
int a[maxn];
int C[maxn];
signed main(){
	n=read();k=read();
	for(register int i=1;i<=n;i++)a[i]=read();
	C[k-1]=1;
	for(register int i=k;i<=n;i++){
		C[i]=C[i-1]*i%mod*(ksm(mod-2,i-k+1))%mod;	
	}
	sort(a+1,a+n+1);
	int sum=0,ans=0;
	for(register int i=n;i>=k;i--){
		(ans=ans+C[i-1]*a[i]%mod)%=mod;
	}
	for(register int i=1;i+k-1<=n;i++){
		(ans=ans-C[n-i]*a[i]%mod+mod)%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

ll n,k;
vl a(9);

bool f(ll x){
  bool b=true;
  vl cnt(10,0);
  while(x!=0){
    cnt[x%10]++;
    x /=10;
  }
  rep(i,k){
    if(cnt[a[i]]!=0){
      b=false;
    }
  }
  return b;
}

int main() {
  cin >> n >> k;
  rep(i,k){
    cin >> a[i];
  }
  while(!f(n)){
    n++;
  }
  cout << n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right

#define INF 1000000000
ll N , M, X;
vector<ll> C;
vector<vector<ll> > A;

ll check(vector<ll>& candi){
    ll ans = 0;
    
    vector<ll> su; rep(i, M) su.pb(0);
    rep(i, candi.size()){
        ans += C[candi[i]];
        
        rep(j, A[candi[i]].size()){
            su[j] += A[candi[i]][j];
        }
    }
    
    // ------------------------------
//    cout << "----------------" << endl;
//    rep(i, candi.size()){
//        cout << candi[i] << " ";
//    }
//    cout << endl;
//    
//    rep(i, su.size()){
//        cout << su[i] << " " ;
//    }
//    cout << endl;
    
    // ------------------------------
    rep(i, su.size()){
        if(su[i] < X) {
            ans = INF;
            return ans;
        }
    }

    return ans;
}

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

    cin >> N >> M >> X;
    
    
    rep(i, N){
        ll ci ; cin >> ci ;
        C.pb(ci);
        
        vector<ll> ai;
        rep(i, M){
            ll inp; cin >> inp;
            ai.pb(inp);
        }
        A.pb(ai);
    }

    ll ans = INF;
    

    for(ll bit = 0; bit < (1<<N); ++bit){
        vector<ll> S;
        rep(i,N){
            if(bit &(1<<i)){
                S.pb(i);
            }
        }
        ans = min( ans, check(S)) ;
    }

    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 3664
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int H = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        int N = Integer.parseInt(sc.next());

        int max = Math.max(H, W);

        out.printf("%d\n", (N - 1) / max + 1);
        out.flush();
    }
}


Measured memory_bytes: 21332