akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
using ll = long long;

int main(){
    ll x;
    cin>>x;
    for(ll a=-200;a<=200;a++){
        for(ll b=-200;b<=200;b++){
            if(a*a*a*a*a-b*b*b*b*b==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define N 100005
#define INF 0x3f3f3f3f 
#define mod 1000000007
using namespace std;
typedef long long ll;
int ans;

int main(){
    int n, m;
    cin >> n >> m;
    for(int i=(m/n)+1; i>0; i--){
        if(m%i == 0 and i*n <= m){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    vector<LLONG> as(N + 1);
    as[0] = 0;
    for (int i = 1; i <= N; ++i)
    {
        cin >> as[i];
    }
    int orig = 0;
    for (int i = 0; i <= N; ++i)
    {
        orig += llabs(as[i] - as[(i + 1) % (N + 1)]);
    }
    for (int i = 1; i <= N; ++i)
    {
        cout << orig - llabs(as[i - 1] - as[i]) - llabs(as[i] - as[(i + 1) % (N + 1)])
            + llabs(as[i - 1] - as[(i + 1) % (N + 1)]) << endl;
    }
}


Measured memory_bytes: 4048
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower

using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        int N, K;
        cin >> N >> K;
        if (N * K % 2 == 0)
        {
                puts("Even");
        }
        else
        {
                puts("Odd");
        }

        return 0;
}


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

int A,B,C,D;

int main() {
    cin>>A>>B>>C>>D;
    string ans;
    for (; A>0&&B>0;) {
        C-=B;
        A-=D;
        if (C<=0) ans="Yes";
        else if (A<=0) ans="No";
    }
    cout<<ans<<endl;
    return 0;
}


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

int n, m, dist[100001], p = 1, total = 0;

int main(){
  dist[1] = 0;
  cin >> n >> m;
  for(int i = 2; i <= n; i++){
    int in;
    cin >> in;
    dist[i] = dist[i - 1] + in;
  }

  for(int i = 0; i < m; i++){
    int move;
    cin >> move;
    if(0 < move){
      total += dist[p + move] - dist[p];
    }
    else{
      total += dist[p] - dist[p + move];
    }
    p += move;
    total %= 100000;
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 1548
import sys
from itertools import count

def makeprime():
  num = 2
  while num <= 55555:
    m = num - 1
    while m > 1 and num % m != 0:
      m -= 1
    if m == 1:
      yield num
      num += 1
    else:
      num += 1 


def main():
  input = sys.stdin.readline
  N = int(input())
  p = makeprime()
  A = []
  while len(A) < N:
    np = next(p)
    if np % 5 == 1:
      A.append(np)
  for n in A:
    print(n, end=' ')


if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e9+7;
const ll N = 1000003;
ll n;
vector<ll> a,b;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;a.resize(n);b.resize(n);
	FOR(i,0,n){
		cin>>a[i]>>b[i];
	}
	ll ans=0;
	REV(a);REV(b);
	FOR(i,0,n){
		ll k=ans+a[i];
		if(k%b[i]!=0)ans+=(b[i]-k%b[i]);
	}
	cout<<ans<<endl;
	return 0;
}


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

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        sc.close();
        System.out.println((x/100>=(x%100)/5+((x%100%5!=0)?1:0))?1:0);
    }
}

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

using namespace std;

int solve(){
    int n;
    cin>>n;
    if(n==0)return -1;
    int ans=0;
    int ansn;
    for (int i = 0; i < n; ++i) {
        int t;
        int a,b;
        cin>>t>>a>>b;

        if(ans<a+b){
            ans=a+b;
            ansn=t;
        }
    }
    cout<<ansn<<" "<<ans<<endl;
    return 0;
}

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


Measured memory_bytes: 3004
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
dif = 1000
for i in range(N):
    Tx = T - H[i] * 0.006
    if  abs(Tx - A) < dif:
        dif = abs(Tx - A)
        ans = i + 1
print(ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>

#define mod 10007;
int dp[1001][10] = { 0 };
char s[1001];
int m[1001];
char tmp[] = { "JOI" };

int main() {
	int n;

	scanf("%d %s", &n,s);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			if (s[i] == tmp[j]) m[i+1] = j;
		}
		//printf("%d ", m[i + 1]);
	}

	for (int i = 0; i < (1 << 3); i++) {
		if ((i >> m[1]) & 1 && (i & 1)) dp[1][i] = 1;
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < (1 << 3); j++) {
			if (!((j >> m[i]) & 1)) continue;
			for (int l = 0; l < (1 << 3); l++) {
				if (j&l) {
					dp[i][j] += dp[i - 1][l];
					dp[i][j] %= mod;
				}
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < (1 << 3); i++) {
		ans += dp[n][i];
		ans %= mod;
	}
	printf("%d\n", ans);
}



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

using namespace std;

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

  if (n%2 == 0) {
    cout << (n * (n/2))-(n/2) << endl;
  } else {
    cout << (n * (n/2)) << endl;
  }
  return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD


ll N,A[303030];
ll mk[303030];
ll ans[303030];
vector<ll> dv[303030];
ll i,j,k,l,m;



int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld",&A[i]);
        mk[A[i]-1]++;
    }
    sort(mk,mk+N,greater<ll>());
    
    j=0;
    k=N;
    l=0;
    m=N;
    fornum(i,0,N){
        l+=m;
        //printf("%lld,%lld,%lld,%lld,%lld\n",i,j,k,l,m);
        if(m==mk[j]){
            j++;
        }
        while(m>0&&j<i&&l>k){
            l-=i+1-j;
            m--;
            while(j<i&&m==mk[j]){
                j++;
            }
        }
        //printf("%lld,%lld,%lld,%lld,%lld\n",i,j,k,l,m);
        printf("%lld\n",j<i?m:min(m,k));
        l-=mk[i];
        k-=mk[i];
    }
    
    
    return 0;
}

Measured memory_bytes: 15104
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

string X;
string Y;

int calc(int x, int y, vector<vector<int> >& Memo){
    if (X[x] == '\0' || Y[y] == '\0') return 0;
    if (Memo[x][y] != -1) return Memo[x][y];

    int unuse = calc(x + 1, y, Memo);
    int use = 0;
    int y_target = Y.find(X[x], y);
    if (y_target == string::npos) {
        use = 0;
    } else {
        use = calc(x + 1, y_target + 1, Memo) + 1;
    }
    return Memo[x][y] = max(unuse, use);
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> X;
        cin >> Y;
        vector<int> tmp(Y.size(), -1);
        vector<vector<int> > Memo(X.size(), tmp);
        cout << calc(0, 0, Memo) << endl;
    }

    return 0;
}

Measured memory_bytes: 6908
#include<iostream>
#include<string>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
#include <vector>
#include<limits.h>
#include<math.h>
using namespace std;

#define rep(i,M,N) for (int i = M; i <= N; i++)
#define rep1(i,M,N) for (int i = M; i >= N; i--)
#define getArray(a,n) rep(i,0,n-1) cin >> a[i];
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
int getNum(vector<int> &a){
    int count = 0;
    long sum = 0;
    sort(a.begin(), a.end());
    for(int x : a){
        if(x > sum*2){
            count = 1;
        }else count ++;
        sum += x;
    }
    return count;
}

int main() {
    
    int n,ai;
    vector<int> a;
    while(cin>>n){
        rep(i,0,n-1){
            cin>>ai;
            a.push_back(ai);
        }
        cout<<getNum(a)<<endl;
    }
    return 0;
}


Measured memory_bytes: 892
#include <stdio.h>

int main(void)

{
int x, a, b, c, yakusu = 0;

scanf("%d %d %d", &a, &b, &c);

for(x = a;x <= b;x++)
{
if(c % x == 0)
{
yakusu = yakusu + 1;
}
}

printf("%d\n", yakusu);

return 0;

}


Measured memory_bytes: 2112
import java.util.*;

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

        for (char c : string.toCharArray()) {
            System.out.print(Character.isUpperCase(c)?
                    Character.toLowerCase(c) : Character.toUpperCase(c));
        }
        System.out.println();
    }
}

