akhauriyash/Code-Regression huggingface dataset:
extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut, SubAssign, Range};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet, HashMap};
use std::fmt::Display;

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}

macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

fn main() {
    let_all!(n: i64, k: i64);
    let mut current = 0_i64;
    for _ in 1 .. n {
        current = (current / (k - 1)) * k + 1 + current % (k - 1);
    }
    println!("{}", current);
}


Measured memory_bytes: 5036
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    long K = sc.nextLong();
	    long Q = sc.nextInt();
	    long[] ans = new long[N+1];
	    
	    for(int i = 1; i <= N; i++) {
	        ans[i] = K - Q;
	    }
	    
	    for(int j = 1; j <= Q; j++) {
	        int a = sc.nextInt();
	        ans[a]++;
	    }
	    
	    for(int k = 1; k <= N; k++) {
	        if(ans[k] <= 0) {
	            System.out.println("No");
	        }else {
	            System.out.println("Yes");
	        }
	    }
	}
}

Measured memory_bytes: 70552
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int h, w;
  while(cin >> h >> w, h || w) {
    int answ = 150, ansh = 150;
    FOR(ww, 2, 151) {
      FOR(hh, 1, ww) {
        if(ww * ww + hh * hh > w * w + h * h) {
          if(answ * answ + ansh * ansh > ww * ww + hh * hh) {
            answ = ww;
            ansh = hh;
          } else if(answ * answ + ansh * ansh == ww * ww + hh * hh && ansh > hh) {
            answ = ww;
            ansh = hh;
          }
        } else if(ww * ww + hh * hh == w * w + h * h && hh > h) {
          if(answ * answ + ansh * ansh > ww * ww + hh * hh) {
            answ = ww;
            ansh = hh;
          } else if(answ * answ + ansh * ansh == ww * ww + hh * hh && ansh > hh) {
            answ = ww;
            ansh = hh;
          }
        }
      }
    }
    cout << ansh << " " << answ << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int ar[n+1];
    memset(ar,0,sizeof(ar));
    for(int i=1;i<=100;i++) for(int j=1;j<=100;j++) for(int k=1;k<=100;k++){
        int res = i*i+j*j+k*k+i*j+i*k+j*k;
        if(res <= n) ar[res]++;
    }
    for(int i=1;i<=n;i++) cout << ar[i] << '\n';
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,ans=0;
    cin>>n;
    long int b[n+1],a[n];
    for(long int i=0;i<n+1;i++)
    {
        cin>>b[i];
    }
    for(long int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(long int i=0;i<n;i++)
    {
        if(b[i]>=a[i])
        {
            ans+=a[i];
            b[i]-=a[i];
            continue;
        }
        else
        {
            ans+=b[i];
            a[i]-=b[i];
            b[i]=0;
        }
        //cout<<a[i]<<" ";
        if(b[i+1]>=a[i])
        {
            ans+=a[i];
            b[i+1]-=a[i];
            continue;
        }
        else
        {
            ans+=b[i+1];
            b[i+1]=0;
            a[i]-=b[i+1];
        }
    }
    cout<<ans<<endl;
    
    
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

bool ret[100005];
int num[100005];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for(int i = 1; i <= n; i++) {
    num[i] = 1;
  }
  ret[1] = true;
  while(m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    if(ret[a]) {
      ret[b] = true;
    }
    if(--num[a] == 0) {
      ret[a] = false;
    }
    num[b]++;
  }
  int ans = 0;
  for(int i = 1; i <= n; i++) {
    if(ret[i]) {
      ans++;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;


int main()
{
  int n;

  cin >> n;
  queue<int> wlist[2];
  vector<queue<int> > qs(n+1);
  for (int j = 1; j <= n; ++j) {
    wlist[0].push(j);
    for (int i = 0; i < n - 1; ++i) {
      int val;
      cin >> val;
      qs[j].push(val);
    }
  }

  vector<bool> b(n+1);
  for (int i = 1; i <= n; ++i) {
    b[i] = false;
  }

  int sw = 0;
  int d = 0;
  queue<int> bq;
  int match = n * (n-1) / 2;
  while (match > 0) {
    ++d;
    while (!wlist[sw].empty()) {
      int i = wlist[sw].front();
      wlist[sw].pop();
      if (!b[i] && !qs[i].empty()) {
        int f = qs[i].front();
        if (!b[f] && qs[f].front() == i) {
          b[i] = true;
          b[f] = true;
          qs[i].pop();
          qs[f].pop();
          bq.push(i);
          bq.push(f);
          wlist[(sw+1) & 1].push(i);
          wlist[(sw+1) & 1].push(f);
          --match;
        }
      }
    }
    if (bq.empty()) {
      break;
    }
    while (!bq.empty()) {
      b[bq.front()] = false;
      bq.pop();
    }
    sw = (sw+1) & 1;
  }
  if (match > 0) {
    cout << -1;
  } else {
    cout << d;
  }
  
  return 0;
}




Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
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; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif




int main(){
	ll n;
	cin >> n;
	
	if ( n >= 30 )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}




Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 5050, mod = 1e9+7;
int n,A,B,f[N][2],g[N][2];

inline int Mod(int x){
	return x>=mod?x-mod:x;
}
inline void upd(int &x,int y){
	x+=y;
	if (x>=mod) x-=mod;
}

int main(){
	n=read(),A=read(),B=read();
	if (A>B) swap(A,B);
	g[0][0]=1;
	FOR(i,1,B){
		For(j,1,i) upd(g[i][1],g[i-j][0]);
		For(j,A,i) upd(g[i][0],g[i-j][1]);
	}
	f[0][0]=f[0][1]=1;
	For(i,1,n){
		For(j,1,min(i,A-1)) upd(f[i][0],f[i-j][1]);
		For(j,1,min(i,B-1)){
			f[i][1]=(f[i][1]+1ll*f[i-j][0]*g[j][1])%mod;
			if (i==j) upd(f[i][1],g[i][0]);
			if (i==n) f[i][0]=(f[i][0]+1ll*g[j][0]*f[i-j][0])%mod;
		}
	}
	int ans=1;
	For(i,1,n) ans=2*ans%mod;
	printf("%d\n",Mod(ans+mod-Mod(f[n][0]+f[n][1])));
}

Measured memory_bytes: 3776
#include <iostream>
#include <cmath>
#include <climits>
#include <vector>
#include <algorithm>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<unsigned long long int>;

// 基本的な演算
namespace BasicMath {
    // 分数の Ceil を求める関数
    static UInt Ceil(const UInt a, const UInt b);

    // 分数の Ceil を求める関数
    UInt Ceil(const UInt a, const UInt b) {
        if (a % b == 0) {
            return a / b;
        } else {
            return a / b + 1;
        }
    }
}
using namespace BasicMath;

int main(void) {
    Int d, g;
    cin >> d >> g;
    VI c(d + 1);
    VI p(d + 1);
    for (Int i = 1; i <= d; ++i) {
        cin >> c[i] >> p[i];
    }

    Int result = INT_MAX;
    Int comb = pow(2, d);

    for (Int i = 0; i < comb; ++i) {
        Int cost = 0;
        Int loop_result = 0;
        for (Int j = 1; j <= d; ++j) {
            if (i & (1 << (j - 1))) {
                cost += (100 * j * c[j] + p[j]);
                loop_result += c[j];
            }
        }
        if (cost >= g) {
            result = min(result, loop_result);
        } else {
            Int diff = g - cost;
            for (Int j = 1; j <= d; ++j) {
                if ((i & (1 << (j - 1))) == 0) {
                    if (diff <= (c[j] * 100 * j)) {
                        result = min(result, loop_result + (Int)Ceil(diff, 100 * j));
                    }
                }
            }
        }
    }
    cout << result << endl;
    return 0;
}


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

using namespace std;

int N,A,B,C;
vector<int> l;

int dfs(int a,int b,int c,int i){

    if(i == N){
        if(a == 0 || b == 0 || c == 0) return 1000000;
        return abs(a-A) + abs(b-B) + abs(c-C) - 30;
    }

    int val1 = dfs(a,b,c,i+1);
    int val2 = dfs(a+l[i],b,c,i+1) + 10;
    int val3 = dfs(a,b+l[i],c,i+1) + 10;
    int val4 = dfs(a,b,c+l[i],i+1) + 10;

    return min({val1,val2,val3,val4});
}

int main(){
    cin >> N >> A >> B >> C;
    l.resize(N);
    for(int i = 0; i < N; i++) cin >> l[i];

    cout << dfs(0,0,0,0) << endl;
    return 0;
}


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

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

    vector<vector<int>> c(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> c[i][j];

    int s1 = c[0][1] - c[0][0];
    int s2 = c[0][2] - c[0][1];
    
    if(c[1][1]-c[1][0] == s1 && c[1][2]-c[1][1] == s2 && c[2][1]-c[2][0] == s1 && c[2][2]-c[2][1] == s2) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

string s,ans,curr;

set <char> a;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    for(int i='a';i<='z';i++){
        a.insert(i);
    }
    cin >> s;
    for(int i=0;i<=s.lg;i++){
        curr="";
        for(int j=0;j<i;j++){
            curr+=s[j];
        }
        char x;
        if(i==s.lg) x='a'-1;
        else x=s[i],a.erase(s[i]);
        auto it=a.upper_bound(x);
        if(it!=a.end()) ans=curr+*it;
    }
    if(ans.lg) cout << ans;
    else cout << -1;
}


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


int main()
{
	long long a, b;
	scanf("%lld%lld", &a, &b);

	long long ans = min(a, b / 2);
	a -= ans; b -= ans * 2;
	printf("%lld\n", ans + b / 4);
}

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

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

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

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int Maxn=1e4+10,Maxd=1e2+10,MOD=1e9+7;
string K;
int D;
int Sum=0;
int Dp[Maxn][Maxd];
signed main()
{
	cin>>K>>D;
	int N=K.length();
	for(int i=1;i<=N;i++)
	{
		int Num=(int)K[i-1]-'0';
		for(int j=0;j<Num;j++)
		{
			++Dp[i][(Sum+j)%D];
		}
		Sum+=Num;
	}
	++Dp[N][Sum%D];
	for(int i=1;i<=N;i++)
	{
		for(int j=0;j<D;j++)
		{
			for(int denum=0;denum<10;denum++)
			{
				(Dp[i][j]+=Dp[i-1][((j-denum)%D+D)%D])%=MOD;
			}
		}
	}
	cout<<(Dp[N][0]-1+MOD)%MOD<<endl;
	return 0;
}

Measured memory_bytes: 8832
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt( sc.nextLine() );
        String[] params = sc.nextLine().split(" " );
        int[] xs = new int[n];
        int minPos = 1000;
        int maxPos = 0;
        for( int i = 0 ; i < n ; i++ ){
            xs[i] = Integer.parseInt( params[i] );
            if( xs[i] < minPos ){
                minPos = xs[i];
            }
            if( maxPos < xs[i] ){
                maxPos = xs[i];
            }
        }

        int minHp = 100000000;
        for( int i = minPos ; i <= maxPos ; i++ ){
            int hpTotal = 0;
            for( int j = 0 ; j < n ; j++ ){
                hpTotal += ( xs[j] - i ) * ( xs[j] - i );
            }
            if( hpTotal < minHp ){
                minHp = hpTotal;
            }
        }

        System.out.println( minHp );

    }


}


Measured memory_bytes: 22608
n=int(input())
a=list(map(int,input().split()))
b=[10**10]
a.sort(reverse=True)
c=a[0]
e=c//2
for i in range(1,n):
    b.append(abs(a[i]-e))
d=a[b.index(min(b))]
print(c,d)

Measured memory_bytes: 14052
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }


int main(){
    int A,B,K;
    cin >> A >> B >> K;
    int cnt=0;
    for(int i=min(A,B); i>0; i--){
        if (A%i==0 && B%i==0){
            cnt ++;
            if (cnt==K){
                cout << i << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
    vector<int> v;
    int q;
    cin >> q;
    int num, qst;
    for (int i = 0; i < q; i++) {
        cin >> qst;
        if (qst == 0) {
            cin >> num;
            v.push_back(num);
        } else if (qst == 1) {
            cin >> num;
            cout << v[num] << endl;
        } else {
            v.pop_back();
        }
    }
    
    return 0;
}



Measured memory_bytes: 3828
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>; using vvi = vector<vector<int>>;
using vl = vector<ll>; using vvl = vector<vector<ll>>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n;
  cin >> n;
  REP(i,10){
    if(n<=i*111){
      cout << i*111 << endl;
      return 0;
    }
  }
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N+2);
  vector<int> C(N+1);
  A.at(0)=0;
  A.at(N+1)=0;
  int cost=0;
  for(int i=1; i<N+1; i++){
    cin >> A.at(i);
    C.at(i-1)=abs(A.at(i)-A.at(i-1));
    cost+=C.at(i-1);
  }
  C.at(N)=abs(A.at(N)-0);
  cost+=C.at(N);
  
  for(int i=0; i<N; i++){
    int ans;
    ans=cost-(C.at(i)+C.at(i+1))+abs(A.at(i)-A.at(i+2));
    cout << ans << endl; 
  }
}

Measured memory_bytes: 2048
object Main {
  def solve(result: Array[Array[Int]]): (Array[Int], Array[Boolean]) = {
    val rank = result.map(res => res.map(s => (if (s != -1) 1 else 0)).sum)
    val time = result.map(_.sum)
    val ret = rank.zipWithIndex.sortWith((p, q) => {
      if (p._1 == q._1)
        if (time(p._2) == time(q._2)) p._2 > q._2
        else time(p._2) < time(q._2)
      else p._1 > q._1
    }).map(p => p._2 + 1)
    val eq = ret.init.zip(ret.tail).map(p =>
      rank(p._1 - 1) == rank(p._2 - 1) && time(p._1 - 1) == time(p._2 - 1))
    (ret, eq)
  }

  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var f = true
    while(f) {
      val m, t, p, r = sc.nextInt
      if(m == 0 && t == 0 && p == 0 && r == 0) f = false
      else {
        val result = Array.fill[Int](t, p)(-1)
        val penalty = Array.ofDim[Int](t, p)
        for(_ <- 1 to r) {
          val mm, tt, pp, j = sc.nextInt
          if (j == 0) result(tt - 1)(pp - 1) = mm + penalty(tt - 1)(pp - 1) * 20
          else penalty(tt - 1)(pp - 1) += 1
        }
        val (rank, eq) = solve(result)
        rank.init.zip(eq).foreach( x => if (x._2) print (x._1 + "=")
                                        else print (x._1 + ","))
        println(rank.last)
      }
    }
  }
}

Measured memory_bytes: 87800
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

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

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int a, b, c;
	cin >> a >> b >> c;
	for(int i = b; i <= c; i++) {
		if(i % a == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	
}





Measured memory_bytes: 3652
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	// 勉強用。先人の丸パクリです
	var s string
	fmt.Scan(&s)
	//スラッシュでsplitさせてAtoi
	ss := strings.Split(s, "/")
	a ,_ := strconv.Atoi(ss[0])
	b ,_ := strconv.Atoi(ss[1])
	c ,_ := strconv.Atoi(ss[2])
	if a <= 2019 && b <= 4 && c <= 30 {
		fmt.Println("Heisei")
		return
	}
	fmt.Println("TBD")
  //ひどいなこれは
}

Measured memory_bytes: 640
import collections
n = int(input())
a = input().split()
a = [int(m) for m in a]
a.sort()
c = collections.Counter(a)
count = 0
for i in c:
    if c[i] % 2 == 0:
        count += 1
if count % 2 == 0:
    print(len(c))
else:
    print(len(c) - 1)


Measured memory_bytes: 18648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll x, y;
  cin >> x >> y;
  cout << (abs(x - y) <= 1 ? "Brown" : "Alice") << endl;
}

