akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
using ll = long long;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
using edge = struct {
    int to;
    ll cost;
};

using Edge = pair<int, long long>; //頂点と重み
using Graph = vector<vector<Edge>>;

// vとvの親p
void rec(const Graph &G, int v, int p, long long sum, vector<long long> &dist) {
    dist[v] = sum;
    //木なので親では無かったら子供でしかない
    for(auto e : G[v]) {
        if(e.first == p) {
            continue;
        } else {
            rec(G, e.first, v, sum + e.second, dist);
        }
    }
}

int main() {
    int N;
    cin >> N;
    Graph G(N);
    for(int i = 0; i < N - 1; i++) {
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }
    int Q, K;
    cin >> Q >> K;
    K--;
    vector<long long> dist(N, 0);
    rec(G, K, -1, 0, dist);
    for(int q = 0; q < Q; q++) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        cout << dist[x] + dist[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 17408
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
N,M = map(int,input().split())
lst=[{} for f in range(N)]
for i in range(M):
 x,y=map(int,input().split())
 lst[x-1][y-1]=1
memo = {}
def cost(a):
 ans=0
 for i in lst[a]: 
  if i in memo:
    ans=max(memo[i]+1,ans)
  else:
    ans=max(cost(i)+1,ans)
 memo[a]=ans
 return ans
T=0
for i in range(N):
 T=max(T,cost(i))
print(T)

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

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

vector<pair<ll, int>> factorize(ll n) 
{
    vector<pair<ll, int>> res;
    
    for (ll i = 2; i*i <= n; ++i) 
    {
        if(n % i) continue;
        res.emplace_back(i, 0);
        while( n % i == 0 )
        {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

int main() 
{
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep (i, n) cin >> a[i];

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


    ll ans1 = 0;
    ll ans2 = 0;
    if (n % 2 == 0) {
        for (int i = 0; i < n / 2 - 1; i++) {
            ans1 += a[i] * 2LL;
        }
        for (int i = 0; i < n / 2 - 1; i++) {
            ans1 -= a[n - 1 - i] * 2LL;
        }
        ans1 += a[n / 2 - 1];
        ans1 -= a[n / 2];
        cout << ans1 << endl;
    }
    else {
        for (int i = 0; i < n / 2; i++) {
            ans1 -= a[n - 1 - i] * 2LL;
        }
        for (int i = 0; i < n / 2 - 1; i++) {
            ans1 += a[i] * 2LL;
        }
        ans1 += a[n / 2 - 1];
        ans1 += a[n / 2];

        for (int i = 0; i < n / 2; i++) {
            ans2 += a[i] * 2LL;
        }
        for (int i = 0; i < n / 2 - 1; i++) {
            ans2 -= a[n - 1 - i] * 2LL;
        }
        ans2 -= a[n / 2 + 1];
        ans2 -= a[n / 2];
        cout << max(ans1, ans2) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int r,c,n,t,x,y,ans;
map<int,int> f[N];
set<int> g[N];
struct data{int x,y;
}a[N];
int main()
{
	r=read(),c=read();n=read();ans=r+1;
	for (int i=1;i<=n;i++) a[i].x=read(),a[i].y=read(),f[a[i].x][a[i].y]=1,g[a[i].y].insert(a[i].x);
	for (int i=1;i<=c;i++) g[i].insert(r+1);
	int x=1,y=1;
	for (;x<r;)
	{
		ans=min(ans,*g[y].lower_bound(x));
		x++;if (!f[x][y+1]&&y<c) y++;
	}
	ans=min(ans,*g[y].lower_bound(x));
	cout<<ans-1;
	return 0;
}

Measured memory_bytes: 56064
#include <bits/stdc++.h>
#define MAX 10000007
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

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

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    string s;
    cin>>s;
    
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='1')
            s[i]='9';
        else if(s[i]=='9')
            s[i]='1';
    }

    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

#define MAX 1000000
bool is_prime[1000001];

int main(){

  REP(i,MAX+1){
    is_prime[i] = true;
  }
  is_prime[0] = false;
  is_prime[1] = false;

  for(int i = 2; i*i<=MAX; ++i){
    if(is_prime[i]){
      for(int j = 2; i * j <= MAX; ++j){
        is_prime[i*j] = false;
      }
    }
  }

  while(true){
    int a, d, n;
    cin >> a >> d >> n;

    if(a == 0 & d == 0 && n == 0) break;

    int cnt = 0, num = a;
    while(true){
      if(is_prime[num]){
        cnt++;
      }
      if(cnt == n) break;
      num += d;
    }
    cout << num << endl;
  }
  return 0;
}




Measured memory_bytes: 4036
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();        
        int M = stdIn.nextInt();  
        int sum = 0;
        int[] A = new int[M];      
        for (int i = 0; i < M; i++) {
            A[i] = stdIn.nextInt();
            sum += A[i];
        }
        stdIn.close();

        if (sum > N) {
            System.out.println(-1);
        } else {
            System.out.println(N - sum);
        }
    }
}

Measured memory_bytes: 39596
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	x1 := readInt()
	if x1 == 1 {
		fmt.Println("Hello World")
		return
	}
	a := readInt()
	b := readInt()
	fmt.Println(a + b)
}

func read() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	i, e := strconv.Atoi(read())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
const main = (input) => {
  const lines = input.trim().split("\n");
  const [N, M] = lines[0].split(' ').map(x => parseInt(x));
  const A = [].concat(...lines.slice(1).map(line => line.split(' ').slice(1))).map(food => parseInt(food) - 1);

  const countMap = Array(M).fill(0);
  A.forEach(food => countMap[food]++);
  const ans = countMap.filter(count => count === N).length

  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        ab: i32,
        bc: i32,
        _ca: i32,
    }
    println!("{}", bc * ab / 2);
}


Measured memory_bytes: 4352
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[][] used;
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int[][] map = new int[n][n];
        boolean[][] notCalc = new boolean[n][n];
        int[][] map2 = new int[n][n];
        long ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                map[i][j] = map2[i][j] = sc.nextInt();
            }
        }
        for(int k = 0; k < n; k++){
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    if(i == j) continue;
                    if(map[i][j] >= map[i][k]+map[k][j]){
                        map[i][j] = map[i][k]+map[k][j];
                        if(i != k && k != j) notCalc[i][j] = true;
                    }
                    
                }
            }
        }
        
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                if(map[i][j] < map2[i][j]){
                    System.out.println(-1);
                    return;
                }else if(!notCalc[i][j]){
                    ans += map[i][j];
                }
            }
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 32624
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;


