akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
    IOS;
    int n,q;
    cin >> n >> q;
    constexpr int sq = 316;
    vector<ll> a(n,0);
    vector<ll> s((n+sq-1)/sq,0);
    REP(i,q){
        int c,x,y;
        cin >> c >> x >> y;
        if(c==0){
            x--;
            a[x] += y;
            int t = x/sq;
            s[t] += y;
        }else{
            ll res = 0;
            x--;y;
            if(x/sq==y/sq){
                FOR(j,x,y){
                    res+=a[j];
                }
            }else{
                int id1=(x+1+sq-1)/sq,id2=y/sq;
                FOR(j,x,id1*sq){
                    res+=a[j];
                }
                FOR(j,id1,id2){
                    res+=s[j];
                }
                FOR(j,id2*sq,y){
                    res+=a[j];
                }
            }
           
            put(res);
        }
    }
}



Measured memory_bytes: 3480
#include <bits/stdc++.h>
#include<map>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
ll const MOD=1e9+7;
using ll = long long;

int main(){
  int n;
  cin>>n;
  map<string,int> data;
  string buf;
  REP(i,n){
    cin>>buf;
    data[buf]=0;
  }
  cout<<data.size()<<endl;
}

Measured memory_bytes: 19196
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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 n, a, b, c;
vector<int> l(8);
int solve(int now,int x,int y,int z,int w){
    if(now==n){
        if(x*y*z==0){
            return 100000;
        }
        return abs(a-x)+abs(b-y)+abs(c-z)+(w-3)*10;
    }
    return min({solve(now + 1, x + l[now], y, z,w+1), solve(now + 1, x, y + l[now], z,w+1), solve(now + 1, x, y, z + l[now],w+1), solve(now + 1, x, y, z,w)});
}
int main()
{
    cin >> n >> a >> b >> c;
    REP(i,n){
        cin >> l[i];
    }
    cout << solve(0,0,0,0,0) << endl;
}


Measured memory_bytes: 3608
H, W = map(int, input().split())

while H != 0 or W != 0:
    print("#" * W)
    for i in range(1, H - 1):
        print("#", "." * (W - 2), "#", sep="")
    print("#" * W)
    print("")
    H, W = map(int, input().split())


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N, K; cin >> N >> K;
    string s = "";
    rep(i, K){
        char a; cin >> a;
        s.push_back(a);
    }
    int res = 0;
    Rep(i, 1, 100000){
        if(i < N) continue;
        string tmp = to_string(i);
        bool f=true;
        rep(j, tmp.size()){
            if(count(all(s), tmp[j])){
                f = false;
                break;
            }
        }
        if(f){
            res = i;
            break;
        }
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
N = int(input())
v = map(int,input().split())

val = 0
v_1 = sorted(v)
for i in range(N-1):
  news = (v_1[0]+v_1[1])/2
  v_1.append(news)
  del v_1[0:2]
  v_1.sort()

print(v_1[0])

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
    int n,k,q;
    cin >> n >> k >> q;
    int a[q];
    for(int i=0;i<q;i++){
        cin >> a[i];
    }
    int po[n];
    for(int i =0;i<n;i++){
        po[i]=0;
    }
    for(int i=0;i<q;i++){
        po[a[i]-1]++;
    }
    for(int i =0;i<n;i++){
        if(k>q-po[i]){
            cout << "Yes"<< "\n";
        }else{
            cout << "No"<< "\n";
        }
        //if(i<n-1){
            //cout << "\n";
        //}
    }
}

Measured memory_bytes: 1408
#include<iostream>

using namespace std;

int main(){
  int S,h,m,s;

  cin >> S;

  h = S / 3600;
  m = S % 3600 / 60;
  s =  S % 3600 % 60;

  cout << h << ":" << m << ":" << s << endl;
} 

Measured memory_bytes: 1168
length = int(input())
unsort_list = list(map(int,input().split()))
sort_list = [i+1 for i in range(length)]


values = [(i,j) for (i,j) in zip(unsort_list,sort_list) if i != j]

if len(values) < 3:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;

  int taroScore = 0;
  int hanakoScore = 0;

  for (int i=0; i<n; i++) {
    string taro;
    string hanako;
    cin >> taro;
    cin >> hanako;

    if (taro>hanako) {
      taroScore+=3;
    }else if(taro<hanako){
      hanakoScore+=3;
    }else{
      taroScore+=1;
      hanakoScore+=1;
   }
  }

  cout << taroScore << " " << hanakoScore << endl;
}

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