Measured memory_bytes: 26788
//ITP 1_4_A
#include <iostream>
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    
    int d,r;
    double f;
    
    d = a / b;
    r = a % b;
    f = 1.0 * a / b;
    
    printf("%d %d %6lf\n",d,r,f);
    return 0;
}


Measured memory_bytes: 3220
# coding: utf-8
# Your code here!

while True:
   N = int(input())
   if N == 0: break
   
   c = 0
   for i in range(1, N // 2 + 2):
      sum = 0
      for j in range(i, N // 2 + 2):
         sum += j
         if sum == N and j != N:
            c += 1
            break
   print(c)



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

Measured memory_bytes: 7644
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using lli = long long int;
ll MM = 1000000000;
ll mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)

int main(){
    ll n; cin >> n;
    ll a[n+2];
    a[0] = 0;
    ll len = 0;
    ll ans = 0;
    for(ll i = 1; i < n+1; i++){
        cin >> a[i];
    }
    a[n+1] = 0;
    for(ll i = 1; i < n+2; i++){
        len += abs(a[i-1] - a[i]);
    }
    ans = len;
    for(ll i = 1; i < n+1; i++){
        ans += abs(a[i-1] - a[i+1]);
        ans -= abs(a[i-1] - a[i]) + abs(a[i] - a[i+1]);
        cout << ans << endl;
        ans = len;
    }
}

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

int main()
{
  int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int k;
  cin>>k;

   cout<<arr[k-1];
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;

ll n,m,a;
string s,t,b;

int main() {
  cin >> a >> s;
  for(char c : s)if(c!='.') b+=c;
  cout << ll(a*stoi(b)/100) << endl;
}

Measured memory_bytes: 3624
using namespace std;
#include<bits/stdc++.h>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define st first
#define nd second
#define FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define FORD(i,a,b) for(int i=(a),b_=(b);i>=b_;--i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define removeDuplicate(a) sort(a.begin(), a.end()); a.resize(distance(a.begin(), unique(a.begin(), a.end())))
 
const int N = 2e5 + 1;
const int MOD = 1e9 + 7; 


 
int main() {
    #define TASK "TASK"	
	// freopen(TASK".inp","r",stdin);
	// freopen(TASK".out","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; 
	cin >> n ; 
	vector <int> a(n + 1), b(n + 1), c(n + 1), dp(n + 1), dp1(n + 1), dp2(n + 1); 
	for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i] >> c[i]; 
	for (int i = 1; i <= n; ++i) {
		dp[i] = max(dp[i], max(dp1[i - 1] + a[i], dp2[i - 1] + a[i]));
		dp1[i] = max(dp1[i], max(dp[i - 1] + b[i], dp2[i - 1] + b[i])); 
		dp2[i] = max(dp2[i], max(dp1[i - 1] + c[i], dp[i - 1] + c[i])); 
	}
	cout << max(max(dp[n], dp2[n]), dp1[n]) << endl; 
     
  	return 0;
}

Measured memory_bytes: 5476
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;

void ABC138B()
{
	int N;
	cin >> N;

	vector<int> A(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	sort(A.begin(), A.end());

	double denom = 0.0;
	for (auto p = A.rbegin(); p != A.rend(); ++p)
	{
		denom += 1.0 / *p;
	}
	double ret = 1.0 / denom;
	cout << std::fixed << std::setprecision(10) << ret << endl;
}

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

Measured memory_bytes: 256
-- | Main entry point to the application.
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Debug.Trace
import Text.Printf

rInt :: String -> Int
rInt str = read str :: Int

tupleFromLine :: String -> (Int, Int)
tupleFromLine str =
    case words str of
        [x, y] -> (rInt x, rInt y)
        
sortTuple (x, y)
    | x <= y = (x, y)
    | x > y = (y, x)

-- | The main entry point.
main :: IO ()
main = do
    --[w, h, x, y, r] <- (map rInt . words) <$> getLine
    s <- getContents
    let lst = map tupleFromLine $ lines s
    forM_ [0..(length lst - 2)] $ \i -> do
        printf "%d %d\n" (fst $ sortTuple (lst !! i)) (snd $ sortTuple (lst !! i))

Measured memory_bytes: 5260
#include<iostream>
using namespace std;
int main(){
    int floor[4][3][10]={{{}}},n,b,f,r,v;
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> b >> f >> r >> v;
      floor[b-1][f-1][r-1] += v;
    }
    for(int i=0;i<4;i++){
      for(int j=0;j<3;j++){
	for(int k=0;k<10;k++){
	  cout << " " << floor[i][j][k];
	}
	cout << endl;
      }
      if(i!=3)
	cout << "####################" << endl;
    }
}




Measured memory_bytes: 3112
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))