int main() {

  int k, s;
  cin >> k >> s;

  int ans = 0;

  rep (x, k+1) {
    rep (y, s-x+1) {
      int z = s - x - y;
      if (x <= k && y <= k && z <= k) ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
# include <iostream>
# include <cstring>
# include <string>
# include <vector>
# include <cmath>
# include <sstream>
# include <iomanip>
# include <algorithm>
# include <fstream>
# include <memory>
using namespace std;

int main(void){
	int n, l;
	cin >> n >> l;
	vector<string> str(n);
	for(int i=0;i<n;i++){
		cin >> str[i];
	}
	sort(str.begin(), str.end());

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

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int h,w,k;
  cin>>h>>w>>k;
  int dp[h+1][w]={};
  dp[0][0]=1;
  int p=1;
  int fiv[10]={};
  fiv[0]=fiv[1]=1;
  repi(i,2,10){
    fiv[i]=fiv[i-1]+fiv[i-2];
  }
  if(w==1){
    cout<<1<<endl;
    return 0;
  }
  rep(i,h){
    rep(j,w){
      if(j==0){
	dp[i+1][j]+=(dp[i][j]*fiv[w-1])%MOD;
	dp[i+1][j]%=MOD;
	dp[i+1][j+1]+=(dp[i][j]*fiv[w-2])%MOD;
	dp[i+1][j+1]%=MOD;
      }
      else if(j==w-1){
	dp[i+1][j]+=(dp[i][j]*fiv[w-1])%MOD;
	dp[i+1][j]%=MOD;
	dp[i+1][j-1]+=(dp[i][j]*fiv[w-2])%MOD;
	dp[i+1][j-1]%=MOD;
      }
      else{
	dp[i+1][j-1]+=(dp[i][j]*fiv[j-1]*fiv[w-j-1])%MOD;
	dp[i+1][j-1]%=MOD;
	dp[i+1][j]+=(dp[i][j]*fiv[j]*fiv[w-j-1])%MOD;
	dp[i+1][j]%=MOD;
	dp[i+1][j+1]+=(dp[i][j]*fiv[j]*fiv[w-j-2])%MOD;
	dp[i+1][j+1]%=MOD;
      }
    }
  }
  rep(i,h+1){
    rep(j,w){
      // cout<<dp[i][j]<<" ";
    }
    //cout<<endl;
  }
  cout<<dp[h][k-1]<<endl;

  return 0;
}


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

using namespace std;

#define ll         long long int
#define ld          double
#define vi          vector <int>
#define vl          vector<ll>
#define vp          vector <pair<int,int>>
#define vvi         vector <vector <int>>
#define vpl         vector<pair<ll,ll>>
#define vvl         vector<vector<ll>>
#define pb          push_back
#define mp          make_pair
#define pi          pair<int,int>
#define all(a)      a.begin(),a.end()
#define tillN(a,n)  a.begin(),a.begin() + n 
#define ff          first
#define ss          second
#define minel(a)	*min_element(all(a))
#define maxel(a)	*max_element(all(a))
#define minelN(a,n) *min_element(tillN(a,n))
#define maxelN(a,n) *max_element(tillN(a,n))
#define mod         1000000007

ll inf = 1e18;

ll expo(ll x,ll y)
{
        ll ans = 1;
        while(y!=0)
        {
                if(y%2)
                {
                        ans = ans*x;
                }

                y = y>>1;
                x = x*x;
        }

        return ans;
}

ll gcd(ll a,ll b)
{
	if(a==0)
	  return b;

	 return gcd(b%a , a);
}

ll lcm(ll a, ll b)
{
	return (a*b) / gcd(a,b);
}

ll max(ll x,ll y)
{
    if(x > y)
        return x;
    return y;

}

ll min(ll x,ll y)
{
    if(x < y)
        return x;
    return y;
    
}

vl gr[200005];
vl max_path(200005);
vl vis(200005);

void dfs(ll node)
{
    vis[node] = 1;
    ll len = gr[node].size();
    ll nbr;
    for(ll i=0;i<len;i++)
    {
        nbr = gr[node][i];
        if(!vis[nbr])
        {
            dfs(nbr);
        }

        max_path[node] = max(max_path[node],max_path[nbr]+1);

    }
}

 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin >> n >> m;
    max_path[0] = -1;
    for(ll i=1;i<=n;i++)
    {
        max_path[i]=0;
        vis[i] = 0;
    }

    ll u,v;
    while(m--)
    {
        cin >> u >> v;
        gr[u].pb(v);
    }

    for(ll i=1;i<=n;i++)
    {
        if(!vis[i])
            dfs(i);
    }

    // cout << "max paths are " << endl;
    // for(ll i=0;i<=n;i++)
    //     cout << max_path[i] << " ";

    // cout << endl;

    ll ans = maxelN(max_path,n+1);
    cout << ans << endl;

}


Measured memory_bytes: 13312
x=int(input())
li =[ 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]
print(li[x-1])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
	VAR(int,n);
  VAR(string,s);
  int r=0,b=0;
  EACH(si,s){
    if(si=='R') ++r;
    else ++b;
  }

  OUT((r>b?"Yes":"No"))BR;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
  cin >> N;
  string S;
  cin >> S;
  
  int count=0;
  for (int i=0;i<N-2;i++) {
    if ((S.at(i)=='A') &&(S.at(i+1)=='B') && (S.at(i+2)=='C')) {
      count ++;
    }
  }
  cout << count << endl;
  
      
  }

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] record = new long[26];
        for(int i=0;i<N;i++){
            String cur = sc.next();
            char initial = cur.charAt(0);
            record[initial-'A'] += 1;
        }
        long[] med = new long[5];
        med[0] = record[0];
        med[1] = record['C'-'A'];
        med[2] = record['H'-'A'];
        med[3] = record['M'-'A'];
        med[4] = record['R'-'A'];
        long ans = 0;
        ans += med[0]*med[1]*med[2];
        ans += med[0]*med[1]*med[3];
        ans += med[0]*med[1]*med[4];
        ans += med[0]*med[2]*med[3];
        ans += med[0]*med[2]*med[4];
        ans += med[0]*med[3]*med[4];
        ans += med[1]*med[2]*med[3];
        ans += med[1]*med[2]*med[4];
        ans += med[1]*med[3]*med[4];
        ans += med[2]*med[3]*med[4];
        System.out.println(ans);


    }
}