Measured memory_bytes: 256
import java.awt.geom.Point2D;
import java.util.*;


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


	class AOJ0110{
		int cnt;
		int[] list;
		int n;
		public AOJ0110() {
			while(true){
				n = in.nextInt();
				cnt=0;
				if(n==0)break;
				list = new int[n];
				for(int i=0;i<n;i++)list[i] = in.nextInt();
				bubble();
				System.out.println(cnt);
			}
		}
		void bubble(){
			for(int s=0;s<n;s++){
				for(int i=0;i<n-1;i++)if(list[i]>list[i+1])change(i,i+1);
			}
		}
		
		void change(int index1,int index2){
			int a = list[index1];
			list[index1] = list[index2];
			list[index2] = a;
			cnt++;
			return;
		}
	}
	
}

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  ll n; cin>>n;
  vector<ll> p(n);
  rep(i, n) {
    cin>>p[i]; p[i]--;
  }
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) {
    a[i] = 30000*(i+1);
    b[i] = 30000*(n-i);
  }
  rep(i, n) {
    a[p[i]] += i;
  }

  for (auto v:a) cout << v << " ";
  cout << endl;
  for (auto v:b) cout << v << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 3800
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(int n, vector<pair<int,int>>& edges) {
        const long long MOD = 1e9 + 7;
        auto norm = [&](long long a) {
            a %= MOD;
            if (a < 0) {
                a += MOD;
            }
            return a;
        };
        auto inverse = [&](long long a) {
            long long b = MOD;
            long long u = 0, v = 1;

            a = norm(a);
            while (a != 0) {
                long long d = b / a;
                b -= d * a;
                u -= d * v;
                swap(a, b);
                swap(u, v);
            }
            return norm(u);
        };

        vector<long long> pow2(n + 1, 1);
        for (int i = 1; i <= n; ++i) {
            pow2[i] = pow2[i - 1] * 2 % MOD;
        }

        vector<vector<int>> graph(n);
        vector<int> pars(n, -1);
        vector<int> sizes(n, 0);

        for (auto& e : edges) {
            int u = e.first, v = e.second;
            graph[u].push_back(v);
            graph[v].push_back(u);
        }

        int rt = 0;
        vector<int> ord;
        ord.push_back(rt);
        for (int i = 0; i < ord.size(); ++i) {
            int u = ord[i];
            for (auto v : graph[u]) {
                if (v == pars[u]) {
                    continue;
                }
                pars[v] = u;
                ord.push_back(v);
            }
        }

        long long res = 0;

        reverse(ord.begin(),ord.end());
        for (auto u : ord) {
            sizes[u] = 1;
            for (auto v : graph[u]) {
                if (v == pars[u]) {
                    continue;
                }
                sizes[u] += sizes[v];
            }
            res += (1 - inverse(pow2[sizes[u]]) + MOD) % MOD * (1 - inverse(pow2[n - sizes[u]]) + MOD) % MOD;
        }


        res = (res + (1 - inverse(pow2[n]) + MOD) % MOD - n * ((MOD + 1) / 2) % MOD) % MOD;
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<int,int>> edges;
    for (int i = 0; i + 1 < n; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        edges.emplace_back(u, v);
    }

    Solution sol;
    cout << sol.solve(n, edges) << "\n";

    return 0;
}

