akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 998244353LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i=N-1; i >= 0; --i)
            ifact[i] = (ifact[i+1]*(i+1))%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};
 
ModFact<300000, ll, MOD> fact;

int main() {
    fastio();
    ll N, A, B, K, ans = 0;
	cin >> N >> A >> B >> K;
    ll g = gcd(A, B);
    if(K%g==0) {
        ll s, ca=B/g, cb=A/g;
        int i, j;
        for (i=0, j=min(N, K/B+1); i<=N && i*A<=K; i++) {
            while ((s=i*A+j*B)>K) j--;
            if (s==K) break;
        }
        while(i<=N && j>=0) {
            ans += fact.comb(N,i)*fact.comb(N,j);
            if(ans > MOD) ans %= MOD;
            i += ca; j -= cb;
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub fn bsearch<F>(ok: i64, ng: i64, pred: F) -> Option<i64>
where
    F: Fn(i64) -> bool,
{
    let orig_ok = ok;
    let mut ok = ok;
    let mut ng = ng;
    while (ok - ng).abs() > 1 {
        let mid = (ok + ng) / 2;
        if pred(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    if ok == orig_ok {
        None
    } else {
        Some(ok)
    }
}

fn solve() {
    input! {
        n: usize,
        mut lv: [usize; n]
    };

    let abv = lv
        .iter()
        .combinations(2)
        .map(|v| (*v[0], *v[1]))
        .collect::<Vec<_>>();
    lv.sort();
    let mut res = 0;
    for (a, b) in abv {
        let cmin = a.max(b) - a.min(b) + 1;
        let cmax = a + b - 1;
        let minj = bsearch(lv.len() as i64, -1, |j| {
            let j = j as usize;
            cmin <= lv[j]
        });
        let maxj = bsearch(-1, lv.len() as i64, |j| {
            let j = j as usize;
            lv[j] <= cmax
        });
        match (minj, maxj) {
            (Some(minj), Some(maxj)) => {
                let mut c = maxj as usize - minj as usize + 1;
                if a >= cmin {
                    c -= 1;
                }
                if b >= cmin {
                    c -= 1;
                }
                res += c;
            }
            _ => {}
        }
    }
    println!("{}", res / 3);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 32376
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(){
  int shuffle_num;
  
  while(1){
    string T;
    cin >> T;
    if(T[0] == '-'){
      break;
    }
    
    cin >> shuffle_num;

    string buf = T;
    int h;
    for(int i=0; i<shuffle_num; i++){
      cin >> h;
      for(int j=0; j<h; j++){
        buf[buf.size()-h+j] = T[j];
      }
      for(int j=h; j<T.size(); j++){
        buf[j-h] = T[j];
      }
      T = buf;
      
    }

    cout << T << endl;
  }
  
  return(0);

}

Measured memory_bytes: 1208
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
    if((i%2==0&&j%2==0)||(i%2==1&&j%2==1))
      cout << "#";
    else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

char C;

signed main(){
	cin>>C;
	if('A'<=C&&C<='Z'){
		cout<<"A"<<endl;
	}
	else{
		cout<<"a"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll ans;
void f(ll h,ll dep)
{
	if(h==0)return;
	ans+=dep;
	f(h/2,dep*2);
}
int main(int argc, char** argv) {
	ll h;cin>>h;
	f(h,1);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  3 19:52:53 2019

@author: Yamazaki Kenichi
"""
from collections import deque

S = input()

ans = 0
q=deque([' '])
for c in S:
    tmp = q.pop()
    s = tmp+c
    if s.count('0') >= 1 and s.count('1') >= 1:
        ans += 2
    else:
        q.append(tmp)
        q.append(c)
print(ans)

Measured memory_bytes: 4212
#include <iostream>
#include <vector>
#define INPUT_FROM_FILE (0)

#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv) {
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	int n = 0;
	std::vector<int> v;

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	v.resize(n, 0);
	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> v[i];
#else
		std::cin >> v[i];
#endif
	}

	for(unsigned int j = 0; j < v.size(); j++){
		std::cout << v[j];
		if(j < v.size() - 1){
			std::cout << " ";
		}
	}
	std::cout << std::endl;
	for(unsigned int i = 1; i < v.size(); i++){
		int key = v[i];
		int j = i - 1;
		while(j >= 0 && v[j] > key){
			v[j + 1] = v[j];
			j--;
		}
		v[j + 1] = key;

		for(unsigned int j = 0; j < v.size(); j++){
			std::cout << v[j];
			if(j < v.size() - 1){
				std::cout << " ";
			}
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3096
import java.io.CharArrayReader;
import java.lang.reflect.Array;
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 = sc.nextInt();
        boolean ab = false, ac = false, bc = false;
        if(((Math.abs(b-c)<=d)&&(Math.abs(a-b)<=d))||(Math.abs(a-c)<=d))System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 35864
//on the way
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(int argc, char const *argv[])
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a < c){
		if(c < b){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else{
		if(b < c){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> a(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n-1){
        for(int j=i+1;j<n;j++){
            if(a[i]==a[j]){
                cout << "No";
                return 0;
            }
        }
    }
    rep(i,n-1){
        if(a[i][a[i].size()-1]==a[i+1][0]){
            continue;
        }
        else{
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";


    return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 1e5 + 10;
int n;
ll a[maxN];
const ll INF = 1e18;
ll from[maxN];
ll to[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
        from[i] = a[i];
        to[i] = INF;
    }
    from[0] = max(from[0], (ll)1);
    to[0] = min(to[0], (ll)1);
    from[n] = max(from[n], a[n]);
    to[n] = min(to[n], a[n]);
    for (int i = 0; i < n; i++) {
        from[i + 1] = max(from[i + 1], from[i] - a[i]);
        to[i + 1] = min(to[i + 1], min(2 * (to[i] - a[i]), INF));
    }
    for (int i = n; i > 1; i--) {
        to[i] = min(to[i], a[i] + to[i + 1]);
        from[i] = max(from[i], (from[i + 1] + 1) / 2 + a[i]);
    }
    for (int i = 0; i <= n; i++) {
        if (from[i] > to[i]) {
            cout << -1;
            return 0;
        }
    }
    ll ans = 0;
    for (int i = 0; i <= n; i++) ans += to[i];
    cout << ans;
    return 0;
}

Measured memory_bytes: 5984
from queue import Queue
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

H, W = map(int, input().split())
S = [input() for _ in range(H)]
dist = [[-1] * W for _ in range(H)]
que = Queue()

# 初期条件
dist[0][0] = 0
que.put((0, 0))

# 幅優先探索
while not que.empty():
    x, y = que.get()
    for dir in range(4):
        x2, y2 = x + dx[dir], y + dy[dir]
        if x2 < 0 or x2 >= H or y2 < 0 or y2 >= W or S[x2][y2] == '#':
            continue
        if dist[x2][y2] != -1:
            continue
        dist[x2][y2] = dist[x][y] + 1
        que.put((x2, y2))

# 白マス数
white = sum(sum(1 if S[x][y] == '.' else 0 for y in range(W)) for x in range(H))

# 答え
print(white - dist[H-1][W-1] - 1 if dist[H-1][W-1] != -1 else -1)


Measured memory_bytes: 9716
#include <stdio.h>
int main()
{
    int sx, sy, tx, ty;
    int dx, dy;
    int i;
    scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
    dx = tx - sx;
    dy = ty - sy;

    for (i = 0; i < dy; ++i)
        printf("U");
    for (i = 0; i < dx; ++i)
        printf("R");

    for (i = 0; i < dy; ++i)
        printf("D");
    for (i = 0; i < dx; ++i)
        printf("L");

    printf("L");
    for (i = 0; i < dy + 1; ++i)
        printf("U");
    for (i = 0; i < dx + 1; ++i)
        printf("R");
    printf("D");

    printf("R");
    for (i = 0; i < dy + 1; ++i)
        printf("D");
    for (i = 0; i < dx + 1; ++i)
        printf("L");
    printf("U\n");
}

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

public class Main {

	public static long[] tree;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] height = new int[n];
		int[] beauty = new int[n];
		long[] dp = new long[n + 1];
		String[] s = br.readLine().split(" ");
		for (int i = 0; i < n; i++)
			height[i] = Integer.parseInt(s[i]);

		s = br.readLine().split(" ");
		for (int i = 0; i < n; i++)
			beauty[i] = Integer.parseInt(s[i]);

		int b = 1;
		while (b < n)
			b *= 2;
		tree = new long[b * 2]; // segment tree stores max beauty in given range
								// we treat the segment tree as storing beauties of flowers w/
								// heights going from 1 -> n
		for (int i = 0; i < n; i++) {
			int k = b + height[i]-1;
			long max = 0;
			while (k > 1) { // because queries will always be from 1-height[i], we never care about right
								// side only care about left side (we are on right side)
//				System.out.println(k);
				if (k % 2 == 1)
					max = Math.max(max, tree[k - 1]); //bottom up; if sibling, compare
				k /= 2;
			}
//			System.out.println(max + "*");
			dp[height[i]] = beauty[i] + max; // dp[x] now represents the max beauty of flower w/
												// height i where it currently stands. if shorter flower
												// comes later, then shorter will have 0, which is ignored.
			k =b + height[i]-1;
			while (k >= 1) {
				tree[k] = Math.max(tree[k], dp[height[i]]);
				k /= 2;
			}
			
//			for (int e = 1; e < b*2; e++)
//				System.out.print(tree[e] + " ");
//			System.out.println();
//			for (int j = i; j >= 0; j--) {
//				if (height[j] < height[i] && dp[j] > max)
//					max = dp[j];
//			}
			// old n^2 approach TLE where dp[i] represents
			// the max beauty if the i'th flower was chosen

		}
		long max = -1;
		for (long x : dp)
			if (x > max)
				max = x;
		System.out.println(max);
//		for (long t : dp) System.out.print(t + " ");
//		System.out.println(dp[n - 1]);
	}

}


Measured memory_bytes: 78372
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> A(N);
	vector<vector<int>> x(N), y(N);
	rep(i, 0, N) {
		cin >> A[i];
		rep(j, 0, A[i]) {
			int a, b; cin >> a >> b; a--;
			x[i].push_back(a);
			y[i].push_back(b);
		}
	}

	int ans = 0;
	rep(mask, 0, (1 << N)) {
		dump(mask);
		int t = 0;
		vector<int> p(N, -1);
		rep(i, 0, N) {
			if (mask >> i & 1) {
				t++;
				p[N - 1 - i] = 1;
			}
		}
		dump(t);
		dump(p);
		rep(i, 0, N) {
			dump(x[i], y[i]);
			if (mask >> i & 1) {
				rep(j, 0, A[N - 1 - i]) {
					if (p[x[N - 1 - i][j]] == -1) {
						p[x[N - 1 - i][j]] = y[N - 1 - i][j];
					}
					else if (p[x[N - 1 - i][j]] != y[N - 1 - i][j]) {
						t = -INF;
					}
				}
			}
			dump(i, p);
		}
		rep(i, 0, N) {
			if (mask >> i & 1 && p[N - 1 - i] == 0)t = -INF;
			if (!(mask >> i & 1) && p[N - 1 - i] == 1)t = -INF;
		}
		dump(t, p);
		chmax(ans, t);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <cassert>
#include <iostream>
using namespace std;
typedef long long ll;

#define REP(i,n) for (int i=0;i<(int)(n);++i)
#define FOR(i,k,n) for (int i=k;i<(int)(n);++i)
#define FOREQ(i,k,n) for (int i=k;i<=(int)(n);++i)

#define MEMSET(v,h) memset((v),(h),sizeof(v))

struct Point {
    int x;
    int y;
    int cost;
    Point(int x, int y, int c) : x(x), y(y), cost(c) {;}
};



bool graph[100][100][4];
bool visit[100][100];
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main() {
    int h, w;
    while (scanf("%d %d", &w, &h), w|h) {
        MEMSET(graph, false);
        MEMSET(visit, false);
        REP(i, 2 * h - 1) {
            int y = i / 2;
            if (i % 2 == 0) {
                REP(x, w - 1) {
                    int exist;
                    scanf("%d", &exist);
                    graph[y][x][0] = !exist;
                    graph[y][x + 1][2] = !exist;
                }
            } else {
                REP(x, w) {
                    int exist;
                    scanf("%d", &exist);
                    graph[y][x][1] = !exist;
                    graph[y + 1][x][3] = !exist;
                }
            }
        }
        queue<Point> que;
        que.push(Point(0, 0, 1));
        while (!que.empty()) {
            Point p = que.front();
            que.pop();
            if (visit[p.y][p.x]) { continue; }
            visit[p.y][p.x] = true;
            if (p.x == w - 1 && p.y == h - 1) {
                printf("%d\n", p.cost);
                goto next;
            }
            REP(i, 4) {
                int nx = p.x + dx[i];
                int ny = p.y + dy[i];
                if (nx < 0 || nx >= w || ny < 0 || ny >= h) { continue; }
                if (!graph[p.y][p.x][i]) { continue; }
                que.push(Point(nx, ny, p.cost + 1));
            }
        }
        puts("0");
next:;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> H;
    for(int i=0;i<N;i++){
        int h;
        cin >> h;
        H.push_back(h);
    }
    int ans=0;
    for(int i=0;i<N;i++){
        while(H[i]!=0){
            for(int j=i;j<N;j++){
                if(H[j]>0){
                    H[j]--;
                }
                else break;
            }
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s;
    cin >> s;
    vector<int>t(26,0);
    rep(i,s.size()){
        int id = s[i]-'a';
        if(t[id]!=0){
            cout << "no" << endl;
            return 0;
        }else{
            t[id]=1;
        }
    }
    cout << "yes" << endl;
}

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

typedef long long ll;
const ll mod=1e9+7;
ll f[2345678];
ll c[2345678];
ll d[2345678];


ll ksm(ll a,ll b){
	ll res = 1;
	while(b){
		if(b&1) res = res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
int main()
{
   int n;
   ll k,count=0;
   cin>>n>>k;
   for(int i=0;i<n;i++)  cin>>f[i];
   for(int i=0;i<n;i++)
   {
       for(int j=i+1;j<n;j++)
           if(f[i]>f[j]) c[i]++;
    
       for(int j=0;j<i;j++)
           if(f[i]>f[j]) d[i]++;
    }
    for(int i=0;i<n;i++)
    {    	
		count=(count+c[i]*k%mod*(1+k)%mod*ksm(2,mod-2)%mod)%mod;
    	count=(count+d[i]*(k-1)%mod*k%mod*ksm(2,mod-2)%mod)%mod;
	}
    cout<<count<<endl;
}

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

vector<int> arr;
int main(){
	int n, m;
	cin >> n >> m;
	arr = vector<int>(n);
	int ttl = 0;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		ttl += arr[i];
	}
	double votes = (double)ttl /(4 * (double)m); 
	sort(arr.begin(), arr.end());
	bool ans = true;
	for(int i = n - 1, j = 0; i >= 0 && j < m; j++, i--){
		if((double)arr[i] < votes) {
			ans = false;
			break;
		}
	}

	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int a,b,c;
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b>>c;
	if(c-a-b<=0) cout<<"No"<<endl;
	else if(4*a*b<(c-a-b)*(c-a-b)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

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

    int p[101] = {0};
    rep(i,n)
    {
        int tmp = i+1;
        rep2(j,2,i+2)
        {
            while(tmp%j == 0)
            {
                p[j]++;
                tmp /= j;
            }
        }        
    }

    int cnt = 0;

    // 74
    rep(i,n+1)
    {
        if(p[i] < 74)
            continue;
        cnt++;
    }

    // (24,2), (14,4)
    rep(i,n+1)
        rep(j,n+1)
        {
            if(i==j) continue;
            if(p[i] >= 24 && p[j] >= 2) cnt++;
            if(p[i] >= 14 && p[j] >= 4) cnt++;
        }

    // (4,4,2)
    rep(i,n+1)
        rep2(j,i+1,n+1)
            rep(k,n+1)
            {
                if(i==j || j==k || k==i) continue;
                if(p[i] >= 4 && p[j] >= 4 && p[k] >=2) cnt++;
            }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
N,M=map(int,input().split())
adj={}
for ln in sys.stdin:
    A,B=map(int,ln.split())
    if A not in adj: adj[A]=[]
    if B not in adj: adj[B]=[]
    adj[A].append(B)
    adj[B].append(A)

a=[0]*(N+1)
a[1]=-1
que=[1]
while que:
    suc=[]
    for u in que:
        for v in adj[u]:
            if a[v]!=0:
                continue
            a[v]=u
            suc.append(v)
    que=suc

#print(N,M)
#print(adj)
#print(a)

ok=True
ans=[]
for i in range(2,N+1):
    if a[i]==0:
        ok=False
        break
    ans.append(a[i])

if not ok:
    print('No')
else:
    print('Yes')
    for x in ans:
        print(x)


Measured memory_bytes: 38552
import java.util.Scanner;

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

		int total = 700;
		for (char topping : S.toCharArray()) {
			if ("o".equals(String.valueOf(topping))) {
				total = total +  100;
			}
		}
		System.out.println(total);

	}
}


Measured memory_bytes: 21332
#include <stdio.h>

int ans[55] = { 0 } ;

void init ( ) ;

int main ( )
{
	int s ;
	init ( ) ;
	while ( scanf ( "%d" , &s ) == 1 ) {
		printf ( "%d\n" , ans[s] ) ;
	}
	return 0 ;
}

void init ( )
{
	for ( int i = 0 ; i <= 9 ; i++ ) {
		for ( int j = 0 ; j <= 9 ; j++ ) {
			for ( int k = 0 ; k <= 9 ; k++ ) {
				for ( int l = 0 ; l <= 9 ; l++ ) {
					ans[i+j+k+l]++ ;
				}
			}
		}
	}
}

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

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    bool find = false;
    for(int i = 1; i <= 1500; i++)
    {
        if((int)(i * 0.08) == A && (int)(i * 0.1) == B)
        {
            cout << i << endl;
            find = true;
            break;
        }
    }
    if(!find) cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
ll n,q;
vector<ll>ch[200010];
ll pl[200010];
ll ans[200010];
void dep(ll now,ll sum){
	for(ll i=0;i<ch[now].size();i++){
		ll nex=ch[now][i];
		if(ans[nex]!=-1){
			continue;
		}
		ans[nex]=sum+pl[nex];
		dep(nex,ans[nex]);
	}
}
int main() {
	cin>>n>>q;
	for(ll i=0;i<n-1;i++){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		ch[x].push_back(y);
		ch[y].push_back(x);
	}
	for(ll i=0;i<q;i++){
		ll now,co;
		cin>>now>>co;
		now--;
		pl[now]+=co;;
	}
	for(ll i=0;i<n;i++){
		ans[i]=-1;
	}
	ans[0]=pl[0];
	dep(0,pl[0]);
	for(ll i=0;i<n;i++){
		cout <<ans[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 27072
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	READ(n);
    string str;
    cin >> str;
    
    int cnt = 1;
    FOR (i, 1, n - 1)
        if (str[i] != str[i - 1]) cnt++;
    
    cout << cnt;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <vector>
#include <limits>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std;

#define REP( i, n )	for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( x )	(x).begin(), (x).end()

int main() {
	int a, b;
	while( ( scanf( "%d %d", &a, &b ) ) != EOF ) {
		
		int sum = a + b;

		int count = 1;
		while( 1 ) {
			sum /= 10;
			if( sum < 1 ) break;
			count++;
		}

		cout << count << endl;
	}

}



Measured memory_bytes: 3132
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int a,b;
	cin >> a >>b;
	string ans;
	if (a == b)ans = "Draw";
	else if ((a > b && b != 1) || a == 1)ans = "Alice";
	else ans = "Bob";
	cout << ans << endl;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    //vector<ll> X(N);
    //vector<ll> Y(N);
    map<ll, ll> X;
    map<ll, ll> Y;
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
        //X[i] = a + i;
        //Y[i] = a - i;
        ll idx = i+1;
        X[a + idx]++;
        Y[idx - a]++;
    }

    ll ans = 0;
    for(auto&& p : X){
        ll k = p.first;
        ll val = p.second;
        ll val2 = Y[k];
        ans += val*val2;
    }


    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 39064
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld radian(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
string s;
bool gm(int i) {
	if (i % 2 == 1)
		return 0;
	string a = "", b = "";
	for (int j = 0; j < i / 2; j++)
		a += s[j], b += s[i / 2 + j];
	return a == b;
}
signed main() {
	cin >> s;
	for (int i = s.size() - 2; i >= 0; i--) {
		if (gm(i)) {
			cout << i << endl;
			goto loop;
		}
	}
loop:;
	getchar(); getchar();
}

Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static private final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static private final int upper(long v) {return (int)(v >> 32);}
	static private final int lower(long v) {return (int)(v & 0xFFFFFFFF);}

	//-----------------------------------------

	static private final long load(int end, int length) {
		return pair(end, length);
	}
	static private final int end(long load) {
		return upper(load);
	}
	static private final int length(long load) {
		return lower(load);
	}
	static private final long score(int count, int last) {
		return pair(count, last);
	}
	static private final int count(long score) {
		return upper(score);
	}
	static private final int last(long score) {
		return lower(score);
	}

	//------------------------------------------

	public void exec() throws Exception{
		final int r = sc.nextInt();
		out.println(r*r);
	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll h,w; cin >> h >> w;
  if(h%3==0 || w%3==0){
    cout << 0 << endl;
  } else {
    ll min_val = mod;
    for(ll i=1;i<h;++i){
      vector<ll> v1,v2;
      ll s1a = i*w;
      ll s1b = (h-i)*(w/2);
      ll s1c = h*w - s1a - s1b;
      v1.push_back(s1a);
      v1.push_back(s1b);
      v1.push_back(s1c);
      sort(all(v1));
      min_val = min(min_val, v1[2]-v1[0]);
      if(i!=h-1){
        ll s2a = i*w;
        ll s2b = ((h-i)/2)*w;
        ll s2c = h*w - s2a - s2b;
        v2.push_back(s2a);
        v2.push_back(s2b);
        v2.push_back(s2c);
        sort(all(v2));
        min_val = min(min_val, v2[2]-v2[0]);
      }
    }
    for(ll i=1;i<w;++i){
      vector<ll> v1,v2;
      ll s1a = h*i;
      ll s1b = h/2*(w-i);
      ll s1c = h*w - s1a - s1b;
      v1.push_back(s1a);
      v1.push_back(s1b);
      v1.push_back(s1c);
      sort(all(v1));
      min_val = min(min_val, v1[2]-v1[0]);
      if(i!=w-1){
        ll s2a = h*i;
        ll s2b = h*((w-i)/2);
        ll s2c = h*w - s2a - s2b;
        v2.push_back(s2a);
        v2.push_back(s2b);
        v2.push_back(s2c);
        sort(all(v2));
        min_val = min(min_val, v2[2]-v2[0]);
      }
    }
    cout << min_val << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/**
 * auther: moririn_cocoa
 */

#include <iostream>
#include <math.h>
using namespace std;

int main(void) {
  
  int A;
  int B;
  int C;
  
  cin >> A;
  cin >> B;
  cin >> C;
  
  if ( A + B + C <= 21 ) {
    
    cout << "win" << endl;
  }
  
  else if ( A + B + C >= 22 ) {
    
    cout << "bust" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3628
fn read_tuple<T: std::str::FromStr>() -> (T, T) {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let mut v: Vec<T> = buf
        .trim()
        .split(' ')
        .map(|x| x.parse().ok().unwrap())
        .collect();
    v.reverse();
    (v.pop().unwrap(), v.pop().unwrap())
}

fn main() {
    let (n, m) = read_tuple();
    let mut lmax = 0;
    let mut rmin = n;
    for _ in 0..m {
        let (l, r) = read_tuple();
        lmax = std::cmp::max(l, lmax);
        rmin = std::cmp::min(r, rmin);
    }
    println!("{}", std::cmp::max(0, rmin - lmax + 1));
}


Measured memory_bytes: 4352
program problemD
  implicit none

  integer, parameter     :: double = selected_real_kind ( 9 )
  integer, parameter     :: i8 = selected_int_kind  ( 18 )
  real ( kind = double ), parameter :: pi = 3.141592653589790_double
  integer ( kind = i8 )  :: a, b, x
  real ( kind = double ) :: ans

  read *, a, b, x
  a = real ( a )
  b = real ( b )
  x = real ( x )

  if ( a **2.0_double * b / 2.0_double < x ) then
     ans = atan ( ( 2.0_double * b ) / a - ( 2.0_double * x ) &
          & / ( a **3.0_double ) ) / ( 2.0_double * pi ) * 360_i8
  else
     ans = atan ( a * b **2.0_double / ( 2.0_double * x ) ) / ( 2.0_double * pi ) * 360_i8
  end if
  print *, ans

end program problemD


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

int main()
{
    int n[3];
   scanf("%d%d%d",&n[0],&n[1],&n[2]);
   sort(n,n+3,greater<int>());
   printf("%d",(10*n[0]+n[1])+n[2]);
    return 0;
}


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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    char field[n][m];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> field[i][j];
        }
    }
    int ans = 1000000000;
    for (int white = 0; white < n - 2; ++white) {
        for (int blue = white + 1; blue < n - 1; ++blue) {
            int cnt = 0;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (field[i][j] != 'W' && i <= white) {
                        ++cnt;
                    }
                    if (field[i][j] != 'B' && white < i && i <= blue) {
                        ++cnt;
                    }
                    if (field[i][j] != 'R' && blue < i) {
                        ++cnt;
                    }
                }
            }
            ans = min(ans, cnt);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> k(n);
	vector<vector<int>> a;
	a = vector<vector<int>>(n, vector<int>(m));

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

	vector<int> suki(m+1, 0);

	// 好きだと答えた数
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < k[i]; j++) {
			suki[a[i][j]]++;
		}
	}

	int cnt = 0;

	for (int i = 0; i <= m; i++) {
		if (suki[i] == n) cnt++;
	}

	cout << cnt << endl;

	return 0;
}

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

struct node {
	node *p, *l, *r;
	int cnt;
	void Init(node *p_) {
		p = p_;
		l = r = nullptr;
		cnt = 0;
	}
};

int it;
node pool[2500000];

node *new_node(node *p) {
	pool[it].Init(p);
	return &pool[it++];
}

class uint_Trie {
	node *root;
	int siz;
public:
	uint_Trie() : root(new_node(nullptr)) {}
	int size() {
		return root->cnt;
	}
	void insert(unsigned val) {
		// if (find(val)) return; // multiset ???????¶????
		node *t = root;
		for (int i = 30; i >= 0; i--) {
			t->cnt++;
			if (val & (1 << i)) {
				if (t->r == nullptr) {
					t->r = new_node(t);
				}
				t = t->r;
			}
			else {
				if (t->l == nullptr) {
					t->l = new_node(t);
				}
				t = t->l;
			}
		}
		t->cnt++;
	}
	void erase(unsigned val) {
		node *t = root, *ne;
		for (int i = 30; i >= 0; i--) {
			t->cnt--;
			if (val & (1 << i)) {
				if (t->r == nullptr) return;
				t = t->r;
			}
			else {
				if (t->l == nullptr) return;
				t = t->l;
			}
		}
		t->cnt--;
		while (t != root && t->cnt == 0) {
			ne = t->p;
			(t == ne->l ? ne->l : ne->r) = nullptr;
			t = ne;
		}
	}
	bool find(unsigned val) {
		node *t = root;
		for (int i = 30; i >= 0; i--) {
			if (val & (1 << i)) {
				if (t->r == nullptr) return false;
				t = t->r;
			}
			else {
				if (t->l == nullptr) return false;
				t = t->l;
			}
		}
		return true;
	}
	unsigned max() {
		assert(root->cnt >= 1);
		node *t = root;
		unsigned res = 0;
		for (int i = 30; i >= 0; i--) {
			assert(t->l != nullptr || t->r != nullptr);
			if (t->r != nullptr) {
				res |= 1 << i;
				t = t->r;
			}
			else {
				t = t->l;
			}
		}
		return res;
	}
	unsigned min() {
		assert(root->cnt >= 1);
		node *t = root;
		unsigned res = 0;
		for (int i = 30; i >= 0; i--) {
			assert(t->l != nullptr || t->r != nullptr);
			if (t->l != nullptr) {
				t = t->l;
			}
			else {
				res |= 1 << i;
				t = t->r;
			}
		}
		return res;
	}
};

int main()
{
	cin.sync_with_stdio(false);
	uint_Trie ut;
	string com;
	int k;
	while (cin >> com, com != "end") {
		if (com == "insert") {
			cin >> k;
			ut.insert(k);
		}
		else {
			int res = ut.max();
			printf("%d\n", res);
			ut.erase(res);
		}
	}
	return 0;
}

Measured memory_bytes: 38276
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  vector<ll> cnt(5,0);
  rep(i,n){
    string s; cin >> s;
    if(s[0]=='M'){ cnt[0]++; continue; }
    if(s[0]=='A'){ cnt[1]++; continue; }
    if(s[0]=='R'){ cnt[2]++; continue; }
    if(s[0]=='C'){ cnt[3]++; continue; }
    if(s[0]=='H'){ cnt[4]++; continue; }
  }
  
  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 += cnt[i]*cnt[j]*cnt[k];
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s, k = input(), int(input())
char=[]
prev = "0"
cnt = 0
for i in s:
    if i==prev: cnt+=1
    else: char.append(cnt);cnt=1
    prev = i
char.append(cnt)

ans = 0
for i in char: ans += i//2
ans *= k
if s[0]==s[-1]: ans += (char[1]%2 and char[-1]%2) * (k-1)

if len(set(s))==1: ans = len(s)*k//2

print(ans)

Measured memory_bytes: 3064
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] l = new int[s[0]];
        for(int i = 0; i < s[0]; i ++) {
            l[i] = int.Parse(Console.ReadLine());
            s[1] -= l[i];
        }
        Array.Sort(l);
        Console.WriteLine(s[0] + s[1]/l[0]);
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
struct edge{long long to,cost;};
struct st{int rate,way,num;};
typedef pair<int,int>P;
#define inf 1000000007
string alph("abcdefghijklmnopqrstuvwxyz");
signed main(){
    int n,a;cin>>n>>a;
    int key=n%500;
    if(key>a)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define MAXN 100000
#define LL long long
int n,m;
vector<int> G[MAXN+5];
int du[MAXN+5],fa[MAXN+5];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<n+m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        du[v]++;
    }
    queue<int> Q;
    for(int i=1;i<=n;i++)if(!du[i])Q.push(i);
    while(!Q.empty())
    {
        int x=Q.front();
        Q.pop();
        for(int i=0;i<G[x].size();i++)
        {
            int nxt=G[x][i];
            du[nxt]--;
            if(!du[nxt]){fa[nxt]=x;Q.push(nxt);}
        }
    }
    for(int i=1;i<=n;i++)printf("%d\n",fa[i]);
}

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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    vector<int> x(m);

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

    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }

    sort(x.begin(), x.end());

    int ans = x.back() - x.front();

    vector<int> d(m - 1);

    for (int i = 0; i < m - 1; i++) {
        d[i] = x[i + 1] - x[i];
    }

    sort(d.rbegin(), d.rend());

    for (int i = 0; i < n - 1; i++) {
        ans -= d[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std ;
 
#define lli long long int
#define pb push_back

int main ()
{
    lli a , b , c ;
    cin >> a >> b >> c ;

    if (c > a)
    {
        c = c - a ;
        a = 0 ;

        if (c >= b)
        {
            b = 0 ;
        }
        else if (c < b)
        {
            b = b - c ;
            c = 0 ;
        }
    }
    else if (a >= c)
    {
        a = a - c ;
        c = 0 ;
        b = b ;
    }
    
    printf("%lld %lld\n", a , b);

    return 0 ;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int a, b, c, d, p, ans, tmp;

int main(){

	cin >> a >> b >> c >> d >> p;

	ans += b;
	if (p > c) {
		tmp = p - c;
		ans += tmp * d;
	}
	ans = min(a * p, ans);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3080
class Node{
  constructor(id, parent, children) {
    this.id = id;
    this.parent = parent;
    this.children = children;
  }

  get type() {
    if (this.parent === null) return 'root';
    if (this.children.length === 0) return 'leaf';
    return 'internal node';
  }

  get depth() {
    const getDepth = (node, i) => {
      return node.parent === null ? i : getDepth(node.parent, i + 1);
    };
    return getDepth(this, 0);
  }

  toString() {
    return `node ${this.id}: parent = ${this.parent !== null ? this.parent.id : -1}, depth = ${this.depth}, ${this.type}, [${this.children.map(n => n.id).join(', ')}]`;
  }
};

class Tree {
  constructor(n) {
    this.nodes = [];
  }

  add(id, childrenIds) {
    let node = this.find(id);
    childrenIds.forEach((cid) => {
      let c = this.find(cid);
      c.parent = node;
      c.id = cid;
      node.children.push(c);
    })
  }

  find(id) { return this.nodes[id] || (this.nodes[id] = new Node(id, null, []));}

  print() { console.log(this.nodes.sort((a, b) => a.id - b.id).map(n => n.toString()).join('\n')); }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  let tree = new Tree(n);
  let id, k, childrenIds;
  lines.map(l => l.split(' ')).forEach(function(line) {
    id = Number(line.shift());
    k = Number(line.shift());
    childrenIds = line.map(Number);
    tree.add(id, childrenIds);
  });
  tree.print();
})();



Measured memory_bytes: 158256
import sys,math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

n=int(input())
t=list(map(int,sys.stdin.read().split()))
print(lcm_list(t))



Measured memory_bytes: 9452
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long x, long long y){
    bool same_sign;
    if(x*y >= 0)
        same_sign = true;
    else
        same_sign = false;
    if(x <= y && same_sign){
        cout << y - x << endl; return;
    }
    if(x <= y && !same_sign){
        if(y+x >=0)
            cout << y+x+1 << endl;
        else
            cout << -y-x+1<<endl;
        return;
    }
    if(x > y && same_sign){
        if(x == 0 || y == 0)
            cout << abs(x-y)+1<<endl;
        else
            cout << abs(x-y)+2<<endl;
        return;
    }
    if(x > y && !same_sign){
        if(x+y >=0)
            cout << 1+y+x <<endl;
        else{
            cout<< -y-x+1<<endl;
        }
        return;
    }
}

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


Measured memory_bytes: 256