Measured memory_bytes: 43740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
 
void solve(){
    ll n; cin >> n;
    string s; cin >> s;
    unordered_map<ll,ll> r, g, b;
    for(ll i = 0;i < s.length();i++){
        if(s[i] == 'R') r[i]++;
        else if(s[i] == 'G') g[i]++;
        else b[i]++;
    }
    ll count = 0;
    for(auto i:r){
        for(auto j:g){
            ll d = abs(i.ff - j.ff);
            if(!(b.find(max(i.ff,j.ff)+d) == b.end())){//cout << i.ff << " " << j.ff << endl;
                count++;
            }
            if(!(b.find(min(i.ff,j.ff)-d) == b.end())){//cout << i.ff << " " << j.ff << endl;
                count++;
            }
            if(d%2 == 0 && !(b.find(min(i.ff,j.ff)+d/2) == b.end())){//cout << i.ff << " " << j.ff << endl;
                count++;
            }
        }
    }
    //cout << count << endl;
    cout << r.size()*b.size()*g.size() - count << endl;
}

int main() {
    //int t; cin >> t; while(t--)
    solve();
    
	return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;

ll gcd(ll a,ll b) {
    if (a<b) swap(a,b);
    while (b>0) {
        ll tmp=b;
        b=a%b;
        a=tmp;
    }
    return a;
}

ll lcm(ll a,ll b) {
    ll c=gcd(a,b);
    ll d=a*b/c;
    return d;
}


int main() {
    ios_base::sync_with_stdio(false); 

    int n,m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) {
        cin >> a[i];
        a[i]/=2;
    }
    bool flag=1;
    ll ans=a[0];
    int ele=1;
    while (a[0]%2==0) {
        a[0]/=2;
        ele*=2;
    }
    repr(i,1,n) {
        if (a[i]%ele==0 && (a[i]/ele)%2>0 && ans<=m) ans=lcm(ans,a[i]);
        else flag=0;
    }
    if (flag) cout << (m/ans+1)/2 << endl;
    else cout << 0 << endl;

    return 0;
}


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