Measured memory_bytes: 17904
#include <stdio.h>
#define X 1
#define Y 2

int main(void){
    // Your code here!
    int xy[5][3],dx,dy;
    scanf("%d %d %d %d",&xy[1][X], &xy[1][Y],&xy[2][X],&xy[2][Y]);
    dx = xy[2][X]-xy[1][X];
    dy = xy[2][Y]-xy[1][Y];
    xy[3][X] = xy[2][X] - dy;
    xy[3][Y] = xy[2][Y] + dx;
    xy[4][X] = xy[3][X] - dx;
    xy[4][Y] = xy[3][Y] - dy;
    printf("%d %d %d %d\n",xy[3][X],xy[3][Y],xy[4][X],xy[4][Y]);
}


Measured memory_bytes: 128
#include <iostream>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main(){
	int K, X;
	cin >> K >> X;
	if(500*K>=X){
		cout << "Yes";
	}else{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N, K;
int P[212345];

int main() {
	cin >> N >> K;
	REP(i, N) scanf("%d", P + i);
	
	double ans = 0;
	double sum = 0;
	REP(i, N) {
		if (i >= K) sum -= (double)(1 + P[i - K]) * P[i - K] / 2 / P[i - K];
		sum += (double)(1 + P[i]) * P[i] / 2 / P[i];
		if (i >= K - 1) {
			chmax(ans, sum);
		}
	}
	
	printf("%.15lf\n", ans);
	
	return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int r;
	cin >> r;
	cout << 3 * r * r << endl;
}


Measured memory_bytes: 3652
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,m,i,j,k;cin>>n>>m;
	vector<string>mat(n+2);
	for(i=1;i<=n;i++){cin>>mat[i];}
	mat[0]=string(m+2,'#');
	mat[n+1]=string(m+2,'#');
	for(i=1;i<=n;i++){
		mat[i].insert(mat[i].begin(),'#');
		mat[i].pub('#');
	}
	int sx,sy,gx,gy,smuki;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(mat[i][j]=='G'){mat[i][j]='.';gy=i;gx=j;}
			if(mat[i][j]=='^'){mat[i][j]='!';sy=i;sx=j;smuki=0;}
			if(mat[i][j]=='>'){mat[i][j]='!';sy=i;sx=j;smuki=1;}
			if(mat[i][j]=='v'){mat[i][j]='!';sy=i;sx=j;smuki=2;}
			if(mat[i][j]=='<'){mat[i][j]='!';sy=i;sx=j;smuki=3;}
		}
	}
	
	int nx=sx,ny=sy,muki=smuki;
	int dy[4]={-1,0,1,0};
	int dx[4]={0,1,0,-1};
	while(-1){
		mat[ny][nx]='!';
		if(ny==gy&&nx==gx){break;}
		//cerr<<nx<<ny<<endl;
		if(mat[ny+dy[muki]][nx+dx[muki]]=='#'){muki+=3;muki&=3;}
		else if(mat[ny+dy[muki]+dy[(muki+1)&3]][nx+dx[muki]+dx[(muki+1)&3]]=='#'){ny+=dy[muki];nx+=dx[muki];}
		else{ny+=dy[muki];nx+=dx[muki];mat[ny][nx]='!';if(ny==gy&&nx==gx){break;}muki++;muki&=3;ny+=dy[muki];nx+=dx[muki];}
		
		if(ny==sy&&nx==sx&&muki==smuki){cout<<-1<<endl;return 0;}
	}
	int ans=0;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(mat[i][j]=='!'){ans++;}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3188
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n <= m then  List.range n `To m else []
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'
let itoa n = Char.chr (n + Char.code '0')

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let a = scan_list ~sep:' ' Int.of_string
let q = scan "%d" id
let bc = scan_lines q "%d %d" Tuple2.make

let () =
  let h = Hashtbl.create n in
  ListL.iter a ~f:(fun a ->
      Hashtbl.modify_def 0 a succ h);
  let total = a |> List.sum in
  ListL.fold_left bc ~init:total ~f:(fun total (b,c) ->
      let n = Hashtbl.find_default h b 0 in
      let total = total - b*n + c*n in
      Printf.printf "%d\n" total;
      Hashtbl.remove_all h b;
      Hashtbl.modify_def 0 c ((+) n) h; total
    ) |> ignore


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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) (a.begin(), a.end())
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////


void solve() {
	int a[E5];	
	int n,k;
	cin >> n >> k;
	for (int i=0;i<n;++i) {
		cin >> a[i];
	}

	if (n <= k) {
		cout << 1 << '\n';
		return;
	} else {
		n -= k;
		int ans = 1;
		ans += (n%(k-1) ? n/(k-1)+1 : n/(k-1));
		cout << ans << '\n';
	}
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

	//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main(){
    int i,n,j,a=0,b=0;
    cin >> n;
    for (i = 1; i<= n; i++){
        for(j = 1; j<= n; j++){
            if(i%j==0){
                a++;
            }
        }

        if(a ==8){
            b++;
        }
        a = 0;
        i++;
    }

    cout << b;
}

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

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

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

	int n, m;
	cin >> n >> m;

	vi d(51);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		d[a]++; d[b]++;
	}

	for (int i = 1; i <= n; i++) {
		cout << d[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cassert>
#include<utility>
#include<algorithm>
#include<complex>
using namespace std;
int main(){
  string s;
  int ans=0;
  cin>>s;
  for(int i=0;i<3;i++){
    if(s[i]=='1')ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

def main():
    n,m = mi()
    mm = min(n,m)
    mn = max(n,m)

    s = ''
    for i in range(mn):
        s+=str(mm)
    print(s)

main()


Measured memory_bytes: 5716
N = int(input())
D = [list(input()) for _ in range(N)]

cnt = 0

for j in range(N):
    if D[j][0] == D[j][2]:
        cnt +=1 
    elif cnt < 3 and D[j][0] != D[j][2]:
        cnt = 0

if cnt >= 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9188
N = int(input())
S = [input() for _ in range(N)]
march = "MARCH"
dic = {"M":0,"A":0,"R":0,"C":0,"H":0}
for s in S:
    if s[0] in march:
        dic[s[0]] += 1
ans = 0
ans += dic["M"]*dic["A"]*dic["R"]
ans += dic["M"]*dic["A"]*dic["C"]
ans += dic["M"]*dic["A"]*dic["H"]
ans += dic["M"]*dic["R"]*dic["C"]
ans += dic["M"]*dic["R"]*dic["H"]
ans += dic["M"]*dic["C"]*dic["H"]
ans += dic["A"]*dic["R"]*dic["C"]
ans += dic["A"]*dic["R"]*dic["H"]
ans += dic["A"]*dic["C"]*dic["H"]
ans += dic["R"]*dic["C"]*dic["H"]
print(ans)

Measured memory_bytes: 9772
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	// ビンゴの正誤表
	bingo := [3][3]bool{
		{false, false, false},
		{false, false, false},
		{false, false, false},
	}

	// ビンゴカード
	A := [3][3]int{}
	for y := 0; y < 3; y++ {
		var err error
		scanner.Scan()
		target := strings.Split(scanner.Text(), " ")
		for x := 0; x < 3; x++ {
			A[y][x], err = strconv.Atoi(target[x])
			if err != nil {
				log.Fatal(err)
			}
		}
	}

	// N
	scanner.Scan()
	N, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	b := make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		target, err := strconv.Atoi(scanner.Text())
		if err != nil {
			log.Fatal(err)
		}
		b[i] = target
	}
	for i := 0; i < len(b); i++ {
		for h := 0; h < 3; h++ {
			for w := 0; w < 3; w++ {
				if A[h][w] == b[i] {
					bingo[h][w] = true
				}
			}
		}
	}

	if bingo[0][0] == true && bingo[0][1] == true && bingo[0][2] == true {
		fmt.Println("Yes")
		os.Exit(0)
	}
	if bingo[1][0] == true && bingo[1][1] == true && bingo[1][2] == true {
		fmt.Println("Yes")
		os.Exit(0)
	}
	if bingo[2][0] == true && bingo[2][1] == true && bingo[2][2] == true {
		fmt.Println("Yes")
		os.Exit(0)
	}
	if bingo[0][0] == true && bingo[1][0] == true && bingo[2][0] == true {
		fmt.Println("Yes")
		os.Exit(0)
	}
	if bingo[0][1] == true && bingo[1][1] == true && bingo[2][1] == true {
		fmt.Println("Yes")
		os.Exit(0)
	}
	if bingo[0][2] == true && bingo[1][2] == true && bingo[2][2] == true {
		fmt.Println("Yes")
		os.Exit(0)
	}
	if bingo[0][0] == true && bingo[1][1] == true && bingo[2][2] == true {
		fmt.Println("Yes")
		os.Exit(0)
	}
	if bingo[2][0] == true && bingo[1][1] == true && bingo[0][2] == true {
		fmt.Println("Yes")
		os.Exit(0)
	}

	fmt.Println("No")

}


Measured memory_bytes: 1844
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, D: int, X: "List[int]", Y: "List[int]"):
    ret = 0
    for i in range(N):
        if X[i] * X[i] + Y[i] * Y[i] <= D * D:
            ret += 1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    Y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, D, X, Y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 71548
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

set<pi> st;
pi ar[M];

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

	ll n,i,ans = 1,v;

	cin >> n;
	for(i=1;i<=n;++i)
		cin >> ar[i].ff >> ar[i].ss;
	sort(ar+1,ar+1+n);
	for(i=1;i<=n;++i)
	{
		auto it = st.lower_bound(pi(ar[i].ss-ar[i].ff,-5));
		if(it == st.end())
			v = 1;
		else
			v = (*it).ss+1;
		auto gt = st.lower_bound(pi(-ar[i].ss-ar[i].ff,-5));
		if(gt == st.end())
			st.insert(pi(-ar[i].ss-ar[i].ff,v));
		else if((*gt).ss < v)
		{
			if((*gt).ff == -ar[i].ss-ar[i].ff)
				st.erase(gt);
			st.insert(pi(-ar[i].ss-ar[i].ff,v));
			auto vt = st.begin();
			while((*vt) != pi(-ar[i].ss-ar[i].ff,v))
			{
				st.erase(vt);
				vt = st.begin();
			}
		}

		ans = max(ans,v);
	}
	cout << ans << "\n";
}


Measured memory_bytes: 11360
#include <bits/stdc++.h>
using namespace std;
#define int long long
void run();
signed main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13); run(); return 0; }
mt19937 rng(random_device{}());

void run() {
   int n;
    cin >> n;
    int x[n];
    for (int i = 0; i < n; ++i)
        cin >> x[i];
    int ans = 1000000000;
    for (int i = 1; i <= 100; ++i) {
        int pos = 0;
        for (int j : x)
            pos += (i - j) * (i - j);
        if (ans > pos) {
            ans = pos;
        }
    }
cout << ans;

}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, k; cin >> n >> k;
    string s; cin >> s;

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

    cout << min(ans + 2 * k, n-1) << endl;
}

Measured memory_bytes: 512
# https://atcoder.jp/contests/abc153/tasks/abc153_f
# 座標圧縮、貪欲法、imos法


import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


# まず、何回攻撃すればいいのかを計算する。これがとにかく必要だ(なくてもいいけど)。
#
# 素直な戦略として、左から倒せるギリギリの爆弾を投下して倒すのが最適
# だけどナイーブに実装すると、O(N^2)。だから体力を管理するのが重要。
# どこにどれだけダメージが蓄積したのかはimos法(デルタ関数をおいてから累積和)で管理できる。

from bisect import bisect_left
N, D, A = read_ints()
XH = read_tuple(N)
XH.sort()  # 座標でソート

n_atk = []  # 何回攻撃するのが必要か
X = []  # 座標アクセス用配列
for x, h in XH:
    n_atk.append((h - 1) // A + 1)
    X.append(x)

damege = [0] * (N + 10)  # ダメージ管理用、配列外アクセスがめんどくさいので長めに取る
ans = 0
j = 0  # 次のxが、今のx+2d以下でもっとも大きなidx
for i, (x, n) in enumerate(zip(X, n_atk)):
    damege[i] += damege[i - 1]  # 積分して、現時点の蓄積回数を表示
    atk = max(0, n - damege[i])  # iには何回攻撃したか
    ans += atk
    # 攻撃下回数を記録
    damege[i] += atk
    # 効果が切れる点を予約 # 尺取ならO(1)で次に行けるけど二分探索でも間に合うか
    while j < len(X) and X[j] < x + 2 * D + 1:
        j += 1
    damege[j] -= atk  # 効果切れを予約

print(ans)


Measured memory_bytes: 99164
#include <stdio.h>
#include <stdlib.h>
#pragma warning (disable : 4996)

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

int main(void) {
 int i, n = 0, N, K, l[50];
  scanf ("%d %d", &N ,&K);
  
  for (i = 0; i < N; i++) { 
   scanf ("%d", &l[i]);
  }
  
  qsort(l, N, sizeof(int), desc);
  
  for(i = 0; i < K; i++) {
    n += l[i];
  }

  
  printf("%d", n);
}


Measured memory_bytes: 128
n,k = map(int,input().split())
H = list(map(int,input().split()))
dp = [0]*n

if n <= k:
    print(abs(H[0]-H[-1]))
else:
    for i in range(1,k+1):
        dp[i] = abs(H[i]-H[0])
    for i in range(k+1,n):
        res = abs(H[i]-H[i-k])+dp[i-k]
        for j in range(1,k):
            res = min(res,abs(H[i]-H[i-j])+dp[i-j])
        dp[i] = res
    print(dp[n-1]) 

Measured memory_bytes: 52448
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K,Q;
    cin>>N>>K>>Q;
    vector<int> score(N+1,K-Q);
    for(int i=1;i<=Q;i++){
        int temp;
        cin>>temp;
        score[temp]++;
    }
    for(int i=1;i<=N;i++){
        if(score[i]<=0){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024