from collections import Counter
dc = Counter(d)
tc = Counter(t)

ans = 'YES'
for dif, num in tc.items():
    if dc[dif] < num:
        # 足りない
        ans = 'NO'
        break

print(ans)

Measured memory_bytes: 167092
#include<iostream>
using namespace std;
int main() {
    int W;
    int H;
    int x;
    int y;
    int r;
    cin >> W >> H >> x >> y >> r;
    if ((x-r) >= 0) {
        if ((x+r) <= W) {
            if ((y-r) >= 0) {
                if ((y+r) <= H) {
                    cout << "Yes" << endl;
                } else {
                    cout << "No" << endl;
                }
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }
return 0;
}


Measured memory_bytes: 3116
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
string s[1005];
ll n,m;
int main(){
	cin>>n>>m;
	for(ll i=0;i<n;i++)cin>>s[i];
	ll dp[n][m];
	memset(dp,0,sizeof(dp));
	for(ll i=0;i<m;i++){
		if(s[0][i]!='#')dp[0][i]=1;
		else break;
	}
	for(ll i=0;i<n;i++){
		if(s[i][0]!='#')dp[i][0]=1;
		else break;
	}
	for(ll i=1;i<n;i++){
		for(ll j=1;j<m;j++){
			if(s[i][j]!='#')dp[i][j]=(dp[i-1][j]+dp[i][j-1])%hell;
		}
	}
	cout<<dp[n-1][m-1]<<endl;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin(),(c).end())
#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define PW(n) (1LL<<(n))
using namespace std;
template <class T> inline bool CHMIN(T& a, T b) { if(a>b) { a=b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if(a<b) { a=b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(ALL(a)); }
template <class T> inline void REV(T& a) { reverse(ALL(a)); }
template <class T> inline void UNI(T& a) { SORT(a); a.erase(unique(ALL(a)),a.end()); }
template <class S, class T> ostream& operator<<(ostream& os, const pair<S,T> a) {
  return os << a.first << ' ' << a.second;
}
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int A,B;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> A >> B;
  cout << max({A+B,2*A-1,2*B-1}) << endl;

  return 0;
}

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

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}


void solve(){
     int n;cin >> n;
     int a[n];
     int sum = 0;
     REP(i,n){
        cin >> a[i];sum += a[i];
     }
     sum = sum/n;
     int ans = 0;
     int ans1 = 0;
     REP(i,n){
        ans += fast_ex(a[i]-sum,2,MOD);
        ans1 += fast_ex(a[i]-(sum+1),2,MOD);
     }
     cout << min(ans,ans1);
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

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

#define int ll

#define pb push_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

const int MAXN = 333;
double dp[MAXN][MAXN][MAXN];
bool mark[MAXN][MAXN][MAXN];
int n;

double f(int k1, int k2, int k3) {
	if(k1 < 0 || k2 < 0 || k3 < 0)
		return 0;
	if(mark[k1][k2][k3])
		return dp[k1][k2][k3];
	if(k1 + k2 + k3 == 0)
		return 0;
	double ret = n;
	ret += k1 * f(k1 - 1, k2, k3);
	ret += k2 * f(k1 + 1, k2 - 1, k3);
	ret += k3 * f(k1, k2 + 1, k3 - 1);
	ret /= k1 + k2 + k3;
	mark[k1][k2][k3] = 1;
	return dp[k1][k2][k3] = ret;
}

int32_t main() {
	cin >> n;
	vi a(n);
	for(int &x : a)
		cin >> x;
	// for(int k3 = MAXN - 1; k3 >= 0; k3--) {
	// 	for(int k2 = MAXN - 1; k2 >= 0; k2--) {
	// 		for(int k1 = MAXN - 1; k1 >= 0; k1--) {
	// 			int k0 = n - k1 - k2 - k3;
	// 			dp[k1][k2][k3] = n + dp[k1][k2 + 1][k3 - 1] + dp[k1 + 1][k2 - 1][k3] + dp[k1 - 1][k2][k3];
	// 			if(k1)
	// 				dp[k1][k2][k3] += dp[k1 - 1][k2][k3] + k1;
	// 			if(k2)
	// 				dp[k1][k2][k3] += dp[k1 + 1][k2 - 1][k3] + k2;
	// 			if(k3)
	// 				dp[k1][k2][k3] += dp[k1][k2 + 1][k3 - 1] + k3;
	// 			if(k1 + k2 + k3)
	// 				dp[k1][k2][k3] /= (k1 + k2 + k3);
	// 		}
	// 	}
	// }
	int k1 = 0, k2 = 0, k3 = 0;
	for(int i = 0; i < n; i++) {
		if(a[i] == 1)
			k1++;
		else if(a[i] == 2)
			k2++;
		else if(a[i] == 3)
			k3++;
	}
	cout << fixed << setprecision(15) << f(k1, k2, k3) << '\n';
}


Measured memory_bytes: 284928
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

// constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
// constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    sort(all(a));
    int cnt = 0;
    REP(i,0,n) REP(j,i+1,n) REP(k,j+1,n) {
        if (a[i] == a[j] || a[j] == a[k] ) continue;
        if (a[i] + a[j] > a[k]) ++cnt;
    }
    cout << cnt << endl;
}

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

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
	class Program
	{
		public class Value
		{
			public long money { get; set; }
			public List<long> skill { get; set; }
		}

		static void Main(string[] args)
		{
			var inputNum = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

			var N = inputNum[0];
			var M = inputNum[1];
			var X = inputNum[2];

			var valueList = new List<Value>();
			
			// 整数を格納するキュー
			var que = new Queue<Value>();
			var nextQue = new Queue<Value>();

			for (int i = 0;i < N; i++)
			{ 
				que = nextQue;
				nextQue = new Queue<Value>();

				var inputSkillNum = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

				if (que.Any())
				{
					// キューから全てを取り出す
					while (que.Count > 0)
					{
						var value = que.Dequeue();

						var newValue = new Value();

						newValue.money = value.money + inputSkillNum[0];
						newValue.skill = new List<long>();
						for (int x = 0; x < M; x++)
						{
							newValue.skill.Add(value.skill[x] + inputSkillNum[x + 1]);
						}
						nextQue.Enqueue(newValue);
						nextQue.Enqueue(value);
					}
					/*					foreach (var value in valueList)
										{
											var newValue = new Value();

											newValue.money = value.money + inputSkillNum[0];
											newValue.skill = new List<int>();
											for(int x = 0; x < M; x++)
											{
												newValue.skill.Add(value.skill[x] + inputSkillNum[x + 1]);
											}
											valueList.Add(newValue);
										}
					*/
				}

				var addValue = new Value();
				addValue.skill = new List<long>();
				addValue.money = inputSkillNum[0];
				for (int x = 0; x < M; x++)
				{
					addValue.skill.Add(inputSkillNum[x + 1]);
				}

				nextQue.Enqueue(addValue);
			}

			var flag = false;
			long answer = 1000000000000000000;
			while (nextQue.Count > 0)
			{
				var targetValue = nextQue.Dequeue();

				if(targetValue.skill.All(x => x >= X))
				{
					flag = true;
					if(answer > targetValue.money)
						answer = targetValue.money;
				}
			}

			if (flag)
			{
				Console.WriteLine(answer);
			}
			else
			{

				Console.WriteLine(-1);
			}



		}
	}
}

Measured memory_bytes: 30216
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
typedef long double ld;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, s, n) for(int i = s; i < n; i++)
using namespace std;