typedef long long LL;

const int N=1000,M=20,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n,m,a[N+9];

void into(){
  scanf("%d%d",&n,&m);
  for (int i=1;i<=m;++i)
	scanf("%d",&a[i]);
}

int inv[N+9],fac[N+9],ifac[N+9];

void Get_inv(){
  inv[1]=1;
  fac[0]=fac[1]=1;
  ifac[0]=ifac[1]=1;
  for (int i=2;i<=n;++i){
	inv[i]=mul(mod-mod/i,inv[mod%i]);
	fac[i]=mul(fac[i-1],i);
	ifac[i]=mul(ifac[i-1],inv[i]);
  }
}

int c[N+9][N+9];

void Get_c(){
  c[0][0]=1;
  for (int i=1;i<=n;++i){
	c[i][0]=c[i][i]=1;
	for (int j=1;j<i;++j) c[i][j]=add(c[i-1][j-1],c[i-1][j]);
  }
}

int dp[M+9][N+9];

void Get_dp(){
  dp[0][0]=1;
  for (int i=1;i<=m;++i)
	for (int j=0;j<=n;++j)
	  for (int k=0;k<=j&&k<=a[i];++k)
		sadd(dp[i][j],mul(mul(c[n-k][a[i]-k],ifac[k]),dp[i-1][j-k]));
}

void work(){
  Get_inv();
  Get_c();
  Get_dp();
}