int N;
int A[20];
int x[20][20];
int y[20][20];
// "<<"　左シフト演算　
// ">>" 右シフト演算
// "&" AND演算(ビット積)
// "^" 排他的論理和
void input() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		for (int j = 1; j <= A[i]; j++) {
			cin >> x[i][j] >> y[i][j];
		}
	}
}
int counter(int x) {
	if (x == 0) return 0;
	return counter(x >> 1) + (x & 1); //2進数の並びを、フラグの数の合計にして返すカウンタ関数
}

void solve() {
	input();
	int ans = 0;   

	//, 0 以上 2^N 未満の整数 j が「1 以上 N 以下の整数 k について, 人 k が正直者であることと, 
	//j を 2 進数表記した際に k−1 桁目が 1 であることが同値」という状態を表すことと定義すると, 容易に全ての場合を試すことが出来る。 
	//この手法は bit 全探索と呼ばれる。

	for (int bits = 1; bits < (1 << N);bits++) {//bit全探索　すべての組み合わせ
		bool judge = true;
		for (int i = 1; i <= N; i++) {//A[i]について
			if (!(bits & (1 << (i - 1)))) continue;  //フラグがない
			for (int j = 1; j <= A[i]; j++) { //bitsのi-1番目のフラグがある
				if (((bits >> (x[i][j] - 1)) & 1) ^ y[i][j]) judge = false;  //矛盾がある： 正直者と仮定している中で不親切だという証言があった
			}
		}
		if (judge) ans = max(ans, counter(bits));
	}
	cout << ans << endl;
	return;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
import sys
#input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    N = int(input())
    S = input()
    mae,usi = S[:N],S[N:][::-1]
    md,ud = defaultdict(int),defaultdict(int)
    
    for i in range(1<<N):
        mr,mb,ur,ub = "","","",""
        for j in range(N):
            if (i>>j)&1:
                mr += mae[j]
                ur += usi[j]
            else:
                mb += mae[j]
                ub += usi[j]
        md[(mr,mb)] += 1
        ud[(ur,ub)] += 1
    
    ans = 0
    for key,val in md.items():
        ans += ud[key]*val
        
    print(ans)

if __name__ == "__main__":
    main()


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

int main(){
    int N;
    cin >> N;
    vector<int> V(N);
    for(int i=0; i<N; i++) cin >> V[i];
    sort(V.begin(), V.end());
    cout << V[N/2] - V[N/2 - 1] << endl;
}

Measured memory_bytes: 3776
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
      	
      	while(true){
        	String strArr[] = br.readLine().split(" ");
	        
          	int a = Integer.parseInt(strArr[0]);
    	    int b = Integer.parseInt(strArr[1]);
			if (a == 0 && b == 0) {
            	break;
            }
            
            for(int i = 0; i < a; i++) {
                for(int j = 0; j < b; j++) {
                  	if (i % 2 == 0) {
                      if (j % 2 == 0) {
                      	sb.append("#");	
                      } else {
                      	sb.append(".");
                      }
                    } else {
                    	if (j % 2 != 0) {
                      	sb.append("#");	
                      } else {
                      	sb.append(".");
                      }
                   }
                }
                sb.append("\n");
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
}



Measured memory_bytes: 25640
#include "bits/stdc++.h"
using namespace std;


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

	int t;
	for (t = 1; t <= x; t++) {
		if (t * (t + 1) / 2 >= x) {
			break;
		}
	}
	cout << t << endl;
}

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

long long M;
long long N;
long long x[100001];
long long y[100001];
long long dp[100001];
vector<long long> v[100001];

long long calc(long long n) {
	if (v[n].size() == 0) return 0;
	for (int i = 0; i < v[n].size(); i++) {
		if (dp[v[n][i]] != -1) {
			dp[n] = max(dp[n],dp[v[n][i]]+1);
		} else {
			dp[n] = max(dp[n],calc(v[n][i])+1);
		}
	}
	return dp[n];
}

int main(){
	scanf("%lld",&N);
	scanf("%lld",&M);
	for(int i = 0 ; i <= M-1 ; i++){
		scanf("%lld",&x[i]);
		scanf("%lld",&y[i]);
	}
	for (long long i = 0; i < N; i++) {
		dp[i] = -1;
	}
	for (long long i = 0; i < M; i++) {
		v[y[i]-1].push_back(x[i]-1);
	}
	for (int i = 0; i < N; i++) {
		dp[i] = calc(i);
	}
	long long res = -1;
	for (int i = 0; i < N; i++) {
		res = max(res,dp[i]);
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 12544
#include <stdio.h>

int main(){
  int i, j, n;
  char s[3][4];

  while(1){
    for(i = 0; i < 3; ++i){
      scanf("%s", s[i]);
      if(s[i][0] == '0') return 0;
    }
    for(i = 0; i < 3; i++)
      if(s[i][0] == s[i][1] && s[i][1] == s[i][2] && s[i][0] != '+'){
	printf("%c\n", s[i][0]); goto e;}
    for(i = 0; i < 3; ++i)
      if(s[0][i] == s[1][i] && s[1][i] == s[2][i] && s[0][i] != '+'){
	printf("%c\n", s[0][i]); goto e;}
    
    if(s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[0][0] != '+'){
      printf("%c\n", s[0][0]); goto e;}
    if(s[0][2] == s[1][1] && s[1][1] == s[2][0] && s[0][2] != '+'){
      printf("%c\n", s[0][2]); goto e;}
    puts("NA");
  e:;
  }
  return 0;
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; i--)
#define REP(i, k, n) for(int i=(int)(k); i<(int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const int INF = INT_MAX;
const ll inf = 1e18;
const ll mod = 998244353;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x, ll y){ if(x>y) swap(x, y);while(x!=0){ y%=x; swap(x, y); }return y; }
ll mpow(ll x, ll r){if(r==0) return 1;if(r%2==1){ return x*mpow(x, r-1)%mod; }else{ ll aa = mpow(x, r/2); return aa*aa%mod; }}

int main(){
	int N, M; cin >> N >> M;
	int p = (M+1)/2, a = 1, b = 2;
	rep(i, p){
		cout << a << " " << b << endl;
		a = (a+N-1)%N;
		if(a==0) a += N;
		b = b+1;
	}
	int c, d;
	if((b-a)%2==1){
		c = (a+b)/2;
		d = c + 2;
	}else{
		c = ((a+b)/2)-1;
		d = c+2;
	}
	rep(i, M-p){
		cout << c << " " << d << endl;;
		c--; d++;
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if (s < t)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int par(int*a,int l,int r){
	int pib=a[r-1];
	int crr=l;
	for(int i=l;i<r;i++){
		if(a[i]<=pib){
			int t=a[crr];
			a[crr]=a[i];
			a[i]=t;
			crr++;
		}
	}
	return crr-1;
}

int a[100010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	int p=par(a,0,n);
	for(int i=0;i<n;i++)printf(i==p?"[%d]%c":"%d%c",a[i],i==n-1?10:32);
}


Measured memory_bytes: 2132
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<int> id[n + 1]; //in degree
    int deg[n + 1]; rep(i, n + 1) deg[i] = 0;
    vector<int> od[n + 1];
    rep(i, m) {
        int x, y; cin >> x >> y;
        id[y].push_back(x); //入次数
        od[x].push_back(y);
    }
    rep(i, n + 1) deg[i] = (int)id[i].size();
    queue<int> q;
    rrep(i, 1, n + 1) {
        if (id[i].size() == 0) {
            q.push(i);
        }
    }
    int dp[n + 1]; rep(i, n + 1) dp[i] = 0;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        rep(i, od[now].size()) {
            int next = od[now][i];
            deg[next]--;
            dp[next] = dp[now] + 1;
            if (deg[next] == 0) {
                q.push(next);
            }
        }
    }
    int ans = 0;
    rep(i, n + 1) ans = max(ans, dp[i]);
    cout << ans << endl;
}


Measured memory_bytes: 12032
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 250000
ll MOD=998244353;

main(){
    int n=in();
    int a[N],b[N];
    rep(i,n+1)cin>>a[i];
    rep(i,n)cin>>b[i];
    ll ans=0;
    rep(i,n+1){
        ans+=min(a[i],b[i]);
        b[i]-=min(a[i],b[i]);
        ans+=min(a[i+1],b[i]);
        a[i+1]-=min(a[i+1],b[i]);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
int h, w;
vector<string> mat;
int main() {
  cin>>h>>w;
  mat.clear();
  for (int i = 0; i < h; ++i) {
  	string s;
    cin>>s;
    mat.push_back(s);
  }
  for (int i = 1; i <= 2 * h; ++i) {
    cout<<mat[(i+1)/2-1]<<endl;
  }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int s[10];
int main(){
	int p,q,r;
	scanf("%d%d%d",&p,&q,&r);
	int s1=p+q,s2=p+r,s3=q+r;
	int s=2e9;
	s=min(s1,min(s2,s3));
	printf("%d\n",s);
}

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

ans = 0

while sum(h) > 0:
    diff = min([_h for _h in h if _h > 0])
    idx = h.index(diff)
    for i in range(idx, len(h)):
        if h[i] == 0:
            break
        h[i] -= diff
    for i in range(0, idx)[::-1]:
        if h[i] == 0:
            break
        h[i] -= diff
    ans += diff


print(ans)

Measured memory_bytes: 3064
#[allow(unused_imports)]
use {
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::ops::*,
};

fn main() {
    input! {
        n: usize,
        k: usize,
        mut td: [(Usize1, usize); n]
    }
    td.sort_by_key(|&(_, d)| Reverse(d));
    let mut s = VecDeque::new();
    let mut p = 0;
    let mut ts = vec![0; n];
    let mut sum = 0;
    for i in 0..k {
        let (t, d) = td[i];
        if ts[t] == 0 {
            p += 1;
        }
        sum += d;
        ts[t] += 1;
        s.push_back((d, t));
    }

    let mut ans = p * p + sum;
    for (t, d) in (k..n).map(|i| td[i]) {
        if p == k {
            break;
        }
        if ts[t] != 0 {
            continue;
        }
        ts[t] = 1;
        sum += d;
        p += 1;
        while let Some((dn, tn)) = s.pop_back() {
            if ts[tn] > 1 {
                ts[tn] -= 1;
                sum -= dn;
                break;
            }
        }
        ans = max(ans, sum + p * p);
    }
    println!("{}", ans);
}


Measured memory_bytes: 7392
# 入力
W,a,b=map(int,input().split())

# 上の図形が下の図形より左側にある場合
if b<a:

  # 初めから接している場合
  if a<=b+W:
    print(0)
  else:
    print(a-(b+W))

# 下の図形の真上に上の図形がある場合
elif b==a:
  print(0)

# 上の図形が下の図形より右側にある場合
else:

  # 初めから接している場合
  if b<=a+W:
    print(0)
  else:
    print(b-(a+W))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll ,ll>;
const ll INF = 1LL<<61LL;

int main(){
	ll N, x;
	cin >> N >> x;
	if(x == 1 || x == 2*N-1)
		cout << "No" << endl;
	else{
		cout << "Yes" << endl;
		vector<ll> v;
		for(int i=1;i<=2*N-1;i++)
			if(abs(x - i) <= 1)
				continue;
			else
				v.push_back(i);
		for(int i=0;i<N-2;i++)
			cout << v[i] << endl;
		cout << x-1 << endl << x << endl << x+1 << endl;
		for(int i=N-2;i<v.size();i++){
      cout << v[i] << endl;
		}
	}
}


Measured memory_bytes: 3184
#include <stdio.h>
int main()
{
	int n;
	long long a=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		a*=i;		
		a%=1000000007;	
	}	
	printf("%d",a);
	return 0;
 } 

Measured memory_bytes: 128
def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

N=int(input())
L=list(map(int,input().split()))
import sys
ans = sys.maxsize

for i in range(-100,101):
  m_diffs = 0
  for j in range(N):
    m_diffs += pow_k((L[j] - i),2)
  ans = min(ans, m_diffs)

print(ans)


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

constexpr int MaxN = 100;

int64_t gcd(int64_t a, int64_t b)
{
	if (b > a)
	{
		swap(a, b);
	}

	int64_t c = a % b;
	if (c == 0)
	{
		return b;
	}
	else
	{
		return gcd(b, c);
	}
}

int main()
{
	int N;
	int64_t T[MaxN];
	cin >> N;

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

	int64_t ans = T[0];
	for (int i = 0; i < N; ++i)
	{
		ans = ans * (T[i] / gcd(ans, T[i]));
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    int da = abs(x - a);
    int db = abs(x - b);
    if(da < db){
        printf("A\n");
    }else if(da > db){
        printf("B\n");
    }

    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef RUS_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef RUS_HOME
    freopen("input", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}




void smain() {

    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes";
    else
        cout<<"No";



}

Measured memory_bytes: 256
// マニ

#include<bits/stdc++.h>
#define ll            long long 
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define rrep(i,a,b) for(ll int i=a;i>=b;i--)
#define all(a)      (a).begin(),(a).end()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define PI 3.14159265358979323846
#define tr(i, cont) for(auto i=cont.begin();i!=cont.end();i++)
#define ios            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define trace(x)                 cerr << #x << ": " << x << "\n";
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << "\n";
#define ar array
#define endl "\n"
using namespace std;

int main(){
    ios;
    ll n,m,k;
    cin>>n>>m>>k;
    char grid[n][m];
    rep(i,0,n){
        rep(j,0,m){
            cin>>grid[i][j];
        }
    }
    ll ans=0;
    rep(r,0,(1<<n)){
        rep(c,0,(1<<m)){
            ll cnt=0;
            rep(i,0,n){
                rep(j,0,m){
                    if(!((r>>i)&1) && !((c>>j)&1) && grid[i][j]=='#'){
                        cnt++;
                    }
                        // trace3(i,j,(c>>j));
                }
            }
            // trace3(r,c,cnt);
            if(cnt==k)
                ans++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;

int a[N],b[N];

vector<int> adj[N];

bool used[N];
bool vis[N];

int par[N];
vector<int> eular;
void dfs(int node) {
   for(int i=0;i<adj[node].size();++i) {
      int id = adj[node][i];
      if(used[id]) {
         continue;
      }
      used[id] = true;
      int ch = a[id]^b[id]^node;
      dfs(ch);
   }
   eular.push_back(node);
}

void solve() {
   int n,m;
   scanf("%d%d",&n,&m);
   for(int i=0;i<m;++i) {
      scanf("%d%d",&a[i],&b[i]);
      adj[a[i]].push_back(i);
      adj[b[i]].push_back(i);
   }
   vector<int> four;
   int numberofSix = 0;
   for(int i=1;i<=n;++i) {
      if(adj[i].size()>=6) {
         ++numberofSix;
      } else if(adj[i].size()==4) {
         four.push_back(i);
      }
      if(adj[i].size()%2 != 0 ){
         printf("No\n");
         return;
      }
   }
   if(numberofSix || four.size()>=3) {
      printf("Yes\n");
      return;
   }

   if(four.size()==2) {
      dfs(four[0]);
      int x = 0,y = 0;
      int f = eular[0];
      int v = four[0]^four[1]^f;
      assert(f== eular.back());
      int ind;
      for(int i=1;i<eular.size();++i) {
         if(eular[i]==f) {
            ind = i;
            break;
         }
      }
      int xx = 0;
      for(int i=1;i<ind;++i) {
         if(eular[i]==v) {
            ++xx;
            break;
         }
      }
      for(int i=ind+1;i<eular.size();++i) {
         if(eular[i]==v) {
            ++xx;
            break;
         }
      }

      //printf("%d %d\n", eular[0],eular.back());
      if(xx==1) {
         printf("Yes\n");
      } else {
         printf("No\n");
      }
   } else {
      printf("No\n");
   }
}
int main()
{
    //freopen("input.txt","r",stdin);
    solve();
}

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

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rp(i,n) cin >> a.at(i);
    vector<ll> res(n+1);
    res[0]=0ll;
    rp(i,n){
        res[i+1]=res[i]+(a[i]-1)%k;
        res[i+1]%=k;
    }
    if(n<k){
        ll ctr=1ll;
        ll ans=0ll;
        sort(res.begin(),res.end());
        rp(i,n){
            if(res[i]==res[i+1]) ctr++;
            else{
                ans+=ctr*(ctr-1ll)/2ll;
                ctr=1ll;
            }
        }
        ans+=ctr*(ctr-1ll)/2ll;
        cout << ans << endl;
        return 0;
    }
    vector<ll> num(k,0);
    ll ans=0ll;
    rp(i,min(n+1,k)){
        num.at(res[i])++;
    }
    for(auto i:num) ans+=i*(i-1ll)/2ll;
    for(int i=k; i<=n; i++){
        num.at(res[i-k])--;
        ans += num.at(res[i]);
        num.at(res[i])++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
	int n;
  ll k;
  cin >> k >> n;
  vector<ll>  a(n);
  for(auto &i: a)cin >> i;
  sort(a.begin(),a.end());
  ll ans = a[n-1]-a[0];
  for(int i = 1; i < n; ++i)ans = min(ans,a[i-1]+k-a[i]);
  cout << ans;
  return 0;
}


Measured memory_bytes: 1920
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

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

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int x;
    cin>>x;
    if(x){cout<<0;}
    else cout<<1;
}



















Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
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;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF 1000000007 //4000000000000000037
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  string s;
  cin>>s;

  cout<< ( s[1]==s[2] and (s[0]==s[1] or s[2]==s[3]) ? "Yes" : "No" )<<"\n";

}

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


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
N, M = map(int, input().split())
X = list(map(int, input().split()))
EDGE = [list(map(int, input().split())) for i in range(M)]
EDGE.sort(key=lambda x:x[2])

EDGELIST = [[] for i in range(N+1)]
for i in range(M):
    x, y, w = EDGE[i]
    EDGELIST[x].append(i)
    EDGELIST[y].append(i)

Group = [i for i in range(N+1)]

def find(x):
    while Group[x] != x:
        x = Group[x]
    return x

def Union(x, y):
    if find(x) != find(y):
        Group[find(y)] = Group[find(x)] = min(find(y), find(x))

USE = [0]*M
WEIGHTSUM = [0] + [X[i] for i in range(N)]

QUE = deque()

for i in range(M):
    x, y, w = EDGE[i]

    if find(x) != find(y):
        WEIGHTSUM[find(x)] = WEIGHTSUM[find(y)] = WEIGHTSUM[find(x)] + WEIGHTSUM[find(y)]
        Union(x, y)

    if w <= WEIGHTSUM[find(x)]:
        QUE.append(i)

while QUE:
    q = QUE.pop()
    x, y, w = EDGE[q]

    NQUE = deque([q])

    while NQUE:
        nq = NQUE.pop()

        if USE[nq] == 1:
            continue

        x, y, _ = EDGE[nq]
        for e in EDGELIST[x] + EDGELIST[y]:
            if EDGE[e][2] <= w:
                NQUE.append(e)
        USE[nq] = 1

print(USE.count(0))



Measured memory_bytes: 58456
a,b = map(int, input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
import collections
a_list = collections.Counter(prime_factorize(a)).keys()
b_list = collections.Counter(prime_factorize(b)).keys()
ans = 0
for i in a_list:
    if i in b_list:
        ans+=1
print(ans+1) #1が入っていないから

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (long long i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int a,b;
ll n,h[100000];

bool ok(ll x) {
	ll cnt=0;
	REP(i,n) {
		if(h[i]>x*b) cnt+=ceil(1.*(h[i]-x*b)/(a-b));
	}
	if(cnt<=x) return true;
	else return false;
}

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

	cin>>n>>a>>b;
	REP(i,n) cin>>h[i];
	sort(h,h+n);

	ll ub=INF,lb=0;
	while (ub-lb>1) {
		ll mid=(ub+lb)/2;
		if(ok(mid)) ub=mid;
		else lb=mid;
	}
	cout<<ub<<endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define M 200010
#define LL long long
#define inf 2147483647
#define rep(i, x, y) for(int i = (x); i <= (y); ++ i)
inline int read() {
	char ch = getchar(); int x = 0, f = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}
struct Edge{
	int u, v, w, Next;
} G[M * 2];
int head[M], tot;
inline void add(int u, int v, int w) {
	G[++ tot] = (Edge){u, v, w, head[u]};
	head[u] = tot;
}
int d[M];
bool vis[M];
inline void dfs(int x) {
	vis[x] = 1;
	for(int i = head[x]; i != -1; i = G[i].Next) {
		if(d[G[i].v] != inf && d[x] + G[i].w != d[G[i].v]) {
			puts("No"); exit(0);
		}
		if(!vis[G[i].v]) {
			d[G[i].v] = d[x] + G[i].w;
			dfs(G[i].v);
		}
	}
}
int main() {
	//freopen("in.txt", "r", stdin);
	int n = read(), m = read();
	memset(head, -1, sizeof(head));
	rep(i, 1, n) d[i] = inf;
	rep(i, 1, m) {
		int u = read(), v = read(), D = read();\
		add(u, v, D); add(v, u, -D);
	}
	rep(i, 1, n) if(!vis[i]) {
		dfs(i);
	}
	puts("Yes");
	return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define _3_ 1

using namespace std;

typedef unsigned long long ull;
typedef pair<int,int> ii;

struct Point { int x,y; };

const int IINF = INT_MAX;
const char PATH = '$';

int h,w,s_size,c_size,bitIndex[12][12];
char c[12][12];
Point source[12],city[12],path[12];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
int mini,blocks;
int bc[1<<9];

void dfs(int sp,int bitmask,int prev,int step,int depth){

  if( step+(c_size-bc[bitmask]) >= mini ) return;
  
  if( sp >= s_size ) return;

  if( bitmask == ((1<<c_size)-1) ) { mini = step; return; }

  bool next = 1;
  rep(dir,4){
    if( prev != -1 && ( prev + 2 ) % 4 == dir ) continue;
    int nx = path[sp].x + dx[dir], ny = path[sp].y + dy[dir];

    if( c[ny][nx] == 'P' || c[ny][nx] == '#' || c[ny][nx] == PATH ) continue;

    bool success = true;
    int cnt = 0;
    rep(i,4){
      int nx2 = nx + dx[i], ny2 = ny + dy[i];
      if( c[ny2][nx2] == PATH || c[ny2][nx2] == 'P' ) ++cnt;
    }
    if( cnt != 1 ) success = false;
    if( !success ) continue;
    
    Point pp = path[sp];
    char pc = c[ny][nx];
    int nbitmask = bitmask;
    bool fin = false;
    if( c[ny][nx] == '*' ) nbitmask |= (1<<bitIndex[ny][nx]), fin = true;

    path[sp] = (Point){nx,ny};
    c[ny][nx] = PATH;

    next = 0;
    dfs(sp,nbitmask,dir,step+1,depth+1);
    if( fin )dfs(sp+1,nbitmask,-1,step+1,0);

    path[sp] = pp;
    c[ny][nx] = pc;

    /*
     '*'?????£??\??????????????´????????????????????????????????????????????????????????????????????????????????????
     ????????§??¨???????????¨??????'*'????????????????????¨?????????
     */
    if( fin ) return; 

  }

  if( depth == 0 )  dfs(sp+1,bitmask,-1,step,0);  
} 

int compute(){
  mini = h*w-s_size - blocks;
  dfs(0,0,-1,0,0);
  return mini;
}



int main(){
  rep(i,(1<<9)) bc[i] = __builtin_popcount(i);
  while( scanf(" %d %d",&h,&w), h|w ){
    s_size = c_size = 0;
    blocks = 0;
    rep(i,h) rep(j,w) {
      scanf(" %c",&c[i][j]);
      if( c[i][j] == 'P' ) { source[s_size] = path[s_size] = (Point){j,i}; s_size++; }
      if( c[i][j] == '*' ) { city[c_size]   = (Point){j,i}; bitIndex[i][j] = c_size++; }
      if( c[i][j] == '#' ) ++blocks;
    }
    printf("%d\n",compute());
    //print_field(); puts("");
  }
  return 0;
}

Measured memory_bytes: 1192
n = gets.to_i
strings = []
n.times { strings << gets.chars.sort.join }
hash = Hash.new { |h, k| h[k] = 0 }
ans = 0

strings.each { |str| hash[str] += 1 }

hash.each do |k, v|
  ans += (v-1..v).inject(:*) / 2 if v > 1
end

p ans


Measured memory_bytes: 31996
#include<iostream>
using namespace std;
int main(){
  long long marchc[5]={0},n;
  long long int ans=0;
  char name[11];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> name;
    switch(name[0]){
      case 'M': marchc[0]++; break;
      case 'A': marchc[1]++; break;
      case 'R': marchc[2]++; break;
      case 'C': marchc[3]++; break;
      case 'H': marchc[4]++; break;
      default : break;
    }
  }
  for(int i=0;i<=2;i++){
    for(int j=i+1;j<=3;j++){
      for(int k=j+1;k<=4;k++){
        ans += marchc[i]*marchc[j]*marchc[k];
      }
    }
  }
  cout << ans<<endl;
}


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

struct sushi
{
	int t;
	int d;
};

int main(){
	int n, k;
	long long ans= 0;

	std::vector<sushi> list;
	std::vector<int> dupList;
	std::vector<bool> isDup(100001, false);

	std::cin>>n>>k;
	list.resize(n);

	for(int i=0; i<n; i++)
		std::cin>>list[i].t>>list[i].d;

	std::stable_sort(list.begin(), list.end(), [](const sushi& x, const sushi& y){return x.t> y.t;});
	std::stable_sort(list.begin(), list.end(), [](const sushi& x, const sushi& y){return x.d> y.d;});

	long long sum=0;

	for(int i=0; i<k; i++){
		sum+= list[i].d;

		if(!isDup[list[i].t])
			isDup[list[i].t]=true;
		else
			dupList.push_back(list[i].d);
	}

	long long numT=0;

	for(int i=0; i<100001; i++)
		if(isDup[i])
			numT++;

	long long score= numT* numT + sum;

	int duplen= dupList.size();
	int dupNo= 0;

	long long score_=0;

	for(int i=k; i<n; i++){

		if(dupNo>= duplen)
			break;

		if(!isDup[list[i].t]){
				score_ = std::max(score_, (numT+1)*(numT+1) + sum - dupList[duplen-1-dupNo] + list[i].d);
				numT++;
				sum= sum - dupList[duplen-1-dupNo] + list[i].d;
				dupNo++;
				isDup[list[i].t]= true;
			
		}
	}


	std::cout<< std::max(score, score_)<<std::endl;

	return 0;
}

Measured memory_bytes: 1436
from collections import deque


K = int(input())

que = deque(["1","2","3","4","5","6","7","8","9"])
cnt = 0
while cnt < K:
    q = que.popleft()
    a = int(q[-1])
    q = int(q)
    cnt += 1 
    if a == 0:
        que.append(str(q*10+a))
        que.append(str(q*10+a+1))
    elif a == 9:
        que.append(str(q*10+a-1))
        que.append(str(q*10+a))
    else:
        que.append(str(q*10+a-1))
        que.append(str(q*10+a))
        que.append(str(q*10+a+1))
    ans = q

print(ans)

Measured memory_bytes: 70364
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
N = ri()
a = [ri()-1 for _ in range(N)]
f = [0] * N
ch = 0
cnt = 0
while 1:
    if f[ch]:
        cnt = -1
        break
    else:
        f[ch] = 1
        cnt += 1
        ch = a[ch]
        if ch == 1:
            break
print(cnt)


Measured memory_bytes: 70104
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=a%b,e=0;
    for(int i=1;i<=100;i++){
      if((d*i)%b==c){
        System.out.println("YES");
        e++;
        break;
      }
    }
    if(e==0){
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;


int main(){
    int a,b;
    char c;
    int ans;
    
    cin >> a;
    cin >> c;
    cin >> b;
    
    if(c == '+'){
        ans = a + b;
    } else if(c == '-'){
        ans = a - b;
    }
    
    cout << ans << endl;
    
     return 0;
}


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

struct Card
{
	char suit, value;
};

void Bubble(struct Card A[], int N) {
	for (int i = 0; i < N;i++) {
		for (int j = N - 1; j >= i + 1;j--) {
			if (A[j].value < A[j - 1].value) {
				Card T = A[j]; A[j] = A[j - 1];A[j - 1] = T;
			}
		}
	}
}

void Selection(struct Card A[], int N) {
	for (int i = 0;i < N;i++) {
		int minj = i;
		for (int j = i;j < N;j++) {
			if (A[j].value < A[minj].value) {
				minj = j;
			}
		}
		Card t = A[i];A[i] = A[minj];A[minj] = t;
	}
}

void print(struct Card A[],int N) {
	for (int i = 0;i < N;i++) {
		if (i > 0) cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

bool isstable(struct Card C1[], struct Card C2[], int N) {
	for (int i = 0;i < N;i++) {
		if (C1[i].suit != C2[i].suit) return  false;
	}
	return  true;
}

int main() {
	Card c1[100], c2[100];
	int N;
	char ch;

	cin >> N;
	for (int i = 0; i < N;i++) {
		cin >> c1[i].suit >> c1[i].value;
	}

	for (int i = 0; i < N;i++) {
		c2[i] = c1[i];
	}

	Bubble(c1, N);
	Selection(c2, N);

	print(c1, N);
	cout << "Stable" << endl;
	print(c2, N);
	if (isstable(c1, c2, N)) {
		cout << "Stable" << endl;
	}else {
		cout << "Not stable" << endl;
	}

	return 0;

}


Measured memory_bytes: 3084
#include<stdio.h>
int main(void)
{
	int i,n,k,p,a[1000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&k,&p);
		if(k%p==0) a[i]=p;
		else a[i]=k%p;
	}
	for(i=0;i<n;i++) printf("%d\n",a[i]);
	return 0;
}


Measured memory_bytes: 2744
import math
N, K = map(int, input().split())
possibility = 0

for i in range(N):
    coin_num = math.log(K/(i+1)) / math.log(2)
    if K > (i+1) :
        if int(coin_num) == coin_num:
            pass
        else:
            coin_num = int(coin_num) + 1
        possibility += (1/N) * ((1/2) ** int(coin_num))
    else:
        possibility += (1/N)

print(possibility)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define WM 1e5
using namespace std;

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

    map<int, long long> cnt;
    map<int, long long> comb;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    
    long long total = 0;
    for (auto x : cnt) {
        comb[x.first] = cnt[x.first] * (cnt[x.first] - 1) / 2;
        total += comb[x.first];
    }
    
    for (int i = 0; i < N; i++) {
        cout << total - (cnt[a[i]] - 1) << endl;
    }

}

Measured memory_bytes: 18176
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n,p[53];
	int cnt = 0;
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i){
		scanf("%d",&p[i]);
		if(p[i] != i) ++cnt;
	}
	if(cnt == 1 || cnt >= 3)  puts("NO");
	else puts("YES");
	return 0;
}


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

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

    int cnt = 0;
    for(int i = 1; i <= N; i++){
        cnt = 0;
        for(int x = 1; x <= sqrt(i); x++){
            for(int y = x; y <= sqrt(i); y++){
                for(int z = y; z <= sqrt(i); z++){
                    if (x*x + y*y + z*z + x*y + y*z + z*x == i){
                        if ((x == y) && (y == z)){
                            cnt += 1;
                        }else if ((x != y) && (y != z) && (z != x)){
                            cnt += 6;
                        }else{
                            cnt += 3;
                        }
                    }
                }
            }
        }
        printf("%d\n", cnt);
        // cout << cnt << endl;
    }


    return 0;
}

Measured memory_bytes: 3580