int fact(int n){
  int x = 1;
  while(n){
    x *= n;
    n--;
  }
  return x;
}

int main(){
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  int fact_n = fact(n);
  int pass_num = fact_n / n * 2;
  ld corr = (double)pass_num / fact_n;
  ld ans = 0.0;
  vector<vector<int>> pass(n, vector<int>(n));
  rep(i, n-1)rep2(j, i+1, n){
    ans += sqrt( (x[i]-x[j]) * (x[i]-x[j]) + (y[i]-y[j]) * (y[i]-y[j]) );
  }
  ans *= corr;
  cout << fixed;
  cout << setprecision(10) << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long int ll;
typedef unsigned long long int ull;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t;
  cin >>s;
  if(s=="SUN")a=7;
  if(s=="MON")a=6;
  if(s=="TUE")a=5;
  if(s=="WED")a=4;
  if(s=="THU")a=3;
  if(s=="FRI")a=2;
  if(s=="SAT")a=1;
  cout <<a;
}

Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 8/8/2018
 
 16:30-16:32 analysis
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=200+1;
int H,W;
LL C[10][10];
int A[MAX_N][MAX_N];
void solve() {
  REP(k,10)REP(i,10)REP(j,10)SMIN(C[i][j],C[i][k]+C[k][j]);
  LL res=0;
  REP(i,H)REP(j,W)if(A[i][j]!=-1)res+=C[A[i][j]][1];
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>H>>W;
  REP(i,10)REP(j,10)cin>>C[i][j];
  REP(i,H)REP(j,W)cin>>A[i][j];
  solve();
  return 0;
}