void outo(){
  printf("%d\n",mul(dp[m][n],fac[n]));
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 7788
#include<bits/stdc++.h>
#define mo 1000000007
#define eps 1e-8
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
int n,a,b,i,j,f[5005][5005][2],sum[5005][5005][2],sum2[5005],sum3[5005],flag[5005],ans;
int main(){
	n=read();a=read();b=read();
	if(a<b)
		swap(a,b);
	sum[0][0][0]=1;
	sum[0][0][1]=1;
	sum2[0]=1;
	flag[0]=1;
	for(i=1;i<=n;i++){
		if(i>=b)
			f[i][0][1]=(sum2[i-1]-sum2[i-b]+mo)%mo;
		else
			f[i][0][1]=sum2[i-1];
		sum[i][0][1]=f[i][0][1];
		for(j=1;j<a&&j<=i;j++){
			f[i][j][0]=sum[i-1][j-1][1];
			if(j>=b)
				f[i][j][1]=sum[i-b][j-b][0];
			sum[i][j][0]=(sum[i-1][j-1][0]+f[i][j][0])%mo;
			sum[i][j][1]=(sum[i-1][j-1][1]+f[i][j][1])%mo;
			sum2[i]=(sum2[i]+f[i][j][0])%mo;
		}
		sum2[i]=(sum2[i]+sum2[i-1])%mo;
		flag[i]=f[i][0][1];
	}
	
	sum3[0]=1;
	for(i=1;i<=n;i++){
		if(i>=b)
			f[i][0][1]=(sum3[i-1]-sum3[i-b]+mo)%mo;
		else
			f[i][0][1]=sum3[i-1];
		sum[i][0][1]=f[i][0][1];
		for(j=1;j<=i;j++){
			f[i][j][0]=sum[i-1][j-1][1];
			if(j>=b)
				f[i][j][1]=sum[i-b][j-b][0];
			if(j>=a){
				ans=(1LL*f[i][j][0]*flag[n-i]+ans)%mo;
				if(i==n)
					ans=(f[i][j][1]+ans)%mo;
			}
			sum[i][j][0]=(sum[i-1][j-1][0]+f[i][j][0])%mo;
			sum[i][j][1]=(sum[i-1][j-1][1]+f[i][j][1])%mo;
			sum3[i]=(sum3[i]+f[i][j][0])%mo;
		}
		sum3[i]=(sum3[i]+sum3[i-1])%mo;
	}
	pus(ans,2);
    return 0;
}

Measured memory_bytes: 237048
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

ll upper(ll n,ll m){return (n+m-1)/m;};
ll rounding(ll n){return (long double)n+0.5;};

bool inG(ll x,ll n){return 0<=x && x<n;}
bool outG(ll x,ll n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  int a,b;

  cin>>a>>b;

  if(b==1){

    coutYN(1);
    return 0;

  }

  a--,b--;

  coutYN(a/b>=2);

  return 0;

}


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

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


Measured memory_bytes: 640
import math
from collections import defaultdict


def main():
    N = int(input())
    A = list(map(int, input().split()))
    minus_A_plus_i = tuple([- A[i] + (i+1) for i in range(N)])
    A_plus_i = tuple([A[i] + (i+1) for i in range(N)])

    cnt = defaultdict(int)
    for e in minus_A_plus_i:
        cnt[e] += 1

    c = 0

    for item in A_plus_i:
        c += cnt[item]

    print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 66204
n = int(input())
f = True
history = []
lw = None
for i in range(n):
    w = input()
    if w in history:
        f = False
        break
    if lw is not None:
        if w[0] != lw:
            f = False
            break
    history.append(w)
    lw = w[-1]
if f:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {


    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static final char NOT_DECIDED = 0;

    public void execute(CustomReader in) throws IOException {
        final String S = in.readLine();
        final String T = in.readLine();

        final int L = S.length();
        char[] s_to_t = new char[26];
        char[] t_to_s = new char[26];
        Arrays.fill(s_to_t, NOT_DECIDED);
        Arrays.fill(t_to_s, NOT_DECIDED);

        boolean mappable = true;


        for (int i = 0; i < L; i++) {
            char sc = S.charAt(i);
            char tc = T.charAt(i);
            if (s_to_t[idx(sc)] == NOT_DECIDED) {
                s_to_t[idx(sc)] = tc;
            }
            if (t_to_s[idx(tc)] == NOT_DECIDED) {
                t_to_s[idx(tc)] = sc;
            }

            if (s_to_t[idx(sc)] != tc || t_to_s[idx(tc)] != sc) {
                mappable = false;
                break;
            }
        }

        System.out.println(mappable ? "Yes" : "No");


    }

    private int idx(char c) {
        return c - 'a';
    }


    static class CustomReader extends BufferedReader {
        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int readLineAsInt() throws IOException {
            return Integer.parseInt(readLine());
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

        public char[][] readAsCharMatrix(int rows) throws IOException {
            char[][] matrix = new char[rows][];
            for (int i = 0; i < rows; i++) {
                matrix[i] = this.readLine().toCharArray();
            }
            return matrix;
        }

    }

}

Measured memory_bytes: 25300
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<vector<char>> vec(Q,vector<char>(2));
  for(int i=0; i<Q; i++){
    for(int j=0; j<2; j++){
      cin >> vec[i][j];
    }
  }
  
  int ans = 0;
  
  //左側に落ちるかどうか
  int ok = -1;
  int ng = N;
  int mid = (ok+ng)/2;
  while(ng - ok > 1){
    mid = max(0,(ok+ng)/2);
    char pos_c = S[mid];
    int pos = mid;
    bool out = false;
    for(int i=0; i<Q; i++){
      if(vec[i][0] == pos_c){
        if(vec[i][1] == 'L'){
          if(pos == 0){
            out = true;
            break;
          }
          else{
            pos--;
            pos_c = S[pos];
          }
        }
        else{
          if(pos == N-1){
            break;
          }
          else{
            pos++;
            pos_c = S[pos];
          }
        }
      }
    }
    if(out){
      ok = mid;
    }
    else{
      ng = mid;
    }
  }
  
  
  int A = ok;
  
  //右側に落ちるかどうか
  
  ok = N;
  ng = -1;
  mid = (ok+ng)/2;
  while(ok - ng > 1){
    mid = min(N-1,(ok+ng)/2);
    char pos_c = S[mid];
    int pos = mid;
    bool out = false;
    for(int i=0; i<Q; i++){
      if(vec[i][0] == pos_c){
        if(vec[i][1] == 'L'){
          if(pos == 0){
            break;
          }
          else{
            pos--;
            pos_c = S[pos];
          }
        }
        else{
          if(pos == N-1){
            out = true;
            break;
          }
          else{
            pos++;
            pos_c = S[pos];
          }
        }
      }
    }
    if(out){
      ok = mid;
    }
    else{
      ng = mid;
    }
  }
  
  int B = ok;
  
  
  cout << max(0, B - A - 1) << endl;
}
  
          

Measured memory_bytes: 11396
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> W(N);
  int sum = 0;
  for (int i = 0; i < N; i++){
    cin >> W[i];
    sum += W[i];
  }
  int Tsum = 0;
  int minD = sum;
  for (int i = 0; i < N; i++){
    Tsum += W[i];
    minD = min(minD,abs(sum - Tsum - Tsum));
  }
  cout << minD;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int N, K;
    cin >> N >> K;
    auto comp1 = [](pl &a, pl &b) {
        return a.second < b.second;
    };
    auto comp2 = [](pi &a, pi &b) {
        return a.second > b.second;
    };
    priority_queue<pl, vector<pl>, decltype(comp1)> remain(comp1);
    for (int i = 0; i < N; i++) {
        ll t, d;
        cin >> t >> d;
        remain.emplace(t, d);
    }
    map<int, int> use_sushi;
    ll score = 0;
    priority_queue<pi, vector<pi>, decltype(comp2)> use(comp2);
    for (int i = 0; i < K; i++) {
        auto now = remain.top();
        remain.pop();
        use_sushi[now.first]++;
        score += now.second;
        use.push(now);
    }
    ll ans = score + (ll) use_sushi.size() * (ll) use_sushi.size();
    while (!remain.empty()) {
        auto now = remain.top();
        remain.pop();
        if (use_sushi.find(now.first) != use_sushi.end()) continue;
        score += now.second;
        use_sushi[now.first]++;
        bool check = false;
        while (!use.empty()) {
            auto erase = use.top();
            use.pop();
            if (use_sushi[erase.first] == 1) continue;
            check = true;
            score -= erase.second;
            use_sushi[erase.first]--;
            break;
        }
        if (check) ans = max(ans, score + (ll) use_sushi.size() * (ll) use_sushi.size());
        else break;
    }
    cout << ans << endl;
}


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

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int a = Integer.parseInt(chr[0]);
			int b = Integer.parseInt(chr[1]);
			 System.out.println((a-1)*(b-1));
		}
	}
}

