akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

typedef long long int64;

int gcd(int64 a,int64 b){return b?gcd(b,a%b):a;}
int64 lcm(int64 a, int64 b) { return a/gcd(a,b)*b;}

int64 f(int64 n) {
    int64 res = 0;
    while(n%2==0) n/=2,res++;
    return res;
}

int main() {
    int64 n,m;
    int64 ans = 1;
    cin >> n >> m;
    vector<int64> a(n);
    for (int64 i=0; i<n; i++) cin >> a[i];


    int64 t = f(a[0]);
    for (int64 i=0; i<n; i++) {
        if (t != f(a[i])) {
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;
    }
    m >>= (t-1);


    int64 LCM = 1;
    for (int64 i=0; i<n; i++) {
        LCM = LCM/gcd(LCM,a[i])*a[i];
        if (LCM > m) {
            cout << 0 << endl;
            return 0;
        }
    }

    if (ans && LCM != 0) {
        m /= LCM;
        ans = (m+1) / 2;
    }


    cout << ans << endl;
}

Measured memory_bytes: 1024
def getMaxindex(lis, val):
        lis.reverse()
        return len(lis) - 1 - lis.index(val)
#input
d, g = map(int, input().split())
p, c =[], []
ans = []
for i in range(d):
    tmp1, tmp2 = map(int, input().split())
    p.append(tmp1)
    c.append(tmp2)
    
#bit全探索
oplist, op = [], []
for i in range(2**d):
    op = [True] * d
    for j in range(d):
        if (i >> j) & 1:
            op[d - 1 - j] = False
    oplist.append(op)

for i in range(2**d):
    cnt, tmp = 0, 0
    for j in range(d):
        if oplist[i][j]:
            tmp += 100*(j+1)*p[j]+c[j]
            cnt += p[j]
    if tmp < g:
        hnp = getMaxindex(oplist[i], False)
        for k in range(p[hnp]):
            cnt += 1
            tmp += 100*(hnp+1)
            if tmp >= g:
                ans.append(cnt)
                break
    else:
        ans.append(cnt)
print(min(ans))


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>                                                                              
using namespace std;
typedef long long ll;

ll N, W;
ll w[101];
ll v[101];
// dp[i][j][k]
// i番目までからj個を選び重さj*w1+k以下の最大の価値
ll dp[101][101][301];

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

    cin >> N >> W;
    ll w1 = 0;
    for(int i = 0; i < N; ++i){
        cin >> w[i] >> v[i];
        if(i == 0){
            w1 = w[0];
            w[0] = 0;
        }
        else {
            w[i] -= w1;
        }
       // cout << w[i] << endl;
    }

    ll ans = 0;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j <= N; ++j){
            for(int k = 0; k <= 300 && j * w1 + k <= W; ++k){
                if(j == 0 || k < w[i]){
                    dp[i + 1][j][k] = dp[i][j][k];
                }
                else {
                    dp[i + 1][j][k] = max(dp[i][j][k], dp[i][j - 1][k - w[i]] + v[i]);
                }
                ans = max(ans, dp[i + 1][j][k]);
                //cout << dp[i][j][k] << " " << i << j << k << endl;
            }
        }
    }/*
    for(int i = 0; i < N; ++i){
        //cout << dp[N][i][300] << endl;
        ans = max(ans, dp[N][i][300]);
    }*/
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 24064
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;
int main()
{
    long long n, ans = LLONG_MAX;
    cin >> n;
    for(long long i = 1; i*i <= n; i++){
        if(n % i == 0){
            ans = min(ans, (i - 1) + (n/i - 1));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> f;
void solve(int n){
	cout<<n<<":";
	int i=0;
	for(i=2;i*i<=n;i++)
		while(n%i==0)f.push_back(i),n/=i;
	if(n!=1)f.push_back(n);
	for(int i=0;i<f.size();i++){
		cout<<" "<<f[i];
	}cout<<endl;
}
int main(){
	int n;cin>>n;
	solve(n);
	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
/* map_for : mapでfor文を回す */
/* gcd_lcm : 最大公倍数 & 最小公約数 */
int main()
{
    cout << fixed << setprecision(10);//小数点以下10桁出力
    int n,m;
    cin >> n >> m;
    vector<double> a(n);
    double sum = 0;
    rep(i,n){
        int in;
        cin >> in;
        a.at(i) = in;
        sum += in;
    }

    double val = sum * (1.0 / (4.0 * m));
    //cout << sum << endl;
    //cout << val << endl;
    int cnt = 0;
    rep(i,n){
        if(val <= a.at(i)){
            cnt++;
        }
    }
    //cout << cnt << endl;
    if(cnt >= m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 998244353;
 
////////////////////////////////////////////////////////////////////

const int N = 3e3 + 5;

int A[N], DP[N][N];

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	int n, s; cin >> n >> s;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> A[i];
		DP[i][A[i]] = i;
		for (int j = A[i]; j <= s; j++) DP[i][j] = (DP[i][j] + DP[i - 1][j - A[i]]) % MOD;
		ans = (ans + 1LL * DP[i][s] * (n - i + 1) % MOD) % MOD;
		for (int j = 1; j <= s; j++) DP[i][j] = (DP[i][j] + DP[i - 1][j]) % MOD;
	}
	cout << ans << endl;

	return 0;
}


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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main() {
    int n;
    cin >> n;
    vi a(n);
    int sum = 0;
    
    rep(i,n){
        cin >> a[i];
        sum = mod(sum + a[i]);
    }
    
    int ans = 0;
    for(int e : a){
        sum = mod(sum - e);
        ans = mod(ans + mod(e * sum));
    }
    
    cout << ans % MOD << endl;
}

Measured memory_bytes: 4816
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

// Union-Find木
// 初期化 UF(N); Nは要素数
// 結合 unite(x,y); 同じ集合か判定 same(x,y);
// 集合の数 count
struct UnionFind {
  vector<ll> par, sizes;
  ll cnt;
  UnionFind(ll N) : par(N), sizes(N, 1), cnt(N) {
    for (ll i = 0; i < N; i++) par[i] = i;
  }

  ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }

  bool same(ll x, ll y) { return find(x) == find(y); }

  ll size(ll x) { return sizes[find(x)]; }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
    cnt--;
  }

  ll count() const { return cnt; }
};

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

  UnionFind uf(n);

  rep(i, q) {
    ll t, x, y;
    cin >> t >> x >> y;
    if (t == 0)
      uf.unite(x, y);
    else
      cout << (uf.same(x, y) ? 1 : 0) << endl;
  }

  return 0;
}



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

int main() {
  int N;  
  cin >> N;
  vector<int> data(N);
  
  for (int i=0; i<N; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(),data.end(),greater<int>());
  
  int ans = 0;
  int tmp = data.at(0)+1;
  for (int i=0; i<N; i++) {
    if (data.at(i)==tmp) {
      continue;
    }
    else {
      tmp = data.at(i);
      ans++;
    }
  }
   cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=6;
static const int D=365;
static const int ntype=26;
static int ans[D+1];
static int max_score=-INF;
static int t=110000;
class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int evaluate(){
    int sum=0;
    vector<int> l(ntype+1,0);
    for(int day=1;day<=D;++day){
        int type=ans[day];
        sum+=contest[type].s[day];
        l[type]=day;
        for(int t=1;t<=ntype;++t){
            sum-=contest[t].c*(day-l[t]);
        }
    }
    return sum;   
}

void Output(){
    for(int d=1;d<=D;++d) cout<<ans[d]<<endl;
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void Greedy(){
    vector<int> l(ntype+1,0);
    int score=0;
    for(int d=1;d<=D;++d){
        for(int i=1;i<=ntype;++i) score-=contest[i].c*(d-l[i]);
        int temp=score;
        int t=-1;
        for(int i=1;i<=ntype;++i){
            int k=contest[i].s[d]+contest[i].c*(d-l[i])+score;
            if(k>temp){
                temp=k;
                t=i;
            }
        }
        ans[d]=t;
        l[t]=d;
    }
}

void change(){
    int p=rand()%D+1;
    int temp=ans[p];
    ans[p]=rand()%ntype+1;
    int temp_score=evaluate();
    if(max_score<temp_score) max_score=temp_score;
    else ans[p]=temp;
}

void swap(){
    int p1=rand()%D+1;
    int p2=rand()%D+1;
    while(p1==p2) p2=rand()%D+1;
    int temp=ans[p1];
    ans[p1]=ans[p2];
    ans[p2]=temp;
    int temp_score=evaluate();
    if(max_score<temp_score) max_score=temp_score;
    else{
        ans[p2]=ans[p1];
        ans[p1]=temp;
    }
}

void solve(int times){
    max_score=evaluate();
    for(int i=0;i<times;++i){
        swap();
        change();
    }
}

int main(){
    srand(seed);
    Input();
    Greedy();
    solve(t);
    Output();
}


Measured memory_bytes: 3496
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define M (L+R)/2
#define N 500009
#define inf 99999999999
#define ll long long
#define mod 1000000007
using namespace std;
ll h,w,n,ans;
int main(){

	ios::sync_with_stdio(0);
	
	cin>>h>>w>>n;
	h=max(h,w);
	ans=n/h;
	if(n%h!=0)ans++;
	cout<<ans<<endl;

	return 0;
}



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

typedef long long ll;
#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define int ll

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;

bool check(string s) {
	int n = 0;
	for (auto x : s) n += (x - '0');
	return n % 9 == 0;
}

void solve() {
	string s;
	cin >> s;

	if (check(s)) cout << "Yes";
	else cout << "No";
}

int32_t main() {
	_

#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
	solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}


Measured memory_bytes: 3920
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n;
    string str;
    cin >> n >> str;
    if(n % 2 != 0){
        cout << "No" << endl;
    } else {
        string t1 = str.substr(0, n/2);
        string t2 = str.substr(n/2, n/2);
        if(t1 == t2){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    N=int(input())
    M=N%10
    hon="hon"
    if M==3:
        hon="bon"
    if M==0 or M==1 or M==6 or M==8:
        hon="pon"
    
    print(hon)

    

        


if __name__ == '__main__':
    main()

Measured memory_bytes: 9180
import java.util.*;

public class Main {	
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new AOJ0085();
	}
	
	class AOJ0085{
		public AOJ0085(){
			Scanner in = new Scanner(System.in);
			while (in.hasNext()) {
				int n = in.nextInt();
				int kankaku = in.nextInt();
				if(n+kankaku==0)break;
				ArrayList<Integer> list = new ArrayList<Integer>();
				for(int i=0;i<n;i++)list.add(i);//1~nまでいれる.
				
				int now = n;
				while(list.size()!=1){
//					System.out.println(now+kankaku);
					now=(now+kankaku-1)%list.size();
					list.remove(now);
//					System.out.println(list.remove(now));
				}
				System.out.println(list.get(0)+1);
			}
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	class  AOJ0155{
		int d[];
		int n;
		int x[];
		int y[];
		int ban[];
		boolean sw;
		ArrayList<Integer> result;
		int back[];
		int[][] cost;
		void dijkstra(int s,int g){
			d = new int[n+1];d[s]=0;
			Arrays.fill(d,100000);
			boolean used[] = new boolean[n+1];
			int sumn[] = new int[n+1];
			int v=s;
			int save = -1;
			back = new int[n+1];
			while(true){
				save = v;
				v=-1;
				for(int u=1;u<n+1;u++)if(!used[u]&&(v==-1||(d[u]<d[v]))){
					v=u;
				}
				if(v==-1)break;
				else back[v]=save;
				used[v]=true;
				for(int u=1;u<n+1;u++)d[u]=Math.min(cost[u][v]+d[v],d[u]);
			}
			for(int i=1;i<d.length;i++){
				System.out.println(i+" "+d[i]);
			}
			int now=g;
			result = new ArrayList<Integer>();
			int a=0;
//			for(int i=0;i<back.length;i++){
//				System.out.println(i+" "+back[i]);
//			}
			while(true){
				if(cost[a][now]==1000000)sw = true;
				result.add(now);
				if(now==s)break;
				a = now;
				now=back[now];
			}
			return;
		}
		public AOJ0155(){
			Scanner in = new Scanner(System.in);
			while(true){
				n = in.nextInt();
				if(n==0)break;
				cost = new int[n+1][n+1];
				ban = new int[n+1];
				x = new int[n+1];
				y = new int[n+1];
				for(int i=1;i<n+1;i++){
					ban[i] = in.nextInt();
					x[ban[i]] = in.nextInt();
					y[ban[i]] = in.nextInt();
				}
				for(int i=1;i<n+1;i++){
					for(int s=i+1;s<n+1;s++){
						int x1 = x[i],y1= y[i],x2=x[s],y2=y[s];
						int costs = (int)Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));		
						cost[i][s] = costs > 50 ? 1000000:costs;
						cost[s][i] = cost[i][s];
					}
				}
				int kai = in.nextInt();
				for(int i=0;i<kai;i++){
					int s = in.nextInt();
					int g = in.nextInt();
					dijkstra(s, g);
//					if(sw){
//						System.out.println("NA");
//						break;
//					}
					for(int a=result.size()-1;a>=0;a--){
						System.out.print(result.get(a)+" ");
					}
					System.out.println();
				}
			}
		}
	}
}

Measured memory_bytes: 17276
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    ta = tb = 1
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        r = max((a + ta - 1) // a, (b + tb - 1) // b)
        ta = a * r
        tb = b * r
    print(ta + tb)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38768
from bisect import bisect_left,bisect_right
n,d,a=map(int,input().split())
xh=[list(map(int,input().split()))for _ in range(n)]
xh.sort()
x=[]
h=[]
for xx,hh in xh:
  x.append(xx)
  h.append(hh)
imos=[0]*(n+1)
mi=0
ans=0
for i in range(n):
  mi-=imos[i]
  h[i]=max(h[i]-mi*a,0)
  atk=0--h[i]//a
  ans+=atk
  mi+=atk
  point=x[i]+d*2
  index=bisect_right(x,point)
  imos[index]+=atk
print(ans)

Measured memory_bytes: 103896
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	vector<int> a(N);
	float sum=0;
	for(int i=0;i<N;i++){
		cin>>a[i];
		sum=sum+a[i];
	}
	int sum1=0;
	float k=sum/N;
	float p=floor(k)+0.5;
	int P;
	if(k>p){
		P=floor(k)+1;
	}
	else{
		P=floor(k);
	}
	
	for(int i=0;i<N;i++){
		sum1=sum1+(a[i]-P)*(a[i]-P);
	}
	cout<<sum1<<endl;
	return 0;
}

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

int main() {
    int K, N;

    cin >> K >> N;
    int A[N];
    for(int i = 0; i< N ; ++i) {
        cin >> A[i];
    }
    vector<int> D(N, 0);
    for(int i = 0; i < N - 1; ++i) {
        D[i] = A[i+1] - A[i];
    }

    D[N -1] = K - A[N - 1] + A[0];

    std::vector<int>::iterator iter = std::max_element(D.begin(), D.end());
    size_t index = std::distance(D.begin(), iter);

    cout << std::accumulate(D.begin(), D.end(), 0) - D[index] << endl;

    return 0;
}

Measured memory_bytes: 1792
n = int(input())
d = {}
for i in range(n):
    a,b = input().split()
    if a in d:
        d[a].append([int(b),i+1])
    else:
        d.setdefault(a,[[int(b),i+1]])
for k in sorted(d.keys()):
    d[k].sort(reverse=True)
    for i in d[k]:
        print(i[1])

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

vector<vector<ll>> divide(vector<ll> &A, int left, int right) {
  int low = left, high = right;
  while (low + 1 < high) {
    int mid = (low + high) / 2;
    if (A[mid] - A[left - 1] <= A[right] - A[mid]) {
      low = mid;
    } else {
      high = mid;
    }
  }
  vector<vector<ll>> ret;
  ret.push_back({A[low] - A[left - 1], A[right] - A[low]});
  if (high < right) {
    ret.push_back({A[high] - A[left - 1], A[right] - A[high]});
  }
  return ret;
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  vector<ll> A(N + 1, 0);
  REP(i, N) {
    cin >> A[i + 1];
    A[i + 1] += A[i];
  }
  ll ans = A[N];
  FOR(r_start, 3, N) {
    vector<vector<ll>> left = divide(A, 1, r_start - 1), right = divide(A, r_start, N);
    for (vector<ll> l : left) {
      for (vector<ll> r : right) {
        vector<ll> s = {l[0], l[1], r[0], r[1]};
        /*
        cout << r_start << ':';
        for (ll x : s) cout << x << ' ';
        cout << endl;
        */
        ans = min(ans, *max_element(ALL(s)) - *min_element(ALL(s)));
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
    long long n,m;
    cin >> n >> m;
    vector<vector<long long>> adj(n);
    ll h[n];
    for (ll i = 0; i < n; i++) cin >> h[i];
    for (ll i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        if (adj[i].size() == 0) {
            ans++;
            continue;
        }
        ll maxi = 0;
        for (auto j:adj[i]) {
            maxi = max(maxi, h[j]);
        }
            if (h[i] > maxi) ans++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 9860
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    LL k,a,b;cin >> k >> a >> b;
    if(k <= a){
        puts("1");
    }
    else if(a <= b){
        puts("-1");
    }
    else{
        k -= a;
        LL t = a - b;
        cout << (k + t - 1) / t * 2 + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<string>
#include<time.h>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;

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

int main() {
    int n,m;
    cin >> n >> m;
    vector<pair<ll, ll>> r;
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        r.push_back(pair<ll, ll>(a, b));
    }
    sort(r.begin(), r.end()
        , [](const pair<ll, ll>& v1, const pair<ll, ll>& v2) {
            if (v1.first == v2.first) return v2.second > v2.second;
            else return v1.first < v2.first;
        }
    );
    int ret = 0;
    ll cur = -999999999999;
    rep(i, m) {
        if (r[i].first >= cur) {
            ret++;
            cur = r[i].second;
        }
        else cur = min(cur, r[i].second);
    }
    cout << ret << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

vector<ll> fac(1e6), finv(1e6), inv(1e6);
ll mod = 998244353;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    
    for (int i = 2; i < 1e6; i++) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = (mod - inv[mod%i]*(mod/i)%mod)%mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(ll n, ll k) {
    if (n < k || k < 0)
        return 0;
    
    return fac[n]*finv[k]%mod*finv[n-k]%mod;
}

ll mod_pow(ll a, ll x, ll mod) {
    if (x == 0)
        return 1;
    
    else if (x % 2) {
        return a * mod_pow(a, x-1, mod) % mod;
    }
    else {
        ll tmp = mod_pow(a, x/2, mod);
        return tmp * tmp % mod;
    }
}

int main() {
    ll n, m, k; cin >> n >> m >> k;
    ll ans = 0;

    COMinit();
    
    for (int i = 0; i <= k; i++) {
        ans += m * mod_pow(m-1, n-i-1, mod) % mod * COM(n-1, i) % mod;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;

}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int input() {int a;cin>>a;return a;}

int n,v[20],c[20],ans;

signed main() {
    cin >> n;
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    rep(i,n) ans += max(0LL, v[i]-c[i]);
    cout << ans << endl;
}




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

using namespace std;
#define MAX_CARDS_NUM 100000

static uint32_t cards[MAX_CARDS_NUM + 1];

int32_t main()
{
  uint32_t N;
  cin >> N;

  for (uint32_t i = 0; i < N; i++) {
    uint32_t num;
    cin >> num;
    cards[num]++;
    if (cards[num] == 3) {
      cards[num] = 1;
    }
  }

  uint32_t double_num = 0;
  uint32_t different_num = 0;
  for (uint32_t i = 1; i <= MAX_CARDS_NUM; i++) {
    if (cards[i] > 0) {
      different_num++;
    }

    if (cards[i] == 2) {
      double_num++;
    }
  }

  if (double_num == 0) {
    cout << different_num << endl;
  } else {
    if (double_num % 2 == 0) {
      cout << different_num << endl;
    } else {
      cout << different_num - 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int N, D;
        void solve(InputReader in, PrintWriter out) {
            N = in.nextInt();
            D = in.nextInt();

            out.println((int)Math.ceil((double)N / (2*D + 1)));
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}

Measured memory_bytes: 23508
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {

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

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();

      int[] seqA = new int[n/2];
      int[] seqB = new int[n/2];

      Integer num;
      List<Integer> listA = new ArrayList<>();
      List<Integer> listB = new ArrayList<>();
      Map<Integer,Integer> mapA = new HashMap<>();
      Map<Integer,Integer> mapB = new HashMap<>();
      int offset=0,next=0;
      char regx = ' ';
      for(int i=0, j=0; i<n; i++, j= i >> 1) {
        if((next = line.indexOf(regx,offset)) == -1)
          next = line.length();
        num = new Integer(line.substring(offset, next));
        offset = ++next;

        if((i & 1) == 0) {
          seqA[j] = num;
          if(mapA.containsKey(num)) {
            mapA.replace(num, mapA.get(num) + 1);
          } else {
            mapA.put(num, 1);
            listA.add(num);
          }
        }
        else {
          seqB[j] = num;
          if(mapB.containsKey(num)) {
            mapB.replace(num, mapB.get(num) + 1);
          } else {
            mapB.put(num, 1);
            listB.add(num);
          }
        }
      }

      int vma,vmb,xa,xb;
      vma = vmb = xa = xb =0;
      for (Integer var : listA) {
        int ma = mapA.get(var);
        if(vma < ma) {
          vma = ma;
          xa = var;
        }
      }
      for (Integer var : listB) {
        int mb = mapB.get(var);
        if(vmb < mb) {
          vmb = mb;
          xb = var;
        }
      }

      int cca,ccb;
      cca = ccb = 0;
      for (int i : seqA) {
        if(i != xa) cca++;
      }
      for (int i : seqB) {
        if(i != xb) ccb++;
      }

      int vma2,vmb2,xa2,xb2;
      vma2 = vmb2= xa2 = xb2 =0;
      int cca2,ccb2;
      cca2 = ccb2 = 0;
      int ans = 0;
      if(xa == xb) {
        for (Integer var : listA) {
          int ma = mapA.get(var);
          if(var != xa && vma2 < ma) {
            vma2 = ma;
            xa2 = var;
          }
        }
        for (Integer var : listB) {
          int mb = mapB.get(var);
          if(var != xb && vmb2 < mb) {
            vmb2 = mb;
            xb2 = var;
          }
        }
      
        for (int i : seqA) {
          if(i != xa2) cca2++;
        }
        for (int i : seqB) {
          if(i != xb2) ccb2++;
        }

        ans = cca2 > ccb2 ? cca + ccb2 : cca2 + ccb;
      }
      else {
        ans = cca + ccb;
      }

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


int main() {
    cout<<fixed<<setprecision(10);

    string s,t; cin>>s>>t;

    ll ans = LLONG_MAX;

    rep(i,s.size()){
        ll tmp = 0;

        rep(j,t.size()){
            if(i+j >= s.size()){
                tmp = LLONG_MAX;
                break;
            }
            if(s[i+j] != t[j]) tmp++;
        }
        chmin(ans, tmp);
    }
    cout<<ans<<endl;


    return 0;

}

Measured memory_bytes: 3628
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define MAXN 100010

typedef long long ll;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> shops(N);
    ll a, b;
    for (ll i = 0; i < N; i++) {
        cin >> a >> b;
        shops.push_back({a, b});
    }
    sort(shops.begin(), shops.end());
    ll ans = 0;
    for (auto shop : shops) {
        if (M - shop.second > 0) {
            ans += shop.second * shop.first;
            M -= shop.second;
        } else {
            ans += M * shop.first;
            break;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <bitset>
#include <functional>
#include <tuple>
#include <complex>
#include <chrono>
#include <climits>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef unsigned int uint;
typedef unsigned long long ull;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
// default_random_engine generator;
// mt19937 rnd(1);

const int MAXN = 1111;

int n, m;
string b[MAXN];
int d[MAXN][MAXN];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

bool onBoard(int x, int y) {
    return 0 <= x && x < n && 0 <= y && y < m;
}

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

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

    cin >> n >> m;

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

    queue<pii> q;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (b[i][j] == '#') {
                q.push({i, j});
                d[i][j] = 0;
            } else {
                d[i][j] = n + m;
            }
        }
    }

    int res = 0;

    while (sz(q) > 0) {
        pii p = q.front();
        int x = p.first;
        int y = p.second;
        q.pop();

        for (int k = 0; k < 4; ++k) {
            int xx = x + dx[k];
            int yy = y + dy[k];
            if (onBoard(xx, yy)) {
                if (d[xx][yy] > d[x][y] + 1) {
                    d[xx][yy] = d[x][y] + 1;
                    q.push({xx, yy});
                    res = max(res, d[xx][yy]);
                }
            }
        }
    }

    cout << res << endl;


}  


Measured memory_bytes: 13840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
 
//隣り合う二つを決めると残りが決まる
//mod2で考えたりxorをとる
 
int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    rep(i,2) {
        rep(j,2) {
            vector<int> res;
            res.push_back(i);res.push_back(j);
            rep(k,N){
                if(s[k] == 'o') res.push_back(res[k] ^ res[k+1]);
                else res.push_back(res[k] ^ res[k+1] ^ 1);
            }
            if(res[N] == i && res[N+1] == j) {
                for(int l = 1; l <= N; l++){
                    cout << (res[l] ? 'W' : 'S');
                }
                cout << endl;
                return 0;
            }
        }
    }
    puts("-1");
    return 0;
}

Measured memory_bytes: 1392
#include <stdio.h>

int main()
{
    int N;
    scanf("%d", &N);
    if(N%10 == 2 || N%10 == 4 || N%10 == 5 || N%10 == 7 || N%10 == 9){
        printf("hon");
    }
    else if(N%10 == 0 ||N%10 == 1 ||N%10 == 6 ||N%10 == 8){
        printf("pon");
    }
    else{
        printf("bon");
    }

     return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<cstring>

using namespace std;

const int MAX_w = 1000;
const int MAX_v = 1000;

int dp[MAX_w + 1][MAX_v + 1];


int n, wet ;
int w[MAX_w], v[MAX_v];

// i番目以降の品物から重さの和がj以下なるように選んだときの、
// 取りうる価値の総和の最大値を返す関数
int rec(int i, int j) {
  int res;
  if(dp[i][j] != -1){
  	
	return dp[i][j];
  }

  if (i == n) {
    // 品物がもう残っていないときは、価値の和の最大値は0で確定
    res = 0;
  } else if (j < w[i]) {
    // 残りの容量が足りず品物iを入れられないので、入れないパターンだけ処理
    // i+1 以降の品物のみを使ったときの最大値をそのままこの場合の最大値にする
    res = rec(i + 1, j);
  } else {
    // 品物iを入れるか入れないか選べるので、両方試して価値の和が大きい方を選ぶ
    res = max(
        rec(i + 1, j),
        rec(i + 1, j - w[i]) + v[i]
    );
  }

  return dp[i][j] = res;
}

void solve(int ca) {
  // 0番目以降で容量W以下の場合の結果を表示する
  int wmin;
  
  memset(dp, -1, sizeof(dp));
  
  cout << "Case" << " " << ca << ":" <<endl; 
  
  int ans =  rec(0, wet) ;
  cout << ans << endl;
  
  for (int w = wet -1 ; w>=0 ; w--){
  	if( ans != rec(0,w)){
		 wmin = w+1;
		 break;
  	}
  }
  
  cout << wmin << endl;  
  
}


int main(){
	
	char x;
	int ca = 0;
	
	while(1){
			
		ca++;
		cin >> wet;
		if(wet == 0 ) break;
		cin >> n;
		
		for(int i = 0 ;  i<n ; i++){
			
			cin >> v[i] >> x >> w[i];
		}
		
		
		 solve(ca);
		
	}
	
	return 0;
	
} 

Measured memory_bytes: 4816
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
 
	ans = 0
	for i in range(1, N+1):
		tmp = str(i)
		tmp = len(tmp)
		if tmp % 2 == 1:
			ans += 1
 
	print(ans)


if __name__ == "__main__":
	main()


Measured memory_bytes: 39280
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  int cursor = 0;
  int vec = 0;
  int counter = 1;
  while(cursor < N){
    int nextvec = 0;
    if(cursor == 0) nextvec = 0;
    else if(A.at(cursor) > A.at(cursor - 1)) nextvec = 1;
    else if(A.at(cursor) == A.at(cursor - 1)) nextvec = 0;
    else nextvec = -1;

    if(vec == 0) vec = nextvec;
    else if(vec == 1 && nextvec == -1){
      counter++;
      vec = 0;
    }
    else if(vec == -1 && nextvec == 1){
      counter++;
      vec = 0;
    }
    cursor++;
  }
  cout << counter << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9

vector<vector<ll> > levenshtein(string s1,string s2){
	ll n1 = s1.size(),n2 = s2.size();
	vector<vector<ll> > dp(n1+1,vector<ll>(n2+1,0) );
	for(ll i=1;i<=n1;i++) dp[i][0] = i;
	for(ll i=1;i<=n2;i++) dp[0][i] = i;
	for(ll i=1;i<=n1;i++){
		for(ll j=1;j<=n2;j++){
			dp[i][j] = min(dp[i][j-1]+1,dp[i-1][j]+1);
			ll cost = 1;
			if(s1[i-1]==s2[j-1]) cost = 0;
			dp[i][j] = min(dp[i][j],dp[i-1][j-1]+cost);
		}
	}
	return dp;
}	

int main(){
	string s1,s2;
	cin>>s1>>s2;
	vector<vector<ll> > dp = levenshtein(s1,s2);
	cout<<dp[s1.size()][s2.size()]<<endl;

	return 0;
}



Measured memory_bytes: 10872
from math import atan


def find_angle(width, height, vol):
    area = vol/width
    if area > 1/2 * width * height:
        return atan(2*(width * height - area)/(width**2))
    else:
        return atan(height**2/(2*area))


a, b, x = [int(i) for i in input().split()]
print(find_angle(a, b, x) / (2*3.1415926535) * 360)


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  string s;
  vector<int> freqs(128, 0);
  char buf[64] = { '\0' };
  for (int i = 0; i < N; ++i) {
    scanf("%s", buf);
    ++freqs[buf[0]];
  }
  vector<int> cands = { 'M', 'A', 'R', 'C', 'H' };
  ll ans = 0;
  for (int i = 0; i < 5; ++i) {
    for (int j = i + 1; j < 5; ++j) {
      for (int k = j + 1; k < 5; ++k) {
        ans += 1LL * freqs[cands[i]] * freqs[cands[j]] * freqs[cands[k]];
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

bool isku(vector<string> w,int s){
    int cor[]={5,7,5,7,7};
    int st = s;
    vector<int> m;
    rep(i,5){
        int t = cor[i];
        int sum = 0;
        for(int o = st;;o++ ){
            sum+=w[o].size();
            if(sum == t){
                st = o+1;
                break;
            }
            else if(sum > t)return false;
        }
    }
    return true;
}

int main(){
    int n;
    cin >>n;
    while(n){
        vector<string> w(n,"");
        rep(i,n)cin >> w[i];
        rep(i,n){
            if(isku(w,i)){
                cout<<i+1<<endl;
                break;
            }
        }
        cin>>n;
    }
    return 0;
}


Measured memory_bytes: 3160
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() { 
		while(true){
			String str[]=sc.nextLine().split(" ");
			if(Integer.valueOf(str[0]).intValue() == 0)break;
			int cnt = 0;
			int ans = 0;
			for(int i = 0;i < str.length;i++){
				int num = Integer.valueOf(str[i]).intValue();
				if(num == 1){
					cnt++;ans++;
				}else{
					if(num > 10){
						ans = ans + 10;
					}else{
						ans = ans + num;
					}
				}
			}
			for(int i = 0;i < cnt;i++){
				if(ans + 10 > 21)break;
				else{
					ans = ans + 10;
				}
			}
			if(ans > 21){
				System.out.println(0);
			}else{
				System.out.println(ans);
			}
		}
     }
    public static void main(String[] args) {
    	// TODO Auto-generated method stub
    	new Main().doIt();
    }
}

Measured memory_bytes: 17344
<?php
// maxより小さければOK
// max<＝xならNG
$n = fgets(STDIN);
$arr = [];
while ($values = fgets(STDIN)){
    array_push($arr, (int)$values);   
}
// $arr = [10,8,9,6]のような配列
rsort($arr);
$counter = 0;
for ($i = 0; $i < $n; $i++) {
    if (!empty($arr[$i+1])) {
        if ($arr[$i] <= $arr[$i+1]) {
            continue;
        } 
    }
    $counter++;
}
echo $counter;

Measured memory_bytes: 16196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int h,w;
	cin>>h>>w;
	vector<vector<char>> g(h,vector<char>(w));
	rep(i,h){
		rep(j,w){
			cin>>g[i][j];
		}
	}
	vector<vector<int>> dp(h,vector<int>(w,INF));
	if(g[0][0]=='#') dp[0][0]=1;
	else dp[0][0]=0;
	rep(i,h)rep(j,w){
		int ni=i+1,nj=j+1;
		if(ni<h){
			if(g[i][j]=='.' && g[ni][j]=='#'){
				chmin(dp[ni][j],dp[i][j]+1);
			}else{
				chmin(dp[ni][j],dp[i][j]);
			}
		}
		if(nj<w){
			if(g[i][j]=='.' && g[i][nj]=='#'){
				chmin(dp[i][nj],dp[i][j]+1);
			}else{
				chmin(dp[i][nj],dp[i][j]);
			}
		}
	}
	cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 384
// #pragma GCC optimize("Ofast") 
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;


typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;


#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(c) c.begin(),c.end()
#define sz(c) c.size()
#define int ll
#define rep(i,j,x) for(int i=j;i<x;i++)
#define repn(i,j,x) for(int i=j;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())


template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }
 
double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}

// Removes leading zeroes from answer, or outputs one '0' if s is all zeroes
void outputAnswer(string s) {
    cout<<regex_replace(s, regex("^0+(?!$)"), "")<<"\n";
}


int32_t main()
{

    int n,wmax=0,temp;
    cin>>n;
    vector<pair<int,int>>vec;
    int w[n+2],s[n+2],v[n+2],w1[n+2],v1[n+2],s1[n+2];
    for (int i = 1; i <= n; ++i)
    {
        cin>>w1[i]>>s1[i]>>v1[i];
        vec.push_back(make_pair(s1[i]+w1[i],i));
        wmax=max(wmax,w1[i]+s1[i]);
    }
    sort(vec.begin(),vec.end());
    for (int i = 1; i <= n; ++i)
    {
        temp=vec[i-1].second;
        //cout<<temp<<endl;
        w[i]=w1[temp];
        v[i]=v1[temp];
        s[i]=s1[temp];
    }
    int dp[n+2][wmax+2];
    memset(dp,0,sizeof(dp));
    //cout<<v[1]<<v[2]<<v[3]<<endl;
    for (int i = 1; i <= wmax; ++i)
    {
        if(i>=w[1])
            dp[1][i]=v[1];
        else
            dp[1][i]=0;
        //cout<<dp[1][i]<<" ";
    }
    //cout<<endl;
    //cout<<wmax<<endl;
    for (int i = 2; i <= n; ++i)
    {
        dp[i][0]=0;
        for (int j = 1; j <= wmax; ++j)
        {
            //if(i==3)
                //cout<<dp[i-1][j]<<endl;
            dp[i][j]=dp[i-1][j];
            if(j-w[i]>=0 && j-w[i]<=s[i])
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            else if(j-w[i]<0)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=max(dp[i-1][j],dp[i-1][s[i]]+v[i]);
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    //cout<<dp[2][6]<<endl;
    cout<<dp[n][wmax]<<endl;
}



Measured memory_bytes: 156928
(let* ((n (read))
       (m (read))
       (as (loop repeat n collect (read)))
       (sum (reduce #'+ as)))
  (format t "~a~%" (if (>= (count-if #'(lambda (x) (>= x (/ sum (* 4 m)))) as) m)
                       "Yes"
                       "No")))


Measured memory_bytes: 16352