Measured memory_bytes: 512
import sys
N, M = map(int, input().split())
num = [1] * (N + 1)
red = [0] * (N + 1)
red[1] = 1
for e in sys.stdin:
    x, y = map(int, e.split())
    if red[x]:
        red[y] = 1
    num[y] += 1
    num[x] -= 1
    if num[x] == 0:
        red[x] = 0
print(sum(red))

Measured memory_bytes: 4596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <random>
#include <queue>
#include <fstream>
#include <iterator> // std::back_inserter
#include <chrono>
#include <string>
#include <stdio.h>
#include <iomanip>
#include <float.h>
#include <cassert>
#include <functional>

using namespace std;

int main(int argc, char *argv[])
{
    int a,b,c;
    int count = 0;
    string ans = "No";

    cin >> a >> b >> c;

    if(a == b) count++;
    if(a == c) count++;
    if(b == c) count++;  
   
    if(count == 1) ans = "Yes";

    cout << ans;

    return 0;
}

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

int main(){
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i=0; i<N; i++){
        cin >> A[i];
        A[i]--;
    }
    vector<int> hist;
    vector<int> seen(N, 0);
    int loop_town = -1;
    int here = 0;
    seen[0] = 1;
    hist.push_back(0);
    while(1){
        int new_town = A[here];
        if (seen[new_town] == 1){
            loop_town = new_town;
            break;
        }
        seen[new_town] = 1;
        hist.push_back(new_town);
        here = new_town;
    }

    // printf("loop\n");
    // for (int i=0; i<hist.size(); i++){
    //     printf("%d -> ", hist[i]);
    // }
    // printf("\n");

    // この時点で、 loop_town がループの起点であることがわかるので
    // loop_town がスタートから何晩目にたどり着く町なのかと
    // ループするまでに通過する街の数がわかれば良い
    int loop_start;
    for (int i=0; i<hist.size(); i++){
        if (hist[i] == loop_town){
            loop_start = i;
            break;
        }
    }
    int loop_length = hist.size() - loop_start;
    int ans = 0;
    if (K < hist.size()){
        ans = hist[K];
    } else{
        int m = ((K - ll(loop_start)) % ll(loop_length));
        ans = hist[loop_start + m];
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 5888
#include <iostream>

using namespace std;

int main()
{
    int a , b , c , x , y , z;
    cin >> x >> y >> z;
    a = x;
    b = y;
    c = z;
    swap(a , b);
    swap(a , c);
    cout << a << ' ' << b << ' ' << c;
    return 0;
}


Measured memory_bytes: 3460
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();
const int N=2e5;
vector<int>edge(N);
vector<pair<int,int>>g[N];

void dfs(int node,int p=-1,int col=-1)
{
	int color=0;
	for(auto child:g[node])
	{
		if(child.ff==p)
		{
			continue;
		}
		color++;
		if(color==col)
		{
			color++;
		}
		dfs(child.ff,node,color);
		edge[child.ss]=color;
	}
}

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int n;
	cin>>n;
	for(i=1;i<=n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back({b,i});
		g[b].push_back({a,i});
	}

	int colors=INT_MIN;

	for(i=1;i<=n;i++)
	{
		colors=max(colors,(int)g[i].size());
	}

	d(colors);
	cout<<colors<<endl;

	dfs(1);

	for(i=1;i<=n-1;i++)
	{
		cout<<edge[i]<<endl;
	}

}