Measured memory_bytes: 25224
from collections import deque
import copy

def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]


    # スタート地点をqueueに追加
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])

    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))

        if nque:
            que = copy.copy(nque)
        else:
            break

    print(count - 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 115536
#!/usr/bin/env python3
import copy

H, W, K = map(int, input().split())
if K > W:
    exit(print(0))

# 現在の盤面を生成する
c = [[] for _ in range(W)]
for i in range(H):
    S = input()
    for j in range(W):
        c[j].append(int(S[j]))

for j in range(W):
    c[j] = c[j][::-1]

# 連鎖消滅後の得点を計算する
def cal_score(c,score,loop):
    # 消滅
    nextc = []
    for j in range(W):
        num0 = c[j].count(0)
        tmp = [*filter(lambda x: x>0,c[j])]
        nextc.append(tmp+[0]*num0)

    # 連鎖
    res = 0# 追加得点
    for i in range(H):
        j = 0
        while j < W:
            seq = 1
            while j<W-1 and nextc[j][i] == nextc[j+1][i] > 0:
                seq += 1
                j += 1
            if seq >= K:
                res += seq * nextc[j][i]
                for k in range(j-seq+1,j+1):
                    nextc[k][i] = 0
            j += 1
    if res == 0:
        return score
    else:
        return cal_score(nextc,score+res*pow(2,loop),loop+1)
    

ans = 0
for p in range(H):
    for q in range(W):
        cc = copy.deepcopy(c)
        cc[q][p] = 0
        z = cal_score(cc,0,0)
        ans = max(ans, z)
print(ans)

Measured memory_bytes: 80628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.nextLine();
		String s2 = sc.nextLine();
		String s3 = sc.nextLine();
		System.out.println(""+s1.charAt(0)+s2.charAt(1)+s3.charAt(2));
	}

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
#define mem(i, a) memset(i, a, sizeof(i))
#define sqr(x) ((x)*(x))
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
typedef long long ll;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 7;
using namespace std;
ll arr[maxn], brr[maxn], c[maxn];
int main(void){
#ifdef ljxtt
freopen("data.in", "r", stdin);
#endif
    int n; scanf("%d", &n);
    c[0] = c[1] = 0;
    c[2] = 1;
    for(int i = 2; i < maxn - 1; i++){
        c[i + 1] = c[i]  * (i + 1)/ (i - 1);
    }
    for(int i = 0; i < n; i++){
        scanf("%d", &brr[i]);
        arr[brr[i]]++;
    }
    ll sum = 0;
    for(int i = 0; i < maxn - 1; i++){
        sum += c[arr[i]];
    }
    for(int i = 0; i < n; i++){
        printf("%lld\n", sum - c[arr[brr[i]]] + c[arr[brr[i]] - 1]); 
    }
    return 0;
}

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