Measured memory_bytes: 17200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    string s;cin>>s;
    rep(i,s.size())s[i]='x';
    cout<<s<<endl;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  string ANS=S;
  string STR="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int L;
  L=S.size();
  for (int i=0; i<L; i++) {
    for (int j=0; j<26; j++) {
      if (S.at(i)==STR.at(j) && j+N < 26) {
        ANS.at(i)=STR.at(j+N);
      }
      else if (S.at(i)==STR.at(j) && j+N >= 26) {
        int f=j+N-26;
        ANS.at(i)=STR.at(f);
      }
    }
  }
  for (int k=0; k<L-1; k++) {
    cout << ANS.at(k);
  }
  cout << ANS.at(L-1) << endl;
}


Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()

height = 0

for i in range(1,N):
    if A[i-1] > A[i]:
        height += A[i-1] - A[i]
        A[i] = A[i-1]

print(height)

Measured memory_bytes: 105040
#include <iostream>
using namespace std;
#define MAX 100
int A[MAX];
int main()
{
    int n, j;
    cin >> n;
    int key;
    for (int i = 0; i < n; i++)
    {
        cin >> j;
        A[i] = j;
    }

    for (int i = 0; i < n; i++)
    {
        key = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > key)
        {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = key;
        if (i >= 0)
        {

            for (int j = 0; j < n; j++)
            {
                if (j)
                {
                    cout << " ";
                }
                cout << A[j];
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;

struct node{
    string name;
    int time;
};
queue<node> Q;

int main(){
    int n, q;
    scanf("%d %d", &n, &q);
    node ns;
    for(int i = 0; i <n; i++){
        cin >> ns.name >> ns.time;
        Q.push(ns);
    }
    int cnt = 0;
    while(!Q.empty()){
        if(Q.front().time > q){
            Q.front().time -= q;
            cnt += q;
            Q.push(Q.front());
            Q.pop();
        }
        else if(Q.front().time > 0){
            cnt += Q.front().time;
            cout << Q.front().name << " " << cnt << endl;;
            Q.pop();
        }
    }
}



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

int main() {
  int A, B;
  cin >> A >> B;
  
  int cnt = 1;
  int ans = 0;
  while (cnt < B) {
    cnt += A - 1;
    ++ans;
    if (cnt >= B) break;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
int main()
{
	int r;
	cin>>r;
	printf("%d\n",r*r); 
return 0;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Ratio

main :: IO ()
main = do
  n <- getl toDbl
  unless (n < 0) $ do
    putStrLn . solve $ n
    main

solve :: Double -> String
solve n = g $ foldl f (toRational n,"") bs
  where
    bs = [128%1,64%1,32%1,16%1,8%1,4%1,2%1,1%1,0%1,1%2,1%4,1%8,1%16]
    f (t,xs) m
      | m == 0 = (t, '.':xs)
      | t >= m = (t - m, '1':xs)
      | otherwise = (t, '0':xs)
    g (t,xs)
      | t > 0%1 = "NA"
      | otherwise = reverse xs
    
toDbl :: String -> Double
toDbl = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4292
#include <bits/stdc++.h>
using namespace std;
long long k[80];
char s[1000010];
int main()
{
	long long n,q,d,m,dm,i,j,ans;
	scanf("%lld",&n);
	scanf("%s",&s);
	scanf("%lld",&q);
	for(i=0;i<q;i++)
		scanf("%lld",&k[i]);
	for(i=0;i<q;i++)
	{
		d=m=dm=ans=0;
		for(j=0;j<n;j++)
		{
			if(j>=k[i])
			{
				if(s[j-k[i]]=='D')
				{
					d--;
					dm-=m;
				}
				if(s[j-k[i]]=='M')
					m--;
			}
			if(s[j]=='D')
				d++;
			if(s[j]=='M')
			{
				m++;
				dm+=d;
			}
			if(s[j]=='C')
				ans+=dm;
		}
		printf("%lld\n",ans);
	}
	return 0;	
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 100000000000000000
signed main(void){
    string s;cin>>s;
    int a=0,b=0,c=0;
    rep(i,s.size()){
        if(s[i]=='a')a++;
        if(s[i]=='b')b++;
        if(s[i]=='c')c++;
    }
    if(abs(a-b)>1||abs(b-c)>1||abs(c-a)>1)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}

Measured memory_bytes: 512
N,L = map(int, input().split())

Apple = []
for i in range(1, N+1):
  Apple.append(L + i - 1)

import itertools
c = itertools.combinations(Apple, N-1)
apple_sum = sum(Apple)
near = (apple_sum + 1 )* 100
ans = 0

if 0 in Apple:
  print(apple_sum)
else:
  for v in c:
    vv = sum(v)
    if abs(apple_sum - vv) <= abs(near):
      near = apple_sum - vv
      ans = vv
  print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main(void) {
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  ll ans = 0;
  sort(a, a + n);
  sort(c, c + n);
  for (int j = 0; j < n; j++) {
    ll bottom = lower_bound(a, a + n, b[j]) - a;
    ll top = n - (upper_bound(c, c + n, b[j]) - c);
    ans += bottom * top;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int n;

constexpr int mod = 998'244'353;
constexpr int N = 300'000;

int f[N];
int comps;

bool ok = false;

int pw2[N];
vector<int> ed[N];
int used[N];
int color[N];
int good[N];
int xr[N];
bool was_m[N];

int my_pow(int x, int k) {
  if (k == 0) {
    return 1;
  }
  int g = my_pow(x, k / 2);
  g = 1ll * g * g % mod;
  if (k & 1) {
    g = 1ll * g * x % mod;
  }
  return g;
}

void go(int v, int t) {
  used[v] = t;
  color[v] = comps;
  for (auto to : ed[v]) {
    if (used[to] == 0) {
      go(to, 3 - t);
    } else if (used[to] != 3 - t) {
      ok = false;
    }
  }
}

int oper(int x) {
  if (x % 2 == 0) {
    return (x / 2) + (1 << (n - 1));
  } else {
    return (x / 2);
  }
}

int main() {
  string s;
  cin >> n;
  cin >> s;
  reverse(s.begin(), s.end());
  vector<int> d;

  pw2[0] = 1;
  for (int i = 1; i <= n; i++) {
    pw2[i] = pw2[i - 1] * 2 % mod;
  }

  for (int i = 1; i <= 2 * n; i++) {
    if ((2 * n) % i == 0) {
      d.push_back(i);
    }
  }

  for (int i = 0; i < d.size(); i++) {
    for (int j = 0; j < i; j++) {
      if (d[i] % d[j] == 0) {
        f[i] += mod - f[j];
        if (f[i] >= mod) {
          f[i] -= mod;
        }
      }
    }

    int k = d[i];
    if (k == 2 * n) {
      f[i]++;
      if (f[i] >= mod) {
        f[i] -= mod;
      }
      for (int it = 0; it < s.size(); it++) {
        f[i] += (s[it] - '0') * my_pow(2, it);
        if (f[i] >= mod) {
          f[i] -= mod;
        }
      }
      continue;
    }
    assert(k <= n);
    for (int it = 0; it < k; it++) {
      ed[it].clear();
      was_m[it] = 0;
      used[it] = 0;
      good[it] = 0;
    }

    for (int it = 0; it < k; it++) {
      ed[it].push_back((n - k + it) % k);
    }

    ok = true;
    comps = 0;
    for (int it = 0; it < k; it++) {
      if (used[it] == 0) {
        go(it, 1);
        comps++;
      }
    }


    if (!ok) {
      continue;
    }

    for (int it = 0; it < k; it++) {
      used[it]--;
    }

    int sz = comps;

    for (int it = n - 1; it >= 0; it--) {
      int v = it % k;
      int bt = s[it] - '0';
      if (was_m[color[v]]) {
        int c = used[v] ^ xr[color[v]];
        if (c < bt) {
          f[i] += pw2[sz];
          if (f[i] >= mod) {
            f[i] -= mod;
          }
          ok = false;
          break;
        }
        if (c > bt && !good[color[v]]) {
          ok = false;
          break;
        }
      } else {
        sz--;
        if (bt == 0) {
          xr[color[v]] = used[v];
        } else {
          xr[color[v]] = (used[v] ^ bt);
          f[i] += pw2[sz];
          if (f[i] >= mod) {
            f[i] -= mod;
          }
        }
        was_m[color[v]] = 1;
      }
    }
    if (ok) {
      f[i]++;
      if (f[i] >= mod) {
        f[i] -= mod;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < d.size(); i++) {
    ans += 1ll * d[i] * f[i] % mod;
     if (ans >= mod) {
      ans -= mod;
    }

  }

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 19972
#include <stdio.h>

long long int choose(long long int n){
    return n*(n-1)/2;
}

int main(void){
    long long int n;
    scanf("%lld",&n);
    long long int a[n];
    long long int s[n];
    long long int t=0;
    long long int ans=0;;
    for(int i=0; i<n; i++){
        scanf("%lld",&a[i]);
        a[i]--;
        s[i]=0;
    }
    for(int i=0; i<n; i++){
        s[a[i]]++;        
    }
    for(int i=0; i<n; i++){
        t+=choose(s[i]);
    }
    for(int i=0; i<n; i++){
        ans=t;
        ans-=choose(s[a[i]]);
        ans+=choose(s[a[i]]-1);
        printf("%lld\n",ans);
    }
    return 0;   
}

Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;
void a()
{
  int a, b;
  cin >> a >> b;
  for(int i = 0; i < 16; i++)
  {
    if(i % 2 == 0)
    {
      a--;
    }else{
      b--;
    }
  }
  if(a <= 0 && b <= 0)
  {
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
}
void b()
{
  int n, d;
  cin >> d >> n;
  if(d == 0)
  {
    if(n == 100)
    {
      cout << 101 << endl;
    }else{
      cout << n << endl;
    }
  }else if(d == 1)
  {
    if(n == 100)
    {
      cout << 10100 << endl;
    }else{
      cout << n * 100 << endl;
    }
  }else{
    if(n == 100)
    {
      cout << 1010000 << endl;
    }else{
      cout << n * 10000 << endl;
    }
  }
}
void c()
{
  int n;
  cin >> n;
  vector<long long int> a(n, 0);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  long long int total = 0;
  for(auto e : a)
  {
    if(e % 2 != 0) continue;
    while (e % 2 == 0)
    {
      e /= 2;
      total++;
    }
  }
  cout << total << endl;
}

int main() {
  int n, m;
  cin >> n >> m;
  typedef long long int ll;
  vector<tuple<ll, ll, ll>> cakes(n);
  for(int i = 0; i < n; i++)
  {
    ll x, y, z;
    cin >> x >> y >> z;
    cakes[i] = make_tuple(x, y, z);
  }
  /*
  *綺麗さ，おいしさ，人気度をそれぞれ正負で最大化することを考える．解が絶対値の和の最大だから
  * この8パターンの中に解は入っていないことはない
  * このパターン内に入っていないということはどれかの要素が最大ではないことになるため絶対値の和は必ず小さくなる
  */
  auto check = [&](int c1, int c2, int c3)
  {
    vector<ll> temp(n, 0);
    for(int i = 0; i < n; i++)
    {
      temp[i] = get<0>(cakes[i]) * c1 + get<1>(cakes[i]) * c2 + get<2>(cakes[i]) * c3;
    }
    sort(temp.begin(), temp.end());
    ll result = 0;
    for(int i = 0; i < m; i++)
    {
      result += temp[n - 1 - i];
    }
    return result;
  };
  ll result = 0;
  result = max(result, check(1, 1, 1));
  result = max(result, check(1, 1, -1));
  result = max(result, check(1, -1, 1));
  result = max(result, check(1, -1, -1));
  result = max(result, check(-1, 1, 1));
  result = max(result, check(-1, 1, -1));
  result = max(result, check(-1, -1, 1));
  result = max(result, check(-1, -1, -1));
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256