int32_t main(){
    char c;
    cin >> c;
    if(c >= 'A' && c <= 'Z'){
        cout << 'A' << "\n";
    } else {
        cout << 'a' << "\n";
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

vector<lvector> comb(ll n) {
  vector<lvector> v(n+1,lvector(n+1,0));
  rep(i,n+1) {v[i][0]=1;v[i][i]=1;}
  for(ll j=1;j<n+1;++j)
  for(ll k=1;k<j;++k) v[j][k]=v[j-1][k-1]+v[j-1][k];
  return v;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,res,zero=0,one=0;cin>>n>>res;
  lvector A(n);
  rep(i,n) {cin>>A[i];A[i]%=2;if(A[i]==0) zero++;else one++;}
  ll v=1,w=0;rep(i,zero) v*=2;
  vector<lvector> vec=comb(n);
  for(ll i=0;2*i+res<=one;++i) w+=vec[one][2*i+res];
  print(v*w);
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
    int n;
    cin >> n;
    vector<lli> a(3*n);
    for(int i=0; i<3*n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    lli ans = 0;
    for(int i=n; i<3*n; i+=2){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int N, X;
    private int[] A;
    private int[] B;

    private void Scan()
    {
        var line = Console.ReadLine().Split(' ');
        N = int.Parse(line[0]);
        X = int.Parse(line[1]);
        A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }

    private long Calc(int k)
    {
        for (int i = 0; i < N; i++)
        {
            int p = i - k;
            if (p < 0)
            {
                p += N;
            }
            B[i] = Math.Min(B[i], A[p]);
        }
        return (long)X * k + B.Sum(i => (long)i);
    }

    public void Solve()
    {
        Scan();

        B = new int[N];

        for (int i = 0; i < N; i++)
        {
            B[i] = int.MaxValue;
        }

        long ans = long.MaxValue;

        for (int k = 0; k < N; k++)
        {
            ans = Math.Min(ans, Calc(k));
        }

        Console.WriteLine(ans);
    }
}


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

using namespace std;

typedef long long ll;
ll n, ans;

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

	cin >> n;

	if (n % 2 == 1) {
		cout << 0 << "\n";
		return 0;
	}

	n /= 2;

	while (n >= 1) {
		ans += (n / 5);
		n /= 5;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

lint LCM(lint a,lint b){
  if(a==0 || b==0) return 0;
  lint tmp,r,x;
  x=a*b;
  if(a<b) tmp=a,a=b,b=tmp;
  r=a%b;
  while(r!=0) a=b,b=r,r=a%b;
  x=x/b;
  return x;
}

lint GCD(lint a,lint b){
  if(a==0 || b==0) return max(a,b);
  else return (a*b)/LCM(a,b);
}

int main(void){
    lint N,M;
    cin >> N >> M;
    string S,T;
    cin >> S >> T;
    lint ans=LCM(N,M);
    map<lint,char> comp;
    map<lint,lint> used;
    bool check=true;
    rep(i,N){
        lint now=i*ans/N+1;
        comp[now]=S[i];
        used[now]=1;
    }
    rep(i,M){
        lint now=i*ans/M+1;
        if(used[now]==1) if(comp[now]!=T[i]) check=false;
    }
    if(check) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 15616
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
#define all(x) x.begin(),x.end() 
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define per(i,a,b) for(ri i=(a);i>=(b);--i)
#define ls (x<<1)
#define rs (x<<1|1)
#define mid (l+r>>1)
#define db(x) cout << "#x:" << x << endl
#define dd() cout << "Out put!\n"
const int mod=1e9+7,maxn=100010;
const double eps=1e-8,pi=acos(-1.0);
const int inf=0x7f7f7f7f7f7f7f7f;
using namespace std;
int a[maxn],b[maxn],v[maxn];
string s; 
signed main()
{
	ios::sync_with_stdio(0);
	int t=1;
//	cin >> t; 
	while(t--)
	{
		int n,k;
		cin >> n >> k;
		rep(i,1,n)	
			cin >> a[i];
		sort(a+1,a+1+n);
		int ans = 0;
		rep(i,1,k)
			ans+=a[i];
		cout << ans << endl;
		
	} 
	return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
vector<int> v[2019];
const int MOD = 2019;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string s;
    cin >> s;
    int n = s.size();
    v[0].push_back(n);
    int sum = 0;
    int tmp = 1;
    for(int i = n-1; i >= 0; i--){
        sum += tmp*(s[i]-'0');
        sum %= MOD;
        v[sum].push_back(i);
        tmp *= 10;
        tmp %= MOD;
    }
    ll ans = 0;
    for(int i = 0; i < MOD; i++){
        ll s = v[i].size();
        if(s >= 2){
            ans += (s*(s-1))/2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4924
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

void solve() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W));
    rep(i,H) rep(j,W) cin >> a[i][j];
    vector<vector<int>> ans;
    rep(i,H) {
        rep(j,W-1) {
            if (a[i][j] % 2) {
                a[i][j+1]++;
                ans.push_back({i+1,j+1,i+1,j+2});
            }
        }
    }
    rep(i,H-1) {
        if (a[i][W-1] % 2) {
            a[i+1][W-1]++;
            ans.push_back({i+1,W,i+2,W});
        }
    }
    cout << ans.size() << endl;
    rep(i,ans.size()) {
        rep(j,4) {
            cout << ans[i][j];
            if (j<3) cout << " ";
            else cout << endl;
        }
    }
    return;
}

int main() {
    solve();
}


Measured memory_bytes: 10032